Commit f5040c914a95b81484677553c515c557c78a6c2c
1 parent
342c7663c4
Exists in
master
móvil
Showing
1 changed file
with
4 additions
and
3 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 (idRemito !== -1 && !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 | var error = 'Los artículos del remito exceden la cantidad disponible del ' + |
| 38 | 'la cantidad disponible del vehiculo'); | 38 | 'vehiculo'; |
| 39 | $uibModalInstance.close(true); | 39 | $uibModalInstance.dismiss(error); |
| 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 | delete $scope.cisternasCarga[i].remitos; |
| 86 | } | 86 | } |
| 87 | var cisterna = { | 87 | var cisterna = { |
| 88 | cisternaMovimientos: cisternaMovimientos, | 88 | cisternaMovimientos: cisternaMovimientos, |
| 89 | cisternaCargas: $scope.cisternasCarga, | 89 | cisternaCargas: $scope.cisternasCarga, |
| 90 | idVehiculo: $scope.vehiculo.id, | 90 | idVehiculo: $scope.vehiculo.id, |
| 91 | fechaReparto: focaModalDetalleCisternasService.fecha | 91 | fechaReparto: focaModalDetalleCisternasService.fecha |
| 92 | }; | 92 | }; |
| 93 | if(!focaModalDetalleCisternasService.idUsuario) { | 93 | if(!focaModalDetalleCisternasService.idUsuario) { |
| 94 | focaModalService.alert('No logeado como vendedor'); | 94 | focaModalService.alert('No logeado como vendedor'); |
| 95 | $scope.cargando = false; | 95 | $scope.cargando = false; |
| 96 | return; | 96 | return; |
| 97 | } | 97 | } |
| 98 | focaModalDetalleCisternasService.guardarCisternas(cisterna, $scope.remito.id) | 98 | focaModalDetalleCisternasService.guardarCisternas(cisterna, $scope.remito.id) |
| 99 | .then(function() { | 99 | .then(function() { |
| 100 | $scope.cargando = false; | 100 | $scope.cargando = false; |
| 101 | $uibModalInstance.close(); | 101 | $uibModalInstance.close(); |
| 102 | }).catch(function(error) { | 102 | }).catch(function(error) { |
| 103 | $scope.cargando = false; | 103 | $scope.cargando = false; |
| 104 | $uibModalInstance.close(); | 104 | $uibModalInstance.close(); |
| 105 | if (error.status === 403) { | 105 | if (error.status === 403) { |
| 106 | focaModalService.alert('ERROR: ' + error.data); | 106 | focaModalService.alert('ERROR: ' + error.data); |
| 107 | return; | 107 | return; |
| 108 | } | 108 | } |
| 109 | focaModalService.alert('Hubo un error al cargar las cisternas'); | 109 | focaModalService.alert('Hubo un error al cargar las cisternas'); |
| 110 | }); | 110 | }); |
| 111 | }; | 111 | }; |
| 112 | $scope.cancelar = function() { | 112 | $scope.cancelar = function() { |
| 113 | $uibModalInstance.dismiss(); | 113 | $uibModalInstance.dismiss(); |
| 114 | }; | 114 | }; |
| 115 | $scope.cargarACisternas = function() { | 115 | $scope.cargarACisternas = function() { |
| 116 | for(var i = 0; i < $scope.cisternas.length; i++) { | 116 | for(var i = 0; i < $scope.cisternas.length; i++) { |
| 117 | var cisterna = $scope.cisternas[i]; | 117 | var cisterna = $scope.cisternas[i]; |
| 118 | var aCargar = parseFloat($scope.aCargar[i]); | 118 | var aCargar = parseFloat($scope.aCargar[i]); |
| 119 | var fechaReparto = focaModalDetalleCisternasService.fecha; | 119 | var fechaReparto = focaModalDetalleCisternasService.fecha; |
| 120 | //validaciones | 120 | //validaciones |
| 121 | if(!aCargar) { | 121 | if(!aCargar) { |
| 122 | continue; | 122 | continue; |
| 123 | } | 123 | } |
| 124 | //cargar | 124 | //cargar |
| 125 | if(cisterna.cisternaCarga.cantidad) { | 125 | if(cisterna.cisternaCarga.cantidad) { |
| 126 | cisterna.cisternaCarga.cantidad += aCargar; | 126 | cisterna.cisternaCarga.cantidad += aCargar; |
| 127 | }else { | 127 | }else { |
| 128 | cisterna.cisternaCarga.cantidad = aCargar; | 128 | cisterna.cisternaCarga.cantidad = aCargar; |
| 129 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; | 129 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; |
| 130 | } | 130 | } |
| 131 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; | 131 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; |
| 132 | 132 | ||
| 133 | cisterna.cisternaCarga.articulo = { | 133 | cisterna.cisternaCarga.articulo = { |
| 134 | DetArt: $scope.articuloSeleccionado.descripcion | 134 | DetArt: $scope.articuloSeleccionado.descripcion |
| 135 | }; | 135 | }; |
| 136 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] | 136 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] |
| 137 | .cargado = true; | 137 | .cargado = true; |
| 138 | 138 | ||
| 139 | $scope.calcularPorcentaje(cisterna); | 139 | $scope.calcularPorcentaje(cisterna); |
| 140 | //Guardar | 140 | //Guardar |
| 141 | var now = new Date(); | 141 | var now = new Date(); |
| 142 | var cisternaMovimiento = { | 142 | var cisternaMovimiento = { |
| 143 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 143 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
| 144 | cantidad: aCargar, | 144 | cantidad: aCargar, |
| 145 | metodo: 'carga', | 145 | metodo: 'carga', |
| 146 | idCisternaCarga: cisterna.cisternaCarga.id, | 146 | idCisternaCarga: cisterna.cisternaCarga.id, |
| 147 | idRemito: $scope.remito.id | 147 | idRemito: $scope.remito.id |
| 148 | }; | 148 | }; |
| 149 | cisterna.cisternaCarga.fechaReparto = fechaReparto; | 149 | cisterna.cisternaCarga.fechaReparto = fechaReparto; |
| 150 | cisterna.cisternaCarga.idCisterna = cisterna.id; | 150 | cisterna.cisternaCarga.idCisterna = cisterna.id; |
| 151 | $scope.cisternasCarga.push(cisterna.cisternaCarga); | 151 | $scope.cisternasCarga.push(cisterna.cisternaCarga); |
| 152 | cisternaMovimientos.push(cisternaMovimiento); | 152 | cisternaMovimientos.push(cisternaMovimiento); |
| 153 | } | 153 | } |
| 154 | var articuloSiguiente = $scope.articulos.filter( | 154 | var articuloSiguiente = $scope.articulos.filter( |
| 155 | function(filter) { | 155 | function(filter) { |
| 156 | return filter.cargado !== true; | 156 | return filter.cargado !== true; |
| 157 | } | 157 | } |
| 158 | ); | 158 | ); |
| 159 | if(articuloSiguiente.length > 0) { | 159 | if(articuloSiguiente.length > 0) { |
| 160 | $scope.seleccionarArticulo(articuloSiguiente[0]); | 160 | $scope.seleccionarArticulo(articuloSiguiente[0]); |
| 161 | } | 161 | } |
| 162 | }; | 162 | }; |
| 163 | $scope.calcularPorcentaje = function(cisterna) { | 163 | $scope.calcularPorcentaje = function(cisterna) { |
| 164 | if(!cisterna.cisternaCarga) { | 164 | if(!cisterna.cisternaCarga) { |
| 165 | cisterna.cisternaCarga = { | 165 | cisterna.cisternaCarga = { |
| 166 | cantidad: 0 | 166 | cantidad: 0 |
| 167 | }; | 167 | }; |
| 168 | } | 168 | } |
| 169 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / | 169 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / |
| 170 | cisterna.capacidad) + '%'; | 170 | cisterna.capacidad) + '%'; |
| 171 | var elementHtml = document.getElementById(cisterna.id); | 171 | var elementHtml = document.getElementById(cisterna.id); |
| 172 | if(elementHtml) { | 172 | if(elementHtml) { |
| 173 | elementHtml.style.width = porcentaje; | 173 | elementHtml.style.width = porcentaje; |
| 174 | } | 174 | } |
| 175 | }; | 175 | }; |
| 176 | 176 | ||
| 177 | $scope.seleccionarArticulo = function(articulo) { | 177 | $scope.seleccionarArticulo = function(articulo) { |
| 178 | $scope.articuloSeleccionado = articulo; | 178 | $scope.articuloSeleccionado = articulo; |
| 179 | $scope.cisternaDisponible(); | 179 | $scope.cisternaDisponible(); |
| 180 | $scope.autoCompletar(); | 180 | $scope.autoCompletar(); |
| 181 | $scope.actualizarArticulo(); | 181 | $scope.actualizarArticulo(); |
| 182 | }; | 182 | }; |
| 183 | 183 | ||
| 184 | $scope.actualizarArticulo = function() { | 184 | $scope.actualizarArticulo = function() { |
| 185 | $scope.articuloSeleccionado.cantidadCargada = 0; | 185 | $scope.articuloSeleccionado.cantidadCargada = 0; |
| 186 | for(var i = 0; i < $scope.aCargar.length; i++) { | 186 | for(var i = 0; i < $scope.aCargar.length; i++) { |
| 187 | $scope.articuloSeleccionado.cantidadCargada += | 187 | $scope.articuloSeleccionado.cantidadCargada += |
| 188 | parseFloat($scope.aCargar[i]) || 0; | 188 | parseFloat($scope.aCargar[i]) || 0; |
| 189 | } | 189 | } |
| 190 | }; | 190 | }; |
| 191 | 191 | ||
| 192 | $scope.autoCompletar = function() { | 192 | $scope.autoCompletar = function() { |
| 193 | var arrayMismoProducto = []; | 193 | var arrayMismoProducto = []; |
| 194 | var arrayVacioProducto = []; | 194 | var arrayVacioProducto = []; |
| 195 | for(var i = 0; i < $scope.cisternas.length; i++) { | 195 | for(var i = 0; i < $scope.cisternas.length; i++) { |
| 196 | var cisterna = $scope.cisternas[i]; | 196 | var cisterna = $scope.cisternas[i]; |
| 197 | cisterna.posicion = i; | 197 | cisterna.posicion = i; |
| 198 | console.info(i, cisterna.posicion); | 198 | console.info(i, cisterna.posicion); |
| 199 | if (!cisterna.disabled && cisterna.disponible > 0) { | 199 | if (!cisterna.disabled && cisterna.disponible > 0) { |
| 200 | if (cisterna.cisternaCarga) { | 200 | if (cisterna.cisternaCarga) { |
| 201 | arrayMismoProducto.push(cisterna); | 201 | arrayMismoProducto.push(cisterna); |
| 202 | } else { | 202 | } else { |
| 203 | arrayVacioProducto.push(cisterna); | 203 | arrayVacioProducto.push(cisterna); |
| 204 | } | 204 | } |
| 205 | } | 205 | } |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | arrayMismoProducto.sort(function(a,b) { | 208 | arrayMismoProducto.sort(function(a,b) { |
| 209 | return a.disponible - b.disponible; | 209 | return a.disponible - b.disponible; |
| 210 | }); | 210 | }); |
| 211 | 211 | ||
| 212 | var cisternas = arrayMismoProducto.concat(arrayVacioProducto); | 212 | var cisternas = arrayMismoProducto.concat(arrayVacioProducto); |
| 213 | 213 | ||
| 214 | for (var j = 0; j < cisternas.length; j++) { | 214 | for (var j = 0; j < cisternas.length; j++) { |
| 215 | var aCargar = $scope.articuloSeleccionado.cantidad - | 215 | var aCargar = $scope.articuloSeleccionado.cantidad - |
| 216 | ($scope.articuloSeleccionado.cantidadCargada || 0); | 216 | ($scope.articuloSeleccionado.cantidadCargada || 0); |
| 217 | 217 | ||
| 218 | if(aCargar > cisternas[j].disponible) { | 218 | if(aCargar > cisternas[j].disponible) { |
| 219 | aCargar = cisternas[j].disponible; | 219 | aCargar = cisternas[j].disponible; |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | if(aCargar > 0) { | 222 | if(aCargar > 0) { |
| 223 | $scope.aCargar[cisternas[j].posicion] = aCargar; | 223 | $scope.aCargar[cisternas[j].posicion] = aCargar; |
| 224 | $scope.actualizarArticulo(); | 224 | $scope.actualizarArticulo(); |
| 225 | } | 225 | } |
| 226 | } | 226 | } |
| 227 | }; | 227 | }; |
| 228 | $scope.cisternaDisponible = function() { | 228 | $scope.cisternaDisponible = function() { |
| 229 | for(var i = 0; i < $scope.cisternas.length; i++) { | 229 | for(var i = 0; i < $scope.cisternas.length; i++) { |
| 230 | //Puede meter un porcentaje del total | 230 | //Puede meter un porcentaje del total |
| 231 | // if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { | 231 | // if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { |
| 232 | // $scope.cisternas[i].disabled = true; | 232 | // $scope.cisternas[i].disabled = true; |
| 233 | // continue; | 233 | // continue; |
| 234 | // } | 234 | // } |
| 235 | if($scope.cisternas[i].cisternaCarga && | 235 | if($scope.cisternas[i].cisternaCarga && |
| 236 | $scope.cisternas[i].cisternaCarga.idProducto && | 236 | $scope.cisternas[i].cisternaCarga.idProducto && |
| 237 | $scope.articuloSeleccionado.idArticulo !== | 237 | $scope.articuloSeleccionado.idArticulo !== |
| 238 | $scope.cisternas[i].cisternaCarga.idProducto) | 238 | $scope.cisternas[i].cisternaCarga.idProducto) |
| 239 | { | 239 | { |
| 240 | $scope.cisternas[i].disabled = true; | 240 | $scope.cisternas[i].disabled = true; |
| 241 | continue; | 241 | continue; |
| 242 | } | 242 | } |
| 243 | $scope.cisternas[i].disabled = false; | 243 | $scope.cisternas[i].disabled = false; |
| 244 | } | 244 | } |
| 245 | }; | 245 | }; |
| 246 | $scope.rellenarInput = function(input, cisterna) { | 246 | $scope.rellenarInput = function(input, cisterna) { |
| 247 | if(!$scope.articuloSeleccionado) return; | 247 | if(!$scope.articuloSeleccionado) return; |
| 248 | if($scope.articuloSeleccionado.cantidad - | 248 | if($scope.articuloSeleccionado.cantidad - |
| 249 | $scope.articuloSeleccionado.cantidadCargada === 0) { | 249 | $scope.articuloSeleccionado.cantidadCargada === 0) { |
| 250 | return input; | 250 | return input; |
| 251 | } | 251 | } |
| 252 | if(!input) input = 0; | 252 | if(!input) input = 0; |
| 253 | input = parseFloat(input); | 253 | input = parseFloat(input); |
| 254 | input += parseFloat($scope.articuloSeleccionado.cantidad - | 254 | input += parseFloat($scope.articuloSeleccionado.cantidad - |
| 255 | $scope.articuloSeleccionado.cantidadCargada); | 255 | $scope.articuloSeleccionado.cantidadCargada); |
| 256 | if(input <= 0) return; | 256 | if(input <= 0) return; |
| 257 | if(input > cisterna.disponible) { | 257 | if(input > cisterna.disponible) { |
| 258 | input = cisterna.disponible; | 258 | input = cisterna.disponible; |
| 259 | } | 259 | } |
| 260 | return input; | 260 | return input; |
| 261 | }; | 261 | }; |
| 262 | $scope.distribucionDisponible = function() { | 262 | $scope.distribucionDisponible = function() { |
| 263 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - | 263 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - |
| 264 | $scope.articuloSeleccionado.cantidadCargada !== 0 || | 264 | $scope.articuloSeleccionado.cantidadCargada !== 0 || |
| 265 | !$scope.tieneArticulosPendientes()) { | 265 | !$scope.tieneArticulosPendientes()) { |
| 266 | return false; | 266 | return false; |
| 267 | } | 267 | } |
| 268 | for(var i = 0; i < $scope.cisternas.length; i++) { | 268 | for(var i = 0; i < $scope.cisternas.length; i++) { |
| 269 | if($scope.aCargar[i] > $scope.cisternas[i].disponible) { | 269 | if($scope.aCargar[i] > $scope.cisternas[i].disponible) { |
| 270 | return false; | 270 | return false; |
| 271 | } | 271 | } |
| 272 | } | 272 | } |
| 273 | return true; | 273 | return true; |
| 274 | }; | 274 | }; |
| 275 | $scope.tieneArticulosPendientes = function() { | 275 | $scope.tieneArticulosPendientes = function() { |
| 276 | var algunValorNegativo = $scope.aCargar.filter(function(p) { | 276 | var algunValorNegativo = $scope.aCargar.filter(function(p) { |
| 277 | return p < 0; | 277 | return p < 0; |
| 278 | }); | 278 | }); |
| 279 | if(algunValorNegativo.length) { | 279 | if(algunValorNegativo.length) { |
| 280 | return false; | 280 | return false; |
| 281 | } | 281 | } |
| 282 | var articulosDescargados = $scope.articulos.filter(function(filter) { | 282 | var articulosDescargados = $scope.articulos.filter(function(filter) { |
| 283 | return filter.cargado === true; | 283 | return filter.cargado === true; |
| 284 | }); | 284 | }); |
| 285 | if(articulosDescargados.length === $scope.articulos.length) { | 285 | if(articulosDescargados.length === $scope.articulos.length) { |
| 286 | $scope.aCargar = []; | 286 | $scope.aCargar = []; |
| 287 | return false; | 287 | return false; |
| 288 | } | 288 | } |
| 289 | return true; | 289 | return true; |
| 290 | }; | 290 | }; |
| 291 | 291 | ||
| 292 | $scope.verRemitos = function(data) { | 292 | $scope.verRemitos = function(data) { |
| 293 | var parametrosModal = { | 293 | var parametrosModal = { |
| 294 | titulo: 'Remitos cargados', | 294 | titulo: 'Remitos cargados', |
| 295 | data: data, | 295 | data: data, |
| 296 | soloMostrar: true, | 296 | soloMostrar: true, |
| 297 | columnas: [ | 297 | columnas: [ |
| 298 | { | 298 | { |
| 299 | nombre: 'Fecha', | 299 | nombre: 'Fecha', |
| 300 | propiedad: 'fechaRemito', | 300 | propiedad: 'fechaRemito', |
| 301 | filtro: { | 301 | filtro: { |
| 302 | nombre: 'date', | 302 | nombre: 'date', |
| 303 | parametro:'dd/MM/yyyy' | 303 | parametro:'dd/MM/yyyy' |
| 304 | } | 304 | } |
| 305 | }, | 305 | }, |
| 306 | { | 306 | { |
| 307 | nombre: 'Cliente', | 307 | nombre: 'Cliente', |
| 308 | propiedad: 'nombreCliente' | 308 | propiedad: 'nombreCliente' |
| 309 | }, | 309 | }, |
| 310 | { | 310 | { |
| 311 | nombre: 'Comprobante', | 311 | nombre: 'Comprobante', |
| 312 | propiedad: ['sucursal', 'numeroRemito'], | 312 | propiedad: ['sucursal', 'numeroRemito'], |
| 313 | filtro: { | 313 | filtro: { |
| 314 | nombre: 'comprobante' | 314 | nombre: 'comprobante' |
| 315 | } | 315 | } |
| 316 | }, | 316 | }, |
| 317 | { | 317 | { |
| 318 | nombre: 'Importe', | 318 | nombre: 'Importe', |
| 319 | propiedad: 'total' | 319 | propiedad: 'total' |
| 320 | } | 320 | } |
| 321 | ] | 321 | ] |
| 322 | }; | 322 | }; |
| 323 | focaModalService.modal(parametrosModal).then(function(transportista) { | 323 | focaModalService.modal(parametrosModal).then(function(transportista) { |
| 324 | $scope.selectVehiculo(transportista.COD, transportista.NOM); | 324 | $scope.selectVehiculo(transportista.COD, transportista.NOM); |
| 325 | }); | 325 | }); |
| 326 | }; | 326 | }; |
| 327 | function validarCargas(cis, remito) { | 327 | function validarCargas(cis, remito) { |
| 328 | var result = true; | 328 | var result = true; |
| 329 | var cisternas = angular.copy(cis); | 329 | var cisternas = angular.copy(cis); |
| 330 | var articulos = angular.copy(remito.articulosRemito); | 330 | var articulos = angular.copy(remito.articulosRemito); |
| 331 | 331 | ||
| 332 | cisternas.sort(ordenarCisternas); | 332 | cisternas.sort(ordenarCisternas); |
| 333 | 333 | ||
| 334 | articulos.forEach(function(articulo) { | 334 | articulos.forEach(function(articulo) { |
| 335 | cisternas.forEach(function(cisterna) { | 335 | cisternas.forEach(function(cisterna) { |
| 336 | if(!cisterna.cisternaCarga) cisterna.cisternaCarga = {}; | ||
| 336 | //SI LA CISTERNA ESTA VACIA O | 337 | //SI LA CISTERNA ESTA VACIA O |
| 337 | //SI LA CISTERNA TIENE EL MISMO PRODUCTO | 338 | //SI LA CISTERNA TIENE EL MISMO PRODUCTO |
| 338 | //Y AUN TIENE LUGAR | 339 | //Y AUN TIENE LUGAR |
| 339 | if(cisterna.capacidad === cisterna.disponible || | 340 | if(cisterna.capacidad === cisterna.disponible || |
| 340 | (cisterna.cisternaCarga.idProducto === articulo.idArticulo && | 341 | (cisterna.cisternaCarga.idProducto === articulo.idArticulo && |
| 341 | cisterna.disponible > 0)){ | 342 | cisterna.disponible > 0)){ |
| 342 | var restante = articulo.cantidad - cisterna.disponible; | 343 | var restante = articulo.cantidad - cisterna.disponible; |
| 343 | 344 | ||
| 344 | if (restante > 0) { | 345 | if (restante > 0) { |
| 345 | cisterna.disponible = 0; | 346 | cisterna.disponible = 0; |
| 346 | articulo.cantidad = restante; | 347 | articulo.cantidad = restante; |
| 347 | } else { | 348 | } else { |
| 348 | cisterna.disponible = restante * -1; | 349 | cisterna.disponible = restante * -1; |
| 349 | articulo.cantidad = 0; | 350 | articulo.cantidad = 0; |
| 350 | } | 351 | } |
| 351 | 352 | ||
| 352 | } | 353 | } |
| 353 | }); | 354 | }); |
| 354 | //SI AUN RESTA CANTIDAD EN EL ARTICULO | 355 | //SI AUN RESTA CANTIDAD EN EL ARTICULO |
| 355 | if (articulo.cantidad > 0) result = false; | 356 | if (articulo.cantidad > 0) result = false; |
| 356 | }); | 357 | }); |
| 357 | return result; | 358 | return result; |
| 358 | } | 359 | } |
| 359 | function ordenarCisternas(a, b) { | 360 | function ordenarCisternas(a, b) { |
| 360 | //DEJA LAS CISTERNAS CON CARGA PRIMERO PARA VALIDAR LAS CARGAS CORRECTAMENTE | 361 | //DEJA LAS CISTERNAS CON CARGA PRIMERO PARA VALIDAR LAS CARGAS CORRECTAMENTE |
| 361 | if (a.cisternaCarga && !b.cisternaCarga) { | 362 | if (a.cisternaCarga && !b.cisternaCarga) { |
| 362 | return -1; | 363 | return -1; |
| 363 | } else if (!a.cisternaCarga && b.cisternaCarga) { | 364 | } else if (!a.cisternaCarga && b.cisternaCarga) { |
| 364 | return 1; | 365 | return 1; |
| 365 | } else { | 366 | } else { |
| 366 | return 0; | 367 | return 0; |
| 367 | } | 368 | } |
| 368 | } | 369 | } |
| 369 | }]); | 370 | }]); |
| 370 | 371 |