Commit d59ba6059b7282c8210267f9bc527524b9c61b9d

Authored by Marcelo Puebla
1 parent 988b6dab93
Exists in master

Agregada validacion para input con valor a descargar.

Showing 1 changed file with 12 additions and 21 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaModalDescarga') 1 angular.module('focaModalDescarga')
2 .controller('focaModalDescargaCtrl', [ 2 .controller('focaModalDescargaCtrl', [
3 '$scope', 3 '$scope',
4 'focaModalDescargasService', 4 'focaModalDescargasService',
5 '$filter', 5 '$filter',
6 'focaModalService', 6 'focaModalService',
7 '$timeout', 7 '$timeout',
8 '$uibModalInstance', 8 '$uibModalInstance',
9 '$uibModal', 9 '$uibModal',
10 'remito', 10 'remito',
11 'focaModalDetalleHojaRutaService', 11 'focaModalDetalleHojaRutaService',
12 'focaSeguimientoService', 12 'focaSeguimientoService',
13 function ($scope, focaModalDescargasService, $filter, 13 function ($scope, focaModalDescargasService, $filter,
14 focaModalService, $timeout, $uibModalInstance, $uibModal, remito, 14 focaModalService, $timeout, $uibModalInstance, $uibModal, remito,
15 focaModalDetalleHojaRutaService, focaSeguimientoService) { 15 focaModalDetalleHojaRutaService, focaSeguimientoService) {
16 16
17 //#region variables 17 //#region variables
18 console.log(remito); 18 console.log(remito);
19 $scope.remito = {}; 19 $scope.remito = {};
20 $scope.remito = remito; 20 $scope.remito = remito;
21 $scope.nroRecibo = 0; 21 $scope.nroRecibo = 0;
22 $scope.cisternas = remito.cisternas; 22 $scope.cisternas = remito.cisternas;
23 $scope.nroRemito = "00" + remito.sucursal + "-000000000" + remito.numeroRemito; 23 $scope.nroSucursal = "00" + remito.sucursal;
24 $scope.articulos = []; 24 $scope.articulos = [];
25 //#endregion 25 //#endregion
26 26
27 $scope.crearRemito = function () { 27 $scope.crearRemito = function () {
28 if (!$scope.remito.cliente) { 28 if (!$scope.remito.cliente) {
29 focaModalService.alert("No has seleccionado cliente"); 29 focaModalService.alert("No has seleccionado cliente");
30 return; 30 return;
31 } 31 }
32 if (!validarDescarga()) { 32 if (validarDescarga()) {
33 focaModalService.alert("Cantidad de descarga ingresada erronea");
34 return;
35 }
36 if (!$scope.nroRecibo) {
37 focaModalService.alert("No ingresaste nro de recibo");
38 return; 33 return;
39 } 34 }
40 //#region OBJETO REMITO 35 //#region OBJETO REMITO
41 var remito = { 36 var remito = {
42 id: 0, 37 id: 0,
43 fechaRemito: new Date().toISOString().slice(0, 19).replace('T', ' '), 38 fechaRemito: new Date().toISOString().slice(0, 19).replace('T', ' '),
44 idCliente: $scope.remito.cliente.cod, 39 idCliente: $scope.remito.cliente.cod,
45 nombreCliente: $scope.remito.cliente.nom, 40 nombreCliente: $scope.remito.cliente.nom,
46 cuitCliente: $scope.remito.cliente.cuit, 41 cuitCliente: $scope.remito.cliente.cuit,
47 total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, 42 total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR,
48 numeroNotaPedido: $scope.remito.numeroNotaPedido, 43 numeroNotaPedido: $scope.remito.numeroNotaPedido,
49 idVendedor: $scope.remito.cliente.ven, 44 idVendedor: $scope.remito.cliente.ven,
50 idProveedor: $scope.remito.proveedor.COD, 45 idProveedor: $scope.remito.proveedor.COD,
51 idDomicilio: 0, 46 idDomicilio: 0,
52 idCotizacion: $scope.remito.cotizacion.ID, 47 idCotizacion: $scope.remito.cotizacion.ID,
53 idListaPrecio: $scope.remito.cliente.mod, 48 idListaPrecio: $scope.remito.cliente.mod,
54 flete: $scope.remito.flete, 49 flete: $scope.remito.flete,
55 fob: $scope.remito.fob, 50 fob: $scope.remito.fob,
56 bomba: $scope.remito.bomba, 51 bomba: $scope.remito.bomba,
57 kilometros: $scope.remito.kilometros, 52 kilometros: $scope.remito.kilometros,
58 domicilioStamp: $scope.remito.cliente.DOM, 53 domicilioStamp: $scope.remito.cliente.DOM,
59 observaciones: $scope.remito.observaciones, 54 observaciones: $scope.remito.observaciones,
60 numeroRemito: parseInt($scope.comprobante), 55 numeroRemito: parseInt($scope.comprobante),
61 sucursal: parseInt($scope.puntoVenta), 56 sucursal: parseInt($scope.puntoVenta),
62 responsabilidadIvaCliente: $scope.remito.cliente.iva, 57 responsabilidadIvaCliente: $scope.remito.cliente.iva,
63 descuento: 0,//TODO, 58 descuento: 0,//TODO,
64 importeNeto: getImporte('netoUnitario'), 59 importeNeto: getImporte('netoUnitario'),
65 importeExento: getImporte('exentoUnitario'), 60 importeExento: getImporte('exentoUnitario'),
66 importeIva: getImporte('ivaUnitario'), 61 importeIva: getImporte('ivaUnitario'),
67 importeIvaServicios: 0,//TODO 62 importeIvaServicios: 0,//TODO
68 importeImpuestoInterno: getImporte('impuestoInternoUnitario'), 63 importeImpuestoInterno: getImporte('impuestoInternoUnitario'),
69 importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), 64 importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'),
70 importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), 65 importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'),
71 percepcion: 0,//TODO 66 percepcion: 0,//TODO
72 percepcionIva: 0,//TODO 67 percepcionIva: 0,//TODO
73 redondeo: 0,//TODO 68 redondeo: 0,//TODO
74 anulado: false, 69 anulado: false,
75 planilla: $filter('date')($scope.now, 'ddMMyyyy'), 70 planilla: $filter('date')($scope.now, 'ddMMyyyy'),
76 lugar: parseInt($scope.puntoVenta), 71 lugar: parseInt($scope.puntoVenta),
77 cuentaMadre: 0,//TODO 72 cuentaMadre: 0,//TODO
78 cuentaContable: 0,//TODO 73 cuentaContable: 0,//TODO
79 asiento: 0,//TODO 74 asiento: 0,//TODO
80 e_hd: '',//TODO 75 e_hd: '',//TODO
81 c_hd: '', 76 c_hd: '',
82 numeroLiquidoProducto: 0,//TODO 77 numeroLiquidoProducto: 0,//TODO
83 estado: 0, 78 estado: 0,
84 destinoVenta: 0,//TODO 79 destinoVenta: 0,//TODO
85 operacionTipo: 0, //TODO 80 operacionTipo: 0, //TODO
86 idHojaRuta: $scope.remito.idHojaRuta 81 idHojaRuta: $scope.remito.idHojaRuta
87 } 82 }
88 //#endregionc 83 //#endregion
89 focaModalDescargasService.crearRemito({ remito: remito, notaPedido: { id: 0 } }) 84 focaModalDescargasService.crearRemito({ remito: remito, notaPedido: { id: 0 } })
90 .then(function (res) { 85 .then(function (res) {
91 console.log(res);
92 remitoId = res.data.id 86 remitoId = res.data.id
93 descargar(remitoId); 87 descargar(remitoId);
94 focaModalDescargasService. 88 focaModalDescargasService.
95 addArticulos($scope.articulos, remitoId, 1); 89 addArticulos($scope.articulos, remitoId, 1);
96 focaModalService.alert("Descarga realizada") 90 focaModalService.alert("Descarga realizada")
97 .then(function () { 91 .then(function () {
98 $uibModalInstance.dismiss(); 92 $uibModalInstance.dismiss();
99 }) 93 })
100 }) 94 })
101 .catch(function (e) { console.log(e); }) 95 .catch(function (e) { console.log(e); })
102 96
103 }; 97 };
104 $scope.getTotal = function () { 98 $scope.getTotal = function () {
105 var total = 0; 99 var total = 0;
106 $scope.cisternas.forEach(function (cisterna) { 100 $scope.cisternas.forEach(function (cisterna) {
107 $scope.articulos.push(cisterna.cisternaCarga.articulo); 101 $scope.articulos.push(cisterna.cisternaCarga.articulo);
108 total += cisterna.cisternaCarga.articulo.PreVen * cisterna.cisternaCarga.descargar; 102 total += cisterna.cisternaCarga.articulo.PreVen * cisterna.cisternaCarga.descargar;
109 }); 103 });
110 // for (var i = 0; i < articulos.length; i++) { 104 // for (var i = 0; i < articulos.length; i++) {
111 // total += articulos[i].PreVen * articulos[i].cantidad; 105 // total += articulos[i].PreVen * articulos[i].cantidad;
112 // } 106 // }
113 return parseFloat(total.toFixed(2)); 107 return parseFloat(total.toFixed(2));
114 }; 108 };
115 function descargar(idRemito) { 109 function descargar(idRemito) {
116 for (var i = 0; i < $scope.cisternas.length; i++) { 110 for (var i = 0; i < $scope.cisternas.length; i++) {
117 var descarga = $scope.cisternas[i].cisternaCarga.descargar; 111 var descarga = $scope.cisternas[i].cisternaCarga.descargar;
118 var hojaRutaMovimientos = []; 112 var hojaRutaMovimientos = [];
119 var cisternaMovimientos = []; 113 var cisternaMovimientos = [];
120 var cisternaCargas = []; 114 var cisternaCargas = [];
121 var cisternaCarga = $scope.cisternas[i].cisternaCarga; 115 var cisternaCarga = $scope.cisternas[i].cisternaCarga;
122 if (!descarga) continue; 116 if (!descarga) continue;
123 // if (descarga > cisternaCarga.cantidad) {
124 // focaModalService.alert('La cantidad a descargar no debe ser ' +
125 // 'mayor a la cantidad de la cisterna');
126 // $scope.cargando = false;
127 // return;
128 // }
129 cisternaCarga.cantidad -= descarga; 117 cisternaCarga.cantidad -= descarga;
130 118
131 //Guardar 119 //Guardar
132 var now = new Date(); 120 var now = new Date();
133 var cisternaMovimiento = { 121 var cisternaMovimiento = {
134 fecha: now.toISOString().slice(0, 19).replace('T', ' '), 122 fecha: now.toISOString().slice(0, 19).replace('T', ' '),
135 cantidad: descarga, 123 cantidad: descarga,
136 metodo: 'descarga', 124 metodo: 'descarga',
137 idCisternaCarga: cisternaCarga.id, 125 idCisternaCarga: cisternaCarga.id,
138 idRemito: idRemito 126 idRemito: idRemito
139 }; 127 };
140 var hojaRutaMovimiento = { 128 var hojaRutaMovimiento = {
141 reciboDescarga: $scope.nroRecibo, 129 reciboDescarga: $scope.nroRecibo,
142 idRemito: idRemito 130 idRemito: idRemito
143 }; 131 };
144 delete cisternaCarga.articulo; 132 delete cisternaCarga.articulo;
145 delete cisternaCarga.descargar; 133 delete cisternaCarga.descargar;
146 cisternaCargas.push(cisternaCarga); 134 cisternaCargas.push(cisternaCarga);
147 cisternaMovimientos.push(cisternaMovimiento); 135 cisternaMovimientos.push(cisternaMovimiento);
148 hojaRutaMovimientos.push(hojaRutaMovimiento); 136 hojaRutaMovimientos.push(hojaRutaMovimiento);
149 } 137 }
150 var save = { 138 var save = {
151 cisternaCargas: cisternaCargas, 139 cisternaCargas: cisternaCargas,
152 cisternaMovimientos: cisternaMovimientos, 140 cisternaMovimientos: cisternaMovimientos,
153 hojaRutaMovimientos: hojaRutaMovimientos, 141 hojaRutaMovimientos: hojaRutaMovimientos,
154 articulo: $scope.articuloSeleccionado 142 articulo: $scope.articuloSeleccionado
155 }; 143 };
156 focaModalDetalleHojaRutaService 144 focaModalDetalleHojaRutaService
157 .postMovimientoHojaRuta(save) 145 .postMovimientoHojaRuta(save)
158 .then(guardarSeguimiento) 146 .then(guardarSeguimiento)
159 .catch(function () { }); 147 .catch(function () { });
160 function guardarSeguimiento(res) { 148 function guardarSeguimiento(res) {
161 focaSeguimientoService 149 focaSeguimientoService
162 .guardarPosicion( 150 .guardarPosicion(
163 'Entrega de producto', 151 'Entrega de producto',
164 res.data[0].id, 152 res.data[0].id,
165 $scope.remito.observaciones); 153 $scope.remito.observaciones);
166 $scope.aDescargar = []; 154 $scope.aDescargar = [];
167 }; 155 };
168 }; 156 };
169 function getImporte(propiedad) { 157 function getImporte(propiedad) {
170 var importe = 0; 158 var importe = 0;
171 $scope.remito.articulosRemito.forEach(function (articulo) { 159 $scope.remito.articulosRemito.forEach(function (articulo) {
172 if (articulo[propiedad]) { 160 if (articulo[propiedad]) {
173 importe += articulo[propiedad] * articulo.cantidad; 161 importe += articulo[propiedad] * articulo.cantidad;
174 } 162 }
175 return; 163 return;
176 }); 164 });
177 return importe; 165 return importe;
178 }; 166 };
179 function validarDescarga() { 167 function validarDescarga() {
180 hasDisponible = $scope.cisternas.find(function (cisterna) { 168 for (var i = 0; i < $scope.cisternas.length; i++) {
181 return parseInt(cisterna.cisternaCarga.descargar) >= 0 && 169 if (parseInt($scope.cisternas[i].cisternaCarga.descargar) >
182 parseInt(cisterna.cisternaCarga.descargar) <= 170 $scope.cisternas[i].cisternaCarga.cantidad ||
183 cisterna.cisternaCarga.cantidad 171 parseInt($scope.cisternas[i].cisternaCarga.descargar) < 0) {
184 }); 172 focaModalService.alert("Cantidad de descarga ingresada erronea");
185 return hasDisponible; 173 return true;
174 }
175 }
176 return false;
186 }; 177 };
187 $scope.seleccionarCliente = function () { 178 $scope.seleccionarCliente = function () {
188 179
189 var modalInstance = $uibModal.open( 180 var modalInstance = $uibModal.open(
190 { 181 {
191 ariaLabelledBy: 'Busqueda de Cliente', 182 ariaLabelledBy: 'Busqueda de Cliente',
192 templateUrl: 'foca-busqueda-cliente-modal.html', 183 templateUrl: 'foca-busqueda-cliente-modal.html',
193 controller: 'focaBusquedaClienteModalController', 184 controller: 'focaBusquedaClienteModalController',
194 resolve: { 185 resolve: {
195 vendedor: function () { return null; }, 186 vendedor: function () { return null; },
196 cobrador: function () { return null; } 187 cobrador: function () { return null; }
197 }, 188 },
198 size: 'lg' 189 size: 'lg'
199 } 190 }
200 ); 191 );
201 modalInstance.result.then(function (cliente) { 192 modalInstance.result.then(function (cliente) {
202 $scope.remito.cliente = cliente; 193 $scope.remito.cliente = cliente;
203 }, function () { 194 }, function () {
204 //funcion ejecutada al cancelar modal 195 //funcion ejecutada al cancelar modal
205 }); 196 });
206 }; 197 };
207 $scope.cancelar = function () { 198 $scope.cancelar = function () {
208 $uibModalInstance.dismiss(); 199 $uibModalInstance.dismiss();
209 } 200 }