Agregar cuentas de banco del emisor
This commit is contained in:
parent
ea298c52d5
commit
a290a034f8
|
@ -238,6 +238,23 @@ class AppEmisor(object):
|
|||
resp.status = falcon.HTTP_204
|
||||
|
||||
|
||||
class AppCuentasBanco(object):
|
||||
|
||||
def __init__(self, db):
|
||||
self._db = db
|
||||
|
||||
def on_get(self, req, resp):
|
||||
values = req.params
|
||||
session = req.env['beaker.session']
|
||||
#~ req.context['result'] = self._db.get_emisor(session['rfc'])
|
||||
resp.status = falcon.HTTP_200
|
||||
|
||||
def on_post(self, req, resp):
|
||||
values = req.params
|
||||
req.context['result'] = self._db.cuentasbanco(values)
|
||||
resp.status = falcon.HTTP_200
|
||||
|
||||
|
||||
class AppFolios(object):
|
||||
|
||||
def __init__(self, db):
|
||||
|
|
|
@ -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, AppFiles, AppPreInvoices
|
||||
AppDocumentos, AppFiles, AppPreInvoices, AppCuentasBanco
|
||||
)
|
||||
from settings import DEBUG
|
||||
|
||||
|
@ -45,6 +45,7 @@ api.add_route('/partners', AppPartners(db))
|
|||
api.add_route('/products', AppProducts(db))
|
||||
api.add_route('/invoices', AppInvoices(db))
|
||||
api.add_route('/preinvoices', AppPreInvoices(db))
|
||||
api.add_route('/cuentasbanco', AppCuentasBanco(db))
|
||||
|
||||
|
||||
if DEBUG:
|
||||
|
|
|
@ -103,6 +103,9 @@ class StorageEngine(object):
|
|||
def _get_bancoupdate(self, values):
|
||||
return main.SATBancos.actualizar(values)
|
||||
|
||||
def _get_emisorcuentasbanco(self, values):
|
||||
return main.CuentasBanco.emisor()
|
||||
|
||||
def _get_satkey(self, values):
|
||||
return main.get_sat_key(values['key'])
|
||||
|
||||
|
@ -112,6 +115,12 @@ class StorageEngine(object):
|
|||
def _get_monedas(self, values):
|
||||
return main.SATMonedas.get_activos()
|
||||
|
||||
def _get_monedasid(self, values):
|
||||
return main.SATMonedas.get_activos_by_id()
|
||||
|
||||
def _get_bancosid(self, values):
|
||||
return main.SATBancos.get_activos_by_id()
|
||||
|
||||
def _get_regimenes(self, values):
|
||||
return main.Emisor.get_regimenes()
|
||||
|
||||
|
@ -182,6 +191,9 @@ class StorageEngine(object):
|
|||
def emisor(self, values):
|
||||
return main.Emisor.add(values)
|
||||
|
||||
def cuentasbanco(self, values):
|
||||
return main.CuentasBanco.add(values)
|
||||
|
||||
def get_folios(self):
|
||||
return main.Folios.get_()
|
||||
|
||||
|
|
|
@ -658,6 +658,17 @@ class SATMonedas(BaseModel):
|
|||
)
|
||||
return tuple(rows)
|
||||
|
||||
@classmethod
|
||||
def get_activos_by_id(cls):
|
||||
rows = (SATMonedas
|
||||
.select(
|
||||
SATMonedas.id,
|
||||
SATMonedas.name.alias('value'))
|
||||
.where(SATMonedas.activo==True)
|
||||
.dicts()
|
||||
)
|
||||
return tuple(rows)
|
||||
|
||||
@classmethod
|
||||
def actualizar(self, values):
|
||||
id = int(values['id'])
|
||||
|
@ -773,12 +784,23 @@ class SATBancos(BaseModel):
|
|||
return 'Banco: {} ({})'.format(self.name, self.key)
|
||||
|
||||
@classmethod
|
||||
def get_(self):
|
||||
def get_(cls):
|
||||
rows = SATBancos.select().dicts()
|
||||
return tuple(rows)
|
||||
|
||||
@classmethod
|
||||
def actualizar(self, values):
|
||||
def get_activos_by_id(cls):
|
||||
rows = (SATBancos
|
||||
.select(
|
||||
SATBancos.id,
|
||||
SATBancos.name.alias('value'))
|
||||
.where(SATBancos.activo==True)
|
||||
.dicts()
|
||||
)
|
||||
return tuple(rows)
|
||||
|
||||
@classmethod
|
||||
def actualizar(cls, values):
|
||||
id = int(values['id'])
|
||||
if values['field'] == 'activo':
|
||||
v = {'0': False, '1': True}
|
||||
|
@ -791,6 +813,7 @@ class SATBancos(BaseModel):
|
|||
|
||||
class CuentasBanco(BaseModel):
|
||||
de_emisor = BooleanField(default=False)
|
||||
activa = BooleanField(default=True)
|
||||
nombre = TextField()
|
||||
banco = ForeignKeyField(SATBancos)
|
||||
fecha_apertura = DateField(null=True)
|
||||
|
@ -799,6 +822,8 @@ class CuentasBanco(BaseModel):
|
|||
moneda = ForeignKeyField(SATMonedas)
|
||||
saldo_inicial = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
||||
auto_round=True)
|
||||
saldo = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
||||
auto_round=True)
|
||||
|
||||
class Meta:
|
||||
order_by = ('nombre',)
|
||||
|
@ -809,6 +834,59 @@ class CuentasBanco(BaseModel):
|
|||
def __str__(self):
|
||||
return '{} ({})'.format(self.banco.name, self.cuenta[-4:])
|
||||
|
||||
@classmethod
|
||||
def emisor(cls):
|
||||
rows = (CuentasBanco
|
||||
.select(
|
||||
CuentasBanco.id,
|
||||
CuentasBanco.activa,
|
||||
CuentasBanco.nombre,
|
||||
SATBancos.name.alias('banco'),
|
||||
CuentasBanco.fecha_apertura,
|
||||
CuentasBanco.cuenta,
|
||||
CuentasBanco.clabe,
|
||||
SATMonedas.name.alias('moneda'),
|
||||
CuentasBanco.saldo
|
||||
)
|
||||
.join(SATBancos).switch(CuentasBanco)
|
||||
.join(SATMonedas).switch(CuentasBanco)
|
||||
.where(CuentasBanco.de_emisor==True).dicts()
|
||||
)
|
||||
return tuple(rows)
|
||||
|
||||
@classmethod
|
||||
def add(cls, values):
|
||||
w = '37137137137137137'
|
||||
dv = str(
|
||||
10 -
|
||||
sum([(int(v) * int(values['clabe'][i])) % 10 for i, v in enumerate(w)])
|
||||
% 10)
|
||||
if dv != values['clabe'][-1]:
|
||||
msg = 'Digito de control de la CLABE es incorrecto'
|
||||
return {'ok': False, 'msg': msg}
|
||||
|
||||
with database_proxy.transaction():
|
||||
obj = CuentasBanco.create(**values)
|
||||
|
||||
rows = (CuentasBanco
|
||||
.select(
|
||||
CuentasBanco.id,
|
||||
CuentasBanco.activa,
|
||||
CuentasBanco.nombre,
|
||||
SATBancos.name.alias('banco'),
|
||||
CuentasBanco.fecha_apertura,
|
||||
CuentasBanco.cuenta,
|
||||
CuentasBanco.clabe,
|
||||
SATMonedas.name.alias('moneda'),
|
||||
CuentasBanco.saldo
|
||||
)
|
||||
.join(SATBancos).switch(CuentasBanco)
|
||||
.join(SATMonedas).switch(CuentasBanco)
|
||||
.where(CuentasBanco.id==obj.id).dicts()
|
||||
)
|
||||
data = {'ok': True, 'row': row[0]}
|
||||
return data
|
||||
|
||||
|
||||
class SATUsoCfdi(BaseModel):
|
||||
key = TextField(index=True, unique=True)
|
||||
|
|
|
@ -21,6 +21,8 @@ var controllers = {
|
|||
$$('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)
|
||||
$$('cmd_emisor_agregar_cuenta').attachEvent('onItemClick', cmd_emisor_agregar_cuenta_click)
|
||||
$$('emisor_cuenta_saldo_inicial').attachEvent('onChange', emisor_cuenta_saldo_inicial_change)
|
||||
//~ SAT
|
||||
tb_sat = $$('tab_sat').getTabbar()
|
||||
tb_sat.attachEvent('onChange', tab_sat_change)
|
||||
|
@ -178,6 +180,38 @@ function get_certificado(){
|
|||
}
|
||||
|
||||
|
||||
function get_cuentas_banco(){
|
||||
|
||||
webix.ajax().get('/values/monedasid', function(text, data){
|
||||
var values = data.json()
|
||||
pre = values[0]
|
||||
$$('lst_emisor_cuenta_moneda').getList().parse(values)
|
||||
$$('lst_emisor_cuenta_moneda').setValue(pre.id)
|
||||
})
|
||||
|
||||
webix.ajax().get('/values/bancosid', function(text, data){
|
||||
var values = data.json()
|
||||
pre = values[0]
|
||||
$$('lst_emisor_banco').getList().parse(values)
|
||||
if(values.length == 1){
|
||||
$$('lst_emisor_banco').setValue(pre.id)
|
||||
}
|
||||
})
|
||||
|
||||
webix.ajax().get('/values/emisorcuentasbanco', {}, {
|
||||
error: function(text, data, xhr) {
|
||||
msg = 'Error al consultar'
|
||||
msg_error(msg)
|
||||
},
|
||||
success: function(text, data, xhr) {
|
||||
var values = data.json()
|
||||
$$('grid_emisor_cuentas_banco').parse(values)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_table_folios(){
|
||||
webix.ajax().get("/folios", {}, {
|
||||
error: function(text, data, xhr) {
|
||||
|
@ -263,6 +297,7 @@ function multi_admin_change(prevID, nextID){
|
|||
$$('tab_emisor').setValue('Datos Fiscales')
|
||||
get_emisor()
|
||||
get_certificado()
|
||||
get_cuentas_banco()
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -819,3 +854,104 @@ function grid_admin_bancos_on_check(row, column, state){
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function emisor_cuenta_saldo_inicial_change(new_value, old_value){
|
||||
if(!isFinite(new_value)){
|
||||
this.config.value = old_value
|
||||
this.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function cmd_emisor_agregar_cuenta_click(){
|
||||
var form = $$('form_emisor_cuenta_banco')
|
||||
|
||||
if (!form.validate()){
|
||||
msg = 'Valores inválidos'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
var values = form.getValues()
|
||||
|
||||
var si = parseFloat(values.emisor_cuenta_saldo_inicial.replace('$', '').replace(',', ''))
|
||||
var cuenta = {
|
||||
de_emisor: true,
|
||||
activa: true,
|
||||
nombre: values.emisor_cuenta_nombre.trim(),
|
||||
banco: values.emisor_banco,
|
||||
fecha_apertura: values.emisor_cuenta_fecha,
|
||||
cuenta: values.emisor_cuenta.trim(),
|
||||
clabe: values.emisor_clabe.trim(),
|
||||
moneda: values.emisor_cuenta_moneda,
|
||||
saldo_inicial: si
|
||||
}
|
||||
|
||||
if(!cuenta.nombre){
|
||||
msg = 'El nombre de la cuenta es requerido'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
if(!cuenta.cuenta){
|
||||
msg = 'La cuenta es requerida'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
if(!cuenta.cuenta.is_number()){
|
||||
msg = 'Solo digitos en la cuenta'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
if(cuenta.cuenta.length < 9){
|
||||
msg = 'Longitud incorrecta de la cuenta'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
if(!cuenta.clabe){
|
||||
msg = 'La CLABE es requerida'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
if(cuenta.clabe.length != 18){
|
||||
msg = 'La CLABE debe ser de 18 digitos'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
if(!cuenta.clabe.is_number()){
|
||||
msg = 'Solo digitos en la CLABE'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
//~ if(!isFinite(cuenta.saldo_inicial)){
|
||||
if(cuenta.saldo_inicial <= 0){
|
||||
msg = 'El saldo inicial no puede ser negativo o cero'
|
||||
msg_error(msg)
|
||||
return
|
||||
}
|
||||
|
||||
cuenta.saldo = cuenta.saldo_inicial
|
||||
|
||||
webix.ajax().post('/cuentasbanco', cuenta, {
|
||||
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){
|
||||
$$('grid_emisor_cuentas_banco').add(values.row)
|
||||
}else{
|
||||
msg_error(values.msg)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,11 @@ Number.prototype.round = function(decimals){
|
|||
}
|
||||
|
||||
|
||||
String.prototype.is_number = function(){
|
||||
return /^\d+$/.test(this)
|
||||
}
|
||||
|
||||
|
||||
webix.protoUI({
|
||||
$cssName: "text",
|
||||
name: "currency",
|
||||
|
|
|
@ -132,6 +132,78 @@ var emisor_certificado = [
|
|||
]
|
||||
|
||||
|
||||
var grid_emisor_cuentas_banco_cols = [
|
||||
{id: 'id', header: 'ID', hidden: true},
|
||||
{id: 'activa', header: 'Activa', template: '{common.checkbox()}',
|
||||
editor: 'checkbox', width: 50},
|
||||
{id: 'nombre', header: 'Nombre', fillspace: 1},
|
||||
{id: 'banco', header: 'Banco', fillspace: 1},
|
||||
{id: 'fecha_apertura', header: 'Fecha de Apertura', fillspace: 1},
|
||||
{id: 'cuenta', header: 'Cuenta', fillspace: 1},
|
||||
{id: 'clabe', header: 'CLABE', fillspace: 1},
|
||||
{id: 'moneda', header: 'Moneda', fillspace: 1},
|
||||
{id: 'saldo', header: 'Saldo', width: 150, format: webix.i18n.priceFormat,
|
||||
css: 'right'},
|
||||
]
|
||||
|
||||
|
||||
var grid_emisor_cuentas_banco = {
|
||||
view: 'datatable',
|
||||
id: 'grid_emisor_cuentas_banco',
|
||||
select: 'row',
|
||||
adjust: true,
|
||||
autoheight: true,
|
||||
headermenu: true,
|
||||
columns: grid_emisor_cuentas_banco_cols
|
||||
}
|
||||
|
||||
|
||||
var emisor_cuentas_banco = [
|
||||
{template: 'Agregar cuenta de banco', type: 'section'},
|
||||
{view: 'form', id: 'form_emisor_cuenta_banco', rows: [
|
||||
{cols: [
|
||||
{view: 'text', id: 'emisor_cuenta_nombre', name: 'emisor_cuenta_nombre',
|
||||
label: 'Nombre: ', required: true}, {}]},
|
||||
{cols: [
|
||||
{view: 'richselect', id: 'lst_emisor_banco', name: 'emisor_banco',
|
||||
label: 'Banco: ', required: true, options: []},
|
||||
{view: 'datepicker', id: 'emisor_cuenta_fecha', format: '%d-%M-%Y',
|
||||
name: 'emisor_cuenta_fecha', label: 'Fecha de apertura: ',
|
||||
required: true},
|
||||
]},
|
||||
{cols: [
|
||||
{view: 'text', id: 'emisor_cuenta', name: 'emisor_cuenta',
|
||||
label: 'Cuenta: ', required: true},
|
||||
{view: 'text', id: 'emisor_clabe', name: 'emisor_clabe',
|
||||
label: 'CLABE: ', required: true},
|
||||
]},
|
||||
{cols: [
|
||||
{view: 'richselect', id: 'lst_emisor_cuenta_moneda',
|
||||
name: 'emisor_cuenta_moneda', label: 'Moneda: ', required: true,
|
||||
options: []},
|
||||
{view: 'currency', type: 'text', id: 'emisor_cuenta_saldo_inicial',
|
||||
name: 'emisor_cuenta_saldo_inicial', label: 'Saldo inicial',
|
||||
required: true, invalidMessage: 'Captura un valor númerico',
|
||||
inputAlign: 'right', value: 0},
|
||||
]},
|
||||
{minHeight: 10},
|
||||
{cols: [{}, {view: 'button', id: 'cmd_emisor_agregar_cuenta',
|
||||
label: 'Agregar cuenta'}, {}]},
|
||||
|
||||
],
|
||||
|
||||
rules: {
|
||||
emisor_cuenta_saldo_inicial: function(value){return value.trim() != "$";},
|
||||
}
|
||||
|
||||
},
|
||||
{minHeight: 20},
|
||||
{template: 'Cuentas de banco existentes', type: 'section'},
|
||||
grid_emisor_cuentas_banco,
|
||||
{minHeight: 50},
|
||||
]
|
||||
|
||||
|
||||
var controls_emisor = [
|
||||
{
|
||||
view: 'tabview',
|
||||
|
@ -139,13 +211,14 @@ var controls_emisor = [
|
|||
tabbar: {options: [
|
||||
'Datos Fiscales',
|
||||
'Otros Datos',
|
||||
'Certificado']},
|
||||
'Certificado',
|
||||
'Cuentas de Banco']},
|
||||
animate: true,
|
||||
cells: [
|
||||
{id: 'Datos Fiscales', rows: emisor_datos_fiscales},
|
||||
{id: 'Otros Datos', rows: emisor_otros_datos},
|
||||
{id: 'Certificado', rows: emisor_certificado},
|
||||
{},
|
||||
{id: 'Cuentas de Banco', rows: emisor_cuentas_banco}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -580,7 +653,6 @@ var ui_admin = {
|
|||
{view: 'toolbar', padding: 3, elements: [
|
||||
{view: 'button', type: 'icon', icon: 'bars',
|
||||
width: 37, align: 'left', css: 'app_button', click: function(){
|
||||
//~ $$('$sidebar1').toggle()
|
||||
$$('sidebar_admin').toggle()
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue