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