Commit f6de94983d9e8708e7501dbdc8e7ca697e1d5763

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Agrego buscador

See merge request !4
src/js/controller.js
1 angular.module('focaAbmPreciosCondiciones') 1 angular.module('focaAbmPreciosCondiciones')
2 .controller('focaAbmPreciosCondicionesController', [ 2 .controller('focaAbmPreciosCondicionesController', [
3 '$scope', 'focaAbmPreciosCondicionesService', '$location', 3 '$scope', 'focaAbmPreciosCondicionesService', '$location',
4 'focaModalService', 'focaBotoneraLateralService', '$timeout', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout',
5 function($scope, focaAbmPreciosCondicionesService, $location, 5 function($scope, focaAbmPreciosCondicionesService, $location,
6 focaModalService, focaBotoneraLateralService, $timeout) { 6 focaModalService, focaBotoneraLateralService, $timeout) {
7 focaAbmPreciosCondicionesService.obtenerPreciosCondiciones().then(function(datos) { 7 focaAbmPreciosCondicionesService.obtenerPreciosCondiciones().then(function(datos) {
8 console.log(datos.data);
9 $scope.preciosCondiciones = datos.data; 8 $scope.preciosCondiciones = datos.data;
10 $scope.preciosCondiciones.forEach(function(precioCondicion) { 9 $scope.preciosCondiciones.forEach(function(precioCondicion) {
11 precioCondicion.plazoPago.sort(function(a, b) { 10 precioCondicion.plazoPago.sort(function(a, b) {
12 return a.dias- b.dias; 11 return a.dias- b.dias;
13 }); 12 });
14 }); 13 });
15 }); 14 });
16 15
17 $timeout(function() { 16 $timeout(function() {
18 focaBotoneraLateralService.showSalir(true); 17 focaBotoneraLateralService.showSalir(true);
19 focaBotoneraLateralService.showPausar(false); 18 focaBotoneraLateralService.showPausar(false);
20 focaBotoneraLateralService.showCancelar(false); 19 focaBotoneraLateralService.showCancelar(false);
21 focaBotoneraLateralService.showGuardar(false); 20 focaBotoneraLateralService.showGuardar(false);
22 }); 21 });
23 22
24 $scope.now = new Date(); 23 $scope.now = new Date();
25 $scope.editar = function(id) { 24 $scope.editar = function(id) {
26 $location.path('/precio-condicion/' + id); 25 $location.path('/precio-condicion/' + id);
27 }; 26 };
28 $scope.solicitarConfirmacion = function(precioCondicion) { 27 $scope.solicitarConfirmacion = function(precioCondicion) {
29 focaModalService.confirm('¿Está seguro que desea borrar el precio condición' + 28 focaModalService.confirm('¿Está seguro que desea borrar el precio condición' +
30 precioCondicion.codigo + ' ' + precioCondicion.nombre + ' ?').then( 29 precioCondicion.codigo + ' ' + precioCondicion.nombre + ' ?').then(
31 function(data) { 30 function(data) {
32 if (data) { 31 if (data) {
33 focaAbmPreciosCondicionesService 32 focaAbmPreciosCondicionesService
34 .borrarPrecioCondicion(precioCondicion.id); 33 .borrarPrecioCondicion(precioCondicion.id);
35 $scope.preciosCondiciones.splice( 34 $scope.preciosCondiciones.splice(
36 $scope.preciosCondiciones.indexOf(precioCondicion), 1 35 $scope.preciosCondiciones.indexOf(precioCondicion), 1
37 ); 36 );
38 } 37 }
39 } 38 }
40 ); 39 );
41 }; 40 };
42 } 41 }
43 ]) 42 ])
44 .controller('focaAbmPrecioCondicionController', [ 43 .controller('focaAbmPrecioCondicionController', [
45 '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService', 44 '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService',
46 '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', 45 '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window',
47 function( 46 function(
48 $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService, 47 $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService,
49 $routeParams, $location, focaModalService, $timeout, $uibModal, $window 48 $routeParams, $location, focaModalService, $timeout, $uibModal, $window
50 ) { 49 ) {
51 $scope.plazosAEliminar = []; 50 $scope.plazosAEliminar = [];
52 $scope.mostrarPlazos = $routeParams.id > 0; 51 $scope.mostrarPlazos = $routeParams.id > 0;
53 $scope.now = new Date(); 52 $scope.now = new Date();
54 $scope.listaPrecioLabel = ''; 53 $scope.listaPrecioLabel = '';
55 focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id) 54 focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id)
56 .then(function(datos) { 55 .then(function(datos) {
57 $scope.precioCondicion = { 56 $scope.precioCondicion = {
58 id: 0, 57 id: 0,
59 codigo: '', 58 codigo: '',
60 nombre: '', 59 nombre: '',
61 descripcion: '', 60 descripcion: '',
62 idListaPrecio: 0, 61 idListaPrecio: 0,
63 vigencia: new Date() 62 vigencia: new Date()
64 }; 63 };
65 if(datos.data.id) { 64 if(datos.data.id) {
66 $scope.precioCondicion = datos.data; 65 $scope.precioCondicion = datos.data;
67 $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() + 66 $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() +
68 ' - ' + datos.data.listaPrecio.DES; 67 ' - ' + datos.data.listaPrecio.DES;
69 $scope.$broadcast('addCabecera', { 68 $scope.$broadcast('addCabecera', {
70 label: 'Precio y condición:', 69 label: 'Precio y condición:',
71 valor: datos.data.nombre 70 valor: datos.data.nombre
72 }); 71 });
73 focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id) 72 focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id)
74 .then(function(datos) { 73 .then(function(datos) {
75 $scope.precioCondicion.plazos = datos.data; 74 $scope.precioCondicion.plazos = datos.data;
76 $scope.precioCondicion.plazos.sort(function(a, b) { 75 $scope.precioCondicion.plazos.sort(function(a, b) {
77 return a.dias- b.dias; 76 return a.dias- b.dias;
78 }); 77 });
79 $scope.plazoACargar = 78 $scope.plazoACargar =
80 { 79 {
81 item: datos.data.length + 1 80 item: datos.data.length + 1
82 }; 81 };
83 }); 82 });
84 } 83 }
85 }); 84 });
86 85
87 $timeout(function() { 86 $timeout(function() {
88 focaBotoneraLateralService.showSalir(false); 87 focaBotoneraLateralService.showSalir(false);
89 focaBotoneraLateralService.showPausar(true); 88 focaBotoneraLateralService.showPausar(true);
90 focaBotoneraLateralService.showCancelar(true); 89 focaBotoneraLateralService.showCancelar(true);
91 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 90 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
92 }); 91 });
93 92
94 $scope.cancelar = function() { 93 $scope.cancelar = function() {
95 $location.path('/precio-condicion'); 94 $location.path('/precio-condicion');
96 }; 95 };
97 $scope.guardar = function() { 96 $scope.guardar = function() {
98 var promises = []; 97 var promises = [];
99 var precioCondicion = $scope.precioCondicion; 98 var precioCondicion = $scope.precioCondicion;
100 precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; 99 precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID;
101 delete precioCondicion.listaPrecio; 100 delete precioCondicion.listaPrecio;
102 if($scope.mostrarPlazos) { 101 if($scope.mostrarPlazos) {
103 promises.push( 102 promises.push(
104 focaAbmPreciosCondicionesService 103 focaAbmPreciosCondicionesService
105 .guardarPlazosPago($scope.precioCondicion.plazos) 104 .guardarPlazosPago($scope.precioCondicion.plazos)
106 ); 105 );
107 $scope.plazosAEliminar.forEach(function(id) { 106 $scope.plazosAEliminar.forEach(function(id) {
108 promises.push( 107 promises.push(
109 focaAbmPreciosCondicionesService 108 focaAbmPreciosCondicionesService
110 .borrarPlazoPago(id) 109 .borrarPlazoPago(id)
111 ); 110 );
112 }); 111 });
113 } 112 }
114 promises.push( 113 promises.push(
115 focaAbmPreciosCondicionesService 114 focaAbmPreciosCondicionesService
116 .guardarPrecioCondicion(precioCondicion) 115 .guardarPrecioCondicion(precioCondicion)
117 ); 116 );
118 117
119 Promise.all(promises).then(function() { 118 Promise.all(promises).then(function() {
120 $window.location.assign('/#!/precio-condicion'); 119 $window.location.assign('/#!/precio-condicion');
121 }, function(err){ 120 }, function(err){
122 console.error(err); 121 console.error(err);
123 }); 122 });
124 }; 123 };
125 124
126 $scope.agregarPlazo = function(key) { 125 $scope.agregarPlazo = function(key) {
127 if(key === 13) { 126 if(key === 13) {
128 if(!$scope.plazoACargar.dias) { 127 if(!$scope.plazoACargar.dias) {
129 focaModalService.alert('Ingrese cantidad de días'); 128 focaModalService.alert('Ingrese cantidad de días');
130 return; 129 return;
131 } 130 }
132 var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { 131 var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) {
133 return a.dias === $scope.plazoACargar.dias; 132 return a.dias === $scope.plazoACargar.dias;
134 }); 133 });
135 if(tieneEseDia.length > 0) { 134 if(tieneEseDia.length > 0) {
136 focaModalService.alert('Ya ha ingresado un plazo con esos días'); 135 focaModalService.alert('Ya ha ingresado un plazo con esos días');
137 return; 136 return;
138 } 137 }
139 $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id; 138 $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id;
140 $scope.plazoACargar.activo = true; 139 $scope.plazoACargar.activo = true;
141 $scope.precioCondicion.plazos.push($scope.plazoACargar); 140 $scope.precioCondicion.plazos.push($scope.plazoACargar);
142 $scope.plazoACargar = 141 $scope.plazoACargar =
143 { 142 {
144 item: $scope.precioCondicion.plazos.length + 1 143 item: $scope.precioCondicion.plazos.length + 1
145 }; 144 };
146 } 145 }
147 }; 146 };
148 $scope.quitarPlazo = function(key) { 147 $scope.quitarPlazo = function(key) {
149 if($scope.precioCondicion.plazos[key].id) 148 if($scope.precioCondicion.plazos[key].id)
150 $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); 149 $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id);
151 150
152 $scope.precioCondicion.plazos.splice(key, 1); 151 $scope.precioCondicion.plazos.splice(key, 1);
153 $scope.plazoACargar = 152 $scope.plazoACargar =
154 { 153 {
155 item: $scope.precioCondicion.plazos.length + 1 154 item: $scope.precioCondicion.plazos.length + 1
156 }; 155 };
157 }; 156 };
158 $scope.solicitarConfirmacionPlazoPago = function(plazoPago) { 157 $scope.solicitarConfirmacionPlazoPago = function(plazoPago) {
159 focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' + 158 focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' +
160 plazoPago.item + ' ' + plazoPago.dias + ' ?').then( 159 plazoPago.item + ' ' + plazoPago.dias + ' ?').then(
161 function(confirm) { 160 function(confirm) {
162 if (confirm) { 161 if (confirm) {
163 focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id); 162 focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id);
164 $scope.precioCondicion.plazos.splice( 163 $scope.precioCondicion.plazos.splice(
165 $scope.precioCondicion.plazos.indexOf(plazoPago), 1 164 $scope.precioCondicion.plazos.indexOf(plazoPago), 1
166 ); 165 );
167 } 166 }
168 } 167 }
169 ); 168 );
170 }; 169 };
171 170
172 $scope.seleccionarListaPrecio = function() { 171 $scope.seleccionarListaPrecio = function() {
173 var modalInstance = $uibModal.open( 172 var modalInstance = $uibModal.open(
174 { 173 {
175 ariaLabelledBy: 'Busqueda de Listas de precio', 174 ariaLabelledBy: 'Busqueda de Listas de precio',
176 templateUrl: 'modal-lista-precio.html', 175 templateUrl: 'modal-lista-precio.html',
177 controller: 'focaModalListaPrecioCtrl', 176 controller: 'focaModalListaPrecioCtrl',
178 size: 'lg' 177 size: 'lg'
179 } 178 }
180 ); 179 );
181 modalInstance.result.then(function(listaPrecio) { 180 modalInstance.result.then(function(listaPrecio) {
182 $scope.precioCondicion.listaPrecio = listaPrecio; 181 $scope.precioCondicion.listaPrecio = listaPrecio;
183 $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; 182 $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES;
184 }); 183 });
185 }; 184 };
186 } 185 }
187 ]); 186 ]);
188 187
src/views/foca-abm-precios-condiciones-listado.html
1 <div class="row"> 1 <div class="row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Precios y condiciones'" 3 titulo="'Precios y condiciones'"
4 fecha="now" 4 fecha="now"
5 class="mb-0 col-lg-12" 5 class="mb-0 col-lg-12"
6 ></foca-cabecera-facturador> 6 ></foca-cabecera-facturador>
7 </div> 7 </div>
8 <div class="row"> 8 <div class="row">
9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> 9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded">
10 <div class="form-group input-group mt-3 px-5">
11 <input
12 type="text"
13 class="form-control form-control-sm"
14 id="search"
15 placeholder="Búsqueda"
16 teclado-virtual
17 ng-keypress="busquedaPress($event.keyCode)"
18 ng-model="filters"
19 />
20 <div class="input-group-append">
21 <button
22 ladda="searchLoading"
23 class="btn btn-outline-secondary"
24 type="button"
25 ng-click="busquedaPress(13)"
26 >
27 <i class="fa fa-search" aria-hidden="true"></i>
28 </button>
29 </div>
30 </div>
10 <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> 31 <table class="table table-default table-hover table-sm table-abm table-striped mb-0">
11 <thead> 32 <thead>
12 <tr> 33 <tr>
13 <th>Nombre</th> 34 <th>Nombre</th>
14 <th>Lista de precio</th> 35 <th>Lista de precio</th>
15 <th>Plazos</th> 36 <th>Plazos</th>
16 <th colspan="2" class="text-center"> 37 <th colspan="2" class="text-center">
17 <button 38 <button
18 title="Agregar" 39 title="Agregar"
19 class="btn btn-outline-debo boton-accion" 40 class="btn btn-outline-debo boton-accion"
20 ng-click="editar(0)"> 41 ng-click="editar(0)">
21 <i class="fa fa-plus"></i> 42 <i class="fa fa-plus"></i>
22 </button> 43 </button>
23 </th> 44 </th>
24 </tr> 45 </tr>
25 </thead> 46 </thead>
26 <tbody> 47 <tbody>
27 <tr ng-repeat="precioCondicion in preciosCondiciones"> 48 <tr ng-repeat="precioCondicion in preciosCondiciones | filter: filters">
28 <td ng-bind="precioCondicion.nombre"></td> 49 <td ng-bind="precioCondicion.nombre"></td>
29 <td ng-bind="precioCondicion.listaPrecio.ID + ' - ' + precioCondicion.listaPrecio.DES + ' - ' + precioCondicion.listaPrecio.moneda.DETALLE"></td> 50 <td ng-bind="precioCondicion.listaPrecio.ID + ' - ' + precioCondicion.listaPrecio.DES + ' - ' + precioCondicion.listaPrecio.moneda.DETALLE"></td>
30 <td><span 51 <td><span
31 ng-repeat="plazo in precioCondicion.plazoPago" 52 ng-repeat="plazo in precioCondicion.plazoPago"
32 ng-if="plazo.activo" 53 ng-if="plazo.activo"
33 ng-bind="$last ? plazo.dias : plazo.dias + ', '"></span></td> 54 ng-bind="$last ? plazo.dias : plazo.dias + ', '"></span></td>
34 <td class="text-center"> 55 <td class="text-center">
35 <button 56 <button
36 title="Editar" 57 title="Editar"
37 class="btn btn-outline-dark boton-accion" 58 class="btn btn-outline-dark boton-accion"
38 ng-click="editar(precioCondicion.id)"> 59 ng-click="editar(precioCondicion.id)">
39 <i class="fa fa-pencil"></i> 60 <i class="fa fa-pencil"></i>
40 </button> 61 </button>
41 <button 62 <button
42 title="Eliminar" 63 title="Eliminar"
43 class="btn btn-outline-dark boton-accion" 64 class="btn btn-outline-dark boton-accion"
44 ng-click="solicitarConfirmacion(precioCondicion)"> 65 ng-click="solicitarConfirmacion(precioCondicion)">
45 <i class="fa fa-trash"></i> 66 <i class="fa fa-trash"></i>
46 </button> 67 </button>
47 </td> 68 </td>
48 </tr> 69 </tr>
49 </tbody> 70 </tbody>
50 </table> 71 </table>
51 </div> 72 </div>
52 </div> 73 </div>
53 74