Commit 4c26d0978431f758f6a700a16965eb153f843fb5

Authored by Jose Pinto
Exists in master and in 2 other branches develop, lab

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !15
src/js/controller.js
1 angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', 1 angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
2 [ 2 [
3 '$scope', 3 '$scope',
4 '$uibModal', 4 '$uibModal',
5 '$location', 5 '$location',
6 '$filter', 6 '$filter',
7 '$timeout', 7 '$timeout',
8 'focaCrearHojaRutaService', 8 'focaCrearHojaRutaService',
9 'focaModalService', 9 'focaModalService',
10 'focaBotoneraLateralService', 10 'focaBotoneraLateralService',
11 'focaLoginService',
11 function($scope, $uibModal, $location, $filter, $timeout, 12 function($scope, $uibModal, $location, $filter, $timeout,
12 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService) { 13 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService,
14 focaLoginSrv)
15 {
13 16
14 $scope.botonera = focaCrearHojaRutaService.getBotonera(); 17 $scope.botonera = focaCrearHojaRutaService.getBotonera();
15 $scope.datepickerAbierto = false; 18 $scope.datepickerAbierto = false;
16 19
17 $scope.show = false; 20 $scope.show = false;
18 $scope.cargando = true; 21 $scope.cargando = true;
19 22
20 function nuevaHojaRuta() { 23 function nuevaHojaRuta() {
21 $scope.hojaRuta = { 24 $scope.hojaRuta = {
22 fecha: new Date(), 25 fecha: new Date(),
23 litros: 0, 26 litros: 0,
24 chofer: {}, 27 chofer: {},
25 vehiculo: { 28 vehiculo: {
26 capacidad: 0 29 capacidad: 0
27 }, 30 },
28 transportista: {}, 31 transportista: {},
29 tarifario: { 32 tarifario: {
30 costo: null 33 costo: null
31 } 34 }
32 }; 35 };
33 } 36 }
34 nuevaHojaRuta(); 37 nuevaHojaRuta();
35 $scope.showCabecera = true; 38 $scope.showCabecera = true;
36 39
37 $scope.now = new Date(); 40 $scope.now = new Date();
38 $scope.puntoVenta = '0000'; 41 $scope.puntoVenta = '0000';
39 $scope.comprobante = '00000000'; 42 $scope.comprobante = '00000000';
40 $scope.remitosTabla = []; 43 $scope.remitosTabla = [];
41 $scope.idLista = undefined; 44 $scope.idLista = undefined;
42 45
43 //SETEO BOTONERA LATERAL 46 //SETEO BOTONERA LATERAL
44 $timeout(function() { 47 $timeout(function() {
45 focaBotoneraLateralService.showSalir(true); 48 focaBotoneraLateralService.showSalir(true);
46 focaBotoneraLateralService.showPausar(true); 49 focaBotoneraLateralService.showPausar(true);
47 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); 50 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta);
48 }); 51 });
49 52
50 focaCrearHojaRutaService.getNumeroHojaRuta().then( 53 focaCrearHojaRutaService.getNumeroHojaRuta().then(
51 function(res) { 54 function(res) {
52 $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); 55 $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4);
53 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); 56 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8);
54 }, 57 },
55 function(err) { 58 function(err) {
56 focaModalService.alert('La terminal no esta configurada correctamente'); 59 focaModalService.alert('La terminal no esta configurada correctamente');
57 console.info(err); 60 console.info(err);
58 } 61 }
59 ); 62 );
60 $scope.crearHojaRuta = function() { 63 $scope.crearHojaRuta = function() {
61 if(!$scope.remitosTabla.length) { 64 if(!$scope.remitosTabla.length) {
62 focaModalService.alert('Ingrese Remitos'); 65 focaModalService.alert('Ingrese Remitos');
63 return; 66 return;
64 } 67 }
65 if(!$scope.hojaRuta.chofer.id) { 68 if(!$scope.hojaRuta.chofer.id) {
66 focaModalService.alert('Ingrese Chofer'); 69 focaModalService.alert('Ingrese Chofer');
67 return; 70 return;
68 } 71 }
69 if(!$scope.hojaRuta.vehiculo.id) { 72 if(!$scope.hojaRuta.vehiculo.id) {
70 focaModalService.alert('Ingrese Vehiculo'); 73 focaModalService.alert('Ingrese Vehiculo');
71 return; 74 return;
72 } 75 }
73 if(!$scope.hojaRuta.transportista.COD) { 76 if(!$scope.hojaRuta.transportista.COD) {
74 focaModalService.alert('Ingrese Transportista'); 77 focaModalService.alert('Ingrese Transportista');
75 return; 78 return;
76 } 79 }
77 if(!$scope.hojaRuta.tarifario.costo) { 80 if(!$scope.hojaRuta.tarifario.costo) {
78 focaModalService.alert('Ingrese Tarifario'); 81 focaModalService.alert('Ingrese Tarifario');
79 return; 82 return;
80 } 83 }
81 if(!$scope.hojaRuta.datosExtra) { 84 if(!$scope.hojaRuta.datosExtra) {
82 focaModalService.alert('Ingrese Datos extra'); 85 focaModalService.alert('Ingrese Datos extra');
83 return; 86 return;
84 } 87 }
85 var date = new Date(); 88 var date = new Date();
86 var save = { 89 var save = {
87 hojaRuta: { 90 hojaRuta: {
88 id: 0, 91 id: 0,
89 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) 92 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19)
90 .replace('T', ' '), 93 .replace('T', ' '),
91 idTransportista: $scope.hojaRuta.transportista.COD, 94 idTransportista: $scope.hojaRuta.transportista.COD,
92 idChofer: $scope.hojaRuta.chofer.id, 95 idChofer: $scope.hojaRuta.chofer.id,
93 idVehiculo: $scope.hojaRuta.vehiculo.id, 96 idVehiculo: $scope.hojaRuta.vehiculo.id,
94 tarifaFlete: $scope.hojaRuta.tarifario.costo, 97 tarifaFlete: $scope.hojaRuta.tarifario.costo,
95 fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10), 98 fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10),
96 estado: 0 99 estado: 0
97 }, 100 },
98 remitos: $scope.remitosTabla 101 remitos: $scope.remitosTabla
99 }; 102 };
100 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); 103 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra);
101 focaCrearHojaRutaService.crearHojaRuta(save).then( 104 focaCrearHojaRutaService.crearHojaRuta(save).then(
102 function(data) { 105 function(data) {
103 focaModalService.alert( 106 focaModalService.alert(
104 'Hoja ruta creada Nº: ' + 107 'Hoja ruta creada Nº: ' +
105 $scope.rellenar(data.data.sucursal, 4) + 108 $scope.rellenar(data.data.sucursal, 4) +
106 '-' + 109 '-' +
107 $scope.rellenar(data.data.numeroHojaRuta, 8) 110 $scope.rellenar(data.data.numeroHojaRuta, 8)
108 ); 111 );
109 nuevaHojaRuta(); 112 nuevaHojaRuta();
110 $scope.remitosTabla = []; 113 $scope.remitosTabla = [];
111 $scope.$broadcast('cleanCabecera'); 114 $scope.$broadcast('cleanCabecera');
112 115
113 focaCrearHojaRutaService.getNumeroHojaRuta().then(function(res) { 116 focaCrearHojaRutaService.getNumeroHojaRuta().then(function(res) {
114 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); 117 $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8);
115 }); 118 });
116 }, 119 },
117 function(error) { 120 function(error) {
118 focaModalService.alert('Hubo un error al crear la hoja de ruta'); 121 focaModalService.alert('Hubo un error al crear la hoja de ruta');
119 console.info(error); 122 console.info(error);
120 } 123 }
121 ); 124 );
122 }; 125 };
123 126
124 $scope.seleccionarTransportista = function() { 127 $scope.seleccionarTransportista = function() {
125 if(eligioPreConfirmado()) return; 128 if(eligioPreConfirmado()) return;
126 var modalInstance = $uibModal.open( 129 var modalInstance = $uibModal.open(
127 { 130 {
128 ariaLabelledBy: 'Busqueda de Transportista', 131 ariaLabelledBy: 'Busqueda de Transportista',
129 templateUrl: 'modal-proveedor.html', 132 templateUrl: 'modal-proveedor.html',
130 controller: 'focaModalProveedorCtrl', 133 controller: 'focaModalProveedorCtrl',
131 size: 'lg', 134 size: 'lg',
132 resolve: { 135 resolve: {
133 transportista: function() { 136 transportista: function() {
134 return true; 137 return true;
135 } 138 }
136 } 139 }
137 } 140 }
138 ); 141 );
139 modalInstance.result.then( 142 modalInstance.result.then(
140 function(proveedor) { 143 function(proveedor) {
141 $scope.hojaRuta.transportista = proveedor; 144 $scope.hojaRuta.transportista = proveedor;
142 $scope.$broadcast('addCabecera', { 145 $scope.$broadcast('addCabecera', {
143 label: 'Transportista:', 146 label: 'Transportista:',
144 valor: proveedor.NOM 147 valor: proveedor.NOM
145 }); 148 });
146 }, function() { 149 }, function() {
147 150
148 } 151 }
149 ); 152 );
150 }; 153 };
151 154
152 $scope.seleccionarChofer = function() { 155 $scope.seleccionarChofer = function() {
153 var modalInstance = $uibModal.open( 156 var modalInstance = $uibModal.open(
154 { 157 {
155 ariaLabelledBy: 'Busqueda de Chofer', 158 ariaLabelledBy: 'Busqueda de Chofer',
156 templateUrl: 'modal-chofer.html', 159 templateUrl: 'modal-chofer.html',
157 controller: 'focaModalChoferController', 160 controller: 'focaModalChoferController',
158 size: 'lg' 161 size: 'lg'
159 } 162 }
160 ); 163 );
161 164
162 modalInstance.result.then( 165 modalInstance.result.then(
163 function(chofer) { 166 function(chofer) {
164 $scope.hojaRuta.chofer = chofer; 167 $scope.hojaRuta.chofer = chofer;
165 $scope.$broadcast('addCabecera', { 168 $scope.$broadcast('addCabecera', {
166 label: 'Chofer:', 169 label: 'Chofer:',
167 valor: chofer.nombre 170 valor: chofer.nombre
168 }); 171 });
169 }, function() { 172 }, function() {
170 // funcion ejecutada cuando se cancela el modal 173 // funcion ejecutada cuando se cancela el modal
171 } 174 }
172 ); 175 );
173 }; 176 };
174 177
175 $scope.seleccionarVehiculo = function() { 178 $scope.seleccionarVehiculo = function() {
176 if(eligioPreConfirmado()) return; 179 if(!eligioFecha() || eligioPreConfirmado()) return;
177 modalVehiculos(); 180 modalVehiculos();
178 }; 181 };
179 182
180 $scope.seleccionarTarifario = function() { 183 $scope.seleccionarTarifario = function() {
181 var modalInstance = $uibModal.open( 184 var modalInstance = $uibModal.open(
182 { 185 {
183 ariaLabelledBy: 'Busqueda de Tarifario', 186 ariaLabelledBy: 'Busqueda de Tarifario',
184 templateUrl: 'modal-tarifa-flete.html', 187 templateUrl: 'modal-tarifa-flete.html',
185 controller: 'focaModalTarifaFleteController', 188 controller: 'focaModalTarifaFleteController',
186 size: 'lg', 189 size: 'lg',
187 resolve: { 190 resolve: {
188 parametrosTarifaFlete: function() { 191 parametrosTarifaFlete: function() {
189 return $scope.hojaRuta.tarifario.costo; 192 return $scope.hojaRuta.tarifario.costo;
190 } 193 }
191 } 194 }
192 } 195 }
193 ); 196 );
194 197
195 modalInstance.result.then( 198 modalInstance.result.then(
196 function(tarifario) { 199 function(tarifario) {
197 $scope.hojaRuta.tarifario = tarifario; 200 $scope.hojaRuta.tarifario = tarifario;
198 $scope.$broadcast('addCabecera', { 201 $scope.$broadcast('addCabecera', {
199 label: 'Tarifario:', 202 label: 'Tarifario:',
200 valor: tarifario.costo 203 valor: tarifario.costo
201 }); 204 });
202 }, function() { 205 }, function() {
203 // funcion ejecutada cuando se cancela el modal 206 // funcion ejecutada cuando se cancela el modal
204 } 207 }
205 ); 208 );
206 }; 209 };
207 210
208 $scope.seleccionarRemitos = function() { 211 $scope.seleccionarRemitos = function() {
209 if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; 212 if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return;
210 var modalInstance = $uibModal.open( 213 var modalInstance = $uibModal.open(
211 { 214 {
212 ariaLabelledBy: 'Busqueda de Remito', 215 ariaLabelledBy: 'Busqueda de Remito',
213 templateUrl: 'foca-modal-remito.html', 216 templateUrl: 'foca-modal-remito.html',
214 controller: 'focaModalRemitoController', 217 controller: 'focaModalRemitoController',
215 size: 'lg', 218 size: 'lg',
216 resolve: {usadoPor: function() {return 'hojaRuta';}} 219 resolve: {usadoPor: function() {return 'hojaRuta';}}
217 } 220 }
218 ); 221 );
219 modalInstance.result.then( 222 modalInstance.result.then(
220 function(remito) { 223 function(remito) {
221 // TODO: borrar cuando no se use definitivamente 224 // TODO: borrar cuando no se use definitivamente
222 // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { 225 // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) {
223 // if ($scope.remitosTabla[i].id === remito.id) { 226 // if ($scope.remitosTabla[i].id === remito.id) {
224 // focaModalService.alert('Remito ya incluido'); 227 // focaModalService.alert('Remito ya incluido');
225 // return; 228 // return;
226 // } 229 // }
227 // } 230 // }
228 231
229 // var litros = 0; 232 // var litros = 0;
230 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { 233 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) {
231 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); 234 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad);
232 // } 235 // }
233 236
234 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { 237 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) {
235 // focaModalService.alert( 238 // focaModalService.alert(
236 // 'Debe ingresar toda la información para el transporte' 239 // 'Debe ingresar toda la información para el transporte'
237 // ); 240 // );
238 // return; 241 // return;
239 // } 242 // }
240 243
241 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) 244 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad)
242 // { 245 // {
243 // var litrostotales = litros; 246 // var litrostotales = litros;
244 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; 247 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros;
245 // focaModalService.alert( 248 // focaModalService.alert(
246 // 'La carga excede la capacidad disponible del vehiculo. ' + 249 // 'La carga excede la capacidad disponible del vehiculo. ' +
247 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' 250 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros'
248 // ); 251 // );
249 // } 252 // }
250 253
251 // remito.litros = litros; 254 // remito.litros = litros;
252 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; 255 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros;
253 $scope.cargarCisterna(remito.id).then(function() { 256 $scope.cargarCisterna(remito.id).then(function() {
254 $scope.remitosTabla.push(remito); 257 $scope.remitosTabla.push(remito);
255 $scope.seleccionarRemitos(); 258 $scope.seleccionarRemitos();
256 }, function() { 259 }, function() {
257 $scope.seleccionarRemitos(); 260 $scope.seleccionarRemitos();
258 }); 261 });
259 }, function() { 262 }, function() {
260 // funcion ejecutada cuando se cancela el modal 263 // funcion ejecutada cuando se cancela el modal
261 } 264 }
262 ); 265 );
263 }; 266 };
264 267
265 $scope.seleccionarVehiculosPrecargados = function() { 268 $scope.seleccionarVehiculosPrecargados = function() {
266 if(!eligioFecha()) return; 269 if(!eligioFecha()) return;
267 modalVehiculos(true); 270 modalVehiculos(true);
268 }; 271 };
269 272
270 $scope.cargarCisterna = function(idRemito) { 273 $scope.cargarCisterna = function(idRemito) {
271 if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; 274 if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return;
272 var modalInstance = $uibModal.open( 275 var modalInstance = $uibModal.open(
273 { 276 {
274 ariaLabelledBy: 'Busqueda de Vehiculo', 277 ariaLabelledBy: 'Busqueda de Vehiculo',
275 templateUrl: 'foca-detalle-vehiculo.html', 278 templateUrl: 'foca-detalle-vehiculo.html',
276 controller: 'focaDetalleVehiculo', 279 controller: 'focaDetalleVehiculo',
277 size: 'lg', 280 size: 'lg',
278 resolve: { 281 resolve: {
279 idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, 282 idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;},
280 idRemito: function() {return idRemito;}, 283 idRemito: function() {return idRemito;},
281 fechaReparto: function() {return $scope.fechaReparto;} 284 fechaReparto: function() {return $scope.fechaReparto;}
282 } 285 }
283 } 286 }
284 ); 287 );
285 return modalInstance.result; 288 return modalInstance.result;
286 }; 289 };
287 290
288 $scope.seleccionarFechaEntrega = function() { 291 $scope.seleccionarFechaEntrega = function() {
289 if(!$scope.fechaReparto) { 292 if(!$scope.fechaReparto) {
290 elegirFecha(); 293 elegirFecha();
291 return; 294 return;
292 } 295 }
293 focaModalService 296 focaModalService
294 .confirm('Si cambia la fecha se perderán los datos actuales') 297 .confirm('Si cambia la fecha se perderán los datos actuales')
295 .then(function() { 298 .then(function() {
296 elegirFecha(); 299 elegirFecha();
297 }, function() { 300 }, function() {
298 return ; 301 return ;
299 }); 302 });
300 }; 303 };
301 304
302 $scope.seleccionarDatosExtra = function() { 305 $scope.seleccionarDatosExtra = function() {
303 var datosHojaRuta = $scope.hojaRuta.datosExtra; 306 var datosHojaRuta = $scope.hojaRuta.datosExtra;
304 var modalInstance = $uibModal.open( 307 var modalInstance = $uibModal.open(
305 { 308 {
306 templateUrl: 'foca-modal-datos-hoja-ruta.html', 309 templateUrl: 'foca-modal-datos-hoja-ruta.html',
307 controller: 'focaModalDatosHojaRutaCtrl', 310 controller: 'focaModalDatosHojaRutaCtrl',
308 size: 'lg', 311 size: 'lg',
309 resolve: { 312 resolve: {
310 parametrosDatos: function() { 313 parametrosDatos: function() {
311 return { 314 return {
312 datosHojaRuta: datosHojaRuta 315 datosHojaRuta: datosHojaRuta
313 }; 316 };
314 } 317 }
315 } 318 }
316 } 319 }
317 ); 320 );
318 return modalInstance.result.then(function(datosExtra) { 321 return modalInstance.result.then(function(datosExtra) {
319 $scope.hojaRuta.datosExtra = datosExtra; 322 $scope.hojaRuta.datosExtra = datosExtra;
320 }, function() { 323 }, function() {
321 //se ejecuta cuando se cancela el modal 324 //se ejecuta cuando se cancela el modal
322 }); 325 });
323 }; 326 };
324 327
325 $scope.desasociarRemito = function(key, idRemito) { 328 $scope.desasociarRemito = function(key, idRemito) {
326 var idsRemito = [idRemito]; 329 var idsRemito = [idRemito];
327 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + 330 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' +
328 ' vehículo?').then(function() { 331 ' vehículo?').then(function() {
329 focaCrearHojaRutaService.desasociarRemitos(idsRemito, 332 focaCrearHojaRutaService.desasociarRemitos(idsRemito,
330 $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then( 333 $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then(
331 function() { 334 function() {
332 $scope.remitosTabla.splice(key, 1); 335 $scope.remitosTabla.splice(key, 1);
333 focaModalService.alert('Remito desasociado con éxito'); 336 focaModalService.alert('Remito desasociado con éxito');
334 } 337 }
335 ); 338 );
336 }); 339 });
337 }; 340 };
338 341
339 function elegirFecha() { 342 function elegirFecha() {
340 focaModalService.modalFecha('Fecha de entrega').then(function(fecha) { 343 focaModalService.modalFecha('Fecha de entrega').then(function(fecha) {
341 $scope.$broadcast('addCabecera', { 344 $scope.$broadcast('addCabecera', {
342 label: 'Fecha de entrega:', 345 label: 'Fecha de entrega:',
343 valor: fecha.toLocaleDateString() 346 valor: fecha.toLocaleDateString()
344 }); 347 });
345 $scope.fechaReparto = fecha; 348 $scope.fechaReparto = fecha;
346 nuevaHojaRuta(); 349 nuevaHojaRuta();
347 }); 350 });
348 } 351 }
349 352
350 $scope.rellenar = function(relleno, longitud) { 353 $scope.rellenar = function(relleno, longitud) {
351 relleno = '' + relleno; 354 relleno = '' + relleno;
352 while (relleno.length < longitud) { 355 while (relleno.length < longitud) {
353 relleno = '0' + relleno; 356 relleno = '0' + relleno;
354 } 357 }
355 return relleno; 358 return relleno;
356 }; 359 };
357 360
358 function eligioPreConfirmado() { 361 function eligioPreConfirmado() {
359 if($scope.eligioPreConfirmado) { 362 if($scope.eligioPreConfirmado) {
360 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); 363 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado');
361 return true; 364 return true;
362 } 365 }
363 return false; 366 return false;
364 } 367 }
365 368
366 function eligioFecha() { 369 function eligioFecha() {
367 if(!$scope.fechaReparto) { 370 if(!$scope.fechaReparto) {
368 focaModalService.alert('Primero seleccione fecha de reparto'); 371 focaModalService.alert('Primero seleccione fecha de reparto');
369 return false; 372 return false;
370 } 373 }
371 return true; 374 return true;
372 } 375 }
373 376
374 function eligioVehiculo() { 377 function eligioVehiculo() {
375 if(!$scope.hojaRuta.vehiculo.id) { 378 if(!$scope.hojaRuta.vehiculo.id) {
376 focaModalService.alert('Primero seleccione vehiculo'); 379 focaModalService.alert('Primero seleccione vehiculo');
377 return false; 380 return false;
378 } 381 }
379 return true; 382 return true;
380 } 383 }
381 384
382 function modalVehiculos(preCargados) { 385 function modalVehiculos(preCargados) {
383 var query = ''; 386 var query = '';
384 var titulo = ''; 387 var titulo = '';
385 if(preCargados) { 388 if(preCargados) {
386 query = '/vehiculo/obtener/pre-confirmados/' + $scope.fechaReparto 389 query = '/vehiculo/obtener/pre-confirmados/' + $scope.fechaReparto
387 .toISOString().substring(0, 10); 390 .toISOString().substring(0, 10);
388 titulo = 'Búsqueda de vehiculos pre confirmados'; 391 titulo = 'Búsqueda de vehiculos pre confirmados';
389 }else { 392 }else {
390 query = '/vehiculo'; 393 query = '/vehiculo';
391 titulo = 'Búsqueda de vehículos'; 394 titulo = 'Búsqueda de vehículos';
392 } 395 }
393 var columnas = { 396 var columnas = {
394 nombre: ['Código', 'tractor', 'Semi'], 397 nombre: ['Código', 'tractor', 'Semi'],
395 propiedad: ['codigo', 'tractor', 'semi'] 398 propiedad: ['codigo', 'tractor', 'semi']
396 }; 399 };
397 focaModalService.modal(columnas, query, titulo).then(function(vehiculo) { 400 focaModalService.modal(columnas, query, titulo).then(function(vehiculo) {
401 if(vehiculoEnUso(vehiculo)) return;
398 $scope.hojaRuta.vehiculo = vehiculo; 402 $scope.hojaRuta.vehiculo = vehiculo;
399 $scope.hojaRuta.transportista = vehiculo.transportista; 403 $scope.hojaRuta.transportista = vehiculo.transportista;
400 if(preCargados) { 404 if(preCargados) {
401 $scope.eligioPreConfirmado = true; 405 $scope.eligioPreConfirmado = true;
402 $scope.hojaRuta.vehiculo = vehiculo; 406 $scope.hojaRuta.vehiculo = vehiculo;
403 $scope.$broadcast('addCabecera', { 407 $scope.$broadcast('addCabecera', {
404 label: 'Transportista:', 408 label: 'Transportista:',
405 valor: vehiculo.transportista.NOM 409 valor: vehiculo.transportista.NOM
406 }); 410 });
407 focaCrearHojaRutaService 411 focaCrearHojaRutaService
408 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto) 412 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto)
409 .then(function(res) { 413 .then(function(res) {
410 $scope.remitosTabla = res.data; 414 $scope.remitosTabla = res.data;
411 }); 415 });
416 }else {
417 focaCrearHojaRutaService
418 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true)
419 .then(function(res) {
420 $scope.remitosTabla = res.data;
421 });
412 } 422 }
413 $scope.$broadcast('addCabecera', { 423 $scope.$broadcast('addCabecera', {
414 label: 'Tractor:', 424 label: 'Tractor:',
415 valor: vehiculo.tractor 425 valor: vehiculo.tractor
416 }); 426 });
417 $scope.$broadcast('addCabecera', { 427 $scope.$broadcast('addCabecera', {
418 label: 'Semi:', 428 label: 'Semi:',
419 valor: vehiculo.semi 429 valor: vehiculo.semi
420 }); 430 });
421 $scope.$broadcast('addCabecera', { 431 $scope.$broadcast('addCabecera', {
422 label: 'Capacidad:', 432 label: 'Capacidad:',
423 valor: vehiculo.capacidad 433 valor: vehiculo.capacidad
424 }); 434 });
425 }); 435 });
426 } 436 }
437
438 function vehiculoEnUso(vehiculo) {
439 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador;
440 for(var i = 0; i < vehiculo.cisternas.length; i++) {
441 for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
442 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
443 if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
444 .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso &&
445 cisternaCarga.idUsuarioProceso !== idUsuario)
446 {
447 focaModalService.alert('El vehículo está siendo usado por otro' +
448 ' usuario');
449 return true;
450 }
451 }
452 }
453 return false;
454 }
427 } 455 }
428 ]); 456 ]);
429 457
1 angular.module('focaCrearHojaRuta') 1 angular.module('focaCrearHojaRuta')
2 .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { 2 .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 var route = API_ENDPOINT.URL; 3 var route = API_ENDPOINT.URL;
4 return { 4 return {
5 crearHojaRuta: function(hojaRuta) { 5 crearHojaRuta: function(hojaRuta) {
6 return $http.post(route + '/hoja-ruta', hojaRuta); 6 return $http.post(route + '/hoja-ruta', hojaRuta);
7 }, 7 },
8 obtenerHojaRuta: function() { 8 obtenerHojaRuta: function() {
9 return $http.get(route +'/hoja-ruta'); 9 return $http.get(route +'/hoja-ruta');
10 }, 10 },
11 setHojaRuta: function(hojaRuta) { 11 setHojaRuta: function(hojaRuta) {
12 this.hojaRuta = hojaRuta; 12 this.hojaRuta = hojaRuta;
13 }, 13 },
14 clearHojaRuta: function() { 14 clearHojaRuta: function() {
15 this.hojaRuta = undefined; 15 this.hojaRuta = undefined;
16 }, 16 },
17 getHojaRuta: function() { 17 getHojaRuta: function() {
18 return this.hojaRuta; 18 return this.hojaRuta;
19 }, 19 },
20 getArticulosByIdHojaRuta: function(id) { 20 getArticulosByIdHojaRuta: function(id) {
21 return $http.get(route+'/articulos/hoja-ruta/'+id); 21 return $http.get(route+'/articulos/hoja-ruta/'+id);
22 }, 22 },
23 crearArticulosParaHojaRuta: function(articuloHojaRuta) { 23 crearArticulosParaHojaRuta: function(articuloHojaRuta) {
24 return $http.post(route + '/articulos/hoja-ruta', 24 return $http.post(route + '/articulos/hoja-ruta',
25 {articuloHojaRuta: articuloHojaRuta}); 25 {articuloHojaRuta: articuloHojaRuta});
26 }, 26 },
27 getDomiciliosByIdHojaRuta: function(id) { 27 getDomiciliosByIdHojaRuta: function(id) {
28 return $http.get(route +'/hoja-ruta/' + id + '/domicilios'); 28 return $http.get(route +'/hoja-ruta/' + id + '/domicilios');
29 }, 29 },
30 getDomiciliosByIdCliente: function(id) { 30 getDomiciliosByIdCliente: function(id) {
31 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) 31 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega)
32 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); 32 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id );
33 }, 33 },
34 getPrecioCondicion: function() { 34 getPrecioCondicion: function() {
35 return $http.get(route + '/precio-condicion'); 35 return $http.get(route + '/precio-condicion');
36 }, 36 },
37 getPrecioCondicionById: function(id) { 37 getPrecioCondicionById: function(id) {
38 return $http.get(route + '/precio-condicion/' + id); 38 return $http.get(route + '/precio-condicion/' + id);
39 }, 39 },
40 getPlazoPagoByPrecioCondicion: function(id) { 40 getPlazoPagoByPrecioCondicion: function(id) {
41 return $http.get(route + '/plazo-pago/precio-condicion/' + id); 41 return $http.get(route + '/plazo-pago/precio-condicion/' + id);
42 }, 42 },
43 crearFlete: function(flete) { 43 crearFlete: function(flete) {
44 return $http.post(route + '/flete', {flete : flete}); 44 return $http.post(route + '/flete', {flete : flete});
45 }, 45 },
46 crearPlazosParaHojaRuta: function(plazos) { 46 crearPlazosParaHojaRuta: function(plazos) {
47 return $http.post(route + '/plazo-pago/hoja-ruta', plazos); 47 return $http.post(route + '/plazo-pago/hoja-ruta', plazos);
48 }, 48 },
49 getCotizacionByIdMoneda: function(id) { 49 getCotizacionByIdMoneda: function(id) {
50 return $http.get(route + '/moneda/' + id); 50 return $http.get(route + '/moneda/' + id);
51 }, 51 },
52 crearEstadoParaHojaRuta: function(estado) { 52 crearEstadoParaHojaRuta: function(estado) {
53 return $http.post(route + '/estado', {estado: estado}); 53 return $http.post(route + '/estado', {estado: estado});
54 }, 54 },
55 getNumeroHojaRuta: function() { 55 getNumeroHojaRuta: function() {
56 return $http.get(route + '/hoja-ruta/numero-siguiente'); 56 return $http.get(route + '/hoja-ruta/numero-siguiente');
57 }, 57 },
58 getRemitosByIdVehiculo: function(idVehiculo, fechaReparto) { 58 getRemitosByIdVehiculo: function(idVehiculo, fechaReparto, sinConfirmar) {
59 var noCofirmados = sinConfirmar ? '/sinConfirmar' : '';
59 return $http.get(route + '/vehiculo/obtener/remitos/' + 60 return $http.get(route + '/vehiculo/obtener/remitos/' +
60 idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10)); 61 idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10) + noCofirmados);
61 }, 62 },
62 desasociarRemitos: function(idsRemitos, idVehiculo, sinRemitos) { 63 desasociarRemitos: function(idsRemitos, idVehiculo, sinRemitos) {
63 return $http.post(route + '/vehiculo/desasociar-remitos', 64 return $http.post(route + '/vehiculo/desasociar-remitos',
64 { 65 {
65 idsRemitos: idsRemitos, 66 idsRemitos: idsRemitos,
66 idVehiculo: idVehiculo, 67 idVehiculo: idVehiculo,
67 vehiculoSinRemitos: sinRemitos 68 vehiculoSinRemitos: sinRemitos
68 }); 69 });
69 }, 70 },
70 getBotonera: function() { 71 getBotonera: function() {
71 return [ 72 return [
72 { 73 {
73 label: 'Fecha Entrega', 74 label: 'Fecha Entrega',
74 image: 'fechaDeReparto.png' 75 image: 'fechaDeReparto.png'
75 }, 76 },
76 { 77 {
77 label: 'Transportista', 78 label: 'Transportista',
78 image: 'transportista.png' 79 image: 'transportista.png'
79 }, 80 },
80 { 81 {
81 label: 'Chofer', 82 label: 'Chofer',
82 image: 'chofer.png' 83 image: 'chofer.png'
83 }, 84 },
84 { 85 {
85 label: 'Vehiculo', 86 label: 'Vehiculo',
86 image: 'vehiculos.png' 87 image: 'vehiculos.png'
87 }, 88 },
88 { 89 {
89 label: 'Tarifario', 90 label: 'Tarifario',
90 image: 'tarifario.png' 91 image: 'tarifario.png'
91 }, 92 },
92 { 93 {
93 label: 'Remitos', 94 label: 'Remitos',
94 image: 'remito.png' 95 image: 'remito.png'
95 }, 96 },
96 { 97 {
97 label: 'Vehiculos precargados', 98 label: 'Vehiculos precargados',
98 image: 'vehiculos.png' 99 image: 'vehiculos.png'
99 }, 100 },
100 { 101 {
101 label: 'Datos extra', 102 label: 'Datos extra',
102 image: 'tarifario.png' 103 image: 'tarifario.png'
103 } 104 }
104 ]; 105 ];
105 } 106 }
106 }; 107 };
107 }]); 108 }]);
108 109