Commit ce7a007600ea7dffbc21ec3cdbc1e5951b487fa7

Authored by Marcelo Puebla
1 parent af9e4723d0
Exists in master

agregado variable articulos.

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