Commit e22a685b3d74898e1d2b80d877a8aacf9a67a9b4

Authored by Eric
1 parent e51d8be247
Exists in master and in 1 other branch develop

fix id

Showing 1 changed file with 8 additions and 16 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaParametros') 1 angular.module('focaParametros')
2 .controller('focaParametrosCtrl', [ 2 .controller('focaParametrosCtrl', [
3 '$scope', 3 '$scope',
4 'focaParametrosService', 4 'focaParametrosService',
5 'focaBotoneraLateralService', 5 'focaBotoneraLateralService',
6 '$filter', 6 '$filter',
7 'focaModalService', 7 'focaModalService',
8 '$timeout', 8 '$timeout',
9 '$uibModal', 9 '$uibModal',
10 '$location',
10 function($scope, focaParametrosService, focaBotoneraLateralService, $filter, 11 function($scope, focaParametrosService, focaBotoneraLateralService, $filter,
11 focaModalService, $timeout, $uibModal) 12 focaModalService, $timeout, $uibModal, $location)
12 { 13 {
13 14
14 $scope.botonera = []; 15 $scope.botonera = [];
15 $scope.now = new Date(); 16 $scope.now = new Date();
16 17
17 $scope.botoneraPrincipal = focaParametrosService.getBotonesPrincipal; 18 $scope.botoneraPrincipal = focaParametrosService.getBotonesPrincipal;
18 19
19 $timeout(function() { 20 $timeout(function() {
20 focaBotoneraLateralService.showSalir(true); 21 focaBotoneraLateralService.showSalir(true);
21 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 22 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
22 }); 23 });
23 24
24 focaParametrosService.getParametros().then(function(res) { 25 focaParametrosService.getParametros().then(function(res) {
25 26
26 $scope.$broadcast('cleanCabecera'); 27 $scope.$broadcast('cleanCabecera');
27 res.data.forEach(function(entidad) { 28 res.data.forEach(function(entidad) {
28 29
29 setearEntidad(entidad); 30 setearEntidad(entidad);
30 }); 31 });
31 }); 32 });
32 33
33 $scope.guardar = function() { 34 $scope.guardar = function() {
34 35
35 focaParametrosService.saveParametros(getObjGuardar()).then(function() { 36 focaParametrosService.saveParametros(getObjGuardar()).then(function() {
36 focaModalService.alert('Parámetros guardados con éxito'); 37 focaModalService.alert('Parámetros guardados con éxito');
38 $location.url('/');
37 }); 39 });
38 }; 40 };
39 41
40 $scope.seleccionarPuntosDeDescarga = function() { 42 $scope.seleccionarPuntosDeDescarga = function() {
41 if (!$scope[getModulo()].cliente.COD || !$scope[getModulo()].domicilio.id) { 43 if (!$scope[getModulo()].cliente.COD || !$scope[getModulo()].domicilio.id) {
42 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 44 focaModalService.alert('Primero seleccione un cliente y un domicilio');
43 return; 45 return;
44 } else { 46 } else {
45 var modalInstance = $uibModal.open( 47 var modalInstance = $uibModal.open(
46 { 48 {
47 ariaLabelledBy: 'Búsqueda de Puntos de descarga', 49 ariaLabelledBy: 'Búsqueda de Puntos de descarga',
48 templateUrl: 'modal-punto-descarga.html', 50 templateUrl: 'modal-punto-descarga.html',
49 controller: 'focaModalPuntoDescargaController', 51 controller: 'focaModalPuntoDescargaController',
50 size: 'lg', 52 size: 'lg',
51 resolve: { 53 resolve: {
52 filters: { 54 filters: {
53 idDomicilio: $scope[getModulo()].domicilio.id, 55 idDomicilio: $scope[getModulo()].domicilio.id,
54 idCliente: $scope[getModulo()].cliente.COD, 56 idCliente: $scope[getModulo()].cliente.COD,
55 articulos: $scope[getModulo()].articulosNotaPedido || [], 57 articulos: $scope[getModulo()].articulosNotaPedido || [],
56 puntoDescarga: $scope[getModulo()].notaPedidoPuntoDescarga, 58 puntoDescarga: $scope[getModulo()].notaPedidoPuntoDescarga,
57 domicilio: $scope[getModulo()].domicilio 59 domicilio: $scope[getModulo()].domicilio
58 } 60 }
59 } 61 }
60 } 62 }
61 ); 63 );
62 modalInstance.result.then( 64 modalInstance.result.then(
63 function(puntoDescarga) { 65 function(puntoDescarga) {
64 $scope[getModulo()].notaPedidoPuntoDescarga = puntoDescarga; 66 $scope[getModulo()].notaPedidoPuntoDescarga = puntoDescarga;
65 67
66 $scope.$broadcast('addCabecera', { 68 $scope.$broadcast('addCabecera', {
67 label: 'Puntos de descarga:', 69 label: 'Puntos de descarga:',
68 seccion: getModulo('label'), 70 seccion: getModulo('label'),
69 valor: getCabeceraPuntoDescarga(puntoDescarga) 71 valor: getCabeceraPuntoDescarga(puntoDescarga)
70 }); 72 });
71 }, function() { 73 }, function() {
72 $scope.abrirModalDomicilios($scope.cliente); 74 $scope.abrirModalDomicilios($scope.cliente);
73 } 75 }
74 ); 76 );
75 } 77 }
76 }; 78 };
77 79
78 $scope.seleccionarFlete = function() { 80 $scope.seleccionarFlete = function() {
79 81
80 if ($scope[getModulo()].flete === undefined) { 82 if ($scope[getModulo()].flete === undefined) {
81 $scope[getModulo()].fob = undefined; 83 $scope[getModulo()].fob = undefined;
82 $scope[getModulo()].bomba = undefined; 84 $scope[getModulo()].bomba = undefined;
83 $scope[getModulo()].kilometros = undefined; 85 $scope[getModulo()].kilometros = undefined;
84 86
85 } 87 }
86 88
87 var modalInstance = $uibModal.open( 89 var modalInstance = $uibModal.open(
88 { 90 {
89 ariaLabelledBy: 'Busqueda de Flete', 91 ariaLabelledBy: 'Busqueda de Flete',
90 templateUrl: 'modal-flete.html', 92 templateUrl: 'modal-flete.html',
91 controller: 'focaModalFleteController', 93 controller: 'focaModalFleteController',
92 size: 'lg', 94 size: 'lg',
93 resolve: { 95 resolve: {
94 parametrosFlete: 96 parametrosFlete:
95 function() { 97 function() {
96 return { 98 return {
97 flete: $scope[getModulo()].fob ? 'FOB' : 99 flete: $scope[getModulo()].fob ? 'FOB' :
98 ( $scope[getModulo()].flete ? '1' : 100 ( $scope[getModulo()].flete ? '1' :
99 ($scope[getModulo()].flete === undefined ? 101 ($scope[getModulo()].flete === undefined ?
100 null : '0')), 102 null : '0')),
101 bomba: $scope[getModulo()].bomba ? '1' : 103 bomba: $scope[getModulo()].bomba ? '1' :
102 ($scope[getModulo()].bomba === undefined ? 104 ($scope[getModulo()].bomba === undefined ?
103 null : '0'), 105 null : '0'),
104 kilometros: $scope[getModulo()].kilometros 106 kilometros: $scope[getModulo()].kilometros
105 }; 107 };
106 } 108 }
107 } 109 }
108 } 110 }
109 ); 111 );
110 modalInstance.result.then( 112 modalInstance.result.then(
111 function(datos) { 113 function(datos) {
112 $scope[getModulo()].flete = datos.flete; 114 $scope[getModulo()].flete = datos.flete;
113 $scope[getModulo()].fob = datos.FOB; 115 $scope[getModulo()].fob = datos.FOB;
114 $scope[getModulo()].bomba = datos.bomba; 116 $scope[getModulo()].bomba = datos.bomba;
115 $scope[getModulo()].kilometros = datos.kilometros; 117 $scope[getModulo()].kilometros = datos.kilometros;
116 $scope.$broadcast('addCabecera', { 118 $scope.$broadcast('addCabecera', {
117 label: 'Flete:', 119 label: 'Flete:',
118 seccion: getModulo('label'), 120 seccion: getModulo('label'),
119 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') 121 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No')
120 }); 122 });
121 if (datos.flete) { 123 if (datos.flete) {
122 $scope.$broadcast('addCabecera', { 124 $scope.$broadcast('addCabecera', {
123 label: 'Bomba:', 125 label: 'Bomba:',
124 seccion: getModulo('label'), 126 seccion: getModulo('label'),
125 valor: datos.bomba ? 'Si' : 'No' 127 valor: datos.bomba ? 'Si' : 'No'
126 }); 128 });
127 $scope.$broadcast('addCabecera', { 129 $scope.$broadcast('addCabecera', {
128 label: 'Kilometros:', 130 label: 'Kilometros:',
129 seccion: getModulo('label'), 131 seccion: getModulo('label'),
130 valor: datos.kilometros 132 valor: datos.kilometros
131 }); 133 });
132 } else { 134 } else {
133 $scope.$broadcast('removeCabecera', 'Bomba:'); 135 $scope.$broadcast('removeCabecera', 'Bomba:');
134 $scope.$broadcast('removeCabecera', 'Kilometros:'); 136 $scope.$broadcast('removeCabecera', 'Kilometros:');
135 $scope[getModulo()].bomba = false; 137 $scope[getModulo()].bomba = false;
136 $scope[getModulo()].kilometros = null; 138 $scope[getModulo()].kilometros = null;
137 } 139 }
138 }, function() { 140 }, function() {
139 } 141 }
140 ); 142 );
141 }; 143 };
142 144
143 $scope.seleccionarVendedor = function() { 145 $scope.seleccionarVendedor = function() {
144 146
145 var parametrosModal = { 147 var parametrosModal = {
146 titulo: 'Búsqueda vendedores', 148 titulo: 'Búsqueda vendedores',
147 query: '/vendedor', 149 query: '/vendedor',
148 columnas: [ 150 columnas: [
149 { 151 {
150 propiedad: 'NUM', 152 propiedad: 'NUM',
151 nombre: 'Código', 153 nombre: 'Código',
152 filtro: { 154 filtro: {
153 nombre: 'rellenarDigitos', 155 nombre: 'rellenarDigitos',
154 parametro: 3 156 parametro: 3
155 } 157 }
156 }, 158 },
157 { 159 {
158 propiedad: 'NOM', 160 propiedad: 'NOM',
159 nombre: 'Nombre' 161 nombre: 'Nombre'
160 } 162 }
161 ], 163 ],
162 size: 'md' 164 size: 'md'
163 }; 165 };
164 focaModalService.modal(parametrosModal).then( 166 focaModalService.modal(parametrosModal).then(
165 function(vendedor) { 167 function(vendedor) {
166 $scope.$broadcast('addCabecera', { 168 $scope.$broadcast('addCabecera', {
167 label: 'Vendedor:', 169 label: 'Vendedor:',
168 seccion: getModulo('label'), 170 seccion: getModulo('label'),
169 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 171 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
170 vendedor.NOM 172 vendedor.NOM
171 }); 173 });
172 $scope[getModulo()].vendedor = vendedor; 174 $scope[getModulo()].vendedor = vendedor;
173 }, function() {} 175 }, function() {}
174 ); 176 );
175 }; 177 };
176 178
177 $scope.seleccionarCliente = function() { 179 $scope.seleccionarCliente = function() {
178 180
179 if (!$scope[getModulo()].vendedor) { 181 if (!$scope[getModulo()].vendedor) {
180 focaModalService.alert('Seleccione Vendedor'); 182 focaModalService.alert('Seleccione Vendedor');
181 return; 183 return;
182 } 184 }
183 185
184 var modalInstance = $uibModal.open( 186 var modalInstance = $uibModal.open(
185 { 187 {
186 ariaLabelledBy: 'Busqueda de Cliente', 188 ariaLabelledBy: 'Busqueda de Cliente',
187 templateUrl: 'foca-busqueda-cliente-modal.html', 189 templateUrl: 'foca-busqueda-cliente-modal.html',
188 controller: 'focaBusquedaClienteModalController', 190 controller: 'focaBusquedaClienteModalController',
189 resolve: { 191 resolve: {
190 vendedor: function() { return $scope.notaPedido.vendedor; }, 192 vendedor: function() { return $scope.notaPedido.vendedor; },
191 cobrador: function() { return null; } 193 cobrador: function() { return null; }
192 }, 194 },
193 size: 'lg' 195 size: 'lg'
194 } 196 }
195 ); 197 );
196 modalInstance.result.then( 198 modalInstance.result.then(
197 function(cliente) { 199 function(cliente) {
198 $scope.abrirModalDomicilios(cliente); 200 $scope.abrirModalDomicilios(cliente);
199 }, function() { } 201 }, function() { }
200 ); 202 );
201 }; 203 };
202 204
203 $scope.seleccionarProveedor = function() { 205 $scope.seleccionarProveedor = function() {
204 206
205 var parametrosModal = { 207 var parametrosModal = {
206 titulo: 'Búsqueda de Proveedor', 208 titulo: 'Búsqueda de Proveedor',
207 query: '/proveedor', 209 query: '/proveedor',
208 columnas: [ 210 columnas: [
209 { 211 {
210 nombre: 'Código', 212 nombre: 'Código',
211 propiedad: 'COD', 213 propiedad: 'COD',
212 filtro: { 214 filtro: {
213 nombre: 'rellenarDigitos', 215 nombre: 'rellenarDigitos',
214 parametro: 5 216 parametro: 5
215 } 217 }
216 }, 218 },
217 { 219 {
218 nombre: 'Nombre', 220 nombre: 'Nombre',
219 propiedad: 'NOM' 221 propiedad: 'NOM'
220 }, 222 },
221 { 223 {
222 nombre: 'CUIT', 224 nombre: 'CUIT',
223 propiedad: 'CUIT' 225 propiedad: 'CUIT'
224 } 226 }
225 ], 227 ],
226 tipo: 'POST', 228 tipo: 'POST',
227 json: {razonCuitCod: ''} 229 json: {razonCuitCod: ''}
228 }; 230 };
229 focaModalService.modal(parametrosModal).then( 231 focaModalService.modal(parametrosModal).then(
230 function(proveedor) { 232 function(proveedor) {
231 $scope[getModulo()].proveedor = proveedor; 233 $scope[getModulo()].proveedor = proveedor;
232 $scope.$broadcast('addCabecera', { 234 $scope.$broadcast('addCabecera', {
233 label: 'Proveedor:', 235 label: 'Proveedor:',
234 seccion: getModulo('label'), 236 seccion: getModulo('label'),
235 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 237 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
236 proveedor.NOM 238 proveedor.NOM
237 }); 239 });
238 }, function() { 240 }, function() {
239 } 241 }
240 ); 242 );
241 243
242 }; 244 };
243 245
244 $scope.abrirModalDomicilios = function(cliente) { 246 $scope.abrirModalDomicilios = function(cliente) {
245 var modalInstanceDomicilio = $uibModal.open( 247 var modalInstanceDomicilio = $uibModal.open(
246 { 248 {
247 ariaLabelledBy: 'Busqueda de Domicilios', 249 ariaLabelledBy: 'Busqueda de Domicilios',
248 templateUrl: 'modal-domicilio.html', 250 templateUrl: 'modal-domicilio.html',
249 controller: 'focaModalDomicilioController', 251 controller: 'focaModalDomicilioController',
250 resolve: { 252 resolve: {
251 idCliente: function() { return cliente.cod; }, 253 idCliente: function() { return cliente.cod; },
252 esNuevo: function() { return cliente.esNuevo; } 254 esNuevo: function() { return cliente.esNuevo; }
253 }, 255 },
254 size: 'lg', 256 size: 'lg',
255 } 257 }
256 ); 258 );
257 modalInstanceDomicilio.result.then( 259 modalInstanceDomicilio.result.then(
258 function(domicilio) { 260 function(domicilio) {
259 261
260 $scope[getModulo()].domicilio = domicilio; 262 $scope[getModulo()].domicilio = domicilio;
261 263
262 $scope[getModulo()].cliente = { 264 $scope[getModulo()].cliente = {
263 COD: cliente.cod, 265 COD: cliente.cod,
264 CUIT: cliente.cuit, 266 CUIT: cliente.cuit,
265 NOM: cliente.nom, 267 NOM: cliente.nom,
266 MOD: cliente.mod 268 MOD: cliente.mod
267 }; 269 };
268 270
269 var domicilioStamp = 271 var domicilioStamp =
270 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 272 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
271 domicilio.Localidad + ', ' + domicilio.Provincia; 273 domicilio.Localidad + ', ' + domicilio.Provincia;
272 $scope[getModulo()].domicilioStamp = domicilioStamp; 274 $scope[getModulo()].domicilioStamp = domicilioStamp;
273 275
274 $scope[getModulo()].notaPedidoPuntoDescarga = domicilio.puntoDescarga; 276 $scope[getModulo()].notaPedidoPuntoDescarga = domicilio.puntoDescarga;
275 277
276 $scope.$broadcast('addCabecera', { 278 $scope.$broadcast('addCabecera', {
277 label: 'Cliente:', 279 label: 'Cliente:',
278 seccion: getModulo('label'), 280 seccion: getModulo('label'),
279 valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom 281 valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom
280 }); 282 });
281 $scope.$broadcast('addCabecera', { 283 $scope.$broadcast('addCabecera', {
282 label: 'Domicilio:', 284 label: 'Domicilio:',
283 seccion: getModulo('label'), 285 seccion: getModulo('label'),
284 valor: domicilioStamp 286 valor: domicilioStamp
285 }); 287 });
286 if (domicilio.verPuntos) { 288 if (domicilio.verPuntos) {
287 delete $scope[getModulo()].domicilio.verPuntos; 289 delete $scope[getModulo()].domicilio.verPuntos;
288 $scope.seleccionarPuntosDeDescarga(); 290 $scope.seleccionarPuntosDeDescarga();
289 } else { 291 } else {
290 focaParametrosService 292 focaParametrosService
291 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) 293 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
292 .then(function(res) { 294 .then(function(res) {
293 if (res.data.length) $scope.seleccionarPuntosDeDescarga(); 295 if (res.data.length) $scope.seleccionarPuntosDeDescarga();
294 }); 296 });
295 } 297 }
296 }, function() { 298 }, function() {
297 $scope.seleccionarCliente(true); 299 $scope.seleccionarCliente(true);
298 return; 300 return;
299 } 301 }
300 ); 302 );
301 }; 303 };
302 304
303 $scope.seleccionarMoneda = function() { 305 $scope.seleccionarMoneda = function() {
304 306
305 var parametrosModal = { 307 var parametrosModal = {
306 titulo: 'Búsqueda de monedas', 308 titulo: 'Búsqueda de monedas',
307 query: '/moneda', 309 query: '/moneda',
308 columnas: [ 310 columnas: [
309 { 311 {
310 propiedad: 'DETALLE', 312 propiedad: 'DETALLE',
311 nombre: 'Nombre' 313 nombre: 'Nombre'
312 }, 314 },
313 { 315 {
314 propiedad: 'SIMBOLO', 316 propiedad: 'SIMBOLO',
315 nombre: 'Símbolo' 317 nombre: 'Símbolo'
316 } 318 }
317 ], 319 ],
318 size: 'md' 320 size: 'md'
319 }; 321 };
320 focaModalService.modal(parametrosModal).then( 322 focaModalService.modal(parametrosModal).then(
321 function(moneda) { 323 function(moneda) {
322 $scope.abrirModalCotizacion(moneda); 324 $scope.abrirModalCotizacion(moneda);
323 }, function() { 325 }, function() {
324 } 326 }
325 ); 327 );
326 328
327 }; 329 };
328 330
329 $scope.abrirModalCotizacion = function(moneda) { 331 $scope.abrirModalCotizacion = function(moneda) {
330 var modalInstance = $uibModal.open( 332 var modalInstance = $uibModal.open(
331 { 333 {
332 ariaLabelledBy: 'Busqueda de Cotización', 334 ariaLabelledBy: 'Busqueda de Cotización',
333 templateUrl: 'modal-cotizacion.html', 335 templateUrl: 'modal-cotizacion.html',
334 controller: 'focaModalCotizacionController', 336 controller: 'focaModalCotizacionController',
335 size: 'lg', 337 size: 'lg',
336 resolve: { 338 resolve: {
337 idMoneda: function() { 339 idMoneda: function() {
338 return moneda.ID; 340 return moneda.ID;
339 } 341 }
340 } 342 }
341 } 343 }
342 ); 344 );
343 modalInstance.result.then( 345 modalInstance.result.then(
344 function(cotizacion) { 346 function(cotizacion) {
345 // var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || [];
346 // for (var i = 0; i < articulosTablaTemp.length; i++) {
347 // articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
348 // $scope.notaPedido.cotizacion.VENDEDOR;
349 // articulosTablaTemp[i].precio = (articulosTablaTemp[i].precio /
350 // cotizacion.VENDEDOR).toFixed(4);
351 // }
352 // $scope[getModulo()].articulosNotaPedido = articulosTablaTemp;
353 $scope[getModulo()].cotizacion = cotizacion; 347 $scope[getModulo()].cotizacion = cotizacion;
354 $scope[getModulo()].cotizacion.moneda = moneda; 348 $scope[getModulo()].cotizacion.moneda = moneda;
355 349
356 $scope.$broadcast('addCabecera', { 350 $scope.$broadcast('addCabecera', {
357 label: 'Moneda:', 351 label: 'Moneda:',
358 seccion: getModulo('label'), 352 seccion: getModulo('label'),
359 valor: moneda.DETALLE 353 valor: moneda.DETALLE
360 }); 354 });
361 $scope.$broadcast('addCabecera', { 355 $scope.$broadcast('addCabecera', {
362 label: 'Fecha cotizacion:', 356 label: 'Fecha cotizacion:',
363 seccion: getModulo('label'), 357 seccion: getModulo('label'),
364 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 358 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
365 }); 359 });
366 $scope.$broadcast('addCabecera', { 360 $scope.$broadcast('addCabecera', {
367 label: 'Cotizacion:', 361 label: 'Cotizacion:',
368 seccion: getModulo('label'), 362 seccion: getModulo('label'),
369 valor: $filter('number')(cotizacion.VENDEDOR, '2') 363 valor: $filter('number')(cotizacion.VENDEDOR, '2')
370 }); 364 });
371 365
372 }, function() { 366 }, function() {
373 367
374 } 368 }
375 ); 369 );
376 }; 370 };
377 371
378 $scope.seleccionarObservaciones = function() { 372 $scope.seleccionarObservaciones = function() {
379 var observacion = { 373 var observacion = {
380 titulo: 'Ingrese Observaciones', 374 titulo: 'Ingrese Observaciones',
381 value: $scope[getModulo()].observaciones, 375 value: $scope[getModulo()].observaciones,
382 maxlength: 155, 376 maxlength: 155,
383 textarea: true 377 textarea: true
384 }; 378 };
385 379
386 focaModalService 380 focaModalService
387 .prompt(observacion) 381 .prompt(observacion)
388 .then(function(observaciones) { 382 .then(function(observaciones) {
389 $scope[getModulo()].observaciones = observaciones; 383 $scope[getModulo()].observaciones = observaciones;
390 $scope.$broadcast('addCabecera', { 384 $scope.$broadcast('addCabecera', {
391 label: 'Observaciones:', 385 label: 'Observaciones:',
392 valor: observaciones 386 valor: observaciones
393 }); 387 });
394 }); 388 });
395 }; 389 };
396 390
397 $scope.seleccionarPreciosYCondiciones = function() { 391 $scope.seleccionarPreciosYCondiciones = function() {
398 if (!$scope[getModulo()].cliente || !$scope[getModulo()].cliente.COD) { 392 if (!$scope[getModulo()].cliente || !$scope[getModulo()].cliente.COD) {
399 focaModalService.alert('Primero seleccione un cliente'); 393 focaModalService.alert('Primero seleccione un cliente');
400 return; 394 return;
401 } 395 }
402 396
403 var modalInstance = $uibModal.open( 397 var modalInstance = $uibModal.open(
404 { 398 {
405 ariaLabelledBy: 'Busqueda de Precio Condición', 399 ariaLabelledBy: 'Busqueda de Precio Condición',
406 templateUrl: 'modal-precio-condicion.html', 400 templateUrl: 'modal-precio-condicion.html',
407 controller: 'focaModalPrecioCondicionController', 401 controller: 'focaModalPrecioCondicionController',
408 size: 'lg', 402 size: 'lg',
409 resolve: { 403 resolve: {
410 idListaPrecio: function() { 404 idListaPrecio: function() {
411 return $scope[getModulo()].cliente.MOD || null; 405 return $scope[getModulo()].cliente.MOD || null;
412 } 406 }
413 } 407 }
414 } 408 }
415 ); 409 );
416 410
417 modalInstance.result.then( 411 modalInstance.result.then(
418 function(precioCondicion) { 412 function(precioCondicion) {
419 var cabecera = ''; 413 var cabecera = '';
420 var plazosConcat = ''; 414 var plazosConcat = '';
421 if (!Array.isArray(precioCondicion)) { 415 if (!Array.isArray(precioCondicion)) {
422 $scope[getModulo()][getModulo() + 'Plazo' ]= precioCondicion.plazoPago; 416 $scope[getModulo()][getModulo() + 'Plazo' ]= precioCondicion.plazoPago;
423 $scope[getModulo()].precioCondicion = precioCondicion; 417 $scope[getModulo()].precioCondicion = precioCondicion;
424 $scope[getModulo()].idPrecioCondicion = precioCondicion.id; 418 $scope[getModulo()].idPrecioCondicion = precioCondicion.id;
425 $scope.idLista = precioCondicion.idListaPrecio; 419 $scope.idLista = precioCondicion.idListaPrecio;
426 for (var i = 0; i < precioCondicion.plazoPago.length; i++) { 420 for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
427 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 421 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
428 } 422 }
429 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + 423 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
430 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); 424 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
431 } else { //Cuando se ingresan los plazos manualmente 425 } else { //Cuando se ingresan los plazos manualmente
432 $scope[getModulo()].idPrecioCondicion = 0; 426 $scope[getModulo()].idPrecioCondicion = 0;
433 //-1, el modal productos busca todos los productos 427 //-1, el modal productos busca todos los productos
434 $scope.idLista = -1; 428 $scope.idLista = -1;
435 $scope[getModulo()][ getModulo() + 'Plazo'] = precioCondicion; 429 $scope[getModulo()][ getModulo() + 'Plazo'] = precioCondicion;
436 for (var j = 0; j < precioCondicion.length; j++) { 430 for (var j = 0; j < precioCondicion.length; j++) {
437 plazosConcat += precioCondicion[j].dias + ' '; 431 plazosConcat += precioCondicion[j].dias + ' ';
438 } 432 }
439 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 433 cabecera = 'Ingreso manual ' + plazosConcat.trim();
440 } 434 }
441 $scope.$broadcast('addCabecera', { 435 $scope.$broadcast('addCabecera', {
442 label: 'Precios y condiciones:', 436 label: 'Precios y condiciones:',
443 seccion: getModulo('label'), 437 seccion: getModulo('label'),
444 valor: cabecera 438 valor: cabecera
445 }); 439 });
446 }, function() { 440 }, function() {
447 441
448 } 442 }
449 ); 443 );
450 444
451 }; 445 };
452 446
453 $scope.$watch('botonera', function() { 447 $scope.$watch('botonera', function() {
454 448
455 // Creo el string en donde guardo el objeto parseado 449 // Creo el string en donde guardo el objeto parseado
456 $scope[getModulo()] = $scope[getModulo()] || {}; 450 $scope[getModulo()] = $scope[getModulo()] || {};
457 451
458 getCheckeds(); 452 getCheckeds();
459 }, true); 453 }, true);
460 454
461 $scope.botoneraPrincipal.forEach(function(botonPincipal) { 455 $scope.botoneraPrincipal.forEach(function(botonPincipal) {
462 456
463 // watch en objetos principales para ir guardando los valores 457 // watch en objetos principales para ir guardando los valores
464 $scope.$watch(botonPincipal.variable, function() { 458 $scope.$watch(botonPincipal.variable, function() {
465 459
466 $scope[botonPincipal.variable + 'String'] = { 460 $scope[botonPincipal.variable + 'String'] = {
467 jsonText: JSON.stringify($scope[botonPincipal.variable]), 461 jsonText: JSON.stringify($scope[botonPincipal.variable]),
468 modulo: botonPincipal.variable, 462 modulo: botonPincipal.variable,
469 id: $scope[botonPincipal.variable] ? 463 id: $scope[botonPincipal.variable + 'String'] ?
470 $scope[botonPincipal.variable].id : null 464 $scope[botonPincipal.variable + 'String'].id : undefined
471 }; 465 };
472 466
473 getCheckeds(); 467 getCheckeds();
474 }, true); 468 }, true);
475 469
476 // creo las funciones para seleccionar boton principal 470 // creo las funciones para seleccionar boton principal
477 $scope[nombreFuncion(botonPincipal.label)] = function() { 471 $scope[nombreFuncion(botonPincipal.label)] = function() {
478 472
479 $scope.botoneraPrincipal.filter(function(boton) { 473 $scope.botoneraPrincipal.filter(function(boton) {
480 boton.checked = false; 474 boton.checked = false;
481 }); 475 });
482 476
483 botonPincipal.checked = true; 477 botonPincipal.checked = true;
484 $scope.botonera = focaParametrosService.getBotones(botonPincipal.modulo); 478 $scope.botonera = focaParametrosService.getBotones(botonPincipal.modulo);
485 }; 479 };
486 480
487 }); 481 });
488 482
489 function nombreFuncion(string) { 483 function nombreFuncion(string) {
490 var texto = 'seleccionar'; 484 var texto = 'seleccionar';
491 var arr = string.split(' '); 485 var arr = string.split(' ');
492 arr.forEach(function(palabra) { 486 arr.forEach(function(palabra) {
493 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); 487 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1);
494 texto += palabra; 488 texto += palabra;
495 }); 489 });
496 return texto; 490 return texto;
497 } 491 }
498 492
499 function getModulo(propiedad) { 493 function getModulo(propiedad) {
500 var nombre = ''; 494 var nombre = '';
501 495
502 $scope.botoneraPrincipal.filter(function(boton) { 496 $scope.botoneraPrincipal.filter(function(boton) {
503 if (boton.checked) { 497 if (boton.checked) {
504 if(!propiedad) { 498 if(!propiedad) {
505 nombre = boton.variable; 499 nombre = boton.variable;
506 } else { 500 } else {
507 nombre = boton[propiedad]; 501 nombre = boton[propiedad];
508 } 502 }
509 } 503 }
510 }); 504 });
511 return nombre; 505 return nombre;
512 } 506 }
513 507
514 function getCheckeds() { 508 function getCheckeds() {
515 509
516 $scope.botonera.forEach(function(boton) { 510 $scope.botonera.forEach(function(boton) {
517 511
518 if ($scope[getModulo()][boton.variable] !== undefined) { 512 if ($scope[getModulo()][boton.variable] !== undefined) {
519 513
520 boton.checked = true; 514 boton.checked = true;
521 515
522 //Creo la función para limpiar obj 516 //Creo la función para limpiar obj
523 $scope['clean' + boton.variable] = function() { 517 $scope['clean' + boton.variable] = function() {
524 518
525 focaModalService.alert('Esta seguro que desea eliminar el parámetro?') 519 focaModalService.alert('Esta seguro que desea eliminar el parámetro?')
526 .then(function() { 520 .then(function() {
527 delete $scope[getModulo()][boton.variable]; 521 delete $scope[getModulo()][boton.variable];
528 $scope.$broadcast('cleanCabecera', { 522 $scope.$broadcast('cleanCabecera', {
529 seccion: getModulo('label') 523 seccion: getModulo('label')
530 }); 524 });
531 setearEntidad({ 525 setearEntidad({
532 jsonText: JSON.stringify($scope[getModulo()]), 526 jsonText: JSON.stringify($scope[getModulo()]),
533 modulo: getModulo(), 527 modulo: getModulo(),
534 id: $scope[getModulo()].id 528 id: $scope[getModulo() + 'String'].id
535 }); 529 });
536 }); 530 });
537 }; 531 };
538 532
539 } else { 533 } else {
540 boton.checked = false; 534 boton.checked = false;
541 } 535 }
542 }); 536 });
543 } 537 }
544 538
545 function getCabeceraPuntoDescarga(puntoDescarga) { 539 function getCabeceraPuntoDescarga(puntoDescarga) {
546 var puntosStamp = ''; 540 var puntosStamp = '';
547 puntoDescarga.forEach(function(punto, idx, arr) { 541 puntoDescarga.forEach(function(punto, idx, arr) {
548 puntosStamp += punto.descripcion; 542 puntosStamp += punto.descripcion;
549 if ((idx + 1) !== arr.length) puntosStamp += ', '; 543 if ((idx + 1) !== arr.length) puntosStamp += ', ';
550 }); 544 });
551 return puntosStamp; 545 return puntosStamp;
552 } 546 }
553 547
554 function setearEntidad(entidad) { 548 function setearEntidad(entidad) {
555 549
556 $scope[entidad.modulo] = JSON.parse(entidad.jsonText) || {}; 550 $scope[entidad.modulo] = JSON.parse(entidad.jsonText) || {};
557 $scope[entidad.modulo].id = entidad.id; 551 $scope[entidad.modulo + 'String'].id = entidad.id;
558 552
559 if (!$scope[entidad.modulo].domicilio) { 553 if (!$scope[entidad.modulo].domicilio) {
560 $scope[entidad.modulo].domicilio = { 554 $scope[entidad.modulo].domicilio = {
561 id: $scope[entidad.modulo].idDomicilio 555 id: $scope[entidad.modulo].idDomicilio
562 }; 556 };
563 } 557 }
564 558
565 var cabeceras = []; 559 var cabeceras = [];
566 560
567 if ($scope[entidad.modulo].cotizacion && 561 if ($scope[entidad.modulo].cotizacion) {
568 $scope[entidad.modulo].cotizacion.moneda.CODIGO_AFIP !== 'PES')
569 {
570 cabeceras.push({ 562 cabeceras.push({
571 label: 'Moneda:', 563 label: 'Moneda:',
572 valor: $scope[entidad.modulo].cotizacion.moneda.DETALLE 564 valor: $scope[entidad.modulo].cotizacion.moneda.DETALLE
573 }); 565 });
574 cabeceras.push({ 566 cabeceras.push({
575 label: 'Fecha cotizacion:', 567 label: 'Fecha cotizacion:',
576 valor: $filter('date')($scope[entidad.modulo].cotizacion.FECHA, 568 valor: $filter('date')($scope[entidad.modulo].cotizacion.FECHA,
577 'dd/MM/yyyy') 569 'dd/MM/yyyy')
578 }); 570 });
579 cabeceras.push({ 571 cabeceras.push({
580 label: 'Cotizacion:', 572 label: 'Cotizacion:',
581 valor: $filter('number')($scope[entidad.modulo].cotizacion.VENDEDOR, 573 valor: $filter('number')($scope[entidad.modulo].cotizacion.VENDEDOR,
582 '2') 574 '2')
583 }); 575 });
584 } 576 }
585 577
586 if ($scope[entidad.modulo].vendedor && $scope[entidad.modulo].vendedor.NUM) { 578 if ($scope[entidad.modulo].vendedor && $scope[entidad.modulo].vendedor.NUM) {
587 cabeceras.push({ 579 cabeceras.push({
588 label: 'Vendedor:', 580 label: 'Vendedor:',
589 valor: $filter('rellenarDigitos')($scope[entidad.modulo].vendedor.NUM, 3) + 581 valor: $filter('rellenarDigitos')($scope[entidad.modulo].vendedor.NUM, 3) +
590 ' - ' + $scope[entidad.modulo].vendedor.NOM 582 ' - ' + $scope[entidad.modulo].vendedor.NOM
591 }); 583 });
592 } 584 }
593 585
594 if ($scope[entidad.modulo].cliente && $scope[entidad.modulo].cliente.COD) { 586 if ($scope[entidad.modulo].cliente && $scope[entidad.modulo].cliente.COD) {
595 cabeceras.push({ 587 cabeceras.push({
596 label: 'Cliente:', 588 label: 'Cliente:',
597 valor: $scope[entidad.modulo].cliente.NOM 589 valor: $scope[entidad.modulo].cliente.NOM
598 }); 590 });
599 cabeceras.push({ 591 cabeceras.push({
600 label: 'Domicilio:', 592 label: 'Domicilio:',
601 valor: $scope[entidad.modulo].domicilioStamp 593 valor: $scope[entidad.modulo].domicilioStamp
602 }); 594 });
603 } 595 }
604 596
605 if ($scope[entidad.modulo].proveedor && $scope[entidad.modulo].proveedor.COD) { 597 if ($scope[entidad.modulo].proveedor && $scope[entidad.modulo].proveedor.COD) {
606 cabeceras.push({ 598 cabeceras.push({
607 label: 'Proveedor:', 599 label: 'Proveedor:',
608 valor: $filter('rellenarDigitos')($scope[entidad.modulo].proveedor.COD, 5) + 600 valor: $filter('rellenarDigitos')($scope[entidad.modulo].proveedor.COD, 5) +
609 ' - ' + $scope[entidad.modulo].proveedor.NOM 601 ' - ' + $scope[entidad.modulo].proveedor.NOM
610 }); 602 });
611 } 603 }
612 604
613 if ($scope[entidad.modulo][entidad + 'Plazo'] && 605 if ($scope[entidad.modulo][entidad + 'Plazo'] &&
614 $scope[entidad.modulo][entidad + 'Plazo'].length) 606 $scope[entidad.modulo][entidad + 'Plazo'].length)
615 { 607 {
616 cabeceras.push({ 608 cabeceras.push({
617 label: 'Precios y condiciones:', 609 label: 'Precios y condiciones:',
618 valor: valorPrecioCondicion() + ' ' + 610 valor: valorPrecioCondicion() + ' ' +
619 focaParametrosService.plazoToString( 611 focaParametrosService.plazoToString(
620 $scope[entidad.modulo][entidad.modulo + 'Plazo']) 612 $scope[entidad.modulo][entidad.modulo + 'Plazo'])
621 }); 613 });
622 } 614 }
623 615
624 if ($scope[entidad.modulo].flete !== undefined) { 616 if ($scope[entidad.modulo].flete !== undefined) {
625 cabeceras.push({ 617 cabeceras.push({
626 label: 'Flete:', 618 label: 'Flete:',
627 valor: $scope[entidad.modulo].fob === 1 ? 'FOB' : ( 619 valor: $scope[entidad.modulo].fob === 1 ? 'FOB' : (
628 $scope[entidad.modulo].flete === 1 ? 'Si' : 'No') 620 $scope[entidad.modulo].flete === 1 ? 'Si' : 'No')
629 }); 621 });
630 } 622 }
631 623
632 function valorPrecioCondicion() { 624 function valorPrecioCondicion() {
633 if ($scope[entidad.modulo].idPrecioCondicion > 0) { 625 if ($scope[entidad.modulo].idPrecioCondicion > 0) {
634 return $scope[entidad.modulo].precioCondicion.nombre; 626 return $scope[entidad.modulo].precioCondicion.nombre;
635 } else { 627 } else {
636 return 'Ingreso Manual'; 628 return 'Ingreso Manual';
637 } 629 }
638 } 630 }
639 631
640 if ($scope[entidad.modulo].flete === 1) { 632 if ($scope[entidad.modulo].flete === 1) {
641 var cabeceraBomba = { 633 var cabeceraBomba = {
642 label: 'Bomba:', 634 label: 'Bomba:',
643 valor: $scope[entidad.modulo].bomba === 1 ? 'Si' : 'No' 635 valor: $scope[entidad.modulo].bomba === 1 ? 'Si' : 'No'
644 }; 636 };
645 if ($scope[entidad.modulo].kilometros) { 637 if ($scope[entidad.modulo].kilometros) {
646 var cabeceraKilometros = { 638 var cabeceraKilometros = {
647 label: 'Kilometros:', 639 label: 'Kilometros:',
648 valor: $scope[entidad.modulo].kilometros 640 valor: $scope[entidad.modulo].kilometros
649 }; 641 };
650 cabeceras.push(cabeceraKilometros); 642 cabeceras.push(cabeceraKilometros);
651 } 643 }
652 cabeceras.push(cabeceraBomba); 644 cabeceras.push(cabeceraBomba);
653 } 645 }
654 646
655 if ($scope[entidad.modulo].idPrecioCondicion > 0) { 647 if ($scope[entidad.modulo].idPrecioCondicion > 0) {
656 $scope.idLista = $scope[entidad.modulo].precioCondicion.idListaPrecio; 648 $scope.idLista = $scope[entidad.modulo].precioCondicion.idListaPrecio;
657 } else { 649 } else {
658 $scope.idLista = -1; 650 $scope.idLista = -1;
659 } 651 }
660 652
661 if ($scope[entidad.modulo][entidad.modulo + 'PuntoDescarga']) { 653 if ($scope[entidad.modulo][entidad.modulo + 'PuntoDescarga']) {
662 var puntos = []; 654 var puntos = [];
663 $scope[entidad.modulo][entidad.modulo + 'PuntoDescarga'] 655 $scope[entidad.modulo][entidad.modulo + 'PuntoDescarga']
664 .forEach(function(entidadPuntoDescarga) { 656 .forEach(function(entidadPuntoDescarga) {
665 puntos.push(entidadPuntoDescarga); 657 puntos.push(entidadPuntoDescarga);
666 }); 658 });
667 cabeceras.push({ 659 cabeceras.push({
668 label: 'Puntos de descarga: ', 660 label: 'Puntos de descarga: ',
669 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) 661 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos))
670 }); 662 });
671 } 663 }
672 664
673 addArrayCabecera(cabeceras, entidad.modulo); 665 addArrayCabecera(cabeceras, entidad.modulo);
674 666
675 } 667 }
676 668
677 function addArrayCabecera(array, entidad) { 669 function addArrayCabecera(array, entidad) {
678 for (var i = 0; i < array.length; i++) { 670 for (var i = 0; i < array.length; i++) {
679 $scope.$broadcast('addCabecera', { 671 $scope.$broadcast('addCabecera', {
680 label: array[i].label, 672 label: array[i].label,
681 valor: array[i].valor, 673 valor: array[i].valor,
682 seccion: $filter('filter') 674 seccion: $filter('filter')
683 ($scope.botoneraPrincipal, {variable: entidad}, true)[0].label 675 ($scope.botoneraPrincipal, {variable: entidad}, true)[0].label
684 }); 676 });
685 } 677 }
686 } 678 }
687 679
688 function getObjGuardar() { 680 function getObjGuardar() {
689 var guardar = []; 681 var guardar = [];
690 $scope.botoneraPrincipal.forEach(function(botonPincipal) { 682 $scope.botoneraPrincipal.forEach(function(botonPincipal) {
691 if (!botonPincipal || !$scope[botonPincipal.variable + 'String']) return; 683 if (!botonPincipal || !$scope[botonPincipal.variable + 'String']) return;
692 guardar.push($scope[botonPincipal.variable + 'String']); 684 guardar.push($scope[botonPincipal.variable + 'String']);
693 }); 685 });
694 686
695 return guardar; 687 return guardar;
696 } 688 }
697 689