Commit 5b8426e39b368d1c3b56172bb06efe5f0cac10ee
1 parent
7a8d5d0121
Exists in
master
si el chofer tiene hoja ruta asignada, avisa modal confirm
Showing
3 changed files
with
49 additions
and
15 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaActivarHojaRuta') | 1 | angular.module('focaActivarHojaRuta') |
2 | .controller('focaActivarHojaRutaController', [ | 2 | .controller('focaActivarHojaRutaController', [ |
3 | '$scope', 'focaActivarHojaRutaService', '$location', 'focaModalService', | 3 | '$scope', 'focaActivarHojaRutaService', 'focaModalService', 'focaBotoneraLateralService', |
4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', | 4 | '$filter', |
5 | function($scope, focaActivarHojaRutaService, $location, focaModalService, | 5 | function($scope, focaActivarHojaRutaService, focaModalService, focaBotoneraLateralService, |
6 | $uibModal, focaBotoneraLateralService, $timeout) { | 6 | $filter) { |
7 | config(); | 7 | config(); |
8 | 8 | ||
9 | //METODOS | 9 | //METODOS |
10 | function config() { | 10 | function config() { |
11 | $scope.botonera = [{ | 11 | $scope.botonera = [{ |
12 | label: 'Chofer', | 12 | label: 'Chofer', |
13 | image: 'cliente.png' | 13 | image: 'cliente.png' |
14 | }]; | 14 | }]; |
15 | //SETEO BOTONERA LATERAL | 15 | //SETEO BOTONERA LATERAL |
16 | focaBotoneraLateralService.showSalir(true); | 16 | focaBotoneraLateralService.showSalir(true); |
17 | focaBotoneraLateralService.showPausar(false); | 17 | focaBotoneraLateralService.showPausar(false); |
18 | focaBotoneraLateralService.showCancelar(false); | 18 | focaBotoneraLateralService.showCancelar(false); |
19 | focaBotoneraLateralService.showGuardar(false); | 19 | focaBotoneraLateralService.showGuardar(false); |
20 | 20 | ||
21 | init(); | 21 | init(); |
22 | } | 22 | } |
23 | 23 | ||
24 | function init() { | 24 | function init() { |
25 | $scope.now = new Date(); | 25 | $scope.now = new Date(); |
26 | $scope.hojasRuta = []; | 26 | $scope.hojasRuta = []; |
27 | $scope.$broadcast('removeCabecera', 'Chofer:'); | 27 | $scope.$broadcast('removeCabecera', 'Chofer:'); |
28 | } | 28 | } |
29 | 29 | ||
30 | $scope.seleccionarChofer = function() { | 30 | $scope.seleccionarChofer = function() { |
31 | var parametrosModal = { | 31 | var parametrosModal = { |
32 | titulo: 'Búsqueda de Chofer', | 32 | titulo: 'Búsqueda de Chofer', |
33 | query: '/chofer', | 33 | query: '/chofer', |
34 | columnas: [ | 34 | columnas: [ |
35 | { | 35 | { |
36 | propiedad: 'id', | 36 | propiedad: 'id', |
37 | nombre: 'Código', | 37 | nombre: 'Código', |
38 | filtro: { | 38 | filtro: { |
39 | nombre: 'rellenarDigitos', | 39 | nombre: 'rellenarDigitos', |
40 | parametro: 3 | 40 | parametro: 3 |
41 | } | 41 | } |
42 | }, | 42 | }, |
43 | { | 43 | { |
44 | propiedad: 'nombre', | 44 | propiedad: 'nombre', |
45 | nombre: 'Nombre' | 45 | nombre: 'Nombre' |
46 | }, | 46 | }, |
47 | { | 47 | { |
48 | propiedad: 'dni', | 48 | propiedad: 'dni', |
49 | nombre: 'DNI' | 49 | nombre: 'DNI' |
50 | }, | 50 | }, |
51 | { | 51 | { |
52 | propiedad: 'telefono', | 52 | propiedad: 'telefono', |
53 | nombre: 'Teléfono' | 53 | nombre: 'Teléfono' |
54 | } | 54 | } |
55 | ] | 55 | ] |
56 | }; | 56 | }; |
57 | focaModalService.modal(parametrosModal).then( | 57 | focaModalService.modal(parametrosModal).then( |
58 | function(chofer) { | 58 | function(chofer) { |
59 | $scope.chofer = chofer.id; | 59 | $scope.chofer = chofer.id; |
60 | focaActivarHojaRutaService.getHojasRutas($scope.chofer) | 60 | focaActivarHojaRutaService.getHojasRutas($scope.chofer) |
61 | .then(function(hojasRutas) { | 61 | .then(function(hojasRutas) { |
62 | $scope.$broadcast('addCabecera', { | 62 | $scope.$broadcast('addCabecera', { |
63 | label: 'Chofer:', | 63 | label: 'Chofer:', |
64 | valor: $scope.chofer + ' - ' + chofer.nombre | 64 | valor: $scope.chofer + ' - ' + chofer.nombre |
65 | }); | 65 | }); |
66 | 66 | ||
67 | $scope.hojasRuta = hojasRutas.data; | 67 | $scope.hojasRuta = hojasRutas.data; |
68 | }) | 68 | }); |
69 | }, function() { | 69 | }, function() {} |
70 | ); | ||
71 | }; | ||
72 | |||
73 | $scope.activarHojaRuta = function(hoja_ruta) { | ||
74 | validarChoferDisponible().then(function(hojaRutaAsignada) { | ||
70 | 75 | ||
76 | if (hojaRutaAsignada) { | ||
77 | var texto = 'El chofer tiene asignada la Hoja de Ruta Nº ' + | ||
78 | $filter('comprobante')([hojaRutaAsignada.sucursal, | ||
79 | hojaRutaAsignada.numeroHojaRuta]) + | ||
80 | ', ¿desea reemplazarla por esta?'; | ||
81 | |||
82 | focaModalService | ||
83 | .confirm(texto) | ||
84 | .then(function(res) { | ||
85 | if (res) activar(); | ||
86 | }); | ||
87 | } else { | ||
88 | activar(); | ||
71 | } | 89 | } |
72 | ); | 90 | |
91 | function activar() { | ||
92 | focaActivarHojaRutaService | ||
93 | .activarHojaRuta(hoja_ruta.id, $scope.chofer) | ||
94 | .then(function(hojaRuta) { | ||
95 | init(); | ||
96 | focaModalService.alert('Hoja de ruta activada'); | ||
97 | }); | ||
98 | } | ||
99 | |||
100 | }); | ||
73 | }; | 101 | }; |
74 | 102 | ||
75 | $scope.activarHojaRuta = function(hoja_ruta_id) { | 103 | function validarChoferDisponible() { |
76 | focaActivarHojaRutaService.activarHojaRuta(hoja_ruta_id, $scope.chofer) | 104 | return new Promise(function(resolve, reject) { |
77 | .then(function(hojaRuta) { | 105 | focaActivarHojaRutaService |
78 | init(); | 106 | .getHojaRutaByIdChofer($scope.chofer) |
79 | focaModalService.alert('Hoja de ruta activada'); | 107 | .then(function(res) { |
80 | }) | 108 | resolve(res.data); |
109 | }) | ||
110 | .catch(reject); | ||
111 | }); | ||
81 | } | 112 | } |
82 | 113 | ||
83 | 114 | ||
84 | /* | 115 | /* |
85 | 116 | ||
86 | if(focaActivarHojaRutaService.transportistaSeleccionado.COD) { | 117 | if(focaActivarHojaRutaService.transportistaSeleccionado.COD) { |
87 | elegirTransportista(focaActivarHojaRutaService.transportistaSeleccionado); | 118 | elegirTransportista(focaActivarHojaRutaService.transportistaSeleccionado); |
88 | } | 119 | } |
89 | focaActivarHojaRutaService.cleanCisternasLocal(); | 120 | focaActivarHojaRutaService.cleanCisternasLocal(); |
90 | $scope.editar = function(id) { | 121 | $scope.editar = function(id) { |
91 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 122 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); |
92 | }; | 123 | }; |
93 | $scope.solicitarConfirmacion = function(vehiculo) { | 124 | $scope.solicitarConfirmacion = function(vehiculo) { |
94 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 125 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + |
95 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 126 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( |
96 | function(data) { | 127 | function(data) { |
97 | if(data) { | 128 | if(data) { |
98 | focaActivarHojaRutaService.deleteVehiculo(vehiculo.id); | 129 | focaActivarHojaRutaService.deleteVehiculo(vehiculo.id); |
99 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 130 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
100 | } | 131 | } |
101 | } | 132 | } |
102 | ); | 133 | ); |
103 | }; | 134 | }; |
104 | 135 | ||
105 | function elegirTransportista(transportista) { | 136 | function elegirTransportista(transportista) { |
106 | var codigo = ('00000' + transportista.COD).slice(-5); | 137 | var codigo = ('00000' + transportista.COD).slice(-5); |
107 | $scope.idTransportista = transportista.COD; | 138 | $scope.idTransportista = transportista.COD; |
108 | $scope.filtros = transportista.NOM.trim(); | 139 | $scope.filtros = transportista.NOM.trim(); |
109 | $timeout(function() { | 140 | $timeout(function() { |
110 | $scope.$broadcast('addCabecera', { | 141 | $scope.$broadcast('addCabecera', { |
111 | label: 'Transportista:', | 142 | label: 'Transportista:', |
112 | valor: codigo + ' - ' + transportista.NOM | 143 | valor: codigo + ' - ' + transportista.NOM |
113 | }); | 144 | }); |
114 | }); | 145 | }); |
115 | buscar(transportista.COD); | 146 | buscar(transportista.COD); |
116 | } | 147 | } |
117 | 148 | ||
118 | function buscar(idTransportista) { | 149 | function buscar(idTransportista) { |
119 | focaActivarHojaRutaService | 150 | focaActivarHojaRutaService |
120 | .getVehiculosPorTransportista(idTransportista) | 151 | .getVehiculosPorTransportista(idTransportista) |
121 | .then(function(datos) { | 152 | .then(function(datos) { |
122 | $scope.vehiculos = datos.data; | 153 | $scope.vehiculos = datos.data; |
123 | }); | 154 | }); |
124 | }*/ | 155 | }*/ |
125 | } | 156 | } |
126 | ]); | 157 | ]); |
127 | 158 |
src/js/service.js
1 | angular.module('focaActivarHojaRuta') | 1 | angular.module('focaActivarHojaRuta') |
2 | .factory('focaActivarHojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .factory('focaActivarHojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { |
3 | return { | 3 | return { |
4 | getHojasRutas: function(chofer) { | 4 | getHojasRutas: function(chofer) { |
5 | return $http.get(API_ENDPOINT.URL + '/hoja-ruta/disponible/' + chofer); | 5 | return $http.get(API_ENDPOINT.URL + '/hoja-ruta/disponible/' + chofer); |
6 | }, | 6 | }, |
7 | activarHojaRuta: function(hoja_ruta, chofer) { | 7 | activarHojaRuta: function(hoja_ruta, chofer) { |
8 | return $http.get(API_ENDPOINT.URL + '/hoja-ruta/activar/' + hoja_ruta + '/' + chofer); | 8 | return $http.get(API_ENDPOINT.URL + '/hoja-ruta/activar/' + hoja_ruta + '/' + chofer); |
9 | }, | ||
10 | getHojaRutaByIdChofer: function(chofer) { | ||
11 | return $http.get(API_ENDPOINT.URL + '/hoja-ruta/chofer/' + chofer); | ||
9 | } | 12 | } |
10 | }; | 13 | }; |
11 | }]); | 14 | }]); |
12 | 15 |
src/views/activar-hoja-ruta.html
1 | <div class="row"> | 1 | <div class="row"> |
2 | <foca-cabecera-facturador | 2 | <foca-cabecera-facturador |
3 | titulo="'Activar Hoja de Ruta'" | 3 | titulo="'Activar Hoja de Ruta'" |
4 | fecha="now" | 4 | fecha="now" |
5 | class="mb-0 col-lg-12" | 5 | class="mb-0 col-lg-12" |
6 | ></foca-cabecera-facturador> | 6 | ></foca-cabecera-facturador> |
7 | </div> | 7 | </div> |
8 | <div class="row"> | 8 | <div class="row"> |
9 | <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> | 9 | <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> |
10 | <div class="row px-5 py-2 botonera-secundaria"> | 10 | <div class="row px-5 py-2 botonera-secundaria"> |
11 | <div class="col-12"> | 11 | <div class="col-12"> |
12 | <foca-botonera-facturador botones="botonera" max="6" class="row"></foca-botonera-facturador> | 12 | <foca-botonera-facturador botones="botonera" max="6" class="row"></foca-botonera-facturador> |
13 | </div> | 13 | </div> |
14 | </div> | 14 | </div> |
15 | <!-- <div class="col-6 form-group"> | 15 | <!-- <div class="col-6 form-group"> |
16 | <input seleccionarTransportista() | 16 | <input seleccionarTransportista() |
17 | type="text" | 17 | type="text" |
18 | teclado-virtual | 18 | teclado-virtual |
19 | class="form-control form-control-sm" | 19 | class="form-control form-control-sm" |
20 | placeholder="Búsqueda" | 20 | placeholder="Búsqueda" |
21 | ng-model="filtros" | 21 | ng-model="filtros" |
22 | /> | 22 | /> |
23 | </div> --> | 23 | </div> --> |
24 | <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> | 24 | <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> |
25 | <thead> | 25 | <thead> |
26 | <tr> | 26 | <tr> |
27 | <th>Número</th> | 27 | <th>Número</th> |
28 | <th>Fecha</th> | 28 | <th>Fecha</th> |
29 | <th>Remitos</th> | 29 | <th>Remitos</th> |
30 | <th class="text-center"> | 30 | <th class="text-center"> |
31 | </th> | 31 | </th> |
32 | </tr> | 32 | </tr> |
33 | </thead> | 33 | </thead> |
34 | <tbody> | 34 | <tbody> |
35 | <tr ng-repeat="hojaRuta in hojasRuta | filter:filtros"> | 35 | <tr ng-repeat="hojaRuta in hojasRuta | filter:filtros"> |
36 | <td ng-bind="[hojaRuta.sucursal, hojaRuta.numeroHojaRuta] | comprobante"></td> | 36 | <td ng-bind="[hojaRuta.sucursal, hojaRuta.numeroHojaRuta] | comprobante"></td> |
37 | <td ng-bind="hojaRuta.fechaReparto | date:'yyyy-MM-dd'"></td> | 37 | <td ng-bind="hojaRuta.fechaReparto | date:'yyyy-MM-dd':'-0300'"></td> |
38 | <td ng-bind="hojaRuta.remitos.length"></td> | 38 | <td ng-bind="hojaRuta.remitos.length"></td> |
39 | <td class="text-center"> | 39 | <td class="text-center"> |
40 | <button | 40 | <button |
41 | class="btn btn-outline-dark boton-accion" | 41 | class="btn btn-outline-dark boton-accion" |
42 | title="Activar" | 42 | title="Activar" |
43 | ng-click="activarHojaRuta(hojaRuta.id)" | 43 | ng-click="activarHojaRuta(hojaRuta)" |
44 | > | 44 | > |
45 | <i class="fa fa-check"></i> | 45 | <i class="fa fa-check"></i> |
46 | </button> | 46 | </button> |
47 | </td> | 47 | </td> |
48 | </tr> | 48 | </tr> |
49 | </body> | 49 | </body> |
50 | </table> | 50 | </table> |
51 | </div> | 51 | </div> |
52 | </div> | 52 | </div> |
53 | 53 |