Commit e40b4a34da74708bc8c6af994f133360f048b3e8

Authored by Luigi
1 parent 7c6be3b387
Exists in master

Eliminacion de codigo comentado

Showing 1 changed file with 0 additions and 34 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', '$localStorage', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage',
5 '$routeParams', '$filter', 5 '$routeParams', '$filter',
6 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService, 6 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService,
7 focaBotoneraLateralService, $timeout, $localStorage, $routeParams, $filter) { 7 focaBotoneraLateralService, $timeout, $localStorage, $routeParams, $filter) {
8 8
9 $scope.focused = 1; 9 $scope.focused = 1;
10 $scope.now = new Date(); 10 $scope.now = new Date();
11 $scope.nuevo = $routeParams.id === '0'; 11 $scope.nuevo = $routeParams.id === '0';
12 $scope.filters = ''; 12 $scope.filters = '';
13 $scope.choferes = []; 13 $scope.choferes = [];
14 $scope.creando = false; 14 $scope.creando = false;
15 $scope.crear = false; 15 $scope.crear = false;
16 $scope.transportistas = []; 16 $scope.transportistas = [];
17 $scope.botonera = [{ 17 $scope.botonera = [{
18 label: 'Transportista', 18 label: 'Transportista',
19 image: 'cliente.png' 19 image: 'cliente.png'
20 }]; 20 }];
21 $scope.next = function(key) { 21 $scope.next = function(key) {
22 if (key === 13) $scope.focused++; 22 if (key === 13) $scope.focused++;
23 }; 23 };
24 24
25 //SETEO BOTONERA LATERAL 25 //SETEO BOTONERA LATERAL
26 $timeout(function() { 26 $timeout(function() {
27 focaBotoneraLateralService.showSalir(false); 27 focaBotoneraLateralService.showSalir(false);
28 focaBotoneraLateralService.showPausar(false); 28 focaBotoneraLateralService.showPausar(false);
29 focaBotoneraLateralService.showCancelar(false); 29 focaBotoneraLateralService.showCancelar(false);
30 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 30 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
31 focaBotoneraLateralService.addCustomButton('Salir', salir); 31 focaBotoneraLateralService.addCustomButton('Salir', salir);
32 }); 32 });
33 33
34 if (focaAbmChoferService.transportistaSeleccionado.COD) { 34 if (focaAbmChoferService.transportistaSeleccionado.COD) {
35 elegirTransportista(focaAbmChoferService.transportistaSeleccionado); 35 elegirTransportista(focaAbmChoferService.transportistaSeleccionado);
36 } 36 }
37 37
38 focaAbmChoferService.getTiposDocumento().then(function(res) { 38 focaAbmChoferService.getTiposDocumento().then(function(res) {
39 $scope.tiposDocumento = res.data; 39 $scope.tiposDocumento = res.data;
40 }); 40 });
41 41
42 $scope.crearChofer = function () { 42 $scope.crearChofer = function () {
43 var chofer = { 43 var chofer = {
44 id: 0, 44 id: 0,
45 nombre: '', 45 nombre: '',
46 telefono: '', 46 telefono: '',
47 editando: true, 47 editando: true,
48 }; 48 };
49 $scope.choferes.unshift(chofer); 49 $scope.choferes.unshift(chofer);
50 $scope.crear = false; 50 $scope.crear = false;
51 }; 51 };
52 52
53 $scope.editar = function(chofer) { 53 $scope.editar = function(chofer) {
54 $scope.choferes.forEach(function(chofer) { 54 $scope.choferes.forEach(function(chofer) {
55 chofer.editando = false; 55 chofer.editando = false;
56 $scope.crear = false; 56 $scope.crear = false;
57 }); 57 });
58 chofer.editando = true; 58 chofer.editando = true;
59 $scope.inicial = angular.copy(chofer); 59 $scope.inicial = angular.copy(chofer);
60 }; 60 };
61 61
62 $scope.agregarChofer = function (chofer) { 62 $scope.agregarChofer = function (chofer) {
63 if (!chofer.nombre) { 63 if (!chofer.nombre) {
64 focaModalService.alert('Ingrese nombre'); 64 focaModalService.alert('Ingrese nombre');
65 return; 65 return;
66 } else if (!chofer.idTipoDocumento) { 66 } else if (!chofer.idTipoDocumento) {
67 focaModalService.alert('Ingrese tipo documento'); 67 focaModalService.alert('Ingrese tipo documento');
68 return; 68 return;
69 } 69 }
70 validaDni(chofer); 70 validaDni(chofer);
71 }; 71 };
72 72
73 $scope.tipoDocumento = function (idTipoDocumento) { 73 $scope.tipoDocumento = function (idTipoDocumento) {
74 var value = ''; 74 var value = '';
75 switch (parseInt(idTipoDocumento)) { 75 switch (parseInt(idTipoDocumento)) {
76 case 96 : 76 case 96 :
77 value = 'DNI'; 77 value = 'DNI';
78 break; 78 break;
79 case 80 : 79 case 80 :
80 value = 'CUIT'; 80 value = 'CUIT';
81 break; 81 break;
82 case 86 : 82 case 86 :
83 value = 'CUIL'; 83 value = 'CUIL';
84 break; 84 break;
85 default: 85 default:
86 value = ''; 86 value = '';
87 break; 87 break;
88 } 88 }
89 return value; 89 return value;
90 }; 90 };
91 91
92 $scope.volver = function (chofer, key) { 92 $scope.volver = function (chofer, key) {
93 if (chofer.idTransportista === undefined) { 93 if (chofer.idTransportista === undefined) {
94 $scope.choferes.shift(); 94 $scope.choferes.shift();
95 $scope.crear = true; 95 $scope.crear = true;
96 chofer.editando = false; 96 chofer.editando = false;
97 return; 97 return;
98 } else if (chofer.id !== 0 || !$scope.crear) { 98 } else if (chofer.id !== 0 || !$scope.crear) {
99 $scope.choferes[key] = $scope.inicial; 99 $scope.choferes[key] = $scope.inicial;
100 $scope.choferes[key].editando = false; 100 $scope.choferes[key].editando = false;
101 } 101 }
102 $scope.crear = true; 102 $scope.crear = true;
103 }; 103 };
104 104
105 $scope.guardar = function() { 105 $scope.guardar = function() {
106 $scope.choferes.forEach( function (chofer) { 106 $scope.choferes.forEach( function (chofer) {
107 if (chofer.id === 0) { 107 if (chofer.id === 0) {
108 delete chofer.id; 108 delete chofer.id;
109 } 109 }
110 delete chofer.transportista; 110 delete chofer.transportista;
111 delete chofer.editando; 111 delete chofer.editando;
112 }); 112 });
113 focaAbmChoferService.guardarChoferes($scope.choferes); 113 focaAbmChoferService.guardarChoferes($scope.choferes);
114 }; 114 };
115 115
116 $scope.solicitarConfirmacion = function(chofer) { 116 $scope.solicitarConfirmacion = function(chofer) {
117 focaModalService.confirm('¿Está seguro que desea borrar el chofer ' + 117 focaModalService.confirm('¿Está seguro que desea borrar el chofer ' +
118 chofer.nombre + ' ?').then(function(confirmed) { 118 chofer.nombre + ' ?').then(function(confirmed) {
119 if (confirmed) { 119 if (confirmed) {
120 chofer.desactivado = true; 120 chofer.desactivado = true;
121 } 121 }
122 }); 122 });
123 }; 123 };
124 124
125 $scope.seleccionarTransportista = function() { 125 $scope.seleccionarTransportista = function() {
126 var parametrosModal = { 126 var parametrosModal = {
127 titulo: 'Búsqueda de Transportista', 127 titulo: 'Búsqueda de Transportista',
128 query: '/transportista', 128 query: '/transportista',
129 columnas: [ 129 columnas: [
130 { 130 {
131 nombre: 'Código', 131 nombre: 'Código',
132 propiedad: 'COD' 132 propiedad: 'COD'
133 }, 133 },
134 { 134 {
135 nombre: 'Nombre', 135 nombre: 'Nombre',
136 propiedad: 'NOM' 136 propiedad: 'NOM'
137 }, 137 },
138 { 138 {
139 nombre: 'CUIT', 139 nombre: 'CUIT',
140 propiedad: 'CUIT' 140 propiedad: 'CUIT'
141 } 141 }
142 ] 142 ]
143 }; 143 };
144 focaModalService.modal(parametrosModal).then( 144 focaModalService.modal(parametrosModal).then(
145 function(transportista) { 145 function(transportista) {
146 $scope.crear = true; 146 $scope.crear = true;
147 elegirTransportista(transportista); 147 elegirTransportista(transportista);
148 focaAbmChoferService.transportistaSeleccionado = transportista; 148 focaAbmChoferService.transportistaSeleccionado = transportista;
149 }, function() {} 149 }, function() {}
150 ); 150 );
151 }; 151 };
152 152
153 function elegirTransportista(transportista) { 153 function elegirTransportista(transportista) {
154 buscar(transportista.COD); 154 buscar(transportista.COD);
155 var codigo = ('00000' + transportista.COD).slice(-5); 155 var codigo = ('00000' + transportista.COD).slice(-5);
156 $scope.idTransportista = transportista.COD; 156 $scope.idTransportista = transportista.COD;
157 $timeout(function() { 157 $timeout(function() {
158 $scope.$broadcast('addCabecera', { 158 $scope.$broadcast('addCabecera', {
159 label: 'Transportista:', 159 label: 'Transportista:',
160 valor: codigo + ' - ' + transportista.NOM 160 valor: codigo + ' - ' + transportista.NOM
161 }); 161 });
162 }); 162 });
163 } 163 }
164 164
165 function buscar(id) { 165 function buscar(id) {
166 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) { 166 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) {
167 $scope.choferes = res.data; 167 $scope.choferes = res.data;
168 }); 168 });
169 } 169 }
170 170
171 function salir() { 171 function salir() {
172 focaAbmChoferService.transportistaSeleccionado = {}; 172 focaAbmChoferService.transportistaSeleccionado = {};
173 $location.path('/'); 173 $location.path('/');
174 } 174 }
175 175
176 function validaDni(chofer) { 176 function validaDni(chofer) {
177 if (!chofer.dni) { 177 if (!chofer.dni) {
178 focaModalService.alert('Ingrese DNI'); 178 focaModalService.alert('Ingrese DNI');
179 return; 179 return;
180 } else if (!chofer.telefono) { 180 } else if (!chofer.telefono) {
181 focaModalService.alert('Ingrese teléfono'); 181 focaModalService.alert('Ingrese teléfono');
182 return; 182 return;
183 } 183 }
184 184
185 return new Promise(function(resolve, reject) { 185 return new Promise(function(resolve, reject) {
186 focaAbmChoferService 186 focaAbmChoferService
187 .getChoferPorDni(chofer.dni) 187 .getChoferPorDni(chofer.dni)
188 .then(function(res) { 188 .then(function(res) {
189 if (res.data.id && 189 if (res.data.id &&
190 chofer.id !== res.data.id) { 190 chofer.id !== res.data.id) {
191 reject(res.data); 191 reject(res.data);
192 } else { 192 } else {
193 resolve(); 193 resolve();
194 } 194 }
195 }) 195 })
196 .then(function() { 196 .then(function() {
197 chofer.idTransportista = focaAbmChoferService.transportistaSeleccionado.COD; 197 chofer.idTransportista = focaAbmChoferService.transportistaSeleccionado.COD;
198 delete chofer.transportista; 198 delete chofer.transportista;
199 }, function() { 199 }, function() {
200 focaModalService.alert('Dni existente'); 200 focaModalService.alert('Dni existente');
201 $scope.editando = true; 201 $scope.editando = true;
202 }); 202 });
203 $scope.crear = true; 203 $scope.crear = true;
204 chofer.editando = false; 204 chofer.editando = false;
205 }); 205 });
206 } 206 }
207 207
208 if ($localStorage.chofer) { 208 if ($localStorage.chofer) {
209 var chofer = JSON.parse($localStorage.chofer); 209 var chofer = JSON.parse($localStorage.chofer);
210 if (!chofer.id) { chofer.id = 0; } 210 if (!chofer.id) { chofer.id = 0; }
211 $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista); 211 $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista);
212 } 212 }
213
214 /*$timeout(function() {getLSChofer();});
215
216 function setearChofer(chofer) {
217 $scope.chofer = chofer;
218 $scope.$broadcast('addCabecera', {
219 label: 'Transportista:',
220 valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - '
221 });
222 }
223
224 function getLSChofer() {
225 var chofer = JSON.parse($localStorage.chofer || null);
226
227 if (chofer) {
228 setearChofer(chofer);
229 delete $localStorage.chofer;
230 }
231 }
232
233 $scope.$watch('chofer', function(newValue) {
234 focaBotoneraLateralService.setPausarData({
235 label: 'chofer',
236 val: {
237 dni: newValue.dni,
238 idTransportista: newValue.idTransportista,
239 nombre: newValue.nombre,
240 telefono: newValue.telefono,
241 idTipoDocumento: newValue.idTipoDocumento,
242 id: newValue.id
243 }
244 });
245 }, true);*/
246
247 } 213 }
248 ]); 214 ]);
249 215