Commit d6d4ef19c2fb050efa95e7c4dcff8a8f60ce4309

Authored by Eric Fernandez
1 parent 913fe74c8b
Exists in master and in 1 other branch develop

prueba commit

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