Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Schedules #14

Open
KieranP opened this issue May 16, 2009 · 3 comments
Open

Feature: Schedules #14

KieranP opened this issue May 16, 2009 · 3 comments

Comments

@KieranP
Copy link

KieranP commented May 16, 2009

Details

Everyone has payments that need to go out weekly, fortnightly etc. Schedules would work with these payments and in combination with buckets, to ensure they that amounts needed are met on time by indicating via green/orange/red current values for scheduled events, and to automatically create expenses that have occurred since your last login. The reverse where money is expected on a regular basis would in turn add deposits that occurred since your last login. This makes management of bills/automatic payments easier to keep track of. It would also be constructed so that if a expense/deposit is created, you'll get alerts on the dashboard to review the payments made, with the ability to delete that payment, amend etc.

Model Implementation

  • User has many schedules
  • Bucket has many actions, has many schedules through actions
  • Schedule model that belongs to account, has user through account, has many actions, has many buckets through actions. Has the fields:
    • id
    • account_id
    • name
    • scheduled_time
    • recurrence (in # weeks)
    • last_executed
  • Action model that belongs to schedule, belongs to bucket. Has the fields:
    • id
    • schedule_id
    • bucket_id
    • type (expense/deposit/transfer)
    • amount (in $)

Routes Implementation

  • /accounts/1/schedules
  • /accounts/1/schedules/new
  • /accounts/1/schedules/edit/5
  • /accounts/1/schedules/show/5
  • /accounts/1/schedules/destroy/5
  • /buckets/5/schedules

UI Implementation

  • Dashboard, Buckets show, and accounts show would get new widget "Upcoming Schedules" listing name and when. Clicking will take them to schedule show page, listing the actions that schedule has in details (what type, what bucket, how much) and showing how much in in there at present in the buckets it'll be taking action in. Depending on the pages visited, schedules will be constrained to that area (dash = all, account = only in account, bucket = only in bucket).
  • Dashboard would get new widget "Recent Alerts" listing events that took place since the last login, with links to each transaction that took place for review.
    • (you may know of a faster more efficient way to do this, but the idea is here)
    • When you login, schedules are checked against the current time, scheduled time, and the last executed time. Formula for finding schedules via SQL is something like WHERE (Time.now > schedule.scheduled_time AND schedule.scheduled_time > schedule.last_executed ) (essentially, run schedules that have occurred prior to now, but after the last execution).
    • The schedule is then executed (its actions are run, depositing/subtracting money from the baskets it's tied to). and the alerts model is then populated as needed in a before_filter so alerts are available on the next request
    • The schedule is then either deleted if it isn't needed again, or is updated with Time.now for the execution time, and scheduled_time becomes scheduled_time + recurrence.weeks (where recurrence is number weeks after the last scheduled_time that is should run again)
    • A query is run again to ensure no more schedules have taken place (incase user doesn't login for 2/3 weeks. Something like this
      • while Schedule.count(:conditions => "#{Time.now} > schedule.scheduled_time AND schedule.scheduled_time > schedule.last_executed") > 0
  • Any place where buckets are listed (account buckets, dashboard etc) get modified to include amounts of transactions coming within 7 days of today. The label will be colored according to time remaining and money available.
    • In the case that we have funds in that basket are met, the label is green
    • In the case that the funds in that basket are below required levels, and the next schedule is 2 or more days, the label is orange
    • In the case that the funds in that basket are below required levels, and the next schedule is within 2 days, the label is red
  • Schedule show/destroy don't need any specific stuff, however add will need the following:
    • The link to the page will be within an account page, next to 'Buckets in xxxxx' called 'Add Schedule in xxxxx' (along with view schedules in xxxxx)
    • The new schedule form will need the following fields
      • Account selection dropdown (default to current account)
      • Actions section similar to multiple buckets expenses/deposit where you can add extra buckets. Each line has a bucket dropdown for the current account, a type dropdown (expense/deposit/transfer) and an amount). These populate actions association
      • First payment section where it has year, months and day fields. This populates the scheduled time field on creation
      • Recurrence section where you select either "one time payment" (for future payment usage, this would make recurrence fields nil) or you select the occurrence. Weekly, fortnightly, monthly, or a text fields to specify number of weeks. That amount is stored in the schedules recurrence field and used as described in the section on how alerts are created.
  • Schedules should be able to be skipped. On the schedule show page, you should be able to "Skip the next occurrence", which would then make scheduled_time on the model == (scheduled_time + recurrence.weeks), effectively skipping it till next time.

Conclusion

I think think this feature would be quite useful. If you have any questions about its implementation, let me know.

@jamis
Copy link
Owner

jamis commented May 16, 2009

Sounds like you've about got it done. :) It's on my plate to implement, as this is a feature I've wanted, too, but I suspect my solution will be much simpler than what you've described here. If you'd rather implement this to your own specification, let me know and I'll hold off on mine until a patch is ready.

@KieranP
Copy link
Author

KieranP commented May 16, 2009

I'd love to help but if I can't get it done sometime tomorrow, I probably won't have time for another week or two :-( If I find some time to implement it, and it's not already done, I'll give a shot and let you know.

@KieranP
Copy link
Author

KieranP commented May 17, 2009

Took a crack at implementing this. Code at

http://github.com/KieranP/bucketwise/commit/cd4fe87be309be492f1ae7700dd34f9084ebd1a6

Adding, editing, deleting and upcoming schedules are implemented. Still got to implement code to execute the actions along with other things (see commit message).

Feel free to take and continue with it. Sorry for the lack of tests.

That's all the time I'll have till next weekend. Hope this has helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants