IDEMPIERE-814 POS Sales Order generating Cash transactions

This commit is contained in:
Richard Morales 2013-04-23 18:25:10 -05:00
parent 976654ef25
commit 2fa71e092f
1 changed files with 48 additions and 35 deletions

View File

@ -1721,47 +1721,60 @@ public class MInvoice extends X_C_Invoice implements DocAction
fromPOS = getC_Order().getC_POS_ID() > 0; fromPOS = getC_Order().getC_POS_ID() > 0;
} }
// Create Cash // Create Cash Payment
if (PAYMENTRULE_Cash.equals(getPaymentRule()) && !fromPOS ) if (PAYMENTRULE_Cash.equals(getPaymentRule()) && !fromPOS )
{ {
// Modifications for POSterita String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
// MBankAccount ba = new Query(getCtx(),MBankAccount.Table_Name,whereClause,get_TrxName())
// MCash cash = MCash.get (getCtx(), getAD_Org_ID(), .setParameters(getAD_Org_ID(), getC_Currency_ID())
// getDateInvoiced(), getC_Currency_ID(), get_TrxName()); .setOrderBy("IsDefault DESC")
.first();
MCash cash; if (ba == null) {
m_processMsg = "@NoAccountOrgCurrency@";
int posId = Env.getContextAsInt(getCtx(),Env.POS_ID);
if (posId != 0)
{
MPOS pos = new MPOS(getCtx(),posId,get_TrxName());
int cashBookId = pos.getC_CashBook_ID();
cash = MCash.get(getCtx(),cashBookId,getDateInvoiced(),get_TrxName());
}
else
{
cash = MCash.get (getCtx(), getAD_Org_ID(),
getDateInvoiced(), getC_Currency_ID(), get_TrxName());
}
// End Posterita Modifications
if (cash == null || cash.get_ID() == 0)
{
m_processMsg = "@NoCashBook@";
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
MCashLine cl = new MCashLine (cash);
cl.setInvoice(this); MDocType[] doctypes = MDocType.getOfDocBaseType(getCtx(), MDocType.DOCBASETYPE_ARReceipt);
if (!cl.save(get_TrxName())) if (doctypes == null || doctypes.length == 0) {
{ m_processMsg = "No document type for AR Receipt";
m_processMsg = "Could not save Cash Journal Line";
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
info.append("@C_Cash_ID@: " + cash.getName() + " #" + cl.getLine()); MDocType doctype = null;
setC_CashLine_ID(cl.getC_CashLine_ID()); for (MDocType doc : doctypes) {
} // CashBook if (doc.getAD_Org_ID() == this.getAD_Org_ID()) {
doctype = doc;
break;
}
}
if (doctype == null)
doctype = doctypes[0];
MPayment payment = new MPayment(getCtx(), 0, get_TrxName());
payment.setAD_Org_ID(getAD_Org_ID());
payment.setTenderType(MPayment.TENDERTYPE_Cash);
payment.setC_BankAccount_ID(ba.getC_BankAccount_ID());
payment.setC_BPartner_ID(getC_BPartner_ID());
payment.setC_Invoice_ID(getC_Invoice_ID());
payment.setC_Currency_ID(getC_Currency_ID());
payment.setC_DocType_ID(doctype.getC_DocType_ID());
payment.setPayAmt(getGrandTotal());
payment.setIsPrepayment(false);
payment.setDateAcct(getDateAcct());
payment.setDateTrx(getDateInvoiced());
// Save payment
payment.saveEx();
payment.setDocAction(MPayment.DOCACTION_Complete);
if (!payment.processIt(MPayment.DOCACTION_Complete)) {
m_processMsg = "Cannot Complete the Payment :" + payment;
return DocAction.STATUS_Invalid;
}
payment.saveEx();
info.append("@C_Payment_ID@: " + payment.getDocumentInfo());
} // Payment
// Update Order & Match // Update Order & Match
int matchInv = 0; int matchInv = 0;