Commit 75c5fa64e7159cb52db475173feeeee3aef25b55

Authored by Luigi
1 parent fc72e09617
Exists in master and in 1 other branch develop

Alerta al cambiar lista de precios

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