/// <summary> /// After Save /// </summary> /// <param name="newRecord">new Record</param> /// <param name="success">save success</param> /// <returns>success</returns> protected override bool AfterSave(bool newRecord, bool success) { if (!success) { return(success); } if (newRecord) { // Info info = new MOrgInfo(this); info.Save(); // Access MRoleOrgAccess.CreateForOrg(this); MRole.GetDefault(GetCtx(), true); // reload } // Value/Name change if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name"))) { MAccount.UpdateValueDescription(GetCtx(), "AD_Org_ID=" + GetAD_Org_ID(), Get_Trx()); if ("Y".Equals(GetCtx().GetContext("$Element_OT"))) { MAccount.UpdateValueDescription(GetCtx(), "AD_OrgTrx_ID=" + GetAD_Org_ID(), Get_Trx()); } } return(true); }
/** * After Save * @param newRecord new * @param success success * @return success */ protected override bool AfterSave(bool newRecord, bool success) { if (newRecord & success) { Insert_Accounting("C_Project_Acct", "C_AcctSchema_Default", null); } // Value/Name change MProject prjph = null; if (success && !newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name"))) { MAccount.UpdateValueDescription(GetCtx(), "C_Project_ID=" + GetC_Project_ID(), Get_TrxName()); } if (GetC_Campaign_ID() != 0) { MCampaign cam = new MCampaign(GetCtx(), GetC_Campaign_ID(), null); decimal plnAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0) FROM C_Project pl WHERE pl.IsActive = 'Y' AND pl.C_Campaign_ID = " + GetC_Campaign_ID())); cam.SetCosts(plnAmt); cam.Save(); } else { prjph = new MProject(GetCtx(), GetC_Project_ID(), Get_Trx()); decimal plnAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(PlannedAmt),0) FROM C_ProjectPhase WHERE IsActive= 'Y' AND C_Project_ID= " + GetC_Project_ID())); DB.ExecuteQuery("UPDATE C_Project SET PlannedAmt=" + plnAmt + " WHERE C_Project_ID=" + GetC_Project_ID(), null, Get_Trx()); } return(success); }
} // setAccount /// <summary> /// Get Account Combination based on Account and Overwrite /// </summary> /// <returns>account</returns> public MAccount GetAccount() { MAccount acct = MAccount.Get(GetCtx(), _account.GetAD_Client_ID(), IsOverwriteOrg() && GetOrg_ID() != 0 ? GetOrg_ID() : _account.GetAD_Org_ID(), _account.GetC_AcctSchema_ID(), IsOverwriteAcct() && GetAccount_ID() != 0 ? GetAccount_ID() : _account.GetAccount_ID(), _account.GetC_SubAcct_ID(), // IsOverwriteProduct() ? GetM_Product_ID() : _account.GetM_Product_ID(), IsOverwriteBPartner() ? GetC_BPartner_ID() : _account.GetC_BPartner_ID(), IsOverwriteOrgTrx() ? GetAD_OrgTrx_ID() : _account.GetAD_OrgTrx_ID(), IsOverwriteLocFrom() ? GetC_LocFrom_ID() : _account.GetC_LocFrom_ID(), IsOverwriteLocTo() ? GetC_LocTo_ID() : _account.GetC_LocTo_ID(), IsOverwriteSalesRegion() ? GetC_SalesRegion_ID() : _account.GetC_SalesRegion_ID(), IsOverwriteProject() ? GetC_Project_ID() : _account.GetC_Project_ID(), IsOverwriteCampaign() ? GetC_Campaign_ID() : _account.GetC_Campaign_ID(), IsOverwriteActivity() ? GetC_Activity_ID() : _account.GetC_Activity_ID(), IsOverwriteUser1() ? GetUser1_ID() : _account.GetUser1_ID(), IsOverwriteUser2() ? GetUser2_ID() : _account.GetUser2_ID(), _account.GetUserElement1_ID(), _account.GetUserElement2_ID()); return(acct); } // setAccount
/// <summary> /// After Save /// </summary> /// <param name="newRecord">new</param> /// <param name="success">success</param> /// <returns>success</returns> protected override bool AfterSave(bool newRecord, bool success) { // Default Value if (IsMandatory() && Is_ValueChanged("IsMandatory")) { if (ELEMENTTYPE_Activity.Equals(GetElementType())) { UpdateData("C_Activity_ID", GetC_Activity_ID()); } else if (ELEMENTTYPE_BPartner.Equals(GetElementType())) { UpdateData("C_BPartner_ID", GetC_BPartner_ID()); } else if (ELEMENTTYPE_Product.Equals(GetElementType())) { UpdateData("M_Product_ID", GetM_Product_ID()); } else if (ELEMENTTYPE_Project.Equals(GetElementType())) { UpdateData("C_Project_ID", GetC_Project_ID()); } } // Resequence if (newRecord || Is_ValueChanged("SeqNo")) { MAccount.UpdateValueDescription(GetCtx(), "AD_Client_ID=" + GetAD_Client_ID(), Get_TrxName()); } // Clear Cache s_cache.Clear(); return(success); }
/// <summary> /// After Delete /// </summary> /// <param name="success">success</param> /// <returns>success</returns> protected override bool AfterDelete(bool success) { // Update Account Info MAccount.UpdateValueDescription(GetCtx(), "AD_Client_ID=" + GetAD_Client_ID(), Get_TrxName()); // s_cache.Clear(); return(success); }
} // setC_ValidCombination_ID /// <summary> /// Get Account (Valid Combination) /// </summary> /// <returns> combination or null</returns> public MAccount GetAccount() { if (m_account == null && GetC_ValidCombination_ID() != 0) { m_account = new MAccount(GetCtx(), GetC_ValidCombination_ID(), Get_TrxName()); } return(m_account); } // getValidCombination
} // 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
/// <summary> /// Get Distribution for combination /// </summary> /// <param name="acct">account (ValidCombination)</param> /// <param name="PostingType">only posting type</param> /// <param name="C_DocType_ID">only document type</param> /// <returns>array of distributions</returns> public static MDistribution[] Get(MAccount acct, String PostingType, int C_DocType_ID) { return(Get(acct.GetCtx(), acct.GetC_AcctSchema_ID(), PostingType, C_DocType_ID, acct.GetAD_Org_ID(), acct.GetAccount_ID(), acct.GetM_Product_ID(), acct.GetC_BPartner_ID(), acct.GetC_Project_ID(), acct.GetC_Campaign_ID(), acct.GetC_Activity_ID(), acct.GetAD_OrgTrx_ID(), acct.GetC_SalesRegion_ID(), acct.GetC_LocTo_ID(), acct.GetC_LocFrom_ID(), acct.GetUser1_ID(), acct.GetUser2_ID())); } // get
} // 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
/// <summary> /// Get from existing Accounting fact /// </summary> /// <param name="fa">accounting fact</param> /// <returns>account</returns> public static MAccount Get(X_Fact_Acct fa) { MAccount acct = Get(fa.GetCtx(), fa.GetAD_Client_ID(), fa.GetAD_Org_ID(), fa.GetC_AcctSchema_ID(), fa.GetAccount_ID(), fa.GetC_SubAcct_ID(), fa.GetM_Product_ID(), fa.GetC_BPartner_ID(), fa.GetAD_OrgTrx_ID(), fa.GetC_LocFrom_ID(), fa.GetC_LocTo_ID(), fa.GetC_SalesRegion_ID(), fa.GetC_Project_ID(), fa.GetC_Campaign_ID(), fa.GetC_Activity_ID(), fa.GetUser1_ID(), fa.GetUser2_ID(), fa.GetUserElement1_ID(), fa.GetUserElement2_ID()); return(acct); }
} // MActivity /// <summary> /// After Save.Insert - create tree /// </summary> /// <param name="newRecord">insert</param> /// <param name="success">save success</param> /// <returns>true if saved</returns> protected override Boolean AfterSave(Boolean newRecord, Boolean success) { if (!success) { return(success); } // Value/Name change if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name"))) { MAccount.UpdateValueDescription(GetCtx(), "C_Activity_ID=" + GetC_Activity_ID(), Get_TrxName()); } return(true); } // afterSave
/// <summary> /// After Save. /// Insert /// - create tree /// </summary> /// <param name="newRecord">insert</param> /// <param name="success">success</param> /// <returns>success</returns> protected override bool AfterSave(bool newRecord, bool success) { if (!success) { return(success); } // Value/Name change if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name"))) { MAccount.UpdateValueDescription(GetCtx(), "C_SalesRegion_ID=" + GetC_SalesRegion_ID(), Get_TrxName()); } return(true); }
/// <summary> /// gain /// </summary> /// <param name="segment"></param> /// <returns></returns> public MAccount GetDueFrom_Acct(String segment) { if (_DueFrom_Acct != null) { return(_DueFrom_Acct); } if (_gl == null) { GetAcctSchemaGL(); } int C_ValidCombination_ID = _gl.GetIntercompanyDueFrom_Acct(); _DueFrom_Acct = MAccount.Get(GetCtx(), C_ValidCombination_ID); return(_DueFrom_Acct); }
/** * Derive MAccount from record * @return Valid Account Combination */ public MAccount GetMAccount() { MAccount acct = MAccount.Get(GetCtx(), GetAD_Client_ID(), GetAD_Org_ID(), GetC_AcctSchema_ID(), GetAccount_ID(), GetC_SubAcct_ID(), GetM_Product_ID(), GetC_BPartner_ID(), GetAD_OrgTrx_ID(), GetC_LocFrom_ID(), GetC_LocTo_ID(), GetC_SalesRegion_ID(), GetC_Project_ID(), GetC_Campaign_ID(), GetC_Activity_ID(), GetUser1_ID(), GetUser2_ID(), GetUserElement1_ID(), GetUserElement2_ID()); if (acct != null && acct.Get_ID() == 0) { acct.Save(); } return(acct); }
/// <summary> /// Get Currency Balancing Account /// </summary> /// <returns>currency balancing account</returns> public MAccount GetCurrencyBalancing_Acct() { if (_CurrencyBalancing_Acct != null) { return(_CurrencyBalancing_Acct); } if (_gl == null) { GetAcctSchemaGL(); } int C_ValidCombination_ID = _gl.GetCurrencyBalancing_Acct(); _CurrencyBalancing_Acct = MAccount.Get(GetCtx(), C_ValidCombination_ID); return(_CurrencyBalancing_Acct); }
/// <summary> /// Get Suspense Error Account /// </summary> /// <returns>suspense error account</returns> public MAccount GetSuspenseBalancing_Acct() { if (_SuspenseError_Acct != null) { return(_SuspenseError_Acct); } if (_gl == null) { GetAcctSchemaGL(); } int C_ValidCombination_ID = _gl.GetSuspenseBalancing_Acct(); _SuspenseError_Acct = MAccount.Get(GetCtx(), C_ValidCombination_ID); return(_SuspenseError_Acct); }
/** * After Save * @param newRecord new * @param success success * @return success */ protected override bool AfterSave(bool newRecord, bool success) { // Value/Name change in Account if (!newRecord && ("Y".Equals(GetCtx().GetContext("$Element_LF")) || "Y".Equals(GetCtx().GetContext("$Element_LT"))) && (Is_ValueChanged("Postal") || Is_ValueChanged("City")) ) { MAccount.UpdateValueDescription(GetCtx(), "(C_LocFrom_ID=" + GetC_Location_ID() + " OR C_LocTo_ID=" + GetC_Location_ID() + ")", Get_TrxName()); } return(success); }
/// <summary> /// Update ValidCombination and Fact with mandatory value /// </summary> /// <param name="element">element</param> /// <param name="id">new default</param> private void UpdateData(String element, int id) { MAccount.UpdateValueDescription(GetCtx(), element + "=" + id, Get_TrxName()); // String sql = "UPDATE C_ValidCombination SET " + element + "=" + id + " WHERE " + element + " IS NULL AND AD_Client_ID=" + GetAD_Client_ID(); int noC = Convert.ToInt32(DataBase.DB.ExecuteQuery(sql, null, Get_TrxName())); // sql = "UPDATE Fact_Acct SET " + element + "=" + id + " WHERE " + element + " IS NULL AND C_AcctSchema_ID=" + GetC_AcctSchema_ID(); int noF = Convert.ToInt32(DataBase.DB.ExecuteQuery(sql, null, Get_TrxName())); // log.Fine("ValidCombination=" + noC + ", Fact=" + noF); }
/// <summary> /// After Save /// </summary> /// <param name="newRecord">new</param> /// <param name="success">success</param> /// <returns>success</returns> protected override bool AfterSave(bool newRecord, bool success) { // Value/Name change if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name"))) { MAccount.UpdateValueDescription(GetCtx(), "Account_ID=" + GetC_ElementValue_ID(), Get_TrxName()); if ("Y".Equals(GetCtx().GetContext("$Element_U1"))) { MAccount.UpdateValueDescription(GetCtx(), "User1_ID=" + GetC_ElementValue_ID(), Get_TrxName()); } if ("Y".Equals(GetCtx().GetContext("$Element_U2"))) { MAccount.UpdateValueDescription(GetCtx(), "User2_ID=" + GetC_ElementValue_ID(), Get_TrxName()); } } return(success); }
/// <summary> /// loass /// </summary> /// <param name="segment"></param> /// <returns></returns> public MAccount GetFRPT_RealizedLoss_Acct() { if (_realizedLoss_Acct != null) { return(_realizedLoss_Acct); } if (_gl == null) { GetAcctSchemaGL(); } int C_ValidCombination_ID = _gl.GetFRPT_RealizedLoss_Acct(); if (C_ValidCombination_ID > 0) { _realizedLoss_Acct = MAccount.Get(GetCtx(), C_ValidCombination_ID); } return(_realizedLoss_Acct); }
/// <summary> /// After Save /// </summary> /// <param name="newRecord">new Record</param> /// <param name="success">save success</param> /// <returns>success</returns> protected override bool AfterSave(bool newRecord, bool success) { if (!success) { return(success); } if (newRecord) { // Info info = new MOrgInfo(this); info.Save(); // Access MRoleOrgAccess.CreateForOrg(this); MRole.GetDefault(GetCtx(), true); // reload } // Value/Name change if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name"))) { MAccount.UpdateValueDescription(GetCtx(), "AD_Org_ID=" + GetAD_Org_ID(), Get_Trx()); if ("Y".Equals(GetCtx().GetContext("$Element_OT"))) { MAccount.UpdateValueDescription(GetCtx(), "AD_OrgTrx_ID=" + GetAD_Org_ID(), Get_Trx()); } } if (!newRecord) { if (!IsSummary()) { int orgTableID = MTable.Get_Table_ID("AD_Org"); string sql = "SELECT AD_Tree_ID FROM AD_Tree " + "WHERE AD_Client_ID=" + GetCtx().GetAD_Client_ID() + " AND AD_Table_ID=" + orgTableID + " AND IsActive='Y' AND IsAllNodes='Y' " + "ORDER BY IsDefault DESC, AD_Tree_ID"; object AD_Tree_ID = DB.ExecuteScalar(sql, null, null); DB.ExecuteQuery("Update AD_TreeNode Set Parent_ID = 0 where Parent_ID=" + GetAD_Org_ID() + " AND AD_Tree_ID=" + Util.GetValueOfInt(AD_Tree_ID)); } } return(true); }
/// <summary> /// Get first with Alias /// </summary> /// <param name="ctx">context</param> /// <param name="C_AcctSchema_ID"></param> /// <param name="alias"></param> /// <returns>account</returns> public static MAccount Get(Ctx ctx, int C_AcctSchema_ID, String alias) { MAccount retValue = null; String sql = "SELECT * FROM C_ValidCombination WHERE C_AcctSchema_ID=" + C_AcctSchema_ID + " AND Alias=" + alias; DataSet ds = new DataSet(); try { ds = DataBase.DB.ExecuteDataset(sql, null, null); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { DataRow rs = ds.Tables[0].Rows[i]; retValue = new MAccount(ctx, rs, null); } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } return(retValue); }
/// <summary> /// After save /// </summary> /// <param name="newRecord">new</param> /// <param name="success">success</param> /// <returns>success</returns> protected override bool AfterSave(bool newRecord, bool success) { if (newRecord & success) { // Accounting Insert_Accounting("C_BP_Customer_Acct", "C_BP_Group_Acct", "p.C_BP_Group_ID=" + GetC_BP_Group_ID()); Insert_Accounting("C_BP_Vendor_Acct", "C_BP_Group_Acct", "p.C_BP_Group_ID=" + GetC_BP_Group_ID()); Insert_Accounting("C_BP_Employee_Acct", "C_AcctSchema_Default", null); } // Value/Name change if (success && !newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name"))) { MAccount.UpdateValueDescription(GetCtx(), "C_BPartner_ID=" + GetC_BPartner_ID(), Get_TrxName()); } return(success); }
/// <summary> /// Update Value/Description after change of /// account element value/description. /// </summary> /// <param name="ctx">context</param> /// <param name="where">where clause</param> /// <param name="trxName">transaction</param> public static void UpdateValueDescription(Ctx ctx, String where, Trx trxName) { String sql = "SELECT * FROM C_ValidCombination"; if (where != null && where.Length > 0) { sql += " WHERE " + where; } sql += " ORDER BY C_ValidCombination_ID"; int count = 0; int errors = 0; DataSet ds = new DataSet(); try { ds = DataBase.DB.ExecuteDataset(sql, null, trxName); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { DataRow rs = ds.Tables[0].Rows[i]; MAccount account = new MAccount(ctx, rs, trxName); account.SetValueDescription(); if (account.Save()) { count++; } else { errors++; } } ds = null; } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } _log.Fine(where + " #" + count + ", Errors=" + errors); }
} // 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
/** * After Save * @param newRecord new * @param success success * @return success */ protected override bool AfterSave(bool newRecord, bool success) { if (!success) { return(success); } // Value/Name change in Account if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name"))) { MAccount.UpdateValueDescription(GetCtx(), "M_Product_ID=" + GetM_Product_ID(), Get_TrxName()); } // Name/Description Change in Asset MAsset.setValueNameDescription if (!newRecord && (Is_ValueChanged("Name") || Is_ValueChanged("Description"))) { //String sql = "UPDATE A_Asset a " // + "SET (Name, Description)=" // + "(SELECT SUBSTR(bp.Name || ' - ' || p.Name,1,60), p.Description " // + "FROM M_Product p, C_BPartner bp " // + "WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID) " // + "WHERE IsActive='Y'" // // + " AND GuaranteeDate > SysDate" // + " AND M_Product_ID=" + GetM_Product_ID(); String sql = " UPDATE A_Asset a SET Name=(SELECT SUBSTR(bp.Name || ' - ' || p.Name,1,60) FROM M_Product p, C_BPartner bp WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID)," + "Description=(SELECT p.Description FROM M_Product p, C_BPartner bp WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID)" + "WHERE IsActive='Y' AND M_Product_ID=" + GetM_Product_ID(); int no = 0; try { no = Utility.Util.GetValueOfInt(DataBase.DB.ExecuteQuery(sql, null, Get_TrxName())); } catch { } log.Fine("Asset Description updated #" + no); } // New - Acct, Tree, Old Costing if (newRecord) { Insert_Accounting("M_Product_Acct", "M_Product_Category_Acct", "p.M_Product_Category_ID=" + GetM_Product_Category_ID()); // MAcctSchema[] mass = MAcctSchema.GetClientAcctSchema(GetCtx(), GetAD_Client_ID(), Get_TrxName()); for (int i = 0; i < mass.Length; i++) { // Old MProductCosting pcOld = new MProductCosting(this, mass[i].GetC_AcctSchema_ID()); pcOld.Save(); } } // New Costing if (newRecord || Is_ValueChanged("M_Product_Category_ID")) { MCost.Create(this); } return(success); }
/** * After Save * @param newRecord new * @param success success * @return success */ protected override bool AfterSave(bool newRecord, bool success) { PO project = null; int _client_ID = 0; StringBuilder _sql = new StringBuilder(); //_sql.Append("Select count(*) from ad_table where tablename like 'FRPT_Project_Acct'"); //_sql.Append("SELECT count(*) FROM all_objects WHERE object_type IN ('TABLE') AND (object_name) = UPPER('FRPT_Project_Acct') AND OWNER LIKE '" + DB.GetSchema() + "'"); _sql.Append(DBFunctionCollection.CheckTableExistence(DB.GetSchema(), "FRPT_Project_Acct")); int count = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString())); if (count > 0) { _sql.Clear(); _sql.Append("Select L.Value From Ad_Ref_List L inner join AD_Reference r on R.AD_REFERENCE_ID=L.AD_REFERENCE_ID where r.name='FRPT_RelatedTo' and l.name='Project'"); var relatedtoProject = Convert.ToString(DB.ExecuteScalar(_sql.ToString())); _client_ID = GetAD_Client_ID(); _sql.Clear(); _sql.Append("select C_AcctSchema_ID from C_AcctSchema where AD_CLIENT_ID=" + _client_ID); DataSet ds3 = new DataSet(); ds3 = DB.ExecuteDataset(_sql.ToString(), null); if (ds3 != null && ds3.Tables[0].Rows.Count > 0) { for (int k = 0; k < ds3.Tables[0].Rows.Count; k++) { int _AcctSchema_ID = Util.GetValueOfInt(ds3.Tables[0].Rows[k]["C_AcctSchema_ID"]); _sql.Clear(); _sql.Append("Select Frpt_Acctdefault_Id,C_Validcombination_Id,Frpt_Relatedto From Frpt_Acctschema_Default Where ISACTIVE='Y' AND AD_CLIENT_ID=" + _client_ID + "AND C_Acctschema_Id=" + _AcctSchema_ID); DataSet ds = DB.ExecuteDataset(_sql.ToString(), null); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string _relatedTo = ds.Tables[0].Rows[i]["Frpt_Relatedto"].ToString(); if (_relatedTo != "" && (_relatedTo == relatedtoProject)) { _sql.Clear(); _sql.Append("Select COUNT(*) From C_Project Bp Left Join FRPT_Project_Acct ca On Bp.C_Project_ID=ca.C_Project_ID And ca.Frpt_Acctdefault_Id=" + ds.Tables[0].Rows[i]["FRPT_AcctDefault_ID"] + " WHERE Bp.IsActive='Y' AND Bp.AD_Client_ID=" + _client_ID + " AND ca.C_Validcombination_Id = " + Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Validcombination_Id"]) + " AND Bp.C_Project_ID = " + GetC_Project_ID()); int recordFound = Convert.ToInt32(DB.ExecuteScalar(_sql.ToString(), null, Get_Trx())); if (recordFound == 0) { project = MTable.GetPO(GetCtx(), "FRPT_Project_Acct", 0, null); project.Set_ValueNoCheck("AD_Org_ID", 0); project.Set_ValueNoCheck("C_Project_ID", Util.GetValueOfInt(GetC_Project_ID())); project.Set_ValueNoCheck("FRPT_AcctDefault_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["FRPT_AcctDefault_ID"])); project.Set_ValueNoCheck("C_ValidCombination_ID", Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Validcombination_Id"])); project.Set_ValueNoCheck("C_AcctSchema_ID", _AcctSchema_ID); if (!project.Save()) { } } } } } } } } else if (newRecord & success && (String.IsNullOrEmpty(GetCtx().GetContext("#DEFAULT_ACCOUNTING_APPLICABLE")) || Util.GetValueOfString(GetCtx().GetContext("#DEFAULT_ACCOUNTING_APPLICABLE")) == "Y")) { bool sucs = Insert_Accounting("C_Project_Acct", "C_AcctSchema_Default", null); //Karan. work done to show message if data not saved in accounting tab. but will save data in current tab. // Before this, data was being saved but giving message "record not saved". if (!sucs) { log.SaveWarning("AcctNotSaved", ""); } } // Value/Name change MProject prjph = null; if (success && !newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name"))) { MAccount.UpdateValueDescription(GetCtx(), "C_Project_ID=" + GetC_Project_ID(), Get_TrxName()); } if (GetC_Campaign_ID() != 0) { //Used transaction because total was not updating on header MCampaign cam = new MCampaign(GetCtx(), GetC_Campaign_ID(), Get_TrxName()); decimal plnAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(pl.PlannedAmt),0) FROM C_Project pl WHERE pl.IsActive = 'Y' AND pl.C_Campaign_ID = " + GetC_Campaign_ID(), null, Get_TrxName())); cam.SetCosts(plnAmt); cam.Save(); } else { //Used transaction because total was not updating on header prjph = new MProject(GetCtx(), GetC_Project_ID(), Get_TrxName()); if (!prjph.IsOpportunity()) { //Used transaction because total was not updating on header decimal plnAmt = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT COALESCE(SUM(PlannedAmt),0) FROM C_ProjectPhase WHERE IsActive= 'Y' AND C_Project_ID= " + GetC_Project_ID(), null, Get_TrxName())); DB.ExecuteQuery("UPDATE C_Project SET PlannedAmt=" + plnAmt + " WHERE C_Project_ID=" + GetC_Project_ID(), null, Get_TrxName()); } } return(success); }
/** * Get Charge Account * @param C_Charge_ID charge * @param as account schema * @param amount amount for expense(+)/revenue(-) * @return Charge Account or null */ public static MAccount GetAccount(int C_Charge_ID, MAcctSchema aSchema, Decimal amount) { if (C_Charge_ID == 0 || aSchema == null) { return(null); } int acct_index = 1; // Expense (positive amt) if (amount < 0) { acct_index = 2; // Revenue (negative amt) } String sql = "SELECT CH_Expense_Acct, CH_Revenue_Acct FROM C_Charge_Acct WHERE C_Charge_ID=" + C_Charge_ID + " AND C_AcctSchema_ID=" + aSchema.GetC_AcctSchema_ID(); int Account_ID = 0; IDataReader dr = null; try { // PreparedStatement pstmt = DataBase.prepareStatement(sql, null); // pstmt.setInt (1, C_Charge_ID); // pstmt.setInt (2, aSchema.getC_AcctSchema_ID()); // ResultSet dr = pstmt.executeQuery(); dr = DataBase.DB.ExecuteReader(sql, null, null); if (dr.Read()) { Account_ID = Utility.Util.GetValueOfInt(dr[acct_index - 1].ToString()); } dr.Close(); //pstmt.close(); } catch (SqlException e) { if (dr != null) { dr.Close(); } _log.Log(Level.SEVERE, sql, e); return(null); } finally { if (dr != null) { dr.Close(); } } // No account if (Account_ID == 0) { _log.Severe("NO account for C_Charge_ID=" + C_Charge_ID); return(null); } // Return Account MAccount acct = MAccount.Get(aSchema.GetCtx(), Account_ID); return(acct); } // getAccount
/** Fill Accounting Dimensions from line combination **/ private void fillDimensionsFromCombination() { if (GetC_ValidCombination_ID() > 0) { MAccount combi = new MAccount(GetCtx(), GetC_ValidCombination_ID(), Get_TrxName()); if (Get_ColumnIndex("Account_ID") > 0) { Set_Value("Account_ID", combi.GetAccount_ID() > 0 ? combi.GetAccount_ID() : 0); } if (Get_ColumnIndex("C_SubAcct_ID") > 0) { Set_Value("C_SubAcct_ID", combi.GetC_SubAcct_ID() > 0 ? combi.GetC_SubAcct_ID() : 0); } if (Get_ColumnIndex("M_Product_ID") > 0) { Set_Value("M_Product_ID", combi.GetM_Product_ID() > 0 ? combi.GetM_Product_ID() : 0); } if (Get_ColumnIndex("C_BPartner_ID") > 0) { Set_Value("C_BPartner_ID", combi.GetC_BPartner_ID() > 0 ? combi.GetC_BPartner_ID() : 0); } if (Get_ColumnIndex("AD_OrgTrx_ID") > 0) { Set_Value("AD_OrgTrx_ID", combi.GetAD_OrgTrx_ID() > 0 ? combi.GetAD_OrgTrx_ID() : 0); } if (Get_ColumnIndex("AD_Org_ID") > 0) { Set_Value("AD_Org_ID", combi.GetAD_Org_ID() > 0 ? combi.GetAD_Org_ID() : 0); } if (Get_ColumnIndex("C_LocFrom_ID") > 0) { Set_Value("C_LocFrom_ID", combi.GetC_LocFrom_ID() > 0 ? combi.GetC_LocFrom_ID() : 0); } if (Get_ColumnIndex("C_LocTo_ID") > 0) { Set_Value("C_LocTo_ID", combi.GetC_LocTo_ID() > 0 ? combi.GetC_LocTo_ID() : 0); } if (Get_ColumnIndex("C_SalesRegion_ID") > 0) { Set_Value("C_SalesRegion_ID", combi.GetC_SalesRegion_ID() > 0 ? combi.GetC_SalesRegion_ID() : 0); } if (Get_ColumnIndex("C_Project_ID") > 0) { Set_Value("C_Project_ID", combi.GetC_Project_ID() > 0 ? combi.GetC_Project_ID() : 0); } if (Get_ColumnIndex("C_Campaign_ID") > 0) { Set_Value("C_Campaign_ID", combi.GetC_Campaign_ID() > 0 ? combi.GetC_Campaign_ID() : 0); } if (Get_ColumnIndex("C_Activity_ID") > 0) { Set_Value("C_Activity_ID", combi.GetC_Activity_ID() > 0 ? combi.GetC_Activity_ID() : 0); } if (Get_ColumnIndex("User1_ID") > 0) { Set_Value("User1_ID", combi.GetUser1_ID() > 0 ? combi.GetUser1_ID() : 0); } if (Get_ColumnIndex("User2_ID") > 0) { Set_Value("User2_ID", combi.GetUser2_ID() > 0 ? combi.GetUser2_ID() : 0); } } }
} // afterDelete /** Update combination and optionally **/ private bool GetOrCreateCombination(Boolean newRecord) { int Account_ID = 0, C_SubAcct_ID = 0, M_Product_ID = 0, C_BPartner_ID = 0, AD_Org_ID = 0, AD_OrgTrx_ID = 0, C_LocFrom_ID = 0, C_LocTo_ID = 0, C_SalesRegion_ID = 0, C_Project_ID = 0, C_Campaign_ID = 0, C_Activity_ID = 0, User1_ID = 0, User2_ID = 0; if (GetC_ValidCombination_ID() == 0 || (!newRecord && (Is_ValueChanged("Account_ID") || Is_ValueChanged("M_Product_ID") || Is_ValueChanged("C_BPartner_ID") || Is_ValueChanged("AD_Org_ID") || Is_ValueChanged("C_Project_ID") || Is_ValueChanged("C_Campaign_ID") || Is_ValueChanged("C_Activity_ID")))) { MJournal gl = new MJournal(GetCtx(), GetGL_Journal_ID(), Get_TrxName()); // Validate all mandatory combinations are set MAcctSchema asc = MAcctSchema.Get(GetCtx(), gl.GetC_AcctSchema_ID()); MAcctSchemaElement[] elements = MAcctSchemaElement.GetAcctSchemaElements(asc); for (int i = 0; i < elements.Length; i++) { MAcctSchemaElement elem = elements[i]; String et = elem.GetElementType(); if (MAcctSchemaElement.ELEMENTTYPE_Account.Equals(et) && Get_ColumnIndex("Account_ID") > 0) { Account_ID = Util.GetValueOfInt(Get_Value("Account_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_Account.Equals(et) && Get_ColumnIndex("C_SubAcct_ID") > 0) { C_SubAcct_ID = Util.GetValueOfInt(Get_Value("C_SubAcct_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_Activity.Equals(et) && Get_ColumnIndex("C_Activity_ID") > 0) { C_Activity_ID = Util.GetValueOfInt(Get_Value("C_Activity_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_BPartner.Equals(et) && Get_ColumnIndex("C_BPartner_ID") > 0) { C_BPartner_ID = Util.GetValueOfInt(Get_Value("C_BPartner_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_Campaign.Equals(et) && Get_ColumnIndex("C_BPartner_ID") > 0) { C_BPartner_ID = Util.GetValueOfInt(Get_Value("C_BPartner_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_Organization.Equals(et)) { AD_Org_ID = GetAD_Org_ID(); } if (MAcctSchemaElement.ELEMENTTYPE_OrgTrx.Equals(et) && Get_ColumnIndex("AD_OrgTrx_ID") > 0) { AD_OrgTrx_ID = Util.GetValueOfInt(Get_Value("AD_OrgTrx_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(et) && Get_ColumnIndex("C_LocFrom_ID") > 0) { C_LocFrom_ID = Util.GetValueOfInt(Get_Value("C_LocFrom_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(et) && Get_ColumnIndex("C_LocTo_ID") > 0) { C_LocTo_ID = Util.GetValueOfInt(Get_Value("C_LocTo_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(et) && Get_ColumnIndex("M_Product_ID") > 0) { M_Product_ID = Util.GetValueOfInt(Get_Value("M_Product_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_Project.Equals(et) && Get_ColumnIndex("C_Project_ID") > 0) { C_Project_ID = Util.GetValueOfInt(Get_Value("C_Project_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_Project.Equals(et) && Get_ColumnIndex("C_Campaign_ID") > 0) { C_Campaign_ID = Util.GetValueOfInt(Get_Value("C_Campaign_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_SalesRegion.Equals(et) && Get_ColumnIndex("C_SalesRegion_ID") > 0) { C_SalesRegion_ID = Util.GetValueOfInt(Get_Value("C_SalesRegion_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_UserList1.Equals(et) && Get_ColumnIndex("User1_ID") > 0) { User1_ID = Util.GetValueOfInt(Get_Value("User1_ID")); } if (MAcctSchemaElement.ELEMENTTYPE_UserList2.Equals(et) && Get_ColumnIndex("User2_ID") > 0) { User2_ID = Util.GetValueOfInt(Get_Value("User2_ID")); } } MAccount acct = MAccount.Get(GetCtx(), GetAD_Client_ID(), AD_Org_ID, gl.GetC_AcctSchema_ID(), Account_ID, C_SubAcct_ID, M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID, C_LocTo_ID, C_SalesRegion_ID, C_Project_ID, C_Campaign_ID, C_Activity_ID, User1_ID, User2_ID, 0, 0, 0, 0, 0, 0, 0, 0, 0); if (acct != null) { acct.Save(Get_TrxName()); // get ID from transaction SetC_ValidCombination_ID(acct.Get_ID()); //if (acct.GetAlias() != null && acct.GetAlias().length > 0) // setAlias_ValidCombination_ID(acct.get_ID()); //else // setAlias_ValidCombination_ID(0); } } else { fillDimensionsFromCombination(); } return(true); }