Commit c76376a71266e7490cdae257797f8ab8a7b8c8f6

Authored by Jose Pinto
1 parent 2a07998e7e
Exists in master

fuera log

Showing 1 changed file with 0 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 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