Commit 46fd86bb204059e34459e93cfb14a45bb216fb08

Authored by Luigi
1 parent 7965aabb27
Exists in master

Boton Pausar

Showing 1 changed file with 47 additions and 16 deletions   Show diff stats
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', '$localStorage',
5 function($scope, focaAbmPreciosCondicionesService, $location, 5 function($scope, focaAbmPreciosCondicionesService, $location,
6 focaModalService, focaBotoneraLateralService, $timeout) { 6 focaModalService, focaBotoneraLateralService, $timeout, $localStorage) {
7 7
8 $timeout(function() { 8 $timeout(function() {
9 focaBotoneraLateralService.showSalir(true); 9 focaBotoneraLateralService.showSalir(true);
10 focaBotoneraLateralService.showPausar(false); 10 focaBotoneraLateralService.showPausar(false);
11 focaBotoneraLateralService.showCancelar(false); 11 focaBotoneraLateralService.showCancelar(false);
12 focaBotoneraLateralService.showGuardar(false); 12 focaBotoneraLateralService.showGuardar(false);
13 }); 13 });
14
14 $scope.filters = ''; 15 $scope.filters = '';
15 $scope.now = new Date(); 16 $scope.now = new Date();
16 $scope.editar = function(id) { 17 $scope.editar = function(id) {
17 $location.path('/precio-condicion/' + id); 18 $location.path('/precio-condicion/' + id);
18 }; 19 };
19 $scope.solicitarConfirmacion = function(precioCondicion) { 20 $scope.solicitarConfirmacion = function(precioCondicion) {
20 focaModalService.confirm('¿Está seguro que desea borrar el precio condición' + 21 focaModalService.confirm('¿Está seguro que desea borrar el precio condición' +
21 precioCondicion.codigo + ' ' + precioCondicion.nombre + ' ?').then( 22 precioCondicion.codigo + ' ' + precioCondicion.nombre + ' ?').then(
22 function(data) { 23 function(data) {
23 if (data) { 24 if (data) {
24 focaAbmPreciosCondicionesService 25 focaAbmPreciosCondicionesService
25 .borrarPrecioCondicion(precioCondicion.id); 26 .borrarPrecioCondicion(precioCondicion.id);
26 $scope.preciosCondiciones.splice( 27 $scope.preciosCondiciones.splice(
27 $scope.preciosCondiciones.indexOf(precioCondicion), 1 28 $scope.preciosCondiciones.indexOf(precioCondicion), 1
28 ); 29 );
29 } 30 }
30 } 31 }
31 ); 32 );
32 }; 33 };
33 34
34 $scope.buscar = function(key) { 35 $scope.buscar = function(key) {
35 if(key === 13){ 36 if(key === 13){
36 focaAbmPreciosCondicionesService 37 focaAbmPreciosCondicionesService
37 .obtenerPreciosCondiciones($scope.filters) 38 .obtenerPreciosCondiciones($scope.filters)
38 .then(function(datos) { 39 .then(function(datos) {
39 $scope.preciosCondiciones = datos.data; 40 $scope.preciosCondiciones = datos.data;
40 $scope.preciosCondiciones.forEach(function(precioCondicion) { 41 $scope.preciosCondiciones.forEach(function(precioCondicion) {
41 precioCondicion.plazoPago.sort(function(a, b) { 42 precioCondicion.plazoPago.sort(function(a, b) {
42 return a.dias- b.dias; 43 return a.dias- b.dias;
43 }); 44 });
44 }); 45 });
45 }); 46 });
46 } 47 }
47 }; 48 };
49
50 if ($localStorage.precioCondicion) {
51 var precioCondicion = JSON.parse($localStorage.precioCondicion);
52 if (!precioCondicion.id) { precioCondicion.id = 0; }
53 $location.path('/precio-condicion/' + precioCondicion.id);
54 }
48 } 55 }
49 ]) 56 ])
50 .controller('focaAbmPrecioCondicionController', [ 57 .controller('focaAbmPrecioCondicionController', [
51 '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService', 58 '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService',
52 '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', 59 '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', '$localStorage', '$filter',
53 function( 60 function(
54 $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService, 61 $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService,
55 $routeParams, $location, focaModalService, $timeout, $uibModal, $window 62 $routeParams, $location, focaModalService, $timeout, $uibModal, $window, $localStorage, $filter) {
56 ) {
57 $scope.focused = 1; 63 $scope.focused = 1;
58 $scope.plazosAEliminar = []; 64 $scope.plazosAEliminar = [];
59 $scope.mostrarPlazos = $routeParams.id > 0; 65 $scope.mostrarPlazos = $routeParams.id > 0;
60 $scope.now = new Date(); 66 $scope.now = new Date();
61 $scope.listaPrecioLabel = ''; 67 $scope.listaPrecioLabel = '';
62 focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id) 68 focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id)
63 .then(function(datos) { 69 .then(function(datos) {
64 $scope.precioCondicion = { 70 $scope.precioCondicion = {
65 id: 0, 71 id: 0,
66 codigo: '', 72 codigo: '',
67 nombre: '', 73 nombre: '',
68 descripcion: '', 74 descripcion: '',
69 idListaPrecio: 0, 75 idListaPrecio: 0,
70 vigencia: new Date() 76 vigencia: new Date()
71 }; 77 };
72 if(datos.data.id) { 78 if (datos.data.id) {
73 $scope.precioCondicion = datos.data; 79 $scope.precioCondicion = datos.data;
74 $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() + 80 $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() +
75 ' - ' + datos.data.listaPrecio.DES; 81 ' - ' + datos.data.listaPrecio.DES;
76 $scope.$broadcast('addCabecera', { 82 $scope.$broadcast('addCabecera', {
77 label: 'Precio y condición:', 83 label: 'Precio y condición:',
78 valor: datos.data.nombre 84 valor: datos.data.nombre
79 }); 85 });
80 focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id) 86 focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id)
81 .then(function(datos) { 87 .then(function(datos) {
82 $scope.precioCondicion.plazos = datos.data; 88 $scope.precioCondicion.plazos = datos.data;
83 $scope.precioCondicion.plazos.sort(function(a, b) { 89 $scope.precioCondicion.plazos.sort(function(a, b) {
84 return a.dias- b.dias; 90 return a.dias- b.dias;
85 }); 91 });
86 $scope.plazoACargar = 92 $scope.plazoACargar =
87 { 93 {
88 item: datos.data.length + 1 94 item: datos.data.length + 1
89 }; 95 };
90 }); 96 });
91 } 97 }
92 }); 98 });
93 99
100 $timeout(function() {getLSPrecioC();});
101
94 $timeout(function() { 102 $timeout(function() {
95 focaBotoneraLateralService.showSalir(false); 103 focaBotoneraLateralService.showSalir(false);
96 focaBotoneraLateralService.showPausar(true); 104 focaBotoneraLateralService.showPausar(true);
97 focaBotoneraLateralService.showCancelar(true); 105 focaBotoneraLateralService.showCancelar(true);
98 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 106 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
99 }); 107 });
100 108
101 $scope.cancelar = function() { 109 $scope.cancelar = function() {
102 $location.path('/precio-condicion'); 110 $location.path('/precio-condicion');
103 }; 111 };
104 $scope.guardar = function() { 112 $scope.guardar = function() {
105 113
106 console.log($scope.precioCondicion);
107
108 if (!$scope.precioCondicion.nombre) { 114 if (!$scope.precioCondicion.nombre) {
109 focaModalService.alert('Ingrese nombre'); 115 focaModalService.alert('Ingrese nombre');
110 return; 116 return;
111 } else if (!$scope.precioCondicion.descripcion) { 117 } else if (!$scope.precioCondicion.descripcion) {
112 focaModalService.alert('Ingrese descripcion'); 118 focaModalService.alert('Ingrese descripcion');
113 return; 119 return;
114 } else if (!$scope.precioCondicion.idListaPrecio) { 120 } else if (!$scope.precioCondicion.idListaPrecio) {
115 focaModalService.alert('Seleccione precio'); 121 focaModalService.alert('Seleccione precio');
116 return; 122 return;
117 } 123 }
118 124
119 var promises = []; 125 var promises = [];
120 var precioCondicion = $scope.precioCondicion; 126 var precioCondicion = $scope.precioCondicion;
121 precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; 127 precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID;
122 delete precioCondicion.listaPrecio; 128 delete precioCondicion.listaPrecio;
123 if($scope.mostrarPlazos) { 129 if ($scope.mostrarPlazos) {
124 promises.push( 130 promises.push(
125 focaAbmPreciosCondicionesService 131 focaAbmPreciosCondicionesService
126 .guardarPlazosPago($scope.precioCondicion.plazos) 132 .guardarPlazosPago($scope.precioCondicion.plazos)
127 ); 133 );
128 $scope.plazosAEliminar.forEach(function(id) { 134 $scope.plazosAEliminar.forEach(function(id) {
129 promises.push( 135 promises.push(
130 focaAbmPreciosCondicionesService 136 focaAbmPreciosCondicionesService
131 .borrarPlazoPago(id) 137 .borrarPlazoPago(id)
132 ); 138 );
133 }); 139 });
134 } 140 }
135 promises.push( 141 promises.push(
136 focaAbmPreciosCondicionesService 142 focaAbmPreciosCondicionesService
137 .guardarPrecioCondicion(precioCondicion) 143 .guardarPrecioCondicion(precioCondicion)
138 ); 144 );
139 145
140 Promise.all(promises).then(function() { 146 Promise.all(promises).then(function() {
141 $timeout(function() { 147 $timeout(function() {
142 $location.path('/precio-condicion'); 148 $location.path('/precio-condicion');
143 }, 0); 149 }, 0);
144 }, function(err){ 150 }, function(err){
145 console.error(err); 151 console.error(err);
146 }); 152 });
147 }; 153 };
148 154
149 $scope.agregarPlazo = function(key) { 155 $scope.agregarPlazo = function(key) {
150 if(key === 13) { 156 if (key === 13) {
151 if(!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) { 157 if (!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) {
152 focaModalService.alert('Ingrese cantidad de días'); 158 focaModalService.alert('Ingrese cantidad de días');
153 return; 159 return;
154 } 160 }
155 var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { 161 var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) {
156 return a.dias === $scope.plazoACargar.dias; 162 return a.dias === $scope.plazoACargar.dias;
157 }); 163 });
158 if(tieneEseDia.length > 0) { 164 if (tieneEseDia.length > 0) {
159 focaModalService.alert('Ya ha ingresado un plazo con esos días'); 165 focaModalService.alert('Ya ha ingresado un plazo con esos días');
160 return; 166 return;
161 } 167 }
162 $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id; 168 $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id;
163 $scope.plazoACargar.activo = true; 169 $scope.plazoACargar.activo = true;
164 $scope.precioCondicion.plazos.push($scope.plazoACargar); 170 $scope.precioCondicion.plazos.push($scope.plazoACargar);
165 $scope.plazoACargar = 171 $scope.plazoACargar =
166 { 172 {
167 item: $scope.precioCondicion.plazos.length + 1 173 item: $scope.precioCondicion.plazos.length + 1
168 }; 174 };
169 } 175 }
170 }; 176 };
171 $scope.quitarPlazo = function(key) { 177 $scope.quitarPlazo = function(key) {
172 if($scope.precioCondicion.plazos[key].id) 178 if ($scope.precioCondicion.plazos[key].id)
173 $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); 179 $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id);
174 180
175 $scope.precioCondicion.plazos.splice(key, 1); 181 $scope.precioCondicion.plazos.splice(key, 1);
176 $scope.plazoACargar = 182 $scope.plazoACargar =
177 { 183 {
178 item: $scope.precioCondicion.plazos.length + 1 184 item: $scope.precioCondicion.plazos.length + 1
179 }; 185 };
180 }; 186 };
181 $scope.solicitarConfirmacionPlazoPago = function(plazoPago) { 187 $scope.solicitarConfirmacionPlazoPago = function(plazoPago) {
182 focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' + 188 focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' +
183 plazoPago.item + ' ' + plazoPago.dias + ' ?').then( 189 plazoPago.item + ' ' + plazoPago.dias + ' ?').then(
184 function(confirm) { 190 function(confirm) {
185 if (confirm) { 191 if (confirm) {
186 focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id); 192 focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id);
187 $scope.precioCondicion.plazos.splice( 193 $scope.precioCondicion.plazos.splice(
188 $scope.precioCondicion.plazos.indexOf(plazoPago), 1 194 $scope.precioCondicion.plazos.indexOf(plazoPago), 1
189 ); 195 );
190 } 196 }
191 } 197 }
192 ); 198 );
193 }; 199 };
194 200
195 $scope.seleccionarListaPrecio = function(key) { 201 $scope.seleccionarListaPrecio = function(key) {
196 if(key === 13){ 202 if (key === 13){
197 var modalInstance = $uibModal.open( 203 var modalInstance = $uibModal.open(
198 { 204 {
199 ariaLabelledBy: 'Busqueda de Listas de precio', 205 ariaLabelledBy: 'Busqueda de Listas de precio',
200 templateUrl: 'modal-lista-precio.html', 206 templateUrl: 'modal-lista-precio.html',
201 controller: 'focaModalListaPrecioCtrl', 207 controller: 'focaModalListaPrecioCtrl',
202 size: 'lg' 208 size: 'lg'
203 } 209 }
204 ); 210 );
205 modalInstance.result.then(function(listaPrecio) { 211 modalInstance.result.then(function(listaPrecio) {
206 $scope.precioCondicion.idListaPrecio = listaPrecio.ID; 212 $scope.precioCondicion.idListaPrecio = listaPrecio.ID;
207 $scope.precioCondicion.listaPrecio = listaPrecio; 213 $scope.precioCondicion.listaPrecio = listaPrecio;
208 $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; 214 $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES;
209 $scope.focused = 4; 215 $scope.focused = 4;
210 }); 216 });
211 } 217 }
212 }; 218 };
213 219
214 $scope.verProductosListaPrecio = function() { 220 $scope.verProductosListaPrecio = function() {
215 $uibModal.open( 221 $uibModal.open(
216 { 222 {
217 ariaLabelledBy: 'Busqueda de Productos', 223 ariaLabelledBy: 'Busqueda de Productos',
218 templateUrl: 'modal-busqueda-productos.html', 224 templateUrl: 'modal-busqueda-productos.html',
219 controller: 'modalBusquedaProductosCtrl', 225 controller: 'modalBusquedaProductosCtrl',
220 resolve: { 226 resolve: {
221 parametroProducto: { 227 parametroProducto: {
222 idLista: $scope.precioCondicion.listaPrecio.ID, 228 idLista: $scope.precioCondicion.listaPrecio.ID,
223 cotizacion: 1, 229 cotizacion: 1,
224 simbolo: '$', 230 simbolo: '$',
225 soloMostrar: true 231 soloMostrar: true
226 } 232 }
227 }, 233 },
228 size: 'md' 234 size: 'md'
229 } 235 }
230 ); 236 );
231 }; 237 };
232 238
233 $scope.next = function(key) { 239 $scope.next = function(key) {
234 if(key === 13) $scope.focused++; 240 if (key === 13) $scope.focused++;
235 }; 241 };
242
243 //watch
244 $scope.$watch('precioCondicion', function(newValue) {
245 focaBotoneraLateralService.setPausarData({
246 label: 'precioCondicion',
247 val: newValue
248 });
249 }, true);
250
251 function setearPrecioCondicion(precioCondicion) {
252 $scope.precioCondicion = precioCondicion;
253 $scope.$broadcast('addCabecera', {
254 label: 'Precio y Condicion:',
255 valor: $filter('rellenarDigitos')(precioCondicion.id)
256 });
257 }
258
259 function getLSPrecioC() {
260 var precioCondicion = JSON.parse($localStorage.precioCondicion || null);
261
262 if (precioCondicion) {
263 setearPrecioCondicion(precioCondicion);
264 delete $localStorage.precioCondicion;
265 }
266 }