} // setC_Currency_ID /// <summary> /// Set Rate /// </summary> private void SetRate() { // Source info int C_Currency_ID = GetC_Currency_ID(); int C_ConversionType_ID = GetC_ConversionType_ID(); if (C_Currency_ID == 0 || C_ConversionType_ID == 0) { return; } DateTime?DateAcct = GetDateAcct(); if (DateAcct == null) { DateAcct = DateTime.Now;// new Timestamp(System.currentTimeMillis()); } // int C_AcctSchema_ID = GetC_AcctSchema_ID(); MAcctSchema a = MAcctSchema.Get(GetCtx(), C_AcctSchema_ID); int AD_Client_ID = GetAD_Client_ID(); int AD_Org_ID = GetAD_Org_ID(); Decimal?CurrencyRate = (Decimal?)MConversionRate.GetRate(C_Currency_ID, a.GetC_Currency_ID(), DateAcct, C_ConversionType_ID, AD_Client_ID, AD_Org_ID); log.Fine("rate = " + CurrencyRate); //if (CurrencyRate.Value == null) //{ // CurrencyRate = Env.ZERO; //} SetCurrencyRate(CurrencyRate.Value); } // setRate
/// <summary> ///Get Default Accounting Currency /// </summary> /// <returns>currency or 0</returns> public int GetC_Currency_ID() { if (_acctSchema == null) { GetMAcctSchema(); } if (_acctSchema != null) { return(_acctSchema.GetC_Currency_ID()); } return(0); } // getC_Currency_ID
public static bool InsertForeignCostMatchOrder(Ctx ctx, MOrderLine orderLine, decimal matchQty, int ASI, Trx trx) { int acctSchema_ID = 0; int M_CostElement_ID = 0; int AD_Org_ID = 0; int M_ASI_ID = 0; MProduct product = null; MAcctSchema acctSchema = null; MCostForeignCurrency foreignCost = null; dynamic pc = null; String cl = null; MOrder order = null; try { order = new MOrder(ctx, orderLine.GetC_Order_ID(), trx); if (!order.IsSOTrx() && !order.IsReturnTrx()) { acctSchema_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT asch.c_acctschema_id FROM c_acctschema asch INNER JOIN ad_clientinfo ci ON ci.c_acctschema1_id = asch.c_acctschema_id WHERE ci.ad_client_id = " + order.GetAD_Client_ID())); acctSchema = new MAcctSchema(ctx, acctSchema_ID, trx); if (acctSchema.GetC_Currency_ID() != order.GetC_Currency_ID()) { // Get Costing Element of Av. PO M_CostElement_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT M_CostElement_ID FROM M_CostElement WHERE AD_Client_ID = " + order.GetAD_Client_ID() + " AND IsActive = 'Y' AND CostingMethod = 'A'")); product = new MProduct(ctx, orderLine.GetM_Product_ID(), trx); if (product != null && product.GetProductType() == "I" && product.GetM_Product_ID() > 0) // for Item Type product { pc = MProductCategory.Get(product.GetCtx(), product.GetM_Product_Category_ID()); // Get Costing Level if (pc != null) { cl = pc.GetCostingLevel(); } if (cl == null) { cl = acctSchema.GetCostingLevel(); } if (cl == "C" || cl == "B") { AD_Org_ID = 0; } else { AD_Org_ID = order.GetAD_Org_ID(); } if (cl != "B") { M_ASI_ID = 0; } else { M_ASI_ID = ASI; } foreignCost = MCostForeignCurrency.Get(product, M_ASI_ID, AD_Org_ID, M_CostElement_ID, order.GetC_BPartner_ID(), order.GetC_Currency_ID()); foreignCost.SetC_Order_ID(order.GetC_Order_ID()); foreignCost.SetCumulatedQty(Decimal.Add(foreignCost.GetCumulatedQty(), matchQty)); foreignCost.SetCumulatedAmt(Decimal.Add(foreignCost.GetCumulatedAmt(), Decimal.Multiply(orderLine.GetPriceActual(), matchQty))); if (foreignCost.GetCumulatedQty() != 0) { foreignCost.SetCostPerUnit(Decimal.Round(Decimal.Divide(foreignCost.GetCumulatedAmt(), foreignCost.GetCumulatedQty()), acctSchema.GetCostingPrecision())); } else { foreignCost.SetCostPerUnit(0); } if (!foreignCost.Save(trx)) { ValueNamePair pp = VLogger.RetrieveError(); _log.Severe("Error occured during updating M_Cost_ForeignCurrency. Error name : " + pp.GetName() + " AND Error Value : " + pp.GetValue() + " , For Invoice line : " + orderLine.GetC_OrderLine_ID() + " , AND Ad_Client_ID : " + orderLine.GetAD_Client_ID()); return(false); } } } } } catch (Exception ex) { _log.Log(Level.SEVERE, "", ex); return(false); } return(true); }
public static bool InsertForeignCostAverageInvoice(Ctx ctx, MInvoice invoice, MInvoiceLine invoiceLine, Trx trx) { int acctSchema_ID = 0; int M_CostElement_ID = 0; int AD_Org_ID = 0; int M_ASI_ID = 0; MProduct product = null; MAcctSchema acctSchema = null; MCostForeignCurrency foreignCost = null; dynamic pc = null; String cl = null; try { // if cost is calculated then not to calculate again if (invoiceLine.IsFutureCostCalculated()) { return(true); } acctSchema_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT asch.c_acctschema_id FROM c_acctschema asch INNER JOIN ad_clientinfo ci ON ci.c_acctschema1_id = asch.c_acctschema_id WHERE ci.ad_client_id = " + invoice.GetAD_Client_ID())); acctSchema = new MAcctSchema(ctx, acctSchema_ID, trx); if (acctSchema.GetC_Currency_ID() != invoice.GetC_Currency_ID()) { // Get Costing Element of Av. Invoice M_CostElement_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT M_CostElement_ID FROM M_CostElement WHERE AD_Client_ID = " + invoice.GetAD_Client_ID() + " AND IsActive = 'Y' AND CostingMethod = 'I'")); product = new MProduct(ctx, invoiceLine.GetM_Product_ID(), trx); if (product != null && product.GetProductType() == "I" && product.GetM_Product_ID() > 0) // for Item Type product { pc = MProductCategory.Get(product.GetCtx(), product.GetM_Product_Category_ID()); // Get Costing Level if (pc != null) { cl = pc.GetCostingLevel(); } if (cl == null) { cl = acctSchema.GetCostingLevel(); } if (cl == "C" || cl == "B") { AD_Org_ID = 0; } else { AD_Org_ID = invoice.GetAD_Org_ID(); } if (cl != "B") { M_ASI_ID = 0; } else { M_ASI_ID = invoiceLine.GetM_AttributeSetInstance_ID(); } foreignCost = MCostForeignCurrency.Get(product, M_ASI_ID, AD_Org_ID, M_CostElement_ID, invoice.GetC_BPartner_ID(), invoice.GetC_Currency_ID()); foreignCost.SetC_Invoice_ID(invoice.GetC_Invoice_ID()); foreignCost.SetCumulatedQty(Decimal.Add(foreignCost.GetCumulatedQty(), invoiceLine.GetQtyInvoiced())); foreignCost.SetCumulatedAmt(Decimal.Add(foreignCost.GetCumulatedAmt(), invoiceLine.GetLineNetAmt())); if (foreignCost.GetCumulatedQty() != 0) { foreignCost.SetCostPerUnit(Decimal.Round(Decimal.Divide(foreignCost.GetCumulatedAmt(), foreignCost.GetCumulatedQty()), acctSchema.GetCostingPrecision())); } else { foreignCost.SetCostPerUnit(0); } if (!foreignCost.Save(trx)) { ValueNamePair pp = VLogger.RetrieveError(); _log.Severe("Error occured during updating M_Cost_ForeignCurrency. Error name : " + pp.GetName() + " AND Error Value : " + pp.GetValue() + " , For Invoice line : " + invoiceLine.GetC_InvoiceLine_ID() + " , AND Ad_Client_ID : " + invoiceLine.GetAD_Client_ID()); return(false); } else { invoiceLine.SetIsFutureCostCalculated(true); if (!invoiceLine.Save(trx)) { ValueNamePair pp = VLogger.RetrieveError(); _log.Severe("Error occured during updating Is Foreign Cost On C_invoice. Error name : " + pp.GetName() + " AND Error Value : " + pp.GetValue() + " , For Invoice line : " + invoiceLine.GetC_InvoiceLine_ID() + " , AND Ad_Client_ID : " + invoiceLine.GetAD_Client_ID()); return(false); } } } } } catch (Exception ex) { _log.Log(Level.SEVERE, "", ex); return(false); } return(true); }
} // setC_Currency_ID /// <summary> /// set rate /// </summary> /// <param name="windowNo"></param> private void SetRate(int windowNo) { // Source info int?C_Currency_ID = GetC_Currency_ID(); int?C_ConversionType_ID = GetC_ConversionType_ID(); if (C_Currency_ID == 0 || C_ConversionType_ID == 0) { return; } DateTime?DateAcct = GetDateAcct(); if (DateAcct == null) { DateAcct = DateTime.Now;// new Timestamp(System.currentTimeMillis()); } // int? C_AcctSchema_ID = GetCtx().GetContextAsInt(windowNo, "C_AcctSchema_ID"); MAcctSchema ass = MAcctSchema.Get(GetCtx(), C_AcctSchema_ID.Value); int? AD_Client_ID = GetAD_Client_ID(); int? AD_Org_ID = GetAD_Org_ID(); Decimal?CurrencyRate = (Decimal?)MConversionRate.GetRate(C_Currency_ID.Value, ass.GetC_Currency_ID(), DateAcct, C_ConversionType_ID.Value, AD_Client_ID.Value, AD_Org_ID.Value); log.Fine("rate = " + CurrencyRate); if (CurrencyRate == null) { CurrencyRate = Env.ZERO; } SetCurrencyRate(CurrencyRate); SetAmt(windowNo); } // setRate
/// <summary> /// Get PO Cost from Purchase Info - and convert it to AcctSchema Currency /// </summary> /// <param name="as1">accounting schema</param> /// <returns>po cost</returns> private Decimal?GetPOCost(MAcctSchema as1) { String sql = "SELECT C_Currency_ID, PriceList,PricePO,PriceLastPO " + "FROM M_Product_PO WHERE M_Product_ID=" + _M_Product_ID + "ORDER BY IsCurrentVendor DESC"; int C_Currency_ID = 0; Decimal? PriceList = null; Decimal? PricePO = null; Decimal? PriceLastPO = null; IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql, null, null); if (idr.Read()) { C_Currency_ID = Utility.Util.GetValueOfInt(idr[0]); //.getInt(1); PriceList = Utility.Util.GetValueOfDecimal(idr[1]); //.getBigDecimal(2); PricePO = Utility.Util.GetValueOfDecimal(idr[2]); //.getBigDecimal(3); PriceLastPO = Utility.Util.GetValueOfDecimal(idr[3]); //.getBigDecimal(4); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); idr = null; } log.Log(Level.SEVERE, sql, e); } // nothing found if (C_Currency_ID == 0) { return(null); } Decimal?cost = PriceLastPO; // best bet if (cost == null || cost.Equals(Env.ZERO)) { cost = PricePO; } if (cost == null || cost.Equals(Env.ZERO)) { cost = PriceList; } // Convert - standard precision!! - should be costing precision if (cost != null && !cost.Equals(Env.ZERO)) { cost = MConversionRate.Convert(as1.GetCtx(), Utility.Util.GetValueOfDecimal(cost), C_Currency_ID, as1.GetC_Currency_ID(), as1.GetAD_Client_ID(), as1.GetAD_Org_ID()); } return(cost); }
/// <summary> /// Get PO Price from PriceList - and convert it to AcctSchema Currency /// </summary> /// <param name="as1">accounting schema</param> /// <param name="onlyPOPriceList">use only PO price list</param> /// <returns>po price</returns> private Decimal?GetPriceList(MAcctSchema as1, bool onlyPOPriceList) { StringBuilder sql = new StringBuilder( "SELECT pl.C_Currency_ID, pp.PriceList, pp.PriceStd, pp.PriceLimit " + "FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp " + "WHERE pl.M_PriceList_ID = plv.M_PriceList_ID" + " AND plv.M_PriceList_Version_ID = pp.M_PriceList_Version_ID" + " AND pp.M_Product_ID=" + _M_Product_ID); if (onlyPOPriceList) { sql.Append(" AND pl.IsSOPriceList='N'"); } sql.Append(" ORDER BY pl.IsSOPriceList ASC, plv.ValidFrom DESC"); int C_Currency_ID = 0; Decimal? PriceList = null; Decimal? PriceStd = null; Decimal? PriceLimit = null; IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql.ToString(), null, null); if (idr.Read()) { C_Currency_ID = Utility.Util.GetValueOfInt(idr[0]); //.getInt(1); PriceList = Utility.Util.GetValueOfDecimal(idr[1]); //.getBigDecimal(2); PriceStd = Utility.Util.GetValueOfDecimal(idr[2]); //.getBigDecimal(3); PriceLimit = Utility.Util.GetValueOfDecimal(idr[3]); //.getBigDecimal(4); } idr.Close(); } catch (Exception e) { log.Log(Level.SEVERE, sql.ToString(), e); } // nothing found if (C_Currency_ID == 0) { return(null); } Decimal?price = PriceLimit; // best bet if (price == null || price.Equals(Env.ZERO)) { price = PriceStd; } if (price == null || price.Equals(Env.ZERO)) { price = PriceList; } // Convert if (price != null && !price.Equals(Env.ZERO)) { price = MConversionRate.Convert(as1.GetCtx(), Utility.Util.GetValueOfDecimal(price), C_Currency_ID, as1.GetC_Currency_ID(), as1.GetAD_Client_ID(), 0); } return(price); }