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