📄 mbankstatement.java
字号:
return DocAction.STATUS_Invalid;
}
// Lines
BigDecimal total = Env.ZERO;
Timestamp minDate = getStatementDate();
Timestamp maxDate = minDate;
for (int i = 0; i < lines.length; i++)
{
MBankStatementLine line = lines[i];
total = total.add(line.getStmtAmt());
if (line.getDateAcct().before(minDate))
minDate = line.getDateAcct();
if (line.getDateAcct().after(maxDate))
maxDate = line.getDateAcct();
}
setStatementDifference(total);
setEndingBalance(getBeginningBalance().add(total));
if (!MPeriod.isOpen(getCtx(), minDate, MDocType.DOCBASETYPE_BankStatement)
|| !MPeriod.isOpen(getCtx(), maxDate, MDocType.DOCBASETYPE_BankStatement))
{
m_processMsg = "@PeriodClosed@";
return DocAction.STATUS_Invalid;
}
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("approveIt - " + toString());
setIsApproved(true);
return true;
} // approveIt
/**
* Reject Approval
* @return true if success
*/
public boolean rejectIt()
{
log.info("rejectIt - " + 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("completeIt - " + toString());
// Set Payment reconciled
MBankStatementLine[] lines = getLines(false);
for (int i = 0; i < lines.length; i++)
{
MBankStatementLine line = lines[i];
if (line.getC_Payment_ID() != 0)
{
MPayment payment = new MPayment (getCtx(), line.getC_Payment_ID(), get_TrxName());
payment.setIsReconciled(true);
payment.save(get_TrxName());
}
}
// Update Bank Account
MBankAccount ba = MBankAccount.get(getCtx(), getC_BankAccount_ID());
String sql = "SELECT * FROM C_BankAccount "
+ "WHERE C_BankAccount_ID=?";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getC_BankAccount_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
ba = new MBankAccount(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(ba.getCurrentBalance());
setEndingBalance(ba.getCurrentBalance().add(getStatementDifference()));
ba.setCurrentBalance(getEndingBalance());
ba.save(get_TrxName());
// User Validation
String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
if (valid != null)
{
m_processMsg = valid;
return DocAction.STATUS_Invalid;
}
//
setProcessed(true);
setDocAction(DOCACTION_Close);
return DocAction.STATUS_Completed;
} // completeIt
/**
* Void Document.
* @return false
*/
public boolean voidIt()
{
log.info(toString());
if (DOCSTATUS_Closed.equals(getDocStatus())
|| DOCSTATUS_Reversed.equals(getDocStatus())
|| DOCSTATUS_Voided.equals(getDocStatus()))
{
m_processMsg = "Document Closed: " + getDocStatus();
setDocAction(DOCACTION_None);
return false;
}
// Not Processed
if (DOCSTATUS_Drafted.equals(getDocStatus())
|| DOCSTATUS_Invalid.equals(getDocStatus())
|| DOCSTATUS_InProgress.equals(getDocStatus())
|| DOCSTATUS_Approved.equals(getDocStatus())
|| DOCSTATUS_NotApproved.equals(getDocStatus()) )
;
// Std Period open?
else
{
if (!MPeriod.isOpen(getCtx(), getStatementDate(), MDocType.DOCBASETYPE_BankStatement))
{
m_processMsg = "@PeriodClosed@";
return false;
}
if (MFactAcct.delete(Table_ID, getC_BankStatement_ID(), get_TrxName()) < 0)
return false; // could not delete
}
// Set lines to 0
MBankStatementLine[] lines = getLines(true);
for (int i = 0; i < lines.length; i++)
{
MBankStatementLine line = lines[i];
BigDecimal old = line.getStmtAmt();
if (line.getStmtAmt().compareTo(Env.ZERO) != 0)
{
String description = Msg.getMsg(getCtx(), "Voided") + " ("
+ Msg.translate(getCtx(), "StmtAmt") + "=" + line.getStmtAmt();
if (line.getTrxAmt().compareTo(Env.ZERO) != 0)
description += ", " + Msg.translate(getCtx(), "TrxAmt") + "=" + line.getTrxAmt();
if (line.getChargeAmt().compareTo(Env.ZERO) != 0)
description += ", " + Msg.translate(getCtx(), "ChargeAmt") + "=" + line.getChargeAmt();
if (line.getInterestAmt().compareTo(Env.ZERO) != 0)
description += ", " + Msg.translate(getCtx(), "InterestAmt") + "=" + line.getInterestAmt();
description += ")";
line.addDescription(description);
//
line.setStmtAmt(Env.ZERO);
line.setTrxAmt(Env.ZERO);
line.setChargeAmt(Env.ZERO);
line.setInterestAmt(Env.ZERO);
line.save(get_TrxName());
//
if (line.getC_Payment_ID() != 0)
{
MPayment payment = new MPayment (getCtx(), line.getC_Payment_ID(), get_TrxName());
payment.setIsReconciled(false);
payment.save(get_TrxName());
}
}
}
addDescription(Msg.getMsg(getCtx(), "Voided"));
setStatementDifference(Env.ZERO);
setProcessed(true);
setDocAction(DOCACTION_None);
return true;
} // voidIt
/**
* Close Document.
* @return true if success
*/
public boolean closeIt()
{
log.info("closeIt - " + toString());
setDocAction(DOCACTION_None);
return true;
} // closeIt
/**
* Reverse Correction
* @return false
*/
public boolean reverseCorrectIt()
{
log.info("reverseCorrectIt - " + toString());
return false;
} // reverseCorrectionIt
/**
* Reverse Accrual
* @return false
*/
public boolean reverseAccrualIt()
{
log.info("reverseAccrualIt - " + toString());
return false;
} // reverseAccrualIt
/**
* Re-activate
* @return false
*/
public boolean reActivateIt()
{
log.info("reActivateIt - " + toString());
return false;
} // reActivateIt
/*************************************************************************
* 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(),"StatementDifference")).append("=").append(getStatementDifference())
.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 getUpdatedBy();
} // getDoc_User_ID
/**
* Get Document Approval Amount.
* Statement Difference
* @return amount
*/
public BigDecimal getApprovalAmt()
{
return getStatementDifference();
} // getApprovalAmt
/**
* Get Document Currency
* @return C_Currency_ID
*/
public int getC_Currency_ID()
{
// MPriceList pl = MPriceList.get(getCtx(), getM_PriceList_ID());
// return pl.getC_Currency_ID();
return 0;
} // getC_Currency_ID
} // MBankStatement
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -