Commit 8aac173c17f19c7cbb829cc985984a184bf2f50b

Authored by Nicolás Guarnieri
1 parent fd679a711e
Exists in master and in 1 other branch develop

refactor seguimiento

Showing 2 changed files with 161 additions and 111 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaAdminSeguimiento') .controller('focaAdminSeguimientoController', [ 1 angular.module('focaAdminSeguimiento') .controller('focaAdminSeguimientoController', [
2 '$scope', '$timeout', 'focaAdminSeguimientoService', 2 '$scope', '$timeout', 'focaAdminSeguimientoService',
3 'focaBotoneraLateralService','$location', '$routeParams', 3 'focaBotoneraLateralService','$location', '$routeParams',
4 function($scope, $timeout, focaAdminSeguimientoService, 4 function($scope, $timeout, focaAdminSeguimientoService,
5 focaBotoneraLateralService, $location, $routeParams) { 5 focaBotoneraLateralService, $location, $routeParams) {
6 6
7 $scope.actividad = ''; 7 $scope.actividad = '';
8 $scope.titulo = ''; 8 $scope.titulo = '';
9 var cabecera = ''; 9 var cabecera = '';
10 10
11 $scope.now = new Date(); 11 $scope.now = new Date();
12 12
13 if ($routeParams.parametro === 'nota-pedido') { 13 if ($routeParams.parametro === 'nota-pedido') {
14 $scope.actividad = 'Nota de pedido'; 14 $scope.actividad = 'Nota de pedido';
15 $scope.titulo = 'Seguimiento de nota de pedido'; 15 $scope.titulo = 'Seguimiento de nota de pedido';
16 cabecera = 'Vendedor:'; 16 cabecera = 'Vendedor:';
17 } 17 }
18 18
19 if ($routeParams.parametro === 'hoja-ruta') { 19 if ($routeParams.parametro === 'hoja-ruta') {
20 $scope.actividad = 'Entrega de producto'; 20 $scope.actividad = 'Entrega de producto';
21 $scope.titulo = 'Seguimiento de hoja de ruta'; 21 $scope.titulo = 'Seguimiento de hoja de ruta';
22 cabecera = 'Vehiculo:'; 22 cabecera = 'Vehiculo:';
23 } 23 }
24 24
25 if ($routeParams.parametro === 'cobranza') { 25 if ($routeParams.parametro === 'cobranza') {
26 $scope.actividad = 'Cobranza'; 26 $scope.actividad = 'Cobranza';
27 $scope.titulo = 'Seguimiento de cobranza'; 27 $scope.titulo = 'Seguimiento de cobranza';
28 cabecera = 'Cobrador:'; 28 cabecera = 'Cobrador:';
29 } 29 }
30 30
31 $scope.idUsuario = 0; 31 $scope.idUsuario = 0;
32 $scope.marcadores = []; 32 $scope.marcadores = [];
33 getSeguimiento(); 33 getSeguimiento();
34 34
35 $timeout(function() { 35 $timeout(function() {
36 $scope.$broadcast('addCabecera',{ 36 $scope.$broadcast('addCabecera',{
37 label: 'General', 37 label: 'General',
38 valor: '' 38 valor: ''
39 }); 39 });
40 }) 40 });
41 41
42 //SETEO BOTONERA LATERAL 42 //SETEO BOTONERA LATERAL
43 focaBotoneraLateralService.showSalir(true); 43 focaBotoneraLateralService.showSalir(true);
44 focaBotoneraLateralService.showPausar(false); 44 focaBotoneraLateralService.showPausar(false);
45 focaBotoneraLateralService.showGuardar(false); 45 focaBotoneraLateralService.showGuardar(false);
46 46
47 $scope.general = function() { 47 $scope.general = function() {
48 $scope.idUsuario = 0; 48 $scope.idUsuario = 0;
49 getSeguimiento(); 49 getSeguimiento();
50 $scope.$broadcast('removeCabecera', cabecera); 50 $scope.$broadcast('removeCabecera', cabecera);
51 $scope.$broadcast('addCabecera',{ 51 $scope.$broadcast('addCabecera',{
52 label: 'General', 52 label: 'General',
53 valor: '' 53 valor: ''
54 }); 54 });
55 }; 55 };
56 56
57 $scope.individual = function() { 57 $scope.individual = function() {
58 $scope.idUsuario = -1; 58 $scope.idUsuario = -1;
59 }; 59 };
60 60
61 $scope.salir = function() { 61 $scope.salir = function() {
62 $location.path('/'); 62 $location.path('/');
63 }; 63 };
64 64
65 $scope.search = function(key) { 65 $scope.search = function(key) {
66 if (key === 13) { 66 if (key === 13) {
67 $scope.idUsuario = $scope.idUsuarioInput; 67 $scope.idUsuario = $scope.idUsuarioInput;
68 getSeguimiento(); 68 getSeguimiento();
69 $scope.$broadcast('removeCabecera', 'General'); 69 $scope.$broadcast('removeCabecera', 'General');
70 $scope.$broadcast('addCabecera', { 70 $scope.$broadcast('addCabecera', {
71 label: cabecera, 71 label: cabecera,
72 valor: $scope.idUsuarioInput 72 valor: $scope.idUsuarioInput
73 }); 73 });
74 } 74 }
75 }; 75 };
76 76
77 $scope.fecha = function() { 77 $scope.fecha = function() {
78 getSeguimiento(); 78 getSeguimiento();
79 }; 79 };
80 80
81 function getSeguimiento() { 81 function getSeguimiento() {
82 var now = $scope.now; 82 var now = $scope.now;
83 var desde = new Date(new Date(now.setHours(0)).setMinutes(0)); 83 var desde = new Date(new Date(now.setHours(0)).setMinutes(0));
84 desde = desde.setDate(desde.getDate() - 1); 84 desde = desde.setDate(desde.getDate() - 1);
85 desde = new Date(desde); 85 desde = new Date(desde);
86 var datos = { 86 var datos = {
87 actividad: $scope.actividad, 87 actividad: $scope.actividad,
88 idUsuario: $scope.idUsuario, 88 idUsuario: $scope.idUsuario,
89 fechaDesde: desde, 89 fechaDesde: desde,
90 fechaHasta: new Date(new Date(now.setHours(23)).setMinutes(59)) 90 fechaHasta: new Date(new Date(now.setHours(23)).setMinutes(59))
91 }; 91 };
92 92
93 $scope.datosBuscados = { 93 $scope.datosBuscados = {
94 actividad: $scope.actividad, 94 actividad: $scope.actividad,
95 individual: $scope.idUsuario !== 0 ? true : false 95 individual: $scope.idUsuario !== 0 ? true : false
96 }; 96 };
97 97
98 focaAdminSeguimientoService.obtenerActividad(datos).then(function(datos) { 98 focaAdminSeguimientoService.obtenerActividad(datos).then(function(datos) {
99 99
100 $scope.marcadores = datos.data; 100 $scope.marcadores = datos.data;
101 }); 101 });
102 } 102 }
103 } 103 }
104 ]); 104 ]);
105 105
src/js/osm-directive.js
1 angular.module('focaAdminSeguimiento').directive('osm', function() { 1 angular.module('focaAdminSeguimiento').directive('osm', function() {
2 return { 2 return {
3 restrict: 'E', 3 restrict: 'E',
4 link: function(scope, el, attrs) { 4 link: function(scope, el, attrs) {
5 var contenedor = document.createElement('div'); 5 var contenedor = document.createElement('div');
6 el.append(contenedor); 6 el.append(contenedor);
7 scope.map = L.map(contenedor).setView([attrs.latitud, attrs.longitud], attrs.zoom); 7 scope.map = L.map(contenedor).setView([attrs.latitud, attrs.longitud], attrs.zoom);
8 L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(scope.map); 8 L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(scope.map);
9 }, 9 },
10 controller: ['$scope', '$filter', function($scope, $filter) { 10 controller: ['$scope', '$filter', function($scope, $filter) {
11 $scope.markers = []; 11 $scope.markers = [];
12 $scope.$watch('marcadores', function() { 12 $scope.$watch('marcadores', function() {
13 for(var i in $scope.markers) { 13 for(var i in $scope.markers) {
14 $scope.map.removeLayer($scope.markers[i]); 14 $scope.map.removeLayer($scope.markers[i]);
15 } 15 }
16 16
17 $scope.markers = []; 17 $scope.markers = [];
18 var observacion = '';
19
18 angular.forEach($scope.marcadores, function(marcador) { 20 angular.forEach($scope.marcadores, function(marcador) {
19 var observacion = '';
20
21 if ($scope.parametros.actividad === 'Nota de pedido') { 21 if ($scope.parametros.actividad === 'Nota de pedido') {
22 observacion += 22 observacion = generarObservacion(getNotaPedido(marcador));
23 'Vendedor: ' + marcador.notaPedido.idVendedor + ' - ' +
24 (
25 marcador.notaPedido.vendedor ?
26 marcador.notaPedido.vendedor.NomVen :
27 ''
28 ) + '<br/>';
29
30 if (!$scope.parametros.individual) {
31 observacion += '<b>Ultima Nota de Pedido</b><br/>';
32 }
33 observacion += 'Fecha: ' +
34 $filter('date')(marcador.fecha.slice(0,10), 'dd/MM/yyyy') + ' ' +
35 marcador.fecha.slice(11,19) + '<br/>';
36 observacion += 'Nº: ' + $filter('comprobante')([
37 marcador.notaPedido.sucursal,
38 marcador.notaPedido.numeroNotaPedido
39 ]) + '<br/>';
40 observacion += 'Cliente: ' +
41 marcador.notaPedido.cliente.NOM + '<br/>';
42
43 if ($scope.parametros.individual) {
44 observacion +=
45 'Total: ' + $filter('currency')(marcador.notaPedido.total, '$');
46 observacion = 'Orden: ' + marcador.orden + '<br/>' + observacion;
47
48 if (marcador.distancia) {
49 observacion += '<br/>Distancia a casa central: ' +
50 marcador.distancia + 'km';
51 }
52 } else {
53 observacion += 'Cantidad de nota de pedido: ' +
54 marcador.cantidad + '<br/>';
55 observacion += 'Total Vendido: ' +
56 $filter('currency')(marcador.total, '$');
57 }
58 } 23 }
59 24
60 if ($scope.parametros.actividad === 'Cobranza') { 25 if ($scope.parametros.actividad === 'Cobranza') {
61 observacion += 'Cobrador: ' + marcador.recibo.cobrador.id + ' - ' + 26 observacion = getCobranza(marcador);
62 marcador.recibo.CFE + '<br/>'; 27 }
28
29 if ($scope.parametros.actividad === 'Entrega de producto') {
30 observacion = getEntrega(marcador);
31 }
32
33 if (observacion) {
34 $scope.markers.push(
35 L.marker([marcador.latitud, marcador.longitud]).addTo($scope.map)
36 .bindPopup(observacion)
37 );
38
39 $scope.markers[0].openPopup();
40 }
41 });
63 42
64 if (!$scope.parametros.individual) { 43 function getNotaPedido(marcador) {
65 observacion += '<b>Ultima Cobranza</b><br/>'; 44 var observacion = [];
45
46 if (!marcador.notaPedido.id) {
47 return false;
48 }
49
50 var notaPedido = marcador.notaPedido;
51 var textVendedor = notaPedido.idVendedor + ' - ';
52
53 if (notaPedido.vendedor) {
54 textVendedor += notaPedido.vendedor.NomVen;
55 }
56
57 observacion.push(['Vendedor', textVendedor]);
58
59 if (!$scope.parametros.individual) {
60 observacion.push(['Ultima Nota de Pedido', '']);
61 }
62
63 var textFecha = $filter('date')(marcador.fecha.slice(0,10), 'dd/MM/yyyy') +
64 ' ' + marcador.fecha.slice(11,19);
65 observacion.push(['Fecha', textFecha]);
66
67 observacion.push(['Nº',
68 $filter('comprobante')([notaPedido.sucursal, notaPedido.numeroNotaPedido ])
69 ]);
70
71 if (notaPedido.cliente) {
72 observacion.push(['Cliente', notaPedido.cliente.NOM]);
73 }
74
75 if ($scope.parametros.individual) {
76 observacion.push(['Total', $filter('currency')(notaPedido.total, '$')]);
77 observacion.unshift(['Orden', marcador.orden]);
78
79 if (marcador.distancia) {
80 observacion.push(['Distancia a casa central',
81 marcador.distancia + 'km'
82 ]);
66 } 83 }
84 } else {
85 observacion.push(['Cantidad de nota de pedido',
86 marcador.cantidad
87 ]);
88
89 observacion.push(['Total Vendido',
90 $filter('currency')(marcador.total, '$')
91 ]);
92 }
93
94 console.info(marcador, observacion);
95 return observacion;
96 }
97
98 function getCobranza(marcador) {
99 observacion += 'Cobrador: ' + marcador.recibo.cobrador.id + ' - ' +
100 marcador.recibo.CFE + '<br/>';
101
102 if (!$scope.parametros.individual) {
103 observacion += '<b>Ultima Cobranza</b><br/>';
104 }
67 105
68 observacion += 'Fecha: ' + 106 observacion += 'Fecha: ' +
69 $filter('date')(marcador.fecha.slice(0,10), 'dd/MM/yyyy') + ' ' + 107 $filter('date')(marcador.fecha.slice(0,10), 'dd/MM/yyyy') + ' ' +
70 marcador.fecha.slice(11,19) + '<br/>'; 108 marcador.fecha.slice(11,19) + '<br/>';
71 observacion += 'Nº: ' + $filter('comprobante')([ 109 observacion += 'Nº: ' + $filter('comprobante')([
72 marcador.sucursal, marcador.idUsuario]) + '<br/>'; 110 marcador.sucursal, marcador.idUsuario]) + '<br/>';
73 observacion += 'Cliente: ' + marcador.recibo.cliente.NOM + '<br/>'; 111 observacion += 'Cliente: ' + marcador.recibo.cliente.NOM + '<br/>';
74 112
75 if ($scope.parametros.individual) { 113 if ($scope.parametros.individual) {
76 if (marcador.distancia) { 114 if (marcador.distancia) {
77 observacion += 'Distancia a casa central: ' + 115 observacion += 'Distancia a casa central: ' +
78 marcador.distancia + 'km' + '<br/>'; 116 marcador.distancia + 'km' + '<br/>';
79 observacion += 'Total Cobrado: ' +
80 $filter('currency')(marcador.factura.IPA, '$');
81 }
82 } else {
83 observacion += 'Cantidad de cobranzas: ' +
84 marcador.cantidad + '<br/>';
85 observacion += 'Total Cobrado: ' + 117 observacion += 'Total Cobrado: ' +
86 $filter('currency')(marcador.factura.IPA, '$'); 118 $filter('currency')(marcador.factura.IPA, '$');
87 } 119 }
88 } 120 } else {
121 observacion += 'Cantidad de cobranzas: ' +
122 marcador.cantidad + '<br/>';
123 observacion += 'Total Cobrado: ' +
124 $filter('currency')(marcador.factura.IPA, '$');
125 }
89 126
90 if ($scope.parametros.actividad === 'Entrega de producto') { 127 return observacion;
91 var remito = marcador.hojaRutaMovimiento.remito; 128 }
92 observacion += 'Vehiculo: ' + 129
93 remito.hojaRuta.idVehiculo + ' - ' + 130 function getEntrega(marcador) {
94 remito.hojaRuta.vehiculo.tractor + '<br/>'; 131 var observacion = '';
95 observacion += 'Transportista: ' + 132 var remito = marcador.hojaRutaMovimiento.remito;
96 remito.hojaRuta.transportista.NOM + '<br/>'; 133 observacion += 'Vehiculo: ' +
97 observacion += 'Chofer: ' + 134 remito.hojaRuta.idVehiculo + ' - ' +
98 remito.hojaRuta.chofer.nombre + '<br/>'; 135 remito.hojaRuta.vehiculo.tractor + '<br/>';
99 observacion += 'Hoja de ruta: ' + $filter('comprobante')([ 136 observacion += 'Transportista: ' +
100 remito.hojaRuta.sucursal, 137 remito.hojaRuta.transportista.NOM + '<br/>';
101 remito.hojaRuta.numeroHojaRuta 138 observacion += 'Chofer: ' +
102 ]) + '<br/>'; 139 remito.hojaRuta.chofer.nombre + '<br/>';
103 140 observacion += 'Hoja de ruta: ' + $filter('comprobante')([
104 if (!$scope.parametros.individual) { 141 remito.hojaRuta.sucursal,
105 observacion += '<b>Ultimo Remito</b><br/>'; 142 remito.hojaRuta.numeroHojaRuta
143 ]) + '<br/>';
144
145 if (!$scope.parametros.individual) {
146 observacion += '<b>Ultimo Remito</b><br/>';
147 }
148
149 observacion += 'Fecha: ' +
150 $filter('date')(marcador.fecha.slice(0,10), 'dd/MM/yyyy') + ' ' +
151 marcador.fecha.slice(11,19) + '<br/>';
152
153 observacion += 'Nº: ' + $filter('comprobante')([
154 remito.sucursal,
155 remito.numeroRemito
156 ]) + '<br/>';
157 observacion += 'Cliente: ' +
158 remito.cliente.NOM + '<br/>';
159
160 if ($scope.parametros.individual) {
161 observacion += 'Producto: ' +
162 remito.articulosRemito[0].descripcion + '<br/>';
163 observacion += 'Cantidad entregada: ' +
164 remito.carga + '<br/>';