diff --git a/package.json b/package.json index 6a6b17c..67ab9f9 100644 --- a/package.json +++ b/package.json @@ -34,14 +34,14 @@ "pump": "^3.0.x" }, "devDependencies": { - "angular": "^1.7.7", - "angular-mocks": "^1.7.7", - "angular-route": "^1.7.7", + "angular": "^1.7.8", + "angular-mocks": "^1.7.8", + "angular-route": "^1.7.8", "bootstrap": "^4.2.1", "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", "font-awesome": "^4.7.0", "gulp": "^3.9.1", - "gulp-angular-templatecache": "^2.2.6", + "gulp-angular-templatecache": "^2.2.7", "gulp-clean": "^0.4.0", "gulp-connect": "^5.7.0", "gulp-htmlmin": "^5.0.1", @@ -51,11 +51,14 @@ "gulp-sequence": "^1.0.0", "gulp-uglify": "^3.0.1", "gulp-uglify-es": "^1.0.4", - "jasmine-core": "^3.3.0", - "jquery": "^3.3.1", - "jshint": "^2.10.1", + "jasmine-core": "^3.4.0", + "jquery": "^3.4.1", + "jshint": "^2.10.2", "pre-commit": "^1.2.2", "pump": "^3.0.0", "ui-bootstrap4": "^3.0.6" + }, + "dependencies": { + "popper.js": "^1.15.0" } } diff --git a/src/js/controller.js b/src/js/controller.js index 044aa78..5ab7ddd 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,27 +1,87 @@ angular.module('focaAbmPreciosCondiciones') .controller('focaAbmPreciosCondicionesController', [ '$scope', 'focaAbmPreciosCondicionesService', '$location', - 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage', + 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage','$routeParams','$uibModal', function($scope, focaAbmPreciosCondicionesService, $location, - focaModalService, focaBotoneraLateralService, $timeout, $localStorage) { + focaModalService, focaBotoneraLateralService, $timeout, $localStorage,$routeParams, $uibModal) { $scope.focusSearch = false; $scope.filters = ''; $scope.now = new Date(); + $scope.creando = false; + $scope.crear = false; + $scope.listaPrecioLabel = ''; + $scope.mostrarPlazos = $routeParams.id > 0; + $timeout(function() { focaBotoneraLateralService.showSalir(true); focaBotoneraLateralService.showPausar(false); focaBotoneraLateralService.showCancelar(false); - focaBotoneraLateralService.showGuardar(false); + focaBotoneraLateralService.showGuardar(true, $scope.guardar); $scope.focusSearch = true; }); - $scope.filters = ''; - $scope.now = new Date(); - $scope.editar = function(id) { - $location.path('/precio-condicion/' + id); + $scope.crearPrecioYCondicion = function () { + $scope.precioCondicion = { + id: 0, + codigo: '', + nombre: '', + idListaPrecio: 0, + vigencia: new Date(), + editando: true, + activo: true, + plazos: { + dias: 0 + } + }; + $scope.crear = false; + $scope.preciosCondiciones.unshift($scope.precioCondicion); + console.log('Nuevo:', $scope.precioCondicion); + }; + + $scope.guardarBD = function () { + console.log('Guardar BD: ', $scope.preciosCondiciones); + }; + + $scope.agregarPrecioYCondicion = function (precioCondicion) { + //push a plazos + if (!precioCondicion.nombre) { + focaModalService.alert('Ingrese un nombre'); + return; + } else if (!precioCondicion.listaPrecio) { + focaModalService.alert('Seleccione un precio'); + return; + } else if (!precioCondicion.plazos || precioCondicion.plazos === 0) { + focaModalService.alert('Ingrese almenos un plazo'); + return; + } + //Plazo + + precioCondicion.editando = false; + $scope.crear = true; + }; + + $scope.editar = function(precioCondicion) { + $scope.preciosCondiciones.forEach( function(precioCondicion) { + precioCondicion.editando = false; + $scope.crear = false; + }); + precioCondicion.editando = true; + $scope.inicial = angular.copy(precioCondicion); + }; + + $scope.volver = function (precioCondicion, key) { + if (precioCondicion.id === 0) { + $scope.preciosCondiciones.shift(); + $scope.crear = true; + } else { + $scope.preciosCondiciones[key] = $scope.inicial; + $scope.preciosCondiciones[key].editando = false; + $scope.crear = true; + } }; + $scope.solicitarConfirmacion = function(precioCondicion) { focaModalService.confirm('¿Está seguro que desea borrar el precio condición' + precioCondicion.codigo + ' ' + precioCondicion.nombre + ' ?').then( @@ -38,25 +98,126 @@ angular.module('focaAbmPreciosCondiciones') }; $scope.buscar = function(key) { - if(key === 13){ + if (key === 13) { + $scope.crear = true; focaAbmPreciosCondicionesService .obtenerPreciosCondiciones($scope.filters) .then(function(datos) { $scope.preciosCondiciones = datos.data; $scope.preciosCondiciones.forEach(function(precioCondicion) { precioCondicion.plazoPago.sort(function(a, b) { - return a.dias- b.dias; + return a.dias - b.dias; }); }); }); } }; + $scope.seleccionarListaPrecio = function(key) { + if (key === 13){ + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Listas de precio', + templateUrl: 'modal-lista-precio.html', + controller: 'focaModalListaPrecioCtrl', + size: 'lg' + } + ); + modalInstance.result.then(function(listaPrecio) { + $scope.precioCondicion.idListaPrecio = listaPrecio.ID; + $scope.precioCondicion.listaPrecio = listaPrecio; + $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; + $scope.focused = 4; + }); + } + }; + + $scope.verProductosListaPrecio = function() { + $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Productos', + templateUrl: 'modal-busqueda-productos.html', + controller: 'modalBusquedaProductosCtrl', + resolve: { + parametroProducto: { + idLista: $scope.precioCondicion.listaPrecio.ID, + cotizacion: 1, + simbolo: '$', + soloMostrar: true + } + }, + size: 'md' + } + ); + }; + if ($localStorage.precioCondicion) { var precioCondicion = JSON.parse($localStorage.precioCondicion); if (!precioCondicion.id) { precioCondicion.id = 0; } $location.path('/precio-condicion/' + precioCondicion.id); } + + + //Guardar + $scope.guardar = function() { + + var promises = []; + var precioCondicion = $scope.precioCondicion; + precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; + // delete precioCondicion.listaPrecio; + if ($scope.mostrarPlazos) { + promises.push( + focaAbmPreciosCondicionesService + .guardarPlazosPago($scope.precioCondicion.plazos) + ); + $scope.plazosAEliminar.forEach(function(id) { + promises.push( + focaAbmPreciosCondicionesService + .borrarPlazoPago(id) + ); + }); + } + promises.push( + focaAbmPreciosCondicionesService + .guardarPrecioCondicion(precioCondicion) + ); + + Promise.all(promises).then(function() { + $timeout(function() { + $location.path('/precio-condicion'); + }, 0); + }, function(err){ + console.error(err); + }); + }; + + // Plazo pago + + // focaAbmPreciosCondicionesService.obtenerPrecioCondicion($scope.filters) + // .then(function(datos) { + // console.log('Precios y condiciones: ', datos); + // if (datos.data.id) { + // $scope.precioCondicion = datos.data; + // $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() + + // ' - ' + datos.data.listaPrecio.DES; + // $scope.$broadcast('addCabecera', { + // label: 'Precio y condición:', + // valor: datos.data.nombre + // }); + // focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id) + // .then(function(datos) { + // console.log('Plazos Pago: ', datos); + // $scope.precioCondicion.plazos = datos.data; + // $scope.precioCondicion.plazos.sort(function(a, b) { + // return a.dias- b.dias; + // }); + // $scope.plazoACargar = + // { + // item: datos.data.length + 1 + // }; + // }); + // } + // }); } ]) .controller('focaAbmPrecioCondicionController', [ @@ -78,29 +239,30 @@ angular.module('focaAbmPreciosCondiciones') idListaPrecio: 0, vigencia: new Date() }; - focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id) - .then(function(datos) { - if (datos.data.id) { - $scope.precioCondicion = datos.data; - $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() + - ' - ' + datos.data.listaPrecio.DES; - $scope.$broadcast('addCabecera', { - label: 'Precio y condición:', - valor: datos.data.nombre - }); - focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id) - .then(function(datos) { - $scope.precioCondicion.plazos = datos.data; - $scope.precioCondicion.plazos.sort(function(a, b) { - return a.dias- b.dias; - }); - $scope.plazoACargar = - { - item: datos.data.length + 1 - }; - }); - } - }); + // focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id) + // .then(function(datos) { + // if (datos.data.id) { + // $scope.precioCondicion = datos.data; + // $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() + + // ' - ' + datos.data.listaPrecio.DES; + // $scope.$broadcast('addCabecera', { + // label: 'Precio y condición:', + // valor: datos.data.nombre + // }); + // focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id) + // .then(function(datos) { + // console.log('Datos: ', datos); + // $scope.precioCondicion.plazos = datos.data; + // $scope.precioCondicion.plazos.sort(function(a, b) { + // return a.dias- b.dias; + // }); + // $scope.plazoACargar = + // { + // item: datos.data.length + 1 + // }; + // }); + // } + // }); $timeout(function() {getLSPrecioC();}); @@ -126,132 +288,91 @@ angular.module('focaAbmPreciosCondiciones') $location.path('/precio-condicion'); } }; - $scope.guardar = function() { - - if (!$scope.precioCondicion.nombre) { - focaModalService.alert('Ingrese nombre'); - return; - } else if (!$scope.precioCondicion.descripcion) { - focaModalService.alert('Ingrese descripcion'); - return; - } else if (!$scope.precioCondicion.idListaPrecio) { - focaModalService.alert('Seleccione precio'); - return; - } - - var promises = []; - var precioCondicion = $scope.precioCondicion; - precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; - delete precioCondicion.listaPrecio; - if ($scope.mostrarPlazos) { - promises.push( - focaAbmPreciosCondicionesService - .guardarPlazosPago($scope.precioCondicion.plazos) - ); - $scope.plazosAEliminar.forEach(function(id) { - promises.push( - focaAbmPreciosCondicionesService - .borrarPlazoPago(id) - ); - }); - } - promises.push( - focaAbmPreciosCondicionesService - .guardarPrecioCondicion(precioCondicion) - ); - - Promise.all(promises).then(function() { - $timeout(function() { - $location.path('/precio-condicion'); - }, 0); - }, function(err){ - console.error(err); - }); - }; + - $scope.agregarPlazo = function(key) { - if (key === 13) { - if (!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) { - focaModalService.alert('Ingrese cantidad de días'); - return; - } - var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { - return a.dias === $scope.plazoACargar.dias; - }); - if (tieneEseDia.length > 0) { - focaModalService.alert('Ya ha ingresado un plazo con esos días'); - return; - } - $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id; - $scope.plazoACargar.activo = true; - $scope.precioCondicion.plazos.push($scope.plazoACargar); - $scope.plazoACargar = - { - item: $scope.precioCondicion.plazos.length + 1 - }; - } - }; - $scope.quitarPlazo = function(key) { - if ($scope.precioCondicion.plazos[key].id) - $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); + // $scope.agregarPlazo = function(key) { + // if (key === 13) { + // if (!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) { + // focaModalService.alert('Ingrese cantidad de días'); + // return; + // } + // var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { + // return a.dias === $scope.plazoACargar.dias; + // }); + // if (tieneEseDia.length > 0) { + // focaModalService.alert('Ya ha ingresado un plazo con esos días'); + // return; + // } + // $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id; + // $scope.plazoACargar.activo = true; + // $scope.precioCondicion.plazos.push($scope.plazoACargar); + // $scope.plazoACargar = + // { + // item: $scope.precioCondicion.plazos.length + 1 + // }; + // } + // }; + // $scope.quitarPlazo = function(key) { + // if ($scope.precioCondicion.plazos[key].id) + // $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); - $scope.precioCondicion.plazos.splice(key, 1); - $scope.plazoACargar = - { - item: $scope.precioCondicion.plazos.length + 1 - }; - }; - $scope.solicitarConfirmacionPlazoPago = function(plazoPago) { - focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' + - plazoPago.item + ' ' + plazoPago.dias + ' ?').then( - function(confirm) { - if (confirm) { - focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id); - $scope.precioCondicion.plazos.splice( - $scope.precioCondicion.plazos.indexOf(plazoPago), 1 - ); - } - } - ); - }; + // $scope.precioCondicion.plazos.splice(key, 1); + // $scope.plazoACargar = + // { + // item: $scope.precioCondicion.plazos.length + 1 + // }; + // }; + // $scope.solicitarConfirmacionPlazoPago = function(plazoPago) { + // focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' + + // plazoPago.item + ' ' + plazoPago.dias + ' ?').then( + // function(confirm) { + // if (confirm) { + // focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id); + // $scope.precioCondicion.plazos.splice( + // $scope.precioCondicion.plazos.indexOf(plazoPago), 1 + // ); + // } + // } + // ); + // }; - $scope.seleccionarListaPrecio = function(key) { - if (key === 13){ - var modalInstance = $uibModal.open( - { - ariaLabelledBy: 'Busqueda de Listas de precio', - templateUrl: 'modal-lista-precio.html', - controller: 'focaModalListaPrecioCtrl', - size: 'lg' - } - ); - modalInstance.result.then(function(listaPrecio) { - $scope.precioCondicion.idListaPrecio = listaPrecio.ID; - $scope.precioCondicion.listaPrecio = listaPrecio; - $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; - $scope.focused = 4; - }); - } - }; + // $scope.seleccionarListaPrecio = function(key) { + // if (key === 13){ + // var modalInstance = $uibModal.open( + // { + // ariaLabelledBy: 'Busqueda de Listas de precio', + // templateUrl: 'modal-lista-precio.html', + // controller: 'focaModalListaPrecioCtrl', + // size: 'lg' + // } + // ); + // modalInstance.result.then(function(listaPrecio) { + // $scope.precioCondicion.idListaPrecio = listaPrecio.ID; + // $scope.precioCondicion.listaPrecio = listaPrecio; + // $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; + // $scope.focused = 4; + // }); + // } + // }; - $scope.verProductosListaPrecio = function() { - $uibModal.open( - { - ariaLabelledBy: 'Busqueda de Productos', - templateUrl: 'modal-busqueda-productos.html', - controller: 'modalBusquedaProductosCtrl', - resolve: { - parametroProducto: { - idLista: $scope.precioCondicion.listaPrecio.ID, - cotizacion: 1, - simbolo: '$', - soloMostrar: true - } - }, - size: 'md' - } - ); - }; + // $scope.verProductosListaPrecio = function() { + // $uibModal.open( + // { + // ariaLabelledBy: 'Busqueda de Productos', + // templateUrl: 'modal-busqueda-productos.html', + // controller: 'modalBusquedaProductosCtrl', + // resolve: { + // parametroProducto: { + // idLista: $scope.precioCondicion.listaPrecio.ID, + // cotizacion: 1, + // simbolo: '$', + // soloMostrar: true + // } + // }, + // size: 'md' + // } + // ); + // }; $scope.next = function(key) { if (key === 13) $scope.focused++; diff --git a/src/js/service.js b/src/js/service.js index cad963c..f28c76f 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -20,7 +20,7 @@ angular.module('focaAbmPreciosCondiciones') }, obtenerPlazoPago: function(idPrecioCondicion) { return $http.get( - API_ENDPOINT.URL + '/plazo-pago/precio-condicion/' + idPrecioCondicion + API_ENDPOINT.URL + '/precio-condicion/plazo-pago/' + idPrecioCondicion ); }, borrarPlazoPago: function(id) { diff --git a/src/views/foca-abm-precios-condiciones-item.html b/src/views/foca-abm-precios-condiciones-item.html index 4eb61ce..ec8917a 100644 --- a/src/views/foca-abm-precios-condiciones-item.html +++ b/src/views/foca-abm-precios-condiciones-item.html @@ -47,7 +47,7 @@
-
+
- +
@@ -38,28 +38,106 @@ - - - - - + + + + + + + - + + + +
CódigoPlazos
+ + + + + +
+ +
+ + +
+
+
+ + ng-bind="$last ? plazo.dias : plazo.dias + ', '" + > + + + + + + +
diff --git a/src/views/foca-abm-precios-condiciones-modal-confirmar.html b/src/views/foca-abm-precios-condiciones-modal-confirmar.html index 799dccf..695b61f 100644 --- a/src/views/foca-abm-precios-condiciones-modal-confirmar.html +++ b/src/views/foca-abm-precios-condiciones-modal-confirmar.html @@ -3,7 +3,7 @@