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