Agregar retiros de banco
This commit is contained in:
parent
74ac8b9295
commit
2083a19db2
|
@ -287,7 +287,7 @@ class AppMovimientosBanco(object):
|
|||
|
||||
def on_post(self, req, resp):
|
||||
values = req.params
|
||||
req.context['result'] = self._db.cuentasbanco(values)
|
||||
req.context['result'] = self._db.add_movbanco(values)
|
||||
resp.status = falcon.HTTP_200
|
||||
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ from dateutil import parser
|
|||
from .helper import CaseInsensitiveDict, NumLet, SendMail, TemplateInvoice
|
||||
from settings import DEBUG, log, template_lookup, COMPANIES, DB_SAT, \
|
||||
PATH_XSLT, PATH_XSLTPROC, PATH_OPENSSL, PATH_TEMPLATES, PATH_MEDIA, PRE, \
|
||||
PATH_XMLSEC, TEMPLATE_CANCEL, DEFAULT_SAT_PRODUCTO
|
||||
PATH_XMLSEC, TEMPLATE_CANCEL, DEFAULT_SAT_PRODUCTO, DECIMALES
|
||||
|
||||
|
||||
#~ def _get_hash(password):
|
||||
|
@ -1270,6 +1270,10 @@ def get_bool(value):
|
|||
return False
|
||||
|
||||
|
||||
def get_float(value):
|
||||
return round(float(value), DECIMALES)
|
||||
|
||||
|
||||
class ImportFacturaLibre(object):
|
||||
|
||||
def __init__(self, path, rfc):
|
||||
|
|
|
@ -228,6 +228,9 @@ class StorageEngine(object):
|
|||
def cuentasbanco(self, values):
|
||||
return main.CuentasBanco.add(values)
|
||||
|
||||
def add_movbanco(self, values):
|
||||
return main.MovimientosBanco.add(values)
|
||||
|
||||
def get_cuentasbanco(self, values):
|
||||
return main.CuentasBanco.get_(values)
|
||||
|
||||
|
|
|
@ -954,6 +954,12 @@ class CuentasBanco(BaseModel):
|
|||
def __str__(self):
|
||||
return '{} ({})'.format(self.banco.name, self.cuenta[-4:])
|
||||
|
||||
@classmethod
|
||||
def actualizar_saldo(cls, id, saldo):
|
||||
fields = {'saldo': saldo}
|
||||
q = CuentasBanco.update(**fields).where(CuentasBanco.id==id)
|
||||
return bool(q.execute())
|
||||
|
||||
@classmethod
|
||||
def remove(cls, id):
|
||||
try:
|
||||
|
@ -1049,7 +1055,6 @@ class CuentasBanco(BaseModel):
|
|||
nuevo_mov= {
|
||||
'cuenta': obj.id,
|
||||
'fecha': fecha_deposito,
|
||||
'movimiento': 1,
|
||||
'descripcion': 'Saldo inicial',
|
||||
'forma_pago': SATFormaPago.get_by_key('99'),
|
||||
'deposito': values['saldo'],
|
||||
|
@ -1080,7 +1085,6 @@ class CuentasBanco(BaseModel):
|
|||
class MovimientosBanco(BaseModel):
|
||||
cuenta = ForeignKeyField(CuentasBanco)
|
||||
fecha = DateTimeField(default=util.now, formats=['%Y-%m-%d %H:%M:%S'])
|
||||
movimiento = IntegerField(default=0)
|
||||
descripcion = TextField(default='')
|
||||
forma_pago = ForeignKeyField(SATFormaPago)
|
||||
retiro = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
||||
|
@ -1105,12 +1109,28 @@ class MovimientosBanco(BaseModel):
|
|||
|
||||
class Meta:
|
||||
order_by = ('fecha',)
|
||||
indexes = (
|
||||
(('cuenta', 'movimiento'), True),
|
||||
|
||||
def _ultimo_saldo(self, cuenta):
|
||||
query = (MovimientosBanco
|
||||
.select()
|
||||
.where(MovimientosBanco.cuenta==cuenta)[-1]
|
||||
)
|
||||
return round(float(query.saldo), DECIMALES)
|
||||
|
||||
@classmethod
|
||||
def add(cls, values):
|
||||
#~ print(values)
|
||||
if not 'saldo' in values:
|
||||
hora = values.pop('hora')
|
||||
values['fecha'] = '{}T{}'.format(values['fecha'][:10], hora)
|
||||
values['cuenta'] = int(values['cuenta'])
|
||||
values['retiro'] = util.get_float(values['retiro'])
|
||||
values['deposito'] = util.get_float(values['deposito'])
|
||||
values['forma_pago'] = int(values['forma_pago'])
|
||||
|
||||
ultimo_saldo = cls._ultimo_saldo(cls, values['cuenta'])
|
||||
values['saldo'] = \
|
||||
ultimo_saldo - values['retiro'] + values['deposito']
|
||||
with database_proxy.transaction():
|
||||
try:
|
||||
obj = MovimientosBanco.create(**values)
|
||||
|
@ -1118,7 +1138,9 @@ class MovimientosBanco(BaseModel):
|
|||
msg = 'Este movimiento ya existe'
|
||||
return {'ok': False, 'msg': msg}
|
||||
|
||||
return {'ok': True}
|
||||
CuentasBanco.actualizar_saldo(values['cuenta'], obj.saldo)
|
||||
|
||||
return {'ok': True, 'saldo': obj.saldo}
|
||||
|
||||
@classmethod
|
||||
def con(cls, id):
|
||||
|
@ -1173,6 +1195,8 @@ class MovimientosBanco(BaseModel):
|
|||
|
||||
class CfdiPagos(BaseModel):
|
||||
movimiento = ForeignKeyField(MovimientosBanco)
|
||||
fecha = DateTimeField(default=util.now, formats=['%Y-%m-%d %H:%M:%S'])
|
||||
fecha_timbrado = DateTimeField(null=True)
|
||||
xml = TextField(default='')
|
||||
uuid = UUIDField(null=True)
|
||||
estatus = TextField(default='Guardado')
|
||||
|
|
|
@ -5,6 +5,8 @@ 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)
|
||||
$$('cmd_guardar_retiro').attachEvent('onItemClick', cmd_guardar_retiro_click)
|
||||
$$('txt_retiro_importe').attachEvent('onChange', txt_retiro_importe_change)
|
||||
set_year_month()
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +33,6 @@ function set_year_month(){
|
|||
m.unblockEvent()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,11 +97,140 @@ function lst_cuentas_banco_change(nv, ov){
|
|||
}
|
||||
|
||||
|
||||
function get_retiro_forma_pago(){
|
||||
webix.ajax().get('/values/formapago', {}, function(text, data){
|
||||
var values = data.json()
|
||||
$$('lst_retiro_forma_pago').getList().parse(values)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function cmd_agregar_retiro_click(){
|
||||
show('Retiro')
|
||||
get_retiro_forma_pago()
|
||||
$$('multi_bancos').setValue('banco_retiro')
|
||||
}
|
||||
|
||||
|
||||
function cmd_agregar_deposito_click(){
|
||||
show('Depósito')
|
||||
showvar('Depósito')
|
||||
}
|
||||
|
||||
|
||||
function validate_retiro(values){
|
||||
var importe = values.retiro_importe.replace('$', '').replace(',', '').trim()
|
||||
|
||||
if(!importe){
|
||||
msg = 'El importe es requerido'
|
||||
msg_error(msg)
|
||||
return false
|
||||
}
|
||||
importe = parseFloat(importe).round(2)
|
||||
if(importe <= 0){
|
||||
msg = 'El importe debe ser mayor a cero'
|
||||
msg_error(msg)
|
||||
return false
|
||||
}
|
||||
|
||||
if(!values.retiro_descripcion.trim()){
|
||||
msg = 'La descripción es requerida'
|
||||
msg_error(msg)
|
||||
return false
|
||||
}
|
||||
|
||||
var horas = $$('time_retiro').getText().split(':')
|
||||
var seg = parseInt(horas[2])
|
||||
var min = parseInt(horas[1])
|
||||
var horas = parseInt(horas[0])
|
||||
|
||||
if(horas > 23){
|
||||
focus('time_retiro')
|
||||
msg = 'Hora inválida'
|
||||
msg_error(msg)
|
||||
return false
|
||||
}
|
||||
if(min > 59){
|
||||
focus('time_retiro')
|
||||
msg = 'Hora inválida'
|
||||
msg_error(msg)
|
||||
return false
|
||||
}
|
||||
if(seg > 59){
|
||||
focus('time_retiro')
|
||||
msg = 'Hora inválida'
|
||||
msg_error(msg)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
function guardar_retiro(values){
|
||||
var form = $$('form_banco_retiro')
|
||||
|
||||
var importe = get_float(values.retiro_importe)
|
||||
var data = new Object()
|
||||
data['cuenta'] = $$('lst_cuentas_banco').getValue()
|
||||
data['fecha'] = values.retiro_fecha
|
||||
data['hora'] = $$('time_retiro').getText()
|
||||
data['numero_operacion'] = values.retiro_referencia.trim()
|
||||
data['forma_pago'] = $$('lst_retiro_forma_pago').getValue()
|
||||
data['retiro'] = importe
|
||||
data['deposito'] = 0.0
|
||||
data['descripcion'] = values.retiro_descripcion
|
||||
|
||||
webix.ajax().post('/movbanco', 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){
|
||||
$$('txt_cuenta_saldo').setValue(values.saldo)
|
||||
get_estado_cuenta()
|
||||
$$('multi_bancos').setValue('banco_home')
|
||||
form.setValues({})
|
||||
}else{
|
||||
msg_error(values.msg)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function cmd_guardar_retiro_click(){
|
||||
var form = $$('form_banco_retiro')
|
||||
|
||||
if(!form.validate()) {
|
||||
msg_error('Valores inválidos')
|
||||
return
|
||||
}
|
||||
|
||||
var values = form.getValues()
|
||||
if(!validate_retiro(values)){
|
||||
return
|
||||
}
|
||||
|
||||
msg = 'Todos los datos son correctos.<br><br>¿Deseas agregar este retiro?'
|
||||
webix.confirm({
|
||||
title: 'Guardar Retiro',
|
||||
ok: 'Si',
|
||||
cancel: 'No',
|
||||
type: 'confirm-error',
|
||||
text: msg,
|
||||
callback:function(result){
|
||||
if(result){
|
||||
guardar_retiro(values)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function txt_retiro_importe_change(new_value, old_value){
|
||||
if(!isFinite(new_value)){
|
||||
this.config.value = old_value
|
||||
this.refresh()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ function multi_change(prevID, nextID){
|
|||
|
||||
if(nextID == 'app_bancos'){
|
||||
active = $$('multi_bancos').getActiveId()
|
||||
if(active == 'bancos_home'){
|
||||
if(active == 'banco_home'){
|
||||
get_cuentas_banco()
|
||||
}
|
||||
return
|
||||
|
|
|
@ -33,6 +33,11 @@ var months = [
|
|||
]
|
||||
|
||||
|
||||
function focus(name){
|
||||
webix.UIManager.setFocus(name)
|
||||
}
|
||||
|
||||
|
||||
function showvar(values){
|
||||
webix.message(JSON.stringify(values, null, 2))
|
||||
}
|
||||
|
@ -70,6 +75,11 @@ String.prototype.is_number = function(){
|
|||
}
|
||||
|
||||
|
||||
function get_float(value){
|
||||
return parseFloat(value.replace('$', '').replace(',', '').trim()).round(2)
|
||||
}
|
||||
|
||||
|
||||
webix.protoUI({
|
||||
$cssName: "text",
|
||||
name: "currency",
|
||||
|
|
|
@ -51,16 +51,76 @@ var grid_cuentabanco = {
|
|||
}
|
||||
|
||||
|
||||
var toolbar_banco_retiro = [
|
||||
{view: 'label', label: 'Agregar retiro de banco'},
|
||||
{},
|
||||
{view: 'icon', click: '$$("multi_bancos").setValue("banco_home")',
|
||||
icon: 'times-circle'}
|
||||
]
|
||||
|
||||
|
||||
var body_banco_retiro = [
|
||||
|
||||
]
|
||||
|
||||
var controls_banco_retiro = [
|
||||
{view: 'toolbar', elements: toolbar_banco_retiro},
|
||||
{cols: [
|
||||
{view: 'datepicker', id: 'date_retiro', name: 'retiro_fecha',
|
||||
label: 'Fecha', format: '%d-%M-%Y', labelAlign: 'right',
|
||||
required: true, invalidMessage: 'Selecciona una fecha',
|
||||
labelWidth: 125},
|
||||
{view: 'search', id: 'time_retiro', name: 'retiro_hora',
|
||||
label: 'Hora', icon: 'clock-o', labelAlign: 'right',
|
||||
pattern:{mask: '##:##:##', allow:/[0-9]/g}, required: true,
|
||||
invalidMessage: 'Captura una hora'},
|
||||
{view: 'text', id: 'retiro_referencia', name: 'retiro_referencia',
|
||||
label: 'Referencia', labelAlign: 'right'},
|
||||
]},
|
||||
{cols: [
|
||||
{view: 'richselect', id: 'lst_retiro_forma_pago',
|
||||
name: 'retiro_forma_pago', label: 'Forma de Pago', required: true,
|
||||
options: [], labelWidth: 125, labelAlign: 'right'},
|
||||
{view: 'currency', type: 'text', id: 'txt_retiro_importe',
|
||||
name: 'retiro_importe', label: 'Importe', labelAlign: 'right',
|
||||
required: true, invalidMessage: 'Captura un valor númerico',
|
||||
inputAlign: 'right', value: ''}
|
||||
]},
|
||||
{cols: [
|
||||
{view: 'text', id: 'retiro_descripcion', name: 'retiro_descripcion',
|
||||
label: 'Descripción', labelAlign: 'right', required: true,
|
||||
labelWidth: 125},
|
||||
]},
|
||||
{cols: [{},
|
||||
{view: 'button', id: 'cmd_guardar_retiro', label: 'Guardar Retiro',
|
||||
type: 'iconButton', autowidth: true, icon: 'minus'},
|
||||
{}]},
|
||||
]
|
||||
|
||||
|
||||
var form_banco_retiro = {
|
||||
type: 'space',
|
||||
responsive: true,
|
||||
cols: [{
|
||||
view: 'form',
|
||||
id: 'form_banco_retiro',
|
||||
complexData: true,
|
||||
scroll: true,
|
||||
elements: controls_banco_retiro,
|
||||
}]
|
||||
}
|
||||
|
||||
|
||||
var multi_bancos = {
|
||||
id: 'multi_bancos',
|
||||
animate: true,
|
||||
cells:[
|
||||
{id: 'bancos_home', rows:[
|
||||
{id: 'banco_home', rows:[
|
||||
{view: 'toolbar', elements: toolbar_banco},
|
||||
{view: 'toolbar', elements: toolbar_filtro_cuenta},
|
||||
grid_cuentabanco,
|
||||
]}
|
||||
//~ {id: 'partners_new', rows:[form_partner]}
|
||||
]},
|
||||
{id: 'banco_retiro', rows: [form_banco_retiro]}
|
||||
],
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue