From 0465b684f04121d1c037aa7e4e8f309dc68b7d8a Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Fri, 5 Oct 2018 23:13:03 -0500 Subject: [PATCH] Mejora #292 --- source/app/controllers/main.py | 17 +++++++ source/app/controllers/util.py | 29 ++++++++++++ source/app/main.py | 3 +- source/app/models/db.py | 3 ++ source/app/models/main.py | 19 ++++++++ source/static/js/controller/admin.js | 66 ++++++++++++++++++++++++++++ source/static/js/ui/admin.js | 8 ++-- 7 files changed, 141 insertions(+), 4 deletions(-) diff --git a/source/app/controllers/main.py b/source/app/controllers/main.py index f677d14..69ed5e5 100644 --- a/source/app/controllers/main.py +++ b/source/app/controllers/main.py @@ -543,3 +543,20 @@ class AppCfdiPay(object): values = req.params req.context['result'] = self._db.cfdipay(values) resp.status = falcon.HTTP_200 + + +class AppSATBancos(object): + + def __init__(self, db): + self._db = db + + # ~ def on_get(self, req, resp): + # ~ values = req.params + # ~ req.context['result'] = self._db.get_sat_bancos(values) + # ~ resp.status = falcon.HTTP_200 + + def on_post(self, req, resp): + values = req.params + req.context['result'] = self._db.satbancos(values) + resp.status = falcon.HTTP_200 + diff --git a/source/app/controllers/util.py b/source/app/controllers/util.py index 6efd2b6..271f9ec 100644 --- a/source/app/controllers/util.py +++ b/source/app/controllers/util.py @@ -3618,3 +3618,32 @@ def respaldar_db(values, path_bk): args = 'pg_dump -U postgres -Fc {} > "{}"'.format(db, path) _call(args) return + + +def validate_rfc(value): + msg = '' + if len(value) < 12: + msg = 'Longitud inválida del RFC' + return msg + l = 4 + if len(value)==12: + l = 3 + s = value[0:l] + r = re.match('[A-ZÑ&]{%s}' % l, s) + msg = 'Caracteres inválidos al {} del RFC' + if not r: + return msg.format('inicio') + s = value[-3:] + r = re.match('[A-Z0-9]{3}', s) + if not r: + return msg.format('final') + s = value[l:l+6] + r = re.match('[0-9]{6}', s) + msg = 'Fecha inválida en el RFC' + if not r: + return msg + try: + datetime.datetime.strptime(s, '%y%m%d') + return '' + except: + return msg diff --git a/source/app/main.py b/source/app/main.py index 7c21cc2..87352e9 100644 --- a/source/app/main.py +++ b/source/app/main.py @@ -17,7 +17,7 @@ from controllers.main import (AppEmpresas, AppMain, AppValues, AppPartners, AppProducts, AppInvoices, AppFolios, AppDocumentos, AppFiles, AppPreInvoices, AppCuentasBanco, AppMovimientosBanco, AppTickets, AppStudents, AppEmployees, AppNomina, - AppInvoicePay, AppCfdiPay + AppInvoicePay, AppCfdiPay, AppSATBancos ) @@ -58,6 +58,7 @@ api.add_route('/employees', AppEmployees(db)) api.add_route('/nomina', AppNomina(db)) api.add_route('/invoicepay', AppInvoicePay(db)) api.add_route('/cfdipay', AppCfdiPay(db)) +api.add_route('/satbancos', AppSATBancos(db)) # ~ Activa si usas waitress y NO estas usando servidor web diff --git a/source/app/models/db.py b/source/app/models/db.py index 139d571..b1ff1f7 100644 --- a/source/app/models/db.py +++ b/source/app/models/db.py @@ -441,3 +441,6 @@ class StorageEngine(object): def bankmovement(self, values): return main.MovimientosBanco.post(values) + + def satbancos(self, values): + return main.SATBancos.post(values) diff --git a/source/app/models/main.py b/source/app/models/main.py index 91e4154..79f0de0 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -1517,6 +1517,25 @@ class SATBancos(BaseModel): def __str__(self): return 'Banco: {} ({})'.format(self.name, self.key) + def _updaterfc(self, args): + id = int(args['id']) + values = util.loads(args['values']) + msg = util.validate_rfc(values['rfc']) + if msg: + return {'ok': False, 'msg': msg} + + q = (SATBancos + .update(**values) + .where(SATBancos.id==id)) + result = bool(q.execute()) + msg = 'RFC actualizado correctamente' + return {'ok': result, 'msg': msg} + + @classmethod + def post(cls, values): + opt = values.pop('opt') + return getattr(cls, '_{}'.format(opt))(cls, values) + @classmethod def get_(cls): rows = SATBancos.select().dicts() diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js index d81ce7b..d9b2a75 100644 --- a/source/static/js/controller/admin.js +++ b/source/static/js/controller/admin.js @@ -112,6 +112,11 @@ var controllers = { $$('cmd_subir_cfdixml').attachEvent('onItemClick', cmd_subir_cfdixml_click) $$('up_bdfl').attachEvent('onUploadComplete', up_bdfl_upload_complete) $$('up_cfdixml').attachEvent('onUploadComplete', up_cfdixml_upload_complete) + + $$('grid_admin_bancos').attachEvent('onAfterEditStart', grid_admin_bancos_after_edit_start) + $$('grid_admin_bancos').attachEvent('onBeforeEditStop', grid_admin_bancos_before_edit_stop) + //~ $$('grid_admin_bancos').attachEvent('onAfterEditStop', grid_admin_bancos_after_edit_stop) + } } @@ -2276,3 +2281,64 @@ function grid_emisor_cuentas_banco_on_check(row, column, state){ } }) } + + +function admin_sat_bank_update_rfc(id, rfc){ + var data = {opt: 'updaterfc', id: id, values: {rfc: rfc}} + webix.ajax().post('/satbancos', data, { + error:function(text, data, XmlHttpRequest){ + msg = 'Ocurrio un error, consulta a soporte técnico' + msg_error(msg) + }, + success:function(text, data, XmlHttpRequest){ + var values = data.json() + if(values.ok){ + msg_ok(values.msg) + }else{ + msg_error(values.msg) + } + } + }) +} + + +function grid_admin_bancos_after_edit_start(id){ + var grid = $$('grid_admin_bancos') + + if(id['column']=='rfc'){ + var row = grid.getItem(id) + if(row['key']=='999'){ + grid.editCancel() + } + } +} + + +function grid_admin_bancos_before_edit_stop(state, editor){ + var grid = $$('grid_admin_bancos') + var row = grid.getItem(editor.row) + + if(editor.column == 'rfc' && row['key']!='999'){ + var rfc = state.value + if (rfc.length != 12){ + msg_error('Longitud incorrecta del RFC') + grid.blockEvent() + state.value = state.old + grid.editCancel() + grid.unblockEvent() + return true + } + if(!validar_rfc(rfc)){ + grid.blockEvent() + state.value = state.old + grid.editCancel() + grid.unblockEvent() + return true + } + grid.blockEvent() + state.value = state.value.trim().toUpperCase() + grid.editCancel() + grid.unblockEvent() + admin_sat_bank_update_rfc(row.id, state.value) + } +} diff --git a/source/static/js/ui/admin.js b/source/static/js/ui/admin.js index fe8e60f..756bd86 100644 --- a/source/static/js/ui/admin.js +++ b/source/static/js/ui/admin.js @@ -804,7 +804,9 @@ var grid_admin_monedas_cols = [ var grid_admin_bancos_cols = [ {id: 'id', header: 'ID', hidden: true}, {id: 'key', header: 'Clave', footer: {content: 'countRows', css: 'right'}}, - {id: 'name', header: 'Nombre', adjust: 'data', footer: 'Bancos'}, + {id: 'name', header: 'Nombre', footer: 'Bancos', fillspace: true}, + {id: 'razon_social', header: 'Razón Social', fillspace: true}, + {id: 'rfc', header: 'RFC', width: 125, editor: 'text'}, {id: 'activo', header: 'Activo', template: '{common.checkbox()}', editor: 'checkbox'}, ] @@ -851,7 +853,7 @@ var grid_admin_bancos = { id: 'grid_admin_bancos', select: 'cell', adjust: true, - autowidth: true, + editable: true, headermenu: true, footer: true, columns: grid_admin_bancos_cols, @@ -1027,7 +1029,7 @@ var sat_bancos = [ {maxHeight: 20}, {cols: [{maxWidth: 15}, {view: 'label', label: msg_bancos}, {}]}, {maxHeight: 20}, - {cols: [{maxWidth: 15}, grid_admin_bancos, {}]}, + {cols: [{maxWidth: 15}, grid_admin_bancos]}, {maxHeight: 20}, ]