Commit 810b738a6acd806b629c24545b506bb7a24dc39c

Authored by Luigi
1 parent 5b2034ac42
Exists in master and in 2 other branches develop, lab

Borre console.log

Showing 1 changed file with 0 additions and 1 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 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService, 5 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService,
6 focaBotoneraLateralService, $timeout, $localStorage) { 6 focaBotoneraLateralService, $timeout, $localStorage) {
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 if ($localStorage.chofer) { 93 if ($localStorage.chofer) {
94 var chofer = JSON.parse($localStorage.chofer); 94 var chofer = JSON.parse($localStorage.chofer);
95 if (!chofer.id) { chofer.id = 0; } 95 if (!chofer.id) { chofer.id = 0; }
96 $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista); 96 $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista);
97 } 97 }
98 } 98 }
99 ]) 99 ])
100 .controller('focaAbmChoferController', [ 100 .controller('focaAbmChoferController', [
101 '$scope', 'focaAbmChoferService', '$routeParams', '$localStorage', '$filter', 101 '$scope', 'focaAbmChoferService', '$routeParams', '$localStorage', '$filter',
102 '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService', '$window', 102 '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService', '$window',
103 function($scope, focaAbmChoferService, $routeParams, $localStorage, $filter, 103 function($scope, focaAbmChoferService, $routeParams, $localStorage, $filter,
104 $location, focaBotoneraLateralService, $timeout, focaModalService){ 104 $location, focaBotoneraLateralService, $timeout, focaModalService){
105 105
106 $scope.focused = 1; 106 $scope.focused = 1;
107 $scope.nuevo = $routeParams.id === '0'; 107 $scope.nuevo = $routeParams.id === '0';
108 $scope.chofer = {}; 108 $scope.chofer = {};
109 $scope.transportistas = []; 109 $scope.transportistas = [];
110 $scope.now = new Date(); 110 $scope.now = new Date();
111 $scope.next = function(key) { 111 $scope.next = function(key) {
112 if (key === 13) $scope.focused++; 112 if (key === 13) $scope.focused++;
113 }; 113 };
114 114
115 focaAbmChoferService.getTiposDocumento().then(function(res) { 115 focaAbmChoferService.getTiposDocumento().then(function(res) {
116 $scope.tiposDocumento = res.data; 116 $scope.tiposDocumento = res.data;
117 }); 117 });
118 118
119 //SETEO BOTONERA LATERAL 119 //SETEO BOTONERA LATERAL
120 $timeout(function() { 120 $timeout(function() {
121 focaBotoneraLateralService.showSalir(false); 121 focaBotoneraLateralService.showSalir(false);
122 focaBotoneraLateralService.showPausar(true); 122 focaBotoneraLateralService.showPausar(true);
123 focaBotoneraLateralService.showCancelar(false); 123 focaBotoneraLateralService.showCancelar(false);
124 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 124 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
125 focaBotoneraLateralService.addCustomButton('Salir', salir); 125 focaBotoneraLateralService.addCustomButton('Salir', salir);
126 126
127 }); 127 });
128 128
129 $timeout(function() {getLSChofer();}); 129 $timeout(function() {getLSChofer();});
130 130
131 if ($scope.nuevo) { 131 if ($scope.nuevo) {
132 focaAbmChoferService 132 focaAbmChoferService
133 .getTransportistaPorId($routeParams.idTransportista) 133 .getTransportistaPorId($routeParams.idTransportista)
134 .then(function(res) { 134 .then(function(res) {
135 var codigo = ('00000' + res.data.COD).slice(-5); 135 var codigo = ('00000' + res.data.COD).slice(-5);
136 $scope.chofer.idTransportista = res.data.COD; 136 $scope.chofer.idTransportista = res.data.COD;
137 $scope.chofer.transportista = res.data; 137 $scope.chofer.transportista = res.data;
138 $scope.$broadcast('addCabecera', { 138 $scope.$broadcast('addCabecera', {
139 label: 'Transportista:', 139 label: 'Transportista:',
140 valor: codigo + ' - ' + res.data.NOM 140 valor: codigo + ' - ' + res.data.NOM
141 }); 141 });
142 }); 142 });
143 } 143 }
144 144
145 focaAbmChoferService.getChofer($routeParams.id).then(function(res) { 145 focaAbmChoferService.getChofer($routeParams.id).then(function(res) {
146 if (res.data) { 146 if (res.data) {
147 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 147 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
148 $scope.chofer = res.data; 148 $scope.chofer = res.data;
149 $scope.$broadcast('addCabecera', { 149 $scope.$broadcast('addCabecera', {
150 label: 'Transportista:', 150 label: 'Transportista:',
151 valor: codigo + ' - ' + res.data.transportista.NOM 151 valor: codigo + ' - ' + res.data.transportista.NOM
152 }); 152 });
153 } 153 }
154 }); 154 });
155 155
156 focaAbmChoferService.getTransportistas().then(function(res) { 156 focaAbmChoferService.getTransportistas().then(function(res) {
157 $scope.transportistas = res.data; 157 $scope.transportistas = res.data;
158 }); 158 });
159 159
160 function setearChofer(chofer) { 160 function setearChofer(chofer) {
161 $scope.chofer = chofer; 161 $scope.chofer = chofer;
162 $scope.$broadcast('addCabecera', { 162 $scope.$broadcast('addCabecera', {
163 label: 'Transportista:', 163 label: 'Transportista:',
164 valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - ' 164 valor: $filter('rellenarDigitos')(chofer.idTransportista.chofer, 2) + ' - '
165 }); 165 });
166 } 166 }
167 function getLSChofer() { 167 function getLSChofer() {
168 var chofer = JSON.parse($localStorage.chofer || null); 168 var chofer = JSON.parse($localStorage.chofer || null);
169 169
170 if (chofer) { 170 if (chofer) {
171 setearChofer(chofer); 171 setearChofer(chofer);
172 delete $localStorage.chofer; 172 delete $localStorage.chofer;
173 } 173 }
174 } 174 }
175 175
176 $scope.cancelar = function() { 176 $scope.cancelar = function() {
177 $location.path('/chofer'); 177 $location.path('/chofer');
178 }; 178 };
179 179
180 $scope.guardar = function(key) { 180 $scope.guardar = function(key) {
181 181
182 key = (typeof key === 'undefined') ? 13 : key; 182 key = (typeof key === 'undefined') ? 13 : key;
183 if (key === 13) { 183 if (key === 13) {
184 console.log('Datos: ', $scope.chofer);
185 if (!$scope.chofer.nombre) { 184 if (!$scope.chofer.nombre) {
186 focaModalService.alert('Ingrese nombre'); 185 focaModalService.alert('Ingrese nombre');
187 return; 186 return;
188 } else if (!$scope.chofer.idTipoDocumento) { 187 } else if (!$scope.chofer.idTipoDocumento) {
189 focaModalService.alert('Seleccione tipo de documento'); 188 focaModalService.alert('Seleccione tipo de documento');
190 return; 189 return;
191 } else if (!$scope.chofer.dni) { 190 } else if (!$scope.chofer.dni) {
192 focaModalService.alert('Ingrese DNI'); 191 focaModalService.alert('Ingrese DNI');
193 return; 192 return;
194 } else if (!$scope.chofer.telefono) { 193 } else if (!$scope.chofer.telefono) {
195 focaModalService.alert('Ingrese número de teléfono'); 194 focaModalService.alert('Ingrese número de teléfono');
196 return; 195 return;
197 } 196 }
198 197
199 validaDni().then(function() { 198 validaDni().then(function() {
200 $scope.chofer.idTransportista = $routeParams.idTransportista; 199 $scope.chofer.idTransportista = $routeParams.idTransportista;
201 delete $scope.chofer.transportista; 200 delete $scope.chofer.transportista;
202 focaAbmChoferService.guardarChofer($scope.chofer).then(function() { 201 focaAbmChoferService.guardarChofer($scope.chofer).then(function() {
203 $location.path('/chofer'); 202 $location.path('/chofer');
204 }); 203 });
205 }, function() { 204 }, function() {
206 focaModalService.alert('Dni existente'); 205 focaModalService.alert('Dni existente');
207 }); 206 });
208 } 207 }
209 }; 208 };
210 209
211 $scope.$watch('chofer', function(newValue) { 210 $scope.$watch('chofer', function(newValue) {
212 focaBotoneraLateralService.setPausarData({ 211 focaBotoneraLateralService.setPausarData({
213 label: 'chofer', 212 label: 'chofer',
214 val: { 213 val: {
215 dni: newValue.dni, 214 dni: newValue.dni,
216 idTransportista: newValue.idTransportista, 215 idTransportista: newValue.idTransportista,
217 nombre: newValue.nombre, 216 nombre: newValue.nombre,
218 telefono: newValue.telefono, 217 telefono: newValue.telefono,
219 idTipoDocumento: newValue.idTipoDocumento, 218 idTipoDocumento: newValue.idTipoDocumento,
220 id: newValue.id 219 id: newValue.id
221 } 220 }
222 }); 221 });
223 }, true); 222 }, true);
224 223
225 function salir() { 224 function salir() {
226 if ($scope.formChofer.$pristine == false) { 225 if ($scope.formChofer.$pristine == false) {
227 focaModalService.confirm( 226 focaModalService.confirm(
228 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 227 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
229 ).then(function(data) { 228 ).then(function(data) {
230 if (data) { 229 if (data) {
231 $location.path('/chofer'); 230 $location.path('/chofer');
232 } 231 }
233 }); 232 });
234 } else { 233 } else {
235 $location.path('/chofer'); 234 $location.path('/chofer');
236 } 235 }
237 } 236 }
238 237
239 function validaDni() { 238 function validaDni() {
240 return new Promise(function(resolve, reject) { 239 return new Promise(function(resolve, reject) {
241 focaAbmChoferService 240 focaAbmChoferService
242 .getChoferPorDni($scope.chofer.dni) 241 .getChoferPorDni($scope.chofer.dni)
243 .then(function(res) { 242 .then(function(res) {
244 if (res.data.id && 243 if (res.data.id &&
245 $scope.chofer.id !== res.data.id) { 244 $scope.chofer.id !== res.data.id) {
246 reject(res.data); 245 reject(res.data);
247 } else { 246 } else {
248 resolve(); 247 resolve();
249 } 248 }
250 }); 249 });
251 }); 250 });
252 } 251 }
253 } 252 }
254 ]); 253 ]);
255 254