controller-productividad.js
8.85 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
angular.module('focaModalInforme')
.controller('focaModalInformeProductividadController',
[
'$filter',
'$scope',
'$uibModalInstance',
'focaModalInformeProductividadService',
'i18nService',
'focaModalService',
function($filter, $scope, $uibModalInstance,
focaModalInformeProductividadService, i18nService, focaModalService
) {
i18nService.setCurrentLang('es');
var fecha = new Date();
$scope.generando = false;
$scope.buscar = true;
$scope.informe = {};
$scope.params = {
fechaHasta: new Date(),
fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)),
sector: undefined,
diferenciarProductos: false,
diferenciarMeses: false
};
$scope.gridOptions = {
enableGridMenu: true,
exporterMenuCsv: false,
exporterPdfPageSize: 'A4',
exporterPdfFooter: function (currentPage, pageCount) {
return {
columns: [
{text: $filter('date')(new Date(), 'dd/MM/yyyy'),
margin: [40, 0]},
{text: currentPage + ' de ' + pageCount,
margin: [28, 0], alignment: 'right'}
]
};
},
columnDefs: [
{
field: 'cliente',
enableSorting: false,
cellClass: function(grid, row, col) {
var value = grid.getCellValue(row,col);
if (value.indexOf('Vendedores') !== -1 ||
value.indexOf('Cobradores') !== -1 ||
value.indexOf('Transportistas') !== -1)
return 'yellow w-100';
if (value.indexOf('Vendedor:') !== -1 ||
value.indexOf('Cobrador:') !== -1 ||
value.indexOf('Transportista:') !== -1)
return 'red w-100';
if (value.indexOf('Fecha:') !== -1)
return 'green w-100';
}
},
{
field: 'fecha',
enableSorting: false,
cellClass: function(grid, row, col) {
if (!grid.getCellValue(row,col))
return 'd-none';
}
},
{
field: 'kmRecorridos',
enableSorting: false,
cellClass: function(grid, row, col) {
if (!grid.getCellValue(row,col))
return 'd-none';
}
},
{
field: 'geolocalizacion',
enableSorting: false,
cellClass: function(grid, row, col) {
if (!grid.getCellValue(row,col))
return 'd-none';
}
}
]
};
$scope.generarInforme = function() {
//$scope.generando = true;
focaModalInformeProductividadService
.getInformeData($scope.params)
.then(function(res) {
var result = [];
console.log(res);
if (true) {
result.push({
cliente: 'Vendedores'
});
res.data.vendedores.forEach(function(vendedor) {
result.push({
cliente: 'Vendedor: ' + vendedor.NOM
});
vendedor.notasPedido.forEach(function(notaPedido) {
var seguimiento = notaPedido.seguimiento;
result.push({
cliente: notaPedido.cliente.NOM,
fecha: seguimiento ? $filter('date')(seguimiento.fecha) : $filter('date')(notaPedido.fechaCarga),
kmRecorridos: seguimiento ? $filter('number')(seguimiento.kmRecorridos || 0, 2) : $filter('number')(0, 2),
geolocalizacion: seguimiento ? seguimiento.latitud + ', ' + seguimiento.longitud : ''
});
});
});
}
if (true) {
result.push({
cliente: 'Cobradores'
});
res.data.cobradores.forEach(function(cobrador) {
result.push({
cliente: 'Cobrador: ' + cobrador.NOM
});
cobrador.cobranzas.forEach(function(cobranza) {
var seguimiento = cobranza.seguimiento;
result.push({
cliente: cobranza.cliente.NOM,
fecha: seguimiento ? $filter('date')(seguimiento.fecha, 'dd/MM/yyyy') : $filter('date')(cobranza.FEC),
kmRecorridos: seguimiento ? $filter('number')(seguimiento.kmRecorridos || 0, 2) : $filter('number')(0, 2),
geolocalizacion: seguimiento ? seguimiento.latitud + ', ' + seguimiento.longitud : ''
});
});
});
}
if (true) {
result.push({
cliente: 'Transportistas'
});
res.data.transportistas.forEach(function(transportista) {
result.push({
cliente: 'Transportista: ' + transportista.NOM
});
transportista.remitos.forEach(function(remito) {
var kms = 0,
geolocalizacion;
remito.hojaRutaMovimiento.forEach(function(movimiento) {
kms += movimiento.seguimiento.kmRecorridos || 0;
geolocalizacion = geolocalizacion ||
movimiento.seguimiento.latitud + ', ' +
movimiento.seguimiento.longitud;
});
result.push({
cliente: remito.cliente.NOM,
fecha: $filter('date')(remito.fechaRemito, 'dd/MM/yyyy'),
kmRecorridos: $filter('number')(kms, 2),
geolocalizacion: geolocalizacion
});
});
});
}
$scope.gridOptions.data = result;
$scope.generando = false;
$scope.buscar = false;
});
};
$scope.volver = function() {
$scope.buscar = true;
};
$scope.cancel = function() {
$uibModalInstance.dismiss('Cancelar');
};
$scope.clearSector = function() {
$scope.params.sector = undefined;
};
}
]
);