} // 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 Rate /// </summary> /// <param name="ctx"></param> /// <param name="fields"></param> /// <returns></returns> public Decimal GetRate(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); int CurFrom_ID; int CurTo_ID; DateTime?convDate; int ConversionType_ID; int AD_Client_ID; int AD_Org_ID; //Assign parameter value CurFrom_ID = Util.GetValueOfInt(paramValue[0].ToString()); CurTo_ID = Util.GetValueOfInt(paramValue[1].ToString()); // 18/7/2016 create only try catch block. if problem the get current date time try { convDate = System.Convert.ToDateTime(paramValue[2].ToString()); } catch { convDate = DateTime.Now; } //end 18/7/2016 ConversionType_ID = Util.GetValueOfInt(paramValue[3].ToString()); AD_Client_ID = Util.GetValueOfInt(paramValue[4].ToString()); AD_Org_ID = Util.GetValueOfInt(paramValue[5].ToString()); //End Assign parameter value Decimal rate = MConversionRate.GetRate(CurFrom_ID, CurTo_ID, convDate, ConversionType_ID, AD_Client_ID, AD_Org_ID); return(rate); }
/// <summary> /// Create Facts (the accounting logic) for /// GLJ. /// (only for the accounting scheme, it was created) /// <pre> /// account DR CR /// </pre> /// </summary> /// <param name="?"></param> /// <returns>fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); // Other Acct Schema // need to Post GL Journal for Multiple Accounting Schema that's why commented this section //if (as1.GetC_AcctSchema_ID() != _C_AcctSchema_ID) //{ // return facts; //} // create Fact Header Fact fact = new Fact(this, as1, _PostingType); // get conversion rate from Assigned accounting schema tab - Decimal conversionRate = Util.GetValueOfDecimal(DB.ExecuteScalar(@"SELECT CurrencyRate FROM GL_AssignAcctSchema WHERE C_AcctSchema_ID = " + as1.GetC_AcctSchema_ID() + " AND GL_Journal_ID = " + record_Id, null, null)); // GLJ if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_GLJOURNAL)) { // account DR CR for (int i = 0; i < _lines.Length; i++) { // need to Post GL Journal for Multiple Accounting Schema that's why commented this condition //if (_lines[i].GetC_AcctSchema_ID() == as1.GetC_AcctSchema_ID()) //{ // set conversion rate on line, so that amount to be converted based on that multiply rate if (as1.GetC_AcctSchema_ID() != _C_AcctSchema_ID && _lines[i].GetC_Currency_ID() != as1.GetC_Currency_ID()) { conversionRate = MConversionRate.GetRate(_lines[i].GetC_Currency_ID(), as1.GetC_Currency_ID(), _lines[i].GetDateAcct(), _lines[i].GetC_ConversionType_ID(), as1.GetAD_Client_ID(), _lines[i].GetAD_Org_ID()); _lines[i].SetConversionRate(conversionRate); } else if (as1.GetC_AcctSchema_ID() != _C_AcctSchema_ID) { _lines[i].SetConversionRate(conversionRate); } fact.CreateLine(_lines[i], _lines[i].GetAccount(), _lines[i].GetC_Currency_ID(), _lines[i].GetAmtSourceDr(), _lines[i].GetAmtSourceCr()); //} } // for all lines } else { _error = "DocumentType unknown: " + GetDocumentType(); log.Log(Level.SEVERE, _error); fact = null; } // facts.Add(fact); return(facts); }
/// <summary> /// Get Rate /// </summary> /// <param name="ctx"></param> /// <param name="fields"></param> /// <returns></returns> public Decimal GetRate(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); int CurFrom_ID; int CurTo_ID; DateTime?convDate; int ConversionType_ID; int AD_Client_ID; int AD_Org_ID; //Assign parameter value CurFrom_ID = Util.GetValueOfInt(paramValue[0].ToString()); CurTo_ID = Util.GetValueOfInt(paramValue[1].ToString()); convDate = System.Convert.ToDateTime(paramValue[2].ToString()); ConversionType_ID = Util.GetValueOfInt(paramValue[3].ToString()); AD_Client_ID = Util.GetValueOfInt(paramValue[4].ToString()); AD_Org_ID = Util.GetValueOfInt(paramValue[5].ToString()); //End Assign parameter value Decimal rate = MConversionRate.GetRate(CurFrom_ID, CurTo_ID, convDate, ConversionType_ID, AD_Client_ID, AD_Org_ID); return(rate); }
/// <summary> /// Create Facts (the accounting logic) for /// MXP. /// <pre> /// Product PPV <difference> /// PPV_Offset <difference> /// </pre> /// </summary> /// <param name="as1"></param> /// <returns></returns> public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); // if (GetM_Product_ID() == 0 || // Nothing to do if no Product Env.Signum(Utility.Util.GetValueOfDecimal(GetQty())) == 0 || _M_InOutLine_ID == 0) // No posting if not matched to Shipment { log.Fine("No Product/Qty - M_Product_ID=" + GetM_Product_ID() + ",Qty=" + GetQty()); return(facts); } // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); // Purchase Order Line Decimal poCost = _oLine.GetPriceCost(); if (Env.Signum(poCost) == 0) { poCost = _oLine.GetPriceActual(); } poCost = Decimal.Multiply(poCost, Utility.Util.GetValueOfDecimal(GetQty())); // Delivered so far // Different currency if (_oLine.GetC_Currency_ID() != as1.GetC_Currency_ID()) { MOrder order = _oLine.GetParent(); Decimal rate = MConversionRate.GetRate( order.GetC_Currency_ID(), as1.GetC_Currency_ID(), order.GetDateAcct(), order.GetC_ConversionType_ID(), _oLine.GetAD_Client_ID(), _oLine.GetAD_Org_ID()); if (rate.ToString() == null) { _error = "Purchase Order not convertible - " + as1.GetName(); return(null); } poCost = Decimal.Multiply(poCost, rate); if (Env.Scale(poCost) > as1.GetCostingPrecision()) { poCost = Decimal.Round(poCost, as1.GetCostingPrecision(), MidpointRounding.AwayFromZero); } } MOrder order1 = _oLine.GetParent(); bool isReturnTrx = order1.IsReturnTrx(); log.Fine("Temp"); if (!IsPosted()) { // Create PO Cost Detail Record firs MCostDetail.CreateOrder(as1, _oLine.GetAD_Org_ID(), GetM_Product_ID(), _M_AttributeSetInstance_ID, _C_OrderLine_ID, 0, // no cost element isReturnTrx ? Decimal.Negate(poCost) : poCost, isReturnTrx ? Decimal.Negate(Utility.Util.GetValueOfDecimal(GetQty())) : Utility.Util.GetValueOfDecimal(GetQty()), // Delivered _oLine.GetDescription(), GetTrx(), GetRectifyingProcess()); } // Current Costs String costingMethod = as1.GetCostingMethod(); MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); MProductCategoryAcct pca = MProductCategoryAcct.Get(GetCtx(), product.GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), GetTrx()); if (pca.GetCostingMethod() != null) { costingMethod = pca.GetCostingMethod(); } Decimal?costs = _pc.GetProductCosts(as1, GetAD_Org_ID(), costingMethod, _C_OrderLine_ID, false); // non-zero costs // No Costs yet - no PPV if (costs == null || Env.Signum(Utility.Util.GetValueOfDecimal(costs)) == 0) { _error = "Resubmit - No Costs for " + product.GetName(); log.Log(Level.SEVERE, _error); return(null); } // Difference Decimal difference = Decimal.Subtract(poCost, Utility.Util.GetValueOfDecimal(costs)); /***********************************************************************************/ //05,Sep,2011 //Special Check to restic Price varience posting in case of //AvarageInvoice Selected on product Category.Then Neglact the AverageInvoice Cost try { if (as1.IsNotPostPOVariance()) { difference = 0; } } catch (Exception ex) { log.SaveError("AccountSchemaColumnError", ex); } /***********************************************************************************/ // Nothing to post if (Env.Signum(difference) == 0) { log.Log(Level.FINE, "No Cost Difference for M_Product_ID=" + GetM_Product_ID()); facts.Add(fact); return(facts); } // Product PPV FactLine cr = fact.CreateLine(null, _pc.GetAccount(ProductCost.ACCTTYPE_P_PPV, as1), as1.GetC_Currency_ID(), difference); if (cr != null) { cr.SetQty(GetQty()); cr.SetC_BPartner_ID(_oLine.GetC_BPartner_ID()); cr.SetC_Activity_ID(_oLine.GetC_Activity_ID()); cr.SetC_Campaign_ID(_oLine.GetC_Campaign_ID()); cr.SetC_Project_ID(_oLine.GetC_Project_ID()); cr.SetC_UOM_ID(_oLine.GetC_UOM_ID()); cr.SetUser1_ID(_oLine.GetUser1_ID()); cr.SetUser2_ID(_oLine.GetUser2_ID()); } // PPV Offset FactLine dr = fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_PPVOffset, as1), as1.GetC_Currency_ID(), Decimal.Negate(difference)); if (dr != null) { dr.SetQty((Decimal?)Decimal.Negate(Utility.Util.GetValueOfDecimal(GetQty()))); dr.SetC_BPartner_ID(_oLine.GetC_BPartner_ID()); dr.SetC_Activity_ID(_oLine.GetC_Activity_ID()); dr.SetC_Campaign_ID(_oLine.GetC_Campaign_ID()); dr.SetC_Project_ID(_oLine.GetC_Project_ID()); dr.SetC_UOM_ID(_oLine.GetC_UOM_ID()); dr.SetUser1_ID(_oLine.GetUser1_ID()); dr.SetUser2_ID(_oLine.GetUser2_ID()); } // facts.Add(fact); return(facts); }
/// <summary> /// Apply Payment Term with schedule to order /// </summary> /// <param name="order">Order</param> /// <param name="_sch">Payment Term Schedule</param> private void ApplyAdvanceSchedule(MOrder order, MPaySchedule _sch) { MVA009OrderPaySchedule ips = null; Decimal remainder = order.GetGrandTotal(); #region IsAdvance true on Schedule if (_sch.IsVA009_Advance()) { ips = new MVA009OrderPaySchedule(order, _sch); ips.SetVA009_ExecutionStatus("A"); MOrder _Order = new MOrder(GetCtx(), order.GetC_Order_ID(), Get_TrxName()); ips.SetVA009_PaymentMethod_ID(order.GetVA009_PaymentMethod_ID()); ips.SetC_PaymentTerm_ID(order.GetC_PaymentTerm_ID()); ips.SetVA009_GrandTotal(order.GetGrandTotal()); MPaymentTerm payterm = new MPaymentTerm(GetCtx(), order.GetC_PaymentTerm_ID(), Get_TrxName()); int _graceDay = payterm.GetGraceDays(); ips.SetVA009_FollowupDate(ips.GetDueDate().Value.AddDays(_graceDay)); ips.SetVA009_PlannedDueDate(ips.GetDueDate()); int BaseCurrency = GetCtx().GetContextAsInt("$C_Currency_ID"); if (BaseCurrency != order.GetC_Currency_ID()) { decimal multiplyRate = MConversionRate.GetRate(order.GetC_Currency_ID(), BaseCurrency, order.GetDateAcct(), order.GetC_ConversionType_ID(), order.GetAD_Client_ID(), order.GetAD_Org_ID()); ips.SetVA009_OpenAmnt(ips.GetDueAmt() * multiplyRate); } else { ips.SetVA009_OpenAmnt(ips.GetDueAmt()); } // Get Next Business Day if Next Business Days check box is set to true DateTime?payDueDate = null; if (payterm.IsNextBusinessDay()) { payDueDate = payterm.GetNextBusinessDate(ips.GetDueDate()); ips.SetDueDate(payDueDate); payDueDate = payterm.GetNextBusinessDate(ips.GetDiscountDate()); ips.SetDiscountDate(payDueDate); } ips.SetC_Currency_ID(order.GetC_Currency_ID()); ips.SetVA009_BseCurrncy(BaseCurrency); ips.SetVA009_OpnAmntInvce(ips.GetDueAmt()); ips.SetC_BPartner_ID(order.GetC_BPartner_ID()); string sql = "SELECT VA009_PaymentMode, VA009_PaymentType, VA009_PaymentTrigger FROM VA009_PaymentMethod WHERE VA009_PaymentMethod_ID=" + order.GetVA009_PaymentMethod_ID() + " AND IsActive = 'Y' AND AD_Client_ID = " + order.GetAD_Client_ID(); DataSet ds = new DataSet(); ds = DB.ExecuteDataset(sql); if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { ips.SetVA009_PaymentMode(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentMode"])); if (!String.IsNullOrEmpty(Convert.ToString(ds.Tables[0].Rows[0]["VA009_PaymentType"]))) { ips.SetVA009_PaymentType(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentType"])); } ips.SetVA009_PaymentTrigger(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentTrigger"])); ips.SetVA009_ExecutionStatus("A"); } ips.SetProcessed(true); ips.Save(order.Get_TrxName()); log.Fine(ips.ToString()); remainder = Decimal.Subtract(remainder, ips.GetDueAmt()); } #endregion }
/// <summary> /// Apply Payment Term without schedule to Order /// </summary> /// <param name="order">Order</param> private void ApplyAdvanceTermSchedule(MOrder order) { //for(int i=0;i<_schedule.Length;i++)) StringBuilder _sql = new StringBuilder(); Decimal remainder = order.GetGrandTotal(); MVA009OrderPaySchedule schedule = new MVA009OrderPaySchedule(GetCtx(), 0, Get_TrxName()); MPaymentTerm payterm = new MPaymentTerm(GetCtx(), order.GetC_PaymentTerm_ID(), Get_TrxName()); schedule.SetAD_Client_ID(order.GetAD_Client_ID()); schedule.SetAD_Org_ID(order.GetAD_Org_ID()); schedule.SetC_Order_ID(order.GetC_Order_ID()); schedule.SetC_PaymentTerm_ID(order.GetC_PaymentTerm_ID()); schedule.SetVA009_PaymentMethod_ID(order.GetVA009_PaymentMethod_ID()); //schedule.SetDueDate(GetDueDate(order)); // Get Next Business Day if Next Business Days check box is set to true DateTime?payDueDate = null; if (payterm.IsNextBusinessDay()) { payDueDate = payterm.GetNextBusinessDate(TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetNetDays())); } else { payDueDate = TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetNetDays()); } schedule.SetDueDate(payDueDate); schedule.SetDueAmt(order.GetGrandTotal()); if (payterm.IsNextBusinessDay()) { payDueDate = payterm.GetNextBusinessDate(TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetDiscountDays())); } else { payDueDate = TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetDiscountDays()); } schedule.SetDiscountDate(payDueDate); //schedule.SetDiscountDate(order.GetDateOrdered().Value.AddDays(Util.GetValueOfInt(payterm.GetDiscountDays()))); schedule.SetDiscountAmt((Util.GetValueOfDecimal((order.GetGrandTotal() * payterm.GetDiscount()) / 100))); if (payterm.IsNextBusinessDay()) { payDueDate = payterm.GetNextBusinessDate(TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetDiscountDays2())); } else { payDueDate = TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetDiscountDays2()); } schedule.SetDiscountDays2(payDueDate); //schedule.SetDiscountDays2(order.GetDateOrdered().Value.AddDays(Util.GetValueOfInt(payterm.GetDiscountDays2()))); schedule.SetDiscount2((Util.GetValueOfDecimal((order.GetGrandTotal() * payterm.GetDiscount2()) / 100))); schedule.SetVA009_PlannedDueDate(GetDueDate(order)); int BaseCurrency = GetCtx().GetContextAsInt("$C_Currency_ID"); if (BaseCurrency != order.GetC_Currency_ID()) { decimal multiplyRate = MConversionRate.GetRate(order.GetC_Currency_ID(), BaseCurrency, order.GetDateAcct(), order.GetC_ConversionType_ID(), order.GetAD_Client_ID(), order.GetAD_Org_ID()); schedule.SetVA009_OpenAmnt(order.GetGrandTotal() * multiplyRate); } else { schedule.SetVA009_OpenAmnt(order.GetGrandTotal()); } schedule.SetC_Currency_ID(order.GetC_Currency_ID()); schedule.SetVA009_BseCurrncy(BaseCurrency); schedule.SetVA009_OpnAmntInvce(order.GetGrandTotal()); schedule.SetC_BPartner_ID(order.GetC_BPartner_ID()); MOrder _Order = new MOrder(GetCtx(), order.GetC_Order_ID(), Get_TrxName()); //schedule.SetVA009_PaymentMethod_ID(_Order.GetVA009_PaymentMethod_ID()); //schedule.SetC_PaymentTerm_ID(_Order.GetC_PaymentTerm_ID()); int _graceDay = payterm.GetGraceDays(); DateTime?_followUpDay = GetDueDate(order); schedule.SetVA009_FollowupDate(_followUpDay.Value.AddDays(_graceDay)); _sql.Clear(); _sql.Append("SELECT VA009_PaymentMode, VA009_PaymentType, VA009_PaymentTrigger FROM VA009_PaymentMethod WHERE VA009_PaymentMethod_ID=" + order.GetVA009_PaymentMethod_ID() + " AND IsActive = 'Y' AND AD_Client_ID = " + order.GetAD_Client_ID()); DataSet ds = new DataSet(); ds = DB.ExecuteDataset(_sql.ToString()); if (ds != null && ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { schedule.SetVA009_PaymentMode(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentMode"])); schedule.SetVA009_PaymentType(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentType"])); schedule.SetVA009_PaymentTrigger(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentTrigger"])); schedule.SetVA009_ExecutionStatus("A"); } // updateInvoice if (!schedule.Save()) { ValueNamePair pp = VLogger.RetrieveError(); log.Info("Error found during creation of Order Schedule against Order ID = " + order.GetC_Order_ID() + " Error Name is " + pp.GetName()); } }