Commit 66061beaa86ca65b638c0a707168393da5694e09

Authored by Luigi
1 parent ee4262c6e8
Exists in master

Validacion Chofer

Showing 1 changed file with 14 additions and 2 deletions   Show diff stats
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 parametrosModal = { 44 var parametrosModal = {
45 titulo: 'Búsqueda de Transportista', 45 titulo: 'Búsqueda de Transportista',
46 query: '/transportista', 46 query: '/transportista',
47 columnas: [ 47 columnas: [
48 { 48 {
49 nombre: 'Código', 49 nombre: 'Código',
50 propiedad: 'COD' 50 propiedad: 'COD'
51 }, 51 },
52 { 52 {
53 nombre: 'Nombre', 53 nombre: 'Nombre',
54 propiedad: 'NOM' 54 propiedad: 'NOM'
55 }, 55 },
56 { 56 {
57 nombre: 'CUIT', 57 nombre: 'CUIT',
58 propiedad: 'CUIT' 58 propiedad: 'CUIT'
59 } 59 }
60 ] 60 ]
61 }; 61 };
62 focaModalService.modal(parametrosModal).then( 62 focaModalService.modal(parametrosModal).then(
63 function(transportista) { 63 function(transportista) {
64 elegirTransportista(transportista); 64 elegirTransportista(transportista);
65 focaAbmChoferService.transportistaSeleccionado = transportista; 65 focaAbmChoferService.transportistaSeleccionado = transportista;
66 }, function() {} 66 }, function() {}
67 ); 67 );
68 }; 68 };
69 69
70 function elegirTransportista(transportista) { 70 function elegirTransportista(transportista) {
71 buscar(transportista.COD); 71 buscar(transportista.COD);
72 var codigo = ('00000' + transportista.COD).slice(-5); 72 var codigo = ('00000' + transportista.COD).slice(-5);
73 $scope.idTransportista = transportista.COD; 73 $scope.idTransportista = transportista.COD;
74 $timeout(function() { 74 $timeout(function() {
75 $scope.$broadcast('addCabecera', { 75 $scope.$broadcast('addCabecera', {
76 label: 'Transportista:', 76 label: 'Transportista:',
77 valor: codigo + ' - ' + transportista.NOM 77 valor: codigo + ' - ' + transportista.NOM
78 }); 78 });
79 }); 79 });
80 } 80 }
81 81
82 function buscar(id) { 82 function buscar(id) {
83 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) { 83 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) {
84 $scope.choferes = res.data; 84 $scope.choferes = res.data;
85 }); 85 });
86 } 86 }
87 87
88 function salir() { 88 function salir() {
89 focaAbmChoferService.transportistaSeleccionado = {}; 89 focaAbmChoferService.transportistaSeleccionado = {};
90 $location.path('/'); 90 $location.path('/');
91 } 91 }
92 } 92 }
93 ]) 93 ])
94 .controller('focaAbmChoferController', [ 94 .controller('focaAbmChoferController', [
95 '$scope', 'focaAbmChoferService', '$routeParams', 95 '$scope', 'focaAbmChoferService', '$routeParams',
96 '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService', 96 '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService',
97 function($scope, focaAbmChoferService, $routeParams, 97 function($scope, focaAbmChoferService, $routeParams,
98 $location, focaBotoneraLateralService, $timeout, focaModalService) { 98 $location, focaBotoneraLateralService, $timeout, focaModalService) {
99 99
100 $scope.focused = 1; 100 $scope.focused = 1;
101 $scope.nuevo = $routeParams.id === '0'; 101 $scope.nuevo = $routeParams.id === '0';
102 $scope.chofer = {}; 102 $scope.chofer = {};
103 $scope.transportistas = []; 103 $scope.transportistas = [];
104 $scope.now = new Date(); 104 $scope.now = new Date();
105 $scope.next = function(key) { 105 $scope.next = function(key) {
106 if (key === 13) $scope.focused++; 106 if (key === 13) $scope.focused++;
107 }; 107 };
108 108
109 focaAbmChoferService.getTiposDocumento().then(function(res) { 109 focaAbmChoferService.getTiposDocumento().then(function(res) {
110 $scope.tiposDocumento = res.data; 110 $scope.tiposDocumento = res.data;
111 }); 111 });
112 112
113 //SETEO BOTONERA LATERAL 113 //SETEO BOTONERA LATERAL
114 $timeout(function() { 114 $timeout(function() {
115 focaBotoneraLateralService.showSalir(false); 115 focaBotoneraLateralService.showSalir(false);
116 focaBotoneraLateralService.showPausar(true); 116 focaBotoneraLateralService.showPausar(true);
117 focaBotoneraLateralService.showCancelar(true); 117 focaBotoneraLateralService.showCancelar(true);
118 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 118 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
119 }); 119 });
120 120
121 if($scope.nuevo) { 121 if($scope.nuevo) {
122 focaAbmChoferService 122 focaAbmChoferService
123 .getTransportistaPorId($routeParams.idTransportista) 123 .getTransportistaPorId($routeParams.idTransportista)
124 .then(function(res) { 124 .then(function(res) {
125 var codigo = ('00000' + res.data.COD).slice(-5); 125 var codigo = ('00000' + res.data.COD).slice(-5);
126 $scope.chofer.idTransportista = res.data.COD; 126 $scope.chofer.idTransportista = res.data.COD;
127 $scope.chofer.transportista = res.data; 127 $scope.chofer.transportista = res.data;
128 $scope.$broadcast('addCabecera', { 128 $scope.$broadcast('addCabecera', {
129 label: 'Transportista:', 129 label: 'Transportista:',
130 valor: codigo + ' - ' + res.data.NOM 130 valor: codigo + ' - ' + res.data.NOM
131 }); 131 });
132 }); 132 });
133 } 133 }
134 134
135 focaAbmChoferService.getChofer($routeParams.id).then(function(res) { 135 focaAbmChoferService.getChofer($routeParams.id).then(function(res) {
136 if(res.data) { 136 if (res.data) {
137 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 137 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
138 $scope.chofer = res.data; 138 $scope.chofer = res.data;
139 $scope.$broadcast('addCabecera', { 139 $scope.$broadcast('addCabecera', {
140 label: 'Transportista:', 140 label: 'Transportista:',
141 valor: codigo + ' - ' + res.data.transportista.NOM 141 valor: codigo + ' - ' + res.data.transportista.NOM
142 }); 142 });
143 } 143 }
144 }); 144 });
145 145
146 focaAbmChoferService.getTransportistas().then(function(res) { 146 focaAbmChoferService.getTransportistas().then(function(res) {
147 $scope.transportistas = res.data; 147 $scope.transportistas = res.data;
148 }); 148 });
149 149
150 $scope.cancelar = function() { 150 $scope.cancelar = function() {
151 $location.path('/chofer'); 151 $location.path('/chofer');
152 }; 152 };
153 153
154 $scope.guardar = function(key) { 154 $scope.guardar = function(key) {
155
156 if (!$scope.chofer.nombre) {
157 focaModalService.alert('Ingrese nombre');
158 return;
159 } else if (!$scope.chofer.idTipoDocumento) {
160 focaModalService.alert('Seleccione tipo de documento');
161 return;
162 } else if (!$scope.chofer.dni){
163 focaModalService.alert('Ingrese DNI');
164 return;
165 }
166
155 key = (typeof key === 'undefined') ? 13 : key; 167 key = (typeof key === 'undefined') ? 13 : key;
156 if(key === 13) { 168 if(key === 13) {
157 validaDni().then(function() { 169 validaDni().then(function() {
158 $scope.chofer.idTransportista = $routeParams.idTransportista; 170 $scope.chofer.idTransportista = $routeParams.idTransportista;
159 delete $scope.chofer.transportista; 171 delete $scope.chofer.transportista;
160 focaAbmChoferService.guardarChofer($scope.chofer).then(function() { 172 focaAbmChoferService.guardarChofer($scope.chofer).then(function() {
161 $location.path('/chofer'); 173 $location.path('/chofer');
162 }); 174 });
163 }, function() { 175 }, function() {
164 focaModalService.alert('Dni existente'); 176 focaModalService.alert('Dni existente');
165 }); 177 });
166 } 178 }
167 }; 179 };
168 180
169 function validaDni() { 181 function validaDni() {
170 return new Promise(function(resolve, reject) { 182 return new Promise(function(resolve, reject) {
171 focaAbmChoferService 183 focaAbmChoferService
172 .getChoferPorDni($scope.chofer.dni) 184 .getChoferPorDni($scope.chofer.dni)
173 .then(function(res) { 185 .then(function(res) {
174 if(res.data.id && 186 if(res.data.id &&
175 $scope.chofer.id !== res.data.id) { 187 $scope.chofer.id !== res.data.id) {
176 reject(res.data); 188 reject(res.data);
177 }else { 189 }else {
178 resolve(); 190 resolve();
179 } 191 }
180 }); 192 });
181 }); 193 });
182 } 194 }
183 } 195 }
184 ]); 196 ]);
185 197