BambooInvoice Forums

HOWTO: Recurring / Automatic invoice generation WORKS!

 
Total Posts: 6

Hi everyone.

I’d like to say that after using Bamboo for over a year now i have finally spent a few hours on my Sunday afternoon to
create a recurring invoice feature in Bamboo!

What i have done is put a “Recur Annually” checkbox on the new invoice page. Then on the same day a year later, the script will create the same invoice with the same items and client details. Easy! This will happen every year.
The invoice number generated is the same as the original, followed by the year. eg invoice 3 next year will be created as invoice 3.09

Installation of this feature requires

1. replace the /application/views/invoices/newinvoice.php with my modified one.
2. replace the /application/controllers/invoices.php with my modified one.
3. add a varchar field to the database table bamboo_invoices called ‘recur_date’
4. upload recur.php to the bambooinvoice folder and have it run once a day (using cron or windows scheduler).

Things to note.

You will need to modify the recur.php to suit your mysql database settings, as the script is not part of Bamboo and does not read from
any configuration files.

I can think of ways to setup a choice of monthy / quarterly generation, however i have no need for it myself. If anyone is interested out there for this kind of feature please PM or drop me an email.

——I take no responsibility for the code contained in this archive. backup your stuff first.——

The code for recur.php is really rough, but it does work.

File Attachments
recur0.1.zip  (File Size: 9KB - Downloads: 456)
Total Posts: 15

That’s great! I know you said PM you or drop you an email, but just curious as to how much work is involved for a recurring monthly or quarterly generation?

Total Posts: 6

Looking back on what i have done, i think rather than using a recur_date field in the table, the field should be recur_interval. The recur_iterval would be a value of days (30,90,365) etc.
When the daily script runs in the background, it checks the invoice issue date, and see’s if the invoice is 30,90 or 395 days ago. at this point it re-creates a new invoice.

I will need to do this for myself one day soon. But please if anyone else is interested post here and ill make it a bigger priority.

Total Posts: 53

count me in for more details.

Total Posts: 11

This doesnt work at all for me, im on version 0.8.7.

My output from the cron reads something like this:

line 1: no such directory,
line 2: command not found:
line 3 command not found

etc

im not to familiar with using cron to automate.

Any clues anyone, this is a great addion to bamboo!

Total Posts: 10

I am very interested in these features as well.  Is there any way I can help get this done?  I can provide a test server. 
If this is done, we can ask Derek to include it in the next release.

Total Posts: 10
dsb - Oct 14, 2008 02:53pm

This doesnt work at all for me, im on version 0.8.7.

My output from the cron reads something like this:

line 1: no such directory,
line 2: command not found:
line 3 command not found

etc

im not to familiar with using cron to automate.

Any clues anyone, this is a great addion to bamboo!

DSB,
I will install this patch and report back with the crontab command.
Maybe in the meantime you can post your crontab file.

Total Posts: 11

I spent the time to recreate the script so you can set the interval for recurring invoices. This is an early version and there are probably some weird bugs that’ll need to be fixed. Download and install instructions here:

http://www.amtstudios.com/mods/bambooinvoice-recurring-invoices.html

Total Posts: 2324

oh darn, I wish you had contacted me smile  I’m about to release a new version of Bamboo shortly.  What can I do to facilitate your code working without buggering up Bamboo.  Your current drop in solution won’t be compatible, as I’ve subclassed the Controller and moved a few other things around.  You need a new database field I see… that’s no problem - anything else?  Not everyone (in fact, most people in my experience) don’t have access to cron, so I’m thinking we’ll at least add an additional hidden config variable, and it’ll be disabled by default, but people who want to can enable it.

I’d like to re-work recur.php a bit also… this is probably best served as a controller function of invoice… as without it you have no security implemented, and also people need to enter information twice (ie: database information).

Total Posts: 11

I was short on time and couldn’t properly integrate it with the Bamboo Invoice system, so I just improved Cody’s method.

One thing I never got around to is fixing the naming system. It just tacks on the current date to the invoice number (even if it already has one). Should be fixed before the BambooInvoice update.

