Commit 147f24460946e782d905d85194d9012f20b7d24d

Authored by Jose Pinto
1 parent 5162b47e46
Exists in master

Agrego campo tipo documento

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', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout',
5 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService, 5 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService,
6 focaBotoneraLateralService, $timeout) { 6 focaBotoneraLateralService, $timeout) {
7 7
8 $scope.now = new Date(); 8 $scope.now = new Date();
9 $scope.filters = ''; 9 $scope.filters = '';
10 $scope.choferes = []; 10 $scope.choferes = [];
11 $scope.botonera = [{ 11 $scope.botonera = [{
12 label: 'Transportista', 12 label: 'Transportista',
13 image: 'cliente.png' 13 image: 'cliente.png'
14 }]; 14 }];
15 15
16 //SETEO BOTONERA LATERAL 16 //SETEO BOTONERA LATERAL
17 $timeout(function() { 17 $timeout(function() {
18 focaBotoneraLateralService.showSalir(false); 18 focaBotoneraLateralService.showSalir(false);
19 focaBotoneraLateralService.showPausar(false); 19 focaBotoneraLateralService.showPausar(false);
20 focaBotoneraLateralService.showCancelar(false); 20 focaBotoneraLateralService.showCancelar(false);
21 focaBotoneraLateralService.showGuardar(false); 21 focaBotoneraLateralService.showGuardar(false);
22 focaBotoneraLateralService.addCustomButton('Salir', salir); 22 focaBotoneraLateralService.addCustomButton('Salir', salir);
23 }); 23 });
24 24
25 if(focaAbmChoferService.transportistaSeleccionado.COD) { 25 if(focaAbmChoferService.transportistaSeleccionado.COD) {
26 elegirTransportista(focaAbmChoferService.transportistaSeleccionado); 26 elegirTransportista(focaAbmChoferService.transportistaSeleccionado);
27 } 27 }
28 28
29 $scope.editar = function(id) { 29 $scope.editar = function(id) {
30 $location.path('/chofer/' + id + '/' + $scope.idTransportista); 30 $location.path('/chofer/' + id + '/' + $scope.idTransportista);
31 }; 31 };
32 32
33 $scope.solicitarConfirmacion = function(chofer) { 33 $scope.solicitarConfirmacion = function(chofer) {
34 focaModalService.confirm('¿Está seguro que desea borrar el chofer ' + 34 focaModalService.confirm('¿Está seguro que desea borrar el chofer ' +
35 chofer.nombre + ' ?').then(function(confirmed) { 35 chofer.nombre + ' ?').then(function(confirmed) {
36 if(confirmed) { 36 if(confirmed) {
37 focaAbmChoferService.deleteChofer(chofer.id); 37 focaAbmChoferService.deleteChofer(chofer.id);
38 $scope.choferes.splice($scope.choferes.indexOf(chofer), 1); 38 $scope.choferes.splice($scope.choferes.indexOf(chofer), 1);
39 } 39 }
40 }); 40 });
41 }; 41 };
42 42
43 $scope.seleccionarTransportista = function() { 43 $scope.seleccionarTransportista = function() {
44 var modalInstance = $uibModal.open( 44 var modalInstance = $uibModal.open(
45 { 45 {
46 ariaLabelledBy: 'Busqueda de Transportista', 46 ariaLabelledBy: 'Busqueda de Transportista',
47 templateUrl: 'modal-proveedor.html', 47 templateUrl: 'modal-proveedor.html',
48 controller: 'focaModalProveedorCtrl', 48 controller: 'focaModalProveedorCtrl',
49 size: 'lg', 49 size: 'lg',
50 resolve: { 50 resolve: {
51 transportista: function() { 51 transportista: function() {
52 return true; 52 return true;
53 } 53 }
54 } 54 }
55 } 55 }
56 ); 56 );
57 modalInstance.result.then( 57 modalInstance.result.then(
58 function(transportista) { 58 function(transportista) {
59 elegirTransportista(transportista); 59 elegirTransportista(transportista);
60 focaAbmChoferService.transportistaSeleccionado = transportista; 60 focaAbmChoferService.transportistaSeleccionado = transportista;
61 }, function() {} 61 }, function() {}
62 ); 62 );
63 }; 63 };
64 64
65 function elegirTransportista(transportista) { 65 function elegirTransportista(transportista) {
66 buscar(transportista.COD); 66 buscar(transportista.COD);
67 var codigo = ('00000' + transportista.COD).slice(-5); 67 var codigo = ('00000' + transportista.COD).slice(-5);
68 $scope.idTransportista = transportista.COD; 68 $scope.idTransportista = transportista.COD;
69 $timeout(function() { 69 $timeout(function() {
70 $scope.$broadcast('addCabecera', { 70 $scope.$broadcast('addCabecera', {
71 label: 'Transportista:', 71 label: 'Transportista:',
72 valor: codigo + ' - ' + transportista.NOM 72 valor: codigo + ' - ' + transportista.NOM
73 }); 73 });
74 }); 74 });
75 } 75 }
76 76
77 function buscar(id) { 77 function buscar(id) {
78 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) { 78 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) {
79 $scope.choferes = res.data; 79 $scope.choferes = res.data;
80 }); 80 });
81 } 81 }
82 82
83 function salir() { 83 function salir() {
84 focaAbmChoferService.transportistaSeleccionado = {}; 84 focaAbmChoferService.transportistaSeleccionado = {};
85 $location.path('/'); 85 $location.path('/');
86 } 86 }
87 } 87 }
88 ]) 88 ])
89 .controller('focaAbmChoferController', [ 89 .controller('focaAbmChoferController', [
90 '$scope', 'focaAbmChoferService', '$routeParams', 90 '$scope', 'focaAbmChoferService', '$routeParams',
91 '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService', 91 '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService',
92 function($scope, focaAbmChoferService, $routeParams, 92 function($scope, focaAbmChoferService, $routeParams,
93 $location, focaBotoneraLateralService, $timeout, focaModalService) { 93 $location, focaBotoneraLateralService, $timeout, focaModalService) {
94 94
95 $scope.focused = 1; 95 $scope.focused = 1;
96 $scope.nuevo = $routeParams.id === '0'; 96 $scope.nuevo = $routeParams.id === '0';
97 $scope.chofer = {}; 97 $scope.chofer = {};
98 $scope.transportistas = []; 98 $scope.transportistas = [];
99 $scope.now = new Date(); 99 $scope.now = new Date();
100 $scope.next = function(key) { 100 $scope.next = function(key) {
101 if (key === 13) $scope.focused++; 101 if (key === 13) $scope.focused++;
102 }; 102 };
103 103
104 focaAbmChoferService.getTiposDocumento().then(function(res) {
105 $scope.tiposDocumento = res.data;
106 });
107
104 //SETEO BOTONERA LATERAL 108 //SETEO BOTONERA LATERAL
105 $timeout(function() { 109 $timeout(function() {
106 focaBotoneraLateralService.showSalir(false); 110 focaBotoneraLateralService.showSalir(false);
107 focaBotoneraLateralService.showPausar(true); 111 focaBotoneraLateralService.showPausar(true);
108 focaBotoneraLateralService.showCancelar(true); 112 focaBotoneraLateralService.showCancelar(true);
109 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 113 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
110 }); 114 });
111 115
112 if($scope.nuevo) { 116 if($scope.nuevo) {
113 focaAbmChoferService 117 focaAbmChoferService
114 .getTransportistaPorId($routeParams.idTransportista) 118 .getTransportistaPorId($routeParams.idTransportista)
115 .then(function(res) { 119 .then(function(res) {
116 var codigo = ('00000' + res.data.COD).slice(-5); 120 var codigo = ('00000' + res.data.COD).slice(-5);
117 $scope.chofer.idTransportista = res.data.COD; 121 $scope.chofer.idTransportista = res.data.COD;
118 $scope.chofer.transportista = res.data; 122 $scope.chofer.transportista = res.data;
119 $scope.$broadcast('addCabecera', { 123 $scope.$broadcast('addCabecera', {
120 label: 'Transportista:', 124 label: 'Transportista:',
121 valor: codigo + ' - ' + res.data.NOM 125 valor: codigo + ' - ' + res.data.NOM
122 }); 126 });
123 }); 127 });
124 } 128 }
125 129
126 focaAbmChoferService.getChofer($routeParams.id).then(function(res) { 130 focaAbmChoferService.getChofer($routeParams.id).then(function(res) {
127 if(res.data) { 131 if(res.data) {
128 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 132 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
129 $scope.chofer = res.data; 133 $scope.chofer = res.data;
130 $scope.$broadcast('addCabecera', { 134 $scope.$broadcast('addCabecera', {
131 label: 'Transportista:', 135 label: 'Transportista:',
132 valor: codigo + ' - ' + res.data.transportista.NOM 136 valor: codigo + ' - ' + res.data.transportista.NOM
133 }); 137 });
134 } 138 }
135 }); 139 });
136 140
137 focaAbmChoferService.getTransportistas().then(function(res) { 141 focaAbmChoferService.getTransportistas().then(function(res) {
138 $scope.transportistas = res.data; 142 $scope.transportistas = res.data;
139 }); 143 });
140 144
141 $scope.cancelar = function() { 145 $scope.cancelar = function() {
142 $location.path('/chofer'); 146 $location.path('/chofer');
143 }; 147 };
144 148
145 $scope.guardar = function(key) { 149 $scope.guardar = function(key) {
146 key = (typeof key === 'undefined') ? 13 : key; 150 key = (typeof key === 'undefined') ? 13 : key;
147
148 if(key === 13) { 151 if(key === 13) {
149 validaDni().then(function() { 152 validaDni().then(function() {
150 $scope.chofer.idTransportista = $routeParams.idTransportista; 153 $scope.chofer.idTransportista = $routeParams.idTransportista;
151 delete $scope.chofer.transportista; 154 delete $scope.chofer.transportista;
152 focaAbmChoferService.guardarChofer($scope.chofer).then(function() { 155 focaAbmChoferService.guardarChofer($scope.chofer).then(function() {
153 $location.path('/chofer'); 156 $location.path('/chofer');
154 }); 157 });
155 }, function() { 158 }, function() {
156 focaModalService.alert('Dni existente'); 159 focaModalService.alert('Dni existente');
157 }); 160 });
158 } 161 }
159 }; 162 };
160 163
161 function validaDni() { 164 function validaDni() {
162 return new Promise(function(resolve, reject) { 165 return new Promise(function(resolve, reject) {
163 focaAbmChoferService 166 focaAbmChoferService
164 .getChoferPorTransportista(parseInt($routeParams.idTransportista)) 167 .getChoferPorDni($scope.chofer.dni)
165 .then(function(res) { 168 .then(function(res) {
166 //Valida si existe dni 169 if(res.data.id &&
167 var existe = res.data.filter(function(chofer) { 170 $scope.chofer.id !== res.data.id) {
168 return chofer.dni === $scope.chofer.dni && 171 reject(res.data);
169 chofer.id !== $scope.chofer.id;
170 });
171
172 if(existe.length) {
173 reject(existe);
174 }else { 172 }else {
175 resolve(); 173 resolve();
176 } 174 }
177 }); 175 });
178 }); 176 });
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) {
14 return $http.post(API_ENDPOINT.URL + '/chofer/dni', {dni: dni});
15 },
13 guardarChofer: function(chofer) { 16 guardarChofer: function(chofer) {
14 return $http.post(API_ENDPOINT.URL + '/chofer', {chofer: chofer}); 17 return $http.post(API_ENDPOINT.URL + '/chofer', {chofer: chofer});
15 }, 18 },
16 getTransportistas: function() { 19 getTransportistas: function() {
17 return $http.get(API_ENDPOINT.URL + '/transportista'); 20 return $http.get(API_ENDPOINT.URL + '/transportista');
18 }, 21 },
19 getTransportistaPorId: function(id) { 22 getTransportistaPorId: function(id) {
20 return $http.get(API_ENDPOINT.URL + '/transportista/' + id); 23 return $http.get(API_ENDPOINT.URL + '/transportista/' + id);
21 }, 24 },
22 deleteChofer: function(id) { 25 deleteChofer: function(id) {
23 return $http.delete(API_ENDPOINT.URL + '/chofer/' + id); 26 return $http.delete(API_ENDPOINT.URL + '/chofer/' + id);
24 }, 27 },
28 getTiposDocumento: function() {
29 return $http.get(API_ENDPOINT.URL + '/tipo-documento');
30 },
25 transportistaSeleccionado: {} 31 transportistaSeleccionado: {}
26 }; 32 };
27 }]); 33 }]);
28 34
src/views/foca-abm-choferes-item.html
1 <div class="row"> 1 <div class="row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Chofer'" 3 titulo="'Chofer'"
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 <form name="formChofer" class="col-md-12"> 9 <form name="formChofer" class="col-md-12">
10 <input type="hidden" name="id" ng-model="chofer.id" /> 10 <input type="hidden" name="id" ng-model="chofer.id" />
11 <div class="form-group row"> 11 <div class="form-group row">
12 <label class="offset-sm-1 col-sm-2 col-form-label">Nombre</label> 12 <label class="offset-sm-1 col-sm-2 col-form-label">Nombre</label>
13 <div class="col-sm-4"> 13 <div class="col-sm-4">
14 <input 14 <input
15 class="form-control" 15 class="form-control"
16 type="text" 16 type="text"
17 teclado-virtual 17 teclado-virtual
18 ng-model="chofer.nombre" 18 ng-model="chofer.nombre"
19 ng-required="true" 19 ng-required="true"
20 ng-keypress="next($event.keyCode)" 20 ng-keypress="next($event.keyCode)"
21 foca-focus="focused == 1" 21 foca-focus="focused == 1"
22 ng-focus="focused = 1" 22 ng-focus="focused = 1"
23 /> 23 />
24 </div> 24 </div>
25 </div> 25 </div>
26 <div class="form-group row"> 26 <div class="form-group row">
27 <label class="offset-sm-1 col-sm-2 col-form-label">Tipo documento</label>
28 <div class="col-sm-4">
29 <select
30 class="form-control"
31 ng-options="tipoDocumento.id as tipoDocumento.descripcion for tipoDocumento in tiposDocumento track by tipoDocumento.id"
32 ng-model="chofer.idTipoDocumento">
33 </select>
34 </div>
35 </div>
36 <div class="form-group row">
27 <label class="offset-sm-1 col-sm-2 col-form-label">DNI</label> 37 <label class="offset-sm-1 col-sm-2 col-form-label">DNI</label>
28 <div class="col-sm-4"> 38 <div class="col-sm-4">
29 <input 39 <input
30 class="form-control" 40 class="form-control"
31 type="text" 41 type="text"
32 teclado-virtual 42 teclado-virtual
33 ng-model="chofer.dni" 43 ng-model="chofer.dni"
34 ng-required="true" 44 ng-required="true"
35 ng-keypress="next($event.keyCode)" 45 ng-keypress="next($event.keyCode)"
36 foca-focus="focused == 2" 46 foca-focus="focused == 2"
37 ng-focus="focused = 2" 47 ng-focus="focused = 2"
38 ng-disabled="!nuevo" 48 ng-disabled="!nuevo"
39 /> 49 />
40 </div> 50 </div>
41 </div> 51 </div>
42 <div class="form-group row"> 52 <div class="form-group row">
43 <label class="offset-sm-1 col-sm-2 col-form-label">Teléfono</label> 53 <label class="offset-sm-1 col-sm-2 col-form-label">Teléfono</label>
44 <div class="col-sm-4"> 54 <div class="col-sm-4">
45 <input 55 <input
46 class="form-control" 56 class="form-control"
47 type="text" 57 type="text"
48 teclado-virtual 58 teclado-virtual
49 ng-model="chofer.telefono" 59 ng-model="chofer.telefono"
50 ng-required="true" 60 ng-required="true"
51 ng-keypress="guardar($event.keyCode)" 61 ng-keypress="guardar($event.keyCode)"
52 foca-focus="focused == 3" 62 foca-focus="focused == 3"
53 ng-focus="focused = 3" 63 ng-focus="focused = 3"
54 /> 64 />
55 </div> 65 </div>
56 </div> 66 </div>
57 </form> 67 </form>
58 </div> 68 </div>
59 69
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>DNI</th> 19 <th>Documento</th>
20 <th>Teléfono</th> 20 <th>Teléfono</th>
21 <th class="text-center"> 21 <th class="text-center">
22 <button 22 <button
23 ng-disabled="!idTransportista" 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="editar(0)">
27 <i class="fa fa-plus"></i> 27 <i class="fa fa-plus"></i>
28 </button> 28 </button>
29 </th> 29 </th>
30 </tr> 30 </tr>
31 </thead> 31 </thead>
32 <tbody> 32 <tbody>
33 <tr ng-repeat="chofer in choferes | filter:filters"> 33 <tr ng-repeat="chofer in choferes | filter:filters">
34 <td ng-bind="chofer.nombre"></td> 34 <td ng-bind="chofer.nombre"></td>
35 <td ng-bind="chofer.dni"></td> 35 <td ng-bind="chofer.dni"></td>
36 <td ng-bind="chofer.telefono"></td> 36 <td ng-bind="chofer.telefono"></td>
37 <td class="text-center"> 37 <td class="text-center">
38 <button 38 <button
39 class="btn btn-outline-dark boton-accion" 39 class="btn btn-outline-dark boton-accion"
40 title="Editar" 40 title="Editar"
41 ng-click="editar(chofer.id)" 41 ng-click="editar(chofer.id)"
42 > 42 >
43 <i class="fa fa-pencil"></i> 43 <i class="fa fa-pencil"></i>
44 </button> 44 </button>
45 <button 45 <button
46 class="btn btn-outline-dark boton-accion" 46 class="btn btn-outline-dark boton-accion"
47 title="Eliminar" 47 title="Eliminar"
48 ng-click="solicitarConfirmacion(chofer)" 48 ng-click="solicitarConfirmacion(chofer)"
49 > 49 >
50 <i class="fa fa-trash"></i> 50 <i class="fa fa-trash"></i>
51 </button> 51 </button>
52 </td> 52 </td>
53 </tr> 53 </tr>
54 </body> 54 </body>
55 </table> 55 </table>
56 </div> 56 </div>
57 </div> 57 </div>
58 58