Commit 059814304958875f3da1b09eddca872342e05b66

Authored by Marcelo Puebla
1 parent 5d0a4d7bfa
Exists in master and in 1 other branch develop

agregados metodos y logica para manejar la lista de precios.

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 function ( 12 function (
13 $timeout, $filter, $scope, $uibModal, $uibModalInstance, 13 $timeout, $filter, $scope, $uibModal, $uibModalInstance,
14 focaModalService, focaModalPrecioCondicionService, idListaPrecio 14 focaModalService, focaModalPrecioCondicionService, idListaPrecio
15 ) { 15 ) {
16 16 $scope.plazos = [{ dias: 0 }];
17 $scope.filters = ''; 17 $scope.editingPlazo = false;
18 $scope.ingreso = false; 18 $scope.openModalListaDePrecios = false;
19 $scope.plazosNuevos = []; 19 $scope.chosenClientList = true;
20 $scope.plazoACargar = 20 $scope.listaDePreciosAlternativa = null;
21 { 21
22 item: 1 22 onInit();
23 }; 23
24 // pagination 24 function onInit() {
25 $scope.numPerPage = 10; 25 //Metodo para traer la lista de precio asociada al cliente
26 $scope.currentPage = 1; 26 focaModalPrecioCondicionService.getListaPrecio(idListaPrecio)
27 $scope.filteredPrecioCondicion = []; 27 .then(function (res) {
28 $scope.currentPagePrecioCondicion = []; 28 console.log("Lista de precios", res);
29 $scope.selectedPrecioCondicion = -1; 29 $scope.listaDePreciosAsociada = res.data[0];
30
31 var funcionGet = idListaPrecio ? 'getPreciosCondicionesByIdListaPrecio' :
32 'getPreciosCondiciones';
33
34 focaModalPrecioCondicionService
35 [funcionGet](idListaPrecio)
36 .then(function (res) {
37 for (var i = 0; i < res.data.length; i++) {
38 var plazosTemp = '';
39 res.data[i].plazoPago.sort(function (a, b) {
40 return a.dias - b.dias;
41 });
42 for (var j = 0; j < res.data[i].plazoPago.length; j++) {
43 if (j + 1 === res.data[i].plazoPago.length) {
44 plazosTemp += res.data[i].plazoPago[j].dias;
45 } else {
46 plazosTemp += res.data[i].plazoPago[j].dias + ', ';
47 }
48 }
49 res.data[i].plazos = plazosTemp.trim();
50 }
51 $scope.precioCondicion = res.data;
52 $scope.search();
53 });
54
55 //METODOS
56 $scope.agregarPlazo = function (key) {
57 if (key === 13) {
58 if (!$scope.plazoACargar.dias) {
59 focaModalService.alert('Ingrese cantidad de días');
60 return;
61 }
62 var tieneEseDia = $scope.plazosNuevos.filter(function (a) {
63 return a.dias === $scope.plazoACargar.dias;
64 }); 30 });
65 if (tieneEseDia.length > 0) { 31 }
66 focaModalService.alert('Ya ha ingresado un plazo con esos días');
67 return;
68 }
69 $scope.plazosNuevos.push($scope.plazoACargar);
70 $scope.plazoACargar =
71 {
72 item: $scope.plazosNuevos.length + 1
73 };
74 }
75 };
76
77 $scope.volver = function () {
78 $scope.ingreso = false;
79 $scope.plazosNuevos = [];
80 $scope.plazoACargar =
81 {
82 item: $scope.plazosNuevos.length + 1
83 };
84 };
85
86 $scope.quitarPlazo = function (key) {
87 $scope.plazosNuevos.splice(key, 1);
88 $scope.plazoACargar =
89 {
90 item: $scope.plazosNuevos.length + 1
91 };
92 };
93
94 $scope.search = function (pressed) {
95 $scope.filteredPrecioCondicion = $filter('filter')(
96 $scope.precioCondicion,
97 { $: $scope.filters }
98 );
99 32
100 if (pressed) { 33 //#region Metodos para la lista de precios
101 if ($scope.filteredPrecioCondicion.length === 0) { 34 $scope.openListaDePrecios = function () {
102 $timeout(function () { 35 var datos = null;
103 angular.element('#search')[0].focus(); 36 focaModalPrecioCondicionService.getAllListaPrecio()
104 $scope.filters = ''; 37 .then(function (res) {
38 datos = res.data;
39 focaModalService.modal({
40 titulo: 'Lista de precios',
41 data: datos,
42 size: 'md',
43 columnas: [
44 {
45 propiedad: 'ID',
46 nombre: 'Codigo'
47 },
48 {
49 propiedad: 'DES',
50 NOMBRE: 'Nombre'
51 }
52 ],
53 }).then(function (res) {
54 $scope.chosenClientList = false;
55 $scope.listaDePreciosAlternativa = res;
56 console.log(res);
57 }).catch(function (e) {
58 console.log(e);
105 }); 59 });
106 } else { 60 });
107 primera();
108 }
109 }
110
111 $scope.lastPage = Math.ceil(
112 $scope.filteredPrecioCondicion.length / $scope.numPerPage
113 );
114
115 $scope.resetPage();
116 };
117
118 $scope.resetPage = function () {
119 $scope.currentPage = 1;
120 $scope.selectPage(1);
121 };
122
123 $scope.selectPage = function (page) {
124 var start = (page - 1) * $scope.numPerPage;
125 var end = start + $scope.numPerPage;
126 $scope.paginas = [];
127 $scope.paginas = calcularPages(page);
128 $scope.currentPagePrecioCondicion =
129 $scope.filteredPrecioCondicion.slice(start, end);
130 $scope.currentPage = page;
131 };
132
133 $scope.select = function (precioCondicion) {
134 $uibModalInstance.close(precioCondicion);
135 };
136
137 $scope.cancel = function () {
138 $uibModalInstance.dismiss('cancel');
139 };
140
141 $scope.busquedaDown = function (key) {
142 if (key === 40) {
143 primera(key);
144 }
145 };
146
147 $scope.busquedaPress = function (key) {
148 if (key === 13) {
149 $scope.search(true);
150 }
151 }; 61 };
152 62 $scope.selectListaDePrecios = function (listaDePrecios) {
153 $scope.itemProducto = function (key) { 63 $scope.chosenClientList = true;
154 if (key === 38) {
155 anterior(key);
156 }
157
158 if (key === 40) {
159 siguiente(key);
160 }
161
162 if (key === 37) {
163 retrocederPagina();
164 }
165
166 if (key === 39) {
167 avanzarPagina();
168 }
169 }; 64 };
170 65 $scope.verListaProductos = function (id) {
171 $scope.verListaPrecio = function (id) { 66 var modalInstance = $uibModal.open(
172 $uibModal.open(
173 { 67 {
174 ariaLabelledBy: 'Busqueda de Productos', 68 ariaLabelledBy: 'Busqueda de Productos',
175 templateUrl: 'modal-busqueda-productos.html', 69 templateUrl: 'modal-busqueda-productos.html',
176 controller: 'modalBusquedaProductosCtrl', 70 controller: 'modalBusquedaProductosCtrl',
177 resolve: { 71 resolve: {
178 parametroProducto: { 72 parametroProducto: {
179 idLista: id, 73 idLista: parseInt(id),
180 cotizacion: 1, 74 cotizacion: 1,
181 simbolo: '$', 75 simbolo: '$',
182 soloMostrar: true 76 soloMostrar: true
183 } 77 }
184 }, 78 },
185 size: 'md' 79 size: 'md'
186 } 80 }
187 ); 81 );
82 modalInstance.result
83 .then(function (res) {
84 console.log("Producto => ", res);
85 })
86 .catch(function (e) { console.log(e) });
188 }; 87 };
88 $scope.closeModalPrecioCondicion = function () {
89 $uibModalInstance.dismiss('cancel');
90 };
91 //#endregion
189 92
190 function calcularPages(paginaActual) { 93 //#region Metodos para los plazos
191 var paginas = []; 94 $scope.addMorePlazos = function () {
192 paginas.push(paginaActual); 95 if ($scope.plazos.length < 4) {
193 96 $scope.plazos.unshift({ dias: 0 });
194 if (paginaActual - 1 > 1) {
195
196 paginas.unshift(paginaActual - 1);
197 if (paginaActual - 2 > 1) {
198 paginas.unshift(paginaActual - 2);
199 }
200 }
201
202 if (paginaActual + 1 < $scope.lastPage) {
203 paginas.push(paginaActual + 1);
204 if (paginaActual + 2 < $scope.lastPage) {
205 paginas.push(paginaActual + 2);
206 }
207 }
208
209 if (paginaActual !== 1) {
210 paginas.unshift(1);
211 }
212
213 if (paginaActual !== $scope.lastPage) {
214 paginas.push($scope.lastPage);
215 }
216
217 return paginas;
218 }
219
220 function primera() {
221 $scope.selectedPrecioCondicion = 0;
222 }
223
224 function anterior() {
225 if ($scope.selectedPrecioCondicion === 0 && $scope.currentPage > 1) {
226 retrocederPagina();
227 } else {
1 angular.module('focaModalPrecioCondicion') 1 angular.module('focaModalPrecioCondicion')
2 .service('focaModalPrecioCondicionService', [ 2 .service('focaModalPrecioCondicionService', [
3 '$http', 3 '$http',
4 'API_ENDPOINT', 4 'API_ENDPOINT',
5 function ($http, API_ENDPOINT) { 5 function ($http, API_ENDPOINT) {
6 return { 6 return {
7 getPlazosByIdPrecioCondicion: function (id) { 7 getPlazosByIdPrecioCondicion: function (id) {
8 return $http.get(API_ENDPOINT.URL + '/plazo-pago/precio-condicion/' + id); 8 return $http.get(API_ENDPOINT.URL + '/plazo-pago/precio-condicion/' + id);
9 }, 9 },
10 getPreciosCondiciones: function () { 10 getPreciosCondiciones: function () {
11 return $http.get(API_ENDPOINT.URL + '/precio-condicion/plazo-pago'); 11 return $http.get(API_ENDPOINT.URL + '/precio-condicion/plazo-pago');
12 }, 12 },
13 getPreciosCondicionesByIdListaPrecio: function (idListaPrecio) { 13 getPreciosCondicionesByIdListaPrecio: function (idListaPrecio) {
14 return $http.get(API_ENDPOINT.URL + '/precio-condicion/plazo-pago/' + 14 return $http.get(API_ENDPOINT.URL + '/precio-condicion/plazo-pago/' +
15 idListaPrecio); 15 idListaPrecio);
16 },
17 getListaPrecio: function (idListaPrecio) {
18 return $http.get(API_ENDPOINT.URL + '/lista-precio/' +
19 idListaPrecio);
20 },
21 getAllListaPrecio: function () {
22 return $http.get(API_ENDPOINT.URL + '/lista-precio');
16 } 23 }
17 }; 24 };
18 } 25 }
19 ]); 26 ]);
20 27
src/views/modal-precio-condicion.html
1 <div class="modal-header py-1"> 1 <div>
2 <div class="row w-100"> 2 <div class="modal-header py-1">
3 <div class="col-lg-6"> 3 <div class="row w-100">
4 <h5 ng-show="!ingreso" class="modal-title my-1">Búsqueda de Precio-Condición</h5> 4 <div class="col-lg-6">
5 <h5 ng-show="ingreso" class="modal-title my-1">Nuevos Plazos</h5> 5 <h5 class="modal-title my-1">Precio-Condición</h5>
6 </div>
7 <div class="input-group col-lg-6 pr-0 my-2" ng-show="!ingreso">
8 <button
9 class="btn btn-outline-debo mr-2"
10 ng-click="ingreso = true"
11 ng-show="!ingreso"
12 title="Nuevo">
13 <i class="fa fa-plus" aria-hidden="true"></i>
14 </button>
15 <input
16 type="text"
17 class="form-control form-control-sm"
18 id="search"
19 placeholder="Busqueda"
20 ng-model="filters"
21 ng-change="search()"
22 ng-keydown="busquedaDown($event.keyCode)"
23 ng-keypress="busquedaPress($event.keyCode)"
24 foca-focus="selectedPrecioCondicion == -1"
25 ng-focus="selectedPrecioCondicion = -1"
26 teclado-virtual
27 >
28 <div class="input-group-append">
29 <button
30 class="btn btn-outline-secondary"
31 type="button"
32 title="Buscar"
33 ng-click="busquedaPress(13)">
34 <i class="fa fa-search" aria-hidden="true"></i>
35 </button>
36 </div> 6 </div>
37 </div> 7 </div>
38 </div> 8 </div>
39 </div> 9 <div class="modal-body" id="modal-body">
40 <div class="modal-body" id="modal-body"> 10 <div ng-show="!ingreso">
41 11 <div class="row" ng-show="listaDePreciosAsociada.length == 0">
42 12 <div class="col">
43 <table ng-show="!ingreso" class="table table-striped table-sm">
44 <thead>
45 <tr>
46 <th>Código</th>
47 <th>Nombre</th>
48 <th>Lista Precio</th>
49 <th>Plazos</th>
50 <th></th>
51 </tr>
52 </thead>
53 <tbody>
54 <tr ng-show="currentPagePrecioCondicion.length == 0">
55 <td colspan="6">
56 No se encontraron resultados. 13 No se encontraron resultados.
57 </td> 14 </div>
58 </tr> 15 </div>
59 <tr class="selectable" 16 <div class="row px-2">
60 ng-repeat="(key, precioCondicion) in currentPagePrecioCondicion"> 17 <div class="col-lg-6">
61 <td ng-bind="precioCondicion.id | rellenarDigitos: 4: 0" 18 <div class="row border-top py-2">
62 ng-click="select(precioCondicion)"></td> 19 <div class="col-lg-9 col-9">Lista asociada al cliente</div>
63 <td ng-bind="precioCondicion.nombre" 20 <div class="col-lg-3 col-3 text-center">
64 ng-click="select(precioCondicion)"></td> 21 <button
65 <td ng-bind="precioCondicion.idListaPrecio" 22 ng-class="{'btn-primary': chosenClientList, 'btn-default': !chosenClientList}"
66 ng-click="select(precioCondicion)"></td> 23 class="btn btn-sm p-1"
67 <td ng-bind="precioCondicion.plazos" 24 ng-click="selectListaDePrecios(listaDePreciosAsociada)">
68 ng-click="select(precioCondicion)"></td> 25 <span class="fa fa-circle-thin"></span>
69 <td> 26 </button>
70 <button 27 </div>
71 type="button" 28 </div>
72 class="btn btn-sm p-1 float-right" 29 <div class="row align-items-center pb-2">
73 title="Seleccionar" 30 <div class="col-lg-2 col-2 text-center" ng-bind="listaDePreciosAsociada.ID"></div>
74 ng-class="{ 31 <div class="col-lg-7 col-7" ng-bind="listaDePreciosAsociada.DES"></div>
75 'btn-secondary': selectedPrecioCondicion != key + 1, 32 <div class="col-lg-3 col-3 text-center">
76 'btn-primary': selectedPrecioCondicion == key + 1 33 <button ng-click="verListaProductos(listaDePreciosAsociada.ID)" class="btn btn-sm p-1">
77 }" 34 <span class="fa fa-eye"></span>
78 foca-focus="selectedPrecioCondicion == {{key + 1}}" 35 </button>
79 ng-keydown="itemProducto($event.keyCode)" 36 </div>
80 ng-click="select(precioCondicion)" 37 </div>
81 > 38 <div class="row border-top py-2">
82 <i class="fa fa-circle-thin" aria-hidden="true"></i> 39 <div class="col-lg-9 col-9">Trabajar con otra lista</div>
83 </button> 40 <div class="col-lg-3 col-3 text-center">
84 <button 41 <button
85 type="button" 42 ng-class="{'btn-primary': !chosenClientList, 'btn-default': chosenClientList}"
86 class="btn btn-sm p-1 float-right btn-secondary mr-2" 43 class="btn btn-sm btn-default p-1"
87 title="Ver lista precio" 44 ng-click="openListaDePrecios()">
88 ng-click="verListaPrecio(precioCondicion.idListaPrecio)" 45 <span class="fa fa-circle-thin"></span>
89 > 46 </button>
90 <i class="fa fa-eye" aria-hidden="true"></i> 47 </div>
91 </button> 48 </div>
92 </td> 49 <div ng-show="listaDePreciosAlternativa != null" class="row align-items-center pb-1">
93 </tr> 50 <div class="col-lg-2 col-2 text-center" ng-bind="listaDePreciosAlternativa.ID"></div>
94 </tbody> 51 <div class="col-lg-7 col-7" ng-bind="listaDePreciosAlternativa.DES"></div>
95 </table> 52 <div class="col-lg-3 col-3 text-center">
96 53 <button ng-click="verListaProductos(listaDePreciosAlternativa.ID)" class="btn btn-sm p-1">
97 <table class="table table-striped table-sm" ng-show="ingreso"> 54 <span class="fa fa-eye"></span>
98 <thead> 55 </button>
99 <tr> 56 </div>
100 <th>Item</th> 57 </div>
101 <th>Días</th> 58 </div>
102 <th></th> 59 <div class="col">
103 </tr> 60 <div class="row border-bottom py-1">
104 </thead> 61 <div class="col text-center font-weight-bold">Plazos</div>
105 <tbody> 62 </div>
106 <tr> 63 <div ng-if="!editingPlazo" class="row align-items-center justify-content-end py-2">
107 <td> 64 <div class="col-lg-9 col-9 text-center">300, 254, 215, 265, 300, 300</div>
108 <input 65 <div class="col-lg-3 col-3">
109 type="number" 66 <button class="btn btn-sm text-center" ng-click="editPlazo()">
110 class="form-control text-right" 67 <span class="fa fa-pencil"></span>
111 ng-model="plazoACargar.item" 68 </button>
112 readonly 69 </div>
113 /> 70 </div>
114 </td> 71 <div ng-if="editingPlazo" class="row align-items-center justify-content-end py-2">
115 <td> 72 <div class="col-2 col-sm-2 px-2" ng-repeat="plazo in plazos" ng-show="plazos.length > 0">
116 <input 73 <input
117 type="number" 74 type="text"
118 class="form-control text-right" 75 class="form-control form-control-sm text-center"
119 min="0" 76 ng-model="plazo.dias"
120 ng-model="plazoACargar.dias" 77 limite-numeros-max="3"
121 ng-keypress="agregarPlazo($event.keyCode)" 78 ng-keyup="validateMinMax(plazo, 0, 365)"
122 foca-focus="ingreso" 79 select-on-click
123 /> 80 teclado-virtual
124 </td> 81 foca-tipo-input
125 <td class="text-center"> 82 solo-positivos>
126 <button 83 </div>
127 class="btn btn-outline-secondary" 84 <div class="col-lg-2 col-2 text-center">
128 title="Agregar" 85 <button
129 ng-click="agregarPlazo(13)" 86 class="btn btn-outline-debo"
130 > 87 ng-click="addMorePlazos()"
131 <i class="fa fa-save"></i> 88 ng-disabled="plazos.length == 4">
132 </button> 89 <span class="fa fa-plus"></span>
133 </td> 90 </button>
134 </tr> 91 </div>
135 <tr ng-repeat="(key, plazo) in plazosNuevos"> 92 <div class="col-lg-2 col-2 text-center">
136 <td class="text-right" ng-bind="key + 1"></td> 93 <button class="btn btn-primary">
137 <td class="text-right" ng-bind="plazo.dias"></td> 94 <span class="fa fa-save"></span>
138 <td class="text-center"> 95 </button>
139 <button 96 </div>
140 class="btn btn-outline-secondary" 97 </div>
141 title="Eliminar" 98 </div>
142 ng-click="quitarPlazo(key)" 99 </div>
143 > 100 </div>
144 <i class="fa fa-trash"></i> 101 </div>
145 </button> 102 <div class="modal-footer py-2">
146 </td> 103 <button class="btn btn-sm btn-secondary" type="button" ng-click="closeModalPrecioCondicion()">Cerrar
147 </tr> 104 </button>
148 </tbody> 105 </div>
149 </table> 106 </div>
150 </div>
151 <div class="modal-footer py-1">
152 <nav ng-show="currentPagePrecioCondicion.length > 0 && !ingreso" class="mr-auto">
153 <ul class="pagination pagination-sm mb-0">
154 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
155 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)">
156 <span aria-hidden="true">&laquo;</span>
157 <span class="sr-only">Anterior</span>
158 </a>
159 </li>
160 <li
161 class="page-item"
162 ng-repeat="pagina in paginas"
163 ng-class="{'active': pagina == currentPage}"
164 >
165 <a
166 class="page-link"
167 href="javascript:void();"
168 ng-click="selectPage(pagina)"
169 ng-bind="pagina"
170 ></a>
171 </li>
172 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
173 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)">
174 <span aria-hidden="true">&raquo;</span>
175 <span class="sr-only">Siguiente</span>
176 </a>
177 </li>
178 </ul>
179 </nav>
180 <button
181 ng-show="!ingreso"
182 class="btn btn-sm btn-secondary"
183 type="button"
184 ng-click="cancel()"
185 >Cancelar
186 </button>
187 <button
188 ng-show="ingreso"
189 ng-disabled="plazosNuevos.length === 0"
190 class="btn btn-sm btn-primary"
191 type="button"
192 ng-click="select(plazosNuevos)"
193 >Aceptar
194 </button>
195 <button
196 ng-show="ingreso"
197 class="btn btn-sm btn-secondary"
198 type="button"
199 ng-click="volver()"
200 >Volver
201 </button>
202 </div>
203