/// <summary> /// Costing Method must exist /// </summary> /// <param name="to">test</param> /// <returns>true valid</returns> private bool IsValid(String to) { if (_SetFutureCostTo.Length == 0) { return(true); } String toTarget = to; if (to.Equals(TO_AverageInvoiceHistory)) { to = TO_AverageInvoice; } if (to.Equals(TO_AveragePOHistory)) { to = TO_AveragePO; } if (to.Equals(TO_FutureStandardCost)) { to = TO_StandardCost; } // if (to.Equals(TO_AverageInvoice) || to.Equals(TO_AveragePO) || to.Equals(TO_FiFo) || to.Equals(TO_LiFo) || to.Equals(TO_StandardCost)) { MCostElement ce = GetCostElement(_SetFutureCostTo); return(ce != null); } return(true); }
/// <summary> /// Process /// </summary> /// <returns>info</returns> protected override String DoIt() { log.Info("M_Product_Category_ID=" + _M_Product_Category_ID + ", Future=" + _SetFutureCostTo + ", Standard=" + _SetStandardCostTo + "; M_PriceList_Version_ID=" + _M_PriceList_Version_ID); if (_SetFutureCostTo == null) { _SetFutureCostTo = ""; } if (_SetStandardCostTo == null) { _SetStandardCostTo = ""; } // Nothing to Do if (_SetFutureCostTo.Length == 0 && _SetStandardCostTo.Length == 0) { return("-"); } // PLV required if (_M_PriceList_Version_ID == 0 && (_SetFutureCostTo.Equals(TO_PriceListLimit) || _SetStandardCostTo.Equals(TO_PriceListLimit))) { throw new Exception("@FillMandatory@ @M_PriceList_Version_ID@"); } // Validate Source if (!IsValid(_SetFutureCostTo)) { throw new Exception("@NotFound@ @M_CostElement_ID@ (Future) " + _SetFutureCostTo); } if (!IsValid(_SetStandardCostTo)) { throw new Exception("@NotFound@ @M_CostElement_ID@ (Standard) " + _SetStandardCostTo); } // Prepare MClient client = MClient.Get(GetCtx()); _ce = MCostElement.GetMaterialCostElement(client, MAcctSchema.COSTINGMETHOD_StandardCosting); if (_ce.Get_ID() == 0) { throw new Exception("@NotFound@ @M_CostElement_ID@ (StdCost)"); } log.Config(_ce.ToString()); _ass = MAcctSchema.GetClientAcctSchema(GetCtx(), client.GetAD_Client_ID()); for (int i = 0; i < _ass.Length; i++) { CreateNew(_ass[i]); } Commit(); // Update Cost int counter = Update(); return("#" + counter); }
public override String LoadDocumentDetails() { costupdate = (MCostUpdate)GetPO(); if (costupdate.GetM_Product_Category_ID() != 0) { mpc = MProductCategory.Get(GetCtx(), costupdate.GetM_Product_Category_ID()); } _lines = LoadLines(costupdate); m_ce = MCostElement.GetMaterialCostElement(MClient.Get(GetCtx()), X_C_AcctSchema.COSTINGMETHOD_StandardCosting); SetDateAcct(costupdate.GetDateAcct()); SetDateDoc(costupdate.GetDateAcct()); return(null); }
/// <summary> /// Get Cost Element /// </summary> /// <param name="CostingMethod">method</param> /// <returns>costing element or null</returns> private MCostElement GetCostElement(String CostingMethod) { MCostElement ce = null; //if (_ces.Count == 0) //{ // ce = null; //} //else //{ // ce = _ces[CostingMethod];// _ces.get(CostingMethod); //} if (_ces.ContainsKey(CostingMethod)) { ce = _ces[CostingMethod];// _ces.get(CostingMethod); } if (ce == null) { ce = MCostElement.GetMaterialCostElement(GetCtx(), CostingMethod); //_ces.put(CostingMethod, ce); _ces.Add(CostingMethod, ce); } return(ce); }
/// <summary> /// Get Costs /// </summary> /// <param name="cost">Cost</param> /// <param name="to">where to get costs from </param> /// <returns>costs (could be 0) or null if not found</returns> private Decimal?GetCosts(VAdvantage.Model.MCost cost, String to) { Decimal?retValue = null; // Average Invoice if (to.Equals(TO_AverageInvoice)) { MCostElement ce = GetCostElement(TO_AverageInvoice); if (ce == null) { throw new Exception("CostElement not found: " + TO_AverageInvoice); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } // Average Invoice History else if (to.Equals(TO_AverageInvoiceHistory)) { MCostElement ce = GetCostElement(TO_AverageInvoice); if (ce == null) { throw new Exception("CostElement not found: " + TO_AverageInvoice); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetHistoryAverage(); } } // Average PO else if (to.Equals(TO_AveragePO)) { MCostElement ce = GetCostElement(TO_AveragePO); if (ce == null) { throw new Exception("CostElement not found: " + TO_AveragePO); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } // Average PO History else if (to.Equals(TO_AveragePOHistory)) { MCostElement ce = GetCostElement(TO_AveragePO); if (ce == null) { throw new Exception("CostElement not found: " + TO_AveragePO); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetHistoryAverage(); } } // FiFo else if (to.Equals(TO_FiFo)) { MCostElement ce = GetCostElement(TO_FiFo); if (ce == null) { throw new Exception("CostElement not found: " + TO_FiFo); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } // Future Std Costs else if (to.Equals(TO_FutureStandardCost)) { retValue = cost.GetFutureCostPrice(); } // Last Inv Price else if (to.Equals(TO_LastInvoicePrice)) { MCostElement ce = GetCostElement(TO_LastInvoicePrice); if (ce != null) { VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } if (retValue == null) { MProduct product = MProduct.Get(GetCtx(), cost.GetM_Product_ID()); MAcctSchema as1 = MAcctSchema.Get(GetCtx(), cost.GetC_AcctSchema_ID()); retValue = VAdvantage.Model.MCost.GetLastInvoicePrice(product, cost.GetM_AttributeSetInstance_ID(), cost.GetAD_Org_ID(), as1.GetC_Currency_ID()); } } // Last PO Price else if (to.Equals(TO_LastPOPrice)) { MCostElement ce = GetCostElement(TO_LastPOPrice); if (ce != null) { if (BTR002_IsPickLastPO == "N") { VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } } if (retValue == null) { MProduct product = MProduct.Get(GetCtx(), cost.GetM_Product_ID()); MAcctSchema as1 = MAcctSchema.Get(GetCtx(), cost.GetC_AcctSchema_ID()); retValue = VAdvantage.Model.MCost.GetLastPOPrice(product, cost.GetM_AttributeSetInstance_ID(), cost.GetAD_Org_ID(), as1.GetC_Currency_ID()); } } // FiFo else if (to.Equals(TO_LiFo)) { MCostElement ce = GetCostElement(TO_LiFo); if (ce == null) { throw new Exception("CostElement not found: " + TO_LiFo); } VAdvantage.Model.MCost xCost = VAdvantage.Model.MCost.Get(GetCtx(), cost.GetAD_Client_ID(), cost.GetAD_Org_ID(), cost.GetM_Product_ID(), cost.GetM_CostType_ID(), cost.GetC_AcctSchema_ID(), ce.GetM_CostElement_ID(), cost.GetM_AttributeSetInstance_ID()); if (xCost != null) { retValue = xCost.GetCurrentCostPrice(); } } // Old Std Costs else if (to.Equals(TO_OldStandardCost)) { retValue = GetOldCurrentCostPrice(cost); } // Price List else if (to.Equals(TO_PriceListLimit)) { retValue = GetPrice(cost); } // Standard Costs else if (to.Equals(TO_StandardCost)) { retValue = cost.GetCurrentCostPrice(); } return(retValue); }
protected override string DoIt() { try { // Get Combination Record sql = @"SELECT ce.M_CostElement_ID , ce.Name , cel.lineno , cel.m_ref_costelement FROM M_CostElement ce INNER JOIN m_costelementline cel ON ce.M_CostElement_ID = cel.M_CostElement_ID " + " WHERE ce.AD_Client_ID=" + GetAD_Client_ID() + " AND ce.M_CostElement_ID = " + costElement_ID + " AND ce.IsActive='Y' AND cel.IsActive='Y'"; dsCostCombination = DB.ExecuteDataset(sql, null, null); if (dsCostCombination != null && dsCostCombination.Tables.Count > 0 && dsCostCombination.Tables[0].Rows.Count > 0) { for (int i = 0; i < dsCostCombination.Tables[0].Rows.Count; i++) { costElement.Add(Util.GetValueOfInt(dsCostCombination.Tables[0].Rows[i]["m_ref_costelement"])); } } //var costElementRecord = dsCostCombination.Tables[0].AsEnumerable().Select(r => r.Field<int>("m_ref_costelement")).ToList(); // Get All Product sql = @"SELECT ad_client_id , ad_org_id , m_product_id , m_attributesetinstance_id , c_acctschema_id , m_costtype_id , m_costelement_id , cumulatedamt , cumulatedqty , currentcostprice , currentqty FROM m_cost WHERE ad_client_id = " + GetAD_Client_ID() + " ORDER BY m_product_id , ad_org_id , m_attributesetinstance_id , c_acctschema_id"; dsProductCost = DB.ExecuteDataset(sql, null, null); if (dsProductCost != null && dsProductCost.Tables.Count > 0 && dsProductCost.Tables[0].Rows.Count > 0) { // update all record of m_Cost having cost Element = costElement_ID sql = "UPDATE M_Cost SET currentcostprice = 0 , currentqty = 0 , cumulatedamt = 0 , cumulatedqty = 0 WHERE M_CostElement_ID = " + costElement_ID + " AND AD_Client_ID = " + GetAD_Client_ID(); int no = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_TrxName())); for (int i = 0; i < dsProductCost.Tables[0].Rows.Count; i++) { if (!costElement.Contains(Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["m_costelement_id"]))) continue; if (_m_Product_ID != Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["m_product_id"]) || _ad_Org_ID != Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["ad_org_id"]) || _m_Attributesetinstance_ID != Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["m_attributesetinstance_id"]) || _c_AcctSchema_ID != Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["c_acctschema_id"])) { _m_Product_ID = Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["m_product_id"]); _ad_Org_ID = Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["ad_org_id"]); _m_Attributesetinstance_ID = Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["m_attributesetinstance_id"]); _c_AcctSchema_ID = Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["c_acctschema_id"]); MProduct product = new MProduct(GetCtx(), _m_Product_ID, Get_TrxName()); MAcctSchema acctSchema = new MAcctSchema(GetCtx(), _c_AcctSchema_ID, Get_TrxName()); costcombination = MCost.Get(product, _m_Attributesetinstance_ID, acctSchema, _ad_Org_ID, Util.GetValueOfInt(dsCostCombination.Tables[0].Rows[0]["M_CostElement_ID"])); } // created object of Cost elemnt for checking iscalculated = true/ false ce = MCostElement.Get(GetCtx(), Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["m_costelement_id"])); costcombination.SetCurrentCostPrice(Decimal.Add(costcombination.GetCurrentCostPrice(), Util.GetValueOfDecimal(dsProductCost.Tables[0].Rows[i]["currentcostprice"]))); costcombination.SetCumulatedAmt(Decimal.Add(costcombination.GetCumulatedAmt(), Util.GetValueOfDecimal(dsProductCost.Tables[0].Rows[i]["cumulatedamt"]))); // if calculated = true then we added qty else not and costing method is Standard Costing if (ce.IsCalculated() || ce.GetCostingMethod() == MCostElement.COSTINGMETHOD_StandardCosting) { costcombination.SetCurrentQty(Decimal.Add(costcombination.GetCurrentQty(), Util.GetValueOfDecimal(dsProductCost.Tables[0].Rows[i]["currentqty"]))); costcombination.SetCumulatedQty(Decimal.Add(costcombination.GetCumulatedQty(), Util.GetValueOfDecimal(dsProductCost.Tables[0].Rows[i]["cumulatedqty"]))); } if (costcombination.Save()) { Commit(); } else { log.Info("Cost Combination not updated for this product <===> " + Util.GetValueOfInt(dsProductCost.Tables[0].Rows[i]["m_product_id"])); } } dsProductCost.Dispose(); } } catch { if (dsProductCost != null) { dsProductCost.Dispose(); } if (dsCostCombination != null) { dsCostCombination.Dispose(); } } return Msg.GetMsg(GetCtx(), "SucessfullyUpdated"); }