Hook Requests - FormPayPlan and CreditCards

This forum is for programmers who have questions about the source code.
Post Reply
dporter
Posts: 18
Joined: Thu Jan 07, 2010 8:58 am
Contact:

Hook Requests - FormPayPlan and CreditCards

Post by dporter » Wed Jan 29, 2014 10:44 pm

Please add the following hooks. I'd be ultra happy to see these back ported to 13.2.

FormPayPlan.cs around line 896 at the end of FormPayPlan_Load:

Code: Select all

FillCharges();
Plugins.HookAddCode(this, "FormPayPlan.FormPayPlan_Load_end");
FormPayPlan.cs around line 1133 in the middle of butCreateSched_Click. This is a goto HookMethod:

Code: Select all

			if(table.Rows.Count>0){
				if(!MsgBox.Show(this,true,"Replace existing amortization schedule?")){
					return;
				}
				PayPlanCharges.DeleteAllInPlan(PayPlanCur.PayPlanNum);
			}

            if (Plugins.HookMethod(this, "FormPayPlan.butCreateSched_Click", PayPlanCur, PatCur, (GroupBox)this.Controls.Find("groupBox2", true)[0]))
            {
                goto HookSkipToFillCharges;
            }

			PayPlanCharge ppCharge;
The goto HookSkipToFillCharges; is in FormPayPlan around line 1230 in the butCreateSched_Click method just before the call to FillCharges():

Code: Select all

				PayPlanCharges.Insert(ppCharge);
				countCharges++;
			}

            HookSkipToFillCharges: { }

			FillCharges();
CreditCards.cs around line 144 at the beginning of the FilterRecurringChargeList() method:

Code: Select all

		public static void FilterRecurringChargeList(DataTable table) {

            if (Plugins.HookMethod(null, "CreditCards.FilterRecurringChargeList"))
            {
                return;
            }

dporter
Posts: 18
Joined: Thu Jan 07, 2010 8:58 am
Contact:

Re: Hook Requests - FormPayPlan and CreditCards

Post by dporter » Sat Feb 01, 2014 7:45 am

Did I post this request in the right place?

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: Hook Requests - FormPayPlan and CreditCards

Post by allends » Sat Feb 01, 2014 9:16 am

Yes. I will get this added as soon as possible.
Allen
Open Dental Software
http://www.opendental.com

dporter
Posts: 18
Joined: Thu Jan 07, 2010 8:58 am
Contact:

Re: Hook Requests - FormPayPlan and CreditCards

Post by dporter » Sat Feb 01, 2014 12:31 pm

Thanks Allen.

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: Hook Requests - FormPayPlan and CreditCards

Post by allends » Tue Feb 04, 2014 9:51 am

dporter wrote: CreditCards.cs around line 144 at the beginning of the FilterRecurringChargeList() method:

Code: Select all

		public static void FilterRecurringChargeList(DataTable table) {

            if (Plugins.HookMethod(null, "CreditCards.FilterRecurringChargeList"))
            {
                return;
            }
I was wondering why you need this hook in the business layer of OD :?: If you are looking to do something different then the current FilterRecurringChargeList, you could recreate it with a HookAddCode.
Putting a plug-in hook into the business layer means that it could accidentally be used in other places in the program that it was not intended to be used at. :|
Allen
Open Dental Software
http://www.opendental.com

dporter
Posts: 18
Joined: Thu Jan 07, 2010 8:58 am
Contact:

Re: Hook Requests - FormPayPlan and CreditCards

Post by dporter » Tue Feb 04, 2014 11:48 am

Actually, I just discovered that you guys are adding flexible payment dates to payment plans in version 13.3. All of the hooks requested in this thread were to create this functionality ourselves in our plugin. I'm digging through the 13.3 code now to make sure it fits our needs. If this feature makes it in the next release then I no longer need these hooks.

Do you have a timeline for 13.3?

Thanks...Damon

dporter
Posts: 18
Joined: Thu Jan 07, 2010 8:58 am
Contact:

Re: Hook Requests - FormPayPlan and CreditCards

Post by dporter » Tue Feb 04, 2014 12:20 pm

Looks like you are still working on these payment plan options. I still see the same problem with the CreditCards.FilterRecurringChargeList() method. Using 13.3 I selected the option to have the payment plan run weekly, however, the payment is removed from the load of the Grid after a successful payment in the month. This will always prevent more than 1 payment in the same month. This filter needs to be removed now that we can select weekly or every other week. Here is the problem code block for this feature:

Code: Select all

		///<summary>Talbe must include columns labeled LatestPayment and DateStart.</summary>
		public static void FilterRecurringChargeList(DataTable table) {
			DateTime curDate=MiscData.GetNowDateTime();
			//Loop through table and remove patients that do not need to be charged yet.
			for(int i=0;i<table.Rows.Count;i++) {
				DateTime latestPayment=PIn.Date(table.Rows[i]["LatestPayment"].ToString());
				DateTime dateStart=PIn.Date(table.Rows[i]["DateStart"].ToString());
				if(curDate>latestPayment.AddDays(31)) {//if it's been more than a month since they made any sort of payment
					//if we reduce the days below 31, then slighly more people will be charged, especially from Feb to March.  31 eliminates those false positives.
					continue;//charge them
				}
				//Not enough days in the current month so show on the last day of the month
				//Example: DateStart=8/31/2010 and the current month is February 2011 which does not have 31 days.
				//So the patient needs to show in list if current day is the 28th (or last day of the month).
				int daysInMonth=DateTime.DaysInMonth(curDate.Year,curDate.Month);
				if(daysInMonth<=dateStart.Day && daysInMonth==curDate.Day && curDate.Date!=latestPayment.Date) {//if their recurring charge would fall on an invalid day of the month, and this is that last day of the month
					continue;//we want them to show because the charge should go in on this date.
				}
				if(curDate.Day>=dateStart.Day) {//If the recurring charge date was earlier in this month, then the recurring charge will go in for this month.
					if(curDate.Month>latestPayment.Month || curDate.Year>latestPayment.Year) {//if the latest payment was last month (or earlier).  The year check catches December
						continue;//No payments were made this month, so charge.
					}
				}
				else {//Else, current date is before the recurring date in the current month, so the recurring charge will be going in for last month
					//Check if payment didn't happen last month.
					if(curDate.AddMonths(-1).Month!=latestPayment.Month && curDate.Date!=latestPayment.Date) {
						//Charge did not happen last month so the patient needs to show up in list.
						//Example: Last month had a recurring charge set at the end of the month that fell on a weekend.
						//Today is the next month and still before the recurring charge date. 
						//This will allow the charge for the previous month to happen if the 30 day check didn't catch it above.
						continue;
					}
				}
				//Patient doesn't need to be charged yet so remove from the table.
				table.Rows.RemoveAt(i);
				i--;
			}
		}

dporter
Posts: 18
Joined: Thu Jan 07, 2010 8:58 am
Contact:

Re: Hook Requests - FormPayPlan and CreditCards

Post by dporter » Tue Feb 04, 2014 2:59 pm

FYI...there is another method that will need to change in order to make weekly, bi-weekly payment plans work.

FormCreditRecurringCharges.GetPayDate() is only looking at days in the current or previous month. The current code will always return the day of the month that the payment plan started as the PayDate that gets stored in PaySplit.DatePay. This effects the Production and Income report because for some reason it uses PaySplit.DatePay instead of PaySplit.DateEntry.

Code: Select all

		///<summary>Returns a valid DateTime for the payment's PayDate.  Contains logic if payment should be for the previous or the current month.</summary>
		private DateTime GetPayDate(DateTime latestPayment,DateTime dateStart) {
			//Most common, current day >= dateStart so we use current month and year with the dateStart day.  Will always be a legal DateTime.
			if(nowDateTime.Day>=dateStart.Day) {
				return new DateTime(nowDateTime.Year,nowDateTime.Month,dateStart.Day);
			}
			//If not enough days in current month to match the dateStart see if on the last day in the month.
			//Example: dateStart=08/31/2009 and month is February 28th so we need the PayDate to be today not for last day on the last month, which would happen below.
			int daysInMonth=DateTime.DaysInMonth(nowDateTime.Year,nowDateTime.Month);
			if(daysInMonth<=dateStart.Day && daysInMonth==nowDateTime.Day) {
				return nowDateTime;//Today is last day of the month so return today as the PayDate.
			}
			//PayDate needs to be for the previous month so we need to determine if using the dateStart day would be a legal DateTime.
			DateTime nowMinusOneMonth=nowDateTime.AddMonths(-1);
			daysInMonth=DateTime.DaysInMonth(nowMinusOneMonth.Year,nowMinusOneMonth.Month);
			if(daysInMonth<=dateStart.Day) {
				return new DateTime(nowMinusOneMonth.Year,nowMinusOneMonth.Month,daysInMonth);//Returns the last day of the previous month.
			}
			return new DateTime(nowMinusOneMonth.Year,nowMinusOneMonth.Month,dateStart.Day);//Previous month contains a legal date using dateStart's day.
		}

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: Hook Requests - FormPayPlan and CreditCards

Post by allends » Fri Feb 14, 2014 2:02 pm

Adding the new payment plan options to work with Recurring Charges is another feature request. Since this feature was just released in public beta it will be get triaged soon as how important updating it is.
As for your plugin, to make it work you may need to change the method that is called in the CreditCards.cs class since we don't put plugin-hooks in the business layer. :|
Allen
Open Dental Software
http://www.opendental.com

Post Reply