Commit 669972d07c5419d422a914276929deccf097de27
1 parent
501aacd590
Exists in
master
Boton cancelar
Showing
1 changed file
with
1 additions
and
4 deletions
Show diff stats
src/js/controllerDetalles.js
1 | angular.module('focaCrearHojaRuta') | 1 | angular.module('focaCrearHojaRuta') |
2 | .controller('focaModalDetalleController', [ | 2 | .controller('focaModalDetalleController', [ |
3 | '$scope', '$timeout', '$uibModalInstance', 'focaModalService', | 3 | '$scope', '$timeout', '$uibModalInstance', 'focaModalService', |
4 | 'focaCrearHojaRutaService', 'hojasRutas', | 4 | 'focaCrearHojaRutaService', 'hojasRutas', |
5 | function ($scope, $timeout, $uibModalInstance, focaModalService, | 5 | function ($scope, $timeout, $uibModalInstance, focaModalService, |
6 | focaCrearHojaRutaService, hojasRutas) { | 6 | focaCrearHojaRutaService, hojasRutas) { |
7 | 7 | ||
8 | $scope.mostrar = false; | 8 | $scope.mostrar = false; |
9 | $scope.articulos = []; | 9 | $scope.articulos = []; |
10 | $scope.cisternaMovimientos = []; | 10 | $scope.cisternaMovimientos = []; |
11 | 11 | ||
12 | init(); | 12 | init(); |
13 | function init() { | 13 | function init() { |
14 | $scope.hojasRutas = hojasRutas; | 14 | $scope.hojasRutas = hojasRutas; |
15 | 15 | ||
16 | $scope.hojasRutas.vehiculo.cisternas = $scope.hojasRutas.vehiculo.cisternas.filter( | 16 | $scope.hojasRutas.vehiculo.cisternas = $scope.hojasRutas.vehiculo.cisternas.filter( |
17 | function (cisterna) { | 17 | function (cisterna) { |
18 | return !cisterna.desactivado; | 18 | return !cisterna.desactivado; |
19 | } | 19 | } |
20 | ); | 20 | ); |
21 | focaCrearHojaRutaService.getArticulos() | 21 | focaCrearHojaRutaService.getArticulos() |
22 | .then(function (articulos) { | 22 | .then(function (articulos) { |
23 | $scope.articulos = articulos.data; | 23 | $scope.articulos = articulos.data; |
24 | }); | 24 | }); |
25 | } | 25 | } |
26 | 26 | ||
27 | $scope.validarCisternaDisponible = function (cisterna) { | 27 | $scope.validarCisternaDisponible = function (cisterna) { |
28 | if (parseInt(cisterna.disponible) > cisterna.capacidad) { | 28 | if (parseInt(cisterna.disponible) > cisterna.capacidad) { |
29 | focaModalService.alert('No se puede ingresar una capacidad disponible ' + | 29 | focaModalService.alert('No se puede ingresar una capacidad disponible ' + |
30 | 'superior a la ' + 'capacidad del vehiculo '); | 30 | 'superior a la ' + 'capacidad del vehiculo '); |
31 | cisterna.disponible = cisterna.capacidad; | 31 | cisterna.disponible = cisterna.capacidad; |
32 | return; | 32 | return; |
33 | } | 33 | } |
34 | }; | 34 | }; |
35 | 35 | ||
36 | $scope.seleccionarProductos = function (key, cisterna) { | 36 | $scope.seleccionarProductos = function (key, cisterna) { |
37 | focaModalService.modal({ | 37 | focaModalService.modal({ |
38 | titulo: 'Productos', | 38 | titulo: 'Productos', |
39 | data: $scope.articulos, | 39 | data: $scope.articulos, |
40 | size: 'md', | 40 | size: 'md', |
41 | columnas: [ | 41 | columnas: [ |
42 | { | 42 | { |
43 | propiedad: 'CodRub', | 43 | propiedad: 'CodRub', |
44 | nombre: 'Codigo' | 44 | nombre: 'Codigo' |
45 | }, | 45 | }, |
46 | { | 46 | { |
47 | propiedad: 'descripcion', | 47 | propiedad: 'descripcion', |
48 | nombre: 'Nombre' | 48 | nombre: 'Nombre' |
49 | }, | 49 | }, |
50 | ], | 50 | ], |
51 | }).then(function (res) { | 51 | }).then(function (res) { |
52 | cisterna.disponible = cisterna.capacidad; | 52 | cisterna.disponible = cisterna.capacidad; |
53 | var newArt = | 53 | var newArt = |
54 | { | 54 | { |
55 | id: 0, | 55 | id: 0, |
56 | idRemito: 0, | 56 | idRemito: 0, |
57 | codigo: res.codigo, | 57 | codigo: res.codigo, |
58 | sector: res.sector, | 58 | sector: res.sector, |
59 | sectorCodigo: res.sector + '-' + res.codigo, | 59 | sectorCodigo: res.sector + '-' + res.codigo, |
60 | descripcion: res.descripcion, | 60 | descripcion: res.descripcion, |
61 | item: key + 1, | 61 | item: key + 1, |
62 | nombre: res.descripcion, | 62 | nombre: res.descripcion, |
63 | precio: parseFloat(res.precio).toFixed(4), | 63 | precio: parseFloat(res.precio).toFixed(4), |
64 | costoUnitario: res.costo, | 64 | costoUnitario: res.costo, |
65 | editCantidad: false, | 65 | editCantidad: false, |
66 | editPrecio: false, | 66 | editPrecio: false, |
67 | rubro: res.CodRub, | 67 | rubro: res.CodRub, |
68 | ivaUnitario: res.IMPIVA, | 68 | ivaUnitario: res.IMPIVA, |
69 | impuestoInternoUnitario: res.ImpInt, | 69 | impuestoInternoUnitario: res.ImpInt, |
70 | impuestoInterno1Unitario: res.ImpInt2, | 70 | impuestoInterno1Unitario: res.ImpInt2, |
71 | impuestoInterno2Unitario: res.ImpInt3, | 71 | impuestoInterno2Unitario: res.ImpInt3, |
72 | precioLista: res.precio, | 72 | precioLista: res.precio, |
73 | combustible: 1, | 73 | combustible: 1, |
74 | facturado: 0, | 74 | facturado: 0, |
75 | idArticulo: res.id, | 75 | idArticulo: res.id, |
76 | tasaIva: res.tasaIVA | 76 | tasaIva: res.tasaIVA |
77 | }; | 77 | }; |
78 | 78 | ||
79 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : res.neto; | 79 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : res.neto; |
80 | newArt.netoUnitario = newArt.ivaUnitario ? res.neto : 0; | 80 | newArt.netoUnitario = newArt.ivaUnitario ? res.neto : 0; |
81 | 81 | ||
82 | cisterna.articuloSeleccionado = newArt; | 82 | cisterna.articuloSeleccionado = newArt; |
83 | cisterna.nombreArticulo = res.descripcion; | 83 | cisterna.nombreArticulo = res.descripcion; |
84 | }).catch(function (e) { | 84 | }).catch(function (e) { |
85 | console.log(e); | 85 | console.log(e); |
86 | }); | 86 | }); |
87 | }; | 87 | }; |
88 | 88 | ||
89 | $scope.guardar = function () { | 89 | $scope.guardar = function () { |
90 | 90 | ||
91 | var cisternasFilter = validarArticulos(); | 91 | var cisternasFilter = validarArticulos(); |
92 | 92 | ||
93 | var articulos = []; | 93 | var articulos = []; |
94 | if (cisternasFilter === undefined) { | 94 | if (cisternasFilter === undefined) { |
95 | return; | 95 | return; |
96 | } | 96 | } |
97 | cisternasFilter.forEach(function (cisterna) { | 97 | cisternasFilter.forEach(function (cisterna) { |
98 | 98 | ||
99 | var fechaReparto = $scope.hojasRutas.fechaReparto; | 99 | var fechaReparto = $scope.hojasRutas.fechaReparto; |
100 | 100 | ||
101 | var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) { | 101 | var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) { |
102 | return carga.fechaReparto === fechaReparto; | 102 | return carga.fechaReparto === fechaReparto; |
103 | }); | 103 | }); |
104 | 104 | ||
105 | if (filtroCisternaCarga.length) { | 105 | if (filtroCisternaCarga.length) { |
106 | cisterna.cisternaCarga = filtroCisternaCarga[0]; | 106 | cisterna.cisternaCarga = filtroCisternaCarga[0]; |
107 | } else { | 107 | } else { |
108 | cisterna.cisternaCarga = { | 108 | cisterna.cisternaCarga = { |
109 | confirmado: null, | 109 | confirmado: null, |
110 | fechaReparto: fechaReparto, | 110 | fechaReparto: fechaReparto, |
111 | idCisterna: cisterna.id, | 111 | idCisterna: cisterna.id, |
112 | }; | 112 | }; |
113 | } | 113 | } |
114 | 114 | ||
115 | //cargar | 115 | //cargar |
116 | if (cisterna.cisternaCarga.cantidad) { | 116 | if (cisterna.cisternaCarga.cantidad) { |
117 | cisterna.cisternaCarga.cantidad += cisterna.disponible; | 117 | cisterna.cisternaCarga.cantidad += cisterna.disponible; |
118 | } else { | 118 | } else { |
119 | cisterna.cisternaCarga.cantidad = cisterna.disponible; | 119 | cisterna.cisternaCarga.cantidad = cisterna.disponible; |
120 | cisterna.cisternaCarga.idProducto = | 120 | cisterna.cisternaCarga.idProducto = |
121 | cisterna.articuloSeleccionado.idArticulo; | 121 | cisterna.articuloSeleccionado.idArticulo; |
122 | } | 122 | } |
123 | 123 | ||
124 | //Guardar | 124 | //Guardar |
125 | var now = new Date(); | 125 | var now = new Date(); |
126 | var cisternaMovimiento = { | 126 | var cisternaMovimiento = { |
127 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 127 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
128 | cantidad: cisterna.disponible, | 128 | cantidad: cisterna.disponible, |
129 | metodo: 'carga', | 129 | metodo: 'carga', |
130 | idCisternaCarga: cisterna.cisternaCarga.id, | 130 | idCisternaCarga: cisterna.cisternaCarga.id, |
131 | }; | 131 | }; |
132 | 132 | ||
133 | cisterna.cisternaCarga.fechaReparto = fechaReparto; | 133 | cisterna.cisternaCarga.fechaReparto = fechaReparto; |
134 | cisterna.articuloSeleccionado.cantidad = cisterna.disponible; | 134 | cisterna.articuloSeleccionado.cantidad = cisterna.disponible; |
135 | articulos.push(cisterna.articuloSeleccionado); | 135 | articulos.push(cisterna.articuloSeleccionado); |
136 | $scope.cisternaMovimientos.push(cisternaMovimiento); | 136 | $scope.cisternaMovimientos.push(cisternaMovimiento); |
137 | }); | 137 | }); |
138 | 138 | ||
139 | $uibModalInstance.close({ | 139 | $uibModalInstance.close({ |
140 | cisternas: cisternasFilter, | 140 | cisternas: cisternasFilter, |
141 | movimientos: $scope.cisternaMovimientos, | 141 | movimientos: $scope.cisternaMovimientos, |
142 | articulos: articulos | 142 | articulos: articulos |
143 | }); | 143 | }); |
144 | }; | 144 | }; |
145 | 145 | ||
146 | $scope.cancel = function () { | 146 | $scope.cancel = function () { |
147 | var validarCisternas = validarArticulos(); | 147 | $uibModalInstance.dismiss(null); |
148 | if (validarCisternas !== undefined) { | ||
149 | $uibModalInstance.dismiss(null); | ||
150 | } | ||
151 | }; | 148 | }; |
152 | 149 | ||
153 | function validarArticulos () { | 150 | function validarArticulos () { |
154 | var cisternasFilter = $scope.hojasRutas.vehiculo.cisternas | 151 | var cisternasFilter = $scope.hojasRutas.vehiculo.cisternas |
155 | .filter(function (cisterna) { | 152 | .filter(function (cisterna) { |
156 | return parseInt(cisterna.disponible) > 0 || cisterna.articuloSeleccionado; | 153 | return parseInt(cisterna.disponible) > 0 || cisterna.articuloSeleccionado; |
157 | }); | 154 | }); |
158 | 155 | ||
159 | var cisternasIncompletas = cisternasFilter.filter(function(cisterna) { | 156 | var cisternasIncompletas = cisternasFilter.filter(function(cisterna) { |
160 | return (cisterna.articuloSeleccionado && !cisterna.disponible) || | 157 | return (cisterna.articuloSeleccionado && !cisterna.disponible) || |
161 | (!cisterna.articuloSeleccionado && cisterna.disponible); | 158 | (!cisterna.articuloSeleccionado && cisterna.disponible); |
162 | }); | 159 | }); |
163 | 160 | ||
164 | if (cisternasIncompletas.length > 0 && cisternasFilter.length > 0 ) { | 161 | if (cisternasIncompletas.length > 0 && cisternasFilter.length > 0 ) { |
165 | focaModalService.alert('Ingrese todos los campos para completar el remito'); | 162 | focaModalService.alert('Ingrese todos los campos para completar el remito'); |
166 | cisternasFilter = undefined; | 163 | cisternasFilter = undefined; |
167 | } | 164 | } |
168 | return cisternasFilter; | 165 | return cisternasFilter; |
169 | } | 166 | } |
170 | } | 167 | } |
171 | ]); | 168 | ]); |
172 | 169 |