Search in sources :

Example 1 with MPaymentAllocate

use of org.compiere.model.MPaymentAllocate in project adempiere by adempiere.

the class Collect method payCreditMemo.

// payCheck
/**
	 * 	Payment with credit note
	 * 
	 * @return true if payment processed correctly; otherwise false
	 * 
	 */
public boolean payCreditMemo(MInvoice creditNote, BigDecimal amount) {
    int invoiceId = order.getC_Invoice_ID();
    if (invoiceId == 0)
        return false;
    MPayment payment = createPayment(MPayment.TENDERTYPE_Account);
    if (payment.getC_Invoice_ID() > 0)
        payment.setC_Invoice_ID(0);
    if (payment.getC_Order_ID() > 0)
        payment.setC_Order_ID(0);
    if (payment.getC_Charge_ID() > 0)
        payment.setC_Charge_ID(0);
    payment.setAmount(order.getC_Currency_ID(), Env.ZERO);
    payment.setC_BankAccount_ID(entityPOS.getC_BankAccount_ID());
    payment.setDateTrx(getDateTrx());
    payment.setDateAcct(getDateTrx());
    payment.saveEx();
    //Invoice
    MPaymentAllocate paymentAllocate = new MPaymentAllocate(Env.getCtx(), 0, trxName);
    paymentAllocate.setC_Payment_ID(payment.getC_Payment_ID());
    paymentAllocate.setC_Invoice_ID(invoiceId);
    paymentAllocate.setInvoiceAmt(amount);
    paymentAllocate.setAmount(amount);
    paymentAllocate.saveEx();
    //CreditNote
    paymentAllocate = new MPaymentAllocate(Env.getCtx(), 0, trxName);
    paymentAllocate.setC_Payment_ID(payment.getC_Payment_ID());
    paymentAllocate.setC_Invoice_ID(creditNote.getC_Invoice_ID());
    paymentAllocate.setAmount(amount.negate());
    paymentAllocate.setInvoiceAmt(amount.negate());
    paymentAllocate.saveEx();
    payment.setDocAction(MPayment.DOCACTION_Complete);
    payment.setDocStatus(MPayment.DOCSTATUS_Drafted);
    if (payment.processIt(MPayment.DOCACTION_Complete)) {
        payment.saveEx();
        MBankStatement.addPayment(payment);
        return true;
    } else {
        return false;
    }
}
Also used : MPayment(org.compiere.model.MPayment) MPaymentAllocate(org.compiere.model.MPaymentAllocate)

Aggregations

MPayment (org.compiere.model.MPayment)1 MPaymentAllocate (org.compiere.model.MPaymentAllocate)1