Commit faee029b955e998cfd0b970c7b4d17f014bdb6c1
1 parent
2cddee92b6
Exists in
master
and in
2 other branches
delete de remitos y no mostrar información cuando no tiene remitos
Showing
2 changed files
with
3 additions
and
1 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaModalDetalleCisternas') | 1 | angular.module('focaModalDetalleCisternas') |
2 | .controller('focaDetalleVehiculo', | 2 | .controller('focaDetalleVehiculo', |
3 | ['$scope', | 3 | ['$scope', |
4 | '$uibModalInstance', | 4 | '$uibModalInstance', |
5 | 'idVehiculo', | 5 | 'idVehiculo', |
6 | 'idRemito', | 6 | 'idRemito', |
7 | 'focaModalService', | 7 | 'focaModalService', |
8 | '$filter', | 8 | '$filter', |
9 | 'focaModalDetalleCisternasService', | 9 | 'focaModalDetalleCisternasService', |
10 | 'fechaReparto', | 10 | 'fechaReparto', |
11 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, | 11 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, |
12 | focaModalDetalleCisternasService, fechaReparto | 12 | focaModalDetalleCisternasService, fechaReparto |
13 | ) { | 13 | ) { |
14 | //seteo variables | 14 | //seteo variables |
15 | $scope.cargandoDatos = true; | 15 | $scope.cargandoDatos = true; |
16 | $scope.idRemito = idRemito; | 16 | $scope.idRemito = idRemito; |
17 | $scope.articulos = []; | 17 | $scope.articulos = []; |
18 | $scope.vehiculo = {}; | 18 | $scope.vehiculo = {}; |
19 | $scope.cisternas = []; | 19 | $scope.cisternas = []; |
20 | $scope.cisternasCarga = []; | 20 | $scope.cisternasCarga = []; |
21 | $scope.remito = {}; | 21 | $scope.remito = {}; |
22 | $scope.aCargar = []; | 22 | $scope.aCargar = []; |
23 | var cisternaMovimientos = []; | 23 | var cisternaMovimientos = []; |
24 | var promesaRemito; | 24 | var promesaRemito; |
25 | 25 | ||
26 | if(fechaReparto) { | 26 | if(fechaReparto) { |
27 | focaModalDetalleCisternasService.fecha = fechaReparto; | 27 | focaModalDetalleCisternasService.fecha = fechaReparto; |
28 | } | 28 | } |
29 | var promesaVehiculo = focaModalDetalleCisternasService.obtenerVehiculoById(idVehiculo); | 29 | var promesaVehiculo = focaModalDetalleCisternasService.obtenerVehiculoById(idVehiculo); |
30 | var promesaCisternas = focaModalDetalleCisternasService | 30 | var promesaCisternas = focaModalDetalleCisternasService |
31 | .obtenerCisternasPorFecha(idVehiculo); | 31 | .obtenerCisternasPorFecha(idVehiculo); |
32 | if(idRemito !== -1) { | 32 | if(idRemito !== -1) { |
33 | promesaRemito = focaModalDetalleCisternasService.obtenerRemitoById(idRemito); | 33 | promesaRemito = focaModalDetalleCisternasService.obtenerRemitoById(idRemito); |
34 | } | 34 | } |
35 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { | 35 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { |
36 | if (!validarCargas(res[1].data, res[2].data)) { | 36 | if (idRemito !== -1 && !validarCargas(res[1].data, res[2].data)) { |
37 | focaModalService.alert('Los artículos del remito exceden ' + | 37 | focaModalService.alert('Los artículos del remito exceden ' + |
38 | 'la cantidad disponible del vehiculo'); | 38 | 'la cantidad disponible del vehiculo'); |
39 | $uibModalInstance.close(); | 39 | $uibModalInstance.close(); |
40 | return; | 40 | return; |
41 | } | 41 | } |
42 | $scope.cargandoDatos = false; | 42 | $scope.cargandoDatos = false; |
43 | $scope.vehiculo = res[0].data; | 43 | $scope.vehiculo = res[0].data; |
44 | $scope.cisternas = res[1].data; | 44 | $scope.cisternas = res[1].data; |
45 | if(!$scope.cisternas.length) { | 45 | if(!$scope.cisternas.length) { |
46 | focaModalService.alert('El vehículo no tiene cisternas'); | 46 | focaModalService.alert('El vehículo no tiene cisternas'); |
47 | $uibModalInstance.dismiss(); | 47 | $uibModalInstance.dismiss(); |
48 | return; | 48 | return; |
49 | } | 49 | } |
50 | if(!res[2]) { | 50 | if(!res[2]) { |
51 | $scope.$digest(); | 51 | $scope.$digest(); |
52 | return; | 52 | return; |
53 | } | 53 | } |
54 | $scope.remito = res[2].data; | 54 | $scope.remito = res[2].data; |
55 | if($scope.remito.idUsuarioProceso) { | 55 | if($scope.remito.idUsuarioProceso) { |
56 | focaModalService.alert('Remito ya asignado'); | 56 | focaModalService.alert('Remito ya asignado'); |
57 | $uibModalInstance.close(); | 57 | $uibModalInstance.close(); |
58 | } | 58 | } |
59 | $scope.articulos = $scope.remito.articulosRemito; | 59 | $scope.articulos = $scope.remito.articulosRemito; |
60 | if(!$scope.articulos.length) { | 60 | if(!$scope.articulos.length) { |
61 | focaModalService.alert('El remito no tiene articulos'); | 61 | focaModalService.alert('El remito no tiene articulos'); |
62 | $uibModalInstance.dismiss(); | 62 | $uibModalInstance.dismiss(); |
63 | return; | 63 | return; |
64 | } | 64 | } |
65 | 65 | ||
66 | $scope.seleccionarArticulo($scope.articulos[0]); | 66 | $scope.seleccionarArticulo($scope.articulos[0]); |
67 | var tieneUsuario = $scope.cisternas.filter(function(cisterna) { | 67 | var tieneUsuario = $scope.cisternas.filter(function(cisterna) { |
68 | if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) { | 68 | if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) { |
69 | return cisterna.cisternaCarga.idUsuarioProceso !== | 69 | return cisterna.cisternaCarga.idUsuarioProceso !== |
70 | focaModalDetalleCisternasService.idUsuario; | 70 | focaModalDetalleCisternasService.idUsuario; |
71 | } | 71 | } |
72 | }); | 72 | }); |
73 | if(tieneUsuario.length) { | 73 | if(tieneUsuario.length) { |
74 | focaModalService.alert('Otro usario esta usando este vehículo'); | 74 | focaModalService.alert('Otro usario esta usando este vehículo'); |
75 | $uibModalInstance.close(); | 75 | $uibModalInstance.close(); |
76 | } | 76 | } |
77 | $scope.$digest(); | 77 | $scope.$digest(); |
78 | }); | 78 | }); |
79 | $scope.aceptar = function() { | 79 | $scope.aceptar = function() { |
80 | $scope.cargando = true; | 80 | $scope.cargando = true; |
81 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { | 81 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { |
82 | $scope.cisternasCarga[i].idUsuarioProceso = | 82 | $scope.cisternasCarga[i].idUsuarioProceso = |
83 | focaModalDetalleCisternasService.idUsuario; | 83 | focaModalDetalleCisternasService.idUsuario; |
84 | delete $scope.cisternasCarga[i].articulo; | 84 | delete $scope.cisternasCarga[i].articulo; |
85 | delete $scope.cisternasCarga[i].remitos; | ||
85 | } | 86 | } |
86 | var cisterna = { | 87 | var cisterna = { |
87 | cisternaMovimientos: cisternaMovimientos, | 88 | cisternaMovimientos: cisternaMovimientos, |
88 | cisternaCargas: $scope.cisternasCarga, | 89 | cisternaCargas: $scope.cisternasCarga, |
89 | idVehiculo: $scope.vehiculo.id, | 90 | idVehiculo: $scope.vehiculo.id, |
90 | fechaReparto: focaModalDetalleCisternasService.fecha | 91 | fechaReparto: focaModalDetalleCisternasService.fecha |
91 | }; | 92 | }; |
92 | if(!focaModalDetalleCisternasService.idUsuario) { | 93 | if(!focaModalDetalleCisternasService.idUsuario) { |
93 | focaModalService.alert('No logeado como vendedor'); | 94 | focaModalService.alert('No logeado como vendedor'); |
94 | $scope.cargando = false; | 95 | $scope.cargando = false; |
95 | return; | 96 | return; |
96 | } | 97 | } |
97 | focaModalDetalleCisternasService.guardarCisternas(cisterna, $scope.remito.id) | 98 | focaModalDetalleCisternasService.guardarCisternas(cisterna, $scope.remito.id) |
98 | .then(function() { | 99 | .then(function() { |
99 | $scope.cargando = false; | 100 | $scope.cargando = false; |
100 | $uibModalInstance.close(); | 101 | $uibModalInstance.close(); |
101 | }).catch(function(error) { | 102 | }).catch(function(error) { |
102 | $scope.cargando = false; | 103 | $scope.cargando = false; |
103 | $uibModalInstance.close(); | 104 | $uibModalInstance.close(); |
104 | if (error.status === 403) { | 105 | if (error.status === 403) { |
105 | focaModalService.alert('ERROR: ' + error.data); | 106 | focaModalService.alert('ERROR: ' + error.data); |
106 | return; | 107 | return; |
107 | } | 108 | } |
108 | focaModalService.alert('Hubo un error al cargar las cisternas'); | 109 | focaModalService.alert('Hubo un error al cargar las cisternas'); |
109 | }); | 110 | }); |
110 | }; | 111 | }; |
111 | $scope.cancelar = function() { | 112 | $scope.cancelar = function() { |
112 | $uibModalInstance.dismiss(); | 113 | $uibModalInstance.dismiss(); |
113 | }; | 114 | }; |
114 | $scope.cargarACisternas = function() { | 115 | $scope.cargarACisternas = function() { |
115 | for(var i = 0; i < $scope.cisternas.length; i++) { | 116 | for(var i = 0; i < $scope.cisternas.length; i++) { |
116 | var cisterna = $scope.cisternas[i]; | 117 | var cisterna = $scope.cisternas[i]; |
117 | var aCargar = parseFloat($scope.aCargar[i]); | 118 | var aCargar = parseFloat($scope.aCargar[i]); |
118 | var fechaReparto = focaModalDetalleCisternasService.fecha; | 119 | var fechaReparto = focaModalDetalleCisternasService.fecha; |
119 | //validaciones | 120 | //validaciones |
120 | if(!aCargar) { | 121 | if(!aCargar) { |
121 | continue; | 122 | continue; |
122 | } | 123 | } |
123 | //cargar | 124 | //cargar |
124 | if(cisterna.cisternaCarga.cantidad) { | 125 | if(cisterna.cisternaCarga.cantidad) { |
125 | cisterna.cisternaCarga.cantidad += aCargar; | 126 | cisterna.cisternaCarga.cantidad += aCargar; |
126 | }else { | 127 | }else { |
127 | cisterna.cisternaCarga.cantidad = aCargar; | 128 | cisterna.cisternaCarga.cantidad = aCargar; |
128 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; | 129 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; |
129 | } | 130 | } |
130 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; | 131 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; |
131 | 132 | ||
132 | cisterna.cisternaCarga.articulo = { | 133 | cisterna.cisternaCarga.articulo = { |
133 | DetArt: $scope.articuloSeleccionado.descripcion | 134 | DetArt: $scope.articuloSeleccionado.descripcion |
134 | }; | 135 | }; |
135 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] | 136 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] |
136 | .cargado = true; | 137 | .cargado = true; |
137 | 138 | ||
138 | $scope.calcularPorcentaje(cisterna); | 139 | $scope.calcularPorcentaje(cisterna); |
139 | //Guardar | 140 | //Guardar |
140 | var now = new Date(); | 141 | var now = new Date(); |
141 | var cisternaMovimiento = { | 142 | var cisternaMovimiento = { |
142 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 143 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
143 | cantidad: aCargar, | 144 | cantidad: aCargar, |
144 | metodo: 'carga', | 145 | metodo: 'carga', |
145 | idCisternaCarga: cisterna.cisternaCarga.id, | 146 | idCisternaCarga: cisterna.cisternaCarga.id, |
146 | idRemito: $scope.remito.id | 147 | idRemito: $scope.remito.id |
147 | }; | 148 | }; |
148 | cisterna.cisternaCarga.fechaReparto = fechaReparto; | 149 | cisterna.cisternaCarga.fechaReparto = fechaReparto; |
149 | cisterna.cisternaCarga.idCisterna = cisterna.id; | 150 | cisterna.cisternaCarga.idCisterna = cisterna.id; |
150 | $scope.cisternasCarga.push(cisterna.cisternaCarga); | 151 | $scope.cisternasCarga.push(cisterna.cisternaCarga); |
151 | cisternaMovimientos.push(cisternaMovimiento); | 152 | cisternaMovimientos.push(cisternaMovimiento); |
152 | } | 153 | } |
153 | var articuloSiguiente = $scope.articulos.filter( | 154 | var articuloSiguiente = $scope.articulos.filter( |
154 | function(filter) { | 155 | function(filter) { |
155 | return filter.cargado !== true; | 156 | return filter.cargado !== true; |
156 | } | 157 | } |
157 | ); | 158 | ); |
158 | if(articuloSiguiente.length > 0) { | 159 | if(articuloSiguiente.length > 0) { |
159 | $scope.seleccionarArticulo(articuloSiguiente[0]); | 160 | $scope.seleccionarArticulo(articuloSiguiente[0]); |
160 | } | 161 | } |
161 | }; | 162 | }; |
162 | $scope.calcularPorcentaje = function(cisterna) { | 163 | $scope.calcularPorcentaje = function(cisterna) { |
163 | if(!cisterna.cisternaCarga) { | 164 | if(!cisterna.cisternaCarga) { |
164 | cisterna.cisternaCarga = { | 165 | cisterna.cisternaCarga = { |
165 | cantidad: 0 | 166 | cantidad: 0 |
166 | }; | 167 | }; |
167 | } | 168 | } |
168 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / | 169 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / |
169 | cisterna.capacidad) + '%'; | 170 | cisterna.capacidad) + '%'; |
170 | var elementHtml = document.getElementById(cisterna.id); | 171 | var elementHtml = document.getElementById(cisterna.id); |
171 | if(elementHtml) { | 172 | if(elementHtml) { |
172 | elementHtml.style.width = porcentaje; | 173 | elementHtml.style.width = porcentaje; |
173 | } | 174 | } |
174 | }; | 175 | }; |
175 | 176 | ||
176 | $scope.seleccionarArticulo = function(articulo) { | 177 | $scope.seleccionarArticulo = function(articulo) { |
177 | $scope.articuloSeleccionado = articulo; | 178 | $scope.articuloSeleccionado = articulo; |
178 | $scope.cisternaDisponible(); | 179 | $scope.cisternaDisponible(); |
179 | $scope.autoCompletar(); | 180 | $scope.autoCompletar(); |
180 | $scope.actualizarArticulo(); | 181 | $scope.actualizarArticulo(); |
181 | }; | 182 | }; |
182 | 183 | ||
183 | $scope.actualizarArticulo = function() { | 184 | $scope.actualizarArticulo = function() { |
184 | $scope.articuloSeleccionado.cantidadCargada = 0; | 185 | $scope.articuloSeleccionado.cantidadCargada = 0; |
185 | for(var i = 0; i < $scope.aCargar.length; i++) { | 186 | for(var i = 0; i < $scope.aCargar.length; i++) { |
186 | $scope.articuloSeleccionado.cantidadCargada += | 187 | $scope.articuloSeleccionado.cantidadCargada += |
187 | parseFloat($scope.aCargar[i]) || 0; | 188 | parseFloat($scope.aCargar[i]) || 0; |
188 | } | 189 | } |
189 | }; | 190 | }; |
190 | 191 | ||
191 | $scope.autoCompletar = function() { | 192 | $scope.autoCompletar = function() { |
192 | var arrayMismoProducto = []; | 193 | var arrayMismoProducto = []; |
193 | var arrayVacioProducto = []; | 194 | var arrayVacioProducto = []; |
194 | for(var i = 0; i < $scope.cisternas.length; i++) { | 195 | for(var i = 0; i < $scope.cisternas.length; i++) { |
195 | var cisterna = $scope.cisternas[i]; | 196 | var cisterna = $scope.cisternas[i]; |
196 | cisterna.posicion = i; | 197 | cisterna.posicion = i; |
197 | console.info(i, cisterna.posicion); | 198 | console.info(i, cisterna.posicion); |
198 | if (!cisterna.disabled && cisterna.disponible > 0) { | 199 | if (!cisterna.disabled && cisterna.disponible > 0) { |
199 | if (cisterna.cisternaCarga) { | 200 | if (cisterna.cisternaCarga) { |
200 | arrayMismoProducto.push(cisterna); | 201 | arrayMismoProducto.push(cisterna); |
201 | } else { | 202 | } else { |
202 | arrayVacioProducto.push(cisterna); | 203 | arrayVacioProducto.push(cisterna); |
203 | } | 204 | } |
204 | } | 205 | } |
205 | } | 206 | } |
206 | 207 | ||
207 | arrayMismoProducto.sort(function(a,b) { | 208 | arrayMismoProducto.sort(function(a,b) { |
208 | return a.disponible - b.disponible; | 209 | return a.disponible - b.disponible; |
209 | }); | 210 | }); |
210 | 211 | ||
211 | var cisternas = arrayMismoProducto.concat(arrayVacioProducto); | 212 | var cisternas = arrayMismoProducto.concat(arrayVacioProducto); |
212 | 213 | ||
213 | for (var j = 0; j < cisternas.length; j++) { | 214 | for (var j = 0; j < cisternas.length; j++) { |
214 | var aCargar = $scope.articuloSeleccionado.cantidad - | 215 | var aCargar = $scope.articuloSeleccionado.cantidad - |
215 | ($scope.articuloSeleccionado.cantidadCargada || 0); | 216 | ($scope.articuloSeleccionado.cantidadCargada || 0); |
216 | 217 | ||
217 | if(aCargar > cisternas[j].disponible) { | 218 | if(aCargar > cisternas[j].disponible) { |
218 | aCargar = cisternas[j].disponible; | 219 | aCargar = cisternas[j].disponible; |
219 | } | 220 | } |
220 | 221 | ||
221 | if(aCargar > 0) { | 222 | if(aCargar > 0) { |
222 | $scope.aCargar[cisternas[j].posicion] = aCargar; | 223 | $scope.aCargar[cisternas[j].posicion] = aCargar; |
223 | $scope.actualizarArticulo(); | 224 | $scope.actualizarArticulo(); |
224 | } | 225 | } |
225 | } | 226 | } |
226 | }; | 227 | }; |
227 | $scope.cisternaDisponible = function() { | 228 | $scope.cisternaDisponible = function() { |
228 | for(var i = 0; i < $scope.cisternas.length; i++) { | 229 | for(var i = 0; i < $scope.cisternas.length; i++) { |
229 | //Puede meter un porcentaje del total | 230 | //Puede meter un porcentaje del total |
230 | // if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { | 231 | // if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { |
231 | // $scope.cisternas[i].disabled = true; | 232 | // $scope.cisternas[i].disabled = true; |
232 | // continue; | 233 | // continue; |
233 | // } | 234 | // } |
234 | if($scope.cisternas[i].cisternaCarga && | 235 | if($scope.cisternas[i].cisternaCarga && |
235 | $scope.cisternas[i].cisternaCarga.idProducto && | 236 | $scope.cisternas[i].cisternaCarga.idProducto && |
236 | $scope.articuloSeleccionado.idArticulo !== | 237 | $scope.articuloSeleccionado.idArticulo !== |
237 | $scope.cisternas[i].cisternaCarga.idProducto) | 238 | $scope.cisternas[i].cisternaCarga.idProducto) |
238 | { | 239 | { |
239 | $scope.cisternas[i].disabled = true; | 240 | $scope.cisternas[i].disabled = true; |
240 | continue; | 241 | continue; |
241 | } | 242 | } |
242 | $scope.cisternas[i].disabled = false; | 243 | $scope.cisternas[i].disabled = false; |
243 | } | 244 | } |
244 | }; | 245 | }; |
245 | $scope.rellenarInput = function(input, cisterna) { | 246 | $scope.rellenarInput = function(input, cisterna) { |
246 | if(!$scope.articuloSeleccionado) return; | 247 | if(!$scope.articuloSeleccionado) return; |
247 | if($scope.articuloSeleccionado.cantidad - | 248 | if($scope.articuloSeleccionado.cantidad - |
248 | $scope.articuloSeleccionado.cantidadCargada === 0) { | 249 | $scope.articuloSeleccionado.cantidadCargada === 0) { |
249 | return input; | 250 | return input; |
250 | } | 251 | } |
251 | if(!input) input = 0; | 252 | if(!input) input = 0; |
252 | input = parseFloat(input); | 253 | input = parseFloat(input); |
253 | input += parseFloat($scope.articuloSeleccionado.cantidad - | 254 | input += parseFloat($scope.articuloSeleccionado.cantidad - |
254 | $scope.articuloSeleccionado.cantidadCargada); | 255 | $scope.articuloSeleccionado.cantidadCargada); |
255 | if(input <= 0) return; | 256 | if(input <= 0) return; |
256 | if(input > cisterna.disponible) { | 257 | if(input > cisterna.disponible) { |
257 | input = cisterna.disponible; | 258 | input = cisterna.disponible; |
258 | } | 259 | } |
259 | return input; | 260 | return input; |
260 | }; | 261 | }; |
261 | $scope.distribucionDisponible = function() { | 262 | $scope.distribucionDisponible = function() { |
262 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - | 263 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - |
263 | $scope.articuloSeleccionado.cantidadCargada !== 0 || | 264 | $scope.articuloSeleccionado.cantidadCargada !== 0 || |
264 | !$scope.tieneArticulosPendientes()) { | 265 | !$scope.tieneArticulosPendientes()) { |
265 | return false; | 266 | return false; |
266 | } | 267 | } |
267 | for(var i = 0; i < $scope.cisternas.length; i++) { | 268 | for(var i = 0; i < $scope.cisternas.length; i++) { |
268 | if($scope.aCargar[i] > $scope.cisternas[i].disponible) { | 269 | if($scope.aCargar[i] > $scope.cisternas[i].disponible) { |
269 | return false; | 270 | return false; |
270 | } | 271 | } |
271 | } | 272 | } |
272 | return true; | 273 | return true; |
273 | }; | 274 | }; |
274 | $scope.tieneArticulosPendientes = function() { | 275 | $scope.tieneArticulosPendientes = function() { |
275 | var algunValorNegativo = $scope.aCargar.filter(function(p) { | 276 | var algunValorNegativo = $scope.aCargar.filter(function(p) { |
276 | return p < 0; | 277 | return p < 0; |
277 | }); | 278 | }); |
278 | if(algunValorNegativo.length) { | 279 | if(algunValorNegativo.length) { |
279 | return false; | 280 | return false; |
280 | } | 281 | } |
281 | var articulosDescargados = $scope.articulos.filter(function(filter) { | 282 | var articulosDescargados = $scope.articulos.filter(function(filter) { |
282 | return filter.cargado === true; | 283 | return filter.cargado === true; |
283 | }); | 284 | }); |
284 | if(articulosDescargados.length === $scope.articulos.length) { | 285 | if(articulosDescargados.length === $scope.articulos.length) { |
285 | $scope.aCargar = []; | 286 | $scope.aCargar = []; |
286 | return false; | 287 | return false; |
287 | } | 288 | } |
288 | return true; | 289 | return true; |
289 | }; | 290 | }; |
290 | 291 | ||
291 | $scope.verRemitos = function(data) { | 292 | $scope.verRemitos = function(data) { |
292 | var parametrosModal = { | 293 | var parametrosModal = { |
293 | titulo: 'Remitos cargados', | 294 | titulo: 'Remitos cargados', |
294 | data: data, | 295 | data: data, |
295 | soloMostrar: true, | 296 | soloMostrar: true, |
296 | columnas: [ | 297 | columnas: [ |
297 | { | 298 | { |
298 | nombre: 'Fecha', | 299 | nombre: 'Fecha', |
299 | propiedad: 'fechaRemito', | 300 | propiedad: 'fechaRemito', |
300 | filtro: { | 301 | filtro: { |
301 | nombre: 'date', | 302 | nombre: 'date', |
302 | parametro:'dd/MM/yyyy' | 303 | parametro:'dd/MM/yyyy' |
303 | } | 304 | } |
304 | }, | 305 | }, |
305 | { | 306 | { |
306 | nombre: 'Cliente', | 307 | nombre: 'Cliente', |
307 | propiedad: 'nombreCliente' | 308 | propiedad: 'nombreCliente' |
308 | }, | 309 | }, |
309 | { | 310 | { |
310 | nombre: 'Comprobante', | 311 | nombre: 'Comprobante', |
311 | propiedad: ['sucursal', 'numeroRemito'], | 312 | propiedad: ['sucursal', 'numeroRemito'], |
312 | filtro: { | 313 | filtro: { |
313 | nombre: 'comprobante' | 314 | nombre: 'comprobante' |
314 | } | 315 | } |
315 | }, | 316 | }, |
316 | { | 317 | { |
317 | nombre: 'Importe', | 318 | nombre: 'Importe', |
318 | propiedad: 'total' | 319 | propiedad: 'total' |
319 | } | 320 | } |
320 | ] | 321 | ] |
321 | }; | 322 | }; |
322 | focaModalService.modal(parametrosModal).then(function(transportista) { | 323 | focaModalService.modal(parametrosModal).then(function(transportista) { |
323 | $scope.selectVehiculo(transportista.COD, transportista.NOM); | 324 | $scope.selectVehiculo(transportista.COD, transportista.NOM); |
324 | }); | 325 | }); |
325 | }; | 326 | }; |
326 | function validarCargas(cis, remito) { | 327 | function validarCargas(cis, remito) { |
327 | var result = true; | 328 | var result = true; |
328 | var cisternas = angular.copy(cis); | 329 | var cisternas = angular.copy(cis); |
329 | var articulos = angular.copy(remito.articulosRemito); | 330 | var articulos = angular.copy(remito.articulosRemito); |
330 | 331 | ||
331 | cisternas.sort(ordenarCisternas); | 332 | cisternas.sort(ordenarCisternas); |
332 | 333 | ||
333 | articulos.forEach(function(articulo) { | 334 | articulos.forEach(function(articulo) { |
334 | cisternas.forEach(function(cisterna) { | 335 | cisternas.forEach(function(cisterna) { |
335 | //SI LA CISTERNA ESTA VACIA O | 336 | //SI LA CISTERNA ESTA VACIA O |
336 | //SI LA CISTERNA TIENE EL MISMO PRODUCTO | 337 | //SI LA CISTERNA TIENE EL MISMO PRODUCTO |
337 | //Y AUN TIENE LUGAR | 338 | //Y AUN TIENE LUGAR |
338 | if(cisterna.capacidad === cisterna.disponible || | 339 | if(cisterna.capacidad === cisterna.disponible || |
339 | (cisterna.cisternaCarga.idProducto === articulo.idArticulo && | 340 | (cisterna.cisternaCarga.idProducto === articulo.idArticulo && |
340 | cisterna.disponible > 0)){ | 341 | cisterna.disponible > 0)){ |
341 | var restante = articulo.cantidad - cisterna.disponible; | 342 | var restante = articulo.cantidad - cisterna.disponible; |
342 | 343 | ||
343 | if (restante > 0) { | 344 | if (restante > 0) { |
344 | cisterna.disponible = 0; | 345 | cisterna.disponible = 0; |
345 | articulo.cantidad = restante; | 346 | articulo.cantidad = restante; |
346 | } else { | 347 | } else { |
347 | cisterna.disponible = restante * -1; | 348 | cisterna.disponible = restante * -1; |
348 | articulo.cantidad = 0; | 349 | articulo.cantidad = 0; |
349 | } | 350 | } |
350 | 351 | ||
351 | } | 352 | } |
352 | }); | 353 | }); |
353 | //SI AUN RESTA CANTIDAD EN EL ARTICULO | 354 | //SI AUN RESTA CANTIDAD EN EL ARTICULO |
354 | if (articulo.cantidad > 0) result = false; | 355 | if (articulo.cantidad > 0) result = false; |
355 | }); | 356 | }); |
356 | return result; | 357 | return result; |
357 | } | 358 | } |
358 | function ordenarCisternas(a, b) { | 359 | function ordenarCisternas(a, b) { |
359 | //DEJA LAS CISTERNAS CON CARGA PRIMERO PARA VALIDAR LAS CARGAS CORRECTAMENTE | 360 | //DEJA LAS CISTERNAS CON CARGA PRIMERO PARA VALIDAR LAS CARGAS CORRECTAMENTE |
360 | if (a.cisternaCarga && !b.cisternaCarga) { | 361 | if (a.cisternaCarga && !b.cisternaCarga) { |
361 | return -1; | 362 | return -1; |
362 | } else if (!a.cisternaCarga && b.cisternaCarga) { | 363 | } else if (!a.cisternaCarga && b.cisternaCarga) { |
363 | return 1; | 364 | return 1; |
364 | } else { | 365 | } else { |
365 | return 0; | 366 | return 0; |
366 | } | 367 | } |
367 | } | 368 | } |
368 | }]); | 369 | }]); |
369 | 370 |
src/views/foca-detalle-vehiculo.html
1 | <div class="modal-header"> | 1 | <div class="modal-header"> |
2 | <h4>Detalle de carga</h4> | 2 | <h4>Detalle de carga</h4> |
3 | Transportista | 3 | Transportista |
4 | <strong ng-bind="vehiculo.transportista.COD"></strong> | 4 | <strong ng-bind="vehiculo.transportista.COD"></strong> |
5 | <strong ng-bind="vehiculo.transportista.NOM"></strong> | 5 | <strong ng-bind="vehiculo.transportista.NOM"></strong> |
6 | Unidad <strong ng-bind="vehiculo.codigo"></strong> | 6 | Unidad <strong ng-bind="vehiculo.codigo"></strong> |
7 | Tractor <strong ng-bind="vehiculo.tractor"></strong> | 7 | Tractor <strong ng-bind="vehiculo.tractor"></strong> |
8 | <br> | 8 | <br> |
9 | <div ng-show="idRemito !== -1"> | 9 | <div ng-show="idRemito !== -1"> |
10 | <span>Remito Nº</span> | 10 | <span>Remito Nº</span> |
11 | <strong ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"></strong> | 11 | <strong ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"></strong> |
12 | <span>, Fecha</span> | 12 | <span>, Fecha</span> |
13 | <strong ng-bind="remito.fechaRemito | date: 'dd/MM/yyyy HH:mm'"></strong> | 13 | <strong ng-bind="remito.fechaRemito | date: 'dd/MM/yyyy HH:mm'"></strong> |
14 | <span>, Cliente</span> | 14 | <span>, Cliente</span> |
15 | <strong ng-bind="remito.nombreCliente"></strong> | 15 | <strong ng-bind="remito.nombreCliente"></strong> |
16 | <span>, Domicilio entrega</span> | 16 | <span>, Domicilio entrega</span> |
17 | <strong ng-bind="remito.domicilioStamp"></strong> | 17 | <strong ng-bind="remito.domicilioStamp"></strong> |
18 | </div> | 18 | </div> |
19 | </div> | 19 | </div> |
20 | <div class="modal-body"> | 20 | <div class="modal-body"> |
21 | <div> | 21 | <div> |
22 | <table class="table table-sm" ng-show="idRemito !== -1"> | 22 | <table class="table table-sm" ng-show="idRemito !== -1"> |
23 | <thead> | 23 | <thead> |
24 | <tr> | 24 | <tr> |
25 | <th></th> | 25 | <th></th> |
26 | <th>Articulo</th> | 26 | <th>Articulo</th> |
27 | <th>Cantidad</th> | 27 | <th>Cantidad</th> |
28 | <th>Cargado</th> | 28 | <th>Cargado</th> |
29 | <th>Resta asignar</th> | 29 | <th>Resta asignar</th> |
30 | </tr> | 30 | </tr> |
31 | </thead> | 31 | </thead> |
32 | <tbody> | 32 | <tbody> |
33 | <tr ng-repeat="(key, articulo) in articulos"> | 33 | <tr ng-repeat="(key, articulo) in articulos"> |
34 | <td><input | 34 | <td><input |
35 | type="radio" | 35 | type="radio" |
36 | name="articuloRadio" | 36 | name="articuloRadio" |
37 | id="{{'articulo' + articulo.id}}" | 37 | id="{{'articulo' + articulo.id}}" |
38 | ng-checked="articuloSeleccionado.id === articulo.id" | 38 | ng-checked="articuloSeleccionado.id === articulo.id" |
39 | ng-disabled="articulo.cargado" | 39 | ng-disabled="articulo.cargado" |
40 | ng-click="seleccionarArticulo(articulo)" | 40 | ng-click="seleccionarArticulo(articulo)" |
41 | ></td> | 41 | ></td> |
42 | <td ng-bind="articulo.descripcion"></td> | 42 | <td ng-bind="articulo.descripcion"></td> |
43 | <td ng-bind="articulo.cantidad"></td> | 43 | <td ng-bind="articulo.cantidad"></td> |
44 | <td ng-bind="articulo.cantidadCargada || 0"></td> | 44 | <td ng-bind="articulo.cantidadCargada || 0"></td> |
45 | <td ng-bind="articulo.cantidad - articulo.cantidadCargada"></td> | 45 | <td ng-bind="articulo.cantidad - articulo.cantidadCargada"></td> |
46 | </tr> | 46 | </tr> |
47 | </tbody> | 47 | </tbody> |
48 | </table> | 48 | </table> |
49 | <table class="table table-sm" ladda="cargandoDatos" data-spinner-color="#FF0000"> | 49 | <table class="table table-sm" ladda="cargandoDatos" data-spinner-color="#FF0000"> |
50 | <thead> | 50 | <thead> |
51 | <tr> | 51 | <tr> |
52 | <th width="10%">Cisterna</th> | 52 | <th width="10%">Cisterna</th> |
53 | <th>Capacidad</th> | 53 | <th>Capacidad</th> |
54 | <th>Articulo cargado</th> | 54 | <th>Articulo cargado</th> |
55 | <th width="20%">Por asignar</th> | 55 | <th width="20%">Por asignar</th> |
56 | <th>Cargado / Capacidad Disponible</th> | 56 | <th>Cargado / Capacidad Disponible</th> |
57 | <th></th> | 57 | <th></th> |
58 | </tr> | 58 | </tr> |
59 | </thead> | 59 | </thead> |
60 | <tbody> | 60 | <tbody> |
61 | <tr ng-repeat="(key, cisterna) in cisternas"> | 61 | <tr ng-repeat="(key, cisterna) in cisternas"> |
62 | <td class="py-3" ng-bind="cisterna.codigo"></td> | 62 | <td class="py-3" ng-bind="cisterna.codigo"></td> |
63 | <td class="py-3" ng-bind="cisterna.capacidad"></td> | 63 | <td class="py-3" ng-bind="cisterna.capacidad"></td> |
64 | <td class="py-3" ng-bind="cisterna.cisternaCarga.articulo.DetArt || 'Sin asignar'"></td> | 64 | <td class="py-3" ng-bind="cisterna.cisternaCarga.articulo.DetArt || 'Sin asignar'"></td> |
65 | <td ng-if="idRemito != -1"> | 65 | <td ng-if="idRemito != -1"> |
66 | <input | 66 | <input |
67 | class="form-control" | 67 | class="form-control" |
68 | foca-tipo-input | 68 | foca-tipo-input |
69 | foca-teclado | 69 | foca-teclado |
70 | placeholder="A cargar..." | 70 | placeholder="A cargar..." |
71 | ng-model="aCargar[key]" | 71 | ng-model="aCargar[key]" |
72 | ng-disabled="cisterna.disabled || !tieneArticulosPendientes()" | 72 | ng-disabled="cisterna.disabled || !tieneArticulosPendientes()" |
73 | ng-focus="aCargar[key] = rellenarInput(aCargar[key], cisterna); actualizarArticulo()" | 73 | ng-focus="aCargar[key] = rellenarInput(aCargar[key], cisterna); actualizarArticulo()" |
74 | ng-change="actualizarArticulo()" | 74 | ng-change="actualizarArticulo()" |
75 | > | 75 | > |
76 | </td> | 76 | </td> |
77 | <td ng-if="idRemito == -1"> | 77 | <td ng-if="idRemito == -1"> |
78 | <input | 78 | <input |
79 | class="form-control" | 79 | class="form-control" |
80 | placeholder="A cargar..." | 80 | placeholder="A cargar..." |
81 | readonly> | 81 | readonly> |
82 | </td> | 82 | </td> |
83 | <td><div class="progress foca-alto-progress pl-0 pr-0 mt-1"> | 83 | <td><div class="progress foca-alto-progress pl-0 pr-0 mt-1"> |
84 | <strong | 84 | <strong |
85 | class="mt-2 col-4 text-center position-absolute" | 85 | class="mt-2 col-4 text-center position-absolute" |
86 | ng-bind="(cisterna.cisternaCarga.cantidad || 0) + '/' + | 86 | ng-bind="(cisterna.cisternaCarga.cantidad || 0) + '/' + |
87 | (cisterna.capacidad - cisterna.cisternaCarga.cantidad)"> | 87 | (cisterna.capacidad - cisterna.cisternaCarga.cantidad)"> |
88 | </strong> | 88 | </strong> |
89 | <div | 89 | <div |
90 | id="{{cisterna.id}}" | 90 | id="{{cisterna.id}}" |
91 | class="progress-bar" | 91 | class="progress-bar" |
92 | role="progressbar" | 92 | role="progressbar" |
93 | aria-valuemin="0" | 93 | aria-valuemin="0" |
94 | aria-valuemax="{{cisterna.capacidad}}" | 94 | aria-valuemax="{{cisterna.capacidad}}" |
95 | ng-style="{'width':'{{calcularPorcentaje(cisterna)}}'}"> | 95 | ng-style="{'width':'{{calcularPorcentaje(cisterna)}}'}"> |
96 | </div> | 96 | </div> |
97 | </div> | 97 | </div> |
98 | </td> | 98 | </td> |
99 | <td> | 99 | <td> |
100 | <button | 100 | <button |
101 | class="btn btn-outline-secondary" | 101 | class="btn btn-outline-secondary" |
102 | ng-disabled="!cisterna.cisternaCarga.remitos.length" | ||
102 | ng-click="verRemitos(cisterna.cisternaCarga.remitos)"> | 103 | ng-click="verRemitos(cisterna.cisternaCarga.remitos)"> |
103 | <i class="fa fa-info" aria-hidden="true"></i> | 104 | <i class="fa fa-info" aria-hidden="true"></i> |
104 | </button> | 105 | </button> |
105 | </td> | 106 | </td> |
106 | </tr> | 107 | </tr> |
107 | </tbody> | 108 | </tbody> |
108 | </table> | 109 | </table> |
109 | <div class="col-12"> | 110 | <div class="col-12"> |
110 | <button | 111 | <button |
111 | class="form-control btn btn-success" | 112 | class="form-control btn btn-success" |
112 | ladda="cargando" | 113 | ladda="cargando" |
113 | data-spinner-color="#FF0000" | 114 | data-spinner-color="#FF0000" |
114 | type="button" | 115 | type="button" |
115 | ng-disabled="!distribucionDisponible()" | 116 | ng-disabled="!distribucionDisponible()" |
116 | ng-class="{'btn-light': !distribucionDisponible()}" | 117 | ng-class="{'btn-light': !distribucionDisponible()}" |
117 | ng-click="cargarACisternas(vehiculo)" | 118 | ng-click="cargarACisternas(vehiculo)" |
118 | foca-focus="distribucionDisponible()"> | 119 | foca-focus="distribucionDisponible()"> |
119 | Aplicar distribución de cargas | 120 | Aplicar distribución de cargas |
120 | </button> | 121 | </button> |
121 | </div> | 122 | </div> |
122 | </div> | 123 | </div> |
123 | </div> | 124 | </div> |
124 | <div class="modal-footer py-1"> | 125 | <div class="modal-footer py-1"> |
125 | <button | 126 | <button |
126 | class="btn btn-sm btn-secondary" | 127 | class="btn btn-sm btn-secondary" |
127 | ladda="cargando" | 128 | ladda="cargando" |
128 | type="button" | 129 | type="button" |
129 | ng-click="cancelar()">Cancelar</button> | 130 | ng-click="cancelar()">Cancelar</button> |
130 | <button | 131 | <button |
131 | class="btn btn-sm btn-primary" | 132 | class="btn btn-sm btn-primary" |
132 | ladda="cargando" | 133 | ladda="cargando" |
133 | type="button" | 134 | type="button" |
134 | ng-click="aceptar()" | 135 | ng-click="aceptar()" |
135 | ng-disabled="tieneArticulosPendientes() || idRemito === -1" | 136 | ng-disabled="tieneArticulosPendientes() || idRemito === -1" |
136 | foca-focus="!tieneArticulosPendientes() && idRemito !== -1">Cargar</button> | 137 | foca-focus="!tieneArticulosPendientes() && idRemito !== -1">Cargar</button> |
137 | </div> | 138 | </div> |
138 | 139 |