diff --git a/gulpfile.js b/gulpfile.js index a79cb57..44ddfe3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -46,6 +46,7 @@ gulp.task('uglify', ['templates'], function() { replace('"ngRoute","ui.bootstrap","focaModal","focaModalFactura","focaBusquedaCliente",'+ '"focaDirectivas","focaModalMoneda","focaModalCotizacion"', ''), gulp.dest(paths.dist) + ] ); }); diff --git a/src/js/controller.js b/src/js/controller.js index d1923a1..9f89c17 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -6,7 +6,9 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', '$filter', 'focaCrearCobranzaService', 'focaModalService', - function($scope, $uibModal, $location, $filter, focaCrearCobranzaService, focaModalService) + '$cookies', + function($scope, $uibModal, $location, $filter, focaCrearCobranzaService, focaModalService, + $cookies) { $scope.botonera = [ {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, @@ -27,46 +29,30 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', minDate: new Date(2010, 0, 1) }; - $scope.cobranza = { - fecha: new Date() - }; - $scope.cabecera = []; $scope.showCabecera = true; - $scope.now = new Date(); + $scope.cobranza = {}; + + $scope.fecha = new Date(); $scope.puntoVenta = '0000'; $scope.comprobante = '00000000'; $scope.facturaTabla = []; $scope.cobrosTabla = []; - var monedaPorDefecto; - //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' - focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { - monedaPorDefecto = res.data[0]; - addCabecera('Moneda:', monedaPorDefecto.DETALLE); - addCabecera('Fecha cotizacion:', - new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); - addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].VENDEDOR); - $scope.cobranza.moneda = monedaPorDefecto; - $scope.cobranza.cotizacion = monedaPorDefecto.cotizaciones[0]; + focaCrearCobranzaService.getUsuario($cookies.get('idUsuario')).then(function(data) { + $scope.usuario = data.data; }); - focaCrearCobranzaService.getNumeroRecibo().then( - function(res) { - $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); - $scope.comprobante = $scope.rellenar(res.data.numeroRecibo, 8); - }, - function(err) { - focaModalService.alert('La terminal no esta configurada correctamente'); - console.info(err); - } - ); $scope.crearCobranza = function() { if(!$scope.cobranza.cliente) { focaModalService.alert('Ingrese Cliente'); return; } + if(!$scope.cobranza.cobrador) { + focaModalService.alert('Ingrese Cobrador'); + return; + } if($scope.facturaTabla.length < 1) { focaModalService.alert('Ingrese al menos una factura'); return; @@ -76,10 +62,163 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', $scope.cobranza.moneda.SIMBOLO + '0,00'); return; } - //TODO: Guarda cobranza - // var date = new Date(); - // var cobranza = { - // }; + var cobranza = {}; + var cheques = []; + var cuerpos = []; + + for (var i = 0; i < $scope.facturaTabla.length; i++) { + var cuerpoFactura = { + CYV: 'V', + TIP: 'C', + TCO: 'RC', + PVE: $scope.puntoVenta, + NCO: $scope.comprobante, + LOP: 'L', + TIL: $scope.facturaTabla[i].TCO, + COM: $scope.facturaTabla[i].numeroFactura, + FEC: $scope.fecha.toISOString().slice(0, 19).replace('T', ' '), + IMP: $scope.facturaTabla[i].IPA, + RES: 0,//caja de tesorería + SUBM: 0 + }; + cuerpos.push(cuerpoFactura); + } + + for (var j = 0; j < $scope.cobrosTabla.length; j++) { + + var efectivo = $scope.cobrosTabla[j].tipo === 'Efectivo' ? true : false; + + var cuerpoCobros = { + CYV: 'V', + TIP: 'C', + TCO: 'RC', + PVE: $scope.puntoVenta, + NCO: $scope.comprobante, + LOP: 'P', + TIL: 'EF', + COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : 'ch(' + + $scope.cobrosTabla[j].numero + ')' + $scope.cobrosTabla[j].banco.desbco, + FEC: efectivo ? + $scope.cobrosTabla[j].fecha + .toISOString().slice(0, 19).replace('T', ' ') : + $scope.cobrosTabla[j].fechaPresentacion + .toISOString().slice(0, 19).replace('T', ' '), + IMP: $scope.cobrosTabla[j].importe, + RES: 0,//caja de tesorería + SUBM: 0 + }; + cuerpos.push(cuerpoCobros); + + if(!efectivo) { + var cheque = { + BCO: $scope.cobrosTabla[j].banco.ID, + NUM: $scope.comprobante, + FEP: $scope.cobrosTabla[j].fechaPresentacion + .toISOString().slice(0, 19).replace('T', ' '), + FEE: $scope.cobrosTabla[j].fechaEmision + .toISOString().slice(0, 19).replace('T', ' '), + LUG: $scope.cobrosTabla[j].localidad.NOMBRE, + IMP: $scope.cobrosTabla[j].importe, + LIB: $scope.cobrosTabla[j].librador, + EST: 'C',//'D' depositado, 'E' entregado, 'C' en cartera + PCI: $scope.cobrosTabla[j].provincia.ID, + LPLA: 0, + PLA: 0, + VEN: $scope.usuario.CodVen,//Id vendedor + CCLIE: $scope.cobranza.cliente.COD,//Id cliente + REN: 0, + PVEC: $scope.puntoVenta, + NCOC: $scope.comprobante, + OBSE: $scope.cobrosTabla[j].observaciones, + LUV: 0, + ORI: 've', + FER: '', + BIMP: 0, + COMP: 'C ' +'RC ' + $scope.puntoVenta + '-' + $scope.comprobante, + VAL_E: '',//Cuando egresa por ingresos y egresos en el numero de egreso + VAL_I: '',//Cuando Ingresa por ingresos y egresos en el numero ingreso + REC_CAJ: 'D', + TIPO_C: 0,//?? + SALDO_CAJ: 'S', + FECHA_INGRESO: $scope.fecha + .toISOString().slice(0, 19).replace('T', ' '), + Vendedor_valor: 0, + FAMILIA: 0, + CUIT_LIB: '', + COD_LUG: $scope.cobrosTabla[j].localidad.ID,//código lugar + SEN: '', + NRC: 0, + COD_LARGO: '', + VN: 0, + ID_LECTOR: 0, + NATHB: '' + }; + cheques.push(cheque); + } + } + + cobranza = { + recibo: { + CYV: 'V', + TIP: 'C', + TCO: 'RC', + PVE: $scope.puntoVenta, //Sucursar, punto de venta + NCO: $scope.comprobante, //Numero de comprobante + FEC: $scope.fecha.toISOString().slice(0, 19).replace('T', ' '), + CLI: $scope.cobranza.cliente.COD, + ATO: 0, //número de asiento + CFE: $scope.usuario.NomVen.trim(), + PLA: '',//Numero de planilla, sin uso + ID_MONEDA: $scope.cobranza.moneda.ID, + COTIZACION: $scope.cobranza.cotizacion.VENDEDOR + }, + cuerpo: cuerpos, + cheques: cheques, + acobypag: { + CYV: 'V', + COD: $scope.cobranza.cliente.COD, + FEP: $scope.fecha.toISOString().slice(0, 19).replace('T', ' '), + TIP: '',//?? + TCO: 'RC', + SUC: $scope.puntoVenta, + NCO: $scope.comprobante, + IPA: $scope.getTotalCobrado(), + SAL: '',//?? + TCA: 1, + ZONA: 1, + FPA: 2,//Forma de pago + REC: 0, + REP: 0, + FER: null, + REM: 0, + FRE: null,//?? + PRO: 'N', + FEV: $scope.fecha.toISOString().slice(0, 19).replace('T', ' ') + }, + datosCobrador: { + COD: $scope.cobranza.cobrador.id, + PVE: $scope.puntoVenta, + NUM: $scope.comprobante, + EST: 'C', + OBS: 'RC: ' + $scope.comprobante + '-' + $scope.fecha.toLocaleDateString(), + DAT1: 'C', + CLI: $scope.cobranza.cliente.COD + } + }; + focaCrearCobranzaService.guardarCobranza(cobranza).then(function() { + focaModalService.alert('Cobranza guardada con éxito'); + + $scope.cobranza = { + fecha: new Date() + }; + setearMonedaPorDefecto(); + obtenerNumeroComprobante(); + + $scope.cabecera = []; + $scope.fecha = new Date(); + $scope.facturaTabla = []; + $scope.cobrosTabla = []; + }); }; $scope.swichCobro = function() { @@ -155,9 +294,18 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', modalInstance.result.then( function(cheque) { var cobro = { - tipo: 'Ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco, - fecha: cheque.fechaPresentacion, - importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR + tipo: 'Ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, + numero: cheque.numero, + banco: cheque.banco, + fecha: cheque.fechaEmision.toLocaleDateString() + '-' + + cheque.fechaPresentacion.toLocaleDateString(), + fechaPresentacion: cheque.fechaPresentacion, + fechaEmision: cheque.fechaEmision, + importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR, + localidad: cheque.localidad, + librador: cheque.librador, + provincia: cheque.provincia, + observaciones: cheque.observaciones }; $scope.cobrosTabla.push(cobro); }, function() { @@ -206,25 +354,6 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', } ); }; - - $scope.seleccionarCobrador = function() { - var modalInstance = $uibModal.open( - { - ariaLabelledBy: 'Busqueda de Cobradores', - templateUrl: 'modal-cobradores.html', - controller: 'focaModalCobradoresController', - size: 'lg' - } - ); - modalInstance.result.then( - function(cobrador) { - addCabecera('Cobrador:', cobrador.nombre); - $scope.cobranza.cobrador = cobrador; - }, function() { - - } - ); - }; $scope.seleccionarCotizacion = function(moneda) { var modalInstance = $uibModal.open( @@ -251,16 +380,24 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', } ); }; - - $scope.agregarCobro = function(key) { - if(key === 13) { - var cobro = { - cobro: 'Efectivo', - fecha: new Date(), - importe: $scope.cobroEfectivo - }; - $scope.cobrosTabla.push(cobro); - } + + $scope.seleccionarCobrador = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Cobradores', + templateUrl: 'modal-cobradores.html', + controller: 'focaModalCobradoresController', + size: 'lg' + } + ); + modalInstance.result.then( + function(cobrador) { + addCabecera('Cobrador:', cobrador.nombre); + $scope.cobranza.cobrador = cobrador; + }, function() { + + } + ); }; $scope.getTotalDeuda = function() { @@ -341,5 +478,29 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); } }*/ + function setearMonedaPorDefecto() { + var monedaPorDefecto; + //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' + focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { + monedaPorDefecto = res.data[0]; + $scope.cobranza.moneda = monedaPorDefecto; + $scope.cobranza.cotizacion = monedaPorDefecto.cotizaciones[0]; + }); + } + + function obtenerNumeroComprobante() { + focaCrearCobranzaService.getNumeroRecibo().then( + function(res) { + $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); + $scope.comprobante = $scope.rellenar(res.data.numeroRecibo, 8); + }, + function(err) { + focaModalService.alert('La terminal no esta configurada correctamente'); + console.info(err); + } + ); + } + obtenerNumeroComprobante(); + setearMonedaPorDefecto(); } ]); diff --git a/src/js/service.js b/src/js/service.js index 701cfb0..6ecaa0d 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -2,10 +2,16 @@ angular.module('focaCrearCobranza') .service('focaCrearCobranzaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { return { getNumeroRecibo: function() { - return $http.get(API_ENDPOINT.URL + '/cobranza/numero-siguiente'); + return $http.get(API_ENDPOINT.URL + '/recibo/numero-siguiente'); }, getCotizacionByIdMoneda: function(id) { return $http.get(API_ENDPOINT.URL + '/moneda/' + id); + }, + getUsuario: function(idUsuario) { + return $http.get(API_ENDPOINT.URL + '/vendedores/obtener/' + idUsuario); + }, + guardarCobranza: function(cobranza) { + return $http.post(API_ENDPOINT.URL + '/recibo/guardar', cobranza); } }; }]); diff --git a/src/views/cobranza.html b/src/views/cobranza.html index d806904..4002172 100644 --- a/src/views/cobranza.html +++ b/src/views/cobranza.html @@ -15,14 +15,14 @@ Fecha: - - Total Deuda: + Cancela: {{(getTotalDeuda() / cobranza.cotizacion.VENDEDOR) | @@ -308,9 +305,7 @@
-
@@ -485,7 +480,7 @@
- Deuda: + Cancela: Cobrado: