protected override string DoIt() { order = new MOrder(GetCtx(), GetRecord_ID(), Get_TrxName()); pt = new MPaymentTerm(GetCtx(), order.GetC_PaymentTerm_ID(), Get_TrxName()); CreateOrderPaySchedule(); return(" "); }
// Added by Bharat on 13/May/2017 public Dictionary <string, string> GetPaymentNote(Ctx ctx, string fields) { int C_PaymentTerm_ID = 0; C_PaymentTerm_ID = Util.GetValueOfInt(fields); MPaymentTerm pt = new MPaymentTerm(ctx, C_PaymentTerm_ID, null); Dictionary <string, string> retVal = new Dictionary <string, string>(); retVal["DocumentNote"] = pt.GetDocumentNote(); return(retVal); }
/// <summary> /// Get Due Date based on the settings on Payment Term. /// </summary> /// <param name="order">Order</param> /// <returns>Datetime, Due Date</returns> private DateTime?GetDueDate(MOrder order) { MPaymentTerm payterm = new MPaymentTerm(GetCtx(), order.GetC_PaymentTerm_ID(), Get_TrxName()); String _sql = "SELECT PAYMENTTERMDUEDATE (C_PaymentTerm_ID, DateOrdered) AS DueDate FROM C_Order WHERE C_Order_ID=" + order.GetC_Order_ID(); DateTime? _dueDate = Util.GetValueOfDateTime(DB.ExecuteScalar(_sql.ToString(), null, Get_TrxName())); if (_dueDate == Util.GetValueOfDateTime("1/1/0001 12:00:00 AM")) { _dueDate = DateTime.Now; } return(_dueDate); }
} // prepare /// <summary> /// Perrform Process. /// </summary> /// <returns> Message</returns> protected override String DoIt() { log.Info("C_PaymentTerm_ID=" + GetRecord_ID()); MPaymentTerm pt = new MPaymentTerm(GetCtx(), GetRecord_ID(), Get_TrxName()); String msg = pt.Validate(); pt.Save(); // if ("@OK@".Equals(msg)) { return(msg); } throw new Exception(msg); } // doIt
/// <summary> /// GetPaymentTerm /// </summary> /// <param name="ctx"></param> /// <param name="fields"></param> /// <returns></returns> public Dictionary <string, string> GetPaymentTerm(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); int C_PaymentTerm_ID; int C_Invoice_ID; //Assign parameter value C_PaymentTerm_ID = Util.GetValueOfInt(paramValue[0].ToString()); C_Invoice_ID = Util.GetValueOfInt(paramValue[1].ToString()); //End Assign parameter value MPaymentTerm pt = new MPaymentTerm(ctx, C_PaymentTerm_ID, null); Dictionary <string, string> retVal = new Dictionary <string, string>(); retVal["Apply"] = pt.Apply(C_Invoice_ID).ToString(); retVal["Get_ID"] = pt.Get_ID().ToString(); return(retVal); }
/// <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()); } }