diff --git a/src/js/controller.js b/src/js/controller.js index 2a7f9cd..48239ac 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,11 +1,14 @@ angular.module('focaAbmVehiculo') .controller('focaAbmVehiculosController', [ - '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', - function($scope, focaAbmVehiculoService, $location, focaModalService) { - focaAbmVehiculoService.getVehiculos().then(function(datos) { - $scope.vehiculos = datos.data; - $scope.vehiculosFiltrados = $scope.vehiculos; - }); + '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', '$uibModal', + function($scope, focaAbmVehiculoService, $location, focaModalService, $uibModal) { + $scope.buscar = function(idTransportista) { + focaAbmVehiculoService + .getVehiculosPorTransportista(idTransportista) + .then(function(datos) { + $scope.vehiculos = datos.data; + }); + }; $scope.editar = function(id) { $location.path('/vehiculo/' + id); }; @@ -20,29 +23,94 @@ angular.module('focaAbmVehiculo') } ); }; + $scope.seleccionarTransportista = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Transportista', + templateUrl: 'modal-proveedor.html', + controller: 'focaModalProveedorCtrl', + size: 'lg', + resolve: { + transportista: function() { + return true; + } + } + } + ); + modalInstance.result.then( + function(transprotista) { + $scope.buscar(transprotista.COD); + $scope.filtros = transprotista.NOM.trim(); + }, function() { + + } + ); + }; } ]) .controller('focaAbmVehiculoController', [ - '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', - function($scope, focaAbmVehiculoService, $routeParams, $location) { - focaAbmVehiculoService.getVehiculo($routeParams.id).then(function(res) { - if(!res.data[0].transportista.COD) { - res.data[0].transportista = ''; - } - $scope.vehiculo = res.data[0]; + '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', + 'focaModalService', + function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, + focaModalService) { + $scope.nuevo = $routeParams.idVehiculo == 0 ? true : false; + $scope.vehiculo = {}; + focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { + if(res.data) $scope.vehiculo = res.data; }); - focaAbmVehiculoService.getTransportistas().then(function(res) { - $scope.transportistas = res.data; + focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo) + .then(function(res) { + $scope.cisternas = res.data; }); $scope.cancelar = function() { $location.path('/vehiculo'); }; + $scope.editar = function(id) { + $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/' + id); + }; $scope.guardar = function() { - $scope.vehiculo.idTransportista = $scope.vehiculo.transportista.COD; + if(!$scope.vehiculo.transportista){ + focaModalService.alert('Elija Transportista'); + return; + } delete $scope.vehiculo.transportista; - focaAbmVehiculoService.guerdarVehiculo($scope.vehiculo).then(function() { - $location.path('/vehiculo'); + focaAbmVehiculoService.guerdarVehiculo($scope.vehiculo).then(function(res) { + $location.path('/vehiculo/' + res.data.id); }); }; + $scope.solicitarConfirmacionCisterna = function(cisterna) { + focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + + cisterna.id + ' ' + cisterna.codigo + ' ?').then( + function(data) { + if(data) { + focaAbmVehiculoService.deleteCisterna(cisterna.id); + $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1); + } + } + ); + }; + $scope.seleccionarTransportista = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Transportista', + templateUrl: 'modal-proveedor.html', + controller: 'focaModalProveedorCtrl', + size: 'lg', + resolve: { + transportista: function() { + return true; + } + } + } + ); + modalInstance.result.then( + function(transprotista) { + $scope.vehiculo.idTransportista = transprotista.COD; + $scope.vehiculo.transportista = transprotista; + }, function() { + + } + ); + }; } ]); diff --git a/src/js/controllerCisterna.js b/src/js/controllerCisterna.js new file mode 100644 index 0000000..8a96a1f --- /dev/null +++ b/src/js/controllerCisterna.js @@ -0,0 +1,84 @@ +angular.module('focaAbmVehiculo') + .controller('focaAbmVehiculoCisternaController', [ + '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', + 'focaModalService', + function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, + focaModalService) { + $scope.editar = false; + $scope.cisterna = { + cisternaCarga: { + articulo: {} + } + }; + + focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) { + if(res.data) { + $scope.cisterna = res.data; + $scope.editar = true; + }else { + $scope.editar = false; + } + }); + $scope.cancelar = function() { + $location.path('/vehiculo/' + $routeParams.idVehiculo); + console.log($routeParams.id); + }; + $scope.guardar = function() { + if(!$scope.cisterna.unidadMedida) { + focaModalService.alert('Ingrese unidad de medida'); + return; + } + if(!$scope.cisterna.cisternaCarga.articulo) { + focaModalService.alert('Ingrese producto'); + return; + } + $scope.cisterna.idVehiculo = $routeParams.idVehiculo; + delete $scope.cisterna.unidadMedida; + delete $scope.cisterna.cisternaCarga.articulo; + focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function() { + $location.path('/vehiculo/' + $routeParams.idVehiculo); + }); + }; + + // $scope.seleccionarArticulo = function() { + // var modalInstance = $uibModal.open( + // { + // ariaLabelledBy: 'Busqueda de Productos', + // templateUrl: 'modal-busqueda-productos.html', + // controller: 'modalBusquedaProductosCtrl', + // resolve: { + // parametroProducto: { + // idLista: -1, + // cotizacion: 1, + // simbolo: '$' + // } + // }, + // size: 'lg' + // } + // ); + // modalInstance.result.then( + // function(producto) { + // $scope.cisterna.cisternaCarga.idProducto = producto.id, + // $scope.cisterna.cisternaCarga.articulo.DetArt = producto.descripcion; + // }, function() { + // // funcion ejecutada cuando se cancela el modal + // } + // ); + // }; + + $scope.seleccionarUnidadMedida = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Unidades de medida', + templateUrl: 'modal-unidad-medida.html', + controller: 'focaModalUnidadMedidaCtrl', + size: 'lg' + } + ); + modalInstance.result.then(function(unidaMedida) { + $scope.cisterna.idUnidadMedida = unidaMedida.ID; + $scope.cisterna.unidadMedida = unidaMedida; + }); + } + } + ]); \ No newline at end of file diff --git a/src/js/route.js b/src/js/route.js index a73b946..d44a0b5 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -11,9 +11,18 @@ angular.module('focaAbmVehiculo') .config([ '$routeProvider', function($routeProvider) { - $routeProvider.when('/vehiculo/:id', { + $routeProvider.when('/vehiculo/:idVehiculo', { controller: 'focaAbmVehiculoController', templateUrl: 'src/views/foca-abm-vehiculos-item.html' }); } + ]) + .config([ + '$routeProvider', + function($routeProvider) { + $routeProvider.when('/vehiculo/:idVehiculo/cisterna/:id', { + controller: 'focaAbmVehiculoCisternaController', + templateUrl: 'src/views/foca-abm-cisterna-item.html' + }); + } ]); diff --git a/src/js/service.js b/src/js/service.js index 729416d..6192bbc 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -15,6 +15,21 @@ angular.module('focaAbmVehiculo') }, deleteVehiculo: function(id) { return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); + }, + getCisternadoPorVehiculo: function(idVehiculo) { + return $http.get(API_ENDPOINT.URL + '/cisterna/listar/vehiculo/' + idVehiculo); + }, + getCisterna: function(id) { + return $http.get(API_ENDPOINT.URL + '/cisterna/' + id); + }, + guardarCisterna: function(cisterna) { + return $http.post(API_ENDPOINT.URL + '/cisterna/guardar', {cisterna: cisterna}); + }, + deleteCisterna: function(id) { + return $http.delete(API_ENDPOINT.URL + '/cisterna/borrar/' + id); + }, + getVehiculosPorTransportista: function(id) { + return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); } }; }]); diff --git a/src/views/foca-abm-cisterna-item.html b/src/views/foca-abm-cisterna-item.html new file mode 100644 index 0000000..50c79d8 --- /dev/null +++ b/src/views/foca-abm-cisterna-item.html @@ -0,0 +1,92 @@ +

