use of org.compiere.model.MPayment 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;
}
}
use of org.compiere.model.MPayment in project adempiere by adempiere.
the class MHRPaySelectionCheck method confirmPrint.
// getBPartnerInfo
/**************************************************************************
* Confirm Print.
* Create Payments the first time
* @param checks checks
* @param batch batch
* @return last Document number or 0 if nothing printed
*/
public static int confirmPrint(Collection<MHRPaySelectionCheck> checks, MPaymentBatch batch) {
int lastDocumentNo = 0;
for (MHRPaySelectionCheck check : checks) {
StringBuilder sqlConcept = new StringBuilder();
sqlConcept.append("SELECT HR_Concept_ID FROM HR_Movement m ").append(" WHERE EXISTS(SELECT 1 FROM HR_PaySelectionLine psl ").append(" WHERE psl.HR_Movement_ID = m.HR_Movement_ID AND m.C_BPartner_ID=?").append(" AND psl.HR_PaySelection_ID=?)");
int conceptId = DB.getSQLValue(check.get_TrxName(), sqlConcept.toString(), check.getC_BPartner_ID(), check.getHR_PaySelection_ID());
StringBuilder sqlPayroll = new StringBuilder();
sqlPayroll.append("SELECT HR_Payroll_ID FROM HR_PaySelection ps INNER JOIN HR_Process p ON (p.HR_Process_ID=ps.HR_Process_ID) ").append("WHERE ps.HR_PaySelection_ID=?");
int payrollId = DB.getSQLValueEx(check.get_TrxName(), sqlPayroll.toString(), check.getHR_PaySelection_ID());
MHRConcept concept = new MHRConcept(check.getCtx(), conceptId, check.get_TrxName());
MHRPayroll payroll = new MHRPayroll(check.getCtx(), payrollId, check.get_TrxName());
MPayment payment = new MPayment(check.getCtx(), check.getC_Payment_ID(), check.get_TrxName());
// Existing Payment
if (check.getC_Payment_ID() > 0) {
// Update check number
if (check.getPaymentRule().equals(PAYMENTRULE_Check)) {
payment.setCheckNo(check.getDocumentNo());
if (!payment.save())
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
}
} else // New Payment
{
payment = new MPayment(check.getCtx(), 0, check.get_TrxName());
if (check.getPaymentRule().equals(PAYMENTRULE_Check))
payment.setBankCheck(check.getParent().getC_BankAccount_ID(), false, check.getDocumentNo());
else if (check.getPaymentRule().equals(PAYMENTRULE_CreditCard))
payment.setTenderType(X_C_Payment.TENDERTYPE_CreditCard);
else if (check.getPaymentRule().equals(PAYMENTRULE_DirectDeposit) || check.getPaymentRule().equals(PAYMENTRULE_DirectDebit))
payment.setTenderType(X_C_Payment.TENDERTYPE_DirectDebit);
else {
s_log.log(Level.SEVERE, "Unsupported Payment Rule=" + check.getPaymentRule());
continue;
}
payment.setTrxType(X_C_Payment.TRXTYPE_CreditPayment);
payment.setDescription(check.getHR_PaySelection().getDescription());
payment.setIsReceipt(check.isReceipt());
payment.setAmount(check.getParent().getC_Currency_ID(), check.getPayAmt());
payment.setDiscountAmt(check.getDiscountAmt());
payment.setDateTrx(check.getParent().getPayDate());
// globalqss [ 2030685 ]
payment.setDateAcct(payment.getDateTrx());
payment.setC_BPartner_ID(check.getC_BPartner_ID());
/*
// Link to Batch
if (batch != null)
{
if (batch.getC_PaymentBatch_ID() == 0)
batch.save(); // new
payment.setC_PaymentBatch_ID(batch.getC_PaymentBatch_ID());
}
*/
if (concept.isPrepayment()) {
payment.setIsPrepayment(true);
} else {
int C_Charge_ID = DB.getSQLValue(check.get_TrxName(), "SELECT MAX(C_Charge_ID) FROM HR_Attribute WHERE IsActive='Y' AND HR_Concept_ID=" + conceptId);
if (// modify e-Evolution 25May2010 if(C_Charge_ID < 0)
C_Charge_ID <= 0)
payment.setC_Charge_ID(payroll.getC_Charge_ID());
else
payment.setC_Charge_ID(C_Charge_ID);
}
payment.setC_BankAccount_ID(check.getParent().getC_BankAccount_ID());
payment.setWriteOffAmt(Env.ZERO);
payment.saveEx();
int C_Payment_ID = payment.get_ID();
if (C_Payment_ID < 1)
s_log.log(Level.SEVERE, "Payment not created=" + check);
else {
check.setC_Payment_ID(C_Payment_ID);
// Payment process needs it
check.save();
// Should start WF
payment.processIt(DocAction.ACTION_Complete);
if (!payment.save())
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
payment.setAD_Org_ID(check.getAD_Org_ID());
payment.setAD_OrgTrx_ID(check.getAD_Org_ID());
payment.saveEx();
}
}
// Get Check Document No
try {
int no = Integer.parseInt(check.getDocumentNo());
if (lastDocumentNo < no)
lastDocumentNo = no;
} catch (NumberFormatException ex) {
s_log.log(Level.SEVERE, "DocumentNo=" + check.getDocumentNo(), ex);
}
check.setIsPrinted(true);
check.setProcessed(true);
check.saveEx();
}
// all checks
s_log.fine("Last Document No = " + lastDocumentNo);
return lastDocumentNo;
}
Aggregations