Commit 627479f5e2bf5f7af34a4867ae0706d7257ae411
1 parent
8cb24dc5b7
Exists in
master
and in
1 other branch
Boton Cancelar Vehiculo - Cisterna
Showing
2 changed files
with
130 additions
and
34 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', | 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', |
5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, |
6 | $uibModal, focaBotoneraLateralService, $timeout) { | 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 ($localStorage.vehiculo) { |
24 | var vehiculo = JSON.parse($localStorage.vehiculo); | ||
25 | if (!vehiculo.idVehiculo) { vehiculo.idVehiculo = 0; } | ||
26 | $location.path('/vehiculo/' + vehiculo.idVehiculo + '/' + vehiculo.idTransportista); | ||
27 | } | ||
28 | |||
29 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { | ||
24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 30 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); |
25 | } | 31 | } |
26 | $scope.editar = function(id) { | 32 | $scope.editar = function(id) { |
27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 33 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); |
28 | }; | 34 | }; |
29 | $scope.solicitarConfirmacion = function(vehiculo) { | 35 | $scope.solicitarConfirmacion = function(vehiculo) { |
30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 36 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + |
31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 37 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( |
32 | function(data) { | 38 | function(data) { |
33 | if(data) { | 39 | if(data) { |
34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 40 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); |
35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 41 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
36 | } | 42 | } |
37 | } | 43 | } |
38 | ); | 44 | ); |
39 | }; | 45 | }; |
40 | $scope.seleccionarTransportista = function() { | 46 | $scope.seleccionarTransportista = function() { |
41 | var parametrosModal = { | 47 | var parametrosModal = { |
42 | titulo: 'Búsqueda de Transportista', | 48 | titulo: 'Búsqueda de Transportista', |
43 | query: '/transportista', | 49 | query: '/transportista', |
44 | columnas: [ | 50 | columnas: [ |
45 | { | 51 | { |
46 | nombre: 'Código', | 52 | nombre: 'Código', |
47 | propiedad: 'COD' | 53 | propiedad: 'COD' |
48 | }, | 54 | }, |
49 | { | 55 | { |
50 | nombre: 'Nombre', | 56 | nombre: 'Nombre', |
51 | propiedad: 'NOM' | 57 | propiedad: 'NOM' |
52 | }, | 58 | }, |
53 | { | 59 | { |
54 | nombre: 'CUIT', | 60 | nombre: 'CUIT', |
55 | propiedad: 'CUIT' | 61 | propiedad: 'CUIT' |
56 | } | 62 | } |
57 | ] | 63 | ] |
58 | }; | 64 | }; |
59 | focaModalService.modal(parametrosModal).then( | 65 | focaModalService.modal(parametrosModal).then( |
60 | function(transportista) { | 66 | function(transportista) { |
61 | elegirTransportista(transportista); | 67 | elegirTransportista(transportista); |
62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 68 | focaAbmVehiculoService.transportistaSeleccionado = transportista; |
63 | }, function() { | 69 | }, function() { |
64 | 70 | ||
65 | } | 71 | } |
66 | ); | 72 | ); |
67 | }; | 73 | }; |
68 | function elegirTransportista(transportista) { | 74 | function elegirTransportista(transportista) { |
69 | var codigo = ('00000' + transportista.COD).slice(-5); | 75 | var codigo = ('00000' + transportista.COD).slice(-5); |
70 | $scope.idTransportista = transportista.COD; | 76 | $scope.idTransportista = transportista.COD; |
71 | $scope.filtros = transportista.NOM.trim(); | 77 | $scope.filtros = transportista.NOM.trim(); |
72 | $timeout(function() { | 78 | $timeout(function() { |
73 | $scope.$broadcast('addCabecera', { | 79 | $scope.$broadcast('addCabecera', { |
74 | label: 'Transportista:', | 80 | label: 'Transportista:', |
75 | valor: codigo + ' - ' + transportista.NOM | 81 | valor: codigo + ' - ' + transportista.NOM |
76 | }); | 82 | }); |
77 | }); | 83 | }); |
78 | buscar(transportista.COD); | 84 | buscar(transportista.COD); |
79 | } | 85 | } |
80 | 86 | ||
81 | function buscar(idTransportista) { | 87 | function buscar(idTransportista) { |
82 | focaAbmVehiculoService | 88 | focaAbmVehiculoService |
83 | .getVehiculosPorTransportista(idTransportista) | 89 | .getVehiculosPorTransportista(idTransportista) |
84 | .then(function(datos) { | 90 | .then(function(datos) { |
85 | $scope.vehiculos = datos.data; | 91 | $scope.vehiculos = datos.data; |
86 | }); | 92 | }); |
87 | } | 93 | } |
88 | function salir() { | 94 | function salir() { |
89 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 95 | focaAbmVehiculoService.transportistaSeleccionado = {}; |
90 | $location.path('/'); | 96 | $location.path('/'); |
91 | } | 97 | } |
92 | } | 98 | } |
93 | ]) | 99 | ]) |
94 | .controller('focaAbmVehiculoController', [ | 100 | .controller('focaAbmVehiculoController', [ |
95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 101 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', | 102 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', '$localStorage', '$filter', |
97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 103 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
98 | focaModalService, $timeout, focaBotoneraLateralService, $window) { | 104 | focaModalService, $timeout, focaBotoneraLateralService, $window, $localStorage, $filter) { |
99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 105 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
100 | $scope.now = new Date(); | 106 | $scope.now = new Date(); |
101 | $scope.focused = 1; | 107 | $scope.focused = 1; |
102 | $scope.transportistaStamp = ''; | 108 | $scope.transportistaStamp = ''; |
103 | $scope.cisternas = []; | 109 | $scope.cisternas = []; |
104 | 110 | ||
105 | $timeout(function() { | 111 | $timeout(function() { |
106 | focaBotoneraLateralService.showSalir(false); | 112 | focaBotoneraLateralService.showSalir(false); |
107 | focaBotoneraLateralService.showPausar(false); | 113 | focaBotoneraLateralService.showPausar(true); |
108 | focaBotoneraLateralService.showCancelar(false); | 114 | focaBotoneraLateralService.showCancelar(false); |
109 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 115 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
110 | focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); | 116 | focaBotoneraLateralService.addCustomButton('Cancelar', cancelar); |
111 | }); | 117 | }); |
118 | |||
119 | $timeout(function() {getLSVehiculo();}); | ||
112 | 120 | ||
113 | if($scope.nuevo) { | 121 | if ($scope.nuevo) { |
114 | focaAbmVehiculoService | 122 | focaAbmVehiculoService |
115 | .getTransportistaPorId($routeParams.idTransportista) | 123 | .getTransportistaPorId($routeParams.idTransportista) |
116 | .then(function(res) { | 124 | .then(function(res) { |
117 | var codigo = ('00000' + res.data.COD).slice(-5); | 125 | var codigo = ('00000' + res.data.COD).slice(-5); |
118 | $scope.vehiculo.idTransportista = res.data.COD; | 126 | $scope.vehiculo.idTransportista = res.data.COD; |
119 | $scope.vehiculo.transportista = res.data; | 127 | $scope.vehiculo.transportista = res.data; |
120 | $scope.$broadcast('addCabecera', { | 128 | $scope.$broadcast('addCabecera', { |
121 | label: 'Transportista:', | 129 | label: 'Transportista:', |
122 | valor: codigo + ' - ' + res.data.NOM | 130 | valor: codigo + ' - ' + res.data.NOM |
123 | }); | 131 | }); |
124 | }); | 132 | }); |
125 | } | 133 | } |
126 | $scope.vehiculo = {}; | 134 | $scope.vehiculo = {}; |
127 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 135 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
128 | if(res.data) { | 136 | if (res.data) { |
129 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 137 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); |
130 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 138 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; |
131 | 139 | ||
132 | $scope.vehiculo = res.data; | 140 | $scope.vehiculo = res.data; |
133 | $scope.$broadcast('addCabecera', { | 141 | $scope.$broadcast('addCabecera', { |
134 | label: 'Transportista:', | 142 | label: 'Transportista:', |
135 | valor: $scope.transportistaStamp | 143 | valor: $scope.transportistaStamp |
136 | }); | 144 | }); |
137 | $scope.$broadcast('addCabecera', { | 145 | $scope.$broadcast('addCabecera', { |
138 | label: 'Unidad:', | 146 | label: 'Unidad:', |
139 | valor: res.data.codigo | 147 | valor: res.data.codigo |
140 | }); | 148 | }); |
141 | focaAbmVehiculoService | 149 | focaAbmVehiculoService |
142 | .getCisternas($routeParams.idVehiculo) | 150 | .getCisternas($routeParams.idVehiculo) |
143 | .then(function(res) { | 151 | .then(function(res) { |
144 | $scope.cisternas = res; | 152 | $scope.cisternas = res; |
145 | $scope.$apply(); | 153 | $scope.$apply(); |
146 | }); | 154 | }); |
147 | } | 155 | } |
148 | }); | 156 | }); |
149 | 157 | ||
150 | $scope.next = function(key) { | 158 | $scope.next = function(key) { |
151 | if (key === 13) $scope.focused++; | 159 | if (key === 13) $scope.focused++; |
152 | }; | 160 | }; |
153 | $scope.cancelar = function() { | 161 | |
154 | $location.path('/vehiculo'); | 162 | function cancelar() { |
155 | }; | 163 | if ($scope.formVehiculo.$pristine == false) { |
164 | focaModalService.confirm( | ||
165 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | ||
166 | ).then(function(data) { | ||
167 | if (data) { | ||
168 | $location.path('/vehiculo'); | ||
169 | } | ||
170 | }); | ||
171 | } else { | ||
172 | $location.path('/vehiculo'); | ||
173 | } | ||
174 | } | ||
175 | |||
156 | $scope.editar = function(key) { | 176 | $scope.editar = function(key) { |
157 | if (key) { | 177 | if (key) { |
158 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 178 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
159 | '/cisterna/' + key); | 179 | '/cisterna/' + key); |
160 | } else { | 180 | } else { |
161 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 181 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); |
162 | } | 182 | } |
163 | }; | 183 | }; |
164 | $scope.guardar = function(key) { | 184 | $scope.guardar = function(key) { |
165 | 185 | ||
166 | if (!$scope.vehiculo.codigo) { | ||
167 | focaModalService.alert('Ingrese unidad'); | ||
168 | return; | ||
169 | } else if (!$scope.vehiculo.tractor) { | ||
170 | focaModalService.alert('Ingrese dominio tractor'); | ||
171 | return; | ||
172 | } else if (!$scope.vehiculo.semi) { | ||
173 | focaModalService.alert('Ingrese dominio semi'); | ||
174 | return; | ||
175 | } else if (!$scope.vehiculo.capacidad) { | ||
176 | focaModalService.alert('Ingrse capacidad total'); | ||
177 | return; | ||
178 | } | ||
179 | |||
180 | |||
181 | key = (typeof key === 'undefined') ? 13 : key; | 186 | key = (typeof key === 'undefined') ? 13 : key; |
187 | |||
182 | if (key === 13) { | 188 | if (key === 13) { |
189 | if (!$scope.vehiculo.codigo) { | ||
190 | focaModalService.alert('Ingrese unidad'); | ||
191 | return; | ||
192 | } else if (!$scope.vehiculo.tractor) { | ||
193 | focaModalService.alert('Ingrese dominio tractor'); | ||
194 | return; | ||
195 | } else if (!$scope.vehiculo.semi) { | ||
196 | focaModalService.alert('Ingrese dominio semi'); | ||
197 | return; | ||
198 | } else if (!$scope.vehiculo.capacidad) { | ||
199 | focaModalService.alert('Ingrese capacidad total'); | ||
200 | return; | ||
201 | } | ||
183 | //Valida si existe numero de unidad | 202 | //Valida si existe numero de unidad |
184 | if(!validaTotalCargas() && !$scope.nuevo) { | 203 | if (!validaTotalCargas() && !$scope.nuevo) { |
185 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 204 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
186 | ' debe ser igual a la capacidad total del vehículo'); | 205 | ' debe ser igual a la capacidad total del vehículo'); |
187 | return; | 206 | return; |
188 | } | 207 | } |
189 | validaCodigoUnidad().then(function() { | 208 | validaCodigoUnidad().then(function() { |
190 | delete $scope.vehiculo.transportista; | 209 | delete $scope.vehiculo.transportista; |
191 | delete $scope.vehiculo.cisternas; | 210 | delete $scope.vehiculo.cisternas; |
192 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 211 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) |
193 | .then(function(res) { | 212 | .then(function(res) { |
194 | if ($scope.nuevo) { | 213 | if ($scope.nuevo) { |
195 | $location.path('/vehiculo/' + res.data.id + | 214 | $location.path('/vehiculo/' + res.data.id + |
196 | '/' + res.data.idTransportista); | 215 | '/' + res.data.idTransportista); |
197 | } else { | 216 | } else { |
198 | guardarCisternas().then(function() { | 217 | guardarCisternas().then(function() { |
199 | $location.path('/vehiculo'); | 218 | $location.path('/vehiculo'); |
200 | }); | 219 | }); |
201 | } | 220 | } |
202 | }); | 221 | }); |
203 | }, function() { | 222 | }, function() { |
204 | focaModalService.alert('Código de unidad existente'); | 223 | focaModalService.alert('Código de unidad existente'); |
205 | }); | 224 | }); |
206 | } | 225 | } |
207 | 226 | ||
208 | }; | 227 | }; |
228 | |||
229 | $scope.$watch('vehiculo', function(newValue) { | ||
230 | focaBotoneraLateralService.setPausarData({ | ||
231 | label:'vehiculo', | ||
232 | val: { | ||
233 | codigo: newValue.codigo, | ||
234 | tractor: newValue.tractor, | ||
235 | semi: newValue.semi, | ||
236 | capacidad: newValue.capacidad, | ||
237 | idVehiculo: newValue.idVehiculo, | ||
238 | idTransportista: newValue.idTransportista | ||
239 | } | ||
240 | }); | ||
241 | }, true); | ||
242 | |||
243 | function getLSVehiculo() { | ||
244 | var vehiculo = JSON.parse($localStorage.vehiculo|| null); | ||
245 | if (vehiculo) { | ||
246 | setearVehiculo(vehiculo); | ||
247 | delete $localStorage.vehiculo; | ||
248 | } | ||
249 | } | ||
250 | |||
251 | function setearVehiculo(vehiculo) { | ||
252 | $scope.vehiculo = vehiculo; | ||
253 | $scope.$broadcast('addCabecera', { | ||
254 | label: 'Vehiculo:', | ||
255 | valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | ||
256 | }); | ||
257 | } | ||
258 | |||
209 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 259 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { |
210 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 260 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + |
211 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 261 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( |
212 | function(data) { | 262 | function(data) { |
213 | if(data) { | 263 | if (data) { |
214 | focaAbmVehiculoService.deleteCisterna(idx); | 264 | focaAbmVehiculoService.deleteCisterna(idx); |
215 | focaAbmVehiculoService | 265 | focaAbmVehiculoService |
216 | .getCisternas($routeParams.idVehiculo) | 266 | .getCisternas($routeParams.idVehiculo) |
217 | .then(function(res) { | 267 | .then(function(res) { |
218 | $scope.cisternas = res; | 268 | $scope.cisternas = res; |
219 | }); | 269 | }); |
220 | } | 270 | } |
221 | } | 271 | } |
222 | ); | 272 | ); |
223 | }; | 273 | }; |
224 | 274 | ||
225 | function validaCodigoUnidad() { | 275 | function validaCodigoUnidad() { |
226 | return new Promise(function(resolve, reject) { | 276 | return new Promise(function(resolve, reject) { |
227 | focaAbmVehiculoService | 277 | focaAbmVehiculoService |
228 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 278 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) |
229 | .then(function(res) { | 279 | .then(function(res) { |
230 | //Valida si existe numero de unidad | 280 | //Valida si existe numero de unidad |
231 | var existe = res.data.filter(function(vehiculo) { | 281 | var existe = res.data.filter(function(vehiculo) { |
232 | return vehiculo.codigo === $scope.vehiculo.codigo && | 282 | return vehiculo.codigo === $scope.vehiculo.codigo && |
233 | vehiculo.id !== $scope.vehiculo.id; | 283 | vehiculo.id !== $scope.vehiculo.id; |
234 | }); | 284 | }); |
235 | 285 | ||
236 | if(existe.length) { | 286 | if(existe.length) { |
237 | reject(existe); | 287 | reject(existe); |
238 | }else { | 288 | }else { |
239 | resolve(); | 289 | resolve(); |
240 | } | 290 | } |
241 | }); | 291 | }); |
242 | }); | 292 | }); |
243 | } | 293 | } |
244 | 294 | ||
245 | function validaTotalCargas() { | 295 | function validaTotalCargas() { |
246 | var total = 0; | 296 | var total = 0; |
247 | $scope.cisternas.forEach(function(cisterna) { | 297 | $scope.cisternas.forEach(function(cisterna) { |
248 | if(!cisterna.desactivado) { | 298 | if(!cisterna.desactivado) { |
249 | total += parseInt(cisterna.capacidad); | 299 | total += parseInt(cisterna.capacidad); |
250 | } | 300 | } |
251 | }); | 301 | }); |
252 | return $scope.vehiculo.capacidad == total; | 302 | return $scope.vehiculo.capacidad == total; |
253 | } | 303 | } |
254 | 304 | ||
255 | function guardarCisternas() { | 305 | function guardarCisternas() { |
256 | var cisternas = $scope.cisternas.map(function(cisterna) { | 306 | var cisternas = $scope.cisternas.map(function(cisterna) { |
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','$localStorage', '$filter', |
5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
6 | focaModalService, focaBotoneraLateralService, $timeout, $window) { | 6 | focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { |
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(false); | 26 | focaBotoneraLateralService.showPausar(true); |
27 | focaBotoneraLateralService.showCancelar(true); | 27 | focaBotoneraLateralService.showCancelar(false); |
28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
29 | focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); | ||
29 | }); | 30 | }); |
30 | 31 | ||
32 | // $timeout(function() {getLSCisterna();}); | ||
33 | |||
34 | // if ($localStorage.cisterna) { | ||
35 | // var cisterna = JSON.parse($localStorage.cisterna); | ||
36 | // console.log('Cisterna datos: ' ,cisterna); | ||
37 | // if (!cisterna.codigo) { cisterna.idcisterna = 0; } | ||
38 | // $location.path('/vehiculo/' + vehiculo.idVehiculo + '/cisterna/'); | ||
39 | // } | ||
40 | |||
31 | if ($routeParams.idx != -1) { | 41 | if ($routeParams.idx != -1) { |
32 | 42 | ||
33 | $scope.cisterna = [$routeParams.idx]; | 43 | $scope.cisterna = [$routeParams.idx]; |
34 | focaAbmVehiculoService | 44 | focaAbmVehiculoService |
35 | .getCisternas($routeParams.idVehiculo) | 45 | .getCisternas($routeParams.idVehiculo) |
36 | .then(function(res) { | 46 | .then(function(res) { |
37 | $scope.cisterna = res[$routeParams.idx]; | 47 | $scope.cisterna = res[$routeParams.idx]; |
38 | }); | 48 | }); |
39 | } | 49 | } |
40 | 50 | ||
41 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 51 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
42 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 52 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); |
43 | $scope.transportista = res.data.transportista.COD; | 53 | $scope.transportista = res.data.transportista.COD; |
44 | $scope.capacidadVechiulo = res.data.capacidad; | 54 | $scope.capacidadVechiulo = res.data.capacidad; |
45 | $scope.$broadcast('addCabecera', { | 55 | $scope.$broadcast('addCabecera', { |
46 | label: 'Transportista:', | 56 | label: 'Transportista:', |
47 | valor: codigo + ' - ' + res.data.transportista.NOM | 57 | valor: codigo + ' - ' + res.data.transportista.NOM |
48 | }); | 58 | }); |
49 | $scope.$broadcast('addCabecera', { | 59 | $scope.$broadcast('addCabecera', { |
50 | label: 'Unidad:', | 60 | label: 'Unidad:', |
51 | valor: res.data.codigo | 61 | valor: res.data.codigo |
52 | }); | 62 | }); |
53 | $scope.$broadcast('addCabecera', { | 63 | $scope.$broadcast('addCabecera', { |
54 | label: 'Capacidad total vehículo:', | 64 | label: 'Capacidad total vehículo:', |
55 | valor: res.data.capacidad | 65 | valor: res.data.capacidad |
56 | }); | 66 | }); |
57 | }); | 67 | }); |
58 | $scope.cancelar = function() { | 68 | $scope.cancelar = function() { |
59 | $location.path('/vehiculo/' + $routeParams.idVehiculo); | 69 | |
70 | if ($scope.formCisterna.$pristine == false) { | ||
71 | focaModalService.confirm( | ||
72 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | ||
73 | ).then(function(data) { | ||
74 | if (data) { | ||
75 | $location.path('/vehiculo'); | ||
76 | } | ||
77 | }); | ||
78 | } | ||
60 | }; | 79 | }; |
61 | $scope.guardar = function() { | 80 | $scope.guardar = function() { |
62 | 81 | ||
63 | if (!$scope.cisterna.codigo) { | 82 | if (!$scope.cisterna.codigo) { |
64 | focaModalService.alert('Ingrese codigo de cisterna'); | 83 | focaModalService.alert('Ingrese codigo de cisterna'); |
65 | return; | 84 | return; |
66 | } else if (!$scope.cisterna.capacidad) { | 85 | } else if (!$scope.cisterna.capacidad) { |
67 | focaModalService.alert('Ingrese capacidad'); | 86 | focaModalService.alert('Ingrese capacidad'); |
68 | return; | 87 | return; |
69 | } else if (!$scope.cisterna.idUnidadMedida) { | 88 | } else if (!$scope.cisterna.idUnidadMedida) { |
70 | focaModalService.alert('Ingrese unidad de medida'); | 89 | focaModalService.alert('Ingrese unidad de medida'); |
71 | return; | 90 | return; |
72 | } | 91 | } |
73 | 92 | ||
74 | validaCodigo() | 93 | validaCodigo() |
75 | .then(function() { | 94 | .then(function() { |
76 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 95 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); |
77 | delete $scope.cisterna.vehiculo; | 96 | delete $scope.cisterna.vehiculo; |
78 | 97 | ||
79 | focaAbmVehiculoService | 98 | focaAbmVehiculoService |
80 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 99 | .guardarCisterna($scope.cisterna, $routeParams.idx); |
81 | 100 | ||
82 | $timeout(function() { | 101 | $timeout(function() { |
83 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 102 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
84 | '/' + $scope.transportista); | 103 | '/' + $scope.transportista); |
85 | }, 0); | 104 | }, 0); |
86 | }, function(err) { | 105 | }, function(err) { |
87 | focaModalService.alert(err); | 106 | focaModalService.alert(err); |
88 | }); | 107 | }); |
89 | 108 | ||
90 | }; | 109 | }; |
91 | 110 | ||
92 | $scope.seleccionarUnidadMedida = function() { | 111 | $scope.seleccionarUnidadMedida = function() { |
93 | var modalInstance = $uibModal.open( | 112 | var modalInstance = $uibModal.open( |
94 | { | 113 | { |
95 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 114 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
96 | templateUrl: 'modal-unidad-medida.html', | 115 | templateUrl: 'modal-unidad-medida.html', |
97 | controller: 'focaModalUnidadMedidaCtrl', | 116 | controller: 'focaModalUnidadMedidaCtrl', |
98 | size: 'lg' | 117 | size: 'lg' |
99 | } | 118 | } |
100 | ); | 119 | ); |
101 | modalInstance.result.then(function(unidaMedida) { | 120 | modalInstance.result.then(function(unidaMedida) { |
102 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 121 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
103 | $scope.cisterna.unidadMedida = unidaMedida; | 122 | $scope.cisterna.unidadMedida = unidaMedida; |
104 | }); | 123 | }); |
105 | }; | 124 | }; |
106 | 125 | ||
126 | /*$scope.$watch('cisterna', function(newValue) { | ||
127 | focaBotoneraLateralService.setPausarData({ | ||
128 | label:'cisterna', | ||
129 | val: { | ||
130 | codigo: newValue.codigo, | ||
131 | capacidad: newValue.capacidad, | ||
132 | unidadMedida: newValue.NOM | ||
133 | } | ||
134 | }); | ||
135 | }, true);*/ | ||
136 | |||
137 | /*function getLSCisterna() { | ||
138 | var cisterna = JSON.parse($localStorage.cisterna|| null); | ||
139 | if (cisterna) { | ||
140 | setearcisterna(cisterna); | ||
141 | delete $localStorage.cisterna; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | function setearcisterna(cisterna) { | ||
146 | $scope.cisterna = cisterna; | ||
147 | $scope.$broadcast('addCabecera', { | ||
148 | label: 'cisterna:', | ||
149 | valor: $filter('rellenarDigitos')(cisterna.codigo) + ' - ' | ||
150 | }); | ||
151 | }*/ | ||
152 | |||
107 | function validaCodigo() { | 153 | function validaCodigo() { |
108 | return new Promise(function(resolve, reject) { | 154 | return new Promise(function(resolve, reject) { |
109 | focaAbmVehiculoService | 155 | focaAbmVehiculoService |
110 | .getCisternas($routeParams.idVehiculo) | 156 | .getCisternas($routeParams.idVehiculo) |
111 | .then(function(res) { | 157 | .then(function(res) { |
112 | var cisternas = res; | 158 | var cisternas = res; |
113 | var totalCargado = 0; | 159 | var totalCargado = 0; |
114 | cisternas.forEach(function(cisterna, idx) { | 160 | cisternas.forEach(function(cisterna, idx) { |
115 | //SI EL CODIGO YA EXISTE | 161 | //SI EL CODIGO YA EXISTE |
116 | if(cisterna.codigo === $scope.cisterna.codigo && | 162 | if(cisterna.codigo === $scope.cisterna.codigo && |
117 | idx != $routeParams.idx && | 163 | idx != $routeParams.idx && |
118 | !cisterna.desactivado) { | 164 | !cisterna.desactivado) { |
119 | reject('Código de cisterna existente'); | 165 | reject('Código de cisterna existente'); |
120 | } | 166 | } |
121 | if(idx != $routeParams.idx && | 167 | if(idx != $routeParams.idx && |
122 | !cisterna.desactivado) { | 168 | !cisterna.desactivado) { |
123 | totalCargado += cisterna.capacidad; | 169 | totalCargado += cisterna.capacidad; |
124 | } | 170 | } |
125 | }); | 171 | }); |
126 | resolve(); | 172 | resolve(); |
127 | }); | 173 | }); |
128 | }); | 174 | }); |
129 | } | 175 | } |
130 | } | 176 | } |
131 | ]); | 177 | ]); |
132 | 178 |