Generating bill for my student

Hello,

I’m trying to generate bills. for my app. I’d like to know where is the most suitable place for me to put this particular function.

Here are the scenarios:

A user can select a student and click somewhere from the profile a Generate Bill button for him/her. A list of bills would also be generated automatically on the first day of the months.

My first thought would be putting it in the Bill model as a class method, for e.g Bill::generate(student). But then, it got me thinking whether it’s a right place since the Bill method has to interact with Student and Enrollment model (stores which package the student is currently subscribed to and it is also linked to another model that stores the fee).

So, my questions are:

  • Where should I put the bill generator function.
  • What are the best way for me to generate bills by bulk every month. Is it ok if I just use whenever gem and call the function or should I queue the task and run it in the background.

Thanks in advance.

Have you written this in Bill yet? I’d start there then take a look at the resulting code to see if it makes sense to extract a service object. Perhaps something like Biller, or maybe something better and more obvious will jump out at you once you have the code written.

To generate bills every month, I’d use a scheduled task that runs a rake task. The Rake task should be as simple as you can possibly make it - push as much logic as possible into application classes which are much simpler to test.

It might make sense to move that to a background job at some point, but again - build it first and see what the impact it. Then react.