Commit 9a6a81b825a204f90431b9acc0a6c332bd142389
1 parent
47f6ee51e8
Exists in
master
and in
1 other branch
Borrado de variable sin uso xD.
Showing
1 changed file
with
1 additions
and
3 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 | id_cliente: idCliente, | 20 | id_cliente: 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 | console.log("Plazos ", res); | 39 | console.log("Plazos ", res); |
40 | res.data.forEach(function (item) { | 40 | res.data.forEach(function (item) { |
41 | $scope.plazos.push(item); | 41 | $scope.plazos.push(item); |
42 | }); | 42 | }); |
43 | }) | 43 | }) |
44 | .catch(function (e) { console.error(e) }); | 44 | .catch(function (e) { console.error(e) }); |
45 | } | 45 | } |
46 | 46 | ||
47 | //#region Metodos para la lista de precios | 47 | //#region Metodos para la lista de precios |
48 | $scope.openListaDePrecios = function () { | 48 | $scope.openListaDePrecios = function () { |
49 | var datos = null; | 49 | var datos = null; |
50 | focaModalPrecioCondicionService.getAllListaPrecio() | 50 | focaModalPrecioCondicionService.getAllListaPrecio() |
51 | .then(function (res) { | 51 | .then(function (res) { |
52 | datos = res.data; | 52 | datos = res.data; |
53 | focaModalService.modal({ | 53 | focaModalService.modal({ |
54 | titulo: 'Lista de precios', | 54 | titulo: 'Lista de precios', |
55 | data: datos, | 55 | data: datos, |
56 | size: 'md', | 56 | size: 'md', |
57 | columnas: [ | 57 | columnas: [ |
58 | { | 58 | { |
59 | propiedad: 'ID', | 59 | propiedad: 'ID', |
60 | nombre: 'Codigo' | 60 | nombre: 'Codigo' |
61 | }, | 61 | }, |
62 | { | 62 | { |
63 | propiedad: 'DES', | 63 | propiedad: 'DES', |
64 | NOMBRE: 'Nombre' | 64 | NOMBRE: 'Nombre' |
65 | } | 65 | } |
66 | ], | 66 | ], |
67 | }).then(function (res) { | 67 | }).then(function (res) { |
68 | $scope.associatedList = false; | 68 | $scope.associatedList = false; |
69 | $scope.listaDePreciosAlternativa = res; | 69 | $scope.listaDePreciosAlternativa = res; |
70 | console.log(res); | 70 | console.log(res); |
71 | }).catch(function (e) { | 71 | }).catch(function (e) { |
72 | console.error(e); | 72 | console.error(e); |
73 | }); | 73 | }); |
74 | }); | 74 | }); |
75 | }; | 75 | }; |
76 | $scope.selectListaDePrecios = function () { | 76 | $scope.selectListaDePrecios = function () { |
77 | $scope.associatedList = true; | 77 | $scope.associatedList = true; |
78 | }; | 78 | }; |
79 | $scope.verListaProductos = function (id) { | 79 | $scope.verListaProductos = function (id) { |
80 | var modalInstance = $uibModal.open( | 80 | var modalInstance = $uibModal.open( |
81 | { | 81 | { |
82 | ariaLabelledBy: 'Busqueda de Productos', | 82 | ariaLabelledBy: 'Busqueda de Productos', |
83 | templateUrl: 'modal-busqueda-productos.html', | 83 | templateUrl: 'modal-busqueda-productos.html', |
84 | controller: 'modalBusquedaProductosCtrl', | 84 | controller: 'modalBusquedaProductosCtrl', |
85 | resolve: { | 85 | resolve: { |
86 | parametroProducto: { | 86 | parametroProducto: { |
87 | idLista: parseInt(id), | 87 | idLista: parseInt(id), |
88 | cotizacion: 1, | 88 | cotizacion: 1, |
89 | simbolo: '$', | 89 | simbolo: '$', |
90 | soloMostrar: true | 90 | soloMostrar: true |
91 | } | 91 | } |
92 | }, | 92 | }, |
93 | size: 'md' | 93 | size: 'md' |
94 | } | 94 | } |
95 | ); | 95 | ); |
96 | modalInstance.result | 96 | modalInstance.result |
97 | .then(function (res) { | 97 | .then(function (res) { |
98 | console.log("Producto => ", res); | 98 | console.log("Producto => ", res); |
99 | }) | 99 | }) |
100 | .catch(function (e) { console.log(e) }); | 100 | .catch(function (e) { console.log(e) }); |
101 | }; | 101 | }; |
102 | //#endregion | 102 | //#endregion |
103 | 103 | ||
104 | //#region Metodos para los plazos | 104 | //#region Metodos para los plazos |
105 | $scope.addPlazo = function () { | 105 | $scope.addPlazo = function () { |
106 | if ($scope.plazos.length === 100) return; | 106 | if ($scope.plazos.length === 100) return; |
107 | for (var i = 1; i < $scope.plazos.length; i++) { | 107 | for (var i = 1; i < $scope.plazos.length; i++) { |
108 | if ($scope.plazos[0].dias == $scope.plazos[i].dias) { | 108 | if ($scope.plazos[0].dias == $scope.plazos[i].dias) { |
109 | focaModalService.alert("Ya existe un plazo con este valor"); | 109 | focaModalService.alert("Ya existe un plazo con este valor"); |
110 | return; | 110 | return; |
111 | } | 111 | } |
112 | } | 112 | } |
113 | $scope.plazos.unshift({ dias: 0, id_cliente: idCliente, activo: true }); | 113 | $scope.plazos.unshift({ dias: 0, id_cliente: idCliente, activo: true }); |
114 | }; | 114 | }; |
115 | $scope.deletePlazo = function (index) { | 115 | $scope.deletePlazo = function (index) { |
116 | $scope.plazos[index].activo = false; | 116 | $scope.plazos[index].activo = false; |
117 | }; | 117 | }; |
118 | $scope.validateMinMax = function (plazo, min, max) { | 118 | $scope.validateMinMax = function (plazo, min, max) { |
119 | plazo.dias = parseInt(plazo.dias); | 119 | plazo.dias = parseInt(plazo.dias); |
120 | if (plazo.dias === null || plazo.dias === undefined || isNaN(plazo.dias)) { | 120 | if (plazo.dias === null || plazo.dias === undefined || isNaN(plazo.dias)) { |
121 | plazo.dias = '0'; | 121 | plazo.dias = '0'; |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | if (parseInt(plazo.dias) < min) { | 124 | if (parseInt(plazo.dias) < min) { |
125 | plazo.dias = '0'; | 125 | plazo.dias = '0'; |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | if (parseInt(plazo.dias) > max) { | 128 | if (parseInt(plazo.dias) > max) { |
129 | plazo.dias = '365'; | 129 | plazo.dias = '365'; |
130 | return; | 130 | return; |
131 | } | 131 | } |
132 | }; | 132 | }; |
133 | //#endregion | 133 | //#endregion |
134 | 134 | ||
135 | $scope.closeModalPrecioCondicion = function () { | 135 | $scope.closeModalPrecioCondicion = function () { |
136 | $uibModalInstance.dismiss('cancel'); | 136 | $uibModalInstance.dismiss('cancel'); |
137 | }; | 137 | }; |
138 | $scope.guardarPrecioCondicion = function () { | 138 | $scope.guardarPrecioCondicion = function () { |
139 | $scope.plazos.shift(); | 139 | $scope.plazos.shift(); |
140 | focaModalPrecioCondicionService.createPlazo($scope.plazos) | 140 | focaModalPrecioCondicionService.createPlazo($scope.plazos) |
141 | .then(function (res) { | 141 | .then(function () { |
142 | var caca = $filter('filter')($scope.plazos, { activo: true }, true) | ||
143 | console.log(caca); | ||
144 | var precioCondicion = { | 142 | var precioCondicion = { |
145 | listaPrecio: $scope.associatedList ? $scope.listaDePreciosAsociada : $scope.listaDePreciosAlternativa, | 143 | listaPrecio: $scope.associatedList ? $scope.listaDePreciosAsociada : $scope.listaDePreciosAlternativa, |
146 | plazoPago: $filter('filter')($scope.plazos, { activo: true }, true) | 144 | plazoPago: $filter('filter')($scope.plazos, { activo: true }, true) |
147 | }; | 145 | }; |
148 | $uibModalInstance.close(precioCondicion); | 146 | $uibModalInstance.close(precioCondicion); |
149 | }) | 147 | }) |
150 | .catch(function (e) { console.error(e) }) | 148 | .catch(function (e) { console.error(e) }) |
151 | } | 149 | } |
152 | } | 150 | } |
153 | ]); | 151 | ]); |
154 | 152 |