forked from elmau/empresa-libre
commit
a05b3d56a8
|
@ -87,6 +87,22 @@ class AppValues(object):
|
|||
resp.status = falcon.HTTP_200
|
||||
|
||||
|
||||
class AppFiles(object):
|
||||
|
||||
def __init__(self, db):
|
||||
self._db = db
|
||||
|
||||
def on_get(self, req, resp, table):
|
||||
values = req.params
|
||||
resp.status = falcon.HTTP_200
|
||||
|
||||
def on_post(self, req, resp, table):
|
||||
session = req.env['beaker.session']
|
||||
file_object = req.get_param('upload')
|
||||
req.context['result'] = self._db.upload_file(session, table, file_object)
|
||||
resp.status = falcon.HTTP_200
|
||||
|
||||
|
||||
class AppConfig(object):
|
||||
|
||||
def __init__(self, db):
|
||||
|
|
|
@ -60,6 +60,15 @@ def save_temp(data, modo='wb'):
|
|||
return path
|
||||
|
||||
|
||||
def save_file(path, data, modo='wb'):
|
||||
try:
|
||||
with open(path, modo) as f:
|
||||
f.write(data)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
def _join(*paths):
|
||||
return os.path.join(*paths)
|
||||
|
||||
|
@ -1081,6 +1090,27 @@ def get_date(value, next_day=False):
|
|||
return d
|
||||
|
||||
|
||||
def upload_file(rfc, opt, file_obj):
|
||||
if opt == 'emisorlogo':
|
||||
tmp = file_obj.filename.split('.')
|
||||
name = '{}.{}'.format(rfc.lower(), tmp[-1].lower())
|
||||
path = _join(PATH_MEDIA, 'logos', name)
|
||||
elif opt == 'txt_plantilla_factura_33':
|
||||
tmp = file_obj.filename.split('.')
|
||||
ext = tmp[-1].lower()
|
||||
if ext != 'ods':
|
||||
msg = 'Extensión de archivo incorrecta, selecciona un archivo ODS'
|
||||
return {'status': 'server', 'name': msg, 'ok': False}
|
||||
|
||||
name = '{}_3.3.ods'.format(rfc.lower())
|
||||
path = _join(PATH_MEDIA, 'templates', name)
|
||||
|
||||
if save_file(path, file_obj.file.read()):
|
||||
return {'status': 'server', 'name': file_obj.filename, 'ok': True}
|
||||
|
||||
return {'status': 'error'}
|
||||
|
||||
|
||||
def cancel_cfdi(uuid, pk12, rfc, auth):
|
||||
from .pac import Finkok as PAC
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from models.db import StorageEngine
|
|||
from controllers.main import (
|
||||
AppLogin, AppLogout, AppAdmin, AppEmisor, AppConfig,
|
||||
AppMain, AppValues, AppPartners, AppProducts, AppInvoices, AppFolios,
|
||||
AppDocumentos
|
||||
AppDocumentos, AppFiles
|
||||
)
|
||||
from settings import DEBUG
|
||||
|
||||
|
@ -38,6 +38,7 @@ api.add_route('/emisor', AppEmisor(db))
|
|||
api.add_route('/folios', AppFolios(db))
|
||||
api.add_route('/main', AppMain(db))
|
||||
api.add_route('/values/{table}', AppValues(db))
|
||||
api.add_route('/files/{table}', AppFiles(db))
|
||||
api.add_route('/config', AppConfig(db))
|
||||
api.add_route('/doc/{type_doc}/{id_doc}', AppDocumentos(db))
|
||||
api.add_route('/partners', AppPartners(db))
|
||||
|
|
|
@ -14,6 +14,12 @@ class StorageEngine(object):
|
|||
def get_values(self, table, values=None):
|
||||
return getattr(self, '_get_{}'.format(table))(values)
|
||||
|
||||
def upload_file(self, session, table, file_obj):
|
||||
if not 'rfc' in session:
|
||||
return {'status': 'error'}
|
||||
|
||||
return main.upload_file(session['rfc'], table, file_obj)
|
||||
|
||||
def get_config(self, values):
|
||||
return main.Configuracion.get_(values)
|
||||
|
||||
|
|
|
@ -60,6 +60,13 @@ def desconectar():
|
|||
return
|
||||
|
||||
|
||||
def upload_file(rfc, opt, file_obj):
|
||||
result = util.upload_file(rfc, opt, file_obj)
|
||||
if result['ok']:
|
||||
Configuracion.add({opt: file_obj.filename})
|
||||
return result
|
||||
|
||||
|
||||
class Configuracion(BaseModel):
|
||||
clave = TextField(unique=True)
|
||||
valor = TextField(default='')
|
||||
|
@ -83,6 +90,15 @@ class Configuracion(BaseModel):
|
|||
.select()
|
||||
.where(Configuracion.clave.in_(fields))
|
||||
)
|
||||
elif keys['fields'] == 'templates':
|
||||
fields = (
|
||||
'txt_plantilla_factura_32',
|
||||
'txt_plantilla_factura_33',
|
||||
'txt_plantilla_factura_33j')
|
||||
data = (Configuracion
|
||||
.select()
|
||||
.where(Configuracion.clave.in_(fields))
|
||||
)
|
||||
|
||||
values = {r.clave: r.valor for r in data}
|
||||
return values
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var msg = ''
|
||||
var tb_options = null
|
||||
|
||||
|
||||
var controllers = {
|
||||
|
@ -18,6 +19,11 @@ var controllers = {
|
|||
$$('grid_folios').attachEvent('onItemClick', grid_folios_click)
|
||||
$$('cmd_probar_correo').attachEvent('onItemClick', cmd_probar_correo_click)
|
||||
$$('cmd_guardar_correo').attachEvent('onItemClick', cmd_guardar_correo_click)
|
||||
$$('emisor_logo').attachEvent('onItemClick', emisor_logo_click)
|
||||
//~ Opciones
|
||||
tb_options = $$('tab_options').getTabbar()
|
||||
tb_options.attachEvent('onChange', tab_options_change)
|
||||
$$('txt_plantilla_factura_33').attachEvent('onItemClick', txt_plantilla_factura_33_click)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +199,26 @@ function get_config_correo(){
|
|||
form.setValues(values)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function get_config_values(opt){
|
||||
if(opt == undefined){
|
||||
return
|
||||
}
|
||||
|
||||
webix.ajax().get('/config', {'fields': opt}, {
|
||||
error: function(text, data, xhr) {
|
||||
msg = 'Error al consultar'
|
||||
msg_error(msg)
|
||||
},
|
||||
success: function(text, data, xhr) {
|
||||
var values = data.json()
|
||||
Object.keys(values).forEach(function(key){
|
||||
$$(key).setValue(values[key])
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
@ -215,6 +240,11 @@ function multi_admin_change(prevID, nextID){
|
|||
get_config_correo()
|
||||
return
|
||||
}
|
||||
|
||||
if(nextID == 'app_options'){
|
||||
get_config_values('templates')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -586,3 +616,71 @@ function cmd_guardar_correo_click(){
|
|||
}
|
||||
|
||||
|
||||
function emisor_logo_click(id, e){
|
||||
|
||||
var w = webix.ui({
|
||||
view: 'window',
|
||||
id: 'win_emisor_logo',
|
||||
modal: true,
|
||||
position: 'center',
|
||||
head: 'Subir logotipo',
|
||||
body: {
|
||||
view: 'form',
|
||||
elements: body_win_emisor_logo,
|
||||
}
|
||||
})
|
||||
|
||||
w.show()
|
||||
|
||||
$$('up_emisor_logo').attachEvent('onUploadComplete', function(response){
|
||||
$$('emisor_logo').setValue(response.name)
|
||||
msg_sucess('Logotipo cargado correctamente')
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
function txt_plantilla_factura_33_click(e){
|
||||
|
||||
var body_elements = [
|
||||
{cols: [{width: 100}, {view: 'uploader', id: 'up_template', autosend: true, link: 'lst_files',
|
||||
value: 'Seleccionar archivo', upload: '/files/txt_plantilla_factura_33',
|
||||
width: 200}, {width: 100}]},
|
||||
{view: 'list', id: 'lst_files', type: 'uploader', autoheight:true,
|
||||
borderless: true},
|
||||
{},
|
||||
{cols: [{}, {view: 'button', label: 'Cerrar', autowidth: true,
|
||||
click:("$$('win_template').close();")}, {}]}
|
||||
]
|
||||
|
||||
var w = webix.ui({
|
||||
view: 'window',
|
||||
id: 'win_template',
|
||||
modal: true,
|
||||
position: 'center',
|
||||
head: 'Subir Plantilla',
|
||||
body: {
|
||||
view: 'form',
|
||||
elements: body_elements,
|
||||
}
|
||||
})
|
||||
|
||||
w.show()
|
||||
|
||||
$$('up_template').attachEvent('onUploadComplete', function(response){
|
||||
if(response.ok){
|
||||
$$('txt_plantilla_factura_33').setValue(response.name)
|
||||
msg_sucess('Plantilla cargada correctamente')
|
||||
}else{
|
||||
msg_error(response.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function tab_options_change(nv, ov){
|
||||
var cv = {
|
||||
Plantillas: 'templates',
|
||||
}
|
||||
get_config_values(cv[nv])
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ var controllers = {
|
|||
$$("cmd_cancel_product").attachEvent("onItemClick", cmd_cancel_product_click)
|
||||
$$("chk_automatica").attachEvent("onChange", chk_automatica_change)
|
||||
$$("valor_unitario").attachEvent("onChange", valor_unitario_change)
|
||||
$$("clave_sat").attachEvent('onSearchIconClick', clave_sat_icon_click)
|
||||
//~ Invoices
|
||||
$$('cmd_new_invoice').attachEvent("onItemClick", cmd_new_invoice_click)
|
||||
$$('cmd_refacturar').attachEvent("onItemClick", cmd_refacturar_click)
|
||||
|
|
|
@ -201,3 +201,8 @@ function valor_unitario_change(new_value, old_value){
|
|||
this.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function clave_sat_icon_click(){
|
||||
show('Buscar SAT')
|
||||
}
|
||||
|
|
|
@ -4,11 +4,14 @@ var menu_data = [
|
|||
{id: 'app_emisor', icon: 'user-circle', value: 'Emisor'},
|
||||
{id: 'app_folios', icon: 'sort-numeric-asc', value: 'Folios'},
|
||||
{id: 'app_correo', icon: 'envelope-o', value: 'Correo'},
|
||||
{id: 'app_sat', icon: 'table', value: 'Catalogos SAT'},
|
||||
{id: 'app_options', icon: 'cog', value: 'Opciones'},
|
||||
]
|
||||
|
||||
|
||||
var sidebar = {
|
||||
var sidebar_admin = {
|
||||
view: 'sidebar',
|
||||
id: 'sidebar_admin',
|
||||
data: menu_data,
|
||||
ready: function(){
|
||||
this.select('app_home');
|
||||
|
@ -328,6 +331,40 @@ var form_correo = {
|
|||
}
|
||||
|
||||
|
||||
var options_templates = [
|
||||
{maxHeight: 15},
|
||||
{cols: [{maxWidth: 15},
|
||||
{view: 'search', id: 'txt_plantilla_factura_32', name: 'plantilla_factura_32',
|
||||
label: 'Plantilla Factura v3.2 (ODT): ', labelPosition: 'top',
|
||||
icon: 'file'}, {}]},
|
||||
{maxHeight: 20},
|
||||
{cols: [{maxWidth: 15},
|
||||
{view: 'search', id: 'txt_plantilla_factura_33', labelPosition: 'top',
|
||||
label: 'Plantilla Factura v3.3 (ODT): ', icon: 'file'}, {}]},
|
||||
{maxHeight: 20},
|
||||
{cols: [{maxWidth: 15},
|
||||
{view: 'search', id: 'txt_plantilla_factura_33j', name: 'plantilla_factura_33j',
|
||||
label: 'Plantilla Factura v3.3 (JSON): ', labelPosition: 'top',
|
||||
icon: 'file'}, {}]},
|
||||
{}]
|
||||
|
||||
|
||||
var tab_options = {
|
||||
view: 'tabview',
|
||||
id: 'tab_options',
|
||||
multiview: true,
|
||||
tabbar: {options: [
|
||||
'Plantillas',
|
||||
'Otros']},
|
||||
animate: true,
|
||||
cells: [
|
||||
{id: 'Plantillas', rows: options_templates},
|
||||
{id: 'Otros', rows: [{}]},
|
||||
{},
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
var app_emisor = {
|
||||
id: 'app_emisor',
|
||||
rows:[
|
||||
|
@ -367,6 +404,26 @@ var app_correo = {
|
|||
}
|
||||
|
||||
|
||||
var app_sat = {
|
||||
id: 'app_sat',
|
||||
rows:[
|
||||
{view: 'template', id: 'th_sat', type: 'header',
|
||||
template: 'Catálogos del SAT'},
|
||||
{},
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
var app_options = {
|
||||
id: 'app_options',
|
||||
rows:[
|
||||
{view: 'template', id: 'th_options', type: 'header',
|
||||
template: 'Opciones'},
|
||||
tab_options,
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
var multi_admin = {
|
||||
id: 'multi_admin',
|
||||
animate: true,
|
||||
|
@ -374,11 +431,13 @@ var multi_admin = {
|
|||
{
|
||||
id: 'app_admin_home',
|
||||
view: 'template',
|
||||
template: 'HOME'
|
||||
template: 'Admin Inicio'
|
||||
},
|
||||
app_emisor,
|
||||
app_folios,
|
||||
app_correo,
|
||||
app_sat,
|
||||
app_options,
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -394,14 +453,16 @@ var menu_user = {
|
|||
type: {
|
||||
subsign: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var ui_admin = {
|
||||
rows: [
|
||||
{view: 'toolbar', padding: 3, elements: [
|
||||
{view: 'button', type: 'icon', icon: 'bars',
|
||||
width: 37, align: 'left', css: 'app_button', click: function(){
|
||||
$$('$sidebar1').toggle()
|
||||
//~ $$('$sidebar1').toggle()
|
||||
$$('sidebar_admin').toggle()
|
||||
}
|
||||
},
|
||||
{view: 'label', label: 'Empresa Libre - Configuración'},
|
||||
|
@ -412,9 +473,22 @@ var ui_admin = {
|
|||
]},
|
||||
{
|
||||
cols:[
|
||||
sidebar,
|
||||
sidebar_admin,
|
||||
multi_admin,
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
|
||||
var body_win_emisor_logo = [
|
||||
{view: 'uploader', id: 'up_emisor_logo', autosend: true, link: 'lst_logo',
|
||||
value: 'Seleccionar logotipo', upload: '/files/emisorlogo', width: 200,
|
||||
accept: "image/png, image/gif, image/jpeg"},
|
||||
{view: 'list', id: 'lst_logo', name: 'logo',
|
||||
type: 'uploader', autoheight:true, borderless: true},
|
||||
{},
|
||||
{cols: [{}, {view: 'button', label: 'Cerrar', autowidth: true,
|
||||
click:("$$('win_emisor_logo').close();")}, {}]}
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue