protected override bool BeforeSave(bool newRecord) { if (GetAD_Org_ID() != 0) { SetAD_Org_ID(0); } if (base.GetTaxCorrectionType() == null) { SetTaxCorrectionType(IsDiscountCorrectsTax() ? TAXCORRECTIONTYPE_Write_OffAndDiscount : TAXCORRECTIONTYPE_None); } // Applied check for Table to enable support with Framework database. if (PO.Get_Table_ID("M_CostType") > 0) { CheckCosting(); } // Check Primary if (GetAD_OrgOnly_ID() != 0) { MClientInfo info = MClientInfo.Get(GetCtx(), GetAD_Client_ID()); if (info.GetC_AcctSchema1_ID() == GetC_AcctSchema_ID()) { SetAD_OrgOnly_ID(0); } } return(true); }
/// <summary> /// Get Primary Accounting Schema /// </summary> /// <returns>Acct Schema or null</returns> internal MAcctSchema GetAcctSchema() { if (_info == null) { _info = MClientInfo.Get(GetCtx(), GetAD_Client_ID(), Get_TrxName()); } if (_info != null) { int C_AcctSchema_ID = _info.GetC_AcctSchema1_ID(); if (C_AcctSchema_ID != 0) { return(MAcctSchema.Get(GetCtx(), C_AcctSchema_ID)); } } return(null); }
/// <summary> /// Is used to check costing method belongs to PO costing method like (Average PO, Weighted Average PO or Last PO) /// Firts we check costing method on Product category, if not found then we will check on Primary Accounting Schema /// </summary> /// <param name="ctx">current context</param> /// <param name="AD_Client_ID">Client reference</param> /// <param name="M_Product_ID">Product whom costing method is to be determine</param> /// <param name="trxName">Transaction</param> /// <returns>True/False</returns> public static bool IsPOCostingmethod(Ctx ctx, int AD_Client_ID, int M_Product_ID, Trx trxName) { MProductCategory pc = null; bool isPOcostingMethod = false; string costingMethod = null; MClient client = MClient.Get(ctx, AD_Client_ID); MProduct product = MProduct.Get(ctx, M_Product_ID); if (product != null) { pc = MProductCategory.Get(product.GetCtx(), product.GetM_Product_Category_ID()); if (pc != null) { // check costing method from product category costingMethod = pc.GetCostingMethod(); if (costingMethod == "C") { costingMethod = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT costingmethod FROM M_CostElement WHERE M_CostElement_ID IN (SELECT CAST(M_Ref_CostElement AS INTEGER) FROM M_CostElementLine WHERE M_CostElement_ID=" + pc.GetM_CostElement_ID() + @" ) AND CostingMethod IS NOT NULL", null, trxName)); } } if (String.IsNullOrEmpty(costingMethod)) { // check costing method against primary accounting schema MClientInfo clientInfo = MClientInfo.Get(ctx, AD_Client_ID); MAcctSchema actSchema = MAcctSchema.Get(ctx, clientInfo.GetC_AcctSchema1_ID()); if (actSchema != null) { costingMethod = actSchema.GetCostingMethod(); if (costingMethod == "C") { costingMethod = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT costingmethod FROM M_CostElement WHERE M_CostElement_ID IN (SELECT CAST(M_Ref_CostElement AS INTEGER) FROM M_CostElementLine WHERE M_CostElement_ID=" + actSchema.GetM_CostElement_ID() + @" ) AND CostingMethod IS NOT NULL", null, trxName)); } } } } if (costingMethod.Equals(COSTINGMETHOD_WeightedAveragePO) || costingMethod.Equals(COSTINGMETHOD_AveragePO) || costingMethod.Equals(COSTINGMETHOD_LastPOPrice)) { isPOcostingMethod = true; } else { isPOcostingMethod = false; } return(isPOcostingMethod); }
protected override bool BeforeSave(bool newRecord) { if (GetAD_Org_ID() != 0) { SetAD_Org_ID(0); } if (base.GetTaxCorrectionType() == null) { SetTaxCorrectionType(IsDiscountCorrectsTax() ? TAXCORRECTIONTYPE_Write_OffAndDiscount : TAXCORRECTIONTYPE_None); } CheckCosting(); // Check Primary if (GetAD_OrgOnly_ID() != 0) { MClientInfo info = MClientInfo.Get(GetCtx(), GetAD_Client_ID()); if (info.GetC_AcctSchema1_ID() == GetC_AcctSchema_ID()) { SetAD_OrgOnly_ID(0); } } return(true); }
} // getClientAcctSchema // by amit 23-12-2015 public static MAcctSchema[] GetClientAcctSchemas(Ctx ctx, int AD_Client_ID, Trx trxName) { // Check Cache int key = AD_Client_ID; if (_schema.ContainsKey(key)) { return((MAcctSchema[])_schema[key]); } // Create New List <MAcctSchema> list = new List <MAcctSchema>(); MClientInfo info = MClientInfo.Get(ctx, AD_Client_ID, trxName); MAcctSchema ass = MAcctSchema.Get(ctx, info.GetC_AcctSchema1_ID(), trxName); if (ass.Get_ID() != 0 && trxName == null) { list.Add(ass); } // Other String sql = "SELECT C_AcctSchema_ID FROM C_AcctSchema acs " + "WHERE IsActive='Y'"; if (AD_Client_ID != 0) { sql += " AND AD_Client_ID=" + AD_Client_ID; } sql += " ORDER BY C_AcctSchema_ID"; IDataReader dr = null; try { dr = DataBase.DB.ExecuteReader(sql, null, trxName); while (dr.Read()) { int id = Utility.Util.GetValueOfInt(dr[0].ToString()); if (id != info.GetC_AcctSchema1_ID()) // already in list { ass = MAcctSchema.Get(ctx, id, trxName); if (ass.Get_ID() != 0 && trxName == null) { list.Add(ass); } } } dr.Close(); dr = null; } catch (System.Data.Common.DbException e) { if (dr != null) { dr.Close(); } _log.Log(Level.SEVERE, sql, e); } finally { if (dr != null) { dr.Close(); dr = null; } } // Save MAcctSchema[] retValue = new MAcctSchema[list.Count]; retValue = list.ToArray(); if (trxName == null) { _schema.Add(key, retValue); } return(retValue); } // getClientAcctSchema