Topic: Recurring expenses

I still couldn't do a working script for recurrence..


What I like to do is:
If an expense entered with "This is a recurring expense" checkbox checked, Recurring every... specified on combobox, Recurrence date and time specified and saved then application saves a new expense with same values at specified period, date and time automatically until "This is a recurring expense" checkbox unchecked.


Please see the sample project attached:

Post's attachments

Attachment icon Recurring Expenses.zip 14.67 kb, 403 downloads since 2017-03-22 

Adam
God... please help me become the person my dog thinks I am.

Re: Recurring expenses

Unfortunately I can help you only with specific question.

Dmitry.

Re: Recurring expenses

AD1408 wrote:

I
If an expense entered with "This is a recurring expense" checkbox checked, Recurring every... specified on combobox, Recurrence date and time specified and saved then application saves a new expense with same values at specified period, date and time automatically until "This is a recurring expense" checkbox unchecked.

In line of the description above, how can I create a recurring event script, in this case recurring expense?
(With reference to attached sample project on post #1)

Adam
God... please help me become the person my dog thinks I am.

Re: Recurring expenses

Adam,
Before a script can be developed, there needs to be a design question answered. Something needs to trigger the creation of a new expense record for a recurring expense. What is that trigger? It needs to be a button click or some sort of event (such as when an expense is paid or something) to cause the next expense record creation for a recurring expense. This needs to be answered first.

Re: Recurring expenses

Hi EHW,

Thanks for the info....
The problem is I know what I want to do but don't know how to do it.
All I can think of that initial trigger is recurring expense checkbox is checked or not. I made the following flowchart in an attempt to clarify bit further. I'm open to suggestions, perhaps there is simpler way to do it?
https://s29.postimg.org/wbtm6gtyv/recurring_01.png

Adam
God... please help me become the person my dog thinks I am.

Re: Recurring expenses

After thinking a bit, initial trigger is recurring checkbox is checked then save button trigger when first expense saved with recurring checkbox is checked?

Adam
God... please help me become the person my dog thinks I am.

Re: Recurring expenses

That might work for the first time of the expense, but it still does not answer when to create the next expense. I didn't want to leave you hanging so I incorporated the trigger based on an expense being paid. In the attached project, there is a button called Paid. Upon clicking this button the expense will be identified as Paid and if it is a recurring expense then the next expense record will automatically be created. The date of the next expense is based on the recurring every... combobox.  Hopefully this will help set you in the direction you want.

Post's attachments

Attachment icon Recurring Expenses 2.zip 350.25 kb, 409 downloads since 2017-03-28 

Re: Recurring expenses

Hi EHW,


Thank you very much for your kind help...................


I get script error message: near "," : syntax error, which I couldn't spot and correct.
when choosing day from recurring every... combo without checking date and time fields
when choosing week, fortnight, month, quarter and annually from recurring every... combo with or without checking date and time fields.


That might work for the first time of the expense, but it still does not answer when to create the next expense.

My thinking was that date and time below recurring every... combobox would be the answer.


Currently, it saves and displays two expense record, one for actual current expense and one for recurring expense on creation of an expense record. Tha's fine but could we have recurring one displayed on specified date and time below recurring every... combobox on tGrid?

Adam
God... please help me become the person my dog thinks I am.

Re: Recurring expenses

Not sure why you are getting a script error. I don't, no matter what entry is selected in the combobox. I did not use the recurring date and time, so it does not matter whether they are checked or not.

10 (edited by AD1408 2017-03-29 17:15:38)

Re: Recurring expenses

I used MVD v2.7 and 3.3 to compile. In both, I get the following error:
https://s13.postimg.org/4rb80q17b/zzzzz_Temp10.png

Adam
God... please help me become the person my dog thinks I am.

11 (edited by ehwagner 2017-03-30 00:24:30)

Re: Recurring expenses

It looks like you are getting the error when you are adding an expense simultaneous to paying it, which is fine. The qty appears to be empty which is causing the error.  I would assume this should never be the case, but to fix this particular situation you can set the default value to 0 for Qty on your Expense form

https://s10.postimg.org/ptvvg9dc9/Qty_Default.jpgimage host

Re: Recurring expenses

Thanks a lot EHW.....
You are right, setting Qty default value to zero fixes the error.


You have done a great work on this EHW... Appreciated very much....


Now if only you or anybody else could use combination of
Recurring expense checkbox
Recurrence Date
Recurrence Time
as a trigger, instead of paid label/button and show recurring expense records on the grid when they recur!!!!

Adam
God... please help me become the person my dog thinks I am.

Re: Recurring expenses

Ok Adam, I think I have put together something that I think you are looking for. I took out all the Paid stuff and put it back to what you had prior. Now the application, upon startup, will check to see if the Recur Date on all recurring expenses has arrived and if it has the appication will create the next expense record at that time. It will turnoff the recurring flag of the original so that it will not create a duplicate expense the next time you start the application.


If you accidentally delete the latest recurring expense, you can go back to the prior expense in the series and turn on the recurring checkbox and set the recurring value combobox and you are all set. The app will re-create the recurring expense the next time you startup.


I did not use the Recur Time. I don't think it's necessary. I don't think there are hourly expenses that you have to check each hour.


Hopefully this is closer to what you want. I'm not in a position where I can spend a lot of time on this, but I'll help you as much as I can. If others have any other ideas on this, they should chime in. I'm certainly not professing that my way is the only way.

Post's attachments

Attachment icon Recurring Expenses 3.zip 351.54 kb, 401 downloads since 2017-03-30 

Re: Recurring expenses

Hi EHW,


Thank you very much................
Truly appreciated.........


Indeed, in this case time is not needed. It was intended for defining what time of the selected period and date recurring expense should be created, but I can do without it.


However, application crashes and refuses to re-start.
Steps:
1. Added a backdated expense and marked as recurring on daily basis to test recurrence.
2. Closed the app.
3. Tried to run .exe again and app didn't start. I got windows ... has stopped working. message
4. Deleted database file and re-run but same, app cannot start.


I put this for your info, without any expectation of you correcting it.  Already, you have been very kind with your help on this and many other ones. So, please don't feel under any obligation whatsoever to put any further time into this project. Perhaps others may offer help on this and we can have a working recurring event script.

Adam
God... please help me become the person my dog thinks I am.

Re: Recurring expenses

Hmmm....Not sure what's going on. How far back did you make the date for the daily expense recurrence. If you go back years, it will create an expense record for each day from that date forward till tomorrow. And if you do that for multiple expenses it will take some time to insert/update records before the app shows the first form. I tested a single daily recurrence and went back a full year, which is highly unlikely in real life.  It took maybe 20 seconds or so before the first form shows, but it did not crash or anything like that. And the app restarted fine. Try emptying your database and start fresh again.

16 (edited by AD1408 2017-03-31 19:21:30)

Re: Recurring expenses

Thanks EHW,

Cleared old data within app and added new recurring item backdated only for few days as seen on the screen cap below. This time no crash. However, there are no recurring items displayed. I didn't touch the script or any settings.

Either I'm doing something wrong or your latest upload is not the same as one you are testing.


https://s17.postimg.org/8dn0dd99r/zzzzz_Temp11.png

Adam
God... please help me become the person my dog thinks I am.

Re: Recurring expenses

Thanks for the screenshot Adam. I think maybe it did not work because it looks like your date fields are DD/MM/YYYY where I have it as MM/DD/YYYY. So I made a small change in my script to reverse the day and month. See if the attached corrects the situation.

Post's attachments

Attachment icon Recurring Expenses 4.zip 354.78 kb, 418 downloads since 2017-03-31 

Re: Recurring expenses

Great stuff EHW...........


I think it works now. I tested back dated 5 days. It display recurring items not after save but after restarting the application. I assume it's due to using back date?


It'd be great if date format read from windows date settings rather than hard coding. I changed my windows7 date format from dd/MM//YYYY to YYYY/MM/DD and it crashed on run.

Adam
God... please help me become the person my dog thinks I am.

Re: Recurring expenses

It only creates new recurring expenses at application startup.


If you changed your date format to MM/DD/YYYY then just go back to Recurring Expenses 3.zip and use that project.

Re: Recurring expenses

Hi Adam, Hi EHW,
I was wondering if you could take a slightly different approach to this issue which might eliminate some of the complications.  My idea is as follows:
1.  For recurring expenses, use both an  'expense from' date and an 'expense until' date (I suspect most recurring expenses WOULD have an end date rather than being totally open-ended).
2.  Specify the frequency of expense payment (ie daily, monthly etc)
3.  When you click 'save', immediately create ALL the expense payment records (ie, for a recurring monthly expense that lasts for 12 months, create 12 records where the expense date of the first record = 'expense from' date, the expense date of the second record = 'expense from' date + 1 month etc etc
4.  Filter your main tablegrid to only show expenses due by the current date or earlier.
Using this approach, the whole question of 'when do you generate the next recurring expense record and what is the trigger' simply goes away - they're already there and waiting.
It also has the added benefit of being able to see what future expenses you are committed to but which aren't yet due (ie what are my recurring expense commitments next month etc etc)..
Anyway, have a look at the attachment and maybe it will help.
Please note - I used EXCEL to generate my test data rather than writing any of the script that would be needed to insert records when 'save' is clicked - but the script that EHW has written already does most of what is needed (it looks like you'd basically be using the 'expense until' date rather than 'today').  I didn't have the time to modify it (and I suspect I'd have struggled anyway - it's a really neat bit of coding).
Regards,
Derek.

Post's attachments

Attachment icon adh recurring.zip 339.94 kb, 425 downloads since 2017-04-01 

21 (edited by AD1408 2017-04-02 19:35:07)

Re: Recurring expenses

Hi Derek,


Thank you very much for your kind contribution........ Appreciated....


While your approach have some nice points but the solution I was looking for is in line of EHW's approach. He has done great work on this. Only missing parts IMHO are:


1. Date format is need to be taken from the user OS rather than hard coding in the app; so that app runs on different machines with different date formats.
2. As recurring expense entered and saved automatically should be displayed on form1 expenses tgrid without the need of restarting the app. Perhaps adding refresh button on form1 where expenses tGrid is may eliminate the need of restart..

Adam
God... please help me become the person my dog thinks I am.

22 (edited by ehwagner 2017-04-03 05:33:30)

Re: Recurring expenses

Adam,  Maybe the attached is a little closer. On initially entering in an expense that is recurring, the system will generate the next recurrence of the expense when saving and show on the grid. From then on, the other process (App Start process) will take over from there to generate the remaining recurring expenses as they are to occur.

The reason for the manually generating the date format in the bulk processing of recurring expenses is because I could not extract the date from the dataset as a date for MVD to recognize. I had to extract it as a string and manipulate it to a date format in order to add days, weeks, months... to it. Maybe Dimitry could assist with this. Here is the line in the project that I was having trouble extracting as a date so instead I used "AsString".

ExpResults.FieldByName('Date(recurDate)').AsString;
Post's attachments

Attachment icon Recurring Expenses 5.zip 357.25 kb, 410 downloads since 2017-04-03 

Re: Recurring expenses

Thanks a lot EHW...............
Still crashes but I think it's irrelevant at this point as date issue needs to be sorted out.


Dmitry,
Could you please help us sorting date issue on this project, so that date format can be read from the user system (OS) rather than trying to manipulate it as EHW explained on the post above #22

Adam
God... please help me become the person my dog thinks I am.

Re: Recurring expenses

AD1408 wrote:

Dmitry,
Could you please help us sorting date issue on this project, so that date format can be read from the user system (OS) rather than trying to manipulate it as EHW explained on the post above #22


Please describe the issue in the one post or create a new topic for the issue.

Dmitry.

25 (edited by AD1408 2017-04-06 23:16:04)

Re: Recurring expenses

DriveSoft wrote:

Please describe the issue in the one post or create a new topic for the issue.


Hi Dmitry,


EHW did a great work on  recurring events - in this case recurring expenses. Two items need your kind attention. Please see the attached sample project EHW coded.


1. Date format is need to be taken from the user OS rather than hard coding in the app (Like MVD date and time component does); so that app runs on different machines with different date formats.


2. As recurring expense entered and saved automatically when they are due, it should be displayed on form1 expenses tgrid without the need of restarting the app. Currently, app needs to be restarted in order to saved recurring expenses to be displayed on form1 tGrid. Perhaps adding refresh button (kind of forced on show event) on form1 / expenses tGrid  may eliminate the need of restart..

Post's attachments

Attachment icon Recurring Expenses 4EHW.zip 22.03 kb, 427 downloads since 2017-04-07 

Adam
God... please help me become the person my dog thinks I am.