Commit eb556b166083e4fbb7026bd298a809de97e23097
1 parent
45096db37a
Exists in
master
and in
2 other branches
refactor cookies
Showing
1 changed file
with
4 additions
and
1 deletions
Show diff stats
src/js/service.js
1 | angular.module('focaLogisticaPedidoRuta') | 1 | angular.module('focaLogisticaPedidoRuta') |
2 | .factory( | 2 | .factory( |
3 | 'focaLogisticaPedidoRutaService', [ | 3 | 'focaLogisticaPedidoRutaService', [ |
4 | '$http', | 4 | '$http', |
5 | '$cookies', | 5 | '$cookies', |
6 | 'API_ENDPOINT', | 6 | 'API_ENDPOINT', |
7 | '$filter', | 7 | '$filter', |
8 | function($http, $cookies, API_ENDPOINT, $filter) { | 8 | function($http, $cookies, API_ENDPOINT, $filter) { |
9 | var url = API_ENDPOINT.URL; | 9 | var url = API_ENDPOINT.URL; |
10 | return { | 10 | return { |
11 | idUsuario: $cookies.get('idUsuario'), | 11 | idUsuario: $cookies.get('vendedorCobrador'), |
12 | obtenerActividad: function(parametros) { | 12 | obtenerActividad: function(parametros) { |
13 | return $http.post(url + '/seguimiento/filtros', parametros); | 13 | return $http.post(url + '/seguimiento/filtros', parametros); |
14 | }, | 14 | }, |
15 | numeroHojaRuta: function() { | 15 | numeroHojaRuta: function() { |
16 | return $http.get(url + '/hoja-ruta/numero-siguiente'); | 16 | return $http.get(url + '/hoja-ruta/numero-siguiente'); |
17 | }, | 17 | }, |
18 | getRemitos: function(idVehiculo) { | 18 | getRemitos: function(idVehiculo) { |
19 | return $http.get(url + '/remito/sin-hoja-ruta/' +idVehiculo); | 19 | return $http.get(url + '/remito/sin-hoja-ruta/' +idVehiculo); |
20 | }, | 20 | }, |
21 | cerrarDistribuicion: function(remitos) { | 21 | cerrarDistribuicion: function(remitos) { |
22 | return $http.post(url + '/vehiculo/cierre-distribuicion', remitos); | 22 | return $http.post(url + '/vehiculo/cierre-distribuicion', remitos); |
23 | }, | 23 | }, |
24 | desasociarRemitos: function(remitos, idVehiculo, sinRemitos) { | 24 | desasociarRemitos: function(remitos, idVehiculo, sinRemitos) { |
25 | var idsRemitos = []; | 25 | var idsRemitos = []; |
26 | for (var i = 0; i < remitos.length; i++) { | 26 | for (var i = 0; i < remitos.length; i++) { |
27 | idsRemitos.push(remitos[i].id); | 27 | idsRemitos.push(remitos[i].id); |
28 | } | 28 | } |
29 | return $http.post(url + '/vehiculo/desasociar-remitos', | 29 | return $http.post(url + '/vehiculo/desasociar-remitos', |
30 | { | 30 | { |
31 | idsRemitos: idsRemitos, | 31 | idsRemitos: idsRemitos, |
32 | idVehiculo: idVehiculo, | 32 | idVehiculo: idVehiculo, |
33 | vehiculoSinRemitos: sinRemitos | 33 | vehiculoSinRemitos: sinRemitos |
34 | }); | 34 | }); |
35 | }, | 35 | }, |
36 | obtenerRemitosDeCarga: function(remitos) { | 36 | obtenerRemitosDeCarga: function(remitos) { |
37 | var remitosRes = []; | 37 | var remitosRes = []; |
38 | for(var i = 0; i < remitos.cisternas.length; i++) { | 38 | for(var i = 0; i < remitos.cisternas.length; i++) { |
39 | procesoCistena(remitos.cisternas[i], this.fecha.toISOString()); | 39 | procesoCistena(remitos.cisternas[i], this.fecha.toISOString()); |
40 | } | 40 | } |
41 | function procesoCistena(cisterna, fecha) { | 41 | function procesoCistena(cisterna, fecha) { |
42 | for(var j = 0; j < cisterna.cisternasCarga.length; j++) { | 42 | for(var j = 0; j < cisterna.cisternasCarga.length; j++) { |
43 | for(var k = 0; k < cisterna.cisternasCarga[j].cisternaMovimientos | 43 | for(var k = 0; k < cisterna.cisternasCarga[j].cisternaMovimientos |
44 | .length; k++) | 44 | .length; k++) |
45 | { | 45 | { |
46 | if(cisterna.cisternasCarga[j].fechaReparto.substring(0, 10) === | 46 | if(cisterna.cisternasCarga[j].fechaReparto.substring(0, 10) === |
47 | fecha.substring(0, 10)) | 47 | fecha.substring(0, 10)) |
48 | { | 48 | { |
49 | procesoMovimiento(cisterna.cisternasCarga[j] | 49 | procesoMovimiento(cisterna.cisternasCarga[j] |
50 | .cisternaMovimientos[k]); | 50 | .cisternaMovimientos[k]); |
51 | } | 51 | } |
52 | } | 52 | } |
53 | } | 53 | } |
54 | } | 54 | } |
55 | function procesoMovimiento(movimiento) { | 55 | function procesoMovimiento(movimiento) { |
56 | if(!movimiento.anulado && movimiento.remito && | 56 | if(!movimiento.anulado && movimiento.remito && |
57 | !movimiento.remito.idHojaRuta) { | 57 | !movimiento.remito.idHojaRuta) { |
58 | var remito = movimiento.remito; | 58 | var remito = movimiento.remito; |
59 | var yaEstaCargado = $filter('filter')(remitosRes, {id: remito.id}); | 59 | var yaEstaCargado = $filter('filter')(remitosRes, {id: remito.id}); |
60 | if(!yaEstaCargado.length && movimiento.metodo === 'carga') { | 60 | if(!yaEstaCargado.length && movimiento.metodo === 'carga') { |
61 | remitosRes.push(remito); | 61 | remitosRes.push(remito); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | } | 64 | } |
65 | return remitosRes; | 65 | return remitosRes; |
66 | }, | 66 | }, |
67 | getVehiculosByIdUsuario: function() { | 67 | getVehiculosByIdUsuario: function() { |
68 | return $http.get(url + '/vehiculo/usuario/' + this.idUsuario); | 68 | return $http.get(url + '/vehiculo/usuario/' + this.idUsuario); |
69 | }, | 69 | }, |
70 | getUnidadesByFecha: function() { | 70 | getUnidadesByFecha: function() { |
71 | return $http.post(url + '/vehiculo/listar/fecha', | 71 | return $http.post(url + '/vehiculo/listar/fecha', |
72 | {fecha: this.fecha}); | 72 | {fecha: this.fecha}); |
73 | }, | 73 | }, |
74 | setFechaReparto: function(fechaReparto) { | 74 | setFechaReparto: function(fechaReparto) { |
75 | this.fecha = fechaReparto; | 75 | this.fecha = fechaReparto; |
76 | }, | ||
77 | obtenerVehiculoById: function(idVehiculo) { | ||
78 | return $http.get(url + '/vehiculo/' + idVehiculo); | ||
76 | } | 79 | } |
77 | }; | 80 | }; |
78 | }]); | 81 | }]); |
79 | 82 |