Commit 47f6ee51e8ec417b719e4c331f1677914285fafe
1 parent
2dfe129876
Exists in
master
and in
1 other branch
Cambio en la seleccion de lista de precios y el abm de plazos
Showing
1 changed file
with
44 additions
and
22 deletions
Show diff stats
src/js/controller.js
| 1 | angular.module('focaModalPrecioCondicion') | 1 | angular.module('focaModalPrecioCondicion') |
| 2 | .controller('focaModalPrecioCondicionController', | 2 | .controller('focaModalPrecioCondicionController', |
| 3 | [ | 3 | [ |
| 4 | '$timeout', | 4 | '$timeout', |
| 5 | '$filter', | 5 | '$filter', |
| 6 | '$scope', | 6 | '$scope', |
| 7 | '$uibModal', | 7 | '$uibModal', |
| 8 | '$uibModalInstance', | 8 | '$uibModalInstance', |
| 9 | 'focaModalService', | 9 | 'focaModalService', |
| 10 | 'focaModalPrecioCondicionService', | 10 | 'focaModalPrecioCondicionService', |
| 11 | 'idListaPrecio', | 11 | 'idListaPrecio', |
| 12 | 'idCliente', | 12 | 'idCliente', |
| 13 | function ( | 13 | function ( |
| 14 | $timeout, $filter, $scope, $uibModal, $uibModalInstance, | 14 | $timeout, $filter, $scope, $uibModal, $uibModalInstance, |
| 15 | focaModalService, focaModalPrecioCondicionService, idListaPrecio, idCliente | 15 | focaModalService, focaModalPrecioCondicionService, idListaPrecio, idCliente |
| 16 | ) { | 16 | ) { |
| 17 | $scope.plazos = [{ dias: 0 }]; | 17 | $scope.plazos = [ |
| 18 | $scope.editingPlazo = false; | 18 | { |
| 19 | dias: 0, | ||
| 20 | id_cliente: idCliente, | ||
| 21 | activo: true | ||
| 22 | } | ||
| 23 | ]; | ||
| 19 | $scope.openModalListaDePrecios = false; | 24 | $scope.openModalListaDePrecios = false; |
| 20 | $scope.associatedList = true; | 25 | $scope.associatedList = true; |
| 21 | $scope.listaDePreciosAlternativa = null; | 26 | $scope.listaDePreciosAlternativa = null; |
| 22 | 27 | ||
| 23 | onInit(); | 28 | onInit(); |
| 24 | 29 | ||
| 25 | function onInit() { | 30 | function onInit() { |
| 26 | //Metodo para traer la lista de precio asociada al cliente | 31 | //Metodo para traer la lista de precio asociada al cliente |
| 27 | focaModalPrecioCondicionService.getListaPrecio(idListaPrecio) | 32 | focaModalPrecioCondicionService.getListaPrecio(idListaPrecio) |
| 28 | .then(function (res) { | 33 | .then(function (res) { |
| 29 | console.log("Lista de precios", res); | ||
| 30 | $scope.listaDePreciosAsociada = res.data[0]; | 34 | $scope.listaDePreciosAsociada = res.data[0]; |
| 31 | }) | 35 | }) |
| 32 | .catch(function (e) { console.log(e) }); | 36 | .catch(function (e) { console.error(e) }); |
| 33 | focaModalPrecioCondicionService.getPlazosByIdCliente(idCliente) | 37 | focaModalPrecioCondicionService.getPlazosByIdCliente(idCliente) |
| 34 | .then(function (res) { | 38 | .then(function (res) { |
| 35 | console.log(res); | 39 | console.log("Plazos ", res); |
| 36 | $scope.plazos = res.data; | 40 | res.data.forEach(function (item) { |
| 41 | $scope.plazos.push(item); | ||
| 42 | }); | ||
| 37 | }) | 43 | }) |
| 38 | .catch(function (e) { console.log(e) }); | 44 | .catch(function (e) { console.error(e) }); |
| 39 | } | 45 | } |
| 40 | 46 | ||
| 41 | //#region Metodos para la lista de precios | 47 | //#region Metodos para la lista de precios |
| 42 | $scope.openListaDePrecios = function () { | 48 | $scope.openListaDePrecios = function () { |
| 43 | var datos = null; | 49 | var datos = null; |
| 44 | focaModalPrecioCondicionService.getAllListaPrecio() | 50 | focaModalPrecioCondicionService.getAllListaPrecio() |
| 45 | .then(function (res) { | 51 | .then(function (res) { |
| 46 | datos = res.data; | 52 | datos = res.data; |
| 47 | focaModalService.modal({ | 53 | focaModalService.modal({ |
| 48 | titulo: 'Lista de precios', | 54 | titulo: 'Lista de precios', |
| 49 | data: datos, | 55 | data: datos, |
| 50 | size: 'md', | 56 | size: 'md', |
| 51 | columnas: [ | 57 | columnas: [ |
| 52 | { | 58 | { |
| 53 | propiedad: 'ID', | 59 | propiedad: 'ID', |
| 54 | nombre: 'Codigo' | 60 | nombre: 'Codigo' |
| 55 | }, | 61 | }, |
| 56 | { | 62 | { |
| 57 | propiedad: 'DES', | 63 | propiedad: 'DES', |
| 58 | NOMBRE: 'Nombre' | 64 | NOMBRE: 'Nombre' |
| 59 | } | 65 | } |
| 60 | ], | 66 | ], |
| 61 | }).then(function (res) { | 67 | }).then(function (res) { |
| 62 | $scope.associatedList = false; | 68 | $scope.associatedList = false; |
| 63 | $scope.listaDePreciosAlternativa = res; | 69 | $scope.listaDePreciosAlternativa = res; |
| 64 | console.log(res); | 70 | console.log(res); |
| 65 | }).catch(function (e) { | 71 | }).catch(function (e) { |
| 66 | console.log(e); | 72 | console.error(e); |
| 67 | }); | 73 | }); |
| 68 | }); | 74 | }); |
| 69 | }; | 75 | }; |
| 70 | $scope.selectListaDePrecios = function (listaDePrecios) { | 76 | $scope.selectListaDePrecios = function () { |
| 71 | $scope.associatedList = true; | 77 | $scope.associatedList = true; |
| 72 | }; | 78 | }; |
| 73 | $scope.verListaProductos = function (id) { | 79 | $scope.verListaProductos = function (id) { |
| 74 | var modalInstance = $uibModal.open( | 80 | var modalInstance = $uibModal.open( |
| 75 | { | 81 | { |
| 76 | ariaLabelledBy: 'Busqueda de Productos', | 82 | ariaLabelledBy: 'Busqueda de Productos', |
| 77 | templateUrl: 'modal-busqueda-productos.html', | 83 | templateUrl: 'modal-busqueda-productos.html', |
| 78 | controller: 'modalBusquedaProductosCtrl', | 84 | controller: 'modalBusquedaProductosCtrl', |
| 79 | resolve: { | 85 | resolve: { |
| 80 | parametroProducto: { | 86 | parametroProducto: { |
| 81 | idLista: parseInt(id), | 87 | idLista: parseInt(id), |
| 82 | cotizacion: 1, | 88 | cotizacion: 1, |
| 83 | simbolo: '$', | 89 | simbolo: '$', |
| 84 | soloMostrar: true | 90 | soloMostrar: true |
| 85 | } | 91 | } |
| 86 | }, | 92 | }, |
| 87 | size: 'md' | 93 | size: 'md' |
| 88 | } | 94 | } |
| 89 | ); | 95 | ); |
| 90 | modalInstance.result | 96 | modalInstance.result |
| 91 | .then(function (res) { | 97 | .then(function (res) { |
| 92 | console.log("Producto => ", res); | 98 | console.log("Producto => ", res); |
| 93 | }) | 99 | }) |
| 94 | .catch(function (e) { console.log(e) }); | 100 | .catch(function (e) { console.log(e) }); |
| 95 | }; | 101 | }; |
| 96 | $scope.closeModalPrecioCondicion = function () { | ||
| 97 | $uibModalInstance.dismiss('cancel'); | ||
| 98 | }; | ||
| 99 | $scope.guardarPrecioCondicion = function () { | ||
| 100 | $uibModalInstance.close(!$scope.associatedList ? $scope.listaDePreciosAsociada : $scope.listaDePreciosAlternativa); | ||
| 101 | } | ||
| 102 | //#endregion | 102 | //#endregion |
| 103 | 103 | ||
| 104 | //#region Metodos para los plazos | 104 | //#region Metodos para los plazos |
| 105 | $scope.addMorePlazos = function () { | 105 | $scope.addPlazo = function () { |
| 106 | if ($scope.plazos.length < 4) { | 106 | if ($scope.plazos.length === 100) return; |
| 107 | $scope.plazos.unshift({ dias: 0 }); | 107 | for (var i = 1; i < $scope.plazos.length; i++) { |
| 108 | if ($scope.plazos[0].dias == $scope.plazos[i].dias) { | ||
| 109 | focaModalService.alert("Ya existe un plazo con este valor"); | ||
| 110 | return; | ||
| 111 | } | ||
| 108 | } | 112 | } |
| 113 | $scope.plazos.unshift({ dias: 0, id_cliente: idCliente, activo: true }); | ||
| 109 | }; | 114 | }; |
| 110 | $scope.editPlazo = function () { | 115 | $scope.deletePlazo = function (index) { |
| 111 | $scope.editingPlazo = true; | 116 | $scope.plazos[index].activo = false; |
| 112 | }; | 117 | }; |
| 113 | $scope.validateMinMax = function (plazo, min, max) { | 118 | $scope.validateMinMax = function (plazo, min, max) { |
| 114 | plazo.dias = parseInt(plazo.dias); | 119 | plazo.dias = parseInt(plazo.dias); |
| 115 | if (plazo.dias === null || plazo.dias === undefined || isNaN(plazo.dias)) { | 120 | if (plazo.dias === null || plazo.dias === undefined || isNaN(plazo.dias)) { |
| 116 | plazo.dias = '0'; | 121 | plazo.dias = '0'; |
| 117 | return; | 122 | return; |
| 118 | } | 123 | } |
| 119 | if (parseInt(plazo.dias) < min) { | 124 | if (parseInt(plazo.dias) < min) { |
| 120 | plazo.dias = '0'; | 125 | plazo.dias = '0'; |
| 121 | return; | 126 | return; |
| 122 | } | 127 | } |
| 123 | if (parseInt(plazo.dias) > max) { | 128 | if (parseInt(plazo.dias) > max) { |
| 124 | plazo.dias = '365'; | 129 | plazo.dias = '365'; |
| 125 | return; | 130 | return; |
| 126 | } | 131 | } |
| 127 | }; | 132 | }; |
| 128 | //#endregion | 133 | //#endregion |
| 134 | |||
| 135 | $scope.closeModalPrecioCondicion = function () { | ||
| 136 | $uibModalInstance.dismiss('cancel'); | ||
| 137 | }; | ||
| 138 | $scope.guardarPrecioCondicion = function () { | ||
| 139 | $scope.plazos.shift(); | ||
| 140 | focaModalPrecioCondicionService.createPlazo($scope.plazos) | ||
| 141 | .then(function (res) { | ||
| 142 | var caca = $filter('filter')($scope.plazos, { activo: true }, true) | ||
| 143 | console.log(caca); | ||
| 144 | var precioCondicion = { | ||
| 145 | listaPrecio: $scope.associatedList ? $scope.listaDePreciosAsociada : $scope.listaDePreciosAlternativa, | ||
| 146 | plazoPago: $filter('filter')($scope.plazos, { activo: true }, true) | ||
| 147 | }; |