Commit 565239b5f6fbec586494fd317eee1298b52f26e1
1 parent
8fa463e44a
Exists in
master
Agregar cisterna
Showing
3 changed files
with
463 additions
and
285 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') |
2 | .controller('focaAbmVehiculosController', [ | 2 | .controller('focaAbmVehiculosController', [ |
3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', | 3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', |
4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', | 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', |
5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, |
6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { | 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { |
7 | 7 | ||
8 | $scope.now = new Date(); | 8 | $scope.now = new Date(); |
9 | $scope.botonera = [{ | 9 | $scope.botonera = [{ |
10 | label: 'Transportista', | 10 | label: 'Transportista', |
11 | image: 'cliente.png' | 11 | image: 'cliente.png' |
12 | }]; | 12 | }]; |
13 | 13 | ||
14 | focaAbmVehiculoService.cleanCisternas(); | 14 | focaAbmVehiculoService.cleanCisternas(); |
15 | 15 | ||
16 | //SETEO BOTONERA LATERAL | 16 | //SETEO BOTONERA LATERAL |
17 | focaBotoneraLateralService.showSalir(false); | 17 | focaBotoneraLateralService.showSalir(false); |
18 | focaBotoneraLateralService.showPausar(false); | 18 | focaBotoneraLateralService.showPausar(false); |
19 | focaBotoneraLateralService.showCancelar(false); | 19 | focaBotoneraLateralService.showCancelar(false); |
20 | focaBotoneraLateralService.showGuardar(false); | 20 | focaBotoneraLateralService.showGuardar(false); |
21 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 21 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
22 | 22 | ||
23 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { | 23 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { |
24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); |
25 | } | 25 | } |
26 | $scope.editar = function(id) { | 26 | $scope.editar = function(id) { |
27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); |
28 | }; | 28 | }; |
29 | $scope.solicitarConfirmacion = function(vehiculo) { | 29 | $scope.solicitarConfirmacion = function(vehiculo) { |
30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + |
31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( |
32 | function(data) { | 32 | function(data) { |
33 | if (data) { | 33 | if (data) { |
34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); |
35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
36 | } | ||
37 | } | ||
38 | ); | ||
39 | }; | ||
40 | $scope.seleccionarTransportista = function() { | ||
41 | var parametrosModal = { | ||
42 | titulo: 'Búsqueda de Transportista', | ||
43 | query: '/transportista', | ||
44 | columnas: [ | ||
45 | { | ||
46 | nombre: 'Código', | ||
47 | propiedad: 'COD' | ||
48 | }, | ||
49 | { | ||
50 | nombre: 'Nombre', | ||
51 | propiedad: 'NOM' | ||
52 | }, | ||
53 | { | ||
54 | nombre: 'CUIT', | ||
55 | propiedad: 'CUIT' | ||
36 | } | 56 | } |
57 | ] | ||
58 | }; | ||
59 | focaModalService.modal(parametrosModal).then( | ||
60 | function(transportista) { | ||
61 | elegirTransportista(transportista); | ||
62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | ||
63 | }, function() { | ||
64 | |||
37 | } | 65 | } |
38 | ); | 66 | ); |
39 | }; | ||
40 | $scope.seleccionarTransportista = function() { | ||
41 | var parametrosModal = { | ||
42 | titulo: 'Búsqueda de Transportista', | ||
43 | query: '/transportista', | ||
44 | columnas: [ | ||
45 | { | ||
46 | nombre: 'Código', | ||
47 | propiedad: 'COD' | ||
48 | }, | ||
49 | { | ||
50 | nombre: 'Nombre', | ||
51 | propiedad: 'NOM' | ||
52 | }, | ||
53 | { | ||
54 | nombre: 'CUIT', | ||
55 | propiedad: 'CUIT' | ||
56 | } | ||
57 | ] | ||
58 | }; | 67 | }; |
59 | focaModalService.modal(parametrosModal).then( | 68 | function elegirTransportista(transportista) { |
60 | function(transportista) { | 69 | var codigo = ('00000' + transportista.COD).slice(-5); |
61 | elegirTransportista(transportista); | 70 | $scope.idTransportista = transportista.COD; |
62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 71 | $scope.filtros = transportista.NOM.trim(); |
63 | }, function() { | 72 | $timeout(function() { |
64 | |||
65 | } | ||
66 | ); | ||
67 | }; | ||
68 | function elegirTransportista(transportista) { | ||
69 | var codigo = ('00000' + transportista.COD).slice(-5); | ||
70 | $scope.idTransportista = transportista.COD; | ||
71 | $scope.filtros = transportista.NOM.trim(); | ||
72 | $timeout(function() { | ||
73 | $scope.$broadcast('addCabecera', { | ||
74 | label: 'Transportista:', | ||
75 | valor: codigo + ' - ' + transportista.NOM | ||
76 | }); | ||
77 | }); | ||
78 | buscar(transportista.COD); | ||
79 | } | ||
80 | |||
81 | function buscar(idTransportista) { | ||
82 | focaAbmVehiculoService | ||
83 | .getVehiculosPorTransportista(idTransportista) | ||
84 | .then(function(datos) { | ||
85 | $scope.vehiculos = datos.data; | ||
86 | }); | ||
87 | } | ||
88 | function salir() { | ||
89 | focaAbmVehiculoService.transportistaSeleccionado = {}; | ||
90 | $location.path('/'); | ||
91 | } | ||
92 | } | ||
93 | ]) | ||
94 | .controller('focaAbmVehiculoController', [ | ||
95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | ||
96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', | ||
97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | ||
98 | focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | ||
99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | ||
100 | $scope.now = new Date(); | ||
101 | $scope.focused = 1; | ||
102 | $scope.transportistaStamp = ''; | ||
103 | $scope.cisternas = []; | ||
104 | |||
105 | $timeout(function() { | ||
106 | focaBotoneraLateralService.showSalir(false); | ||
107 | focaBotoneraLateralService.showPausar(true); | ||
108 | focaBotoneraLateralService.showCancelar(false); | ||
109 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | ||
110 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | ||
111 | }); | ||
112 | |||
113 | $timeout(function() {getLSVehiculo();}); | ||
114 | |||
115 | if ($scope.nuevo) { | ||
116 | focaAbmVehiculoService | ||
117 | .getTransportistaPorId($routeParams.idTransportista) | ||
118 | .then(function(res) { | ||
119 | var codigo = ('00000' + res.data.COD).slice(-5); | ||
120 | $scope.vehiculo.idTransportista = res.data.COD; | ||
121 | $scope.vehiculo.transportista = res.data; | ||
122 | $scope.$broadcast('addCabecera', { | 73 | $scope.$broadcast('addCabecera', { |
123 | label: 'Transportista:', | 74 | label: 'Transportista:', |
124 | valor: codigo + ' - ' + res.data.NOM | 75 | valor: codigo + ' - ' + transportista.NOM |
125 | }); | 76 | }); |
126 | }); | 77 | }); |
78 | buscar(transportista.COD); | ||
79 | } | ||
80 | |||
81 | function buscar(idTransportista) { | ||
82 | focaAbmVehiculoService | ||
83 | .getVehiculosPorTransportista(idTransportista) | ||
84 | .then(function(datos) { | ||
85 | $scope.vehiculos = datos.data; | ||
86 | }); | ||
87 | } | ||
88 | function salir() { | ||
89 | focaAbmVehiculoService.transportistaSeleccionado = {}; | ||
90 | $location.path('/'); | ||
91 | } | ||
127 | } | 92 | } |
128 | $scope.vehiculo = {}; | 93 | ]) |
129 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 94 | .controller('focaAbmVehiculoController', [ |
130 | if (res.data) { | 95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
131 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', |
132 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
98 | focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | ||
99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | ||
100 | $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; | ||
101 | $scope.now = new Date(); | ||
102 | $scope.focused = 1; | ||
103 | $scope.editando = false; | ||
104 | $scope.transportistaStamp = ''; | ||
105 | $scope.cisternas = []; | ||
133 | 106 | ||
134 | $scope.vehiculo = res.data; | 107 | $scope.cisterna = { |
135 | $scope.$broadcast('addCabecera', { | 108 | codigo: '', |
136 | label: 'Transportista:', | 109 | capacidad: '', |
137 | valor: $scope.transportistaStamp | 110 | unidadMedida: {} |
138 | }); | 111 | }; |
139 | $scope.$broadcast('addCabecera', { | 112 | |
140 | label: 'Unidad:', | 113 | $timeout(function() { |
141 | valor: res.data.codigo | 114 | focaBotoneraLateralService.showSalir(false); |
142 | }); | 115 | focaBotoneraLateralService.showPausar(true); |
116 | focaBotoneraLateralService.showCancelar(false); | ||
117 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | ||
118 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | ||
119 | }); | ||
120 | |||
121 | if ($scope.nuevo) { | ||
143 | focaAbmVehiculoService | 122 | focaAbmVehiculoService |
144 | .getCisternas($routeParams.idVehiculo) | 123 | .getTransportistaPorId($routeParams.idTransportista) |
145 | .then(function(res) { | 124 | .then(function(res) { |
146 | $scope.cisternas = res; | 125 | var codigo = ('00000' + res.data.COD).slice(-5); |
147 | $scope.$apply(); | 126 | $scope.vehiculo.idTransportista = res.data.COD; |
127 | $scope.vehiculo.transportista = res.data; | ||
128 | $scope.$broadcast('addCabecera', { | ||
129 | label: 'Transportista:', | ||
130 | valor: codigo + ' - ' + res.data.NOM | ||
131 | }); | ||
148 | }); | 132 | }); |
149 | } | 133 | } |
150 | }); | 134 | $scope.vehiculo = {}; |
151 | 135 | ||
152 | $scope.next = function(key) { | 136 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
153 | if (key === 13) $scope.focused++; | 137 | |
154 | }; | 138 | if (res.data) { |
139 | var vehiculoSeteado = getLSVehiculo(); | ||
140 | if (vehiculoSeteado === false) { | ||
141 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | ||
142 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | ||
155 | 143 | ||
156 | $scope.salir = function() { | 144 | $scope.vehiculo = res.data; |
157 | if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | 145 | $scope.$broadcast('addCabecera', { |
158 | focaModalService.confirm( | 146 | label: 'Transportista:', |
159 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 147 | valor: $scope.transportistaStamp |
160 | ).then(function(data) { | 148 | }); |
161 | if (data) { | 149 | $scope.$broadcast('addCabecera', { |
162 | $location.path('/vehiculo'); | 150 | label: 'Unidad:', |
151 | valor: res.data.codigo | ||
152 | }); | ||
163 | } | 153 | } |
154 | |||
155 | focaAbmVehiculoService | ||
156 | .getCisternas($routeParams.idVehiculo) | ||
157 | .then(function(res) { | ||
158 | $scope.cisternas = res; | ||
159 | $scope.$apply(); | ||
160 | }); | ||
161 | } | ||
162 | }); | ||
163 | |||
164 | $scope.next = function(key) { | ||
165 | if (key === 13) $scope.focused++; | ||
166 | }; | ||
167 | |||
168 | $scope.salir = function() { | ||
169 | if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | ||
170 | focaModalService.confirm( | ||
171 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | ||
172 | ).then(function(data) { | ||
173 | if (data) { | ||
174 | $location.path('/vehiculo'); | ||
175 | } | ||
176 | }); | ||
177 | } else { | ||
178 | $location.path('/vehiculo'); | ||
179 | } | ||
180 | }; | ||
181 | |||
182 | $scope.editar = function(key, cisterna) { | ||
183 | if (key === 'nuevo') { | ||
184 | $scope.editando = true; | ||
185 | } else { | ||
186 | console.log('Editar: '); | ||
187 | $scope.cisterna = cisterna; | ||
188 | $scope.editando = true; | ||
189 | } | ||
190 | }; | ||
191 | |||
192 | $scope.seleccionarUnidadMedida = function() { | ||
193 | var modalInstance = $uibModal.open( | ||
194 | { | ||
195 | ariaLabelledBy: 'Busqueda de Unidades de medida', | ||
196 | templateUrl: 'modal-unidad-medida.html', | ||
197 | controller: 'focaModalUnidadMedidaCtrl', | ||
198 | size: 'lg' | ||
199 | } | ||
200 | ); | ||
201 | modalInstance.result.then(function(unidaMedida) { | ||
202 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | ||
203 | $scope.cisterna.unidadMedida = unidaMedida; | ||
164 | }); | 204 | }); |
165 | } else { | 205 | }; |
166 | $location.path('/vehiculo'); | ||
167 | } | ||
168 | } | ||
169 | 206 | ||
170 | $scope.editar = function(key) { | 207 | $scope.guardar = function(key) { |
171 | if (key) { | 208 | |
172 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 209 | key = (typeof key === 'undefined') ? 13 : key; |
173 | '/cisterna/' + key); | ||
174 | } else { | ||
175 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | ||
176 | } | ||
177 | }; | ||
178 | $scope.guardar = function(key) { | ||
179 | 210 | ||
180 | key = (typeof key === 'undefined') ? 13 : key; | 211 | if (key === 13) { |
181 | 212 | ||
182 | if (key === 13) { | 213 | if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { |
214 | $scope.salir(); | ||
215 | return; | ||
216 | } | ||
183 | 217 | ||
184 | if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | 218 | if (!$scope.vehiculo.codigo) { |
185 | $scope.salir(); | 219 | focaModalService.alert('Ingrese unidad'); |
186 | return; | 220 | return; |
221 | } else if (!$scope.vehiculo.tractor) { | ||
222 | focaModalService.alert('Ingrese dominio tractor'); | ||
223 | return; | ||
224 | } else if (!$scope.vehiculo.semi) { | ||
225 | focaModalService.alert('Ingrese dominio semi'); | ||
226 | return; | ||
227 | } else if (!$scope.vehiculo.capacidad) { | ||
228 | focaModalService.alert('Ingrese capacidad total'); | ||
229 | return; | ||
230 | } | ||
231 | //Valida si existe numero de unidad | ||
232 | if (!validaTotalCargas() && !$scope.nuevo) { | ||
233 | focaModalService.alert('La suma de las capacidades de las cisternas' + | ||
234 | ' debe ser igual a la capacidad total del vehículo'); | ||
235 | return; | ||
236 | } | ||
237 | validaCodigoUnidad().then(function() { | ||
238 | delete $scope.vehiculo.transportista; | ||
239 | delete $scope.vehiculo.cisternas; | ||
240 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | ||
241 | .then(function(res) { | ||
242 | if ($scope.nuevo) { | ||
243 | $location.path('/vehiculo/' + res.data.id + | ||
244 | '/' + res.data.idTransportista); | ||
245 | } else { | ||
246 | guardarCisternas().then(function() { | ||
247 | $location.path('/vehiculo'); | ||
248 | }); | ||
249 | } | ||
250 | }); | ||
251 | }, function() { | ||
252 | focaModalService.alert('Código de unidad existente'); | ||
253 | }); | ||
187 | } | 254 | } |
255 | }; | ||
188 | 256 | ||
189 | if (!$scope.vehiculo.codigo) { | 257 | //Agregar propiedades de cisterna |
190 | focaModalService.alert('Ingrese unidad'); | 258 | $scope.$watch('vehiculo', function(newValue) { |
191 | return; | 259 | focaBotoneraLateralService.setPausarData({ |
192 | } else if (!$scope.vehiculo.tractor) { | 260 | label:'vehiculo', |
193 | focaModalService.alert('Ingrese dominio tractor'); | 261 | val: { |
194 | return; | 262 | codigo: newValue.codigo, |
195 | } else if (!$scope.vehiculo.semi) { | 263 | tractor: newValue.tractor, |
196 | focaModalService.alert('Ingrese dominio semi'); | 264 | semi: newValue.semi, |
197 | return; | 265 | capacidad: newValue.capacidad, |
198 | } else if (!$scope.vehiculo.capacidad) { | 266 | idVehiculo: newValue.idVehiculo, |
199 | focaModalService.alert('Ingrese capacidad total'); | 267 | idTransportista: newValue.idTransportista |
200 | return; | 268 | } |
201 | } | 269 | }); |
202 | //Valida si existe numero de unidad | 270 | }, true); |
203 | if (!validaTotalCargas() && !$scope.nuevo) { | 271 | |
204 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 272 | function getLSVehiculo() { |
205 | ' debe ser igual a la capacidad total del vehículo'); | 273 | var vehiculo = JSON.parse($localStorage.vehiculo|| null); |
206 | return; | 274 | if (vehiculo) { |
275 | setearVehiculo(vehiculo); | ||
276 | delete $localStorage.vehiculo; | ||
277 | return true; | ||
207 | } | 278 | } |
208 | validaCodigoUnidad().then(function() { | 279 | return false; |
209 | delete $scope.vehiculo.transportista; | 280 | } |
210 | delete $scope.vehiculo.cisternas; | 281 | |
211 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 282 | function setearVehiculo(vehiculo) { |
283 | $scope.vehiculo = vehiculo; | ||
284 | $scope.$broadcast('addCabecera', { | ||
285 | label: 'Vehiculo:', | ||
286 | valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | ||
287 | }); | ||
288 | } | ||
289 | |||
290 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | ||
291 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | ||
292 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | ||
293 | function(data) { | ||
294 | if (data) { | ||
295 | focaAbmVehiculoService.deleteCisterna(idx); | ||
296 | focaAbmVehiculoService | ||
297 | .getCisternas($routeParams.idVehiculo) | ||
298 | .then(function(res) { | ||
299 | $scope.cisternas = res; | ||
300 | }); | ||
301 | } | ||
302 | } | ||
303 | ); | ||
304 | }; | ||
305 | |||
306 | function validaCodigoUnidad() { | ||
307 | return new Promise(function(resolve, reject) { | ||
308 | focaAbmVehiculoService | ||
309 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | ||
212 | .then(function(res) { | 310 | .then(function(res) { |
213 | if ($scope.nuevo) { | 311 | //Valida si existe numero de unidad |
214 | $location.path('/vehiculo/' + res.data.id + | 312 | var existe = res.data.filter(function(vehiculo) { |
215 | '/' + res.data.idTransportista); | 313 | return vehiculo.codigo === $scope.vehiculo.codigo && |
314 | vehiculo.id !== $scope.vehiculo.id; | ||
315 | }); | ||
316 | |||
317 | if (existe.length) { | ||
318 | reject(existe); | ||
216 | } else { | 319 | } else { |
217 | guardarCisternas().then(function() { | 320 | resolve(); |
218 | $location.path('/vehiculo'); | ||
219 | }); | ||
220 | } | 321 | } |
221 | }); | 322 | }); |
222 | }, function() { | ||
223 | focaModalService.alert('Código de unidad existente'); | ||
224 | }); | 323 | }); |
225 | } | 324 | } |
226 | 325 | ||
227 | }; | 326 | function validaTotalCargas() { |
327 | var total = 0; | ||
328 | $scope.cisternas.forEach(function(cisterna) { | ||
329 | if (!cisterna.desactivado) { |
src/js/controllerCisterna.js
1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') |
2 | .controller('focaAbmVehiculoCisternaController', [ | 2 | .controller('focaAbmVehiculoCisternaController', [ |
3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', | 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window','$localStorage', |
5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
6 | focaModalService, focaBotoneraLateralService, $timeout, $window) { | 6 | focaModalService, focaBotoneraLateralService, $timeout, $window, $localStorage) { |
7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; | 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; |
8 | $scope.editar = false; | 8 | $scope.editar = false; |
9 | $scope.now = new Date(); | 9 | $scope.now = new Date(); |
10 | $scope.cisterna = { | 10 | $scope.cisterna = { |
11 | codigo: '', | 11 | codigo: '', |
12 | capacidad: '', | 12 | capacidad: '', |
13 | unidadMedida: {} | 13 | unidadMedida: {} |
14 | }; | 14 | }; |
15 | 15 | ||
16 | $scope.focused = $scope.nuevo ? 1 : 2; | 16 | $scope.focused = $scope.nuevo ? 1 : 2; |
17 | $scope.next = function(key) { | 17 | $scope.next = function(key) { |
18 | if (key === 13) $scope.focused++; | 18 | if (key === 13) $scope.focused++; |
19 | }; | 19 | }; |
20 | $scope.capacidadVechiulo = 0; | 20 | $scope.capacidadVechiulo = 0; |
21 | $scope.transportista = ''; | 21 | $scope.transportista = ''; |
22 | 22 | ||
23 | //SETEO BOTONERA LATERAL | 23 | //SETEO BOTONERA LATERAL |
24 | $timeout(function() { | 24 | $timeout(function() { |
25 | focaBotoneraLateralService.showSalir(false); | 25 | focaBotoneraLateralService.showSalir(false); |
26 | focaBotoneraLateralService.showPausar(true); | 26 | focaBotoneraLateralService.showPausar(true); |
27 | focaBotoneraLateralService.showCancelar(false); | 27 | focaBotoneraLateralService.showCancelar(false); |
28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
29 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | 29 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); |
30 | }); | 30 | }); |
31 | 31 | ||
32 | $timeout(function (){getLSCisterna();}); | ||
33 | |||
32 | if ($routeParams.idx !== -1) { | 34 | if ($routeParams.idx !== -1) { |
33 | $scope.cisterna = [$routeParams.idx]; | 35 | $scope.cisterna = [$routeParams.idx]; |
34 | focaAbmVehiculoService | 36 | focaAbmVehiculoService |
35 | .getCisternas($routeParams.idVehiculo) | 37 | .getCisternas($routeParams.idVehiculo) |
36 | .then(function(res) { | 38 | .then(function(res) { |
37 | $scope.cisterna = res[$routeParams.idx]; | 39 | $scope.cisterna = res[$routeParams.idx]; |
38 | }); | 40 | }); |
39 | } | 41 | } |
40 | 42 | ||
41 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 43 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
42 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 44 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); |
43 | $scope.transportista = res.data.transportista.COD; | 45 | $scope.transportista = res.data.transportista.COD; |
44 | $scope.capacidadVechiulo = res.data.capacidad; | 46 | $scope.capacidadVechiulo = res.data.capacidad; |
45 | $scope.$broadcast('addCabecera', { | 47 | $scope.$broadcast('addCabecera', { |
46 | label: 'Transportista:', | 48 | label: 'Transportista:', |
47 | valor: codigo + ' - ' + res.data.transportista.NOM | 49 | valor: codigo + ' - ' + res.data.transportista.NOM |
48 | }); | 50 | }); |
49 | $scope.$broadcast('addCabecera', { | 51 | $scope.$broadcast('addCabecera', { |
50 | label: 'Unidad:', | 52 | label: 'Unidad:', |
51 | valor: res.data.codigo | 53 | valor: res.data.codigo |
52 | }); | 54 | }); |
53 | $scope.$broadcast('addCabecera', { | 55 | $scope.$broadcast('addCabecera', { |
54 | label: 'Capacidad total vehículo:', | 56 | label: 'Capacidad total vehículo:', |
55 | valor: res.data.capacidad | 57 | valor: res.data.capacidad |
56 | }); | 58 | }); |
57 | }); | 59 | }); |
58 | 60 | ||
59 | $scope.salir = function() { | 61 | $scope.salir = function() { |
60 | 62 | ||
61 | if (!$scope.formCisterna.$pristine) { | 63 | if (!$scope.formCisterna.$pristine) { |
62 | focaModalService.confirm( | 64 | focaModalService.confirm( |
63 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 65 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
64 | ).then(function(data) { | 66 | ).then(function(data) { |
65 | if (data) { | 67 | if (data) { |
66 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + | 68 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + |
67 | $scope.transportista); | 69 | $scope.transportista); |
68 | } | 70 | } |
69 | }); | 71 | }); |
70 | } else { | 72 | } else { |
71 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + | 73 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + |
72 | $scope.transportista); | 74 | $scope.transportista); |
73 | } | 75 | } |
74 | }; | 76 | }; |
75 | 77 | ||
76 | $scope.guardar = function() { | 78 | $scope.guardar = function() { |
77 | 79 | ||
78 | if ($scope.formCisterna.$pristine) { | 80 | if ($scope.formCisterna.$pristine) { |
79 | $scope.salir(); | 81 | $scope.salir(); |
80 | return; | 82 | return; |
81 | } else if (!$scope.cisterna.codigo) { | 83 | } else if (!$scope.cisterna.codigo) { |
82 | focaModalService.alert('Ingrese codigo de cisterna'); | 84 | focaModalService.alert('Ingrese codigo de cisterna'); |
83 | return; | 85 | return; |
84 | } else if (!$scope.cisterna.capacidad) { | 86 | } else if (!$scope.cisterna.capacidad) { |
85 | focaModalService.alert('Ingrese capacidad'); | 87 | focaModalService.alert('Ingrese capacidad'); |
86 | return; | 88 | return; |
87 | } else if (!$scope.cisterna.idUnidadMedida) { | 89 | } else if (!$scope.cisterna.idUnidadMedida) { |
88 | focaModalService.alert('Ingrese unidad de medida'); | 90 | focaModalService.alert('Ingrese unidad de medida'); |
89 | return; | 91 | return; |
90 | } | 92 | } |
91 | 93 | ||
92 | validaCodigo() | 94 | validaCodigo() |
93 | .then(function() { | 95 | .then(function() { |
94 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 96 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); |
95 | delete $scope.cisterna.vehiculo; | 97 | delete $scope.cisterna.vehiculo; |
96 | 98 | ||
97 | focaAbmVehiculoService | 99 | focaAbmVehiculoService |
98 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 100 | .guardarCisterna($scope.cisterna, $routeParams.idx); |
99 | 101 | ||
100 | $timeout(function() { | 102 | $timeout(function() { |
101 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 103 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
102 | '/' + $scope.transportista); | 104 | '/' + $scope.transportista); |
103 | }, 0); | 105 | }, 0); |
104 | }, function(err) { | 106 | }, function(err) { |
105 | focaModalService.alert(err); | 107 | focaModalService.alert(err); |
106 | }); | 108 | }); |
107 | 109 | ||
108 | }; | 110 | }; |
109 | 111 | ||
110 | $scope.seleccionarUnidadMedida = function() { | 112 | $scope.seleccionarUnidadMedida = function() { |
111 | var modalInstance = $uibModal.open( | 113 | var modalInstance = $uibModal.open( |
112 | { | 114 | { |
113 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 115 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
114 | templateUrl: 'modal-unidad-medida.html', | 116 | templateUrl: 'modal-unidad-medida.html', |
115 | controller: 'focaModalUnidadMedidaCtrl', | 117 | controller: 'focaModalUnidadMedidaCtrl', |
116 | size: 'lg' | 118 | size: 'lg' |
117 | } | 119 | } |
118 | ); | 120 | ); |
119 | modalInstance.result.then(function(unidaMedida) { | 121 | modalInstance.result.then(function(unidaMedida) { |
120 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 122 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
121 | $scope.cisterna.unidadMedida = unidaMedida; | 123 | $scope.cisterna.unidadMedida = unidaMedida; |
122 | }); | 124 | }); |
123 | }; | 125 | }; |
124 | 126 | ||
127 | $scope.$watch('cisterna', function(newValue) { | ||
128 | focaBotoneraLateralService.setPausarData({ | ||
129 | label:'cisterna', | ||
130 | val: newValue | ||
131 | }); | ||
132 | }, true); | ||
133 | |||
134 | function getLSCisterna() { | ||
135 | var cisterna = JSON.parse($localStorage.cisterna|| null); | ||
136 | if (cisterna) { | ||
137 | setearVehiculo(cisterna); | ||
138 | delete $localStorage.cisterna; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | function setearVehiculo(cisterna) { | ||
143 | $scope.cisterna = cisterna; | ||
144 | $scope.$broadcast('addCabecera', { | ||
145 | label: 'Codigo de Cisterna:', | ||
146 | valor: cisterna.codigo | ||
147 | }); | ||
148 | } | ||
149 | |||
125 | function validaCodigo() { | 150 | function validaCodigo() { |
126 | return new Promise(function(resolve, reject) { | 151 | return new Promise(function(resolve, reject) { |
127 | focaAbmVehiculoService | 152 | focaAbmVehiculoService |
128 | .getCisternas($routeParams.idVehiculo) | 153 | .getCisternas($routeParams.idVehiculo) |
129 | .then(function(res) { | 154 | .then(function(res) { |
130 | var cisternas = res; | 155 | var cisternas = res; |
131 | var totalCargado = 0; | 156 | var totalCargado = 0; |
132 | cisternas.forEach(function(cisterna, idx) { | 157 | cisternas.forEach(function(cisterna, idx) { |
133 | //SI EL CODIGO YA EXISTE | 158 | //SI EL CODIGO YA EXISTE |
134 | if (cisterna.codigo === $scope.cisterna.codigo && | 159 | if (cisterna.codigo === $scope.cisterna.codigo && |
135 | idx != $routeParams.idx && | 160 | idx != $routeParams.idx && |
136 | !cisterna.desactivado) { | 161 | !cisterna.desactivado) { |
137 | reject('Código de cisterna existente'); | 162 | reject('Código de cisterna existente'); |
138 | } | 163 | } |
139 | if (idx !== $routeParams.idx && | 164 | if (idx !== $routeParams.idx && |
140 | !cisterna.desactivado) { | 165 | !cisterna.desactivado) { |
141 | totalCargado += cisterna.capacidad; | 166 | totalCargado += cisterna.capacidad; |
142 | } | 167 | } |
143 | }); | 168 | }); |
144 | resolve(); | 169 | resolve(); |
145 | }); | 170 | }); |
146 | }); | 171 | }); |
147 | } | 172 | } |
148 | } | 173 | } |
149 | ]); | 174 | ]); |
150 | 175 |
src/views/foca-abm-vehiculos-item.html
1 | <div class="row"> | 1 | <div class="row"> |
2 | <foca-cabecera-facturador | 2 | <foca-cabecera-facturador |
3 | titulo="'Vehículo'" | 3 | titulo="'Vehículo'" |
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 | <form name="formVehiculo" class="px-3"> | 10 | <form name="formVehiculo" class="px-3"> |
11 | <input type="hidden" name="id" ng-model="sector.id" /> | 11 | <input type="hidden" name="id" ng-model="sector.id" /> |
12 | <div class="row mt-3"> | 12 | <div class="row mt-3"> |
13 | <div class="form-group d-flex mb-2 col-md-6"> | 13 | <div class="form-group d-flex mb-2 col-md-6"> |
14 | <label class="col-form-label col-md-4">Unidad</label> | 14 | <label class="col-form-label col-md-4">Unidad</label> |
15 | <div class="input-group col-md-8 pl-0"> | 15 | <div class="input-group col-md-8 pl-0"> |
16 | <input | 16 | <input |
17 | class="form-control" | 17 | class="form-control" |
18 | type="text" | 18 | type="text" |
19 | teclado-virtual | 19 | teclado-virtual |
20 | ng-model="vehiculo.codigo" | 20 | ng-model="vehiculo.codigo" |
21 | foca-focus="focused == 1" | 21 | foca-focus="focused == 1" |
22 | ng-focus="focused = 1" | 22 | ng-focus="focused = 1" |
23 | ng-keypress="next($event.keyCode)" | 23 | ng-keypress="next($event.keyCode)" |
24 | ng-disabled="!nuevo" | 24 | ng-disabled="!nuevo" |
25 | /> | 25 | /> |
26 | </div> | 26 | </div> |
27 | </div> | 27 | </div> |
28 | <div class="form-group d-flex mb-2 col-md-6"> | 28 | <div class="form-group d-flex mb-2 col-md-6"> |
29 | <label class="col-form-label col-md-4">Dominio tractor</label> | 29 | <label class="col-form-label col-md-4">Dominio tractor</label> |
30 | <div class="input-group col-md-8 pl-0"> | 30 | <div class="input-group col-md-8 pl-0"> |
31 | <input | 31 | <input |
32 | class="form-control" | 32 | class="form-control" |
33 | type="text" | 33 | type="text" |
34 | teclado-virtual | 34 | teclado-virtual |
35 | ng-model="vehiculo.tractor" | 35 | ng-model="vehiculo.tractor" |
36 | ng-required="true" | 36 | ng-required="true" |
37 | foca-focus="focused == 2" | 37 | foca-focus="focused == 2" |
38 | ng-focus="focused = 2" | 38 | ng-focus="focused = 2" |
39 | ng-keypress="next($event.keyCode)" | 39 | ng-keypress="next($event.keyCode)" |
40 | /> | 40 | /> |
41 | </div> | 41 | </div> |
42 | </div> | 42 | </div> |
43 | <div class="form-group d-flex mb-2 col-md-6"> | 43 | <div class="form-group d-flex mb-2 col-md-6"> |
44 | <label class="col-form-label col-md-4">Dominio semi</label> | 44 | <label class="col-form-label col-md-4">Dominio semi</label> |
45 | <div class="input-group col-md-8 pl-0"> | 45 | <div class="input-group col-md-8 pl-0"> |
46 | <input | 46 | <input |
47 | class="form-control" | 47 | class="form-control" |
48 | type="text" | 48 | type="text" |
49 | teclado-virtual | 49 | teclado-virtual |
50 | ng-model="vehiculo.semi" | 50 | ng-model="vehiculo.semi" |
51 | ng-required="true" | 51 | ng-required="true" |
52 | foca-focus="focused == 3" | 52 | foca-focus="focused == 3" |
53 | ng-focus="focused = 3" | 53 | ng-focus="focused = 3" |
54 | ng-keypress="next($event.keyCode)" | 54 | ng-keypress="next($event.keyCode)" |
55 | /> | 55 | /> |
56 | </div> | 56 | </div> |
57 | </div> | 57 | </div> |
58 | <div class="form-group d-flex mb-2 col-md-6"> | 58 | <div class="form-group d-flex mb-2 col-md-6"> |
59 | <label class="col-form-label col-md-4">Capacidad total</label> | 59 | <label class="col-form-label col-md-4">Capacidad total</label> |
60 | <div class="input-group col-md-8 pl-0"> | 60 | <div class="input-group col-md-8 pl-0"> |
61 | <input | 61 | <input |
62 | class="form-control" | 62 | class="form-control" |
63 | type="text" | 63 | type="text" |
64 | teclado-virtual | 64 | teclado-virtual |
65 | ng-model="vehiculo.capacidad" | 65 | ng-model="vehiculo.capacidad" |
66 | ng-required="true" | 66 | ng-required="true" |
67 | foca-focus="focused == 4" | 67 | foca-focus="focused == 4" |
68 | ng-focus="focused = 4" | 68 | ng-focus="focused = 4" |
69 | ng-keypress="guardar($event.keyCode)" | 69 | ng-keypress="guardar($event.keyCode)" |
70 | /> | 70 | /> |
71 | </div> | 71 | </div> |
72 | </div> | 72 | </div> |
73 | </div> | 73 | </div> |
74 | </form> | 74 | </form> |
75 | <div ng-show="!nuevo"> | 75 | <div ng-show="!nuevo"> |
76 | <h5 class="pl-4 table-title">Cisternas</h5> | 76 | <h5 class="pl-4 table-title">Cisternas</h5> |
77 | <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> | 77 | <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> |
78 | <thead> | 78 | <thead> |
79 | <tr> | 79 | <tr> |
80 | <th class="px-5">Código</th> | 80 | <th class="text-center px-4">Código</th> |
81 | <th class="text-right px-5">Capacidad</th> | 81 | <th class="text-center">Capacidad</th> |
82 | <th class="text-center px-4"> | 82 | <th class="text-center">Unidad de Medida</th> |
83 | <th class="text-center"> | ||
83 | <button | 84 | <button |
84 | class="btn btn-outline-debo boton-accion" | 85 | class="btn btn-outline-debo boton-accion" |
85 | title="Agregar" | 86 | title="Agregar" |
86 | ng-click="editar(-1)"> | 87 | ng-click="editar('nuevo')"> |
87 | <i class="fa fa-plus"></i> | 88 | <i class="fa fa-plus"></i> |
88 | </button> | 89 | </button> |
89 | </th> | 90 | </th> |
90 | </tr> | 91 | </tr> |
91 | </thead> | 92 | </thead> |
92 | <tbody> | 93 | <tbody> |
94 | <tr ng-show="editando"> | ||
95 | <td align="center"> | ||
96 | <input | ||
97 | class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | ||
98 | ng-model="cisterna.codigo" | ||
99 | ng-keypress="next($event.keyCode)" | ||
100 | foca-focus="focused == 1" | ||
101 | ng-focus="focused = 1" | ||
102 | ng-disabled="!nuevoCisterna" | ||
103 | teclado-virtual | ||
104 | > | ||
105 | </td> | ||
106 | <td align="center"> | ||
107 | <input | ||
108 | class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | ||
109 | teclado-virtual | ||
110 | foca-tipo-input | ||
111 | ng-model="cisterna.capacidad" | ||
112 | ng-required="true" | ||
113 | ng-keypress="next($event.keyCode)" | ||
114 | foca-focus="focused == 2" | ||
115 | ng-focus="focused = 2" | ||
116 | > | ||
117 | </td> | ||
118 | <td align="center"> | ||
119 | <div class="input-group"> | ||
120 | <input | ||
121 | ng-model="cisterna.unidadMedida.NOM" | ||
122 | class="form-control" | ||
123 | readonly | ||
124 | /> | ||
125 | <div class="input-group-append"> | ||
126 | <button | ||
127 | ladda="searchLoading" | ||
128 | class="btn btn-outline-secondary form-control" | ||
129 | type="button" | ||
130 | ng-click="seleccionarUnidadMedida()" | ||
131 | foca-focus="focused == 3" | ||
132 | > | ||
133 | <i class="fa fa-search" aria-hidden="true"></i> | ||
134 | </button> | ||
135 | </div> | ||
136 | </div> | ||
137 | </td> | ||
138 | <td align="center"> | ||
139 | <button | ||
140 | class="btn btn-outline-dark boton-accion" | ||
141 | ng-click="guardarCisterna()" | ||
142 | > | ||
143 | <i class="fa fa-save"></i> | ||
144 | </button> | ||
145 | </td> | ||
146 | </tr> | ||
147 | |||
93 | <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" | 148 | <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" |
94 | ng-show="!cisterna.desactivado"> | 149 | ng-show="!cisterna.desactivado"> |
95 | <td ng-bind="cisterna.codigo" class="px-5"></td> | 150 | <td ng-bind="cisterna.codigo" class="text-center"></td> |
96 | <td ng-bind="cisterna.capacidad + ' ' + cisterna.unidadMedida.NOM" class="text-right px-5"></td> | 151 | <td ng-bind="cisterna.capacidad" class="text-center"></td> |
97 | <td class="text-center px-4"> | 152 | <td ng-bind="cisterna.unidadMedida.NOM" class="text-center"></td> |
153 | <td class="text-center"> | ||
98 | <button | 154 | <button |
99 | class="btn btn-outline-dark boton-accion" | 155 | class="btn btn-outline-dark boton-accion" |
100 | title="Editar" | 156 | title="Editar" |
101 | ng-click="editar(key)" | 157 | ng-click="editar('',cisterna)" |
102 | > | 158 | > |
103 | <i class="fa fa-pencil"></i> | 159 | <i class="fa fa-pencil"></i> |
104 | </button> | 160 | </button> |
105 | <button | 161 | <button |
106 | class="btn btn-outline-dark boton-accion" | 162 | class="btn btn-outline-dark boton-accion" |
107 | title="Eliminar" | 163 | title="Eliminar" |
108 | ng-click="solicitarConfirmacionCisterna(cisterna, key)" | 164 | ng-click="solicitarConfirmacionCisterna(cisterna, key)" |
109 | > | 165 | > |
110 | <i class="fa fa-trash"></i> | 166 | <i class="fa fa-trash"></i> |
111 | </button> | 167 | </button> |
112 | </td> | 168 | </td> |
113 | </tr> | 169 | </tr> |
114 | </body> | 170 | </body> |
115 | </table> | 171 | </table> |
116 | </div> | 172 | </div> |
117 | </div> | 173 | </div> |
118 | </div> | 174 | </div> |
119 | 175 |