Commit b10f3782d7729d23d32886d7eb5565bc6a425166
1 parent
025d712e32
Exists in
master
and in
1 other branch
quito modal proveedores
Showing
1 changed file
with
18 additions
and
13 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', |
5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, |
6 | $uibModal, focaBotoneraLateralService, $timeout) { | 6 | $uibModal, focaBotoneraLateralService, $timeout) { |
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 | } | 36 | } |
37 | } | 37 | } |
38 | ); | 38 | ); |
39 | }; | 39 | }; |
40 | $scope.seleccionarTransportista = function() { | 40 | $scope.seleccionarTransportista = function() { |
41 | var modalInstance = $uibModal.open( | 41 | var parametrosModal = { |
42 | { | 42 | titulo: 'Búsqueda de Transportista', |
43 | ariaLabelledBy: 'Busqueda de Transportista', | 43 | query: '/transportista', |
44 | templateUrl: 'modal-proveedor.html', | 44 | columnas: [ |
45 | controller: 'focaModalProveedorCtrl', | 45 | { |
46 | size: 'lg', | 46 | nombre: 'Código', |
47 | resolve: { | 47 | propiedad: 'COD' |
48 | transportista: function() { | 48 | }, |
49 | return true; | 49 | { |
50 | } | 50 | nombre: 'Nombre', |
51 | propiedad: 'NOM' | ||
52 | }, | ||
53 | { | ||
54 | nombre: 'CUIT', | ||
55 | propiedad: 'CUIT' | ||
51 | } | 56 | } |
52 | } | 57 | ] |
53 | ); | 58 | }; |
54 | modalInstance.result.then( | 59 | focaModalService.modal(parametrosModal).then( |
55 | function(transportista) { | 60 | function(transportista) { |
56 | elegirTransportista(transportista); | 61 | elegirTransportista(transportista); |
57 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; |
58 | }, function() { | 63 | }, function() { |
59 | 64 | ||
60 | } | 65 | } |
61 | ); | 66 | ); |
62 | }; | 67 | }; |
63 | 68 | ||
64 | function elegirTransportista(transportista) { | 69 | function elegirTransportista(transportista) { |
65 | var codigo = ('00000' + transportista.COD).slice(-5); | 70 | var codigo = ('00000' + transportista.COD).slice(-5); |
66 | $scope.idTransportista = transportista.COD; | 71 | $scope.idTransportista = transportista.COD; |
67 | $scope.filtros = transportista.NOM.trim(); | 72 | $scope.filtros = transportista.NOM.trim(); |
68 | $timeout(function() { | 73 | $timeout(function() { |
69 | $scope.$broadcast('addCabecera', { | 74 | $scope.$broadcast('addCabecera', { |
70 | label: 'Transportista:', | 75 | label: 'Transportista:', |
71 | valor: codigo + ' - ' + transportista.NOM | 76 | valor: codigo + ' - ' + transportista.NOM |
72 | }); | 77 | }); |
73 | }); | 78 | }); |
74 | buscar(transportista.COD); | 79 | buscar(transportista.COD); |
75 | } | 80 | } |
76 | 81 | ||
77 | function buscar(idTransportista) { | 82 | function buscar(idTransportista) { |
78 | focaAbmVehiculoService | 83 | focaAbmVehiculoService |
79 | .getVehiculosPorTransportista(idTransportista) | 84 | .getVehiculosPorTransportista(idTransportista) |
80 | .then(function(datos) { | 85 | .then(function(datos) { |
81 | $scope.vehiculos = datos.data; | 86 | $scope.vehiculos = datos.data; |
82 | }); | 87 | }); |
83 | } | 88 | } |
84 | function salir() { | 89 | function salir() { |
85 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 90 | focaAbmVehiculoService.transportistaSeleccionado = {}; |
86 | $location.path('/'); | 91 | $location.path('/'); |
87 | } | 92 | } |
88 | } | 93 | } |
89 | ]) | 94 | ]) |
90 | .controller('focaAbmVehiculoController', [ | 95 | .controller('focaAbmVehiculoController', [ |
91 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 96 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
92 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', | 97 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', |
93 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 98 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
94 | focaModalService, $timeout, focaBotoneraLateralService, $window) { | 99 | focaModalService, $timeout, focaBotoneraLateralService, $window) { |
95 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 100 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
96 | $scope.now = new Date(); | 101 | $scope.now = new Date(); |
97 | $scope.focused = 1; | 102 | $scope.focused = 1; |
98 | $scope.transportistaStamp = ''; | 103 | $scope.transportistaStamp = ''; |
99 | $scope.cisternas = []; | 104 | $scope.cisternas = []; |
100 | 105 | ||
101 | $timeout(function() { | 106 | $timeout(function() { |
102 | focaBotoneraLateralService.showSalir(false); | 107 | focaBotoneraLateralService.showSalir(false); |
103 | focaBotoneraLateralService.showPausar(false); | 108 | focaBotoneraLateralService.showPausar(false); |
104 | focaBotoneraLateralService.showCancelar(false); | 109 | focaBotoneraLateralService.showCancelar(false); |
105 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 110 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
106 | focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); | 111 | focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); |
107 | }); | 112 | }); |
108 | 113 | ||
109 | if($scope.nuevo) { | 114 | if($scope.nuevo) { |
110 | focaAbmVehiculoService | 115 | focaAbmVehiculoService |
111 | .getTransportistaPorId($routeParams.idTransportista) | 116 | .getTransportistaPorId($routeParams.idTransportista) |
112 | .then(function(res) { | 117 | .then(function(res) { |
113 | var codigo = ('00000' + res.data.COD).slice(-5); | 118 | var codigo = ('00000' + res.data.COD).slice(-5); |
114 | $scope.vehiculo.idTransportista = res.data.COD; | 119 | $scope.vehiculo.idTransportista = res.data.COD; |
115 | $scope.vehiculo.transportista = res.data; | 120 | $scope.vehiculo.transportista = res.data; |
116 | $scope.$broadcast('addCabecera', { | 121 | $scope.$broadcast('addCabecera', { |
117 | label: 'Transportista:', | 122 | label: 'Transportista:', |
118 | valor: codigo + ' - ' + res.data.NOM | 123 | valor: codigo + ' - ' + res.data.NOM |
119 | }); | 124 | }); |
120 | }); | 125 | }); |
121 | } | 126 | } |
122 | $scope.vehiculo = {}; | 127 | $scope.vehiculo = {}; |
123 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 128 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
124 | if(res.data) { | 129 | if(res.data) { |
125 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 130 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); |
126 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 131 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; |
127 | 132 | ||
128 | $scope.vehiculo = res.data; | 133 | $scope.vehiculo = res.data; |
129 | $scope.$broadcast('addCabecera', { | 134 | $scope.$broadcast('addCabecera', { |
130 | label: 'Transportista:', | 135 | label: 'Transportista:', |
131 | valor: $scope.transportistaStamp | 136 | valor: $scope.transportistaStamp |
132 | }); | 137 | }); |
133 | $scope.$broadcast('addCabecera', { | 138 | $scope.$broadcast('addCabecera', { |
134 | label: 'Unidad:', | 139 | label: 'Unidad:', |
135 | valor: res.data.codigo | 140 | valor: res.data.codigo |
136 | }); | 141 | }); |
137 | focaAbmVehiculoService | 142 | focaAbmVehiculoService |
138 | .getCisternas($routeParams.idVehiculo) | 143 | .getCisternas($routeParams.idVehiculo) |
139 | .then(function(res) { | 144 | .then(function(res) { |
140 | $scope.cisternas = res; | 145 | $scope.cisternas = res; |
141 | $scope.$apply(); | 146 | $scope.$apply(); |
142 | }); | 147 | }); |
143 | } | 148 | } |
144 | }); | 149 | }); |
145 | 150 | ||
146 | $scope.next = function(key) { | 151 | $scope.next = function(key) { |
147 | if (key === 13) $scope.focused++; | 152 | if (key === 13) $scope.focused++; |
148 | }; | 153 | }; |
149 | $scope.cancelar = function() { | 154 | $scope.cancelar = function() { |
150 | $location.path('/vehiculo'); | 155 | $location.path('/vehiculo'); |
151 | }; | 156 | }; |
152 | $scope.editar = function(key) { | 157 | $scope.editar = function(key) { |
153 | if(key) { | 158 | if(key) { |
154 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 159 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
155 | '/cisterna/' + key); | 160 | '/cisterna/' + key); |
156 | }else { | 161 | }else { |
157 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 162 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); |
158 | } | 163 | } |
159 | }; | 164 | }; |
160 | $scope.guardar = function(key) { | 165 | $scope.guardar = function(key) { |
161 | key = (typeof key === 'undefined') ? 13 : key; | 166 | key = (typeof key === 'undefined') ? 13 : key; |
162 | if(key === 13) { | 167 | if(key === 13) { |
163 | //Valida si existe numero de unidad | 168 | //Valida si existe numero de unidad |
164 | if(!validaTotalCargas() && !$scope.nuevo) { | 169 | if(!validaTotalCargas() && !$scope.nuevo) { |
165 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 170 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
166 | ' debe ser igual a la capacidad total del vehículo'); | 171 | ' debe ser igual a la capacidad total del vehículo'); |
167 | return; | 172 | return; |
168 | } | 173 | } |
169 | validaCodigoUnidad().then(function() { | 174 | validaCodigoUnidad().then(function() { |
170 | delete $scope.vehiculo.transportista; | 175 | delete $scope.vehiculo.transportista; |
171 | delete $scope.vehiculo.cisternas; | 176 | delete $scope.vehiculo.cisternas; |
172 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 177 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) |
173 | .then(function(res) { | 178 | .then(function(res) { |
174 | if($scope.nuevo) { | 179 | if($scope.nuevo) { |
175 | $location.path('/vehiculo/' + res.data.id + | 180 | $location.path('/vehiculo/' + res.data.id + |
176 | '/' + res.data.idTransportista); | 181 | '/' + res.data.idTransportista); |
177 | }else { | 182 | }else { |
178 | guardarCisternas().then(function() { | 183 | guardarCisternas().then(function() { |
179 | $window.location.assign('/#!/vehiculo'); | 184 | $window.location.assign('/#!/vehiculo'); |
180 | }); | 185 | }); |
181 | } | 186 | } |
182 | }); | 187 | }); |
183 | }, function() { | 188 | }, function() { |
184 | focaModalService.alert('Código de unidad existente'); | 189 | focaModalService.alert('Código de unidad existente'); |
185 | }); | 190 | }); |
186 | } | 191 | } |
187 | 192 | ||
188 | }; | 193 | }; |
189 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 194 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { |
190 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 195 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + |
191 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 196 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( |
192 | function(data) { | 197 | function(data) { |
193 | if(data) { | 198 | if(data) { |
194 | focaAbmVehiculoService.deleteCisterna(idx); | 199 | focaAbmVehiculoService.deleteCisterna(idx); |
195 | focaAbmVehiculoService | 200 | focaAbmVehiculoService |
196 | .getCisternas($routeParams.idVehiculo) | 201 | .getCisternas($routeParams.idVehiculo) |
197 | .then(function(res) { | 202 | .then(function(res) { |
198 | $scope.cisternas = res; | 203 | $scope.cisternas = res; |
199 | }); | 204 | }); |
200 | } | 205 | } |
201 | } | 206 | } |
202 | ); | 207 | ); |
203 | }; | 208 | }; |
204 | 209 | ||
205 | function validaCodigoUnidad() { | 210 | function validaCodigoUnidad() { |
206 | return new Promise(function(resolve, reject) { | 211 | return new Promise(function(resolve, reject) { |
207 | focaAbmVehiculoService | 212 | focaAbmVehiculoService |
208 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 213 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) |
209 | .then(function(res) { | 214 | .then(function(res) { |
210 | //Valida si existe numero de unidad | 215 | //Valida si existe numero de unidad |
211 | var existe = res.data.filter(function(vehiculo) { | 216 | var existe = res.data.filter(function(vehiculo) { |
212 | return vehiculo.codigo === $scope.vehiculo.codigo && | 217 | return vehiculo.codigo === $scope.vehiculo.codigo && |
213 | vehiculo.id !== $scope.vehiculo.id; | 218 | vehiculo.id !== $scope.vehiculo.id; |
214 | }); | 219 | }); |
215 | 220 | ||
216 | if(existe.length) { | 221 | if(existe.length) { |
217 | reject(existe); | 222 | reject(existe); |
218 | }else { | 223 | }else { |
219 | resolve(); | 224 | resolve(); |
220 | } | 225 | } |
221 | }); | 226 | }); |
222 | }); | 227 | }); |
223 | } | 228 | } |
224 | 229 | ||
225 | function validaTotalCargas() { | 230 | function validaTotalCargas() { |
226 | var total = 0; | 231 | var total = 0; |
227 | $scope.cisternas.forEach(function(cisterna) { | 232 | $scope.cisternas.forEach(function(cisterna) { |
228 | if(!cisterna.desactivado) { | 233 | if(!cisterna.desactivado) { |
229 | total += parseInt(cisterna.capacidad); | 234 | total += parseInt(cisterna.capacidad); |
230 | } | 235 | } |
231 | }); | 236 | }); |
232 | return $scope.vehiculo.capacidad == total; | 237 | return $scope.vehiculo.capacidad == total; |
233 | } | 238 | } |
234 | 239 | ||
235 | function guardarCisternas() { | 240 | function guardarCisternas() { |
236 | var cisternas = $scope.cisternas.map(function(cisterna) { | 241 | var cisternas = $scope.cisternas.map(function(cisterna) { |
237 | return { | 242 | return { |
238 | id: cisterna.id, | 243 | id: cisterna.id, |
239 | capacidad: parseFloat(cisterna.capacidad), | 244 | capacidad: parseFloat(cisterna.capacidad), |
240 | codigo: cisterna.codigo, | 245 | codigo: cisterna.codigo, |
241 | idUnidadMedida: cisterna.idUnidadMedida, | 246 | idUnidadMedida: cisterna.idUnidadMedida, |
242 | idVehiculo: $routeParams.idVehiculo, | 247 | idVehiculo: $routeParams.idVehiculo, |
243 | desactivado: cisterna.desactivado | 248 | desactivado: cisterna.desactivado |
244 | }; | 249 | }; |
245 | }); | 250 | }); |
246 | 251 | ||
247 | return focaAbmVehiculoService.guardarCisternas(cisternas); | 252 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
248 | } | 253 | } |
249 | } | 254 | } |
250 | ]); | 255 | ]); |
251 | 256 |