Commit f1b3ae1d81c90eb45419d9046c8163c632fb9f80

Authored by Marcelo Puebla
1 parent d59ba6059b
Exists in master

Borrado de comentarios y console.log

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