Commit 59d5b6b83b2e63a7141bbb0f0ec28e376171ba79
1 parent
f7945bfaeb
Exists in
master
cambio en precio y condicion
Showing
1 changed file
with
46 additions
and
38 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 | 'parametros', | 11 | 'parametros', |
12 | function ( | 12 | function ( |
13 | $timeout, $filter, $scope, $uibModal, $uibModalInstance, | 13 | $timeout, $filter, $scope, $uibModal, $uibModalInstance, |
14 | focaModalService, focaModalPrecioCondicionService, parametros | 14 | focaModalService, focaModalPrecioCondicionService, parametros |
15 | ) { | 15 | ) { |
16 | $scope.plazos = [ | 16 | $scope.plazos = [ |
17 | { | 17 | { |
18 | dias: 0, | 18 | dias: 0, |
19 | idCliente: parametros.idCliente, | 19 | idCliente: parametros.idCliente, |
20 | activo: true | 20 | activo: true |
21 | } | 21 | } |
22 | ]; | 22 | ]; |
23 | $scope.remito = parametros.remito; | ||
24 | $scope.notaPedido = parametros.notaPedido; | ||
23 | $scope.openModalListaDePrecios = false; | 25 | $scope.openModalListaDePrecios = false; |
24 | $scope.associatedList = true; | 26 | $scope.associatedList = true; |
25 | $scope.listaDePreciosAlternativa = null; | 27 | $scope.listaDePreciosAlternativa = null; |
26 | 28 | ||
27 | onInit(); | 29 | onInit(); |
28 | 30 | ||
29 | function onInit() { | 31 | function onInit() { |
30 | //Metodo para traer la lista de precio asociada al cliente | 32 | //Metodo para traer la lista de precio asociada al cliente |
31 | focaModalPrecioCondicionService.getListaPrecio(parametros.idListaPrecio) | 33 | focaModalPrecioCondicionService.getListaPrecio(parametros.idListaPrecio) |
32 | .then(function (res) { | 34 | .then(function (res) { |
33 | $scope.listaDePreciosAsociada = res.data[0]; | 35 | $scope.listaDePreciosAsociada = res.data[0]; |
34 | }) | 36 | }) |
35 | .catch(function (e) { console.error(e) }); | 37 | .catch(function (e) { console.error(e) }); |
36 | focaModalPrecioCondicionService.getPlazosByIdCliente(parametros.idCliente) | 38 | focaModalPrecioCondicionService.getPlazosByIdCliente(parametros.idCliente) |
37 | .then(function (res) { | 39 | .then(function (res) { |
38 | res.data.forEach(function (item) { | 40 | res.data.forEach(function (item) { |
39 | $scope.plazos.push(item); | 41 | $scope.plazos.push(item); |
40 | }); | 42 | }); |
41 | }) | 43 | }) |
42 | .catch(function (e) { console.error(e) }); | 44 | .catch(function (e) { console.error(e) }); |
43 | } | 45 | } |
44 | 46 | ||
45 | //#region Metodos para la lista de precios | 47 | //#region Metodos para la lista de precios |
46 | $scope.openListaDePrecios = function () { | 48 | $scope.openListaDePrecios = function () { |
47 | var datos = null; | 49 | var datos = null; |
48 | focaModalPrecioCondicionService.getAllListaPrecio() | 50 | focaModalPrecioCondicionService.getAllListaPrecio() |
49 | .then(function (res) { | 51 | .then(function (res) { |
50 | datos = res.data; | 52 | datos = res.data; |
51 | focaModalService.modal({ | 53 | focaModalService.modal({ |
52 | titulo: 'Lista de precios', | 54 | titulo: 'Lista de precios', |
53 | data: datos, | 55 | data: datos, |
54 | size: 'md', | 56 | size: 'md', |
55 | columnas: [ | 57 | columnas: [ |
56 | { | 58 | { |
57 | propiedad: 'ID', | 59 | propiedad: 'ID', |
58 | nombre: 'Codigo' | 60 | nombre: 'Codigo' |
59 | }, | 61 | }, |
60 | { | 62 | { |
61 | propiedad: 'DES', | 63 | propiedad: 'DES', |
62 | NOMBRE: 'Nombre' | 64 | NOMBRE: 'Nombre' |
63 | } | 65 | } |
64 | ], | 66 | ], |
65 | }).then(function (res) { | 67 | }).then(function (res) { |
66 | focaModalService.confirm('¿Desea cambiar la lista de precios?\n'+ | 68 | focaModalService.confirm('¿Desea cambiar la lista de precios?\n'+ |
67 | 'Se perderan los productos ingresados').then(function (data){ | 69 | 'Se perderan los productos ingresados').then(function (data){ |
68 | if (data) { | 70 | if (data) { |
69 | $scope.associatedList = false; | 71 | if ($scope.notaPedido) { |
70 | $scope.listaDePreciosAlternativa = res; | 72 | if ($scope.notaPedido.articulosNotaPedido.length > 0) { |
73 | $scope.notaPedido.articulosNotaPedido = []; | ||
74 | } | ||
75 | } else if ($scope.remito) { | ||
76 | if ($scope.remito.articulosRemito.length > 0) { | ||
77 | $scope.remito.articulosRemito = []; | ||
78 | } | ||
71 | } | 79 | } |
72 | }); | 80 | $scope.associatedList = false; |
73 | }).catch(function (e) { | 81 | $scope.listaDePreciosAlternativa = res; |
82 | } | ||
83 | }); | ||
84 | }).catch(function (e) { | ||
74 | console.error(e); | 85 | console.error(e); |
75 | }); | 86 | }); |
76 | }); | 87 | }); |
77 | }; | 88 | }; |
78 | $scope.selectListaDePrecios = function () { | 89 | $scope.selectListaDePrecios = function () { |
79 | $scope.associatedList = true; | 90 | $scope.associatedList = true; |
80 | }; | 91 | }; |
81 | $scope.verListaProductos = function (id) { | 92 | $scope.verListaProductos = function (id) { |
82 | $uibModal.open( | 93 | $uibModal.open( |
83 | { | 94 | { |
84 | ariaLabelledBy: 'Busqueda de Productos', | 95 | ariaLabelledBy: 'Busqueda de Productos', |
85 | templateUrl: 'modal-busqueda-productos.html', | 96 | templateUrl: 'modal-busqueda-productos.html', |
86 | controller: 'modalBusquedaProductosCtrl', | 97 | controller: 'modalBusquedaProductosCtrl', |
87 | resolve: { | 98 | resolve: { |
88 | parametroProducto: { | 99 | parametroProducto: { |
89 | idLista: parseInt(id), | 100 | idLista: parseInt(id), |
90 | cotizacion: 1, | 101 | cotizacion: 1, |
91 | simbolo: '$', | 102 | simbolo: '$', |
92 | soloMostrar: true | 103 | soloMostrar: true |
93 | } | 104 | } |
94 | }, | 105 | }, |
95 | size: 'md' | 106 | size: 'md' |
96 | } | 107 | } |
97 | ); | 108 | ); |
98 | }; | 109 | }; |
99 | //#endregion | 110 | //#endregion |
100 | 111 | ||
101 | //#region Metodos para los plazos | 112 | //#region Metodos para los plazos |
102 | $scope.addPlazo = function (key) { | 113 | $scope.addPlazo = function (key) { |
103 | if (key != 13) return; | 114 | if (key != 13) return; |
104 | if ($scope.plazos.length === 100) return; | 115 | if ($scope.plazos.length === 100) return; |
105 | for (var i = 1; i < $scope.plazos.length; i++) { | 116 | for (var i = 1; i < $scope.plazos.length; i++) { |
106 | if ($scope.plazos[0].dias == $scope.plazos[i].dias && $scope.plazos[i].activo == true) { | 117 | if ($scope.plazos[0].dias == $scope.plazos[i].dias && $scope.plazos[i].activo == true) { |
107 | focaModalService.alert("Ya existe un plazo con este valor"); | 118 | focaModalService.alert("Ya existe un plazo con este valor"); |
108 | return; | 119 | return; |
109 | } | 120 | } |
110 | } | 121 | } |
111 | $scope.plazos.unshift({ dias: 0, idCliente: parametros.idCliente, activo: true }); | 122 | $scope.plazos.unshift({ dias: 0, idCliente: parametros.idCliente, activo: true }); |
112 | $scope.focused = 1; | 123 | $scope.focused = 1; |
113 | }; | 124 | }; |
114 | $scope.deletePlazo = function (index) { | 125 | $scope.deletePlazo = function (index) { |
115 | $scope.plazos[index].activo = false; | 126 | $scope.plazos[index].activo = false; |
116 | }; | 127 | }; |
117 | $scope.validateMinMax = function (plazo, min, max) { | 128 | $scope.validateMinMax = function (plazo, min, max) { |
118 | plazo.dias = parseInt(plazo.dias); | 129 | plazo.dias = parseInt(plazo.dias); |
119 | if (plazo.dias === null || plazo.dias === undefined || isNaN(plazo.dias)) { | 130 | if (plazo.dias === null || plazo.dias === undefined || isNaN(plazo.dias)) { |
120 | plazo.dias = '0'; | 131 | plazo.dias = '0'; |
121 | return; | 132 | return; |
122 | } | 133 | } |
123 | if (parseInt(plazo.dias) < min) { | 134 | if (parseInt(plazo.dias) < min) { |
124 | plazo.dias = '0'; | 135 | plazo.dias = '0'; |
125 | return; | 136 | return; |
126 | } | 137 | } |
127 | if (parseInt(plazo.dias) > max) { | 138 | if (parseInt(plazo.dias) > max) { |
128 | plazo.dias = '365'; | 139 | plazo.dias = '365'; |
129 | return; | 140 | return; |
130 | } | 141 | } |
131 | }; | 142 | }; |
132 | //#endregion | 143 | //#endregion |
133 | 144 | ||
134 | $scope.closeModalPrecioCondicion = function () { | 145 | $scope.closeModalPrecioCondicion = function () { |
135 | $uibModalInstance.dismiss('cancel'); | 146 | $uibModalInstance.dismiss('cancel'); |
136 | }; | 147 | }; |
137 | $scope.guardarPrecioCondicion = function () { | 148 | $scope.guardarPrecioCondicion = function () { |
138 | var mod = $scope.associatedList ? parseInt($scope.listaDePreciosAsociada.ID) : parseInt($scope.listaDePreciosAlternativa.ID); | ||
139 | focaModalPrecioCondicionService.actualizarLista(parametros.idCliente, mod).then(function (){ | ||
140 | $scope.plazos.shift(); | 149 | $scope.plazos.shift(); |
141 | focaModalPrecioCondicionService.createPlazo($scope.plazos) | 150 | focaModalPrecioCondicionService.createPlazo($scope.plazos) |
142 | .then(function () { | 151 | .then(function () { |
143 | var precioCondicion = { | 152 | var precioCondicion = { |
144 | listaPrecio: $scope.associatedList ? $scope.listaDePreciosAsociada : $scope.listaDePreciosAlternativa, | 153 | listaPrecio: $scope.associatedList ? $scope.listaDePreciosAsociada : $scope.listaDePreciosAlternativa, |
145 | plazoPago: $filter('filter')($scope.plazos, { activo: true }, true) | 154 | plazoPago: $filter('filter')($scope.plazos, { activo: true }, true) |
146 | }; | 155 | }; |
147 | $uibModalInstance.close(precioCondicion); | 156 | $uibModalInstance.close(precioCondicion); |
148 | }) | 157 | }) |
149 | .catch(function (e) { console.error(e) }) | 158 | .catch(function (e) { console.error(e) }) |
150 | }); | ||
151 | }; | 159 | }; |