If you want users without cron to still use the feature, create a script that’s executed every time you load a BambooInvoice page. Have it check to see if the recur.php file has been run today and if not, run it. The only problem with this method is someone has to visit the site at least once a day.

A new integer column in the bamboo_invoices table, the updated view pages, and the updated invoice.php controller are the only things changed from the original BambooInvoice system.

There should probably be an option to have it automatically e-mail the invoice when it is created by the recur.php script.

It’s probably a good idea to update the view invoice page to list the recur interval.

Total Posts: 2324

I already knew it wasn’t the most secure and best way, but I was short on time.

I totally understand, but that’s not something I can do with Bamboo given how widely its distributed.

The only problem with this method is someone has to visit the site at least once a day.

That isn’t too big a deal for me.  The other issues are that your script is a simple db insert.  Then what?  I think in order for this to be useful Bamboo would also need to alert the admin that they’ve been created… possibly auto email it out.  Etc.

In re-reading this it sounds like I’m being critical, and I’m absolutely NOT trying to be - thanks for sharing.  I think that I just need to sort out how I want it to behave before I can implement something like this.

Back to my original point though, is that unfortunately your script will break in any version BUT 0.8.7, and a new version is about to come out.  Since recurring invoicing is something that I want to see anyhow, I want to facilitate this working.  How would you envision that happening?

Total Posts: 11

The only reason I see it breaking is because recur.php is outside the system. The other modifications to how the data is stored, displayed, and edited is all inline with the system.

The recur script would need to be able to be called outside of the BambooInvoice system in-case someone wanted to use crontab instead of the pseudo cron job system.

Total Posts: 2324

No, I’m referring to the changes you made.  Imagine someone updated their version of bamboo (which had your changes) with a new version of Bamboo (which didn’t) - what would they need to do.  Make it easy for me here AMT… I looked at your code, but I don’t really want to comb line by line through the changes you made.  Running a Diff is nearly useless to me right now because of how much else has changed in the code at this point.

Also, let’s open up a discussion about how we want this to happen.  Do we simply want the recurring invoices created?  No notice to the admin?

Total Posts: 11

Ah, right sorry.

bamboo_system_files\application\controllers\invoice.php
- Updated the max_length for invoice_number to 255.
- Edit $invoice_data array to include recur_interval on edit and newinvoice function.

bamboo_system_files\application\views\invoices\edit.php AND bamboo_system_files\application\views\invoices\newinvoice.php
- Updated maxlength field option for invoice_number to 255.
- Added

<p><label>Recur in <input type="text" name="recur_interval" size="2" maxlength="11" value="<? echo $row->recur_interval; ?>"days (leave blank to disable)</label></p

to form.

I’d give you line numbers but they’d be off from the original files. If you need any more info let me know. I’m off to the gym.

Total Posts: 2324

I see.  Thanks for your contributions.  If anyone else has thoughts please share.  As this sits now, I feel it would require a substantive rewrite for inclusion into Bamboo, and, like everyone, I don’t have the time at this moment to make that happen.  There are also issues of behaviour that need to be hashed out - I want recurring invoices to be an integrated part of the Bamboo experience.

Total Posts: 15

some good work here. Like someone pointed out (2 lazy to back scroll) using the days ahead to re-occur would be much more useful / flexible. So when it is included it would be nice to use 30 , 90 , 365 or what ever you want as your re-occuring option.

For crontab or automatic processing i think you will need both options. Crontab is the most robust method to have it happen, but as you pointed out Derek, not everyone has access to it on their webhost. So a secondary method to have it run each time someone logs in should be added. This would also add the benefit of future timed modules being able to attach to the class / method to be run on a login. I know their are issues with that but what else can you really do if you dont have access to cron.

As for the regenerated invoice i think you need to add an option to A) use existing invoice numbering system (i know this is what i would do and plan to do) and B) have some other naming scheme option (not sure how or what as i personally dont see the method / reason behind breaking the whole invoice numbering system for a regenerated invoice, but as someone wanted to do it it may as well be discussed.)