Commit e80bc1985be3f32768fd1aabcd8f712864b0d70c

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

Merge branch 'develop' of http://git.focasoftware.com/npm/foca-abm-chofer

spec/controllerSpec.js
1 describe('Controladores de abm chofer', function() { 1 describe('Controladores de abm chofer', function() {
2 2
3 var $controller; 3 var $controller;
4 4
5 beforeEach(function() { 5 beforeEach(function() {
6 module('focaAbmChofer'); 6 module('focaAbmChofer');
7 inject(function(_$controller_) { 7 inject(function(_$controller_) {
8 $controller = _$controller_; 8 $controller = _$controller_;
9 }); 9 });
10 }); 10 });
11 11
12 describe('Controlador focaAbmChoferesController', function() { 12 describe('Controlador focaAbmChoferesController', function() {
13 13
14 it('Existe el controlador focaAbmChoferesController', function() { 14 it('Existe el controlador focaAbmChoferesController', function() {
15 //arrange 15 //arrange
16 var controlador = $controller('focaAbmChoferesController', { 16 var controlador = $controller('focaAbmChoferesController', {
17 $scope: {}, 17 $scope: {},
18 focaAbmChoferService: { 18 focaAbmChoferService: {
19 transportistaSeleccionado: function() { return; } 19 transportistaSeleccionado: function() { return; }
20 }, 20 },
21 $location: {}, 21 $location: {},
22 $localStorage: {},
22 $uibModal: {}, 23 $uibModal: {},
23 focaModalService: {}, 24 focaModalService: {},
24 focaBotoneraLateralService: {}, 25 focaBotoneraLateralService: {},
25 $timeout: function() { return; } 26 $timeout: function() { return; }
26 }); 27 });
27 28
28 //assert 29 //assert
29 expect(typeof controlador).toEqual('object'); 30 expect(typeof controlador).toEqual('object');
30 }); 31 });
31 32
32 it('$scope.solicitarConfirmacion levanta modal de confirmacion', function() { 33 it('$scope.solicitarConfirmacion levanta modal de confirmacion', function() {
33 //arrange 34 //arrange
34 var fakeParam = ''; 35 var fakeParam = '';
35 var scope = {}; 36 var scope = {};
36 var focaModalService = { 37 var focaModalService = {
37 confirm: function() { } 38 confirm: function() { }
38 }; 39 };
39 var controlador = $controller('focaAbmChoferesController', { 40 var controlador = $controller('focaAbmChoferesController', {
40 $scope: scope, 41 $scope: scope,
41 focaAbmChoferService: { 42 focaAbmChoferService: {
42 transportistaSeleccionado: function() { return; } 43 transportistaSeleccionado: function() { return; }
43 }, 44 },
44 $location: {}, 45 $location: {},
46 $localStorage: {},
45 $uibModal: {}, 47 $uibModal: {},
46 focaModalService: focaModalService, 48 focaModalService: focaModalService,
47 focaBotoneraLateralService: {}, 49 focaBotoneraLateralService: {},
48 $timeout: function() { return; } 50 $timeout: function() { return; }
49 }); 51 });
50 console.info(controlador); 52 console.info(controlador);
51 53
52 //act 54 //act
53 spyOn(focaModalService, 'confirm').and.returnValue({ then: function() { }}); 55 spyOn(focaModalService, 'confirm').and.returnValue({ then: function() { }});
54 scope.solicitarConfirmacion(fakeParam); 56 scope.solicitarConfirmacion(fakeParam);
55 57
56 //assert 58 //assert
57 expect(focaModalService.confirm).toHaveBeenCalled(); 59 expect(focaModalService.confirm).toHaveBeenCalled();
58 }); 60 });
59 61
60 it('$scope.solicitarConfirmacion elimina al confirmar', function(done) { 62 it('$scope.solicitarConfirmacion elimina al confirmar', function(done) {
61 //arrange 63 //arrange
62 var scope = {}; 64 var scope = {};
63 var focaModalService = { 65 var focaModalService = {
64 confirm: function() { 66 confirm: function() {
65 return { 67 return {
66 then: function() { } 68 then: function() { }
67 }; 69 };
68 } 70 }
69 }; 71 };
70 var focaAbmChoferService = { 72 var focaAbmChoferService = {
71 transportistaSeleccionado: function() { return; }, 73 transportistaSeleccionado: function() { return; },
72 deleteChofer: function() { } 74 deleteChofer: function() { }
73 }; 75 };
74 var controlador = $controller('focaAbmChoferesController', { 76 var controlador = $controller('focaAbmChoferesController', {
75 $scope: scope, 77 $scope: scope,
76 focaAbmChoferService: focaAbmChoferService, 78 focaAbmChoferService: focaAbmChoferService,
77 $location: {}, 79 $location: {},
80 $localStorage: {},
78 $uibModal: {}, 81 $uibModal: {},
79 focaModalService: focaModalService, 82 focaModalService: focaModalService,
80 focaBotoneraLateralService: {}, 83 focaBotoneraLateralService: {},
81 $timeout: function() { return; } 84 $timeout: function() { return; }
82 }); 85 });
83 console.info(controlador); 86 console.info(controlador);
84 var fakeParam = ''; 87 var fakeParam = '';
85 var promesa = Promise.resolve(true); 88 var promesa = Promise.resolve(true);
86 89
87 //act 90 //act
88 spyOn(focaModalService, 'confirm').and.returnValue(promesa); 91 spyOn(focaModalService, 'confirm').and.returnValue(promesa);
89 spyOn(focaAbmChoferService, 'deleteChofer'); 92 spyOn(focaAbmChoferService, 'deleteChofer');
90 scope.solicitarConfirmacion(fakeParam); 93 scope.solicitarConfirmacion(fakeParam);
91 94
92 //assert 95 //assert
93 promesa.then(function() { 96 promesa.then(function() {
94 expect(focaAbmChoferService.deleteChofer).toHaveBeenCalled(); 97 expect(focaAbmChoferService.deleteChofer).toHaveBeenCalled();
95 done(); 98 done();
96 }); 99 });
97 }); 100 });
98 101
99 it('$scope.seleccionarTransportista levanta modal', function() { 102 it('$scope.seleccionarTransportista levanta modal', function() {
100 //arrange 103 //arrange
101 var scope = {}; 104 var scope = {};
102 var focaModalService = { 105 var focaModalService = {
103 modal: function() { } 106 modal: function() { }
104 }; 107 };
105 var controlador = $controller('focaAbmChoferesController', { 108 var controlador = $controller('focaAbmChoferesController', {
106 $scope: scope, 109 $scope: scope,
107 focaAbmChoferService: { 110 focaAbmChoferService: {
108 transportistaSeleccionado: function() { } 111 transportistaSeleccionado: function() { }
109 }, 112 },
110 $location: {}, 113 $location: {},
114 $localStorage: {},
111 $uibModal: {}, 115 $uibModal: {},
112 focaModalService: focaModalService, 116 focaModalService: focaModalService,
113 focaBotoneraLateralService: {}, 117 focaBotoneraLateralService: {},
114 $timeout: function() { return; } 118 $timeout: function() { return; }
115 }); 119 });
116 console.info(controlador); 120 console.info(controlador);
117 121
118 //act 122 //act
119 spyOn(focaModalService, 'modal').and.returnValue({ then: function() { }}); 123 spyOn(focaModalService, 'modal').and.returnValue({ then: function() { }});
120 scope.seleccionarTransportista(); 124 scope.seleccionarTransportista();
121 125
122 //assert 126 //assert
123 expect(focaModalService.modal).toHaveBeenCalled(); 127 expect(focaModalService.modal).toHaveBeenCalled();
124 }); 128 });
125 }); 129 });
126 130
127 describe('Controlador focaAbmChoferController', function() { 131 describe('Controlador focaAbmChoferController', function() {
128 132
129 it('Existe el controlador focaAbmChoferController', function() { 133 it('Existe el controlador focaAbmChoferController', function() {
130 //arrange 134 //arrange
131 var controlador = $controller('focaAbmChoferController', { 135 var controlador = $controller('focaAbmChoferController', {
132 $scope: {}, 136 $scope: {
137 $watch: function() {}
138 },
133 focaAbmChoferService: { 139 focaAbmChoferService: {
134 getTiposDocumento: function() { 140 getTiposDocumento: function() {
135 return { 141 return {
136 then: function() { } 142 then: function() { }
137 }; 143 };
138 }, 144 },
139 getChofer: function() { 145 getChofer: function() {
140 return { 146 return {
141 then: function() { } 147 then: function() { }
142 }; 148 };
143 }, 149 },
144 getTransportistas: function() { 150 getTransportistas: function() {
145 return { 151 return {
146 then: function() { } 152 then: function() { }
147 }; 153 };
148 } 154 }
149 }, 155 },
150 $routeParams: {}, 156 $routeParams: {},
151 $location: {}, 157 $location: {},
158 $localStorage: {},
152 focaBotoneraLateralService: {}, 159 focaBotoneraLateralService: {},
153 $timeout: function() { return; }, 160 $timeout: function() { return; },
154 focaModalService: {} 161 focaModalService: {}
155 }); 162 });
156 163
157 //assert 164 //assert
158 expect(typeof controlador).toEqual('object'); 165 expect(typeof controlador).toEqual('object');
159 }); 166 });
160 167
161 it('$scope.cancelar lleva a la ruta correcta', function() { 168 it('$scope.cancelar lleva a la ruta correcta', function() {
162 inject(function($location) { 169 inject(function($location) {
163 //arrange 170 //arrange
164 var scope = {}; 171 var scope = {
172 $watch: function() {}
173 };
165 var controlador = $controller('focaAbmChoferController', { 174 var controlador = $controller('focaAbmChoferController', {
166 $scope: scope, 175 $scope: scope,
167 focaAbmChoferService: { 176 focaAbmChoferService: {
168 getTiposDocumento: function() { 177 getTiposDocumento: function() {
169 return { 178 return {
170 then: function() { } 179 then: function() { }
171 }; 180 };
172 }, 181 },
173 getChofer: function() { 182 getChofer: function() {
174 return { 183 return {
175 then: function() { } 184 then: function() { }
176 }; 185 };
177 }, 186 },
178 getTransportistas: function() { 187 getTransportistas: function() {
179 return { 188 return {
180 then: function() { } 189 then: function() { }
181 }; 190 };
182 } 191 }
183 }, 192 },
184 $routeParams: {}, 193 $routeParams: {},
185 $location: $location, 194 $location: $location,
195 $localStorage: {},
186 focaBotoneraLateralService: {}, 196 focaBotoneraLateralService: {},
187 $timeout: function() { return; }, 197 $timeout: function() { return; },
188 focaModalService: {} 198 focaModalService: {}
189 }); 199 });
190 console.info(controlador); 200 console.info(controlador);
191 201
192 //act 202 //act
193 scope.cancelar(); 203 scope.cancelar();
194 204
195 //assert 205 //assert
196 expect($location.url()).toEqual('/chofer'); 206 expect($location.url()).toEqual('/chofer');
197 }); 207 });
198 }); 208 });
199 209
200 it('$scope.guardar guarda chofer al validarDNI() da ok', function(done) { 210 it('$scope.guardar guarda chofer al validarDNI() da ok', function(done) {
201 211
202 //arrange 212 //arrange
203 var scope = {}; 213 var scope = {
214 $watch: function(){},
215 chofer: {}
216 };
204 var focaAbmChoferService = { 217 var focaAbmChoferService = {
205 getTiposDocumento: function() { 218 getTiposDocumento: function() {
206 return { 219 return {
207 then: function() { } 220 then: function() { }
208 }; 221 };
209 }, 222 },
210 getChofer: function() { 223 getChofer: function() {
211 return { 224 return {
212 then: function() { } 225 then: function() { }
213 }; 226 };
214 }, 227 },
215 getTransportistas: function() { 228 getTransportistas: function() {
216 return { 229 return {
217 then: function() { } 230 then: function() { }
218 }; 231 };
219 }, 232 },
220 guardarChofer: function() { }, 233 guardarChofer: function() { },
221 getChoferPorDni: function() { } 234 getChoferPorDni: function() { }
222 }; 235 };
223 var controlador = $controller('focaAbmChoferController', { 236 var controlador = $controller('focaAbmChoferController', {
224 $scope: scope, 237 $scope: scope,
225 focaAbmChoferService: focaAbmChoferService, 238 focaAbmChoferService: focaAbmChoferService,
226 $routeParams: {}, 239 $routeParams: {},
227 $location: {}, 240 $location: {},
241 $localStorage: {},
228 focaBotoneraLateralService: {}, 242 focaBotoneraLateralService: {},
229 $timeout: function() { return; }, 243 $timeout: function() { return; },
230 focaModalService: {} 244 focaModalService: {
245 alert: function() {}
246 }
231 }); 247 });
232 console.info(controlador); 248 console.info(controlador);
233 var resolveFake = { data: false }; 249 var resolveFake = { data: false };
234 var promesaChoferPorDni = Promise.resolve(resolveFake); 250 var promesaChoferPorDni = Promise.resolve(resolveFake);
235 251 scope.chofer.nombre = true;
252 scope.chofer.idTipoDocumento = true;
253 scope.chofer.dni = true;
236 //act 254 //act
237 spyOn(focaAbmChoferService, 'guardarChofer').and.returnValue({ then: function() { }}); 255 spyOn(focaAbmChoferService, 'guardarChofer').and.returnValue({ then: function() { }});
238 spyOn(focaAbmChoferService, 'getChoferPorDni').and.returnValue(promesaChoferPorDni); 256 spyOn(focaAbmChoferService, 'getChoferPorDni').and.returnValue(promesaChoferPorDni);
239 scope.guardar(13); 257 scope.guardar(13);
240 258
241 //assert 259 //assert
242 promesaChoferPorDni.then(function() { 260 promesaChoferPorDni.then(function() {
243 setTimeout(function() { 261 setTimeout(function() {
244 expect(focaAbmChoferService.guardarChofer).toHaveBeenCalled(); 262 expect(focaAbmChoferService.guardarChofer).toHaveBeenCalled();
245 done(); 263 done();
246 }); 264 });
247 }); 265 });
248 }); 266 });
249 267
250 it('$scope.guardar da alerta chofer al validarDNI() da reject', function(done) { 268 it('$scope.guardar da alerta chofer al validarDNI() da reject', function(done) {
251 269
252 //arrange 270 //arrange
253 var scope = {}; 271 var scope = {
272 $watch: function() {}
273 };
254 var focaModalService = { 274 var focaModalService = {
255 alert: function() { } 275 alert: function() { }
256 }; 276 };
257 var focaAbmChoferService = { 277 var focaAbmChoferService = {
258 getTiposDocumento: function() { 278 getTiposDocumento: function() {
259 return { 279 return {
260 then: function() { } 280 then: function() { }
261 }; 281 };
262 }, 282 },
263 getChofer: function() { 283 getChofer: function() {
264 return { 284 return {
265 then: function() { } 285 then: function() { }
266 }; 286 };
267 }, 287 },
268 getTransportistas: function() { 288 getTransportistas: function() {
269 return { 289 return {
270 then: function() { } 290 then: function() { }
271 }; 291 };
272 }, 292 },
273 getChoferPorDni: function() { } 293 getChoferPorDni: function() { }
274 }; 294 };
275 var controlador = $controller('focaAbmChoferController', { 295 var controlador = $controller('focaAbmChoferController', {
276 $scope: scope, 296 $scope: scope,
277 focaAbmChoferService: focaAbmChoferService, 297 focaAbmChoferService: focaAbmChoferService,
278 $routeParams: {}, 298 $routeParams: {},
279 $location: {}, 299 $location: {},
300 $localStorage: {},
280 focaBotoneraLateralService: {}, 301 focaBotoneraLateralService: {},
281 $timeout: function() { return; }, 302 $timeout: function() { return; },
282 focaModalService: focaModalService 303 focaModalService: focaModalService
283 }); 304 });
284 console.info(controlador); 305 console.info(controlador);
285 var resolveFake = { data: { id: true } }; 306 var resolveFake = { data: { id: true } };
286 var promesaChoferPorDni = Promise.resolve(resolveFake); 307 var promesaChoferPorDni = Promise.resolve(resolveFake);
287 308
288 //act 309 //act
289 spyOn(focaAbmChoferService, 'getChoferPorDni').and.returnValue(promesaChoferPorDni); 310 spyOn(focaAbmChoferService, 'getChoferPorDni').and.returnValue(promesaChoferPorDni);
290 spyOn(focaModalService, 'alert'); 311 spyOn(focaModalService, 'alert');
291 scope.chofer.id = 'dato prueba'; 312 scope.chofer.id = 'dato prueba';
292 scope.guardar(13); 313 scope.guardar(13);
293 314
294 //assert 315 //assert
295 promesaChoferPorDni.then(function() { 316 promesaChoferPorDni.then(function() {
296 //await sleep(100); 317 //await sleep(100);
297 setTimeout(function() { 318 setTimeout(function() {
298 expect(focaModalService.alert).toHaveBeenCalled(); 319 expect(focaModalService.alert).toHaveBeenCalled();
299 done(); 320 done();
300 }); 321 });
301 }); 322 });
302 }); 323 });
303 }); 324 });
304 }); 325 });
305 326
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', '$localStorage',
5 '$routeParams', '$filter',
5 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService, 6 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService,
6 focaBotoneraLateralService, $timeout) { 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 }
93 ])
94 .controller('focaAbmChoferController', [
95 '$scope', 'focaAbmChoferService', '$routeParams',
96 '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService',
97 function($scope, focaAbmChoferService, $routeParams,
98 $location, focaBotoneraLateralService, $timeout, focaModalService) {
99 175
100 $scope.focused = 1; 176 function validaDni(chofer) {
101 $scope.nuevo = $routeParams.id === '0'; 177 if (!chofer.dni) {
102 $scope.chofer = {}; 178 focaModalService.alert('Ingrese DNI');
103 $scope.transportistas = []; 179 return;
104 $scope.now = new Date(); 180 } else if (!chofer.telefono) {
105 $scope.next = function(key) { 181 focaModalService.alert('Ingrese teléfono');
106 if (key === 13) $scope.focused++; 182 return;
107 };
108
109 focaAbmChoferService.getTiposDocumento().then(function(res) {
110 $scope.tiposDocumento = res.data;
111 });
112
113 //SETEO BOTONERA LATERAL
114 $timeout(function() {
115 focaBotoneraLateralService.showSalir(false);
116 focaBotoneraLateralService.showPausar(true);
117 focaBotoneraLateralService.showCancelar(true);
118 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
119 });
120
121 if($scope.nuevo) {
122 focaAbmChoferService
123 .getTransportistaPorId($routeParams.idTransportista)
124 .then(function(res) {
125 var codigo = ('00000' + res.data.COD).slice(-5);
126 $scope.chofer.idTransportista = res.data.COD;
127 $scope.chofer.transportista = res.data;
128 $scope.$broadcast('addCabecera', {
129 label: 'Transportista:',
130 valor: codigo + ' - ' + res.data.NOM
131 });
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-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> 27 <label class="offset-sm-1 col-sm-2 col-form-label">Tipo documento</label>
28 <div class="col-sm-4"> 28 <div class="col-sm-4">
29 <select 29 <select
30 class="form-control" 30 class="form-control"
31 ng-options="tipoDocumento.id as tipoDocumento.descripcion for tipoDocumento in tiposDocumento track by tipoDocumento.id" 31 ng-options="tipoDocumento.id as tipoDocumento.descripcion for tipoDocumento in tiposDocumento track by tipoDocumento.id"
32 ng-model="chofer.idTipoDocumento"> 32 ng-model="chofer.idTipoDocumento">
33 </select> 33 </select>
34 </div> 34 </div>
35 </div> 35 </div>
36 <div class="form-group row"> 36 <div class="form-group row">
37 <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>
38 <div class="col-sm-4"> 38 <div class="col-sm-4">
39 <input 39 <input
40 class="form-control" 40 class="form-control"
41 type="text" 41 foca-tipo-input
42 teclado-virtual 42 teclado-virtual
43 solo-positivos
44 limite-numeros-max="15"
43 ng-model="chofer.dni" 45 ng-model="chofer.dni"
44 ng-required="true" 46 ng-required="true"
45 ng-keypress="next($event.keyCode)" 47 ng-keypress="next($event.keyCode)"
46 foca-focus="focused == 2" 48 foca-focus="focused == 2"
47 ng-focus="focused = 2" 49 ng-focus="focused = 2"
48 ng-disabled="!nuevo" 50 ng-disabled="!nuevo"
51 string-toNumber
49 /> 52 />
50 </div> 53 </div>
51 </div> 54 </div>
52 <div class="form-group row"> 55 <div class="form-group row">
53 <label class="offset-sm-1 col-sm-2 col-form-label">Teléfono</label> 56 <label class="offset-sm-1 col-sm-2 col-form-label">Teléfono</label>
54 <div class="col-sm-4"> 57 <div class="col-sm-4">
55 <input 58 <input
56 class="form-control" 59 class="form-control"
57 type="text" 60 foca-tipo-input
58 teclado-virtual 61 teclado-virtual
62 solo-positivos
63 limite-numeros-max="15"
59 ng-model="chofer.telefono" 64 ng-model="chofer.telefono"
60 ng-required="true" 65 ng-required="true"
61 ng-keypress="guardar($event.keyCode)" 66 ng-keypress="guardar($event.keyCode)"
62 foca-focus="focused == 3" 67 foca-focus="focused == 3"
63 ng-focus="focused = 3" 68 ng-focus="focused = 3"
69 string-toNumber
64 /> 70 />
65 </div> 71 </div>
66 </div> 72 </div>
67 </form> 73 </form>
68 </div> 74 </div>
69 75
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>