Commit bf620a4814a0686822a3b86454b3bef93975bd9a

Authored by Eric Fernandez
Exists in master and in 2 other branches develop, lab

Merge branch 'master' into 'develop'

Master

See merge request !21
src/js/controller.js
1 angular.module('focaAbmChofer') 1 angular.module('focaAbmChofer')
2 .controller('focaAbmChoferesController', [ 2 .controller('focaAbmChoferesController', [
3 '$scope', 'focaAbmChoferService', '$location', '$uibModal', 3 '$scope', 'focaAbmChoferService', '$location', '$uibModal',
4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage',
5 '$routeParams', '$filter',
5 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService, 6 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService,
6 focaBotoneraLateralService, $timeout, $localStorage) { 7 focaBotoneraLateralService, $timeout, $localStorage, $routeParams, $filter) {
7 8
9 $scope.focused = 1;
8 $scope.now = new Date(); 10 $scope.now = new Date();
11 $scope.nuevo = $routeParams.id === '0';
9 $scope.filters = ''; 12 $scope.filters = '';
10 $scope.choferes = []; 13 $scope.choferes = [];
14 $scope.creando = false;
15 $scope.crear = false;
16 $scope.transportistas = [];
11 $scope.botonera = [{ 17 $scope.botonera = [{
12 label: 'Transportista', 18 label: 'Transportista',
13 image: 'cliente.png' 19 image: 'cliente.png'
14 }]; 20 }];
21 $scope.next = function(key) {
22 if (key === 13) $scope.focused++;
23 };
15 24
16 //SETEO BOTONERA LATERAL 25 //SETEO BOTONERA LATERAL
17 $timeout(function() { 26 $timeout(function() {
18 focaBotoneraLateralService.showSalir(false); 27 focaBotoneraLateralService.showSalir(false);
19 focaBotoneraLateralService.showPausar(false); 28 focaBotoneraLateralService.showPausar(false);
20 focaBotoneraLateralService.showCancelar(false); 29 focaBotoneraLateralService.showCancelar(false);
21 focaBotoneraLateralService.showGuardar(false); 30 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
22 focaBotoneraLateralService.addCustomButton('Salir', salir); 31 focaBotoneraLateralService.addCustomButton('Salir', salir);
23 }); 32 });
24 33
25 if (focaAbmChoferService.transportistaSeleccionado.COD) { 34 if (focaAbmChoferService.transportistaSeleccionado.COD) {
26 elegirTransportista(focaAbmChoferService.transportistaSeleccionado); 35 elegirTransportista(focaAbmChoferService.transportistaSeleccionado);
27 } 36 }
28 37
29 $scope.editar = function(id) { 38 focaAbmChoferService.getTiposDocumento().then(function(res) {
30 $location.path('/chofer/' + id + '/' + $scope.idTransportista); 39 $scope.tiposDocumento = res.data;
40 });
41
42 $scope.crearChofer = function () {
43 var chofer = {
44 id: 0,
45 nombre: '',
46 telefono: '',
47 editando: true,
48 };
49 $scope.choferes.unshift(chofer);
50 $scope.crear = false;
51 };
52
53 $scope.editar = function(chofer) {
54 $scope.choferes.forEach(function(chofer) {
55 chofer.editando = false;
56 $scope.crear = false;
57 });
58 chofer.editando = true;
59 $scope.inicial = angular.copy(chofer);
60 };
61
62 $scope.agregarChofer = function (chofer) {
63 if (!chofer.nombre) {
64 focaModalService.alert('Ingrese nombre');
65 return;
66 } else if (!chofer.idTipoDocumento) {
67 focaModalService.alert('Ingrese tipo documento');
68 return;
69 }
70 validaDni(chofer);
71 };
72
73 $scope.tipoDocumento = function (idTipoDocumento) {
74 var value = '';
75 switch (parseInt(idTipoDocumento)) {
76 case 96 :
77 value = 'DNI';
78 break;
79 case 80 :
80 value = 'CUIT';
81 break;
82 case 86 :
83 value = 'CUIL';
84 break;
85 default:
86 value = '';
87 break;
88 }
89 return value;
90 };
91
92 $scope.volver = function (chofer, key) {
93 if (chofer.idTransportista === undefined) {
94 $scope.choferes.shift();
95 $scope.crear = true;
96 chofer.editando = false;
97 return;
98 } else if (chofer.id !== 0 || !$scope.crear) {
99 $scope.choferes[key] = $scope.inicial;
100 $scope.choferes[key].editando = false;
101 }
102 $scope.crear = true;
103 };
104
105 $scope.guardar = function() {
106 $scope.choferes.forEach( function (chofer) {
107 if (chofer.id === 0) {
108 delete chofer.id;
109 }
110 delete chofer.transportista;
111 delete chofer.editando;
112 });
113 focaAbmChoferService.guardarChoferes($scope.choferes);
31 }; 114 };
32 115
33 $scope.solicitarConfirmacion = function(chofer) { 116 $scope.solicitarConfirmacion = function(chofer) {
34 focaModalService.confirm('¿Está seguro que desea borrar el chofer ' + 117 focaModalService.confirm('¿Está seguro que desea borrar el chofer ' +
35 chofer.nombre + ' ?').then(function(confirmed) { 118 chofer.nombre + ' ?').then(function(confirmed) {
36 if (confirmed) { 119 if (confirmed) {
37 focaAbmChoferService.deleteChofer(chofer.id); 120 chofer.desactivado = true;
38 $scope.choferes.splice($scope.choferes.indexOf(chofer), 1);
39 } 121 }
40 }); 122 });
41 }; 123 };
42 124
43 $scope.seleccionarTransportista = function() { 125 $scope.seleccionarTransportista = function() {
44 var parametrosModal = { 126 var parametrosModal = {
45 titulo: 'Búsqueda de Transportista', 127 titulo: 'Búsqueda de Transportista',
46 query: '/transportista', 128 query: '/transportista',
47 columnas: [ 129 columnas: [
48 { 130 {
49 nombre: 'Código', 131 nombre: 'Código',
50 propiedad: 'COD' 132 propiedad: 'COD'
51 }, 133 },
52 { 134 {
53 nombre: 'Nombre', 135 nombre: 'Nombre',
54 propiedad: 'NOM' 136 propiedad: 'NOM'
55 }, 137 },
56 { 138 {
57 nombre: 'CUIT', 139 nombre: 'CUIT',
58 propiedad: 'CUIT' 140 propiedad: 'CUIT'
59 } 141 }
60 ] 142 ]
61 }; 143 };
62 focaModalService.modal(parametrosModal).then( 144 focaModalService.modal(parametrosModal).then(
63 function(transportista) { 145 function(transportista) {
146 $scope.crear = true;
64 elegirTransportista(transportista); 147 elegirTransportista(transportista);
65 focaAbmChoferService.transportistaSeleccionado = transportista; 148 focaAbmChoferService.transportistaSeleccionado = transportista;
66 }, function() {} 149 }, function() {}
67 ); 150 );
68 }; 151 };
69 152
70 function elegirTransportista(transportista) { 153 function elegirTransportista(transportista) {
71 buscar(transportista.COD); 154 buscar(transportista.COD);
72 var codigo = ('00000' + transportista.COD).slice(-5); 155 var codigo = ('00000' + transportista.COD).slice(-5);
73 $scope.idTransportista = transportista.COD; 156 $scope.idTransportista = transportista.COD;
74 $timeout(function() { 157 $timeout(function() {
75 $scope.$broadcast('addCabecera', { 158 $scope.$broadcast('addCabecera', {
76 label: 'Transportista:', 159 label: 'Transportista:',
77 valor: codigo + ' - ' + transportista.NOM 160 valor: codigo + ' - ' + transportista.NOM
78 }); 161 });
79 }); 162 });
80 } 163 }
81 164
82 function buscar(id) { 165 function buscar(id) {
83 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) { 166 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) {
84 $scope.choferes = res.data; 167 $scope.choferes = res.data;
85 }); 168 });
86 } 169 }
87 170
88 function salir() { 171 function salir() {
89 focaAbmChoferService.transportistaSeleccionado = {}; 172 focaAbmChoferService.transportistaSeleccionado = {};
90 $location.path('/'); 173 $location.path('/');
91 } 174 }
92 175
93 if ($localStorage.chofer) { 176 function validaDni(chofer) {
94 var chofer = JSON.parse($localStorage.chofer); 177 if (!chofer.dni) {
95 if (!chofer.id) { chofer.id = 0; } 178 focaModalService.alert('Ingrese DNI');
96 $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista); 179 return;
97 } 180 } else if (!chofer.telefono) {
98 } 181 focaModalService.alert('Ingrese teléfono');
99 ]) 182 return;
100 .controller('focaAbmChoferController', [
101 '$scope', 'focaAbmChoferService', '$routeParams', '$localStorage', '$filter',
102 '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService', '$window',
103 function($scope, focaAbmChoferService, $routeParams, $localStorage, $filter,
104 $location, focaBotoneraLateralService, $timeout, focaModalService){
105
106 $scope.focused = 1;
107 $scope.nuevo = $routeParams.id === '0';
108 $scope.chofer = {};
109 $scope.transportistas = [];
110 $scope.now = new Date();
111 $scope.next = function(key) {
112 if (key === 13) $scope.focused++;
113 };
114
115 focaAbmChoferService.getTiposDocumento().then(function(res) {
116 $scope.tiposDocumento = res.data;
117 });
118
119 //SETEO BOTONERA LATERAL
120 $timeout(function() {
121 focaBotoneraLateralService.showSalir(false);
122 focaBotoneraLateralService.showPausar(true);
123 focaBotoneraLateralService.showCancelar(false);
124 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
125 focaBotoneraLateralService.addCustomButton('Salir', salir);
126
127 });
128
129 $timeout(function() {getLSChofer();});
130
131 if ($scope.nuevo) {
132 focaAbmChoferService
133 .getTransportistaPorId($routeParams.idTransportista)
134 .then(function(res) {
135 var codigo = ('00000' + res.data.COD).slice(-5);
136 $scope.chofer.idTransportista = res.data.COD;
137 $scope.chofer.transportista = res.data;
138 $scope.$broadcast('addCabecera', {
139 label: 'Transportista:',
140 valor: codigo + ' - ' + res.data.NOM
141 });
142 });
143 }
144
145 focaAbmChoferService.getChofer($routeParams.id).then(function(res) {
146 if (res.data) {
147 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
148 $scope.chofer = res.data;
149 $scope.$broadcast('addCabecera', {
150 label: 'Transportista:',
151 valor: codigo + ' - ' + res.data.transportista.NOM
152 });
153 }
154 });
155
156 focaAbmChoferService.getTransportistas().then(function(res) {
157 $scope.transportistas = res.data;
158 });
159
160 function setearChofer(chofer) {
161 $scope.chofer = chofer;
162 $scope.$broadcast('addCabecera', {
163 label: 'Transportista:',
164 valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - '
165 });
166 }
167 function getLSChofer() {
168 var chofer = JSON.parse($localStorage.chofer || null);
169
170 if (chofer) {
1 angular.module('focaAbmChofer') 1 angular.module('focaAbmChofer')
2 .factory('focaAbmChoferService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { 2 .factory('focaAbmChoferService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 return { 3 return {
4 getChoferes: function() { 4 getChoferes: function() {
5 return $http.get(API_ENDPOINT.URL + '/chofer'); 5 return $http.get(API_ENDPOINT.URL + '/chofer');
6 }, 6 },
7 getChofer: function(id) { 7 getChofer: function(id) {
8 return $http.get(API_ENDPOINT.URL + '/chofer/' + id); 8 return $http.get(API_ENDPOINT.URL + '/chofer/' + id);
9 }, 9 },
10 getChoferPorTransportista: function(id) { 10 getChoferPorTransportista: function(id) {
11 return $http.get(API_ENDPOINT.URL + '/chofer/transportista/' + id); 11 return $http.get(API_ENDPOINT.URL + '/chofer/transportista/' + id);
12 }, 12 },
13 getChoferPorDni: function(dni) { 13 getChoferPorDni: function(dni) {
14 return $http.post(API_ENDPOINT.URL + '/chofer/dni', {dni: dni}); 14 return $http.post(API_ENDPOINT.URL + '/chofer/dni', {dni: dni});
15 }, 15 },
16 guardarChofer: function(chofer) { 16 guardarChofer: function(chofer) {
17 return $http.post(API_ENDPOINT.URL + '/chofer', {chofer: chofer}); 17 return $http.post(API_ENDPOINT.URL + '/chofer', {chofer: chofer});
18 }, 18 },
19 guardarChoferes: function(choferes) {
20 return $http.post(API_ENDPOINT.URL + '/chofer', {choferes: choferes});
21 },
19 getTransportistas: function() { 22 getTransportistas: function() {
20 return $http.get(API_ENDPOINT.URL + '/transportista'); 23 return $http.get(API_ENDPOINT.URL + '/transportista');
21 }, 24 },
22 getTransportistaPorId: function(id) { 25 getTransportistaPorId: function(id) {
23 return $http.get(API_ENDPOINT.URL + '/transportista/' + id); 26 return $http.get(API_ENDPOINT.URL + '/transportista/' + id);
24 }, 27 },
25 deleteChofer: function(id) { 28 deleteChofer: function(id) {
26 return $http.delete(API_ENDPOINT.URL + '/chofer/' + id); 29 return $http.delete(API_ENDPOINT.URL + '/chofer/' + id);
27 }, 30 },
28 getTiposDocumento: function() { 31 getTiposDocumento: function() {
29 return $http.get(API_ENDPOINT.URL + '/tipo-documento'); 32 return $http.get(API_ENDPOINT.URL + '/tipo-documento');
30 }, 33 },
31 transportistaSeleccionado: {} 34 transportistaSeleccionado: {}
32 }; 35 };
33 }]); 36 }]);
34 37
src/views/foca-abm-choferes-listado.html
1 <div class="row"> 1 <div class="row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Choferes'" 3 titulo="'Choferes'"
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 <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> 15 <table class="table table-default table-hover table-sm table-abm table-striped mb-0">
16 <thead> 16 <thead>
17 <tr> 17 <tr>
18 <th>Nombre</th> 18 <th>Nombre</th>
19 <th>Tipo</th>
19 <th>Documento</th> 20 <th>Documento</th>
20 <th>Teléfono</th> 21 <th>Teléfono</th>
21 <th class="text-center"> 22 <th class="text-center">
22 <button 23 <button
23 ng-disabled="!idTransportista"
24 title="Agregar" 24 title="Agregar"
25 class="btn btn-outline-debo boton-accion" 25 class="btn btn-outline-debo boton-accion"
26 ng-click="editar(0)"> 26 ng-click="crearChofer()"
27 ng-disabled="!crear"
28 >
27 <i class="fa fa-plus"></i> 29 <i class="fa fa-plus"></i>
28 </button> 30 </button>
29 </th> 31 </th>
30 </tr> 32 </tr>
31 </thead> 33 </thead>
32 <tbody> 34 <tbody>
33 <tr ng-repeat="chofer in choferes | filter:filters"> 35 <tr ng-show="creando">
34 <td ng-bind="chofer.nombre"></td> 36 <td align="center">
35 <td ng-bind="chofer.dni"></td> 37 <input
36 <td ng-bind="chofer.telefono"></td> 38 class="form-control"
37 <td class="text-center"> 39 type="text"
40 teclado-virtual
41 ng-model="chofer.nombre"
42 ng-required="true"
43 ng-keypress="next($event.keyCode)"
44 foca-focus="focused == 1"
45 ng-focus="focused = 1"
46 >
47 </td>
48 <td align="center">
49 <div class="col-sm-4">
50 <select
51 class="form-control"
52 ng-options="tipoDocumento.id as tipoDocumento.descripcion for tipoDocumento in tiposDocumento track by tipoDocumento.id"
53 ng-model="chofer.idTipoDocumento">
54 </select>
55 </div>
56 </td>
57 <td align="center">
58 <input
59 class="form-control"
60 foca-tipo-input
61 teclado-virtual
62 solo-positivos
63 limite-numeros-max="15"
64 ng-model="chofer.dni"
65 ng-required="true"
66 ng-keypress="next($event.keyCode)"
67 foca-focus="focused == 2"
68 ng-focus="focused = 2"
69 ng-disabled="!nuevo"
70 string-toNumber
71 >
72 </td>
73 <td align="center">
74 <input
75 class="form-control"
76 foca-tipo-input
77 teclado-virtual
78 solo-positivos
79 limite-numeros-max="15"
80 ng-model="chofer.telefono"
81 ng-required="true"
82 foca-focus="focused == 3"
83 ng-focus="focused = 3"
84 string-toNumber
85 >
86 </td>
87 <td align="center">
88 <button
89 class="btn btn-outline-dark boton-accion"
90 ng-click="agregarChofer()"
91 >
92 <i class="fa fa-save"></i>
93 </button>
94 </td>
95 </tr>
96
97 <tr ng-repeat="(key, chofer) in choferes | filter:filters" ng-hide="chofer.desactivado">
98 <td ng-bind="chofer.nombre" ng-hide="chofer.editando"></td>
99 <td align="center" ng-show="chofer.editando">
100 <input
101 class="form-control"
102 type="text"
103 teclado-virtual
104 ng-model="chofer.nombre"
105 ng-required="true"
106 ng-keypress="next($event.keyCode)"
107 foca-focus="focused == 1"
108 ng-focus="focused = 1"
109 esc-key="volver(chofer, key)"
110 >
111 </td>
112 <td ng-bind="tipoDocumento(chofer.idTipoDocumento)" ng-hide="chofer.editando"></td>
113 <td align="center" ng-show="chofer.editando">
114 <div class="col-sm-15">
115 <select
116 class="form-control"
117 ng-options="tipoDocumento.id as tipoDocumento.descripcion for tipoDocumento in tiposDocumento track by tipoDocumento.id"
118 ng-model="chofer.idTipoDocumento">
119 </select>
120 </div>
121 </td>
122 <td ng-bind="chofer.dni" ng-hide="chofer.editando">
123 <td align="center" ng-show="chofer.editando">
124 <input
125 class="form-control"
126 type="text"
127 teclado-virtual
128 ng-model="chofer.dni"
129 ng-required="true"
130 ng-keypress="next($event.keyCode)"
131 foca-focus="focused == 2"
132 ng-focus="focused = 2"
133 esc-key="volver(chofer, key)"
134 >
135 </td>
136 </td>
137 <td ng-bind="chofer.telefono" ng-hide="chofer.editando"></td>
138 <td align="center" ng-show="chofer.editando">
139 <input
140 class="form-control"
141 foca-tipo-input
142 teclado-virtual
143 solo-positivos
144 limite-numeros-max="15"
145 ng-model="chofer.telefono"
146 ng-required="true"
147 foca-focus="focused == 3"
148 ng-focus="focused = 3"
149 string-toNumber
150 esc-key="volver(chofer, key)"
151 >
152 </td>
153 <td class="text-center" ng-hide="chofer.editando">
38 <button 154 <button
39 class="btn btn-outline-dark boton-accion" 155 class="btn btn-outline-dark boton-accion"
40 title="Editar" 156 title="Editar"
41 ng-click="editar(chofer.id)" 157 ng-click="editar(chofer)"
42 > 158 >
43 <i class="fa fa-pencil"></i> 159 <i class="fa fa-pencil"></i>
44 </button> 160 </button>
45 <button 161 <button
46 class="btn btn-outline-dark boton-accion" 162 class="btn btn-outline-dark boton-accion"
47 title="Eliminar" 163 title="Eliminar"
48 ng-click="solicitarConfirmacion(chofer)" 164 ng-click="solicitarConfirmacion(chofer)"
49 > 165 >
50 <i class="fa fa-trash"></i> 166 <i class="fa fa-trash"></i>
51 </button> 167 </button>
52 </td> 168 </td>
169 <td align="center" ng-show="chofer.editando">
170 <button
171 class="btn btn-outline-dark boton-accion"
172 ng-click="agregarChofer(chofer)"
173 >
174 <i class="fa fa-save"></i>
175 </button>
176 <button
177 class="btn btn-outline-dark boton-accion"
178 ng-click="volver(chofer, key)"
179 >
180 <i class="fa fa-undo" aria-hidden="true"></i>
181 </button>
182 </td>
53 </tr> 183 </tr>
54 </body> 184 </body>
55 </table> 185 </table>
56 </div> 186 </div>
57 </div> 187 </div>