} // setC_ValidCombination_ID /// <summary> /// Set C_ValidCombination_ID /// </summary> /// <param name="acct">account</param> public void SetC_ValidCombination_ID(MAccount acct) { if (acct == null) { throw new ArgumentException("Account is null"); } base.SetC_ValidCombination_ID(acct.GetC_ValidCombination_ID()); m_account = acct; m_accountElement = null; } // setC_ValidCombination_ID
} // getAccountElement /// <summary> /// Is it posting to a Control Acct /// </summary> /// <returns> true if control acct</returns> public Boolean IsDocControlled() { MElementValue acct = GetAccountElementValue(); if (acct == null) { log.Warning("Account not found for C_ValidCombination_ID=" + GetC_ValidCombination_ID()); return(false); } return(acct.IsDocControlled()); } // isDocControlled
/// <summary> /// Set Account_ID /// </summary> /// <returns>element value</returns> public MElementValue GetAccount() { if (_accountEV == null) { if (GetAccount_ID() != 0) { _accountEV = new MElementValue(GetCtx(), GetAccount_ID(), Get_TrxName()); } } return(_accountEV); }
} // getValidCombination /// <summary> /// Get Natural Account Element Value /// </summary> /// <returns> account</returns> public MElementValue GetAccountElementValue() { if (m_accountElement == null) { MAccount vc = GetAccount(); if (vc != null && vc.GetAccount_ID() != 0) { m_accountElement = new MElementValue(GetCtx(), vc.GetAccount_ID(), Get_TrxName()); } } return(m_accountElement); } // getAccountElement
} // saveAccounts public int GetC_ElementValue_ID(String key) { MElementValue na = null; if (s_base.ContainsKey(key)) { na = (MElementValue)s_base[key]; } if (na == null) { return(0); } return(na.GetC_ElementValue_ID()); } // getC_ElementValue_ID
public bool SaveAccounts(int AD_Client_ID, int AD_Org_ID, int C_Element_ID) { log.Config(""); foreach (string key in s_base.Keys) { MElementValue na = (MElementValue)s_base[key]; na.SetAD_Client_ID(AD_Client_ID); na.SetAD_Org_ID(AD_Org_ID); na.SetC_Element_ID(C_Element_ID); na.SetVIS_DefaultAccount(key); if (!na.Save()) { return(false); } } return(true); } // saveAccounts
} // parse public String ParseAndSaveLine(String line, int AD_Client_ID, int AD_Org_ID, int C_Element_ID, MTree tree) { log.Config(line); // Fields with ',' are enclosed in " StringBuilder newLine = new StringBuilder(); StringTokenizer st = new StringTokenizer(line, "\"", false); newLine.Append(st.NextToken()); // first part while (st.HasMoreElements()) { String s = st.NextToken(); // enclosed part newLine.Append(s.Replace(',', ' ')); // remove ',' with space if (st.HasMoreTokens()) { newLine.Append(st.NextToken()); // unenclosed } } // add space at the end - tokenizer does not count empty fields newLine.Append(" "); // Parse Line - replace ",," with ", ," - tokenizer does not count empty fields String pLine = Utility.Util.Replace(newLine.ToString(), ",,", ", ,"); pLine = Utility.Util.Replace(pLine, ",,", ", ,"); st = new StringTokenizer(pLine, ",", false); // All fields there ? if (st.CountTokens() == 1) { log.Log(Level.SEVERE, "Ignored: Require ',' as separator - " + pLine); return(""); } if (st.CountTokens() < 9) { log.Log(Level.SEVERE, "Ignored: FieldNumber wrong: " + st.CountTokens() + " - " + pLine); return(""); } // Fill variables String Value = null, Name = null, Description = null, AccountType = null, AccountSign = null, IsDocControlled = null, IsSummary = null, Default_Account = null; int accountParent = -1; // for (int i = 0; i < 9 && st.HasMoreTokens(); i++) { String s = st.NextToken().Trim(); // Ignore, if is it header line if (s.StartsWith("[") && s.EndsWith("]")) { return(""); } if (s == null) { s = ""; } // if (i == 0) // A - Value { Value = s; } else if (i == 1) // B - Name { Name = s; } else if (i == 2) // C - Description { Description = s; } else if (i == 3) // D - Type { AccountType = s.Length > 0 ? s[0].ToString() : "E"; } else if (i == 4) // E - Sign { AccountSign = s.Length > 0 ? s[0].ToString() : "N"; } else if (i == 5) // F - DocControlled { IsDocControlled = s.Length > 0 ? s[0].ToString() : "N"; } else if (i == 6) // G - IsSummary { IsSummary = s.Length > 0 ? s[0].ToString() : "N"; } else if (i == 7) // H - Default_Account { Default_Account = s; } else if (i == 8) { accountParent = Util.GetValueOfInt(s); } } // Ignore if Value & Name are empty (no error message) if ((Value == null || Value.Length == 0) && (Name == null || Name.Length == 0)) { return(""); } //////////////////// //Commented By Lakhwinder //// Default Account may be blank //if (Default_Account == null || Default_Account.Length == 0) // // Default_Account = String.valueOf(s_keyNo++); // return ""; //// No Summary Account //if (IsSummary == null || IsSummary.Length == 0) // IsSummary = "N"; //if (!IsSummary.Equals("N")) // return ""; //// Validation //if (AccountType == null || AccountType.Length == 0) // AccountType = "E"; //if (AccountSign == null || AccountSign.Length == 0) // AccountSign = "N"; //if (IsDocControlled == null || IsDocControlled.Length == 0) // IsDocControlled = "N"; ////////////////////// // log.config( "Value=" + Value + ", AcctType=" + AccountType // + ", Sign=" + AccountSign + ", Doc=" + docControlled // + ", Summary=" + summary + " - " + Name + " - " + Description); try { // Try to find - allows to use same natutal account for multiple default accounts MElementValue na = null; if (m_valueMap.ContainsKey(Value)) { na = (MElementValue)m_valueMap[Value]; } if (na == null) { // Create Account - save later na = new MElementValue(m_ctx, Value, Name, Description, AccountType, AccountSign, IsDocControlled.ToUpper().StartsWith("Y"), IsSummary.ToUpper().StartsWith("Y"), m_trx); int refElementID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT C_ElementValue_ID FROM C_ElementValue WHERE IsActive='Y' AND AD_Client_ID=" + na.GetAD_Client_ID() + " AND Value='" + accountParent + @"' AND C_Element_ID=" + C_Element_ID, null, m_trx)); na.SetRef_C_ElementValue_ID(refElementID); m_valueMap[Value] = na; na.SetAD_Client_ID(AD_Client_ID); na.SetAD_Org_ID(AD_Org_ID); na.SetC_Element_ID(C_Element_ID); na.SetVIS_DefaultAccount(Default_Account); if (!na.Save(m_trx)) { return("Acct Element Values NOT inserted"); //m_info.Append(Msg.Translate(m_lang, "C_ElementValue_ID")).Append(" # ").Append(m_nap.Count).Append("\n"); } VAdvantage.Model.MTreeNode mNode = VAdvantage.Model.MTreeNode.Get(tree, na.Get_ID()); if (mNode == null) { mNode = new VAdvantage.Model.MTreeNode(tree, na.Get_ID()); } ((VAdvantage.Model.PO)mNode).Set_Value("Parent_ID", refElementID); if (!mNode.Save(m_trx)) { return("Acct Element Values NOT inserted"); } } if (!(Default_Account == null || Default_Account.Length == 0)) { // Add to Cache s_base.Add(Default_Account.ToUpper(), na); } } catch (Exception e) { return(e.Message); } return(""); } //
/// <summary> /// Create Account Entry for Default Accounts only. /// </summary> /// <param name="line">line with info /// <para> /// Line format (9 fields) /// 1 A [Account Value] /// 2 B [Account Name] /// 3 C [Description] /// 4 D [Account Type] /// 5 E [Account Sign] /// 6 F [Document Controlled] /// 7 G [Summary Account] /// 8 H [Default_Account] /// 9 I [Parent Value] - ignored /// </para> /// </param> /// <returns>error message or "" if OK</returns> public String ParseLine(String line) { log.Config(line); // Fields with ',' are enclosed in " StringBuilder newLine = new StringBuilder(); StringTokenizer st = new StringTokenizer(line, "\"", false); newLine.Append(st.NextToken()); // first part while (st.HasMoreElements()) { String s = st.NextToken(); // enclosed part newLine.Append(s.Replace(',', ' ')); // remove ',' with space if (st.HasMoreTokens()) { newLine.Append(st.NextToken()); // unenclosed } } // add space at the end - tokenizer does not count empty fields newLine.Append(" "); // Parse Line - replace ",," with ", ," - tokenizer does not count empty fields String pLine = Utility.Util.Replace(newLine.ToString(), ",,", ", ,"); pLine = Utility.Util.Replace(pLine, ",,", ", ,"); st = new StringTokenizer(pLine, ",", false); // All fields there ? if (st.CountTokens() == 1) { log.Log(Level.SEVERE, "Ignored: Require ',' as separator - " + pLine); return(""); } if (st.CountTokens() < 9) { log.Log(Level.SEVERE, "Ignored: FieldNumber wrong: " + st.CountTokens() + " - " + pLine); return(""); } // Fill variables String Value = null, Name = null, Description = null, AccountType = null, AccountSign = null, IsDocControlled = null, IsSummary = null, Default_Account = null; // for (int i = 0; i < 8 && st.HasMoreTokens(); i++) { String s = st.NextToken().Trim(); // Ignore, if is it header line if (s.StartsWith("[") && s.EndsWith("]")) { return(""); } if (s == null) { s = ""; } // if (i == 0) // A - Value { Value = s; } else if (i == 1) // B - Name { Name = s; } else if (i == 2) // C - Description { Description = s; } else if (i == 3) // D - Type { AccountType = s.Length > 0 ? s[0].ToString() : "E"; } else if (i == 4) // E - Sign { AccountSign = s.Length > 0 ? s[0].ToString() : "N"; } else if (i == 5) // F - DocControlled { IsDocControlled = s.Length > 0 ? s[0].ToString() : "N"; } else if (i == 6) // G - IsSummary { IsSummary = s.Length > 0 ? s[0].ToString() : "N"; } else if (i == 7) // H - Default_Account { Default_Account = s; } } // Ignore if Value & Name are empty (no error message) if ((Value == null || Value.Length == 0) && (Name == null || Name.Length == 0)) { return(""); } // Default Account may be blank if (Default_Account == null || Default_Account.Length == 0) { // Default_Account = String.valueOf(s_keyNo++); return(""); } // No Summary Account if (IsSummary == null || IsSummary.Length == 0) { IsSummary = "N"; } if (!IsSummary.Equals("N")) { return(""); } // Validation if (AccountType == null || AccountType.Length == 0) { AccountType = "E"; } if (AccountSign == null || AccountSign.Length == 0) { AccountSign = "N"; } if (IsDocControlled == null || IsDocControlled.Length == 0) { IsDocControlled = "N"; } // log.config( "Value=" + Value + ", AcctType=" + AccountType // + ", Sign=" + AccountSign + ", Doc=" + docControlled // + ", Summary=" + summary + " - " + Name + " - " + Description); try { // Try to find - allows to use same natutal account for multiple default accounts MElementValue na = null; if (m_valueMap.ContainsKey(Value)) { na = (MElementValue)m_valueMap[Value]; } if (na == null) { // Create Account - save later na = new MElementValue(m_ctx, Value, Name, Description, AccountType, AccountSign, IsDocControlled.ToUpper().StartsWith("Y"), IsSummary.ToUpper().StartsWith("Y"), m_trx); m_valueMap[Value] = na; } // Add to Cache s_base.Add(Default_Account.ToUpper(), na); } catch (Exception e) { return(e.Message); } return(""); } // parseLine
} // setAmt /// <summary> /// Set C_ValidCombination_ID /// </summary> /// <param name="C_ValidCombination_ID">id</param> public new void SetC_ValidCombination_ID(int C_ValidCombination_ID) { base.SetC_ValidCombination_ID(C_ValidCombination_ID); m_account = null; m_accountElement = null; } // setC_ValidCombination_ID
/// <summary> /// Set Value and Description and Fully Qualified Flag for Combination /// </summary> public void SetValueDescription() { StringBuilder combi = new StringBuilder(); StringBuilder descr = new StringBuilder(); bool fullyQualified = true; // MAcctSchema as1 = new MAcctSchema(GetCtx(), GetC_AcctSchema_ID(), Get_TrxName()); // In Trx! MAcctSchemaElement[] elements = MAcctSchemaElement.GetAcctSchemaElements(as1); for (int i = 0; i < elements.Length; i++) { if (i > 0) { combi.Append(as1.GetSeparator()); descr.Append(as1.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 (_accountEV == null) { _accountEV = new MElementValue(GetCtx(), GetAccount_ID(), Get_TrxName()); } combiStr = _accountEV.GetValue(); descrStr = _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 base.SetCombination(combi.ToString()); base.SetDescription(descr.ToString()); if (fullyQualified != IsFullyQualified()) { SetIsFullyQualified(fullyQualified); _log.Fine("Combination=" + GetCombination() + " - " + GetDescription() + " - FullyQualified=" + fullyQualified); } }
/// <summary> /// Set Account_ID /// </summary> /// <param name="Account_ID">id</param> public new void SetAccount_ID(int Account_ID) { _accountEV = null; // reset base.SetAccount_ID(Account_ID); }