Commit efc61556bbe9c06c6b12eaf4f6e5f8e74d22fecf
Exists in
master
Merge branch 'develop' into 'master'
Develop See merge request !81
Showing
3 changed files
Show diff stats
package.json
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | "description": "sistema de cobranzas a partir de facturas", |
5 | 5 | "main": "index.js", |
6 | 6 | "scripts": { |
7 | + "refresh": "gulp uglify && cp tmp/foca-crear-cobranza.js ../wrapper-demo/node_modules/foca-crear-cobranza/dist/foca-crear-cobranza.min.js", | |
7 | 8 | "test": "test.html", |
8 | 9 | "compile": "gulp uglify", |
9 | 10 | "gulp-pre-commit": "gulp pre-commit", |
spec/controllerSpec.js
... | ... | @@ -439,68 +439,6 @@ describe('controladores módulo crear cobranza', function() { |
439 | 439 | expect(scope.cobroDeuda).toEqual(true); |
440 | 440 | }); |
441 | 441 | |
442 | - it('seleccionarCobranza levanta modal y setea datos', function(done) { | |
443 | - | |
444 | - //arrange | |
445 | - var scope = { | |
446 | - $broadcast: function() { }, | |
447 | - $watch: function() { } | |
448 | - }; | |
449 | - var uibModal = { | |
450 | - open: function() { } | |
451 | - }; | |
452 | - | |
453 | - $controller('cobranzaController', { | |
454 | - $scope: scope, | |
455 | - $timeout: $timeout, | |
456 | - $uibModal: uibModal, | |
457 | - $location: {}, | |
458 | - focaCrearCobranzaService: { | |
459 | - getCotizacionByIdMoneda: function() { | |
460 | - return { | |
461 | - then: function() { } | |
462 | - }; | |
463 | - }, | |
464 | - getBotonera: function() { }, | |
465 | - getNumeroRecibo: function() { | |
466 | - return { | |
467 | - then: function() { } | |
468 | - }; | |
469 | - } | |
470 | - }, | |
471 | - focaModalService: {}, | |
472 | - $filter: $filter, | |
473 | - focaSeguimientoService: {}, | |
474 | - focaBotoneraLateralService: {}, | |
475 | - APP: {}, | |
476 | - focaLoginService: {}, | |
477 | - $localStorage: true | |
478 | - }); | |
479 | - var respuesta = { | |
480 | - facturas: 1, | |
481 | - cobros: 2, | |
482 | - cliente: { }, | |
483 | - moneda: { | |
484 | - cotizaciones: [] | |
485 | - } | |
486 | - }; | |
487 | - var promesa = { result: Promise.resolve(respuesta) }; | |
488 | - | |
489 | - //act | |
490 | - spyOn(uibModal, 'open').and.returnValue(promesa); | |
491 | - spyOn(scope, '$broadcast'); | |
492 | - scope.seleccionarCobranza(); | |
493 | - | |
494 | - //assert | |
495 | - promesa.result.then(function() { | |
496 | - expect(uibModal.open).toHaveBeenCalled(); | |
497 | - expect(scope.$broadcast).toHaveBeenCalledWith('cleanCabecera'); | |
498 | - expect(scope.cobranza.facturas).toEqual(respuesta.facturas); | |
499 | - expect(scope.cobranza.cobros).toEqual(respuesta.cobros); | |
500 | - done(); | |
501 | - }); | |
502 | - }); | |
503 | - | |
504 | 442 | it('seleccionarCliente levanta modal y setea datos', function(done) { |
505 | 443 | |
506 | 444 | //arrange |
... | ... | @@ -950,61 +888,6 @@ describe('controladores módulo crear cobranza', function() { |
950 | 888 | }); |
951 | 889 | }); |
952 | 890 | |
953 | - it('seleccionarCobrador levanta modal', function(done) { | |
954 | - | |
955 | - //arrange | |
956 | - var scope = { | |
957 | - $broadcast: function() { }, | |
958 | - $watch: function() { } | |
959 | - }; | |
960 | - var focaModalService = { | |
961 | - modal: function() { } | |
962 | - }; | |
963 | - | |
964 | - $controller('cobranzaController', { | |
965 | - $scope: scope, | |
966 | - $timeout: $timeout, | |
967 | - $uibModal: {}, | |
968 | - $location: {}, | |
969 | - focaCrearCobranzaService: { | |
970 | - getCotizacionByIdMoneda: function() { | |
971 | - return { | |
972 | - then: function() { } | |
973 | - }; | |
974 | - }, | |
975 | - getBotonera: function() { }, | |
976 | - getNumeroRecibo: function() { | |
977 | - return { | |
978 | - then: function() { } | |
979 | - }; | |
980 | - } | |
981 | - }, | |
982 | - focaModalService: focaModalService, | |
983 | - $filter: $filter, | |
984 | - focaSeguimientoService: {}, | |
985 | - focaBotoneraLateralService: {}, | |
986 | - APP: {}, | |
987 | - focaLoginService: {}, | |
988 | - $localStorage: true | |
989 | - }); | |
990 | - | |
991 | - var respuesta = 1; | |
992 | - var promesa = Promise.resolve(respuesta); | |
993 | - | |
994 | - //act | |
995 | - spyOn(focaModalService, 'modal').and.returnValue(promesa); | |
996 | - spyOn(scope, '$broadcast'); | |
997 | - scope.seleccionarCobrador({ }); | |
998 | - | |
999 | - //assert | |
1000 | - promesa.then(function() { | |
1001 | - expect(focaModalService.modal).toHaveBeenCalled(); | |
1002 | - expect(scope.$broadcast).toHaveBeenCalled(); | |
1003 | - scope.cobranza.cobrador = respuesta; | |
1004 | - done(); | |
1005 | - }); | |
1006 | - }); | |
1007 | - | |
1008 | 891 | it('getTotalDeuda devuelve correcto', function() { |
1009 | 892 | |
1010 | 893 | //arrange |
src/js/controller.js
1 | -angular.module('focaCrearCobranza') .controller('cobranzaController', | |
1 | +angular.module('focaCrearCobranza').controller('cobranzaController', | |
2 | 2 | [ |
3 | 3 | '$scope', '$timeout', '$uibModal', '$location', |
4 | 4 | 'focaCrearCobranzaService', 'focaModalService', '$filter', 'focaSeguimientoService', |
5 | 5 | 'focaBotoneraLateralService', 'APP', 'focaLoginService', '$localStorage', |
6 | - function($scope, $timeout, $uibModal, $location, focaCrearCobranzaService, | |
6 | + function ($scope, $timeout, $uibModal, $location, focaCrearCobranzaService, | |
7 | 7 | focaModalService, $filter, focaSeguimientoService, focaBotoneraLateralService, |
8 | - APP, loginService, $localStorage) | |
9 | - { | |
8 | + APP, loginService, $localStorage) { | |
10 | 9 | config(); |
11 | 10 | |
12 | 11 | function config() { |
... | ... | @@ -23,17 +22,17 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
23 | 22 | }; |
24 | 23 | |
25 | 24 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
26 | - focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) { | |
25 | + focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function (res) { | |
27 | 26 | var moneda = res.data[0]; |
28 | 27 | moneda.cotizacion = moneda.cotizaciones[0]; |
29 | 28 | $scope.cobranza.moneda = $scope.inicial.moneda = moneda; |
30 | - $filter('filter')( $scope.botonera, { | |
29 | + $filter('filter')($scope.botonera, { | |
31 | 30 | label: 'Moneda' |
32 | 31 | })[0].checked = true; |
33 | - $timeout(function() { getLSCobranza();} ); | |
32 | + $timeout(function () { getLSCobranza(); }); | |
34 | 33 | }); |
35 | 34 | |
36 | - $timeout(function() { | |
35 | + $timeout(function () { | |
37 | 36 | focaBotoneraLateralService.showSalir(false); |
38 | 37 | focaBotoneraLateralService.showPausar(true); |
39 | 38 | focaBotoneraLateralService.showGuardar(true, $scope.crearCobranza); |
... | ... | @@ -60,7 +59,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
60 | 59 | |
61 | 60 | if (APP === 'cobranza') { |
62 | 61 | focaCrearCobranzaService.getCobradorById($scope.idCobrador).then( |
63 | - function(res) { | |
62 | + function (res) { | |
64 | 63 | var cobrador = res.data; |
65 | 64 | |
66 | 65 | $scope.$broadcast('addCabecera', { |
... | ... | @@ -78,7 +77,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
78 | 77 | $scope.inicial = angular.copy($scope.cobranza); |
79 | 78 | |
80 | 79 | focaCrearCobranzaService.getNumeroRecibo().then( |
81 | - function(res) { | |
80 | + function (res) { | |
82 | 81 | $scope.puntoVenta = $filter('rellenarDigitos')( |
83 | 82 | res.data.sucursal, 4 |
84 | 83 | ); |
... | ... | @@ -87,7 +86,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
87 | 86 | res.data.numeroRecibo, 8 |
88 | 87 | ); |
89 | 88 | }, |
90 | - function(err) { | |
89 | + function (err) { | |
91 | 90 | focaModalService.alert( |
92 | 91 | 'La terminal no esta configurada correctamente' |
93 | 92 | ); |
... | ... | @@ -96,14 +95,14 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
96 | 95 | ); |
97 | 96 | } |
98 | 97 | |
99 | - $scope.$watch('cobranza', function(newValue) { | |
98 | + $scope.$watch('cobranza', function (newValue) { | |
100 | 99 | focaBotoneraLateralService.setPausarData({ |
101 | 100 | label: 'cobranza', |
102 | 101 | val: newValue |
103 | 102 | }); |
104 | 103 | }, true); |
105 | 104 | |
106 | - $scope.crearCobranza = function() { | |
105 | + $scope.crearCobranza = function () { | |
107 | 106 | if (!$scope.cobranza.cliente.COD) { |
108 | 107 | focaModalService.alert('Ingrese Cliente'); |
109 | 108 | return; |
... | ... | @@ -130,7 +129,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
130 | 129 | $scope.editando = false; |
131 | 130 | focaBotoneraLateralService.startGuardar(); |
132 | 131 | $scope.saveLoading = true; |
133 | - for(var i = 0; i < $scope.cobranza.facturas.length; i++) { | |
132 | + for (var i = 0; i < $scope.cobranza.facturas.length; i++) { | |
134 | 133 | var cuerpoFactura = { |
135 | 134 | CYV: 'V', |
136 | 135 | TIP: 'C', |
... | ... | @@ -144,7 +143,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
144 | 143 | FEC: new Date($scope.cobranza.FEC) |
145 | 144 | .toISOString().slice(0, 19).replace('T', ' '), |
146 | 145 | IMP: Math.abs($scope.cobranza.facturas[i].IMP || |
147 | - $scope.cobranza.facturas[i].IPA), | |
146 | + $scope.cobranza.facturas[i].IPA), | |
148 | 147 | RES: 0,//caja de tesorería |
149 | 148 | SUBM: 0, |
150 | 149 | NCU: $scope.cobranza.facturas[i].NCU |
... | ... | @@ -162,7 +161,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
162 | 161 | LOP: 'P', |
163 | 162 | TIL: $scope.cobranza.cobros[j].TIL, |
164 | 163 | COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : $scope.cobranza.cobros[j].COM, |
165 | - FEC: !$scope.cobranza.cobros[j].fechaPresentacion ? | |
164 | + FEC: !$scope.cobranza.cobros[j].fechaPresentacion ? | |
166 | 165 | new Date($scope.cobranza.cobros[j].FEC) |
167 | 166 | .toISOString().slice(0, 19).replace('T', ' ') : |
168 | 167 | new Date($scope.cobranza.cobros[j].fechaPresentacion) |
... | ... | @@ -201,7 +200,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
201 | 200 | ORI: 've', |
202 | 201 | FER: '', |
203 | 202 | BIMP: 0, |
204 | - COMP: 'C ' +'RC ' + $scope.puntoVenta + '-' + $scope.comprobante, | |
203 | + COMP: 'C ' + 'RC ' + $scope.puntoVenta + '-' + $scope.comprobante, | |
205 | 204 | VAL_E: '',//Cuando egresa por ingresos y egresos en el numero de egreso |
206 | 205 | VAL_I: '',//Cuando Ingresa por ingresos y egresos en el numero ingreso |
207 | 206 | REC_CAJ: 'D', |
... | ... | @@ -222,7 +221,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
222 | 221 | }; |
223 | 222 | cheques.push(cheque); |
224 | 223 | } |
225 | - if ($scope.cobranza.cobros[j].imgs) imgs = $scope.cobranza.cobros[j].imgs; | |
224 | + if ($scope.cobranza.cobros[j].imgs) imgs = $scope.cobranza.cobros[j].imgs; | |
226 | 225 | |
227 | 226 | } |
228 | 227 | |
... | ... | @@ -286,45 +285,44 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
286 | 285 | //COPIO cobranzaMail Y A cobranza LE ELIMINO EL VALOR NCU DE LOS CUERPOS |
287 | 286 | var cobranzaMail = angular.copy(cobranza); |
288 | 287 | |
289 | - cobranza.cuerpo = cobranza.cuerpo.map(function(c) { | |
288 | + cobranza.cuerpo = cobranza.cuerpo.map(function (c) { | |
290 | 289 | if (c.NCU) delete c.NCU; |
291 | 290 | return c; |
292 | 291 | }); |
293 | 292 | focaCrearCobranzaService |
294 | 293 | .guardarCobranza(cobranza) |
295 | 294 | .then( |
296 | - function(result) { | |
297 | - focaBotoneraLateralService.endGuardar(true); | |
298 | - $scope.saveLoading = false; | |
299 | - | |
300 | - enviarMail(cobranzaMail); | |
301 | - | |
302 | - focaSeguimientoService.guardarPosicion( | |
303 | - 'Cobranza', | |
304 | - result.data, | |
305 | - '' | |
306 | - ); | |
307 | - | |
308 | - config(); | |
309 | - }, function(error) { | |
310 | - focaModalService.alert('Hubo un problema al cargar la cobranza'); | |
311 | - focaBotoneraLateralService.endGuardar(); | |
312 | - $scope.saveLoading = false; | |
313 | - console.info(error); | |
314 | - } | |
315 | - ); | |
295 | + function (result) { | |
296 | + focaBotoneraLateralService.endGuardar(true); | |
297 | + $scope.saveLoading = false; | |
298 | + | |
299 | + enviarMail(cobranzaMail); | |
300 | + | |
301 | + focaSeguimientoService.guardarPosicion( | |
302 | + 'Cobranza', | |
303 | + result.data, | |
304 | + '' | |
305 | + ); | |
306 | + | |
307 | + config(); | |
308 | + }, function (error) { | |
309 | + focaModalService.alert('Hubo un problema al cargar la cobranza'); | |
310 | + focaBotoneraLateralService.endGuardar(); | |
311 | + $scope.saveLoading = false; | |
312 | + console.info(error); | |
313 | + } | |
314 | + ); | |
316 | 315 | }; |
317 | 316 | |
318 | - $scope.seleccionarCobros = function() { | |
317 | + $scope.seleccionarCobros = function () { | |
319 | 318 | $scope.cobroDeuda = false; |
320 | 319 | }; |
321 | 320 | |
322 | - $scope.seleccionarComprobantes = function() { | |
321 | + $scope.seleccionarComprobantes = function () { | |
323 | 322 | $scope.cobroDeuda = true; |
324 | 323 | }; |
325 | 324 | |
326 | - $scope.seleccionarCobranza = function() { | |
327 | - | |
325 | + $scope.seleccionarCobranza = function () { | |
328 | 326 | var modalInstance = $uibModal.open( |
329 | 327 | { |
330 | 328 | ariaLabelledBy: 'Busqueda de Cobranzas', |
... | ... | @@ -333,13 +331,13 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
333 | 331 | size: 'lg' |
334 | 332 | } |
335 | 333 | ); |
336 | - modalInstance.result.then(function(cobranza) { | |
334 | + modalInstance.result.then(function (cobranza) { | |
337 | 335 | cobranza.moneda.cotizacion = cobranza.moneda.cotizaciones[0]; |
338 | 336 | setearCobranza(cobranza); |
339 | 337 | }); |
340 | 338 | }; |
341 | 339 | |
342 | - $scope.seleccionarResumenDeCuenta = function() { | |
340 | + $scope.seleccionarResumenDeCuenta = function () { | |
343 | 341 | if (!$scope.cobranza.cliente.COD) { |
344 | 342 | focaModalService.alert('Seleccione primero un cliente'); |
345 | 343 | return; |
... | ... | @@ -350,35 +348,39 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
350 | 348 | templateUrl: 'modal-resumen-cuenta.html', |
351 | 349 | controller: 'focaModalResumenCuentaController', |
352 | 350 | resolve: { |
353 | - cliente: function() { return $scope.cobranza.cliente; } | |
351 | + cliente: function () { return $scope.cobranza.cliente; }, | |
352 | + idMoneda: function () { return $scope.cobranza.moneda.ID; } | |
354 | 353 | }, |
355 | 354 | size: 'lg' |
356 | 355 | } |
357 | 356 | ); |
358 | 357 | modalInstance.result.then( |
359 | - function(cliente) { | |
358 | + function (cliente) { | |
360 | 359 | $scope.abrirModalDomicilios(cliente); |
361 | 360 | $scope.cliente = cliente; |
362 | - }, function() {} | |
361 | + }, function () { } | |
363 | 362 | ); |
364 | 363 | }; |
365 | 364 | |
366 | - $scope.seleccionarCliente = function() { | |
367 | - $scope.seleccionarCobrador(function() { | |
365 | + $scope.seleccionarCliente = function () { | |
366 | + if ($scope.cobranza.id === undefined) { | |
368 | 367 | var modalInstance = $uibModal.open( |
369 | 368 | { |
370 | 369 | ariaLabelledBy: 'Busqueda de Cliente', |
371 | 370 | templateUrl: 'foca-busqueda-cliente-modal.html', |
372 | 371 | controller: 'focaBusquedaClienteModalController', |
373 | 372 | resolve: { |
374 | - vendedor: function() { return null; }, | |
375 | - cobrador: function() { return $scope.cobranza.cobrador; } | |
373 | + vendedor: function () { return null; }, | |
374 | + cobrador: function () { return null; } | |
376 | 375 | }, |
377 | 376 | size: 'lg' |
378 | 377 | } |
379 | 378 | ); |
380 | 379 | modalInstance.result.then( |
381 | - function(cliente) { | |
380 | + function (cliente) { | |
381 | + //ELIMINO CLIENTE | |
382 | + $scope.$broadcast('removeCabecera', 'Cliente:'); | |
383 | + $scope.cobranza.cliente = {}; | |
382 | 384 | |
383 | 385 | var clienteMayus = { |
384 | 386 | COD: cliente.cod, |
... | ... | @@ -387,9 +389,17 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
387 | 389 | MAIL: cliente.mail, |
388 | 390 | DOM: cliente.DOM, |
389 | 391 | LOC: cliente.LOC, |
390 | - PCI: cliente.PCI | |
392 | + PCI: cliente.PCI, | |
393 | + idCobrador: cliente.idCobrador, | |
394 | + cobrador: cliente.cobrador | |
391 | 395 | }; |
392 | - console.log(clienteMayus); | |
396 | + $scope.$broadcast('addCabecera', { | |
397 | + label: 'Cobrador:', | |
398 | + valor: $filter('rellenarDigitos')(clienteMayus.cobrador.NUM, 3) + | |
399 | + ' - ' + clienteMayus.cobrador.NOM | |
400 | + }); | |
401 | + $scope.cobranza.cobrador = clienteMayus.cobrador; | |
402 | + | |
393 | 403 | $scope.$broadcast('addCabecera', { |
394 | 404 | label: 'Cliente:', |
395 | 405 | valor: $filter('rellenarDigitos')(clienteMayus.COD, 5) + ' - ' + |
... | ... | @@ -397,275 +407,262 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
397 | 407 | }); |
398 | 408 | |
399 | 409 | $filter('filter')($scope.botonera, |
400 | - { label: 'Cliente'})[0].checked = true; | |
410 | + { label: 'Cliente' })[0].checked = true; | |
401 | 411 | |
402 | 412 | $scope.cobranza.cliente = clienteMayus; |
403 | 413 | $scope.cobranza.facturas = []; |
404 | - }, function() { | |
405 | - if (APP !== 'cobranza') $scope.seleccionarCliente(); | |
414 | + focaCrearCobranzaService | |
415 | + .getCobradorById($scope.cobranza.cliente.idCobrador); | |
416 | + }, function () { | |
406 | 417 | } |
407 | 418 | ); |
408 | - }); | |
409 | - }; | |
410 | - | |
411 | - $scope.seleccionarCobrador = function(callback) { | |
412 | - | |
413 | - if (APP === 'cobranza') { | |
414 | - callback(); | |
419 | + } else { | |
420 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
415 | 421 | return; |
416 | 422 | } |
423 | + }; | |
417 | 424 | |
418 | - var parametrosModal = { | |
419 | - query: '/cobrador', | |
420 | - columnas: [ | |
425 | + $scope.seleccionarFactura = function () { | |
426 | + if ($scope.cobranza.id === undefined) { | |
427 | + if (!$scope.cobranza.cliente.COD) { | |
428 | + focaModalService.alert('Seleccione primero un cliente'); | |
429 | + return; | |
430 | + } | |
431 | + var modalInstance = $uibModal.open( | |
421 | 432 | { |
422 | - propiedad: 'NUM', | |
423 | - nombre: 'Codigo', | |
424 | - filtro: { | |
425 | - nombre: 'rellenarDigitos', | |
426 | - parametro: 3 | |
433 | + ariaLabelledBy: 'Busqueda de Facturas', | |
434 | + templateUrl: 'foca-modal-factura.html', | |
435 | + controller: 'focaModalFacturaController', | |
436 | + size: 'lg', | |
437 | + resolve: { | |
438 | + parametrosFactura: function () { | |
439 | + return { | |
440 | + cliente: $scope.cobranza.cliente, | |
441 | + simbolo: $scope.cobranza.moneda.SIMBOLO, | |
442 | + cotizacion: $scope.cobranza.moneda, | |
443 | + moneda: $scope.cobranza.moneda.ID | |
444 | + }; | |
445 | + } | |
427 | 446 | } |
428 | - }, | |
429 | - { | |
430 | - propiedad: 'NOM', | |
431 | - nombre: 'Nombre' | |
432 | 447 | } |
433 | - ], | |
434 | - titulo:'Búsqueda de cobradores' | |
435 | - }; | |
436 | - focaModalService.modal(parametrosModal).then( | |
437 | - function(cobrador) { | |
438 | - $scope.$broadcast('addCabecera', { | |
439 | - label: 'Cobrador:', | |
440 | - valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' + | |
441 | - cobrador.NOM | |
442 | - }); | |
443 | - $scope.cobranza.cobrador = cobrador; | |
444 | - | |
445 | - //ELIMINO CLIENTE | |
446 | - $scope.$broadcast('removeCabecera', 'Cliente:'); | |
447 | - $scope.cobranza.cliente = {}; | |
448 | - | |
449 | - callback(); | |
450 | - }, function() {} | |
451 | - ); | |
452 | - }; | |
448 | + ); | |
449 | + modalInstance.result.then( | |
450 | + function (facturas) { | |
451 | + var facturasResult = []; | |
452 | + //AGREGO A FACTURASRESULT LAS FACTURAS QUE NO HAN SIDO SELECCIONADAS | |
453 | + facturas.forEach(function (factura) { | |
454 | + var existe = $scope.cobranza.facturas.filter(function (e) { | |
455 | + return angular.equals(factura, e); | |
456 | + }); | |
457 | + | |
458 | + if (!existe.length) facturasResult.push(factura); | |
459 | + }); | |
453 | 460 | |
454 | - $scope.seleccionarFactura = function() { | |
455 | - if (!$scope.cobranza.cliente.COD) { | |
456 | - focaModalService.alert('Seleccione primero un cliente'); | |
461 | + $scope.cobranza.facturas = | |
462 | + $scope.cobranza.facturas.concat(facturasResult); | |
463 | + }, function () { } | |
464 | + ); | |
465 | + } else { | |
466 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
457 | 467 | return; |
458 | 468 | } |
459 | - var modalInstance = $uibModal.open( | |
460 | - { | |
461 | - ariaLabelledBy: 'Busqueda de Facturas', | |
462 | - templateUrl: 'foca-modal-factura.html', | |
463 | - controller: 'focaModalFacturaController', | |
464 | - size: 'lg', | |
465 | - resolve: { | |
466 | - parametrosFactura: function() { | |
467 | - return { | |
468 | - cliente: $scope.cobranza.cliente, | |
469 | - simbolo: $scope.cobranza.moneda.SIMBOLO, | |
470 | - cotizacion: $scope.cobranza.moneda, | |
471 | - moneda: $scope.cobranza.moneda.ID | |
472 | - }; | |
473 | - } | |
474 | - } | |
475 | - } | |
476 | - ); | |
477 | - modalInstance.result.then( | |
478 | - function(facturas) { | |
479 | - var facturasResult = []; | |
480 | - //AGREGO A FACTURASRESULT LAS FACTURAS QUE NO HAN SIDO SELECCIONADAS | |
481 | - facturas.forEach(function(factura) { | |
482 | - var existe = $scope.cobranza.facturas.filter(function(e) { | |
483 | - return angular.equals(factura, e); | |
484 | - }); | |
485 | 469 | |
486 | - if (!existe.length) facturasResult.push(factura); | |
487 | - }); | |
488 | - | |
489 | - $scope.cobranza.facturas = $scope.cobranza.facturas.concat(facturasResult); | |
490 | - }, function() { } | |
491 | - ); | |
492 | 470 | }; |
493 | 471 | |
494 | - $scope.seleccionarCheque = function(cheque) { | |
495 | - | |
496 | - var parametros; | |
472 | + $scope.seleccionarCheque = function (cheque) { | |
473 | + if ($scope.cobranza.id === undefined) { | |
474 | + var parametros; | |
497 | 475 | |
498 | - if(!cheque) { | |
499 | - parametros = { | |
500 | - importe: getSugerido(), | |
501 | - esNuevo : true | |
502 | - }; | |
503 | - } else { | |
504 | - parametros = cheque; | |
505 | - parametros.importe = cheque.IMP; | |
506 | - } | |
476 | + if (!cheque) { | |
477 | + parametros = { | |
478 | + importe: getSugerido(), | |
479 | + esNuevo: true | |
480 | + }; | |
481 | + } else { | |
482 | + parametros = cheque; | |
483 | + parametros.importe = cheque.IMP; | |
484 | + } | |
507 | 485 | |
508 | - var modalInstance = $uibModal.open( | |
509 | - { | |
510 | - ariaLabelledBy: 'Carga de cheques', | |
511 | - templateUrl: 'modal-cheque.html', | |
512 | - controller: 'focaModalChequeController', | |
513 | - size: 'lg', | |
514 | - resolve: { | |
515 | - cheque: function() { | |
516 | - return parametros; | |
486 | + var modalInstance = $uibModal.open( | |
487 | + { | |
488 | + ariaLabelledBy: 'Carga de cheques', | |
489 | + templateUrl: 'modal-cheque.html', | |
490 | + controller: 'focaModalChequeController', | |
491 | + size: 'lg', | |
492 | + resolve: { | |
493 | + cheque: function () { | |
494 | + return parametros; | |
495 | + } | |
517 | 496 | } |
518 | 497 | } |
519 | - } | |
520 | - ); | |
521 | - modalInstance.result.then( | |
522 | - function(cheque) { | |
523 | - var cobro = { | |
524 | - COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, | |
525 | - numero: cheque.numero, | |
526 | - banco: cheque.banco, | |
527 | - FEC: cheque.fechaEmision.toLocaleDateString() + '-' + | |
528 | - cheque.fechaPresentacion.toLocaleDateString(), | |
529 | - fechaPresentacion: cheque.fechaPresentacion, | |
530 | - fechaEmision: cheque.fechaEmision, | |
531 | - IMP: cheque.importe, | |
532 | - localidad: cheque.localidad, | |
533 | - librador: cheque.librador, | |
534 | - provincia: cheque.provincia, | |
535 | - observaciones: cheque.observaciones, | |
536 | - TIL: 'EF' | |
537 | - }; | |
538 | - pushearCobro(cobro, cheque.$$hashKey); | |
539 | - }, function() { | |
498 | + ); | |
499 | + modalInstance.result.then( | |
500 | + function (cheque) { | |
501 | + var cobro = { | |
502 | + COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco, | |
503 | + numero: cheque.numero, | |
504 | + banco: cheque.banco, | |
505 | + FEC: cheque.fechaEmision.toLocaleDateString() + '-' + | |
506 | + cheque.fechaPresentacion.toLocaleDateString(), | |
507 | + fechaPresentacion: cheque.fechaPresentacion, | |
508 | + fechaEmision: cheque.fechaEmision, | |
509 | + IMP: cheque.importe, | |
510 | + localidad: cheque.localidad, | |
511 | + librador: cheque.librador, | |
512 | + provincia: cheque.provincia, | |
513 | + observaciones: cheque.observaciones, | |
514 | + TIL: 'EF' | |
515 | + }; | |
516 | + pushearCobro(cobro, cheque.$$hashKey); | |
517 | + }, function () { | |
540 | 518 | |
541 | - } | |
542 | - ); | |
543 | - }; | |
519 | + } | |
520 | + ); | |
521 | + } else { | |
522 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
523 | + return; | |
524 | + } | |
544 | 525 | |
545 | - $scope.seleccionarEfectivo = function() { | |
526 | + }; | |
546 | 527 | |
547 | - var importe = 0; | |
548 | - $scope.cobranza.cobros.filter(function(a) { | |
549 | - if(a.COM === 'Efectivo') { | |
550 | - importe = a.IMP; | |
551 | - } | |
552 | - }); | |
528 | + $scope.seleccionarEfectivo = function () { | |
529 | + if ($scope.cobranza.id === undefined) { | |
530 | + var importe = 0; | |
531 | + $scope.cobranza.cobros.filter(function (a) { | |
532 | + if (a.COM === 'Efectivo') { | |
533 | + importe = a.IMP; | |
534 | + } | |
535 | + }); | |
553 | 536 | |
554 | - var modalInstance = $uibModal.open( | |
555 | - { | |
556 | - ariaLabelledBy: 'Carga de cheques', | |
557 | - templateUrl: 'modal-efectivo.html', | |
558 | - controller: 'focaModalEfectivoController', | |
559 | - size: 'sm', | |
560 | - resolve: { | |
561 | - sugerido: function() { | |
562 | - return parseFloat(getSugerido()) + parseFloat(importe); | |
537 | + var modalInstance = $uibModal.open( | |
538 | + { | |
539 | + ariaLabelledBy: 'Carga de cheques', | |
540 | + templateUrl: 'modal-efectivo.html', | |
541 | + controller: 'focaModalEfectivoController', | |
542 | + size: 'sm', | |
543 | + resolve: { | |
544 | + sugerido: function () { | |
545 | + return parseFloat(getSugerido()) + parseFloat(importe); | |
546 | + } | |
563 | 547 | } |
564 | 548 | } |
565 | - } | |
566 | - ); | |
567 | - modalInstance.result.then( | |
568 | - function(efectivo) { | |
549 | + ); | |
550 | + modalInstance.result.then( | |
551 | + function (efectivo) { | |
569 | 552 | |
570 | - var cobro = { | |
571 | - COM: 'Efectivo', | |
572 | - FEC: new Date(), | |
573 | - IMP: efectivo, | |
574 | - TIL: 'EF' | |
575 | - }; | |
553 | + var cobro = { | |
554 | + COM: 'Efectivo', | |
555 | + FEC: new Date(), | |
556 | + IMP: efectivo, | |
557 | + TIL: 'EF' | |
558 | + }; | |
576 | 559 | |
577 | - $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) { | |
578 | - return a.COM !== 'Efectivo'; | |
579 | - }); | |
560 | + $scope.cobranza.cobros = $scope.cobranza.cobros.filter(function (a) { | |
561 | + return a.COM !== 'Efectivo'; | |
562 | + }); | |
580 | 563 | |
581 | - $scope.cobranza.cobros.push(cobro); | |
582 | - }, function() { | |
564 | + $scope.cobranza.cobros.push(cobro); | |
565 | + }, function () { | |
583 | 566 | |
584 | - } | |
585 | - ); | |
567 | + } | |
568 | + ); | |
569 | + } else { | |
570 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
571 | + return; | |
572 | + } | |
586 | 573 | }; |
587 | 574 | |
588 | - $scope.seleccionarDetalles = function(detalle) { | |
575 | + $scope.seleccionarDetalles = function (detalle) { | |
576 | + if ($scope.cobranza.id === undefined) { | |
577 | + var parametro = {}; | |
589 | 578 | |
590 | - var parametro = {}; | |
579 | + if (!detalle) { | |
580 | + parametro = { | |
581 | + importe: getSugerido(), | |
582 | + files: [] | |
583 | + }; | |
584 | + } else { | |
585 | + parametro = detalle; | |
586 | + parametro.importe = detalle.IMP; | |
587 | + parametro.files = detalle.imgs; | |
588 | + } | |
591 | 589 | |
592 | - if(!detalle) { | |
593 | - parametro = { | |
594 | - importe: getSugerido(), | |
595 | - files: [] | |
596 | - }; | |
590 | + var modalInstance = $uibModal.open( | |
591 | + { | |
592 | + ariaLabelledBy: 'Carga de detalles', | |
593 | + templateUrl: 'modal-detalles.html', | |
594 | + controller: 'focaModalDetallesController', | |
595 | + size: 'lg', | |
596 | + resolve: { | |
597 | + parametros: function () { | |
598 | + return parametro; | |
599 | + } | |
600 | + } | |
601 | + } | |
602 | + ); | |
603 | + modalInstance.result.then( | |
604 | + function (detalles) { | |
605 | + | |
606 | + var cobro = { | |
607 | + COM: 'de(COBRO POR DETALLES)', | |
608 | + FEC: new Date(), | |
609 | + IMP: detalles.importe, | |
610 | + imgs: detalles.files, | |
611 | + TIL: 'DE', | |
612 | + observacion: detalles.observacion | |
613 | + }; | |
614 | + pushearCobro(cobro, detalles.$$hashKey); | |
615 | + }, function () { } | |
616 | + ); | |
597 | 617 | } else { |
598 | - parametro = detalle; | |
599 | - parametro.importe = detalle.IMP; | |
600 | - parametro.files= detalle.imgs; | |
618 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
619 | + return; | |
601 | 620 | } |
621 | + }; | |
602 | 622 | |
603 | - var modalInstance = $uibModal.open( | |
604 | - { | |
605 | - ariaLabelledBy: 'Carga de detalles', | |
606 | - templateUrl: 'modal-detalles.html', | |
607 | - controller: 'focaModalDetallesController', | |
608 | - size: 'lg', | |
609 | - resolve: { | |
610 | - parametros: function() { | |
611 | - return parametro; | |
623 | + $scope.seleccionarMoneda = function () { | |
624 | + if ($scope.cobranza.id === undefined) { | |
625 | + var parametrosModal = { | |
626 | + titulo: 'Búsqueda de monedas', | |
627 | + query: '/moneda', | |
628 | + columnas: [ | |
629 | + { | |
630 | + propiedad: 'DETALLE', | |
631 | + nombre: 'Nombre' | |
632 | + }, | |
633 | + { | |
634 | + propiedad: 'SIMBOLO', | |
635 | + nombre: 'Símbolo' | |
612 | 636 | } |
613 | - } | |
614 | - } | |
615 | - ); | |
616 | - modalInstance.result.then( | |
617 | - function(detalles) { | |
618 | - | |
619 | - var cobro = { | |
620 | - COM: 'de(COBRO POR DETALLES)', | |
621 | - FEC: new Date(), | |
622 | - IMP: detalles.importe, | |
623 | - imgs: detalles.files, | |
624 | - TIL: 'DE', | |
625 | - observacion: detalles.observacion | |
626 | - }; | |
627 | - pushearCobro(cobro, detalles.$$hashKey); | |
628 | - }, function() {} | |
629 | - ); | |
630 | - }; | |
637 | + ], | |
638 | + size: 'md' | |
639 | + }; | |
640 | + focaModalService.modal(parametrosModal).then( | |
641 | + function (moneda) { | |
642 | + $scope.seleccionarCotizacion(moneda); | |
643 | + }, function () { | |
631 | 644 | |
632 | - $scope.seleccionarMoneda = function() { | |
633 | - var parametrosModal = { | |
634 | - titulo: 'Búsqueda de monedas', | |
635 | - query: '/moneda', | |
636 | - columnas: [ | |
637 | - { | |
638 | - propiedad: 'DETALLE', | |
639 | - nombre: 'Nombre' | |
640 | - }, | |
641 | - { | |
642 | - propiedad: 'SIMBOLO', | |
643 | - nombre: 'Símbolo' | |
644 | 645 | } |
645 | - ], | |
646 | - size: 'md' | |
647 | - }; | |
648 | - focaModalService.modal(parametrosModal).then( | |
649 | - function(moneda) { | |
650 | - $scope.seleccionarCotizacion(moneda); | |
651 | - }, function() { | |
646 | + ); | |
647 | + } else { | |
648 | + focaModalService.alert('Esta cobranza no se puede editar'); | |
649 | + return; | |
650 | + } | |
652 | 651 | |
653 | - } | |
654 | - ); | |
655 | 652 | }; |
656 | 653 | |
657 | - $scope.seleccionarCotizacion = function(moneda) { | |
654 | + $scope.seleccionarCotizacion = function (moneda) { | |
658 | 655 | var modalInstance = $uibModal.open( |
659 | 656 | { |
660 | 657 | ariaLabelledBy: 'Busqueda de Cotización', |
661 | 658 | templateUrl: 'modal-cotizacion.html', |
662 | 659 | controller: 'focaModalCotizacionController', |
663 | 660 | size: 'lg', |
664 | - resolve: {idMoneda: function() {return moneda.ID;}} | |
661 | + resolve: { idMoneda: function () { return moneda.ID; } } | |
665 | 662 | } |
666 | 663 | ); |
667 | 664 | modalInstance.result.then( |
668 | - function(cotizacion) { | |
665 | + function (cotizacion) { | |
669 | 666 | $scope.cobranza.moneda = moneda; |
670 | 667 | $scope.cobranza.moneda.cotizacion = cotizacion; |
671 | 668 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { |
... | ... | @@ -687,17 +684,17 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
687 | 684 | }); |
688 | 685 | } |
689 | 686 | |
690 | - $filter('filter')( $scope.botonera, { | |
687 | + $filter('filter')($scope.botonera, { | |
691 | 688 | label: 'Moneda' |
692 | 689 | })[0].checked = true; |
693 | 690 | |
694 | - }, function() { | |
691 | + }, function () { | |
695 | 692 | |
696 | 693 | } |
697 | 694 | ); |
698 | 695 | }; |
699 | 696 | |
700 | - $scope.getTotalDeuda = function() { | |
697 | + $scope.getTotalDeuda = function () { | |
701 | 698 | var total = 0; |
702 | 699 | for (var i = 0; i < $scope.cobranza.facturas.length; i++) { |
703 | 700 | total += $scope.cobranza.facturas[i].IMP || $scope.cobranza.facturas[i].IPA; |
... | ... | @@ -705,7 +702,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
705 | 702 | return parseFloat(total.toFixed(2)); |
706 | 703 | }; |
707 | 704 | |
708 | - $scope.getTotalCobrado = function() { | |
705 | + $scope.getTotalCobrado = function () { | |
709 | 706 | var total = 0; |
710 | 707 | for (var i = 0; i < $scope.cobranza.cobros.length; i++) { |
711 | 708 | total += $scope.cobranza.cobros[i].IMP; |
... | ... | @@ -713,73 +710,83 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
713 | 710 | return parseFloat(total.toFixed(2)); |
714 | 711 | }; |
715 | 712 | |
716 | - $scope.getSubTotal = function() { | |
713 | + $scope.getSubTotal = function () { | |
717 | 714 | if ($scope.articuloACargar) { |
718 | 715 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
719 | 716 | } |
720 | 717 | }; |
721 | 718 | //Recibe aviso si el teclado está en uso |
722 | 719 | // $rootScope.$on('usarTeclado', function(event, data) { |
723 | - // if(data) { | |
724 | - // $scope.mostrarTeclado = true; | |
725 | - // return; | |
726 | - // } | |
727 | - // $scope.mostrarTeclado = false; | |
720 | + // if(data) { | |
721 | + // $scope.mostrarTeclado = true; | |
722 | + // return; | |
723 | + // } | |
724 | + // $scope.mostrarTeclado = false; | |
728 | 725 | // }) |
729 | - $scope.selectFocus = function($event) { | |
726 | + $scope.selectFocus = function ($event) { | |
730 | 727 | //Si el teclado esta en uso no selecciona el valor |
731 | 728 | // if($scope.mostrarTeclado) { |
732 | - // return; | |
729 | + // return; | |
733 | 730 | // } |
734 | 731 | $event.target.select(); |
735 | 732 | }; |
736 | 733 | |
737 | - $scope.salir = function() { | |
734 | + $scope.salir = function () { | |
738 | 735 | $location.path('/'); |
739 | 736 | }; |
740 | 737 | |
741 | - $scope.parsearATexto = function(articulo) { | |
738 | + $scope.parsearATexto = function (articulo) { | |
742 | 739 | articulo.cantidad = parseFloat(articulo.cantidad); |
743 | 740 | articulo.precio = parseFloat(articulo.precio); |
744 | 741 | }; |
745 | 742 | |
746 | - $scope.quitarFactura = function(key) { | |
747 | - $scope.cobranza.facturas.splice(key, 1); | |
743 | + $scope.quitarFactura = function (key) { | |
744 | + if ($scope.cobranza.id === undefined) { | |
745 | + $scope.cobranza.facturas.splice(key, 1); | |
746 | + } else { | |
747 | + focaModalService.alert('Esta comprobante no se puede eliminar'); | |
748 | + return; | |
749 | + } | |
748 | 750 | }; |
749 | 751 | |
750 | - $scope.quitarCobro = function(key) { | |
751 | - $scope.cobranza.cobros.splice(key, 1); | |
752 | + $scope.quitarCobro = function (key) { | |
753 | + if ($scope.cobranza.id === undefined) { | |
754 | + $scope.cobranza.cobros.splice(key, 1); | |
755 | + } else { | |
756 | + focaModalService.alert('Esta comprobante no se puede eliminar'); | |
757 | + return; | |
758 | + } | |
752 | 759 | }; |
753 | 760 | |
754 | - $scope.editarCobro = function(cobro) { | |
755 | - if(cobro.COM === 'Efectivo') { | |
761 | + $scope.editarCobro = function (cobro) { | |
762 | + if (cobro.COM === 'Efectivo') { | |
756 | 763 | $scope.seleccionarEfectivo(); |
757 | - } else if(cobro.COM.substring(0, 2) === 'de') { | |
764 | + } else if (cobro.COM.substring(0, 2) === 'de') { | |
758 | 765 | $scope.seleccionarDetalles(cobro); |
759 | - } else if(cobro.COM.substring(0, 2) === 'ch') { | |
766 | + } else if (cobro.COM.substring(0, 2) === 'ch') { | |
760 | 767 | $scope.seleccionarCheque(cobro); |
761 | 768 | } |
762 | 769 | }; |
763 | 770 | |
764 | - $scope.$watch('cobranza.facturas', function() { | |
771 | + $scope.$watch('cobranza.facturas', function () { | |
765 | 772 | if ($scope.cobranza.facturas.length) { |
766 | - $filter('filter')( $scope.botonera, { | |
773 | + $filter('filter')($scope.botonera, { | |
767 | 774 | label: 'Comprobantes' |
768 | 775 | })[0].checked = true; |
769 | 776 | } else { |
770 | - $filter('filter')( $scope.botonera, { | |
777 | + $filter('filter')($scope.botonera, { | |
771 | 778 | label: 'Comprobantes' |
772 | 779 | })[0].checked = false; |
773 | 780 | } |
774 | 781 | }, true); |
775 | 782 | |
776 | - $scope.$watch('cobranza.cobros', function() { | |
783 | + $scope.$watch('cobranza.cobros', function () { | |
777 | 784 | if ($scope.cobranza.cobros.length) { |
778 | - $filter('filter')( $scope.botonera, { | |
785 | + $filter('filter')($scope.botonera, { | |
779 | 786 | label: 'Cobros' |
780 | 787 | })[0].checked = true; |
781 | 788 | } else { |
782 | - $filter('filter')( $scope.botonera, { | |
789 | + $filter('filter')($scope.botonera, { | |
783 | 790 | label: 'Cobros' |
784 | 791 | })[0].checked = false; |
785 | 792 | } |
... | ... | @@ -788,8 +795,8 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
788 | 795 | function pushearCobro(cobro, hashKey) { |
789 | 796 | var existe; |
790 | 797 | |
791 | - $scope.cobranza.cobros.forEach(function(c, idx) { | |
792 | - if(c.$$hashKey === hashKey) { | |
798 | + $scope.cobranza.cobros.forEach(function (c, idx) { | |
799 | + if (c.$$hashKey === hashKey) { | |
793 | 800 | $scope.cobranza.cobros[idx] = cobro; |
794 | 801 | existe = true; |
795 | 802 | } |
... | ... | @@ -809,7 +816,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
809 | 816 | if (confirmacion) { |
810 | 817 | focaModalService.confirm( |
811 | 818 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
812 | - ).then(function(data) { | |
819 | + ).then(function (data) { | |
813 | 820 | if (data) { |
814 | 821 | $location.path('/'); |
815 | 822 | } |
... | ... | @@ -830,7 +837,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
830 | 837 | cobranza.cliente.NOM |
831 | 838 | }); |
832 | 839 | |
833 | - $filter('filter')( $scope.botonera, { | |
840 | + $filter('filter')($scope.botonera, { | |
834 | 841 | label: 'Cliente' |
835 | 842 | })[0].checked = true; |
836 | 843 | } |
... | ... | @@ -846,7 +853,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController', |
846 | 853 | |
847 | 854 | // TODO: Setear moneda |
848 | 855 | if (cobranza.moneda) { |
849 | - $filter('filter')( $scope.botonera, { | |
856 | + $filter('filter')($scope.botonera, { | |
850 | 857 | label: 'Moneda' |
851 | 858 | })[0].checked = true; |
852 | 859 | } |