📄 maccount.java
字号:
* Parent Constructor
* @param as account schema
*/
public MAccount (MAcctSchema as)
{
this (as.getCtx(), 0, as.get_TrxName());
setClientOrg(as);
setC_AcctSchema_ID(as.getC_AcctSchema_ID());
} // Account
/** Account Segment */
private MElementValue m_accountEV = null;
/**************************************************************************
* Return String representation
* @return String
*/
public String toString()
{
StringBuffer sb = new StringBuffer("MAccount=[");
sb.append(getC_ValidCombination_ID());
if (getCombination() != null)
sb.append(",")
.append(getCombination());
else
{
// .append(",Client=").append(getAD_Client_ID())
sb.append(",Schema=").append(getC_AcctSchema_ID())
.append(",Org=").append(getAD_Org_ID())
.append(",Acct=").append(getAccount_ID())
.append(" ");
if (getC_SubAcct_ID() != 0)
sb.append(",C_SubAcct_ID=").append(getC_SubAcct_ID());
if (getM_Product_ID() != 0)
sb.append(",M_Product_ID=").append(getM_Product_ID());
if (getC_BPartner_ID() != 0)
sb.append(",C_BPartner_ID=").append(getC_BPartner_ID());
if (getAD_OrgTrx_ID() != 0)
sb.append(",AD_OrgTrx_ID=").append(getAD_OrgTrx_ID());
if (getC_LocFrom_ID() != 0)
sb.append(",C_LocFrom_ID=").append(getC_LocFrom_ID());
if (getC_LocTo_ID() != 0)
sb.append(",C_LocTo_ID=").append(getC_LocTo_ID());
if (getC_SalesRegion_ID() != 0)
sb.append(",C_SalesRegion_ID=").append(getC_SalesRegion_ID());
if (getC_Project_ID() != 0)
sb.append(",C_Project_ID=").append(getC_Project_ID());
if (getC_Campaign_ID() != 0)
sb.append(",C_Campaign_ID=").append(getC_Campaign_ID());
if (getC_Activity_ID() != 0)
sb.append(",C_Activity_ID=").append(getC_Activity_ID());
if (getUser1_ID() != 0)
sb.append(",User1_ID=").append(getUser1_ID());
if (getUser2_ID() != 0)
sb.append(",User2_ID=").append(getUser2_ID());
if (getUserElement1_ID() != 0)
sb.append(",UserElement1_ID=").append(getUserElement1_ID());
if (getUserElement2_ID() != 0)
sb.append(",UserElement2_ID=").append(getUserElement2_ID());
}
sb.append("]");
return sb.toString();
} // toString
/**
* Set Account_ID
*/
public void setAccount_ID (int Account_ID)
{
m_accountEV = null; // reset
super.setAccount_ID(Account_ID);
} // setAccount
/**
* Set Account_ID
*/
public MElementValue getAccount ()
{
if (m_accountEV == null)
{
if (getAccount_ID() != 0)
m_accountEV = new MElementValue(getCtx(), getAccount_ID(), get_TrxName());
}
return m_accountEV;
} // setAccount
/**
* Get Account Type
* @return Account Type of Account Element
*/
public String getAccountType()
{
if (m_accountEV == null)
getAccount();
if (m_accountEV == null)
{
log.log(Level.SEVERE, "No ElementValue for Account_ID=" + getAccount_ID());
return "";
}
return m_accountEV.getAccountType();
} // getAccountType
/**
* Is this a Balance Sheet Account
* @return boolean
*/
public boolean isBalanceSheet()
{
String accountType = getAccountType();
return (MElementValue.ACCOUNTTYPE_Asset.equals(accountType)
|| MElementValue.ACCOUNTTYPE_Liability.equals(accountType)
|| MElementValue.ACCOUNTTYPE_OwnerSEquity.equals(accountType));
} // isBalanceSheet
/**
* Is this an Activa Account
* @return boolean
*/
public boolean isActiva()
{
return MElementValue.ACCOUNTTYPE_Asset.equals(getAccountType());
} // isActive
/**
* Is this a Passiva Account
* @return boolean
*/
public boolean isPassiva()
{
String accountType = getAccountType();
return (MElementValue.ACCOUNTTYPE_Liability.equals(accountType)
|| MElementValue.ACCOUNTTYPE_OwnerSEquity.equals(accountType));
} // isPassiva
/**
* Set Value and Description and Fully Qualified Flag for Combination
*/
public void setValueDescription()
{
StringBuffer combi = new StringBuffer();
StringBuffer descr = new StringBuffer();
boolean fullyQualified = true;
//
MAcctSchema as = new MAcctSchema(getCtx(), getC_AcctSchema_ID(), get_TrxName()); // In Trx!
MAcctSchemaElement[] elements = MAcctSchemaElement.getAcctSchemaElements(as);
for (int i = 0; i < elements.length; i++)
{
if (i > 0)
{
combi.append(as.getSeparator());
descr.append(as.getSeparator());
}
MAcctSchemaElement element = elements[i];
String combiStr = "_"; // not defined
String descrStr = "_";
if (MAcctSchemaElement.ELEMENTTYPE_Organization.equals(element.getElementType()))
{
if (getAD_Org_ID() != 0)
{
MOrg org = new MOrg(getCtx(), getAD_Org_ID(), get_TrxName()); // in Trx!
combiStr = org.getValue();
descrStr = org.getName();
}
else
{
combiStr = "*";
descrStr = "*";
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_Account.equals(element.getElementType()))
{
if (getAccount_ID() != 0)
{
if (m_accountEV == null)
m_accountEV = new MElementValue(getCtx(), getAccount_ID(), get_TrxName());
combiStr = m_accountEV.getValue();
descrStr = m_accountEV.getName();
}
else if (element.isMandatory())
{
log.warning("Mandatory Element missing: Account");
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_SubAccount.equals(element.getElementType()))
{
if (getC_SubAcct_ID() != 0)
{
X_C_SubAcct sa = new X_C_SubAcct(getCtx(), getC_SubAcct_ID(), get_TrxName());
combiStr = sa.getValue();
descrStr = sa.getName();
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_Product.equals(element.getElementType()))
{
if (getM_Product_ID() != 0)
{
X_M_Product product = new X_M_Product (getCtx(), getM_Product_ID(), get_TrxName());
combiStr = product.getValue();
descrStr = product.getName();
}
else if (element.isMandatory())
{
log.warning("Mandatory Element missing: Product");
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_BPartner.equals(element.getElementType()))
{
if (getC_BPartner_ID() != 0)
{
X_C_BPartner partner = new X_C_BPartner (getCtx(), getC_BPartner_ID(),get_TrxName());
combiStr = partner.getValue();
descrStr = partner.getName();
}
else if (element.isMandatory())
{
log.warning("Mandatory Element missing: Business Partner");
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_OrgTrx.equals(element.getElementType()))
{
if (getAD_OrgTrx_ID() != 0)
{
MOrg org = new MOrg(getCtx(), getAD_OrgTrx_ID(), get_TrxName()); // in Trx!
combiStr = org.getValue();
descrStr = org.getName();
}
else if (element.isMandatory())
{
log.warning("Mandatory Element missing: Trx Org");
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_LocationFrom.equals(element.getElementType()))
{
if (getC_LocFrom_ID() != 0)
{
MLocation loc = new MLocation(getCtx(), getC_LocFrom_ID(), get_TrxName()); // in Trx!
combiStr = loc.getPostal();
descrStr = loc.getCity();
}
else if (element.isMandatory())
{
log.warning("Mandatory Element missing: Location From");
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_LocationTo.equals(element.getElementType()))
{
if (getC_LocTo_ID() != 0)
{
MLocation loc = new MLocation(getCtx(), getC_LocFrom_ID(), get_TrxName()); // in Trx!
combiStr = loc.getPostal();
descrStr = loc.getCity();
}
else if (element.isMandatory())
{
log.warning("Mandatory Element missing: Location To");
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_SalesRegion.equals(element.getElementType()))
{
if (getC_SalesRegion_ID() != 0)
{
MSalesRegion loc = new MSalesRegion(getCtx(), getC_SalesRegion_ID(), get_TrxName());
combiStr = loc.getValue();
descrStr = loc.getName();
}
else if (element.isMandatory())
{
log.warning("Mandatory Element missing: SalesRegion");
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_Project.equals(element.getElementType()))
{
if (getC_Project_ID() != 0)
{
X_C_Project project = new X_C_Project (getCtx(), getC_Project_ID(), get_TrxName());
combiStr = project.getValue();
descrStr = project.getName();
}
else if (element.isMandatory())
{
log.warning("Mandatory Element missing: Project");
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_Campaign.equals(element.getElementType()))
{
if (getC_Campaign_ID() != 0)
{
X_C_Campaign campaign = new X_C_Campaign (getCtx(), getC_Campaign_ID(), get_TrxName());
combiStr = campaign.getValue();
descrStr = campaign.getName();
}
else if (element.isMandatory())
{
log.warning("Mandatory Element missing: Campaign");
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_Activity.equals(element.getElementType()))
{
if (getC_Activity_ID() != 0)
{
X_C_Activity act = new X_C_Activity (getCtx(), getC_Activity_ID(), get_TrxName());
combiStr = act.getValue();
descrStr = act.getName();
}
else if (element.isMandatory())
{
log.warning("Mandatory Element missing: Campaign");
fullyQualified = false;
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_UserList1.equals(element.getElementType()))
{
if (getUser1_ID() != 0)
{
MElementValue ev = new MElementValue(getCtx(), getUser1_ID(), get_TrxName());
combiStr = ev.getValue();
descrStr = ev.getName();
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_UserList2.equals(element.getElementType()))
{
if (getUser2_ID() != 0)
{
MElementValue ev = new MElementValue(getCtx(), getUser2_ID(), get_TrxName());
combiStr = ev.getValue();
descrStr = ev.getName();
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_UserElement1.equals(element.getElementType()))
{
if (getUserElement1_ID() != 0)
{
}
}
else if (MAcctSchemaElement.ELEMENTTYPE_UserElement2.equals(element.getElementType()))
{
if (getUserElement2_ID() != 0)
{
}
}
combi.append(combiStr);
descr.append(descrStr);
}
// Set Values
super.setCombination(combi.toString());
super.setDescription(descr.toString());
if (fullyQualified != isFullyQualified())
setIsFullyQualified(fullyQualified);
log.fine("Combination=" + getCombination()
+ " - " + getDescription()
+ " - FullyQualified=" + fullyQualified);
} // setValueDescription
/**
* Validate combination
* @return true if valid
*/
public boolean validate()
{
boolean ok = true;
// Validate Sub-Account
if (getC_SubAcct_ID() != 0)
{
X_C_SubAcct sa = new X_C_SubAcct(getCtx(), getC_SubAcct_ID(), get_TrxName());
if (sa.getC_ElementValue_ID() != getAccount_ID())
{
log.saveError("Error", "C_SubAcct.C_ElementValue_ID=" + sa.getC_ElementValue_ID()
+ "<>Account_ID=" + getAccount_ID());
ok = false;
}
}
return ok;
} // validate
/**
* Before Save
* @param newRecord new
* @return true
*/
protected boolean beforeSave (boolean newRecord)
{
setValueDescription();
return validate();
} // beforeSave
/**
* Test
* @param args
*/
public static void main (String[] args)
{
org.compiere.Compiere.startup(true);
MAccount acct = get (Env.getCtx(), 11, 11, 101, 600, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
System.out.println(acct);
MAccount acct2 = get (Env.getCtx(), 11, 12, 101, 600, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
System.out.println(acct2);
} // main
} // Account
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -