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