Commit 47f6ee51e8ec417b719e4c331f1677914285fafe
1 parent
2dfe129876
Exists in
master
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
... | ... | @@ -14,8 +14,13 @@ angular.module('focaModalPrecioCondicion') |
14 | 14 | $timeout, $filter, $scope, $uibModal, $uibModalInstance, |
15 | 15 | focaModalService, focaModalPrecioCondicionService, idListaPrecio, idCliente |
16 | 16 | ) { |
17 | - $scope.plazos = [{ dias: 0 }]; | |
18 | - $scope.editingPlazo = false; | |
17 | + $scope.plazos = [ | |
18 | + { | |
19 | + dias: 0, | |
20 | + id_cliente: idCliente, | |
21 | + activo: true | |
22 | + } | |
23 | + ]; | |
19 | 24 | $scope.openModalListaDePrecios = false; |
20 | 25 | $scope.associatedList = true; |
21 | 26 | $scope.listaDePreciosAlternativa = null; |
... | ... | @@ -26,16 +31,17 @@ angular.module('focaModalPrecioCondicion') |
26 | 31 | //Metodo para traer la lista de precio asociada al cliente |
27 | 32 | focaModalPrecioCondicionService.getListaPrecio(idListaPrecio) |
28 | 33 | .then(function (res) { |
29 | - console.log("Lista de precios", res); | |
30 | 34 | $scope.listaDePreciosAsociada = res.data[0]; |
31 | 35 | }) |
32 | - .catch(function (e) { console.log(e) }); | |
36 | + .catch(function (e) { console.error(e) }); | |
33 | 37 | focaModalPrecioCondicionService.getPlazosByIdCliente(idCliente) |
34 | 38 | .then(function (res) { |
35 | - console.log(res); | |
36 | - $scope.plazos = res.data; | |
39 | + console.log("Plazos ", res); | |
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 | 47 | //#region Metodos para la lista de precios |
... | ... | @@ -63,11 +69,11 @@ angular.module('focaModalPrecioCondicion') |
63 | 69 | $scope.listaDePreciosAlternativa = res; |
64 | 70 | console.log(res); |
65 | 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 | 77 | $scope.associatedList = true; |
72 | 78 | }; |
73 | 79 | $scope.verListaProductos = function (id) { |
... | ... | @@ -93,22 +99,21 @@ angular.module('focaModalPrecioCondicion') |
93 | 99 | }) |
94 | 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 | 102 | //#endregion |
103 | 103 | |
104 | 104 | //#region Metodos para los plazos |
105 | - $scope.addMorePlazos = function () { | |
106 | - if ($scope.plazos.length < 4) { | |
107 | - $scope.plazos.unshift({ dias: 0 }); | |
105 | + $scope.addPlazo = function () { | |
106 | + if ($scope.plazos.length === 100) return; | |
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 () { | |
111 | - $scope.editingPlazo = true; | |
115 | + $scope.deletePlazo = function (index) { | |
116 | + $scope.plazos[index].activo = false; | |
112 | 117 | }; |
113 | 118 | $scope.validateMinMax = function (plazo, min, max) { |
114 | 119 | plazo.dias = parseInt(plazo.dias); |
... | ... | @@ -126,6 +131,23 @@ angular.module('focaModalPrecioCondicion') |
126 | 131 | } |
127 | 132 | }; |
128 | 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 | + }; | |
148 | + $uibModalInstance.close(precioCondicion); | |
149 | + }) | |
150 | + .catch(function (e) { console.error(e) }) | |
151 | + } | |
129 | 152 | } |
130 | - ] | |
131 | - ); | |
153 | + ]); |