Commit 3b896ba943ff21b9c76293d412421fb4607d97d0

Authored by Luigi
1 parent b47480a700
Exists in master

Boton volver - crear y editar cisternas

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 } 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 function elegirTransportista(transportista) { 68 function elegirTransportista(transportista) {
69 var codigo = ('00000' + transportista.COD).slice(-5); 69 var codigo = ('00000' + transportista.COD).slice(-5);
70 $scope.idTransportista = transportista.COD; 70 $scope.idTransportista = transportista.COD;
71 $scope.filtros = transportista.NOM.trim(); 71 $scope.filtros = transportista.NOM.trim();
72 $timeout(function() { 72 $timeout(function() {
73 $scope.$broadcast('addCabecera', { 73 $scope.$broadcast('addCabecera', {
74 label: 'Transportista:', 74 label: 'Transportista:',
75 valor: codigo + ' - ' + transportista.NOM 75 valor: codigo + ' - ' + transportista.NOM
76 }); 76 });
77 }); 77 });
78 buscar(transportista.COD); 78 buscar(transportista.COD);
79 } 79 }
80 80
81 function buscar(idTransportista) { 81 function buscar(idTransportista) {
82 focaAbmVehiculoService 82 focaAbmVehiculoService
83 .getVehiculosPorTransportista(idTransportista) 83 .getVehiculosPorTransportista(idTransportista)
84 .then(function(datos) { 84 .then(function(datos) {
85 $scope.vehiculos = datos.data; 85 $scope.vehiculos = datos.data;
86 }); 86 });
87 } 87 }
88 function salir() { 88 function salir() {
89 focaAbmVehiculoService.transportistaSeleccionado = {}; 89 focaAbmVehiculoService.transportistaSeleccionado = {};
90 $location.path('/'); 90 $location.path('/');
91 } 91 }
92 } 92 }
93 ]) 93 ])
94 .controller('focaAbmVehiculoController', [ 94 .controller('focaAbmVehiculoController', [
95 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 95 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
96 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', 96 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter',
97 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 97 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
98 focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { 98 focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) {
99 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; 99 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false;
100 $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; 100 $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true;
101 $scope.now = new Date(); 101 $scope.now = new Date();
102 $scope.focused = 1; 102 $scope.focused = 1;
103 $scope.creando = false; 103 $scope.creando = false;
104 $scope.crear = false;
104 $scope.transportistaStamp = ''; 105 $scope.transportistaStamp = '';
105 $scope.cisternasABorrar = [];
106 $scope.cisternas = []; 106 $scope.cisternas = [];
107 $scope.cisterna = {
108 codigo: '',
109 capacidad: '',
110 idUnidadMedida: 0,
111 unidadMedida: {}
112 };
113 107
114 $timeout(function() { 108 $timeout(function() {
115 focaBotoneraLateralService.showSalir(false); 109 focaBotoneraLateralService.showSalir(false);
116 focaBotoneraLateralService.showPausar(true); 110 focaBotoneraLateralService.showPausar(true);
117 focaBotoneraLateralService.showCancelar(false); 111 focaBotoneraLateralService.showCancelar(false);
118 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 112 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
119 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); 113 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
120 }); 114 });
121 115
122 if ($scope.nuevo) { 116 if ($scope.nuevo) {
123 focaAbmVehiculoService 117 focaAbmVehiculoService
124 .getTransportistaPorId($routeParams.idTransportista) 118 .getTransportistaPorId($routeParams.idTransportista)
125 .then(function(res) { 119 .then(function(res) {
126 var codigo = ('00000' + res.data.COD).slice(-5); 120 var codigo = ('00000' + res.data.COD).slice(-5);
127 $scope.vehiculo.idTransportista = res.data.COD; 121 $scope.vehiculo.idTransportista = res.data.COD;
128 $scope.vehiculo.transportista = res.data; 122 $scope.vehiculo.transportista = res.data;
129 $scope.$broadcast('addCabecera', { 123 $scope.$broadcast('addCabecera', {
130 label: 'Transportista:', 124 label: 'Transportista:',
131 valor: codigo + ' - ' + res.data.NOM 125 valor: codigo + ' - ' + res.data.NOM
132 }); 126 });
133 }); 127 });
134 } 128 }
135 $scope.vehiculo = {}; 129 $scope.vehiculo = {};
136 130
137 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 131 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
138 132
139 if (res.data) { 133 if (res.data) {
140 var vehiculoSeteado = getLSVehiculo(); 134 var vehiculoSeteado = getLSVehiculo();
141 if (vehiculoSeteado === false) { 135 if (vehiculoSeteado === false) {
142 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); 136 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5);
143 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; 137 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM;
144 138
145 $scope.vehiculo = res.data; 139 $scope.vehiculo = res.data;
146 $scope.$broadcast('addCabecera', { 140 $scope.$broadcast('addCabecera', {
147 label: 'Transportista:', 141 label: 'Transportista:',
148 valor: $scope.transportistaStamp 142 valor: $scope.transportistaStamp
149 }); 143 });
150 $scope.$broadcast('addCabecera', { 144 $scope.$broadcast('addCabecera', {
151 label: 'Unidad:', 145 label: 'Unidad:',
152 valor: res.data.codigo 146 valor: res.data.codigo
153 }); 147 });
154 } 148 }
155 149
156 focaAbmVehiculoService 150 focaAbmVehiculoService
157 .getCisternas($routeParams.idVehiculo) 151 .getCisternas($routeParams.idVehiculo)
158 .then(function(res) { 152 .then(function(res) {
159 $scope.cisternas = res; 153 $scope.cisternas = res;
160 $scope.$apply(); 154 $scope.$apply();
161 }); 155 });
162 } 156 }
163 }); 157 });
164 158
165 $scope.next = function(key) { 159 $scope.next = function(key) {
166 if (key === 13) $scope.focused++; 160 if (key === 13) $scope.focused++;
167 }; 161 };
168 162
169 $scope.salir = function() { 163 $scope.salir = function() {
170 if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { 164 if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) {
171 focaModalService.confirm( 165 focaModalService.confirm(
172 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 166 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
173 ).then(function(data) { 167 ).then(function(data) {
174 if (data) { 168 if (data) {
175 $location.path('/vehiculo'); 169 $location.path('/vehiculo');
176 } 170 }
177 }); 171 });
178 } else { 172 } else {
179 $location.path('/vehiculo'); 173 $location.path('/vehiculo');
180 } 174 }
181 }; 175 };
182 176
183 $scope.editar = function(key, cisterna) { 177 $scope.editar = function(cisterna) {
184 if (key === 'nuevo') { 178 $scope.cisternas.forEach(function(cisterna) {
185 $scope.cisterna = {}; 179 cisterna.editando = false;
186 $scope.creando = true; 180 $scope.crear = true;
187 } else { 181 });
188 $scope.cisterna = cisterna; 182 cisterna.editando = true;
189 $scope.creando = true; 183 $scope.inicial = angular.copy(cisterna);
184 };
185
186 $scope.volver = function(cisterna, key) {
187 if (cisterna.id === undefined || !$scope.crear) {
188 $scope.cisternas.shift(cisterna);
189 $scope.crear = false;
190 return;
191 }
192 if (cisterna.id !== undefined) {
193 $scope.cisternas[key] = $scope.inicial;
194 $scope.cisternas[key].editando = false;
190 } 195 }
196 $scope.crear = false;
191 }; 197 };
192 198
193 $scope.seleccionarUnidadMedida = function() { 199 $scope.crearCisterna = function() {
200 var cisterna = {
201 codigo: '',
202 capacidad: '',
203 idUnidadMedida: 0,
204 unidadMedida: {},
205 editando: true,
206 };
207 $scope.cisternas.unshift(cisterna);
208 $scope.crear = true;
209 };
210
211 $scope.seleccionarUnidadMedida = function(cisterna) {
194 var modalInstance = $uibModal.open( 212 var modalInstance = $uibModal.open(
195 { 213 {
196 ariaLabelledBy: 'Busqueda de Unidades de medida', 214 ariaLabelledBy: 'Busqueda de Unidades de medida',
197 templateUrl: 'modal-unidad-medida.html', 215 templateUrl: 'modal-unidad-medida.html',
198 controller: 'focaModalUnidadMedidaCtrl', 216 controller: 'focaModalUnidadMedidaCtrl',
199 size: 'lg' 217 size: 'lg'
200 } 218 }
201 ); 219 );
202 modalInstance.result.then(function(unidaMedida) { 220 modalInstance.result.then(function(unidaMedida) {
203 $scope.cisterna.idUnidadMedida = unidaMedida.ID; 221 cisterna.idUnidadMedida = unidaMedida.ID;
204 $scope.cisterna.unidadMedida = unidaMedida; 222 cisterna.unidadMedida = unidaMedida;
205 }); 223 });
206 }; 224 };
207 225
208 $scope.guardar = function(key) { 226 $scope.guardar = function(key) {
209 key = (typeof key === 'undefined') ? 13 : key; 227 key = (typeof key === 'undefined') ? 13 : key;
210 228
211 if (key === 13) { 229 if (key === 13) {
212 230
213 if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { 231 if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) {
214 $scope.salir(); 232 $scope.salir();
215 return; 233 return;
216 } 234 }
235 $scope.cisternas.forEach( function(cisterna) {
236 if (cisterna.id === 0) cisterna.id = undefined;
237 });
217 238
218 if (!$scope.vehiculo.codigo) { 239 if (!$scope.vehiculo.codigo) {
219 focaModalService.alert('Ingrese unidad'); 240 focaModalService.alert('Ingrese unidad');
220 return; 241 return;
221 } else if (!$scope.vehiculo.tractor) { 242 } else if (!$scope.vehiculo.tractor) {
222 focaModalService.alert('Ingrese dominio tractor'); 243 focaModalService.alert('Ingrese dominio tractor');
223 return; 244 return;
224 } else if (!$scope.vehiculo.semi) { 245 } else if (!$scope.vehiculo.semi) {
225 focaModalService.alert('Ingrese dominio semi'); 246 focaModalService.alert('Ingrese dominio semi');
226 return; 247 return;
227 } else if (!$scope.vehiculo.capacidad) { 248 } else if (!$scope.vehiculo.capacidad) {
228 focaModalService.alert('Ingrese capacidad total'); 249 focaModalService.alert('Ingrese capacidad total');
229 return; 250 return;
230 } 251 }
231 //Valida si existe numero de unidad 252 //Valida si existe numero de unidad
232 if (!validaTotalCargas() && !$scope.nuevo) { 253 if (!validaTotalCargas() && !$scope.nuevo) {
233 focaModalService.alert('La suma de las capacidades de las cisternas' + 254 focaModalService.alert('La suma de las capacidades de las cisternas' +
234 ' debe ser igual a la capacidad total del vehículo'); 255 ' debe ser igual a la capacidad total del vehículo');
235 return; 256 return;
236 } 257 }
237 258
238 borrarCisternas();
239
240 validaCodigoUnidad().then(function() { 259 validaCodigoUnidad().then(function() {
241 delete $scope.vehiculo.transportista; 260 delete $scope.vehiculo.transportista;
242 delete $scope.vehiculo.cisternas; 261 delete $scope.vehiculo.cisternas;
243 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) 262 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo)
244 .then(function(res) { 263 .then(function(res) {
245 if ($scope.nuevo) { 264 if ($scope.nuevo) {
246 $location.path('/vehiculo/' + res.data.id + 265 $location.path('/vehiculo/' + res.data.id +
247 '/' + res.data.idTransportista); 266 '/' + res.data.idTransportista);
248 } else { 267 } else {
249 guardarCisternas().then(function() { 268 guardarCisternas($scope.cisternas).then(function() {
250 $location.path('/vehiculo'); 269 $location.path('/vehiculo');
251 }); 270 });
252 } 271 }
253 }); 272 });
254 }, function() { 273 }, function() {
255 focaModalService.alert('Código de unidad existente'); 274 focaModalService.alert('Código de unidad existente');
256 }); 275 });
257 } 276 }
258 }; 277 };
259
260 //Agregar propiedades de cisterna 278 //Agregar propiedades de cisterna
261 $scope.$watch('vehiculo', function(newValue) { 279 $scope.$watch('vehiculo', function(newValue) {
262 focaBotoneraLateralService.setPausarData({ 280 focaBotoneraLateralService.setPausarData({
263 label:'vehiculo', 281 label:'vehiculo',
264 val: { 282 val: {
265 codigo: newValue.codigo, 283 codigo: newValue.codigo,
266 tractor: newValue.tractor, 284 tractor: newValue.tractor,
267 semi: newValue.semi, 285 semi: newValue.semi,
268 capacidad: newValue.capacidad, 286 capacidad: newValue.capacidad,
269 idVehiculo: newValue.idVehiculo, 287 idVehiculo: newValue.idVehiculo,
270 idTransportista: newValue.idTransportista 288 idTransportista: newValue.idTransportista
271 } 289 }
272 }); 290 });
273 }, true); 291 }, true);
274 292
275 function getLSVehiculo() { 293 function getLSVehiculo() {
276 var vehiculo = JSON.parse($localStorage.vehiculo|| null); 294 var vehiculo = JSON.parse($localStorage.vehiculo|| null);
277 if (vehiculo) { 295 if (vehiculo) {
278 setearVehiculo(vehiculo); 296 setearVehiculo(vehiculo);
279 delete $localStorage.vehiculo; 297 delete $localStorage.vehiculo;
280 return true; 298 return true;
281 } 299 }
282 return false; 300 return false;
283 } 301 }
284 302
285 function borrarCisternas() {
286 $scope.cisternasABorrar.forEach(cisternaABorrar => {
287 focaAbmVehiculoService.deleteCisterna(cisternaABorrar);
288 focaAbmVehiculoService
289 .getCisternas($routeParams.idVehiculo)
290 .then(function(res) {
291 $scope.cisternas = res;
292 });
293 });
294 }
295
296 function setearVehiculo(vehiculo) { 303 function setearVehiculo(vehiculo) {
297 $scope.vehiculo = vehiculo; 304 $scope.vehiculo = vehiculo;
298 $scope.$broadcast('addCabecera', { 305 $scope.$broadcast('addCabecera', {
299 label: 'Vehiculo:', 306 label: 'Vehiculo:',
300 valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' 307 valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - '
301 }); 308 });
302 } 309 }
303 310
304 $scope.solicitarConfirmacionTabla = function(cisterna, idx){ 311 $scope.solicitarConfirmacionTabla = function(cisterna) {
305 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?') 312 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?')
306 .then( function(data) { 313 .then( function(data) {
307 if (data) { 314 if (data) {
308 $scope.cisternasABorrar.push(cisterna); 315 cisterna.desactivado = true;
309 $scope.cisternas.splice(idx,1);
310 } 316 }
311 }); 317 });
312 return; 318 return;
313 }; 319 };
314 320
315 function validaCodigoUnidad() { 321 function validaCodigoUnidad() {
316 return new Promise(function(resolve, reject) { 322 return new Promise(function(resolve, reject) {
317 focaAbmVehiculoService 323 focaAbmVehiculoService
318 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) 324 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista))
319 .then(function(res) { 325 .then(function(res) {
320 //Valida si existe numero de unidad 326 //Valida si existe numero de unidad
321 var existe = res.data.filter(function(vehiculo) { 327 var existe = res.data.filter(function(vehiculo) {
322 return vehiculo.codigo === $scope.vehiculo.codigo && 328 return vehiculo.codigo === $scope.vehiculo.codigo &&
323 vehiculo.id !== $scope.vehiculo.id; 329 vehiculo.id !== $scope.vehiculo.id;
324 }); 330 });
325 331
326 if (existe.length) { 332 if (existe.length) {
327 reject(existe); 333 reject(existe);
328 } else { 334 } else {
329 resolve(); 335 resolve();
330 } 336 }
331 }); 337 });
332 }); 338 });
333 } 339 }
334 340
335 function validaTotalCargas() { 341 function validaTotalCargas() {
336 var total = 0; 342 var total = 0;
337 $scope.cisternas.forEach(function(cisterna) { 343 $scope.cisternas.forEach(function(cisterna) {
338 if (!cisterna.desactivado) { 344 if (!cisterna.desactivado) {
339 total += parseInt(cisterna.capacidad); 345 total += parseInt(cisterna.capacidad);
340 } 346 }
341 }); 347 });
342 return $scope.vehiculo.capacidad >= total; 348 return $scope.vehiculo.capacidad >= total;
343 } 349 }
344 function guardarCisternas() { 350 function guardarCisternas() {
345 var cisternas = $scope.cisternas.map(function(cisterna) { 351 var cisternas = $scope.cisternas.map(function(cisterna) {
346 return { 352 return {
347 id: cisterna.id, 353 id: cisterna.id,
348 capacidad: parseFloat(cisterna.capacidad), 354 capacidad: parseFloat(cisterna.capacidad),
349 codigo: cisterna.codigo, 355 codigo: cisterna.codigo,
350 idUnidadMedida: cisterna.idUnidadMedida, 356 idUnidadMedida: cisterna.idUnidadMedida,
351 idVehiculo: $routeParams.idVehiculo, 357 idVehiculo: $routeParams.idVehiculo,
352 desactivado: cisterna.desactivado 358 desactivado: cisterna.desactivado
353 }; 359 };
354 }); 360 });
355 361
356 return focaAbmVehiculoService.guardarCisternas(cisternas); 362 return focaAbmVehiculoService.guardarCisternas(cisternas);
357 } 363 }
358 364
359 $scope.agregarCisterna = function() { 365 $scope.agregarCisterna = function(cisterna) {
360 if (!$scope.cisterna.codigo) { 366 if (!cisterna) {
367 focaModalService.alert('Ingrese valores');
368 return;
369 } else if (!cisterna.codigo) {
361 focaModalService.alert('Ingrese codigo de cisterna'); 370 focaModalService.alert('Ingrese codigo de cisterna');
362 return; 371 return;
363 } else if (!$scope.cisterna.capacidad) { 372 } else if (!cisterna.capacidad) {
364 focaModalService.alert('Ingrese capacidad'); 373 focaModalService.alert('Ingrese capacidad');
365 return; 374 return;
366 } else if (!$scope.cisterna.idUnidadMedida) { 375 } else if (!cisterna.idUnidadMedida) {
367 focaModalService.alert('Ingrese unidad de medida'); 376 focaModalService.alert('Ingrese unidad de medida');
368 return; 377 return;
369 } 378 }
370 $scope.creando = false;
371 if (!$scope.cisterna.id) {
372 validaCodigo()
373 .then(function() {
374 saveCisterna();
375 }, function(err) {
376 focaModalService.alert(err);
377 });
378 } else {
379 saveCisterna();
380 }
381 };
382 379
383 function saveCisterna () { 380 validaCodigo(cisterna);
384 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); 381 cisterna.id = 0;
385 delete $scope.cisterna.vehiculo; 382 };
386 if (!$scope.cisterna.id) {
387 $timeout(function() { $scope.cisternas.push($scope.cisterna);});
388 }
389 }
390 383
391 if ($routeParams.idx !== -1) { 384 if ($routeParams.idx !== -1) {
392 $scope.cisterna = [$routeParams.idx]; 385 $scope.cisterna = [$routeParams.idx];
393 focaAbmVehiculoService 386 focaAbmVehiculoService
394 .getCisternas($routeParams.idVehiculo) 387 .getCisternas($routeParams.idVehiculo)
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { 2 .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 var cisternas = []; 3 var cisternas = [];
4 var cisternasPristine = true; 4 var cisternasPristine = true;
5 return { 5 return {
6 getVehiculos: function() { 6 getVehiculos: function() {
7 return $http.get(API_ENDPOINT.URL + '/vehiculo'); 7 return $http.get(API_ENDPOINT.URL + '/vehiculo');
8 }, 8 },
9 getVehiculo: function(id) { 9 getVehiculo: function(id) {
10 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); 10 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id);
11 }, 11 },
12 getTransportistas: function() { 12 getTransportistas: function() {
13 return $http.get(API_ENDPOINT.URL + '/transportista'); 13 return $http.get(API_ENDPOINT.URL + '/transportista');
14 }, 14 },
15 guardarVehiculo: function(vehiculo) { 15 guardarVehiculo: function(vehiculo) {
16 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); 16 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo});
17 }, 17 },
18 deleteVehiculo: function(id) { 18 deleteVehiculo: function(id) {
19 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); 19 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id);
20 }, 20 },
21 getCisternas: function(idVehiculo) { 21 getCisternas: function(idVehiculo) {
22 if (cisternas.length) {
23 cisternasPristine = true;
24 return Promise.resolve(angular.copy(cisternas));
25 } else {
26 cisternasPristine = true; 22 cisternasPristine = true;
27 return new Promise(function(resolve) { 23 return new Promise(function(resolve) {
28 $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) 24 $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo)
29 .then(function(res) { 25 .then(function(res) {
30 cisternas = res.data; 26 cisternas = res.data;
31 resolve(res.data); 27 resolve(res.data);
32 }); 28 });
33 }); 29 });
34 }
35 }, 30 },
36 guardarCisterna: function(cisterna, idx) { 31 guardarCisterna: function(cisterna, idx) {
37 if (idx !== '-1') { 32 if (idx !== '-1') {
38 //update 33 //update
39 cisternas[idx] = cisterna; 34 cisternas[idx] = cisterna;
40 cisternasPristine = false; 35 cisternasPristine = false;
41 } else { 36 } else {
42 //insert 37 //insert
43 cisternas.push(cisterna); 38 cisternas.push(cisterna);
44 cisternasPristine = false; 39 cisternasPristine = false;
45 } 40 }
46 }, 41 },
47 guardarCisternas: function(cisternas) { 42 guardarCisternas: function(cisternas) {
48 return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); 43 return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas});
49 }, 44 },
50 deleteCisterna: function(cisterna) { 45 deleteCisterna: function(cisterna) {
51 cisterna.desactivado = true; 46 cisterna.desactivado = true;
52 cisternasPristine = false; 47 cisternasPristine = false;
53 return $http.delete(API_ENDPOINT.URL + '/cisterna/' + cisterna.id); 48 return $http.delete(API_ENDPOINT.URL + '/cisterna/' + cisterna.id);
54 }, 49 },
55 cleanCisternas: function() { 50 cleanCisternas: function() {
56 cisternas = []; 51 cisternas = [];
57 }, 52 },
58 getVehiculosPorTransportista: function(id) { 53 getVehiculosPorTransportista: function(id) {
59 return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); 54 return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id);
60 }, 55 },
61 getTransportistaPorId: function(id) { 56 getTransportistaPorId: function(id) {
62 return $http.get(API_ENDPOINT.URL + '/transportista/' + id); 57 return $http.get(API_ENDPOINT.URL + '/transportista/' + id);
63 }, 58 },
64 transportistaSeleccionado: {} 59 transportistaSeleccionado: {}
65 }; 60 };
66 }]); 61 }]);
67 62
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="text-center px-4">Código</th> 80 <th class="text-center px-4">Código</th>
81 <th class="text-center">Capacidad</th> 81 <th class="text-center">Capacidad</th>
82 <th class="text-center">Unidad de Medida</th> 82 <th class="text-center">Unidad de Medida</th>
83 <th class="text-center"> 83 <th class="text-center">
84 <button 84 <button
85 class="btn btn-outline-debo boton-accion" 85 class="btn btn-outline-debo boton-accion"
86 title="Agregar" 86 title="Agregar"
87 ng-click="editar('nuevo')"> 87 ng-click="crearCisterna()"
88 ng-disabled="crear">
88 <i class="fa fa-plus"></i> 89 <i class="fa fa-plus"></i>
89 </button> 90 </button>
90 </th> 91 </th>
91 </tr> 92 </tr>
92 </thead> 93 </thead>
93 <tbody> 94 <tbody>
94 <tr ng-show="creando"> 95 <tr ng-show="creando">
95 <td align="center"> 96 <td align="center">
96 <input 97 <input
97 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" 98 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
98 ng-model="cisterna.codigo" 99 ng-model="cisterna.codigo"
99 ng-keypress="next($event.keyCode)" 100 ng-keypress="next($event.keyCode)"
100 foca-focus="focused == 1" 101 foca-focus="focused == 1"
101 ng-focus="focused = 1" 102 ng-focus="focused = 1"
102 ng-disabled="!nuevoCisterna" 103 ng-disabled="!nuevoCisterna"
103 teclado-virtual 104 teclado-virtual
104 > 105 >
105 </td> 106 </td>
106 <td align="center"> 107 <td align="center">
107 <input 108 <input
108 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" 109 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
109 teclado-virtual 110 teclado-virtual
110 foca-tipo-input 111 foca-tipo-input
111 ng-model="cisterna.capacidad" 112 ng-model="cisterna.capacidad"
112 ng-required="true" 113 ng-required="true"
113 ng-keypress="next($event.keyCode)" 114 ng-keypress="next($event.keyCode)"
114 foca-focus="focused == 2" 115 foca-focus="focused == 2"
115 ng-focus="focused = 2" 116 ng-focus="focused = 2"
116 > 117 >
117 </td> 118 </td>
118 <td align="center"> 119 <td align="center">
119 <div class="input-group"> 120 <div class="input-group">
120 <input 121 <input
121 ng-model="cisterna.unidadMedida.NOM" 122 ng-model="cisterna.unidadMedida.NOM"
122 class="form-control" 123 class="form-control"
123 readonly 124 readonly
124 /> 125 />
125 <div class="input-group-append"> 126 <div class="input-group-append">
126 <button 127 <button
127 ladda="searchLoading" 128 ladda="searchLoading"
128 class="btn btn-outline-secondary form-control" 129 class="btn btn-outline-secondary form-control"
129 type="button" 130 type="button"
130 ng-click="seleccionarUnidadMedida()" 131 ng-click="seleccionarUnidadMedida()"
131 foca-focus="focused == 3" 132 foca-focus="focused == 3"
132 > 133 >
133 <i class="fa fa-search" aria-hidden="true"></i> 134 <i class="fa fa-search" aria-hidden="true"></i>
134 </button> 135 </button>
135 </div> 136 </div>
136 </div> 137 </div>
137 </td> 138 </td>
138 <td align="center"> 139 <td align="center">
139 <button 140 <button
140 class="btn btn-outline-dark boton-accion" 141 class="btn btn-outline-dark boton-accion"
141 ng-click="agregarCisterna()" 142 ng-click="agregarCisterna()"
142 > 143 >
143 <i class="fa fa-save"></i> 144 <i class="fa fa-save"></i>
144 </button> 145 </button>
145 </td> 146 </td>
146 </tr> 147 </tr>
147 148
148 <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" 149 <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" ng-hide="cisterna.desactivado">
149 ng-show="!cisterna.desactivado"> 150 <td ng-bind="cisterna.codigo" class="text-center" ng-hide="cisterna.editando"></td>
150 <td ng-bind="cisterna.codigo" class="text-center"></td> 151 <td align="center" ng-show="cisterna.editando">
151 <td ng-bind="cisterna.capacidad" class="text-center"></td> 152 <input
152 <td ng-bind="cisterna.unidadMedida.NOM" class="text-center"></td> 153 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
153 <td class="text-center"> 154 ng-model="cisterna.codigo"
155 ng-keypress="next($event.keyCode)"
156 foca-focus="focused == 1"
157 ng-focus="focused = 1"
158 teclado-virtual
159 esc-key="volver(cisterna, key)"
160 >
161 </td>
162 <td ng-bind="cisterna.capacidad" class="text-center" ng-hide="cisterna.editando"></td>
163 <td align="center" ng-show="cisterna.editando" >
164 <input
165 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
166 teclado-virtual
167 foca-tipo-input
168 ng-model="cisterna.capacidad"
169 ng-required="true"
170 ng-keypress="next($event.keyCode)"
171 foca-focus="focused == 2"
172 ng-focus="focused = 2"
173 esc-key="volver(cisterna, key)"
174 >
175 </td>
176 <td ng-bind="cisterna.unidadMedida.NOM" class="text-center" ng-hide="cisterna.editando"></td>
177 <td align="center" ng-show="cisterna.editando">
178 <div class="input-group">
179 <input
180 ng-model="cisterna.unidadMedida.NOM"
181 class="form-control"
182 readonly
183 esc-key="volver(cisterna, key)"
184 />
185 <div class="input-group-append">
186 <button
187 ladda="searchLoading"
188 class="btn btn-outline-secondary form-control"
189 type="button"
190 ng-click="seleccionarUnidadMedida(cisterna)"
191 foca-focus="focused == 3"
192 >
193 <i class="fa fa-search" aria-hidden="true"></i>
194 </button>
195 </div>
196 </div>
197 </td>
198 <td class="text-center" ng-hide="cisterna.editando">
154 <button 199 <button
155 class="btn btn-outline-dark boton-accion" 200 class="btn btn-outline-dark boton-accion"
156 title="Editar" 201 title="Editar"
157 ng-click="editar('',cisterna)" 202 ng-click="editar(cisterna)"
158 > 203 >
159 <i class="fa fa-pencil"></i> 204 <i class="fa fa-pencil"></i>
160 </button> 205 </button>
161 <button 206 <button
162 class="btn btn-outline-dark boton-accion" 207 class="btn btn-outline-dark boton-accion"
163 title="Eliminar" 208 title="Eliminar"
164 ng-click="solicitarConfirmacionTabla(cisterna,$index)" 209 ng-click="solicitarConfirmacionTabla(cisterna, $index)"
165 > 210 >
166 <i class="fa fa-trash"></i> 211 <i class="fa fa-trash"></i>
167 </button> 212 </button>
168 </td> 213 </td>
214 <td align="center" ng-show="cisterna.editando" >
215 <button
216 class="btn btn-outline-dark boton-accion"
217 ng-click="agregarCisterna(cisterna)"
218 >
219 <i class="fa fa-save"></i>
220 </button>
221 <button
222 class="btn btn-outline-dark boton-accion"
223 ng-click="volver(cisterna, key)"
224 >
225 <i class="fa fa-undo" aria-hidden="true"></i>
226 </button>
227 </td>
228 </tr>
229
230 <tr ng-repeat="(key, cisterna) in cisternas" ng-show="false">
169 </tr> 231 </tr>
232
170 </body> 233 </body>
171 </table> 234 </table>
172 </div> 235 </div>
173 </div> 236 </div>
174 </div> 237 </div>
175 238