Commit 8fe02f5aa8436cb46f8a68b0fe9f3a6bdd247480

Authored by Eric Fernandez
1 parent ee3db70dc0
Exists in master

refactor validations

src/js/controller.js
1 angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaController', [ 1 angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaController', [
2 '$scope', 'focaLogisticaPedidoRutaService', '$location', '$uibModal', '$filter', 2 '$scope', 'focaLogisticaPedidoRutaService', '$location', '$uibModal', '$filter',
3 'focaModalService', 'focaBotoneraLateralService', '$interval', 3 'focaModalService', 'focaBotoneraLateralService', '$interval',
4 function($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter, 4 function($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter,
5 focaModalService, focaBotoneraLateralService, $interval 5 focaModalService, focaBotoneraLateralService, $interval
6 ) { 6 ) {
7 $scope.actividad = 'Logistica'; 7 $scope.actividad = 'Logistica';
8 8
9 //Datos Pantalla 9 //Datos Pantalla
10 $scope.titulo = 'Logistica de Pedidos'; 10 $scope.titulo = 'Logistica de Pedidos';
11 var transportista = { 11 var transportista = {
12 label: 'Unidad', 12 label: 'Unidad',
13 image: 'abmChofer.png' 13 image: 'abmChofer.png'
14 }; 14 };
15 var fecha = { 15 var fecha = {
16 label: 'Fecha Reparto', 16 label: 'Fecha Reparto',
17 image: 'fechaDeReparto.png' 17 image: 'fechaDeReparto.png'
18 }; 18 };
19 $scope.botonera = [fecha, transportista]; 19 $scope.botonera = [fecha, transportista];
20 var cabecera = ''; 20 var cabecera = '';
21 $scope.now = new Date(); 21 $scope.now = new Date();
22 $scope.idVendedor = 0; 22 $scope.idVendedor = 0;
23 $scope.marcadores = []; 23 $scope.marcadores = [];
24 $scope.vehiculos = []; 24 $scope.vehiculos = [];
25 getSeguimiento(); 25 getSeguimiento();
26 $scope.arrastrando = false; 26 $scope.arrastrando = false;
27 $scope.general = function() { 27 $scope.general = function() {
28 $scope.idVendedor = 0; 28 $scope.idVendedor = 0;
29 getSeguimiento(); 29 getSeguimiento();
30 }; 30 };
31 31
32 //SETEO BOTONERA LATERAL 32 //SETEO BOTONERA LATERAL
33 focaBotoneraLateralService.showSalir(true); 33 focaBotoneraLateralService.showSalir(true);
34 focaBotoneraLateralService.showPausar(false); 34 focaBotoneraLateralService.showPausar(false);
35 focaBotoneraLateralService.showGuardar(false); 35 focaBotoneraLateralService.showGuardar(false);
36 36
37 37
38 38
39 $scope.general = function() { 39 $scope.general = function() {
40 $scope.idVendedor = 0; 40 $scope.idVendedor = 0;
41 getSeguimiento(); 41 getSeguimiento();
42 $scope.$broadcast('removeCabecera', cabecera); 42 $scope.$broadcast('removeCabecera', cabecera);
43 $scope.$broadcast('addCabecera',{ 43 $scope.$broadcast('addCabecera', {
44 label: 'General', 44 label: 'General',
45 valor: '' 45 valor: ''
46 }); 46 });
47 }; 47 };
48 48
49 $scope.cargar = function(idVehiculo, punto) { 49 $scope.cargar = function(idVehiculo, punto) {
50 if(!$scope.fechaReparto) { 50 if(!eligioFecha()) return;
51 focaModalService.alert('Primero seleccione fecha de reparto');
52 return;
53 }
54 var idRemito; 51 var idRemito;
55 if(punto === -1) { 52 if(punto === -1) {
56 idRemito = -1; 53 idRemito = -1;
57 }else { 54 }else {
58 idRemito = JSON.parse(punto).notaPedido.remito.id; 55 idRemito = JSON.parse(punto).notaPedido.remito.id;
59 } 56 }
60 var modalInstance = $uibModal.open( 57 var modalInstance = $uibModal.open(
61 { 58 {
62 ariaLabelledBy: 'Busqueda de Vehiculo', 59 ariaLabelledBy: 'Busqueda de Vehiculo',
63 templateUrl: 'foca-detalle-vehiculo.html', 60 templateUrl: 'foca-detalle-vehiculo.html',
64 controller: 'focaDetalleVehiculo', 61 controller: 'focaDetalleVehiculo',
65 size: 'lg', 62 size: 'lg',
66 resolve: { 63 resolve: {
67 idVehiculo: function() {return idVehiculo;}, 64 idVehiculo: function() {return idVehiculo;},
68 idRemito: function() {return idRemito;}, 65 idRemito: function() {return idRemito;},
69 fechaReparto: function() {return $scope.fechaReparto;} 66 fechaReparto: function() {return $scope.fechaReparto;}
70 } 67 }
71 } 68 }
72 ); 69 );
73 modalInstance.result.then(function() { 70 modalInstance.result.then(function() {
74 }, function() { 71 }, function() {
75 }); 72 });
76 }; 73 };
77 74
78 $scope.quitarVehiculo = function(vehiculo) { 75 $scope.quitarVehiculo = function(vehiculo) {
79 //TODO: Pasar validación a función 76 if(!eligioFecha()) return;
80 $scope.fechaReparto.setHours(0, 0, 0, 0); 77 if(vehiculoEnUso(vehiculo)) return;
81 var idUsuario = focaLogisticaPedidoRutaService.idUsuario;
82 for(var i = 0; i < vehiculo.cisternas.length; i++) {
83 for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
84 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
85 if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
86 .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso !==
87 idUsuario)
88 {
89 focaModalService.alert('El vehículo está siendo usado por otro usuario');
90 return;
91 }
92 }
93 }
94 focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + 78 focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' +
95 vehiculo.codigo + '?').then(function() { 79 vehiculo.codigo + '?').then(function() {
96 eliminarVehiculo(vehiculo); 80 eliminarVehiculo(vehiculo);
97 }); 81 });
98 }; 82 };
99 83
100 $scope.hacerHojaRuta = function(vehiculo) { 84 $scope.hacerHojaRuta = function(vehiculo) {
101 if(!$scope.fechaReparto) { 85 if(!eligioFecha()) return;
102 focaModalService.alert('Primero seleccione fecha de reparto'); 86 if(vehiculoEnUso(vehiculo)) return;
103 return; 87
104 }
105 //TODO: Pasar validación a función
106 $scope.fechaReparto.setHours(0, 0, 0, 0);
107 var idUsuario = focaLogisticaPedidoRutaService.idUsuario;
108 for(var i = 0; i < vehiculo.cisternas.length; i++) {
109 for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
110 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
111 if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
112 .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso !==
113 idUsuario)
114 {
115 focaModalService.alert('El vehículo está siendo usado por otro usuario');
116 return;
117 }
118 }
119 }
120 var modalInstance = $uibModal.open( 88 var modalInstance = $uibModal.open(
121 { 89 {
122 ariaLabelledBy: 'Creación hoja ruta', 90 ariaLabelledBy: 'Creación hoja ruta',
123 templateUrl: 'foca-modal-cerrar-vehiculo.html', 91 templateUrl: 'foca-modal-cerrar-vehiculo.html',
124 controller: 'focaModalCerrarVehiculo', 92 controller: 'focaModalCerrarVehiculo',
125 size: 'lg', 93 size: 'lg',
126 resolve: { 94 resolve: {
127 idVehiculo: function() {return vehiculo.id;} 95 idVehiculo: function() {return vehiculo.id;},
96 fechaReparto: function() {return $scope.fechaReparto;}
128 } 97 }
129 } 98 }
130 ); 99 );
131 modalInstance.result.then(function() { 100 modalInstance.result.then(function() {
132 101
133 }, function() { 102 }, function() {
134 //usar cuando se cancela el modal 103 //usar cuando se cancela el modal
135 }); 104 });
136 }; 105 };
137 106
138 $scope.arrastra = function() { 107 $scope.arrastra = function() {
139 $scope.arrastrando = true; 108 $scope.arrastrando = true;
140 $scope.$digest(); 109 $scope.$digest();
141 }; 110 };
142 111
143 $scope.noArrastra = function() { 112 $scope.noArrastra = function() {
144 $scope.arrastrando = false; 113 $scope.arrastrando = false;
145 $scope.$digest(); 114 $scope.$digest();
146 }; 115 };
147 116
148 $scope.individual = function() { 117 $scope.individual = function() {
149 $scope.idVendedor = -1; 118 $scope.idVendedor = -1;
150 }; 119 };
151 120
152 $scope.mostrarDetalle = function() { 121 $scope.mostrarDetalle = function() {
153 $scope.detalle = true; 122 $scope.detalle = true;
154 }; 123 };
155 124
156 $scope.salir = function() { 125 $scope.salir = function() {
157 $location.path('/'); 126 $location.path('/');
158 }; 127 };
159 128
160 $scope.search = function() { 129 $scope.search = function() {
161 getSeguimiento(); 130 getSeguimiento();
162 }; 131 };
163 132
164 $scope.fecha = function() { 133 $scope.fecha = function() {
165 getSeguimiento(); 134 getSeguimiento();
166 }; 135 };
167 136
168 $scope.seleccionarUnidad = function() { 137 $scope.seleccionarUnidad = function() {
169 var modalInstance = $uibModal.open( 138 var modalInstance = $uibModal.open(
170 { 139 {
171 ariaLabelledBy: 'Busqueda de Transportista', 140 ariaLabelledBy: 'Busqueda de Transportista',
172 templateUrl: 'modal-proveedor.html', 141 templateUrl: 'modal-proveedor.html',
173 controller: 'focaModalProveedorCtrl', 142 controller: 'focaModalProveedorCtrl',
174 size: 'lg', 143 size: 'lg',
175 resolve: { 144 resolve: {
176 transportista: function() { 145 transportista: function() {
177 return true; 146 return true;
178 } 147 }
179 } 148 }
180 } 149 }
181 ); 150 );
182 modalInstance.result.then(function(transportista) { 151 modalInstance.result.then(function(transportista) {
183 $scope.seleccionarVehiculo(transportista.COD); 152 $scope.seleccionarVehiculo(transportista.COD);
184 }); 153 });
185 }; 154 };
186 155
187 $scope.seleccionarVehiculo = function(idTransportista) { 156 $scope.seleccionarVehiculo = function(idTransportista) {
188 var query = '/vehiculo/transportista/' + idTransportista; 157 var query = '/vehiculo/transportista/' + idTransportista;
189 var columnas = { 158 var columnas = {
190 nombre: ['Código', 'tractor', 'Semi', 'Capacidad'], 159 nombre: ['Código', 'tractor', 'Semi', 'Capacidad'],
191 propiedad: ['codigo', 'tractor', 'semi', 'capacidadTotalCisternas'] 160 propiedad: ['codigo', 'tractor', 'semi', 'capacidadTotalCisternas']
192 }; 161 };
193 var titulo = 'Búsqueda de vehiculos'; 162 var titulo = 'Búsqueda de vehiculos';
194 focaModalService.modal(columnas, query, titulo).then( 163 focaModalService.modal(columnas, query, titulo).then(
195 function(vehiculo) { 164 function(vehiculo) {
196 var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id}); 165 var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id});
197 if(existe.length) { 166 if(existe.length) {
198 focaModalService.alert('El vehiculo ya ha sido cargado'); 167 focaModalService.alert('El vehiculo ya ha sido cargado');
199 return; 168 return;
200 } 169 }
201 if(!vehiculo.cisternas.length) { 170 if(!vehiculo.cisternas.length) {
202 focaModalService.alert('El vehiculo no tiene cisternas'); 171 focaModalService.alert('El vehiculo no tiene cisternas');
203 return; 172 return;
204 } 173 }
205 $scope.vehiculos.push(vehiculo); 174 $scope.vehiculos.push(vehiculo);
206 }, function() { 175 }, function() {
207 // funcion ejecutada cuando se cancela el modal 176 // funcion ejecutada cuando se cancela el modal
208 }); 177 });
209 }; 178 };
210 179
211 $scope.seleccionarFechaReparto = function() { 180 $scope.seleccionarFechaReparto = function() {
212 focaModalService.modalFecha('Fecha de reparto').then(function(fecha) { 181 focaModalService.modalFecha('Fecha de reparto').then(function(fecha) {
213 $scope.$broadcast('addCabecera',{ 182 $scope.$broadcast('addCabecera',{
214 label: 'Fecha:', 183 label: 'Fecha:',
215 valor: fecha.toLocaleDateString() 184 valor: fecha.toLocaleDateString()
216 }); 185 });
217 $scope.fechaReparto = fecha; 186 $scope.fechaReparto = fecha;
218 focaLogisticaPedidoRutaService.setFechaReparto(fecha); 187 focaLogisticaPedidoRutaService.setFechaReparto(fecha);
219 focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha).then(function(res) { 188 focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha).then(function(res) {
220 $scope.vehiculos = res.data; 189 $scope.vehiculos = res.data;
221 }); 190 });
222 }); 191 });
223 }; 192 };
224 193
225 function getSeguimiento() { 194 function getSeguimiento() {
226 var desde = new Date('1900/01/01'); 195 var desde = new Date('1900/01/01');
227 var hasta = new Date('2099/01/01'); 196 var hasta = new Date('2099/01/01');
228 if($scope.fechaDesde) { 197 if($scope.fechaDesde) {
229 var fechaDesde = $scope.fechaDesde; 198 var fechaDesde = $scope.fechaDesde;
230 desde = new Date(new Date(fechaDesde.setHours(0)).setMinutes(0)); 199 desde = new Date(new Date(fechaDesde.setHours(0)).setMinutes(0));
231 desde = new Date(desde); 200 desde = new Date(desde);
232 } 201 }
233 if($scope.fechaHasta) { 202 if($scope.fechaHasta) {
234 var fechaHasta = $scope.fechaHasta; 203 var fechaHasta = $scope.fechaHasta;
235 hasta = new Date(new Date(fechaHasta.setHours(0)).setMinutes(0)); 204 hasta = new Date(new Date(fechaHasta.setHours(0)).setMinutes(0));
236 hasta = hasta.setDate(hasta.getDate() + 1); 205 hasta = hasta.setDate(hasta.getDate() + 1);
237 hasta = new Date(hasta); 206 hasta = new Date(hasta);
238 } 207 }
239 var datos = { 208 var datos = {
240 actividad: $scope.actividad, 209 actividad: $scope.actividad,
241 idUsuario: $scope.idVendedor, 210 idUsuario: $scope.idVendedor,
242 fechaDesde: desde, 211 fechaDesde: desde,
243 fechaHasta: hasta, 212 fechaHasta: hasta,
244 asignacion: $scope.filtroEstado ? true : ($scope.filtroEstado !== undefined ? 213 asignacion: $scope.filtroEstado ? true : ($scope.filtroEstado !== undefined ?
245 false : undefined) 214 false : undefined)
246 }; 215 };
247 216
248 $scope.datosBuscados = { 217 $scope.datosBuscados = {
249 actividad: $scope.actividad, 218 actividad: $scope.actividad,
250 individual: $scope.idVendedor ? true : false 219 individual: $scope.idVendedor ? true : false
251 }; 220 };
252 221
253 focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { 222 focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) {
254 if(JSON.stringify(datos.data) !== JSON.stringify($scope.marcadores)) { 223 if(JSON.stringify(datos.data) !== JSON.stringify($scope.marcadores)) {
255 $scope.marcadores = datos.data; 224 $scope.marcadores = datos.data;
256 } 225 }
257 }); 226 });
258 } 227 }
259 228
260 function eliminarVehiculo(vehiculo) { 229 function eliminarVehiculo(vehiculo) {
261 focaLogisticaPedidoRutaService.getRemitos(vehiculo.id).then(function(res) { 230 focaLogisticaPedidoRutaService.getRemitos(vehiculo.id).then(function(res) {
262 if(!focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data).length) { 231 if(!focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data).length) {
263 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); 232 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
264 }else { 233 }else {
265 focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + 234 focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' +
266 'tiene remitos asociados').then(function() { 235 'tiene remitos asociados').then(function() {
267 $scope.hacerHojaRuta(vehiculo); 236 $scope.hacerHojaRuta(vehiculo);
268 }); 237 });
269 } 238 }
270 }); 239 });
271 } 240 }
241
242 function eligioFecha() {
243 if(!$scope.fechaReparto) {
244 focaModalService.alert('Primero seleccione fecha de reparto');
245 return false;
246 }
src/js/controllerCerrarVehiculo.js
1 angular.module('focaLogisticaPedidoRuta') 1 angular.module('focaLogisticaPedidoRuta')
2 .controller('focaModalCerrarVehiculo', [ 2 .controller('focaModalCerrarVehiculo', [
3 '$scope', 3 '$scope',
4 '$uibModalInstance', 4 '$uibModalInstance',
5 '$uibModal', 5 '$uibModal',
6 'focaLogisticaPedidoRutaService', 6 'focaLogisticaPedidoRutaService',
7 'idVehiculo', 7 'idVehiculo',
8 'focaModalService', 8 'focaModalService',
9 '$filter', 9 '$filter',
10 'fechaReparto',
10 function($scope, $uibModalInstance, $uibModal, focaLogisticaPedidoRutaService, 11 function($scope, $uibModalInstance, $uibModal, focaLogisticaPedidoRutaService,
11 idVehiculo, focaModalService, $filter) { 12 idVehiculo, focaModalService, $filter, fechaReparto) {
12 $scope.vehiculo = {}; 13 $scope.vehiculo = {};
13 $scope.remitos = []; 14 $scope.remitos = [];
14 $scope.now = new Date(); 15 $scope.now = fechaReparto;
15 focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then(function(res) { 16 focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then(function(res) {
16 $scope.vehiculo = res.data; 17 $scope.vehiculo = res.data;
17 }); 18 });
18 focaLogisticaPedidoRutaService.getRemitos(idVehiculo).then(function(res) { 19 focaLogisticaPedidoRutaService.getRemitos(idVehiculo).then(function(res) {
19 $scope.remitos = focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data); 20 $scope.remitos = focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data);
20 }); 21 });
21 focaLogisticaPedidoRutaService.numeroHojaRuta().then(function(res) { 22 focaLogisticaPedidoRutaService.numeroHojaRuta().then(function(res) {
22 $scope.sucursal = res.data.sucursal; 23 $scope.sucursal = res.data.sucursal;
23 $scope.numero = res.data.numeroHojaRuta; 24 $scope.numero = res.data.numeroHojaRuta;
24 }); 25 });
25 $scope.cancelar = function() { 26 $scope.cancelar = function() {
26 $uibModalInstance.close(); 27 $uibModalInstance.close();
27 }; 28 };
28 $scope.aceptar = function() { 29 $scope.aceptar = function() {
29 var idsRemito = []; 30 var idsRemito = [];
30 $scope.remitos.forEach(function(remito) { 31 $scope.remitos.forEach(function(remito) {
31 idsRemito.push(remito.id); 32 idsRemito.push(remito.id);
32 }); 33 });
33 var cierreDistribuicion = { 34 var cierreDistribuicion = {
34 idsRemito: idsRemito, 35 idsRemito: idsRemito,
35 fechaReparto: focaLogisticaPedidoRutaService.fecha 36 fechaReparto: focaLogisticaPedidoRutaService.fecha
36 }; 37 };
37 focaLogisticaPedidoRutaService.cerrarDistribuicion(cierreDistribuicion) 38 focaLogisticaPedidoRutaService.cerrarDistribuicion(cierreDistribuicion)
38 .then(function() { 39 .then(function() {
39 focaModalService.alert('Vehículo cerrado con éxito'); 40 focaModalService.alert('Vehículo cerrado con éxito');
40 } 41 }
41 ); 42 );
42 }; 43 };
43 $scope.seleccionarChofer = function() { 44 $scope.seleccionarChofer = function() {
44 var modalInstance = $uibModal.open( 45 var modalInstance = $uibModal.open(
45 { 46 {
46 ariaLabelledBy: 'Busqueda de Chofer', 47 ariaLabelledBy: 'Busqueda de Chofer',
47 templateUrl: 'modal-chofer.html', 48 templateUrl: 'modal-chofer.html',
48 controller: 'focaModalChoferController', 49 controller: 'focaModalChoferController',
49 size: 'lg' 50 size: 'lg'
50 } 51 }
51 ); 52 );
52 53
53 modalInstance.result.then( 54 modalInstance.result.then(
54 function(chofer) { 55 function(chofer) {
55 $scope.chofer = chofer; 56 $scope.chofer = chofer;
56 }, function() { 57 }, function() {
57 // funcion ejecutada cuando se cancela el modal 58 // funcion ejecutada cuando se cancela el modal
58 } 59 }
59 ); 60 );
60 }; 61 };
61 $scope.eliminarRemitos = function() { 62 $scope.eliminarRemitos = function() {
62 var remitosDel = $filter('filter')($scope.remitos, {checked: true}); 63 var remitosDel = $filter('filter')($scope.remitos, {checked: true});
63 focaModalService.alert('¿Seguro que desea desasociar estos remitos del vehículo?') 64 focaModalService.alert('¿Seguro que desea desasociar estos remitos del vehículo?')
64 .then(function() { 65 .then(function() {
65 eliminarRemitos(remitosDel); 66 eliminarRemitos(remitosDel);
66 } 67 }
67 ); 68 );
68 }; 69 };
69 $scope.minimoUnoChecked = function() { 70 $scope.minimoUnoChecked = function() {
70 var remitosChequeados = $filter('filter')($scope.remitos, {checked: true}); 71 var remitosChequeados = $filter('filter')($scope.remitos, {checked: true});
71 return !remitosChequeados.length; 72 return !remitosChequeados.length;
72 }; 73 };
73 function eliminarRemitos(remitosDel) { 74 function eliminarRemitos(remitosDel) {
74 var nuevosRemitos = $filter('filter')($scope.remitos, {checked: !true}); 75 var nuevosRemitos = $filter('filter')($scope.remitos, {checked: !true});
75 focaLogisticaPedidoRutaService.desasociarRemitos(remitosDel, $scope.vehiculo.id, 76 focaLogisticaPedidoRutaService.desasociarRemitos(remitosDel, $scope.vehiculo.id,
76 nuevosRemitos ? true : false).then(function() { 77 nuevosRemitos ? true : false).then(function() {
77 focaModalService.alert('Remitos desasociados con éxito'); 78 focaModalService.alert('Remitos desasociados con éxito');
78 $scope.remitos = nuevosRemitos; 79 $scope.remitos = nuevosRemitos;
79 }); 80 });
80 } 81 }
81 }]); 82 }]);
82 83
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.cargandoDatos = true; 14 $scope.cargandoDatos = true;
15 $scope.idRemito = idRemito; 15 $scope.idRemito = idRemito;
16 $scope.articulos = []; 16 $scope.articulos = [];
17 $scope.vehiculo = {}; 17 $scope.vehiculo = {};
18 $scope.cisternas = []; 18 $scope.cisternas = [];
19 $scope.cisternasCarga = []; 19 $scope.cisternasCarga = [];
20 $scope.remito = {}; 20 $scope.remito = {};
21 $scope.aCargar = []; 21 $scope.aCargar = [];
22 var cisternaMovimientos = []; 22 var cisternaMovimientos = [];
23 var promesaRemito; 23 var promesaRemito;
24 var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo); 24 var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo);
25 var promesaCisternas = focaLogisticaPedidoRutaService 25 var promesaCisternas = focaLogisticaPedidoRutaService
26 .obtenerCisternasPorFecha(idVehiculo); 26 .obtenerCisternasPorFecha(idVehiculo);
27 if(idRemito !== -1) { 27 if(idRemito !== -1) {
28 promesaRemito = focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito); 28 promesaRemito = focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito);
29 } 29 }
30 Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { 30 Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) {
31 $scope.cargandoDatos = false; 31 $scope.cargandoDatos = false;
32 $scope.vehiculo = res[0].data; 32 $scope.vehiculo = res[0].data;
33 $scope.cisternas = res[1].data; 33 $scope.cisternas = res[1].data;
34 if(!res[2]) return; 34 if(!res[2]) {
35 $scope.$digest();
36 return;
37 }
35 $scope.remito = res[2].data; 38 $scope.remito = res[2].data;
36 if($scope.remito.idUsuarioProceso) { 39 if($scope.remito.idUsuarioProceso) {
37 focaModalService.alert('Remito ya asignado'); 40 focaModalService.alert('Remito ya asignado');
38 $uibModalInstance.close(); 41 $uibModalInstance.close();
39 } 42 }
40 $scope.articulos = $scope.remito.articulosRemito; 43 $scope.articulos = $scope.remito.articulosRemito;
41 $scope.seleccionarArticulo($scope.articulos[0]); 44 $scope.seleccionarArticulo($scope.articulos[0]);
42 var tieneUsuario = $scope.cisternas.filter(function(cisterna) { 45 var tieneUsuario = $scope.cisternas.filter(function(cisterna) {
43 if(cisterna.cisternaCarga) { 46 if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) {
44 return cisterna.cisternaCarga.idUsuarioProceso !== 47 return cisterna.cisternaCarga.idUsuarioProceso !==
45 focaLogisticaPedidoRutaService.idUsuario; 48 focaLogisticaPedidoRutaService.idUsuario;
46 } 49 }
47 }); 50 });
48 if(tieneUsuario.length) { 51 if(tieneUsuario.length) {
49 focaModalService.alert('Otro usario esta usando este vehículo'); 52 focaModalService.alert('Otro usario esta usando este vehículo');
50 $uibModalInstance.close(); 53 $uibModalInstance.close();
51 return;
52 } 54 }
53 $scope.$digest(); 55 $scope.$digest();
54 }); 56 });
55 $scope.aceptar = function() { 57 $scope.aceptar = function() {
56 $scope.cargando = true; 58 $scope.cargando = true;
57 for(var i = 0; i < $scope.cisternasCarga.length; i++) { 59 for(var i = 0; i < $scope.cisternasCarga.length; i++) {
58 $scope.cisternasCarga[i].idUsuarioProceso = 60 $scope.cisternasCarga[i].idUsuarioProceso =
59 focaLogisticaPedidoRutaService.idUsuario; 61 focaLogisticaPedidoRutaService.idUsuario;
60 delete $scope.cisternasCarga[i].articulo; 62 delete $scope.cisternasCarga[i].articulo;
61 } 63 }
62 var cisterna = { 64 var cisterna = {
63 cisternaMovimientos: cisternaMovimientos, 65 cisternaMovimientos: cisternaMovimientos,
64 cisternaCargas: $scope.cisternasCarga, 66 cisternaCargas: $scope.cisternasCarga,
65 idVehiculo: $scope.vehiculo.id, 67 idVehiculo: $scope.vehiculo.id,
66 fechaReparto: focaLogisticaPedidoRutaService.fecha 68 fechaReparto: focaLogisticaPedidoRutaService.fecha
67 }; 69 };
68 focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) 70 focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id)
69 .then(function() { 71 .then(function() {
70 focaModalService.alert('Cisternas cargadas con éxito').then(function() { 72 focaModalService.alert('Cisternas cargadas con éxito').then(function() {
71 $scope.cargando = false; 73 $scope.cargando = false;
72 $uibModalInstance.close(); 74 $uibModalInstance.close();
73 }); 75 });
74 }).catch(function(error) { 76 }).catch(function(error) {
75 $scope.cargando = false; 77 $scope.cargando = false;
76 $uibModalInstance.close(); 78 $uibModalInstance.close();
77 if (error.status === 403) { 79 if (error.status === 403) {
78 focaModalService.alert('ERROR: ' + error.data); 80 focaModalService.alert('ERROR: ' + error.data);
79 return; 81 return;
80 } 82 }
81 focaModalService.alert('Hubo un error al cargar las cisternas'); 83 focaModalService.alert('Hubo un error al cargar las cisternas');
82 }); 84 });
83 }; 85 };
84 $scope.cancelar = function() { 86 $scope.cancelar = function() {
85 $uibModalInstance.close(); 87 $uibModalInstance.close();
86 }; 88 };
87 $scope.cargarACisternas = function() { 89 $scope.cargarACisternas = function() {
88 for(var i = 0; i < $scope.cisternas.length; i++) { 90 for(var i = 0; i < $scope.cisternas.length; i++) {
89 var cisterna = $scope.cisternas[i]; 91 var cisterna = $scope.cisternas[i];
90 var aCargar = parseFloat($scope.aCargar[i]); 92 var aCargar = parseFloat($scope.aCargar[i]);
91 var fechaReparto = focaLogisticaPedidoRutaService.fecha; 93 var fechaReparto = focaLogisticaPedidoRutaService.fecha;
92 //validaciones 94 //validaciones
93 if(!aCargar) { 95 if(!aCargar) {
94 continue; 96 continue;
95 } 97 }
96 //cargar 98 //cargar
97 if(cisterna.cisternaCarga.cantidad) { 99 if(cisterna.cisternaCarga.cantidad) {
98 cisterna.cisternaCarga.cantidad += aCargar; 100 cisterna.cisternaCarga.cantidad += aCargar;
99 }else { 101 }else {
100 cisterna.cisternaCarga.cantidad = aCargar; 102 cisterna.cisternaCarga.cantidad = aCargar;
101 cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; 103 cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo;
102 } 104 }
103 cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; 105 cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad;
104 106
105 cisterna.cisternaCarga.articulo = { 107 cisterna.cisternaCarga.articulo = {
106 DetArt: $scope.articuloSeleccionado.descripcion 108 DetArt: $scope.articuloSeleccionado.descripcion
107 }; 109 };
108 $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] 110 $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0]
109 .cargado = true; 111 .cargado = true;
110 112
111 $scope.calcularPorcentaje(cisterna); 113 $scope.calcularPorcentaje(cisterna);
112 //Guardar 114 //Guardar
113 var now = new Date(); 115 var now = new Date();
114 var cisternaMovimiento = { 116 var cisternaMovimiento = {
115 fecha: now.toISOString().slice(0, 19).replace('T', ' '), 117 fecha: now.toISOString().slice(0, 19).replace('T', ' '),
116 cantidad: aCargar, 118 cantidad: aCargar,
117 metodo: 'carga', 119 metodo: 'carga',
118 idCisternaCarga: cisterna.cisternaCarga.id, 120 idCisternaCarga: cisterna.cisternaCarga.id,
119 idRemito: $scope.remito.id 121 idRemito: $scope.remito.id
120 }; 122 };
121 cisterna.cisternaCarga.fechaReparto = fechaReparto; 123 cisterna.cisternaCarga.fechaReparto = fechaReparto;
122 cisterna.cisternaCarga.idCisterna = cisterna.id; 124 cisterna.cisternaCarga.idCisterna = cisterna.id;
123 $scope.cisternasCarga.push(cisterna.cisternaCarga); 125 $scope.cisternasCarga.push(cisterna.cisternaCarga);
124 cisternaMovimientos.push(cisternaMovimiento); 126 cisternaMovimientos.push(cisternaMovimiento);
125 } 127 }
126 var articuloSiguiente = $scope.articulos.filter( 128 var articuloSiguiente = $scope.articulos.filter(
127 function(filter) { 129 function(filter) {
128 return filter.cargado !== true; 130 return filter.cargado !== true;
129 } 131 }
130 ); 132 );
131 if(articuloSiguiente.length > 0) { 133 if(articuloSiguiente.length > 0) {
132 $scope.seleccionarArticulo(articuloSiguiente[0]); 134 $scope.seleccionarArticulo(articuloSiguiente[0]);
133 } 135 }
134 }; 136 };
135 $scope.calcularPorcentaje = function(cisterna) { 137 $scope.calcularPorcentaje = function(cisterna) {
136 if(!cisterna.cisternaCarga) { 138 if(!cisterna.cisternaCarga) {
137 cisterna.cisternaCarga = { 139 cisterna.cisternaCarga = {
138 cantidad: 0 140 cantidad: 0
139 }; 141 };
140 } 142 }
141 var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / 143 var porcentaje = (cisterna.cisternaCarga.cantidad * 100 /
142 cisterna.capacidad) + '%'; 144 cisterna.capacidad) + '%';
143 var elementHtml = document.getElementById(cisterna.id); 145 var elementHtml = document.getElementById(cisterna.id);
144 if(elementHtml) { 146 if(elementHtml) {
145 elementHtml.style.width = porcentaje; 147 elementHtml.style.width = porcentaje;
146 } 148 }
147 }; 149 };
148 $scope.seleccionarArticulo = function(articulo) { 150 $scope.seleccionarArticulo = function(articulo) {
149 $scope.articuloSeleccionado = articulo; 151 $scope.articuloSeleccionado = articulo;
150 $scope.cisternaDisponible(); 152 $scope.cisternaDisponible();
151 $scope.autoCompletar(); 153 $scope.autoCompletar();
152 $scope.actualizarArticulo(); 154 $scope.actualizarArticulo();
153 }; 155 };
154 $scope.actualizarArticulo = function () { 156 $scope.actualizarArticulo = function () {
155 $scope.articuloSeleccionado.cantidadCargada = 0; 157 $scope.articuloSeleccionado.cantidadCargada = 0;
156 for (var i = 0; i < $scope.aCargar.length; i++) { 158 for (var i = 0; i < $scope.aCargar.length; i++) {
157 $scope.articuloSeleccionado.cantidadCargada += 159 $scope.articuloSeleccionado.cantidadCargada +=
158 parseFloat($scope.aCargar[i]) || 0; 160 parseFloat($scope.aCargar[i]) || 0;
159 } 161 }
160 }; 162 };
161 $scope.autoCompletar = function() { 163 $scope.autoCompletar = function() {
162 $scope.aCargar = []; 164 $scope.aCargar = [];
163 var disponible = $filter('filter')($scope.cisternas, {disabled: false}); 165 var disponible = $filter('filter')($scope.cisternas, {disabled: false});
164 var index = $scope.cisternas.indexOf(disponible[0]); 166 var index = $scope.cisternas.indexOf(disponible[0]);
165 $scope.aCargar[index] = $scope.articuloSeleccionado.cantidad; 167 $scope.aCargar[index] = $scope.articuloSeleccionado.cantidad;
166 }; 168 };
167 $scope.cisternaDisponible = function() { 169 $scope.cisternaDisponible = function() {
168 for(var i = 0; i < $scope.cisternas.length; i++) { 170 for(var i = 0; i < $scope.cisternas.length; i++) {
169 if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { 171 if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) {
170 $scope.cisternas[i].disabled = true; 172 $scope.cisternas[i].disabled = true;
171 continue; 173 continue;
172 } 174 }
173 if($scope.cisternas[i].cisternaCarga && 175 if($scope.cisternas[i].cisternaCarga &&
174 $scope.cisternas[i].cisternaCarga.idProducto && 176 $scope.cisternas[i].cisternaCarga.idProducto &&
175 $scope.articuloSeleccionado.idArticulo !== 177 $scope.articuloSeleccionado.idArticulo !==
176 $scope.cisternas[i].cisternaCarga.idProducto) 178 $scope.cisternas[i].cisternaCarga.idProducto)
177 { 179 {
178 $scope.cisternas[i].disabled = true; 180 $scope.cisternas[i].disabled = true;
179 continue; 181 continue;
180 } 182 }
181 $scope.cisternas[i].disabled = false; 183 $scope.cisternas[i].disabled = false;
182 } 184 }
183 }; 185 };
184 $scope.rellenarInput = function(input) { 186 $scope.rellenarInput = function(input) {
185 if(!$scope.articuloSeleccionado) return; 187 if(!$scope.articuloSeleccionado) return;
186 if($scope.articuloSeleccionado.cantidad - 188 if($scope.articuloSeleccionado.cantidad -
187 $scope.articuloSeleccionado.cantidadCargada === 0) { 189 $scope.articuloSeleccionado.cantidadCargada === 0) {
188 return input; 190 return input;
189 } 191 }
190 if(!input) input = 0; 192 if(!input) input = 0;
191 input = parseFloat(input); 193 input = parseFloat(input);
192 input += parseFloat($scope.articuloSeleccionado.cantidad - 194 input += parseFloat($scope.articuloSeleccionado.cantidad -
193 $scope.articuloSeleccionado.cantidadCargada); 195 $scope.articuloSeleccionado.cantidadCargada);
194 return input; 196 return input;
195 }; 197 };
196 $scope.distribucionDisponible = function() { 198 $scope.distribucionDisponible = function() {
197 if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - 199 if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad -
198 $scope.articuloSeleccionado.cantidadCargada !== 0 || 200 $scope.articuloSeleccionado.cantidadCargada !== 0 ||
199 !$scope.tieneArticulosPendientes()) { 201 !$scope.tieneArticulosPendientes()) {
200 return false; 202 return false;
201 } 203 }
202 return true; 204 return true;
203 }; 205 };
204 $scope.tieneArticulosPendientes = function() { 206 $scope.tieneArticulosPendientes = function() {
205 var algunValorNegativo = $scope.aCargar.filter(function(p) { 207 var algunValorNegativo = $scope.aCargar.filter(function(p) {
206 return p < 0; 208 return p < 0;
207 }); 209 });
208 if(algunValorNegativo.length) { 210 if(algunValorNegativo.length) {
209 return false; 211 return false;
210 } 212 }
211 var articulosDescargados = $scope.articulos.filter(function(filter) { 213 var articulosDescargados = $scope.articulos.filter(function(filter) {
212 return filter.cargado === true; 214 return filter.cargado === true;
213 }); 215 });
214 if(articulosDescargados.length === $scope.articulos.length) { 216 if(articulosDescargados.length === $scope.articulos.length) {
215 $scope.aCargar = []; 217 $scope.aCargar = [];
216 return false; 218 return false;
217 } 219 }
218 return true; 220 return true;
219 }; 221 };
220 }]); 222 }]);
src/views/foca-modal-cerrar-vehiculo.html
1 <div class="modal-header"> 1 <div class="modal-header">
2 <h5>En desarrollo</h5> 2 <h5>En desarrollo</h5>
3 <h4>Cerrar distribución vehículo</h4> 3 <h4>Cerrar distribución vehículo</h4>
4 <div class="row"> 4 <div class="row">
5 <div class="col-6 row"> 5 <div class="col-6 row">
6 <label class="col-3 mt-2">Fecha:</label> 6 <label class="col-3 mt-2">Fecha:</label>
7 <input 7 <input
8 type="text" 8 type="text"
9 readonly 9 readonly
10 ng-model="now" 10 ng-model="now"
11 uib-datepicker-popup="dd/MM/yyyy" 11 uib-datepicker-popup="dd/MM/yyyy"
12 show-button-bar="false" 12 show-button-bar="false"
13 is-open="datepickerOpen" 13 is-open="datepickerOpen"
14 on-open-focus="false" 14 on-open-focus="false"
15 ng-focus="datepickerOpen = true"
16 class="form-control col-8"/> 15 class="form-control col-8"/>
17 </div> 16 </div>
18 </div> 17 </div>
19 </div> 18 </div>
20 <div class="modal-body"> 19 <div class="modal-body">
21 <form class="row" name="formHojaRuta"> 20 <form class="row" name="formHojaRuta">
22 21
23 <div class="col-2"> 22 <div class="col-2">
24 <label>Transportista</label> 23 <label>Transportista</label>
25 </div> 24 </div>
26 <div class="col-4"> 25 <div class="col-4">
27 <input 26 <input
28 class="form-control" 27 class="form-control"
29 readonly 28 readonly
30 ng-value="vehiculo.transportista.COD + ' ' + vehiculo.transportista.NOM" 29 ng-value="vehiculo.transportista.COD + ' ' + vehiculo.transportista.NOM"
31 > 30 >
32 </div> 31 </div>
33 <div class="col-2 form-group"> 32 <div class="col-2 form-group">
34 <label>Unidad</label> 33 <label>Unidad</label>
35 </div> 34 </div>
36 <div class="col-4"> 35 <div class="col-4">
37 <input 36 <input
38 class="form-control" 37 class="form-control"
39 readonly 38 readonly
40 ng-model="vehiculo.tractor" 39 ng-model="vehiculo.tractor"
41 > 40 >
42 </div> 41 </div>
43 </form> 42 </form>
44 <strong>Remitos:</strong> 43 <strong>Remitos:</strong>
45 <table class="table"> 44 <table class="table">
46 <thead> 45 <thead>
47 <tr> 46 <tr>
48 <th>Remito Nº</th> 47 <th>Remito Nº</th>
49 <th>Cliente</th> 48 <th>Cliente</th>
50 <th>Domicilio de entrega</th> 49 <th>Domicilio de entrega</th>
51 <th>Eliminar</th> 50 <th>Eliminar</th>
52 </tr> 51 </tr>
53 </thead> 52 </thead>
54 <tbody> 53 <tbody>
55 <tr ng-show="!remitos.length"> 54 <tr ng-show="!remitos.length">
56 <td colspan="3"> 55 <td colspan="3">
57 No se han encontrado remitos. 56 No se han encontrado remitos.
58 </td> 57 </td>
59 </tr> 58 </tr>
60 <tr ng-repeat="remito in remitos"> 59 <tr ng-repeat="remito in remitos">
61 <td ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"></td> 60 <td ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"></td>
62 <td ng-bind="remito.nombreCliente"></td> 61 <td ng-bind="remito.nombreCliente"></td>
63 <td ng-bind="remito.domicilioStamp"></td> 62 <td ng-bind="remito.domicilioStamp"></td>
64 <td> 63 <td>
65 <div class="custom-control custom-checkbox"> 64 <div class="custom-control custom-checkbox">
66 <input 65 <input
67 type="checkbox" 66 type="checkbox"
68 ng-model="remito.checked" 67 ng-model="remito.checked"
69 class="custom-control-input" 68 class="custom-control-input"
70 id="{{remito.id}}"> 69 id="{{remito.id}}">
71 <label class="custom-control-label" for="{{remito.id}}"></label> 70 <label class="custom-control-label" for="{{remito.id}}"></label>
72 </div> 71 </div>
73 </td> 72 </td>
74 </tr> 73 </tr>
75 </tbody> 74 </tbody>
76 </table> 75 </table>
77 </div> 76 </div>
78 <div class="modal-footer py-1"> 77 <div class="modal-footer py-1">
79 <button 78 <button
80 class="btn btn-sm btn-danger" 79 class="btn btn-sm btn-danger"
81 type="button" 80 type="button"
82 ng-click="eliminarRemitos()" 81 ng-click="eliminarRemitos()"
83 ng-disabled="minimoUnoChecked()">Eliminar</button> 82 ng-disabled="minimoUnoChecked()">Eliminar</button>
84 <button 83 <button
85 class="btn btn-sm btn-secondary" 84 class="btn btn-sm btn-secondary"
86 ladda="cargando" 85 ladda="cargando"
87 type="button" 86 type="button"
88 ng-click="cancelar()">Cancelar</button> 87 ng-click="cancelar()">Cancelar</button>
89 <button 88 <button
90 class="btn btn-sm btn-primary" 89 class="btn btn-sm btn-primary"
91 ladda="cargando" 90 ladda="cargando"
92 type="button" 91 type="button"
93 ng-disabled="!formHojaRuta.$valid || !remitos.length" 92 ng-disabled="!formHojaRuta.$valid || !remitos.length"
94 ng-click="aceptar()">Cerrar distribución</button> 93 ng-click="aceptar()">Cerrar distribución</button>
95 </div> 94 </div>
96 95