Commit d0d33876d9cbcf8785ae23d3a558248ba6005cc2

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master(mpuebla)

See merge request !3
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;
23 24 $scope.articulos = [];
24 console.log(remito);
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.vendedor.NUM,
50 idProveedor: $scope.remito.proveedor.COD, 50 idProveedor: $scope.remito.proveedor.COD,
51 idDomicilio: $scope.remito.idDomicilio || $scope.remito.domicilio.id, 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.domicilioStamp,
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.addArticulos($scope.remito.articulosRemito, remitoId, 1); 94 focaModalDescargasService.
95 addArticulos($scope.articulos, remitoId, 1);
95 focaModalService.alert("Descarga realizada") 96 focaModalService.alert("Descarga realizada")
96 .then(function(){ 97 .then(function () {
97 $uibModalInstance.dismiss(); 98 $uibModalInstance.dismiss();
98 }) 99 })
99 }) 100 })
100 .catch(function (e) { console.log(e); }) 101 .catch(function (e) { console.log(e); })
101 102
102 }; 103 };
103 $scope.getTotal = function () { 104 $scope.getTotal = function () {
104 var total = 0; 105 var total = 0;
105 var arrayTempArticulos = $scope.remito.articulosRemito; 106 $scope.cisternas.forEach(function (cisterna) {
106 for (var i = 0; i < arrayTempArticulos.length; i++) { 107 $scope.articulos.push(cisterna.cisternaCarga.articulo);
107 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 108 total += cisterna.cisternaCarga.articulo.PreVen * cisterna.cisternaCarga.descargar;
108 } 109 });
110 // for (var i = 0; i < articulos.length; i++) {
111 // total += articulos[i].PreVen * articulos[i].cantidad;
112 // }
109 return parseFloat(total.toFixed(2)); 113 return parseFloat(total.toFixed(2));
110 }; 114 };
111 function descargar(idRemito) { 115 function descargar(idRemito) {
112 for (var i = 0; i < $scope.cisternas.length; i++) { 116 for (var i = 0; i < $scope.cisternas.length; i++) {
113 var descarga = $scope.cisternas[i].cisternaCarga.descargar; 117 var descarga = $scope.cisternas[i].cisternaCarga.descargar;
114 var hojaRutaMovimientos = []; 118 var hojaRutaMovimientos = [];
115 var cisternaMovimientos = []; 119 var cisternaMovimientos = [];
116 var cisternaCargas = []; 120 var cisternaCargas = [];
117 var cisternaCarga = $scope.cisternas[i].cisternaCarga; 121 var cisternaCarga = $scope.cisternas[i].cisternaCarga;
118 if (!descarga) continue; 122 if (!descarga) continue;
119 // if (descarga > cisternaCarga.cantidad) { 123 // if (descarga > cisternaCarga.cantidad) {
120 // focaModalService.alert('La cantidad a descargar no debe ser ' + 124 // focaModalService.alert('La cantidad a descargar no debe ser ' +
121 // 'mayor a la cantidad de la cisterna'); 125 // 'mayor a la cantidad de la cisterna');
122 // $scope.cargando = false; 126 // $scope.cargando = false;
123 // return; 127 // return;
124 // } 128 // }
125 cisternaCarga.cantidad -= descarga; 129 cisternaCarga.cantidad -= descarga;
126 130
127 //Guardar 131 //Guardar
128 var now = new Date(); 132 var now = new Date();
129 var cisternaMovimiento = { 133 var cisternaMovimiento = {
130 fecha: now.toISOString().slice(0, 19).replace('T', ' '), 134 fecha: now.toISOString().slice(0, 19).replace('T', ' '),
131 cantidad: descarga, 135 cantidad: descarga,
132 metodo: 'descarga', 136 metodo: 'descarga',
133 idCisternaCarga: cisternaCarga.id, 137 idCisternaCarga: cisternaCarga.id,
134 idRemito: idRemito 138 idRemito: idRemito
135 }; 139 };
136 var hojaRutaMovimiento = { 140 var hojaRutaMovimiento = {
137 reciboDescarga: $scope.nroRecibo, 141 reciboDescarga: $scope.nroRecibo,
138 idRemito: idRemito 142 idRemito: idRemito
139 }; 143 };
140 delete cisternaCarga.articulo; 144 delete cisternaCarga.articulo;
141 delete cisternaCarga.descargar; 145 delete cisternaCarga.descargar;
142 cisternaCargas.push(cisternaCarga); 146 cisternaCargas.push(cisternaCarga);
143 cisternaMovimientos.push(cisternaMovimiento); 147 cisternaMovimientos.push(cisternaMovimiento);
144 hojaRutaMovimientos.push(hojaRutaMovimiento); 148 hojaRutaMovimientos.push(hojaRutaMovimiento);
145 } 149 }
146 var save = { 150 var save = {
147 cisternaCargas: cisternaCargas, 151 cisternaCargas: cisternaCargas,
148 cisternaMovimientos: cisternaMovimientos, 152 cisternaMovimientos: cisternaMovimientos,
149 hojaRutaMovimientos: hojaRutaMovimientos, 153 hojaRutaMovimientos: hojaRutaMovimientos,
150 articulo: $scope.articuloSeleccionado 154 articulo: $scope.articuloSeleccionado
151 }; 155 };
152 focaModalDetalleHojaRutaService 156 focaModalDetalleHojaRutaService
153 .postMovimientoHojaRuta(save) 157 .postMovimientoHojaRuta(save)
154 .then(guardarSeguimiento) 158 .then(guardarSeguimiento)
155 .catch(function() {}); 159 .catch(function () { });
156 function guardarSeguimiento(res) { 160 function guardarSeguimiento(res) {
157 focaSeguimientoService 161 focaSeguimientoService
158 .guardarPosicion( 162 .guardarPosicion(
159 'Entrega de producto', 163 'Entrega de producto',
160 res.data[0].id, 164 res.data[0].id,
161 $scope.remito.observaciones); 165 $scope.remito.observaciones);
162 $scope.aDescargar = []; 166 $scope.aDescargar = [];
163 }; 167 };
164 }; 168 };
165 function getImporte(propiedad) { 169 function getImporte(propiedad) {
166 var importe = 0; 170 var importe = 0;
167
168 $scope.remito.articulosRemito.forEach(function (articulo) { 171 $scope.remito.articulosRemito.forEach(function (articulo) {
169
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
175 }); 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 () {