Commit 299f288f1d38fe403d9b0532a69e6bf23ffedc30

Authored by Luigi
1 parent 66061beaa8
Exists in master and in 2 other branches develop, lab

Boton Pausar

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