forked from elmau/empresa-libre
Mostrar estado de cuenta
This commit is contained in:
parent
c8f7554ff6
commit
3cf46e69ae
|
@ -267,6 +267,23 @@ class AppCuentasBanco(object):
|
|||
resp.status = falcon.HTTP_200
|
||||
|
||||
|
||||
class AppMovimientosBanco(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_movimientosbanco(values)
|
||||
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,8 @@ from models.db import StorageEngine
|
|||
from controllers.main import (
|
||||
AppLogin, AppLogout, AppAdmin, AppEmisor, AppConfig,
|
||||
AppMain, AppValues, AppPartners, AppProducts, AppInvoices, AppFolios,
|
||||
AppDocumentos, AppFiles, AppPreInvoices, AppCuentasBanco
|
||||
AppDocumentos, AppFiles, AppPreInvoices, AppCuentasBanco,
|
||||
AppMovimientosBanco
|
||||
)
|
||||
from settings import DEBUG
|
||||
|
||||
|
@ -46,6 +47,7 @@ api.add_route('/products', AppProducts(db))
|
|||
api.add_route('/invoices', AppInvoices(db))
|
||||
api.add_route('/preinvoices', AppPreInvoices(db))
|
||||
api.add_route('/cuentasbanco', AppCuentasBanco(db))
|
||||
api.add_route('/movbanco', AppMovimientosBanco(db))
|
||||
|
||||
|
||||
if DEBUG:
|
||||
|
|
|
@ -58,6 +58,9 @@ class StorageEngine(object):
|
|||
years2 = main.PreFacturas.filter_years()
|
||||
return [years1, years2]
|
||||
|
||||
def _get_cuentayears(self, values):
|
||||
return main.CuentasBanco.get_years()
|
||||
|
||||
def _get_cert(self, values):
|
||||
return main.Certificado.get_data()
|
||||
|
||||
|
@ -242,3 +245,6 @@ class StorageEngine(object):
|
|||
|
||||
return data, file_name, content_type
|
||||
|
||||
def get_movimientosbanco(self, values):
|
||||
return main.MovimientosBanco.get_(values)
|
||||
|
||||
|
|
|
@ -914,18 +914,40 @@ class CuentasBanco(BaseModel):
|
|||
def __str__(self):
|
||||
return '{} ({})'.format(self.banco.name, self.cuenta[-4:])
|
||||
|
||||
@classmethod
|
||||
def get_years(cls):
|
||||
data = [{'id': -1, 'value': 'Todos'}]
|
||||
year1 = (CuentasBanco
|
||||
.select(fn.Min(CuentasBanco.fecha_apertura.year))
|
||||
.where(CuentasBanco.de_emisor==True, CuentasBanco.activa==True)
|
||||
.group_by(CuentasBanco.fecha_apertura.year)
|
||||
.order_by(CuentasBanco.fecha_apertura.year)
|
||||
.scalar()
|
||||
)
|
||||
|
||||
if year1:
|
||||
year2 = util.now().year + 1
|
||||
data += [{'id': y, 'value': y} for y in range(int(year1), year2)]
|
||||
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
def get_(cls, values):
|
||||
if values['tipo'] == '1':
|
||||
rows = (CuentasBanco
|
||||
.select(
|
||||
CuentasBanco.id,
|
||||
str(CuentasBanco))
|
||||
.where(CuentasBanco.de_emisor==True)
|
||||
.dicts()
|
||||
.select()
|
||||
.where(CuentasBanco.de_emisor==True, CuentasBanco.activa==True)
|
||||
)
|
||||
print (tuple(rows))
|
||||
return {'ok': True, 'rows': tuple(rows)}
|
||||
first = rows[0]
|
||||
rows = [{'id': r.id, 'value': '{} ({})'.format(
|
||||
r.banco.name, r.cuenta[-4:])} for r in rows]
|
||||
data = {
|
||||
'ok': True,
|
||||
'rows': tuple(rows),
|
||||
'moneda': first.moneda.name,
|
||||
'saldo': first.saldo,
|
||||
}
|
||||
return data
|
||||
|
||||
return
|
||||
|
||||
|
@ -983,7 +1005,7 @@ class CuentasBanco(BaseModel):
|
|||
return data
|
||||
|
||||
|
||||
class BancoMovimientos(BaseModel):
|
||||
class MovimientosBanco(BaseModel):
|
||||
cuenta = ForeignKeyField(CuentasBanco)
|
||||
fecha = DateTimeField(default=util.now, formats=['%Y-%m-%d %H:%M:%S'])
|
||||
movimiento = IntegerField(default=0)
|
||||
|
@ -1015,9 +1037,45 @@ class BancoMovimientos(BaseModel):
|
|||
(('cuenta', 'movimiento'), True),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_(cls, values):
|
||||
cuenta = int(values['cuenta'])
|
||||
if 'fechas' in values:
|
||||
rango = values['fechas']
|
||||
fd = (MovimientosBanco.fecha.between(
|
||||
util.get_date(rango['start']),
|
||||
util.get_date(rango['end'], True)))
|
||||
filtros = (fd & MovimientosBanco.cuenta.id==cuenta)
|
||||
else:
|
||||
year = int(values['year'])
|
||||
mes = int(values['mes'])
|
||||
if year == -1:
|
||||
fy = (MovimientosBanco.fecha.year > 0)
|
||||
else:
|
||||
fy = (MovimientosBanco.fecha.year == year)
|
||||
if mes == -1:
|
||||
fm = (MovimientosBanco.fecha.month > 0)
|
||||
else:
|
||||
fm = (MovimientosBanco.fecha.month == mes)
|
||||
filtros = (fy & fm & MovimientosBanco.cuenta.id==cuenta)
|
||||
|
||||
rows = tuple(MovimientosBanco
|
||||
.select(
|
||||
MovimientosBanco.id,
|
||||
MovimientosBanco.fecha,
|
||||
MovimientosBanco.numero_operacion,
|
||||
MovimientosBanco.descripcion,
|
||||
MovimientosBanco.retiro,
|
||||
MovimientosBanco.deposito,
|
||||
MovimientosBanco.saldo)
|
||||
.where(filtros)
|
||||
.dicts()
|
||||
)
|
||||
return {'ok': True, 'rows': rows}
|
||||
|
||||
|
||||
class CfdiPagos(BaseModel):
|
||||
movimiento = ForeignKeyField(BancoMovimientos)
|
||||
movimiento = ForeignKeyField(MovimientosBanco)
|
||||
xml = TextField(default='')
|
||||
uuid = UUIDField(null=True)
|
||||
estatus = TextField(default='Guardado')
|
||||
|
@ -2911,7 +2969,7 @@ def _crear_tablas(rfc):
|
|||
PreFacturasRelacionadas,
|
||||
SATAduanas, SATFormaPago, SATImpuestos, SATMonedas, SATRegimenes,
|
||||
SATTipoRelacion, SATUnidades, SATUsoCfdi, SATBancos,
|
||||
Socios, Tags, Usuarios, CuentasBanco, TipoCambio, BancoMovimientos,
|
||||
Socios, Tags, Usuarios, CuentasBanco, TipoCambio, MovimientosBanco,
|
||||
CfdiPagos, CfdiPagosFacturas,
|
||||
Emisor.regimenes.get_through_model(),
|
||||
Socios.tags.get_through_model(),
|
||||
|
|
|
@ -5,11 +5,39 @@ var bancos_controllers = {
|
|||
$$('lst_cuentas_banco').attachEvent('onChange', lst_cuentas_banco_change)
|
||||
$$('cmd_agregar_retiro').attachEvent('onItemClick', cmd_agregar_retiro_click)
|
||||
$$('cmd_agregar_deposito').attachEvent('onItemClick', cmd_agregar_deposito_click)
|
||||
set_year_month()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function set_year_month(){
|
||||
var d = new Date()
|
||||
var y = $$('filtro_cuenta_year')
|
||||
var m = $$('filtro_cuenta_mes')
|
||||
|
||||
webix.ajax().get('/values/cuentayears', {
|
||||
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()
|
||||
y.getList().parse(values)
|
||||
y.blockEvent()
|
||||
m.blockEvent()
|
||||
y.setValue(d.getFullYear())
|
||||
m.setValue(d.getMonth() + 1)
|
||||
y.unblockEvent()
|
||||
m.unblockEvent()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_cuentas_banco(){
|
||||
var list = $$('lst_cuentas_banco')
|
||||
|
||||
webix.ajax().get('/cuentasbanco', {'tipo': 1}, {
|
||||
error:function(text, data, XmlHttpRequest){
|
||||
msg = 'Ocurrio un error, consulta a soporte técnico'
|
||||
|
@ -18,8 +46,45 @@ function get_cuentas_banco(){
|
|||
success:function(text, data, XmlHttpRequest){
|
||||
var values = data.json()
|
||||
if(values.ok){
|
||||
$$('lst_cuentas_banco').getList().parse(values.rows)
|
||||
$$('lst_cuentas_banco').setValue(values.rows[0].id)
|
||||
list.getList().parse(values.rows)
|
||||
list.blockEvent()
|
||||
list.setValue(values.rows[0].id)
|
||||
list.unblockEvent()
|
||||
$$('txt_cuenta_moneda').setValue(values.moneda)
|
||||
$$('txt_cuenta_saldo').setValue(values.saldo)
|
||||
get_estado_cuenta()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function get_estado_cuenta(rango){
|
||||
if(rango == undefined){
|
||||
var filtro = {
|
||||
cuenta: $$('lst_cuentas_banco').getValue(),
|
||||
year: $$('filtro_cuenta_year').getValue(),
|
||||
mes: $$('filtro_cuenta_mes').getValue(),
|
||||
}
|
||||
}else{
|
||||
var filtro = {
|
||||
cuenta: $$('lst_cuentas_banco').getValue(),
|
||||
fechas: rango,
|
||||
}
|
||||
}
|
||||
|
||||
var grid = $$('grid_cuentabanco')
|
||||
|
||||
webix.ajax().get('/movbanco', filtro, {
|
||||
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()
|
||||
grid.clearAll()
|
||||
if (values.ok){
|
||||
grid.parse(values.rows, 'json')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -164,13 +164,9 @@ var emisor_cuentas_banco = [
|
|||
{view: 'form', id: 'form_emisor_cuenta_banco', rows: [
|
||||
{cols: [
|
||||
{view: 'text', id: 'emisor_cuenta_nombre', name: 'emisor_cuenta_nombre',
|
||||
label: 'Nombre: ', required: true}, {}]},
|
||||
{cols: [
|
||||
label: 'Nombre: ', required: true},
|
||||
{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',
|
||||
|
@ -187,10 +183,17 @@ var emisor_cuentas_banco = [
|
|||
required: true, invalidMessage: 'Captura un valor númerico',
|
||||
inputAlign: 'right', value: ''},
|
||||
]},
|
||||
{cols: [
|
||||
{view: 'datepicker', id: 'emisor_cuenta_fecha', format: '%d-%M-%Y',
|
||||
name: 'emisor_cuenta_fecha', label: 'Fecha de apertura: ',
|
||||
required: true},
|
||||
{view: 'datepicker', id: 'emisor_fecha_saldo', format: '%d-%M-%Y',
|
||||
name: 'emisor_fecha_saldo', label: 'Fecha este depósito: ',
|
||||
required: true},
|
||||
]},
|
||||
{minHeight: 10},
|
||||
{cols: [{}, {view: 'button', id: 'cmd_emisor_agregar_cuenta',
|
||||
label: 'Agregar cuenta'}, {}]},
|
||||
|
||||
],
|
||||
|
||||
rules: {
|
||||
|
|
Loading…
Reference in New Issue