Commit ba12a628a55f709bb4dd90ad5b56c75d446c29a2

Authored by Marcelo Puebla
1 parent ce7a007600
Exists in master

Correccion en creacion de objeto remito.

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