Commit c8aa909c22ba29908c6a173ea8f41446bf46b850
Exists in
master
Merge branch 'master' into 'master'
Master See merge request !8
Showing
3 changed files
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 | $scope.focused = 1; | ||
16 | 15 | ||
17 | //SETEO BOTONERA LATERAL | 16 | //SETEO BOTONERA LATERAL |
18 | $timeout(function() { | 17 | $timeout(function() { |
19 | focaBotoneraLateralService.showSalir(true); | 18 | focaBotoneraLateralService.showSalir(false); |
20 | focaBotoneraLateralService.showPausar(false); | 19 | focaBotoneraLateralService.showPausar(false); |
21 | focaBotoneraLateralService.showCancelar(false); | 20 | focaBotoneraLateralService.showCancelar(false); |
22 | focaBotoneraLateralService.showGuardar(false); | 21 | focaBotoneraLateralService.showGuardar(false); |
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 | |||
83 | function salir() { | ||
84 | focaAbmChoferService.transportistaSeleccionado = {}; | ||
85 | $location.path('/'); | ||
86 | } | ||
82 | } | 87 | } |
83 | ]) | 88 | ]) |
84 | .controller('focaAbmChoferController', [ | 89 | .controller('focaAbmChoferController', [ |
85 | '$scope', 'focaAbmChoferService', '$routeParams', | 90 | '$scope', 'focaAbmChoferService', '$routeParams', |
86 | '$location', 'focaBotoneraLateralService', '$timeout', | 91 | '$location', 'focaBotoneraLateralService', '$timeout', 'focaModalService', |
87 | function($scope, focaAbmChoferService, $routeParams, | 92 | function($scope, focaAbmChoferService, $routeParams, |
88 | $location, focaBotoneraLateralService, $timeout) { | 93 | $location, focaBotoneraLateralService, $timeout, focaModalService) { |
94 | |||
95 | $scope.focused = 1; | ||
89 | $scope.nuevo = $routeParams.id === '0'; | 96 | $scope.nuevo = $routeParams.id === '0'; |
90 | $scope.chofer = {}; | 97 | $scope.chofer = {}; |
91 | $scope.transportistas = []; | 98 | $scope.transportistas = []; |
92 | $scope.now = new Date(); | 99 | $scope.now = new Date(); |
93 | $scope.next = function(key) { | 100 | $scope.next = function(key) { |
94 | if (key === 13) $scope.focused++; | 101 | if (key === 13) $scope.focused++; |
95 | }; | 102 | }; |
96 | 103 | ||
97 | //SETEO BOTONERA LATERAL | 104 | //SETEO BOTONERA LATERAL |
98 | $timeout(function() { | 105 | $timeout(function() { |
99 | focaBotoneraLateralService.showSalir(false); | 106 | focaBotoneraLateralService.showSalir(false); |
100 | focaBotoneraLateralService.showPausar(true); | 107 | focaBotoneraLateralService.showPausar(true); |
101 | focaBotoneraLateralService.showCancelar(true); | 108 | focaBotoneraLateralService.showCancelar(true); |
102 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 109 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
103 | }); | 110 | }); |
104 | 111 | ||
105 | if($scope.nuevo) { | 112 | if($scope.nuevo) { |
106 | focaAbmChoferService | 113 | focaAbmChoferService |
107 | .getTransportistaPorId($routeParams.idTransportista) | 114 | .getTransportistaPorId($routeParams.idTransportista) |
108 | .then(function(res) { | 115 | .then(function(res) { |
109 | var codigo = ('00000' + res.data.COD).slice(-5); | 116 | var codigo = ('00000' + res.data.COD).slice(-5); |
110 | $scope.chofer.idTransportista = res.data.COD; | 117 | $scope.chofer.idTransportista = res.data.COD; |
111 | $scope.chofer.transportista = res.data; | 118 | $scope.chofer.transportista = res.data; |
112 | $scope.$broadcast('addCabecera', { | 119 | $scope.$broadcast('addCabecera', { |
113 | label: 'Transportista:', | 120 | label: 'Transportista:', |
114 | valor: codigo + ' - ' + res.data.NOM | 121 | valor: codigo + ' - ' + res.data.NOM |
115 | }); | 122 | }); |
116 | }); | 123 | }); |
117 | } | 124 | } |
118 | 125 | ||
119 | focaAbmChoferService.getChofer($routeParams.id).then(function(res) { | 126 | focaAbmChoferService.getChofer($routeParams.id).then(function(res) { |
120 | if(res.data) { | 127 | if(res.data) { |
121 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 128 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); |
122 | $scope.chofer = res.data; | 129 | $scope.chofer = res.data; |
123 | $scope.$broadcast('addCabecera', { | 130 | $scope.$broadcast('addCabecera', { |
124 | label: 'Transportista:', | 131 | label: 'Transportista:', |
125 | valor: codigo + ' - ' + res.data.transportista.NOM | 132 | valor: codigo + ' - ' + res.data.transportista.NOM |
126 | }); | 133 | }); |
127 | } | 134 | } |
128 | }); | 135 | }); |
129 | 136 | ||
130 | focaAbmChoferService.getTransportistas().then(function(res) { | 137 | focaAbmChoferService.getTransportistas().then(function(res) { |
131 | $scope.transportistas = res.data; | 138 | $scope.transportistas = res.data; |
132 | }); | 139 | }); |
133 | 140 | ||
134 | $scope.cancelar = function() { | 141 | $scope.cancelar = function() { |
135 | $location.path('/chofer'); | 142 | $location.path('/chofer'); |
136 | }; | 143 | }; |
137 | 144 | ||
138 | $scope.guardar = function() { | 145 | $scope.guardar = function(key) { |
139 | $scope.chofer.idTransportista = $routeParams.idTransportista; | 146 | key = (typeof key === 'undefined') ? 13 : key; |
140 | delete $scope.chofer.transportista; | 147 | |
141 | focaAbmChoferService.guardarChofer($scope.chofer).then(function() { | 148 | if(key === 13) { |
142 | $location.path('/chofer'); | 149 | validaDni().then(function() { |
143 | }); | 150 | $scope.chofer.idTransportista = $routeParams.idTransportista; |
151 | delete $scope.chofer.transportista; | ||
152 | focaAbmChoferService.guardarChofer($scope.chofer).then(function() { | ||
153 | $location.path('/chofer'); | ||
154 | }); | ||
155 | }, function() { | ||
156 | focaModalService.alert('Dni existente'); | ||
157 | }); | ||
158 | } | ||
144 | }; | 159 | }; |
160 | |||
161 | function validaDni() { | ||
162 | return new Promise(function(resolve, reject) { | ||
163 | focaAbmChoferService | ||
164 | .getChoferPorTransportista(parseInt($routeParams.idTransportista)) | ||
165 | .then(function(res) { | ||
166 | //Valida si existe dni | ||
167 | var existe = res.data.filter(function(chofer) { | ||
168 | return chofer.dni === $scope.chofer.dni && | ||
169 | chofer.id !== $scope.chofer.id; | ||
170 | }); | ||
171 | |||
172 | if(existe.length) { | ||
173 | reject(existe); | ||
174 | }else { | ||
175 | resolve(); | ||
176 | } | ||
177 | }); | ||
178 | }); | ||
179 | } | ||
145 | } | 180 | } |
146 | ]); | 181 | ]); |
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">Transportista</label> | ||
13 | <div class="col-sm-4"> | ||
14 | <input | ||
15 | class="form-control" | ||
16 | type="text" | ||
17 | teclado-virtual | ||
18 | ng-model="chofer.transportista.NOM" | ||
19 | readonly | ||
20 | /> | ||
21 | </div> | ||
22 | </div> | ||
23 | <div class="form-group row"> | ||
24 | <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> |
25 | <div class="col-sm-4"> | 13 | <div class="col-sm-4"> |
26 | <input | 14 | <input |
27 | class="form-control" | 15 | class="form-control" |
28 | type="text" | 16 | type="text" |
29 | teclado-virtual | 17 | teclado-virtual |
30 | ng-model="chofer.nombre" | 18 | ng-model="chofer.nombre" |
31 | ng-required="true" | 19 | ng-required="true" |
32 | ng-keypress="next($event.keyCode)" | 20 | ng-keypress="next($event.keyCode)" |
33 | foca-focus="focused == 1" | 21 | foca-focus="focused == 1" |
34 | ng-focus="focused = 1" | 22 | ng-focus="focused = 1" |
35 | /> | 23 | /> |
36 | </div> | 24 | </div> |
37 | </div> | 25 | </div> |
38 | <div class="form-group row"> | 26 | <div class="form-group row"> |
39 | <label class="offset-sm-1 col-sm-2 col-form-label">DNI</label> | 27 | <label class="offset-sm-1 col-sm-2 col-form-label">DNI</label> |
40 | <div class="col-sm-4"> | 28 | <div class="col-sm-4"> |
41 | <input | 29 | <input |
42 | class="form-control" | 30 | class="form-control" |
43 | type="text" | 31 | type="text" |
44 | teclado-virtual | 32 | teclado-virtual |
45 | ng-model="chofer.dni" | 33 | ng-model="chofer.dni" |
46 | ng-required="true" | 34 | ng-required="true" |
47 | ng-keypress="next($event.keyCode)" | 35 | ng-keypress="next($event.keyCode)" |
48 | foca-focus="focused == 2" | 36 | foca-focus="focused == 2" |
49 | ng-focus="focused = 2" | 37 | ng-focus="focused = 2" |
38 | ng-disabled="!nuevo" | ||
50 | /> | 39 | /> |
51 | </div> | 40 | </div> |
52 | </div> | 41 | </div> |
53 | <div class="form-group row"> | 42 | <div class="form-group row"> |
54 | <label class="offset-sm-1 col-sm-2 col-form-label">Teléfono</label> | 43 | <label class="offset-sm-1 col-sm-2 col-form-label">Teléfono</label> |
55 | <div class="col-sm-4"> | 44 | <div class="col-sm-4"> |
56 | <input | 45 | <input |
57 | class="form-control" | 46 | class="form-control" |
58 | type="text" | 47 | type="text" |
59 | teclado-virtual | 48 | teclado-virtual |
60 | ng-model="chofer.telefono" | 49 | ng-model="chofer.telefono" |
61 | ng-required="true" | 50 | ng-required="true" |
62 | ng-keypress="next($event.keyCode)" | 51 | ng-keypress="guardar($event.keyCode)" |
63 | foca-focus="focused == 3" | 52 | foca-focus="focused == 3" |
64 | ng-focus="focused = 3" | 53 | ng-focus="focused = 3" |
65 | /> | 54 | /> |
66 | </div> | 55 | </div> |
67 | </div> | 56 | </div> |
68 | </form> | 57 | </form> |
69 | </div> | 58 | </div> |
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" extra="5" class="row"></foca-botonera-facturador> | 12 | <foca-botonera-facturador botones="botonera" extra="5" 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>Código</th> | ||
19 | <th>Nombre</th> | 18 | <th>Nombre</th> |
20 | <th>DNI</th> | 19 | <th>DNI</th> |
21 | <th>Teléfono</th> | 20 | <th>Teléfono</th> |
22 | <th class="text-center"> | 21 | <th class="text-center"> |
23 | <button | 22 | <button |
24 | ng-disabled="!idTransportista" | 23 | ng-disabled="!idTransportista" |
25 | title="Agregar" | 24 | title="Agregar" |
26 | class="btn btn-outline-debo boton-accion" | 25 | class="btn btn-outline-debo boton-accion" |
27 | ng-click="editar(0)"> | 26 | ng-click="editar(0)"> |
28 | <i class="fa fa-plus"></i> | 27 | <i class="fa fa-plus"></i> |
29 | </button> | 28 | </button> |
30 | </th> | 29 | </th> |
31 | </tr> | 30 | </tr> |
32 | </thead> | 31 | </thead> |
33 | <tbody> | 32 | <tbody> |
34 | <tr ng-repeat="chofer in choferes | filter:filters"> | 33 | <tr ng-repeat="chofer in choferes | filter:filters"> |
35 | <td ng-bind="chofer.id"></td> | ||
36 | <td ng-bind="chofer.nombre"></td> | 34 | <td ng-bind="chofer.nombre"></td> |
37 | <td ng-bind="chofer.dni"></td> | 35 | <td ng-bind="chofer.dni"></td> |
38 | <td ng-bind="chofer.telefono"></td> | 36 | <td ng-bind="chofer.telefono"></td> |
39 | <td class="text-center"> | 37 | <td class="text-center"> |
40 | <button | 38 | <button |
41 | class="btn btn-outline-dark boton-accion" | 39 | class="btn btn-outline-dark boton-accion" |
42 | title="Editar" | 40 | title="Editar" |
43 | ng-click="editar(chofer.id)" | 41 | ng-click="editar(chofer.id)" |
44 | > | 42 | > |
45 | <i class="fa fa-pencil"></i> | 43 | <i class="fa fa-pencil"></i> |
46 | </button> | 44 | </button> |
47 | <button | 45 | <button |
48 | class="btn btn-outline-dark boton-accion" | 46 | class="btn btn-outline-dark boton-accion" |
49 | title="Eliminar" | 47 | title="Eliminar" |
50 | ng-click="solicitarConfirmacion(chofer)" | 48 | ng-click="solicitarConfirmacion(chofer)" |
51 | > | 49 | > |
52 | <i class="fa fa-trash"></i> | 50 | <i class="fa fa-trash"></i> |
53 | </button> | 51 | </button> |
54 | </td> | 52 | </td> |
55 | </tr> | 53 | </tr> |
56 | </body> | 54 | </body> |
57 | </table> | 55 | </table> |
58 | </div> | 56 | </div> |
59 | </div> | 57 | </div> |
60 | 58 |