Cisterna

+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ + +
+
+
+
+ + +
+
+
diff --git a/src/views/foca-abm-vehiculos-item.html b/src/views/foca-abm-vehiculos-item.html index 5f7d091..d420431 100644 --- a/src/views/foca-abm-vehiculos-item.html +++ b/src/views/foca-abm-vehiculos-item.html @@ -1,18 +1,23 @@ -

Sectores

+

Vehiculo

-
+
+
+ +
@@ -22,8 +27,7 @@ class="form-control" type="text" teclado-virtual - ng-model="vehiculo.id" - readonly + ng-model="vehiculo.codigo" />
@@ -64,18 +68,6 @@
- -
- -
-
-
+
+

Cisternas

+ + + + + + + + + + + + + + + + + + + +
CódigoUnidad de MedidaCapacidadCarga + +
+ + +
+
diff --git a/src/views/foca-abm-vehiculos-listado.html b/src/views/foca-abm-vehiculos-listado.html index 7de59f8..b1a06ed 100644 --- a/src/views/foca-abm-vehiculos-listado.html +++ b/src/views/foca-abm-vehiculos-listado.html @@ -1,6 +1,19 @@

Vehiculos

-
+
+ +
+ +
+
+ - - + - + -
CódigoTransportistaCódigo Tractor Capacidad @@ -24,9 +36,8 @@