📄 mallocationhdr.java
字号:
{
log.info(toString());
setProcessing(false);
return true;
} // unlockIt
/**
* 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_PaymentAllocation))
{
m_processMsg = "@PeriodClosed@";
return DocAction.STATUS_Invalid;
}
getLines(false);
if (m_lines.length == 0)
{
m_processMsg = "@NoLines@";
return DocAction.STATUS_Invalid;
}
// Add up Amounts & validate
BigDecimal approval = Env.ZERO;
for (int i = 0; i < m_lines.length; i++)
{
MAllocationLine line = m_lines[i];
approval = approval.add(line.getWriteOffAmt()).add(line.getDiscountAmt());
// Make sure there is BP
if (line.getC_BPartner_ID() == 0)
{
m_processMsg = "No Business Partner";
return DocAction.STATUS_Invalid;
}
}
setApprovalAmt(approval);
//
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());
// Link
getLines(false);
HashSet<Integer> bps = new HashSet<Integer>();
for (int i = 0; i < m_lines.length; i++)
{
MAllocationLine line = m_lines[i];
bps.add(new Integer(line.processIt(false))); // not reverse
}
updateBP(bps);
// 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.
* Same as Close.
* @return true if success
*/
public boolean voidIt()
{
log.info(toString());
boolean retValue = reverseIt();
setDocAction(DOCACTION_None);
return retValue;
} // 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());
boolean retValue = reverseIt();
setDocAction(DOCACTION_None);
return retValue;
} // reverseCorrectionIt
/**
* Reverse Accrual - none
* @return false
*/
public boolean reverseAccrualIt()
{
log.info(toString());
boolean retValue = reverseIt();
setDocAction(DOCACTION_None);
return retValue;
} // reverseAccrualIt
/**
* Re-activate
* @return false
*/
public boolean reActivateIt()
{
log.info(toString());
return false;
} // reActivateIt
/**
* String Representation
* @return info
*/
public String toString ()
{
StringBuffer sb = new StringBuffer ("MAllocationHdr[");
sb.append(get_ID()).append("-").append(getSummary()).append ("]");
return sb.toString ();
} // toString
/**
* Get Document Info
* @return document info (untranslated)
*/
public String getDocumentInfo()
{
return Msg.getElement(getCtx(), "C_AllocationHdr_ID") + " " + getDocumentNo();
} // getDocumentInfo
/**
* Create PDF
* @return File or null
*/
public File createPDF ()
{
try
{
File temp = File.createTempFile(get_TableName()+get_ID()+"_", ".pdf");
return createPDF (temp);
}
catch (Exception e)
{
log.severe("Could not create PDF - " + e.getMessage());
}
return null;
} // getPDF
/**
* Create PDF file
* @param file output file
* @return file if success
*/
public File createPDF (File file)
{
// ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.INVOICE, getC_Invoice_ID());
// if (re == null)
return null;
// return re.getPDF(file);
} // createPDF
/*************************************************************************
* Get Summary
* @return Summary of Document
*/
public String getSummary()
{
StringBuffer sb = new StringBuffer();
sb.append(getDocumentNo());
// : Total Lines = 123.00 (#1)
sb.append(": ")
.append(Msg.translate(getCtx(),"ApprovalAmt")).append("=").append(getApprovalAmt())
.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
/**************************************************************************
* Reverse Allocation.
* Period needs to be open
* @return true if reversed
*/
private boolean reverseIt()
{
if (!isActive())
throw new IllegalStateException("Allocation already reversed (not active)");
// Can we delete posting
if (!MPeriod.isOpen(getCtx(), getDateTrx(), MPeriodControl.DOCBASETYPE_PaymentAllocation))
throw new IllegalStateException("@PeriodClosed@");
// Set Inactive
setIsActive (false);
setDocumentNo(getDocumentNo()+"^");
setDocStatus(DOCSTATUS_Reversed); // for direct calls
if (!save() || isActive())
throw new IllegalStateException("Cannot de-activate allocation");
// Delete Posting
String sql = "DELETE FROM Fact_Acct WHERE AD_Table_ID=" + MAllocationHdr.Table_ID
+ " AND Record_ID=" + getC_AllocationHdr_ID();
int no = DB.executeUpdate(sql, get_TrxName());
log.fine("Fact_Acct deleted #" + no);
// Unlink Invoices
getLines(true);
HashSet<Integer> bps = new HashSet<Integer>();
for (int i = 0; i < m_lines.length; i++)
{
MAllocationLine line = m_lines[i];
line.setIsActive(false);
line.save();
bps.add(new Integer(line.processIt(true))); // reverse
}
updateBP(bps);
return true;
} // reverse
/**
* Update Open Balance of BP's
* @param bps list of business partners
*/
private void updateBP(HashSet<Integer> bps)
{
log.info("#" + bps.size());
Iterator<Integer> it = bps.iterator();
while (it.hasNext())
{
int C_BPartner_ID = it.next();
MBPartner bp = new MBPartner(getCtx(), C_BPartner_ID, get_TrxName());
bp.setTotalOpenBalance(); // recalculates from scratch
// bp.setSOCreditStatus(); // called automatically
if (bp.save())
log.fine(bp.toString());
else
log.log(Level.SEVERE, "BP not updated - " + bp);
}
} // updateBP
} // MAllocation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -