Commit 3289c8f85b3b5a4a33ef083ebf9926bc98af4263

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master

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