Commit fe05d8dc9f7b3b8fdc02cf24fa6742c053bf8be1

Authored by Jose Pinto
1 parent 5493a16be8
Exists in master

fuera window.location.assign

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