Commit a08587385bd444b6f18f6aa3baccd942c0468848

Authored by Luigi
1 parent 1d11b89a3f
Exists in master

Cambio de "Cancelar" a "Salir"

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