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