use of org.compiere.model.MPaySelectionCheck in project adempiere by adempiere.
the class PaySelectionCreateCheck method createCheck.
// doIt
/**
* Create Check from line
* @param line
* @throws Exception for invalid bank accounts
*/
private void createCheck(MPaySelectionLine line) throws Exception {
// Try to find one
for (int i = 0; i < paySelectionChecks.size(); i++) {
MPaySelectionCheck check = (MPaySelectionCheck) paySelectionChecks.get(i);
// Add to existing
if (check.getC_BPartner_ID() == line.getInvoice().getC_BPartner_ID()) {
check.addLine(line);
if (!check.save())
throw new IllegalStateException("Cannot save MPaySelectionCheck");
line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
line.setProcessed(true);
if (!line.save())
throw new IllegalStateException("Cannot save MPaySelectionLine");
return;
}
}
// Create new
String PaymentRule = line.getPaymentRule();
if (p_PaymentRule != null) {
if (!X_C_Order.PAYMENTRULE_DirectDebit.equals(PaymentRule))
PaymentRule = p_PaymentRule;
}
MPaySelectionCheck check = new MPaySelectionCheck(line, PaymentRule);
if (!check.isValid()) {
int C_BPartner_ID = check.getC_BPartner_ID();
MBPartner bp = MBPartner.get(getCtx(), C_BPartner_ID);
String msg = "@NotFound@ @C_BP_BankAccount@: " + bp.getName();
throw new AdempiereUserError(msg);
}
if (!check.save())
throw new IllegalStateException("Cannot save MPaySelectionCheck");
line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
line.setProcessed(true);
if (!line.save())
throw new IllegalStateException("Cannot save MPaySelectionLine");
paySelectionChecks.add(check);
}
use of org.compiere.model.MPaySelectionCheck in project adempiere by adempiere.
the class AllocationAuto method allocateBPPaymentWithInfo.
// getInvoices
/**************************************************************************
* Allocate Individual Payments with payment references
* @return number of allocations
*/
private int allocateBPPaymentWithInfo() {
int count = 0;
//**** See if there is a direct link (Invoice or Pay Selection)
for (int p = 0; p < m_payments.length; p++) {
MPayment payment = m_payments[p];
if (payment.isAllocated())
continue;
BigDecimal allocatedAmt = payment.getAllocatedAmt();
log.info(payment + ", Allocated=" + allocatedAmt);
if (allocatedAmt != null && allocatedAmt.signum() != 0)
continue;
BigDecimal availableAmt = payment.getPayAmt().add(payment.getDiscountAmt()).add(payment.getWriteOffAmt()).add(payment.getOverUnderAmt());
if (!payment.isReceipt())
availableAmt = availableAmt.negate();
log.fine("Available=" + availableAmt);
//
if (payment.getC_Invoice_ID() != 0) {
for (int i = 0; i < m_invoices.length; i++) {
MInvoice invoice = m_invoices[i];
if (invoice.isPaid())
continue;
// log.fine("allocateIndividualPayments - " + invoice);
if (payment.getC_Invoice_ID() == invoice.getC_Invoice_ID()) {
if (payment.getC_Currency_ID() == invoice.getC_Currency_ID()) {
BigDecimal openAmt = invoice.getOpenAmt(true, null);
if (!invoice.isSOTrx())
openAmt = openAmt.negate();
log.fine(invoice + ", Open=" + openAmt);
// With Discount, etc.
if (availableAmt.compareTo(openAmt) == 0) {
if (payment.allocateIt()) {
addLog(0, payment.getDateAcct(), openAmt, payment.getDocumentNo() + " [1]");
count++;
}
break;
}
} else // Mixed Currency
{
}
}
// invoice found
}
// for all invoices
} else // payment has invoice
// No direct invoice
{
MPaySelectionCheck psCheck = MPaySelectionCheck.getOfPayment(getCtx(), payment.getC_Payment_ID(), get_TrxName());
if (psCheck == null)
continue;
//
BigDecimal totalInvoice = Env.ZERO;
List<MPaySelectionLine> paySelectionLines = psCheck.getPaySelectionLinesAsList(false);
//for (int i = 0; i < psLines.length; i++)
for (MPaySelectionLine paySelectionLine : paySelectionLines) {
MInvoice invoice = paySelectionLine.getInvoice();
if (payment.getC_Currency_ID() == invoice.getC_Currency_ID()) {
BigDecimal invoiceAmt = invoice.getOpenAmt(true, null);
BigDecimal overUnder = paySelectionLine.getOpenAmt().subtract(paySelectionLine.getPayAmt()).subtract(paySelectionLine.getDiscountAmt()).subtract(paySelectionLine.getDifferenceAmt());
invoiceAmt = invoiceAmt.subtract(paySelectionLine.getDiscountAmt()).subtract(paySelectionLine.getDifferenceAmt()).subtract(overUnder);
if (!invoice.isSOTrx())
invoiceAmt = invoiceAmt.negate();
log.fine(invoice + ", Invoice=" + invoiceAmt);
totalInvoice = totalInvoice.add(invoiceAmt);
} else // Multi-Currency
{
}
}
if (availableAmt.compareTo(totalInvoice) == 0) {
if (payment.allocateIt()) {
addLog(0, payment.getDateAcct(), availableAmt, payment.getDocumentNo() + " [n]");
count++;
}
}
}
// No direct invoice
}
return count;
}
Aggregations