📄 mcash.java
字号:
/**
* Invalidate Document
* @return true if success
*/
public boolean invalidateIt()
{
log.info(toString());
setDocAction(DOCACTION_Prepare);
return true;
} // invalidateIt
/**
* Prepare Document
* @return new status (In Progress or Invalid)
*/
public String prepareIt()
{
log.info(toString());
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
if (m_processMsg != null)
return DocAction.STATUS_Invalid;
// Std Period open?
if (!MPeriod.isOpen(getCtx(), getDateAcct(), MDocType.DOCBASETYPE_CashJournal))
{
m_processMsg = "@PeriodClosed@";
return DocAction.STATUS_Invalid;
}
MCashLine[] lines = getLines(false);
if (lines.length == 0)
{
m_processMsg = "@NoLines@";
return DocAction.STATUS_Invalid;
}
// Add up Amounts
BigDecimal difference = Env.ZERO;
int C_Currency_ID = getC_Currency_ID();
for (int i = 0; i < lines.length; i++)
{
MCashLine line = lines[i];
if (!line.isActive())
continue;
if (C_Currency_ID == line.getC_Currency_ID())
difference = difference.add(line.getAmount());
else
{
BigDecimal amt = MConversionRate.convert(getCtx(), line.getAmount(),
line.getC_Currency_ID(), C_Currency_ID, getDateAcct(), 0,
getAD_Client_ID(), getAD_Org_ID());
if (amt == null)
{
m_processMsg = "No Conversion Rate found - @C_CashLine_ID@= " + line.getLine();
return DocAction.STATUS_Invalid;
}
difference = difference.add(amt);
}
}
setStatementDifference(difference);
// setEndingBalance(getBeginningBalance().add(getStatementDifference()));
//
m_justPrepared = true;
if (!DOCACTION_Complete.equals(getDocAction()))
setDocAction(DOCACTION_Complete);
return DocAction.STATUS_InProgress;
} // prepareIt
/**
* Approve Document
* @return true if success
*/
public boolean approveIt()
{
log.info(toString());
setIsApproved(true);
return true;
} // approveIt
/**
* Reject Approval
* @return true if success
*/
public boolean rejectIt()
{
log.info(toString());
setIsApproved(false);
return true;
} // rejectIt
/**
* Complete Document
* @return new status (Complete, In Progress, Invalid, Waiting ..)
*/
public String completeIt()
{
// Re-Check
if (!m_justPrepared)
{
String status = prepareIt();
if (!DocAction.STATUS_InProgress.equals(status))
return status;
}
// Implicit Approval
if (!isApproved())
approveIt();
//
log.info(toString());
// Allocation Header
MAllocationHdr alloc = new MAllocationHdr(getCtx(), false,
getDateAcct(), getC_Currency_ID(),
Msg.translate(getCtx(), "C_Cash_ID") + ": " + getName(), get_TrxName());
alloc.setAD_Org_ID(getAD_Org_ID());
if (!alloc.save())
{
m_processMsg = "Could not create Allocation Hdr";
return DocAction.STATUS_Invalid;
}
//
MCashLine[] lines = getLines(false);
for (int i = 0; i < lines.length; i++)
{
MCashLine line = lines[i];
if (MCashLine.CASHTYPE_Invoice.equals(line.getCashType()))
{
boolean differentCurrency = getC_Currency_ID() != line.getC_Currency_ID();
MAllocationHdr hdr = alloc;
if (differentCurrency)
{
hdr = new MAllocationHdr(getCtx(), false,
getDateAcct(), line.getC_Currency_ID(),
Msg.translate(getCtx(), "C_Cash_ID") + ": " + getName(), get_TrxName());
hdr.setAD_Org_ID(getAD_Org_ID());
if (!hdr.save())
{
m_processMsg = "Could not create Allocation Hdr";
return DocAction.STATUS_Invalid;
}
}
// Allocation Line
MAllocationLine aLine = new MAllocationLine (hdr, line.getAmount(),
line.getDiscountAmt(), line.getWriteOffAmt(), Env.ZERO);
aLine.setC_Invoice_ID(line.getC_Invoice_ID());
aLine.setC_CashLine_ID(line.getC_CashLine_ID());
if (!aLine.save())
{
m_processMsg = "Could not create Allocation Line";
return DocAction.STATUS_Invalid;
}
if (differentCurrency)
{
// Should start WF
hdr.processIt(DocAction.ACTION_Complete);
hdr.save();
}
}
else if (MCashLine.CASHTYPE_BankAccountTransfer.equals(line.getCashType()))
{
// Payment just as intermediate info
MPayment pay = new MPayment (getCtx(), 0, get_TrxName());
pay.setAD_Org_ID(getAD_Org_ID());
String documentNo = getName();
pay.setDocumentNo(documentNo);
pay.setR_PnRef(documentNo);
pay.set_Value("TrxType", "X"); // Transfer
pay.set_Value("TenderType", "X");
//
pay.setC_BankAccount_ID(line.getC_BankAccount_ID());
pay.setC_DocType_ID(true); // Receipt
pay.setDateTrx(getStatementDate());
pay.setDateAcct(getDateAcct());
pay.setAmount(line.getC_Currency_ID(), line.getAmount().negate()); // Transfer
pay.setDescription(line.getDescription());
pay.setDocStatus(MPayment.DOCSTATUS_Closed);
pay.setDocAction(MPayment.DOCACTION_None);
pay.setPosted(true);
pay.setIsAllocated(true); // Has No Allocation!
pay.setProcessed(true);
if (!pay.save())
{
m_processMsg = "Could not create Payment";
return DocAction.STATUS_Invalid;
}
}
}
// Should start WF
alloc.processIt(DocAction.ACTION_Complete);
alloc.save();
// User Validation
String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
if (valid != null)
{
m_processMsg = valid;
return DocAction.STATUS_Invalid;
}
//Update Cash Book
MCashBook cb = MCashBook.get(getCtx(), getC_CashBook_ID());
String sql = "SELECT * FROM C_CashBook "
+ "WHERE C_CashBook_ID = ?";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getC_CashBook_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
cb = new MCashBook(getCtx(), rs,
get_TrxName());
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
setBeginningBalance(cb.getCurrentBalance());
setEndingBalance(cb.getCurrentBalance().add(getStatementDifference()));
cb.setCurrentBalance(getEndingBalance());
cb.save(get_TrxName());
//
setProcessed(true);
setDocAction(DOCACTION_Close);
return DocAction.STATUS_Completed;
} // completeIt
/**
* Void Document.
* Same as Close.
* @return true if success
*/
public boolean voidIt()
{
log.info(toString());
setDocAction(DOCACTION_None);
return false;
} // voidIt
/**
* Close Document.
* Cancel not delivered Qunatities
* @return true if success
*/
public boolean closeIt()
{
log.info(toString());
setDocAction(DOCACTION_None);
return true;
} // closeIt
/**
* Reverse Correction
* @return true if success
*/
public boolean reverseCorrectIt()
{
log.info(toString());
return false;
} // reverseCorrectionIt
/**
* Reverse Accrual - none
* @return true if success
*/
public boolean reverseAccrualIt()
{
log.info(toString());
return false;
} // reverseAccrualIt
/**
* Re-activate
* @return true if success
*/
public boolean reActivateIt()
{
log.info(toString());
setProcessed(false);
if (reverseCorrectIt())
return true;
return false;
} // reActivateIt
/**
* Set Processed
* @param processed processed
*/
public void setProcessed (boolean processed)
{
super.setProcessed (processed);
String sql = "UPDATE C_CashLine SET Processed='"
+ (processed ? "Y" : "N")
+ "' WHERE C_Cash_ID=" + getC_Cash_ID();
int noLine = DB.executeUpdate (sql, get_TrxName());
m_lines = null;
log.fine(processed + " - Lines=" + noLine);
} // setProcessed
/**
* String Representation
* @return info
*/
public String toString ()
{
StringBuffer sb = new StringBuffer ("MCash[");
sb.append (get_ID ())
.append ("-").append (getName())
.append(", Balance=").append(getBeginningBalance())
.append("->").append(getEndingBalance())
.append ("]");
return sb.toString ();
} // toString
/*************************************************************************
* Get Summary
* @return Summary of Document
*/
public String getSummary()
{
StringBuffer sb = new StringBuffer();
sb.append(getName());
// : Total Lines = 123.00 (#1)
sb.append(": ")
.append(Msg.translate(getCtx(),"BeginningBalance")).append("=").append(getBeginningBalance())
.append(",")
.append(Msg.translate(getCtx(),"EndingBalance")).append("=").append(getEndingBalance())
.append(" (#").append(getLines(false).length).append(")");
// - Description
if (getDescription() != null && getDescription().length() > 0)
sb.append(" - ").append(getDescription());
return sb.toString();
} // getSummary
/**
* Get Process Message
* @return clear text error message
*/
public String getProcessMsg()
{
return m_processMsg;
} // getProcessMsg
/**
* Get Document Owner (Responsible)
* @return AD_User_ID
*/
public int getDoc_User_ID()
{
return getCreatedBy();
} // getDoc_User_ID
/**
* Get Document Approval Amount
* @return amount difference
*/
public BigDecimal getApprovalAmt()
{
return getStatementDifference();
} // getApprovalAmt
/**
* Get Currency
* @return Currency
*/
public int getC_Currency_ID ()
{
return getCashBook().getC_Currency_ID();
} // getC_Currency_ID
} // MCash
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -