/// <summary> /// Get Payment Term Schedules /// </summary> /// <param name="requery">true or False</param> /// <returns>List of Schedules</returns> private MPaySchedule[] GetSchedule(bool requery) { MPaySchedule ps = null; if (_schedule != null && !requery) { return(_schedule); } // JID_0831: If Payment term header is valid but having lines with advance and Inactive. System should consider that as 100% immedate. However, system is creating schedule of advance on order. String sql = "SELECT * FROM C_PaySchedule WHERE IsActive = 'Y' AND VA009_Advance = 'Y' AND C_PaymentTerm_ID=" + order.GetC_PaymentTerm_ID() + " ORDER BY NetDays"; List <MPaySchedule> list = new List <MPaySchedule>(); try { DataSet ds = VAdvantage.DataBase.DB.ExecuteDataset(sql, null, Get_TrxName()); if (ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { ps = new MPaySchedule(GetCtx(), dr, Get_TrxName()); ps.SetParent(pt); list.Add(ps); } } } catch (Exception e) { log.Log(Level.SEVERE, "GetSchedule", e); } _schedule = new MPaySchedule[list.Count]; _schedule = list.ToArray(); return(_schedule); }
/// <summary> /// Create Order Payment Schedules /// </summary> private void CreateOrderPaySchedule() { if (order == null || order.Get_ID() == 0) { log.Log(Level.SEVERE, "No valid order - " + order); //return false; } GetSchedule(true); DeleteOrderPaySchedule(order.GetC_Order_ID(), order.Get_TrxName()); if (pt.IsVA009_Advance() && pt.IsValid()) { ApplyAdvanceTermSchedule(order); } else { for (int i = 0; i < _schedule.Length; i++) { MPaySchedule _sch = new MPaySchedule(GetCtx(), _schedule[i].GetC_PaySchedule_ID(), Get_TrxName()); if (_sch.IsVA009_Advance()) { ApplyAdvanceSchedule(order, _sch); } //break; } } }
/// <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 }