diff --git a/src/js/controller.js b/src/js/controller.js
index 388a785..31644ad 100644
--- a/src/js/controller.js
+++ b/src/js/controller.js
@@ -22,16 +22,11 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
minDate: new Date(2010, 0, 1)
};
- var monedaPorDefecto;
//Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) {
- monedaPorDefecto = res.data[0];
-
- $scope.cobranza.cotizacion = Object.assign(
- {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0]
- );
- $scope.inicial.cotizacion = $scope.cobranza.cotizacion;
-
+ var moneda = res.data[0];
+ moneda.cotizacion = moneda.cotizaciones[0];
+ $scope.cobranza.moneda = $scope.inicial.moneda = moneda;
});
$timeout(function() {
@@ -52,8 +47,8 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
function init() {
$scope.$broadcast('cleanCabecera');
$scope.cobranza = {
- fecha: new Date(),
- cotizacion: {},
+ FEC: new Date(),
+ moneda: {},
facturas: [],
cobros: [],
cliente: {},
@@ -117,12 +112,11 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
focaModalService.alert('Ingrese al menos una factura');
return;
}
- if ($scope.getTotalCobrado() + $scope.getTotalDeuda() !== 0) {
+ if ($scope.getTotalCobrado() + (Math.abs($scope.getTotalDeuda()) * -1) !== 0) {
focaModalService.alert('La diferencia debe ser ' +
- $scope.cobranza.cotizacion.moneda.SIMBOLO + '0,00');
+ $scope.cobranza.moneda.SIMBOLO + '0,00');
return;
}
-
var cobranza = {};
var cheques = [];
var cuerpos = [];
@@ -141,11 +135,12 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
NCO: $scope.comprobante,
LOP: 'L',
TIL: $scope.cobranza.facturas[i].TCO,
- COM: $scope.cobranza.facturas[i].numeroFactura + '-' +
+ COM: $scope.cobranza.facturas[i].COM + '-' +
$filter('rellenarDigitos')($scope.cobranza.facturas[i].NCU,2),
- FEC: new Date($scope.cobranza.fecha)
+ FEC: new Date($scope.cobranza.FEC)
.toISOString().slice(0, 19).replace('T', ' '),
- IMP: Math.abs($scope.cobranza.facturas[i].IPA),
+ IMP: Math.abs($scope.cobranza.facturas[i].IMP ||
+ $scope.cobranza.facturas[i].IPA),
RES: 0,//caja de tesorería
SUBM: 0,
NCU: $scope.cobranza.facturas[i].NCU
@@ -164,14 +159,14 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
PVE: $scope.puntoVenta,
NCO: $scope.comprobante,
LOP: 'P',
- TIL: $scope.cobranza.cobros[j].til,
- COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : $scope.cobranza.cobros[j].tipo,
+ TIL: $scope.cobranza.cobros[j].TIL,
+ COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : $scope.cobranza.cobros[j].COM,
FEC: !$scope.cobranza.cobros[j].fechaPresentacion ?
- new Date($scope.cobranza.cobros[j].fecha)
+ new Date($scope.cobranza.cobros[j].FEC)
.toISOString().slice(0, 19).replace('T', ' ') :
new Date($scope.cobranza.cobros[j].fechaPresentacion)
.toISOString().slice(0, 19).replace('T', ' '),
- IMP: Math.abs($scope.cobranza.cobros[j].importe),
+ IMP: Math.abs($scope.cobranza.cobros[j].IMP),
RES: 0,//caja de tesorería
SUBM: 0
};
@@ -237,14 +232,14 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
TCO: 'RC',
PVE: $scope.puntoVenta, //Sucursar, punto de venta
NCO: $scope.comprobante, //Numero de comprobante
- FEC: new Date($scope.cobranza.fecha)
+ FEC: new Date($scope.cobranza.FEC)
.toISOString().slice(0, 19).replace('T', ' '),
CLI: $scope.cobranza.cliente.COD,
ATO: 0, //número de asiento
CFE: $scope.cobranza.cobrador.NOM,
PLA: '',//Numero de planilla, sin uso
- ID_MONEDA: $scope.cobranza.cotizacion.moneda.ID,
- COTIZACION: $scope.cobranza.cotizacion.VENDEDOR,
+ ID_MONEDA: $scope.cobranza.moneda.ID,
+ COTIZACION: $scope.cobranza.moneda.cotizacion.VENDEDOR,
idCobrador: $scope.cobranza.cobrador.id
},
cuerpo: cuerpos,
@@ -252,7 +247,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
acobypag: {
CYV: 'V',
COD: $scope.cobranza.cliente.COD,
- FEP: new Date($scope.cobranza.fecha)
+ FEP: new Date($scope.cobranza.FEC)
.toISOString().slice(0, 19).replace('T', ' '),
TIP: 'C',
TCO: 'RC',
@@ -269,7 +264,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
REM: 0,
FRE: null,//??
PRO: 'N',
- FEV: new Date($scope.cobranza.fecha)
+ FEV: new Date($scope.cobranza.FEC)
.toISOString().slice(0, 19).replace('T', ' ')
},
datosCobrador: {
@@ -278,7 +273,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
NUM: $scope.comprobante,
EST: 'C',
OBS: 'RC: ' + $scope.comprobante + '-' +
- new Date($scope.cobranza.fecha).toLocaleDateString(),
+ new Date($scope.cobranza.FEC).toLocaleDateString(),
DAT1: 'C',
CLI: $scope.cobranza.cliente.COD
},
@@ -336,7 +331,10 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
size: 'lg'
}
);
- modalInstance.result.then(setearCobranza);
+ modalInstance.result.then(function(cobranza) {
+ cobranza.moneda.cotizacion = cobranza.moneda.cotizaciones[0];
+ setearCobranza(cobranza);
+ });
};
$scope.seleccionarResumenDeCuenta = function() {
@@ -458,9 +456,9 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
parametrosFactura: function() {
return {
cliente: $scope.cobranza.cliente,
- simbolo: $scope.cobranza.cotizacion.moneda.SIMBOLO,
- cotizacion: $scope.cobranza.cotizacion.VENDEDOR,
- moneda: $scope.cobranza.cotizacion.moneda.ID
+ simbolo: $scope.cobranza.moneda.SIMBOLO,
+ cotizacion: $scope.cobranza.moneda,
+ moneda: $scope.cobranza.moneda.ID
};
}
}
@@ -501,19 +499,19 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
modalInstance.result.then(
function(cheque) {
var cobro = {
- tipo: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco,
+ COM: 'ch' + '(' + cheque.numero + ')' + ' ' + cheque.banco.desbco,
numero: cheque.numero,
banco: cheque.banco,
- fecha: cheque.fechaEmision.toLocaleDateString() + '-' +
+ FEC: cheque.fechaEmision.toLocaleDateString() + '-' +
cheque.fechaPresentacion.toLocaleDateString(),
fechaPresentacion: cheque.fechaPresentacion,
fechaEmision: cheque.fechaEmision,
- importe: cheque.importe * $scope.cobranza.cotizacion.VENDEDOR,
+ IMP: cheque.importe * $scope.cobranza.moneda.cotizacion.VENDEDOR,
localidad: cheque.localidad,
librador: cheque.librador,
provincia: cheque.provincia,
observaciones: cheque.observaciones,
- til: 'EF'
+ TIL: 'EF'
};
$scope.cobranza.cobros.push(cobro);
}, function() {
@@ -531,7 +529,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
size: 'sm',
resolve: {
sugerido: function() {
- var sugerido = $scope.getTotalDeuda() + $scope.getTotalCobrado();
+ var sugerido = $scope.getTotalDeuda() - $scope.getTotalCobrado();
return sugerido < 0 ? sugerido : null;
}
}
@@ -540,10 +538,10 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
modalInstance.result.then(
function(efectivo) {
var cobro = {
- tipo: 'Efectivo',
- fecha: new Date(),
- importe: efectivo * $scope.cobranza.cotizacion.VENDEDOR,
- til: 'EF'
+ COM: 'Efectivo',
+ FEC: new Date(),
+ IMP: efectivo * $scope.cobranza.moneda.cotizacion.VENDEDOR,
+ TIL: 'EF'
};
$scope.cobranza.cobros = $scope.cobranza.cobros.filter(function(a) {
return a.tipo !== 'Efectivo';
@@ -573,11 +571,11 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
modalInstance.result.then(
function(detalles) {
var cobro = {
- tipo: 'de(COBRO POR DETALLES)',
- fecha: new Date(),
- importe: detalles.monto * $scope.cobranza.cotizacion.VENDEDOR,
+ COM: 'de(COBRO POR DETALLES)',
+ FEC: new Date(),
+ IMP: detalles.monto * $scope.cobranza.moneda.cotizacion.VENDEDOR,
imgs: detalles.imgs,
- til: 'DE',
+ TIL: 'DE',
observacion: detalles.observacion
};
var existe = false;
@@ -632,8 +630,8 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
);
modalInstance.result.then(
function(cotizacion) {
- $scope.cobranza.cotizacion = cotizacion;
- $scope.cobranza.cotizacion.moneda = moneda;
+ $scope.cobranza.moneda = moneda;
+ $scope.cobranza.moneda.cotizacion = cotizacion;
if (moneda.DETALLE === 'PESOS ARGENTINOS') {
$scope.$broadcast('removeCabecera', 'Moneda:');
$scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
@@ -652,6 +650,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
valor: $filter('number')(cotizacion.VENDEDOR, '2')
});
}
+
}, function() {
}
@@ -661,7 +660,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
$scope.getTotalDeuda = function() {
var total = 0;
for (var i = 0; i < $scope.cobranza.facturas.length; i++) {
- total += $scope.cobranza.facturas[i].IPA;
+ total += $scope.cobranza.facturas[i].IMP || $scope.cobranza.facturas[i].IPA;
}
return parseFloat(total.toFixed(2));
};
@@ -669,7 +668,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
$scope.getTotalCobrado = function() {
var total = 0;
for (var i = 0; i < $scope.cobranza.cobros.length; i++) {
- total += $scope.cobranza.cobros[i].importe;
+ total += $scope.cobranza.cobros[i].IMP;
}
return parseFloat(total.toFixed(2));
};
diff --git a/src/views/cobranza.html b/src/views/cobranza.html
index 2eb7aa4..37a8276 100644
--- a/src/views/cobranza.html
+++ b/src/views/cobranza.html
@@ -2,7 +2,7 @@