Commit aed323a955256b4d26d6f76c11fb90b520f18d00
1 parent
706f795b5f
Exists in
master
si el remito tiene asignado un idUsuario ya no se puede usar
Showing
1 changed file
with
1 additions
and
3 deletions
Show diff stats
src/js/controllerDetalleVehiculo.js
1 | angular.module('focaLogisticaPedidoRuta') | 1 | angular.module('focaLogisticaPedidoRuta') |
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 | 'focaLogisticaPedidoRutaService', | 9 | 'focaLogisticaPedidoRutaService', |
10 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, | 10 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, |
11 | focaLogisticaPedidoRutaService | 11 | focaLogisticaPedidoRutaService |
12 | ) { | 12 | ) { |
13 | //seteo variables | 13 | //seteo variables |
14 | $scope.articulos = []; | 14 | $scope.articulos = []; |
15 | $scope.vehiculo = {}; | 15 | $scope.vehiculo = {}; |
16 | $scope.remito = {}; | 16 | $scope.remito = {}; |
17 | $scope.aCargar = []; | 17 | $scope.aCargar = []; |
18 | var cisternaMovimientos = []; | 18 | var cisternaMovimientos = []; |
19 | focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then( | 19 | focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then( |
20 | function(res) { | 20 | function(res) { |
21 | $scope.vehiculo = res.data; | 21 | $scope.vehiculo = res.data; |
22 | } | 22 | } |
23 | ); | 23 | ); |
24 | focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito).then( | 24 | focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito).then( |
25 | function(res) { | 25 | function(res) { |
26 | $scope.remito = res.data; | 26 | $scope.remito = res.data; |
27 | if($scope.remito.idUsuarioProceso && $scope.remito.idUsuarioProceso !== | 27 | if($scope.remito.idUsuarioProceso) { |
28 | focaLogisticaPedidoRutaService.idUsuario) | ||
29 | { | ||
30 | focaModalService.alert('El remito esta siendo cargado por otro usario'); | 28 | focaModalService.alert('El remito esta siendo cargado por otro usario'); |
31 | $uibModalInstance.close(); | 29 | $uibModalInstance.close(); |
32 | } | 30 | } |
33 | $scope.articulos = res.data.articulosRemito; | 31 | $scope.articulos = res.data.articulosRemito; |
34 | } | 32 | } |
35 | ); | 33 | ); |
36 | $scope.aceptar = function() { | 34 | $scope.aceptar = function() { |
37 | $scope.cargando = true; | 35 | $scope.cargando = true; |
38 | var cisternaCargas = []; | 36 | var cisternaCargas = []; |
39 | for (var i = 0; i < $scope.vehiculo.cisternas.length; i++) { | 37 | for (var i = 0; i < $scope.vehiculo.cisternas.length; i++) { |
40 | delete $scope.vehiculo.cisternas[i].cisternaCarga.articulo; | 38 | delete $scope.vehiculo.cisternas[i].cisternaCarga.articulo; |
41 | cisternaCargas.push($scope.vehiculo.cisternas[i].cisternaCarga); | 39 | cisternaCargas.push($scope.vehiculo.cisternas[i].cisternaCarga); |
42 | } | 40 | } |
43 | var cisterna = { | 41 | var cisterna = { |
44 | cisternaMovimientos: cisternaMovimientos, | 42 | cisternaMovimientos: cisternaMovimientos, |
45 | cisternaCargas: cisternaCargas, | 43 | cisternaCargas: cisternaCargas, |
46 | idVehiculo: $scope.vehiculo.id | 44 | idVehiculo: $scope.vehiculo.id |
47 | }; | 45 | }; |
48 | focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) | 46 | focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) |
49 | .then(function() { | 47 | .then(function() { |
50 | focaModalService.alert('Cisternas cargadas con éxito').then(function() { | 48 | focaModalService.alert('Cisternas cargadas con éxito').then(function() { |
51 | $scope.cargando = false; | 49 | $scope.cargando = false; |
52 | $uibModalInstance.close(); | 50 | $uibModalInstance.close(); |
53 | }); | 51 | }); |
54 | }).catch(function(error) { | 52 | }).catch(function(error) { |
55 | $scope.cargando = false; | 53 | $scope.cargando = false; |
56 | $uibModalInstance.close(); | 54 | $uibModalInstance.close(); |
57 | if (error.status === 403.1) { | 55 | if (error.status === 403.1) { |
58 | focaModalService.alert('ERROR: El vehículo esta en uso'); | 56 | focaModalService.alert('ERROR: El vehículo esta en uso'); |
59 | } | 57 | } |
60 | if(error.status === 403.2) { | 58 | if(error.status === 403.2) { |
61 | focaModalService.alert('ERROR: Otro usario ya cargó este remito'); | 59 | focaModalService.alert('ERROR: Otro usario ya cargó este remito'); |
62 | return; | 60 | return; |
63 | } | 61 | } |
64 | focaModalService.alert('Hubo un error al cargar las cisternas'); | 62 | focaModalService.alert('Hubo un error al cargar las cisternas'); |
65 | }); | 63 | }); |
66 | }; | 64 | }; |
67 | 65 | ||
68 | $scope.cancelar = function() { | 66 | $scope.cancelar = function() { |
69 | $uibModalInstance.close(); | 67 | $uibModalInstance.close(); |
70 | }; | 68 | }; |
71 | 69 | ||
72 | $scope.cargarACisternas = function(vehiculo) { | 70 | $scope.cargarACisternas = function(vehiculo) { |
73 | for(var i = 0; i < vehiculo.cisternas.length; i++) { | 71 | for(var i = 0; i < vehiculo.cisternas.length; i++) { |
74 | var cisterna = vehiculo.cisternas[i]; | 72 | var cisterna = vehiculo.cisternas[i]; |
75 | var aCargar = parseFloat($scope.aCargar[i]); | 73 | var aCargar = parseFloat($scope.aCargar[i]); |
76 | //validaciones | 74 | //validaciones |
77 | if(!aCargar) { | 75 | if(!aCargar) { |
78 | continue; | 76 | continue; |
79 | } | 77 | } |
80 | if(aCargar > cisterna.disponible) { | 78 | if(aCargar > cisterna.disponible) { |
81 | focaModalService.alert('La cantidad cargada supera la capacidad de la' + | 79 | focaModalService.alert('La cantidad cargada supera la capacidad de la' + |
82 | 'cisterna ' + cisterna.codigo); | 80 | 'cisterna ' + cisterna.codigo); |
83 | return; | 81 | return; |
84 | } | 82 | } |
85 | //cargar | 83 | //cargar |
86 | if(cisterna.cisternaCarga.cantidad) { | 84 | if(cisterna.cisternaCarga.cantidad) { |
87 | cisterna.cisternaCarga.cantidad += aCargar; | 85 | cisterna.cisternaCarga.cantidad += aCargar; |
88 | }else { | 86 | }else { |
89 | cisterna.cisternaCarga.cantidad = aCargar; | 87 | cisterna.cisternaCarga.cantidad = aCargar; |
90 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; | 88 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; |
91 | } | 89 | } |
92 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; | 90 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; |
93 | 91 | ||
94 | cisterna.cisternaCarga.articulo = { | 92 | cisterna.cisternaCarga.articulo = { |
95 | DetArt: $scope.articuloSeleccionado.descripcion | 93 | DetArt: $scope.articuloSeleccionado.descripcion |
96 | }; | 94 | }; |
97 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] | 95 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] |
98 | .cargado = true; | 96 | .cargado = true; |
99 | 97 | ||
100 | $scope.calcularPorcentaje(cisterna); | 98 | $scope.calcularPorcentaje(cisterna); |
101 | //Guardar | 99 | //Guardar |
102 | var now = new Date(); | 100 | var now = new Date(); |
103 | var cisternaMovimiento = { | 101 | var cisternaMovimiento = { |
104 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 102 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
105 | cantidad: aCargar, | 103 | cantidad: aCargar, |
106 | metodo: 'carga', | 104 | metodo: 'carga', |
107 | idCisternaCarga: cisterna.cisternaCarga.id, | 105 | idCisternaCarga: cisterna.cisternaCarga.id, |
108 | idRemito: $scope.remito.id | 106 | idRemito: $scope.remito.id |
109 | }; | 107 | }; |
110 | cisternaMovimientos.push(cisternaMovimiento); | 108 | cisternaMovimientos.push(cisternaMovimiento); |
111 | } | 109 | } |
112 | var articuloSiguiente = $scope.articulos.filter( | 110 | var articuloSiguiente = $scope.articulos.filter( |
113 | function(filter) { | 111 | function(filter) { |
114 | return filter.cargado !== true; | 112 | return filter.cargado !== true; |
115 | } | 113 | } |
116 | ); | 114 | ); |
117 | if(articuloSiguiente.length > 0) { | 115 | if(articuloSiguiente.length > 0) { |
118 | $scope.cambioArticulo(articuloSiguiente[0]); | 116 | $scope.cambioArticulo(articuloSiguiente[0]); |
119 | } | 117 | } |
120 | $scope.aCargar = []; | 118 | $scope.aCargar = []; |
121 | }; | 119 | }; |
122 | $scope.calcularPorcentaje = function(cisterna) { | 120 | $scope.calcularPorcentaje = function(cisterna) { |
123 | if(!cisterna.cisternaCarga.cantidad) { | 121 | if(!cisterna.cisternaCarga.cantidad) { |
124 | cisterna.cisternaCarga.cantidad = 0; | 122 | cisterna.cisternaCarga.cantidad = 0; |
125 | } | 123 | } |
126 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / | 124 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / |
127 | cisterna.capacidad) + '%'; | 125 | cisterna.capacidad) + '%'; |
128 | var elementHtml = document.getElementById(cisterna.id); | 126 | var elementHtml = document.getElementById(cisterna.id); |
129 | if(elementHtml) { | 127 | if(elementHtml) { |
130 | elementHtml.style.width = porcentaje; | 128 | elementHtml.style.width = porcentaje; |
131 | } | 129 | } |
132 | }; | 130 | }; |
133 | $scope.cambioArticulo = function(articulo) { | 131 | $scope.cambioArticulo = function(articulo) { |
134 | articulo.checked = true; | 132 | articulo.checked = true; |
135 | $scope.articuloSeleccionado = articulo; | 133 | $scope.articuloSeleccionado = articulo; |
136 | }; | 134 | }; |
137 | $scope.actualizarArticulo = function () { | 135 | $scope.actualizarArticulo = function () { |
138 | $scope.articuloSeleccionado.cantidadCargada = 0; | 136 | $scope.articuloSeleccionado.cantidadCargada = 0; |
139 | for (var i = 0; i < $scope.aCargar.length; i++) { | 137 | for (var i = 0; i < $scope.aCargar.length; i++) { |
140 | $scope.articuloSeleccionado.cantidadCargada += | 138 | $scope.articuloSeleccionado.cantidadCargada += |
141 | parseFloat($scope.aCargar[i]) || 0; | 139 | parseFloat($scope.aCargar[i]) || 0; |
142 | } | 140 | } |
143 | }; | 141 | }; |
144 | $scope.tieneArticulosPendientes = function() { | 142 | $scope.tieneArticulosPendientes = function() { |
145 | var articulosDescargados = $scope.articulos.filter(function(filter) { | 143 | var articulosDescargados = $scope.articulos.filter(function(filter) { |
146 | return filter.cargado === true; | 144 | return filter.cargado === true; |
147 | }); | 145 | }); |
148 | if(articulosDescargados.length === $scope.articulos.length) { | 146 | if(articulosDescargados.length === $scope.articulos.length) { |
149 | return false; | 147 | return false; |
150 | } | 148 | } |
151 | return true; | 149 | return true; |
152 | }; | 150 | }; |
153 | }]); | 151 | }]); |
154 | 152 |