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