Commit dac138fef10056230eea737bb3ae5c686d505778
1 parent
75c5fa64e7
Exists in
master
and in
1 other branch
Alerta al cambiar precio
Showing
1 changed file
with
2 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 | focaModalService.confirm('¿Desea cambiar la lista de precios?').then(function (data){ | 67 | focaModalService.confirm('¿Desea cambiar la lista de precios?\n'+ |
68 | 'Se perderan los productos ingresados').then(function (data){ | ||
68 | if (data) { | 69 | if (data) { |
69 | $scope.associatedList = false; | 70 | $scope.associatedList = false; |
70 | $scope.listaDePreciosAlternativa = res; | 71 | $scope.listaDePreciosAlternativa = res; |
71 | } | 72 | } |
72 | }); | 73 | }); |
73 | }).catch(function (e) { | 74 | }).catch(function (e) { |
74 | console.error(e); | 75 | console.error(e); |
75 | }); | 76 | }); |
76 | }); | 77 | }); |
77 | }; | 78 | }; |
78 | $scope.selectListaDePrecios = function () { | 79 | $scope.selectListaDePrecios = function () { |
79 | $scope.associatedList = true; | 80 | $scope.associatedList = true; |
80 | }; | 81 | }; |
81 | $scope.verListaProductos = function (id) { | 82 | $scope.verListaProductos = function (id) { |
82 | $uibModal.open( | 83 | $uibModal.open( |
83 | { | 84 | { |
84 | ariaLabelledBy: 'Busqueda de Productos', | 85 | ariaLabelledBy: 'Busqueda de Productos', |
85 | templateUrl: 'modal-busqueda-productos.html', | 86 | templateUrl: 'modal-busqueda-productos.html', |
86 | controller: 'modalBusquedaProductosCtrl', | 87 | controller: 'modalBusquedaProductosCtrl', |
87 | resolve: { | 88 | resolve: { |
88 | parametroProducto: { | 89 | parametroProducto: { |
89 | idLista: parseInt(id), | 90 | idLista: parseInt(id), |
90 | cotizacion: 1, | 91 | cotizacion: 1, |
91 | simbolo: '$', | 92 | simbolo: '$', |
92 | soloMostrar: true | 93 | soloMostrar: true |
93 | } | 94 | } |
94 | }, | 95 | }, |
95 | size: 'md' | 96 | size: 'md' |
96 | } | 97 | } |
97 | ); | 98 | ); |
98 | }; | 99 | }; |
99 | //#endregion | 100 | //#endregion |
100 | 101 | ||
101 | //#region Metodos para los plazos | 102 | //#region Metodos para los plazos |
102 | $scope.addPlazo = function (key) { | 103 | $scope.addPlazo = function (key) { |
103 | if (key != 13) return; | 104 | if (key != 13) return; |
104 | if ($scope.plazos.length === 100) return; | 105 | if ($scope.plazos.length === 100) return; |
105 | for (var i = 1; i < $scope.plazos.length; i++) { | 106 | for (var i = 1; i < $scope.plazos.length; i++) { |
106 | if ($scope.plazos[0].dias == $scope.plazos[i].dias && $scope.plazos[i].activo == true) { | 107 | if ($scope.plazos[0].dias == $scope.plazos[i].dias && $scope.plazos[i].activo == true) { |
107 | focaModalService.alert("Ya existe un plazo con este valor"); | 108 | focaModalService.alert("Ya existe un plazo con este valor"); |
108 | return; | 109 | return; |
109 | } | 110 | } |
110 | } | 111 | } |
111 | $scope.plazos.unshift({ dias: 0, idCliente: idCliente, activo: true }); | 112 | $scope.plazos.unshift({ dias: 0, idCliente: idCliente, activo: true }); |
112 | $scope.focused = 1; | 113 | $scope.focused = 1; |
113 | }; | 114 | }; |
114 | $scope.deletePlazo = function (index) { | 115 | $scope.deletePlazo = function (index) { |
115 | $scope.plazos[index].activo = false; | 116 | $scope.plazos[index].activo = false; |
116 | }; | 117 | }; |
117 | $scope.validateMinMax = function (plazo, min, max) { | 118 | $scope.validateMinMax = function (plazo, min, max) { |
118 | plazo.dias = parseInt(plazo.dias); | 119 | plazo.dias = parseInt(plazo.dias); |
119 | if (plazo.dias === null || plazo.dias === undefined || isNaN(plazo.dias)) { | 120 | if (plazo.dias === null || plazo.dias === undefined || isNaN(plazo.dias)) { |
120 | plazo.dias = '0'; | 121 | plazo.dias = '0'; |
121 | return; | 122 | return; |
122 | } | 123 | } |
123 | if (parseInt(plazo.dias) < min) { | 124 | if (parseInt(plazo.dias) < min) { |
124 | plazo.dias = '0'; | 125 | plazo.dias = '0'; |
125 | return; | 126 | return; |
126 | } | 127 | } |
127 | if (parseInt(plazo.dias) > max) { | 128 | if (parseInt(plazo.dias) > max) { |
128 | plazo.dias = '365'; | 129 | plazo.dias = '365'; |
129 | return; | 130 | return; |
130 | } | 131 | } |
131 | }; | 132 | }; |
132 | //#endregion | 133 | //#endregion |
133 | 134 | ||
134 | $scope.closeModalPrecioCondicion = function () { | 135 | $scope.closeModalPrecioCondicion = function () { |
135 | $uibModalInstance.dismiss('cancel'); | 136 | $uibModalInstance.dismiss('cancel'); |
136 | }; | 137 | }; |
137 | $scope.guardarPrecioCondicion = function () { | 138 | $scope.guardarPrecioCondicion = function () { |
138 | $scope.plazos.shift(); | 139 | $scope.plazos.shift(); |
139 | focaModalPrecioCondicionService.createPlazo($scope.plazos) | 140 | focaModalPrecioCondicionService.createPlazo($scope.plazos) |
140 | .then(function () { | 141 | .then(function () { |
141 | var precioCondicion = { | 142 | var precioCondicion = { |
142 | listaPrecio: $scope.associatedList ? $scope.listaDePreciosAsociada : $scope.listaDePreciosAlternativa, | 143 | listaPrecio: $scope.associatedList ? $scope.listaDePreciosAsociada : $scope.listaDePreciosAlternativa, |
143 | plazoPago: $filter('filter')($scope.plazos, { activo: true }, true) | 144 | plazoPago: $filter('filter')($scope.plazos, { activo: true }, true) |
144 | }; | 145 | }; |
145 | $uibModalInstance.close(precioCondicion); | 146 | $uibModalInstance.close(precioCondicion); |
146 | }) | 147 | }) |
147 | .catch(function (e) { console.error(e) }) | 148 | .catch(function (e) { console.error(e) }) |
148 | } | 149 | } |
149 | } | 150 | } |
150 | ]); | 151 | ]); |
151 | 152 |