此程式碼為會計人員實作了一個撤銷機制,用於反轉他們的操作。這在發生錯誤並需要更正的情況下非常有用。程式碼還根據文件的當前狀態定義了可以對文件執行的有效操作。
這是一段 Java 程式碼,用於在 ERP 系統中自訂折舊分錄的實作,繼承自基礎類別 MDepreciationEntry 並實作 DocOptions 介面。
該類別覆寫了 voidIt() 方法,用於刪除文件的會計分錄,並更新 MDepreciationExp 表以移除 ParentID 並將「processed」標誌設為「N」。該方法還會在刪除會計分錄之前檢查期間是否為開放狀態。
customizeValidActions() 方法也被實作,以根據文件狀態自訂可用的有效操作。例如,如果文件狀態為「已完成」,則唯一可用的有效操作是作廢該文件。
package tw.ninniku.model;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.model.MDepreciationExp;
import org.compiere.model.MPeriod;
import org.compiere.process.DocOptions;
import org.compiere.process.DocumentEngine;
import org.compiere.util.DB;
public class MDepreciationEntry extends org.compiere.model.MDepreciationEntry implements DocOptions {
/**
*
*/
private static final long serialVersionUID = 1L;
public MDepreciationEntry(Properties ctx, int A_Depreciation_Entry_ID, String trxName) {
super(ctx, A_Depreciation_Entry_ID, trxName);
// 自動生成的建構子
}
public MDepreciationEntry(Properties ctx, ResultSet rs, String trxName) {
super(ctx, rs, trxName);
// 自動生成的建構子
}
@Override
public boolean voidIt() {
/**
* 1.刪除此文件的會計分錄。
* 2.重新啟用折舊文件並移除 ParentID。
*/
MPeriod.testPeriodOpen(getCtx(), getDateAcct(), getC_DocType_ID(), getAD_Org_ID());
String sql = "delete from fact_acct where ad_table_id = ? and record_id = ?";
DB.executeUpdateEx(sql, new Object[]{MDepreciationEntry.Table_ID,getA_Depreciation_Entry_ID()}, get_TrxName());
return unprocessLines();
}
private boolean unprocessLines()
{
String sql = "UPDATE " + MDepreciationExp.Table_Name + " SET "
+ MDepreciationExp.COLUMNNAME_A_Depreciation_Entry_ID + "=NULL , processed = 'N' "
+ " WHERE "
+ MDepreciationExp.COLUMNNAME_A_Depreciation_Entry_ID + "=?";
int id = get_ID();
if (id <= 0)
{ // 如果當前 ID 缺失,使用舊 ID
id = get_IDOld();
}
int no = DB.executeUpdateEx(sql, new Object[]{id}, get_TrxName());
if (log.isLoggable(Level.FINE)) log.fine("Updated #" + no);
if(no > 0)
return true;
return false;
}
@Override
public int customizeValidActions(String docStatus, Object processing, String orderType, String isSOTrx,
int AD_Table_ID, String[] docAction, String[] options, int index) {
if (options == null)
throw new IllegalArgumentException("Option array parameter is null");
if (docAction == null)
throw new IllegalArgumentException("Doc action array parameter is null");
// 需要審批 .. NA
if (docStatus.equals(DocumentEngine.STATUS_NotApproved))
{
options[index++] = DocumentEngine.ACTION_Void;
options[index++] = DocumentEngine.ACTION_Complete;
}
// 草稿/無效 .. DR/IN
else if (docStatus.equals(DocumentEngine.STATUS_Drafted)
|| docStatus.equals(DocumentEngine.STATUS_Invalid))
{
options[index++] = DocumentEngine.ACTION_Complete;
options[index++] = DocumentEngine.ACTION_Void;
}
// 處理中 .. IP
else if (docStatus.equals(DocumentEngine.STATUS_InProgress)
|| docStatus.equals(DocumentEngine.STATUS_Approved))
{
options[index++] = DocumentEngine.ACTION_Complete;
}
// 已完成 .. CO
else if (docStatus.equals(DocumentEngine.STATUS_Completed))
{
options[index++] = DocumentEngine.ACTION_Void;
docAction[0] = DocumentEngine.ACTION_Void;
}
// 等待付款
else if (docStatus.equals(DocumentEngine.STATUS_WaitingPayment)
|| docStatus.equals(DocumentEngine.STATUS_WaitingConfirmation))
{
}
// 已關閉、已作廢、已反轉 .. CL/VO/RE
else if (docStatus.equals(DocumentEngine.STATUS_Closed)
|| docStatus.equals(DocumentEngine.STATUS_Voided)
|| docStatus.equals(DocumentEngine.STATUS_Reversed))
return 0;
return index;
}
}
English Version
The code implements an undo mechanism for accounting staff to reverse their actions. This can be useful in situations where a mistake has been made and needs to be corrected. The code also defines valid actions that can be taken on the document depending on its current status.
This is a Java code for a custom implementation of a depreciation entry in an ERP system, extending the base class MDepreciationEntry and implementing the DocOptions interface.
The class overrides the voidIt() method, which deletes the accounting entry of the document and updates the MDepreciationExp table to remove the ParentID and set the “processed” flag to ‘N’. The method also checks if the period is open before deleting the accounting entry.
The customizeValidActions() method is also implemented to customize the valid actions available for this document based on its status. For example, if the document status is “Completed”, the only valid action available is to void the document.
package tw.ninniku.model;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.model.MDepreciationExp;
import org.compiere.model.MPeriod;
import org.compiere.process.DocOptions;
import org.compiere.process.DocumentEngine;
import org.compiere.util.DB;
public class MDepreciationEntry extends org.compiere.model.MDepreciationEntry implements DocOptions {
/**
*
*/
private static final long serialVersionUID = 1L;
public MDepreciationEntry(Properties ctx, int A_Depreciation_Entry_ID, String trxName) {
super(ctx, A_Depreciation_Entry_ID, trxName);
// TODO Auto-generated constructor stub
}
public MDepreciationEntry(Properties ctx, ResultSet rs, String trxName) {
super(ctx, rs, trxName);
// TODO Auto-generated constructor stub
}
@Override
public boolean voidIt() {
/**
* 1.Delete the accounting entry of this document.
* 2.Reactivate the depreciation document and remove the ParentID.
*/
MPeriod.testPeriodOpen(getCtx(), getDateAcct(), getC_DocType_ID(), getAD_Org_ID());
String sql = "delete from fact_acct where ad_table_id = ? and record_id = ?";
DB.executeUpdateEx(sql, new Object[]{MDepreciationEntry.Table_ID,getA_Depreciation_Entry_ID()}, get_TrxName());
return unprocessLines();
}
private boolean unprocessLines()
{
String sql = "UPDATE " + MDepreciationExp.Table_Name + " SET "
+ MDepreciationExp.COLUMNNAME_A_Depreciation_Entry_ID + "=NULL , processed = 'N' "
+ " WHERE "
+ MDepreciationExp.COLUMNNAME_A_Depreciation_Entry_ID + "=?";
int id = get_ID();
if (id <= 0)
{ // Use old ID is current ID is missing (i.e. object was deleted)
id = get_IDOld();
}
int no = DB.executeUpdateEx(sql, new Object[]{id}, get_TrxName());
if (log.isLoggable(Level.FINE)) log.fine("Updated #" + no);
if(no > 0)
return true;
return false;
}
@Override
public int customizeValidActions(String docStatus, Object processing, String orderType, String isSOTrx,
int AD_Table_ID, String[] docAction, String[] options, int index) {
// TODO Auto-generated method stub
if (options == null)
throw new IllegalArgumentException("Option array parameter is null");
if (docAction == null)
throw new IllegalArgumentException("Doc action array parameter is null");
// Approval required .. NA
if (docStatus.equals(DocumentEngine.STATUS_NotApproved))
{
//options[index++] = DocumentEngine.ACTION_Prepare;
options[index++] = DocumentEngine.ACTION_Void;
options[index++] = DocumentEngine.ACTION_Complete;
}
// Draft/Invalid .. DR/IN
else if (docStatus.equals(DocumentEngine.STATUS_Drafted)
|| docStatus.equals(DocumentEngine.STATUS_Invalid))
{
options[index++] = DocumentEngine.ACTION_Complete;
// options[index++] = DocumentEngine.ACTION_Prepare;
options[index++] = DocumentEngine.ACTION_Void;
}
// In Process .. IP
else if (docStatus.equals(DocumentEngine.STATUS_InProgress)
|| docStatus.equals(DocumentEngine.STATUS_Approved))
{
options[index++] = DocumentEngine.ACTION_Complete;
//options[index++] = DocumentEngine.ACTION_Void;
}
// Complete .. CO
else if (docStatus.equals(DocumentEngine.STATUS_Completed))
{
options[index++] = DocumentEngine.ACTION_Void;
docAction[0] = DocumentEngine.ACTION_Void;
}
// Waiting Payment
else if (docStatus.equals(DocumentEngine.STATUS_WaitingPayment)
|| docStatus.equals(DocumentEngine.STATUS_WaitingConfirmation))
{
//options[index++] = DocumentEngine.ACTION_Void;
//options[index++] = DocumentEngine.ACTION_Prepare;
}
// Closed, Voided, REversed .. CL/VO/RE
else if (docStatus.equals(DocumentEngine.STATUS_Closed)
|| docStatus.equals(DocumentEngine.STATUS_Voided)
|| docStatus.equals(DocumentEngine.STATUS_Reversed))
return 0;
return index;
//return 0;
}
}
日本語版
このコードは、経理担当者が操作を取り消すための取消メカニズムを実装しています。これは、ミスが発生し修正が必要な場合に役立ちます。また、ドキュメントの現在のステータスに応じて実行可能な有効なアクションも定義しています。
これは ERP システムにおける減価償却エントリのカスタム実装の Java コードであり、基底クラス MDepreciationEntry を継承し、DocOptions インターフェースを実装しています。
このクラスは voidIt() メソッドをオーバーライドし、ドキュメントの会計エントリを削除し、MDepreciationExp テーブルを更新して ParentID を削除し、「processed」フラグを「N」に設定します。このメソッドは、会計エントリを削除する前に期間が開いているかどうかも確認します。
customizeValidActions() メソッドも実装されており、ドキュメントのステータスに基づいて利用可能な有効なアクションをカスタマイズします。例えば、ドキュメントステータスが「完了」の場合、利用可能な唯一の有効なアクションはドキュメントを無効化することです。
package tw.ninniku.model;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.model.MDepreciationExp;
import org.compiere.model.MPeriod;
import org.compiere.process.DocOptions;
import org.compiere.process.DocumentEngine;
import org.compiere.util.DB;
public class MDepreciationEntry extends org.compiere.model.MDepreciationEntry implements DocOptions {
/**
*
*/
private static final long serialVersionUID = 1L;
public MDepreciationEntry(Properties ctx, int A_Depreciation_Entry_ID, String trxName) {
super(ctx, A_Depreciation_Entry_ID, trxName);
// 自動生成されたコンストラクタ
}
public MDepreciationEntry(Properties ctx, ResultSet rs, String trxName) {
super(ctx, rs, trxName);
// 自動生成されたコンストラクタ
}
@Override
public boolean voidIt() {
/**
* 1.このドキュメントの会計エントリを削除します。
* 2.減価償却ドキュメントを再有効化し、ParentIDを削除します。
*/
MPeriod.testPeriodOpen(getCtx(), getDateAcct(), getC_DocType_ID(), getAD_Org_ID());
String sql = "delete from fact_acct where ad_table_id = ? and record_id = ?";
DB.executeUpdateEx(sql, new Object[]{MDepreciationEntry.Table_ID,getA_Depreciation_Entry_ID()}, get_TrxName());
return unprocessLines();
}
private boolean unprocessLines()
{
String sql = "UPDATE " + MDepreciationExp.Table_Name + " SET "
+ MDepreciationExp.COLUMNNAME_A_Depreciation_Entry_ID + "=NULL , processed = 'N' "
+ " WHERE "
+ MDepreciationExp.COLUMNNAME_A_Depreciation_Entry_ID + "=?";
int id = get_ID();
if (id <= 0)
{ // 現在のIDが欠落している場合は古いIDを使用
id = get_IDOld();
}
int no = DB.executeUpdateEx(sql, new Object[]{id}, get_TrxName());
if (log.isLoggable(Level.FINE)) log.fine("Updated #" + no);
if(no > 0)
return true;
return false;
}
@Override
public int customizeValidActions(String docStatus, Object processing, String orderType, String isSOTrx,
int AD_Table_ID, String[] docAction, String[] options, int index) {
if (options == null)
throw new IllegalArgumentException("Option array parameter is null");
if (docAction == null)
throw new IllegalArgumentException("Doc action array parameter is null");
// 承認が必要 .. NA
if (docStatus.equals(DocumentEngine.STATUS_NotApproved))
{
options[index++] = DocumentEngine.ACTION_Void;
options[index++] = DocumentEngine.ACTION_Complete;
}
// 下書き/無効 .. DR/IN
else if (docStatus.equals(DocumentEngine.STATUS_Drafted)
|| docStatus.equals(DocumentEngine.STATUS_Invalid))
{
options[index++] = DocumentEngine.ACTION_Complete;
options[index++] = DocumentEngine.ACTION_Void;
}
// 処理中 .. IP
else if (docStatus.equals(DocumentEngine.STATUS_InProgress)
|| docStatus.equals(DocumentEngine.STATUS_Approved))
{
options[index++] = DocumentEngine.ACTION_Complete;
}
// 完了 .. CO
else if (docStatus.equals(DocumentEngine.STATUS_Completed))
{
options[index++] = DocumentEngine.ACTION_Void;
docAction[0] = DocumentEngine.ACTION_Void;
}
// 支払待ち
else if (docStatus.equals(DocumentEngine.STATUS_WaitingPayment)
|| docStatus.equals(DocumentEngine.STATUS_WaitingConfirmation))
{
}
// クローズ、無効化、反転 .. CL/VO/RE
else if (docStatus.equals(DocumentEngine.STATUS_Closed)
|| docStatus.equals(DocumentEngine.STATUS_Voided)
|| docStatus.equals(DocumentEngine.STATUS_Reversed))
return 0;
return index;
}
}
