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