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