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