Commit ab64fc7b312ef77f0172dea35eec0c7f8837aa34

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

Arreglo boton Pausar

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