/// <summary> /// Get Product Costs per UOM for Accounting Schema in Accounting Schema Currency. /// - if costType defined - cost /// - else CurrentCosts /// </summary> /// <param name="as1"></param> /// <param name="costType">if null uses Accounting Schema Costs - see AcctSchema.COSTING_*</param> /// <returns>product costs</returns> private Decimal?GetProductItemCostOld(MAcctSchema as1, String costType) { Decimal? current = null; Decimal? cost = null; String cm = as1.GetCostingMethod(); StringBuilder sql = new StringBuilder("SELECT CurrentCostPrice,"); // 1 // if ((costType == null && MAcctSchema.COSTINGMETHOD_AveragePO.Equals(cm)) || MAcctSchema.COSTINGMETHOD_AveragePO.Equals(costType)) { sql.Append("COSTAVERAGE"); // 2 } else if ((costType == null && MAcctSchema.COSTINGMETHOD_LastPOPrice.Equals(cm)) || MAcctSchema.COSTINGMETHOD_LastPOPrice.Equals(costType)) { sql.Append("PRICELASTPO"); } else // AcctSchema.COSTING_STANDARD { sql.Append("COSTSTANDARD"); } sql.Append(" FROM M_Product_Costing WHERE M_Product_ID=" + _M_Product_ID + " AND C_AcctSchema_ID=" + as1.GetC_AcctSchema_ID()); IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql.ToString(), null, null); if (idr.Read()) { current = Utility.Util.GetValueOfDecimal(idr[0]); //.getBigDecimal(1); cost = Utility.Util.GetValueOfDecimal(idr[1]); //.getBigDecimal(2); } idr.Close(); } catch (Exception e) { log.Log(Level.SEVERE, sql.ToString(), e); } // Return Costs if (costType != null && cost != null && !cost.Equals(Env.ZERO)) { log.Fine("Costs=" + cost); return(cost); } else if (current != null && !current.Equals(Env.ZERO)) { log.Fine("Current=" + current); return(current); } // Create/Update Cost Record bool create = (cost == null && current == null); return(UpdateCostsOld(as1, create)); }
/// <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); }