Simple invoicing questions
Page 1 of 2

Author:  taffey01 [ Wed Jul 15, 2009 11:12 pm ]
Post subject:  Simple invoicing questions

1. How do i raise an invoice for a customer and it then resets his preview invoice to the next day?
2. Is there any way to raise the invoice as a pdf or email it?
3. Can i add a monthly DDI cost to the customer invoice including the calls?
4. Where does the agent commision show up?
5. Is there no automation of invoices in Cronjobs for 1.4?
6. Any doco for invoicing/agent stuff yet?

Thanks guys!


Author:  dbenwit [ Thu Jul 23, 2009 6:31 pm ]
Post subject:  Re: Simple invoicing questions

I am also interested in getting info on these questions and more for invoicing in A2Billing 1.4.
Can anyone provide us with a short tutorial on how to set up billing and invoicing in 1.4, including the automation of the process to create invoices and e-mail them to the customer?



Author:  cerien [ Wed Jul 29, 2009 8:19 pm ]
Post subject:  Re: Simple invoicing questions


a bit of searching beyond this link on the forum can also probably help !


Author:  dbenwit [ Wed Aug 19, 2009 7:27 pm ]
Post subject:  Re: Simple invoicing questions


Thanks for the link. I have reviewed that post and have a reasonably good idea how invoicing should work in A2Billing 1.4. I have also looked at your post with suggestions for invoicing in A2B 1.5.

I would like to comment further on the invoicing capabilities of A2Billing, but first, I have a question pertaining to my current setup of A2Billing 1.4. I have set up a postpaid customer and set a credit limit for the customer. However, I set a positive balance for the customer rather than setting the balance to zero initially. Is it possible to change the current balance of the customer to (0 - the current balance) so that the set up will agree with your instructions?

From my reading of your explanation of how invoicing works in A2B 1.4, it is my understanding that you are required to manually inform the customer when the invoice has been generated and then the customer must go through the Customer Web UI to view the invoice and also, to view the CDRs associated with the invoice period. Besides the difficiencies in the invoice generation which you outlined in your post on suggestions for A2B 1.5, the requirement for the customer to go into the CDR module in the Customer UI and manually search for the calls which were included in the invoice charge needs to also be addressed (which is my understanding and, if not the case, I stand corrected). This is also unacceptable, as the call details should be included in the invoice (as most telephone companies and service providers do), properly categorized under outgoing calls (possibly futher sub-categorized under local and long distance calls) and also under incoming DIDs. Don't get me wrong, the CDR module in the customer UI is great and allows the customer to see their call details at any time. However, the customer should not have to use it to view invoiced call details.

I am currently using A2B 1.4 and it is doing a great job for me except for the invoicing capability. So I will have to live with its invoicing difficiencies for now. However, for A2Billing to truely become a first rate billing solution, the invoicing capabilities must be improved. The following are a few things that the invoicing in A2Billing should do:

1. Create a pdf invoice with the following included, beyond the customer information etc. at the top of the invoice and the total charges before and after taxes:
- line items for recurring charges such as DID monthly charges and other charges
- line items for total charge for outgoing calls and incoming DID calls for each DID
- a listing of call records for outgoing calls as well as incoming calls for each DID which is included in the invoice

2. Allow for fexibility in naming and applying taxes. VAT is fine for European users, but in North America, taxes are given different names and sometimes, must be broken down into different taxes (ie. federal and state/provincial taxes). For example, in Canada, we have a federal GST tax and in some provinces, a PST tax as well.

3. Allow for automatic e-mailing of invoice notification as well as attachment of invoice to e-mail.

These are the main things to address at this point. There are probably some others which I have not included.

Please don't get me wrong. I am not a programmer, and therefore, cannot directly contribute to the ongoing development and improvement of A2Billing. However, I do appreciate all the efforts that have made A2Billing the excellent open source billing application that it is. I just believe that the invoicing capability must be improved to make it that much better.


Author:  cerien [ Wed Aug 19, 2009 8:06 pm ]
Post subject:  Re: Simple invoicing questions


your points are very valid ! they can actually be addressed with a bit of programming ! I guess this is the "cost" of going down the opensource route versus paying for a sometimes more complete software.

- re: pdf generation - you might want to look at this thread:

- re: notifying the customer... it is fairly simple to add this to the batch billing script - if you have someone at hand that knows php, I can email the 5 lines that do this trick - though if you succeed in applying the PDF patch I've just indicated, you probably can do this yourself !

- re: notifying customer and emailing the file.... hhhmmm... still have that one on my todo list (not sure if I'll do it, though !)

- detailed CDR along with the invoice... I would not do this - What I've done is send a recap of calls per tarifplan (which in my case match the tariff zones). Then, downloading from the customer UI triggers the question of performance, and this community seems to have voted against !

- tax calculation in the US is an absolute nightmare - back in the 90's, I remember that taxes were calculated based on the city, state of origin & termination of the call.... you had to connect to specific packages to do that. Unfortunately, tax calculation is a bit weak with A2B - this one is going to be hard to overcome in your case !

Next, you'll see that payment management can also be improved - namely, a payment can only be assigned to one invoice !

but finally, I've worked with a couple of multi-million $$$ billing packages, and A2B is very close from them in terms of functionality, and quality !!!

dont hesitate to revert if you need more help

Author:  dbenwit [ Thu Aug 20, 2009 2:34 am ]
Post subject:  Re: Simple invoicing questions


Thanks for the reply.

I will definitely look into setting up pdf generation as per your post.

With respect to modifying the batch billing script for customer notification, my php skills are definitely limited. So if you have the lines that need to be added to the script, I could definitely use them.

Finally, could you elaborate further on your statement about CDRs, namely "What I've done is send a recap of calls per tarifplan (which in my case match the tariff zones)". The capability to provide call details to the customer is a must have for us.

As for tax calculation, the current setup in A2B would work at this point if I could replace the word VAT everywhere with GST.


Author:  cerien [ Thu Aug 20, 2009 3:25 am ]
Post subject:  Re: Simple invoicing questions


Bear in mind that even adding just a few lines to any A2B file will take you on a diverging route, and make applying any upgrade / new svn a bit more complicated. The changes here are simple, and are likely to be brought forward easily - but this is the first mile of a sometimes long road !

Add the following lines into a2billing_batch_billing.php,

around line 87, change the query definition:
        $Query_Customers = "SELECT id, vat, invoiceday, typepaid, credit, language FROM cc_card ";

around line 256, just above the line
} // END for each...

                        // sends a mail to the customer
                        if (strlen($Customer['email'])> 5) {
                        try {
                          $mail = new Mail(Mail::$TYPE_INVOICE, $card_id, $Customer['language']);
                          $mail -> send();
                        } catch (A2bMailException $e) {
                          echo "failed $e";
                          write_log(LOGFILE_CRONT_CHECKACCOUNT, basename(__FILE__) . ' line:' . __LINE__ . "[Sent mail failed : $e]");

                } // END foreach($resmax as $Customer)

Regarding the CDR, I am attaching my invoice layout to this message - however, this has required quite some extensive changes to some files !

Good luck,

A2B_invoice_view.pdf [36.77 KiB]
Downloaded 954 times

Author:  dbenwit [ Thu Aug 20, 2009 3:46 pm ]
Post subject:  Re: Simple invoicing questions


Thanks for all your help and info.

I will look at implementing these changes and see how it works out.


Author:  RobinA [ Sun Nov 08, 2009 1:02 am ]
Post subject:  Re: Simple invoicing questions


Your solution would help me a great deal with the invoicing challenge I see in 1.4X.
I was wondering if I got all of the files in All I see under [INVOICING] is the "configuration" which takes the company info and transpose the zip code and city name. I don't see an input field for "State" and the other options are "invoices" and "payments". Am I missing something?

Anyhow I wanted to implement the mailing feature you suggested for Dave but I cannot find the file mentioned. I guess I'm missing something, somewhere.

A bit more help in this area would be appreciated.

Thanks for all of your insightful input. I'm learning a lot from reading these posts.
Of course, we owe a lot to Joe who is always ready with an answer, Stavros who would teach you "how to fish" whether you want to or not and most of all Areski and Co. working tirelessly to make this a better product.


Author:  cerien [ Sun Nov 08, 2009 7:40 pm ]
Post subject:  Re: Simple invoicing questions

a2billing_batch_billing.php is located under /Cronjob (at the same level as /admin, /customer etc...)

the state is not defined for the invoicing entity, only for the customers - however, you can work around that by adding it in any other field !


Author:  RobinA [ Mon Nov 09, 2009 12:39 am ]
Post subject:  Re: Simple invoicing questions


I'm running A2B and I couldn't find it in the folder you mentioned. I did find it in "/var/lib/asterisk/agi-bin/lib/Cronjobs" and it has some code very similar to what you suggested. So I guess I need to concentrate on the pdf function. What do I have to do to get my invoices looking like yours?

Thanks again,


Author:  cerien [ Mon Nov 09, 2009 3:55 am ]
Post subject:  Re: Simple invoicing questions

RobinA wrote:

I'm running A2B and I couldn't find it in the folder you mentioned. I did find it in "/var/lib/asterisk/agi-bin/lib/Cronjobs" and it has some code very similar to what you suggested. So I guess I need to concentrate on the pdf function. What do I have to do to get my invoices looking like yours?

Thanks again,


you should find this file in the install dir, where you unzipped the original tarball or downlaoded the svn version. what is important is that it requires a link to lib dir, and that it is in a secure dir - in case someone hacks the box ! var/lib should be alright with the proper rights, etc...

regarding the invoice layout, i did some changes based on rev 2293 - a2b 1.4.2 is a later revision... if you want I can email you the changes - but you can do your own layout by changing 2-3 files:
a2b_batch_billing for the processing itself, and
/var/www/html/a2billing/customer/templates/default/css/invoice.css and customer/A2B_invoice_view.php

these last two will define the layout of the invoice.

bear in mind that changing files from the base version will complicate your life in applying later upgrades of a2b

let me know if you want more info,


Author:  RobinA [ Mon Nov 09, 2009 6:17 am ]
Post subject:  Re: Simple invoicing questions


At some point we will stop upgrading to the latest. I see people still running 1.2.3. I'm willing to take the chance. Besides I'm learning PHP which is required if you want to use A2B effectively. So, if you don't mind, could you send me the files.

Thanks a bunch,


Author:  cerien [ Mon Nov 09, 2009 5:41 pm ]
Post subject:  Re: Simple invoicing questions


see attached zip file

the files are provided as is, no warranty expressed or implied or whatsoever, and all the usual legal yada yada...

now, the interresting bit.... description of the files !

you need to retrieve svn version 2993, and do a diff with the files to identify which changes should be made to your current version. alternatively, it might be quicker to diff rev 2293 and your current version - there might be less changes to apply.

1. Create manually two additional columns:

ALTER TABLE `cc_invoice` ADD `total_amount` DECIMAL( 15, 5 ) NULL DEFAULT '0' ;
ALTER TABLE `cc_invoice` ADD `open_amount` DECIMAL( 15, 5 ) NULL DEFAULT '0';

they help a lot in finding out the total invoice amount, and what has been paid to date !

2. Create triggers to automatically populate these columns (when invoices are generated and payments made):
run script with mysql : update_triggers_only.sql
this is a file that does not exist in a2b, that you need to use only once - to create the proper triggers.

3. A2B_invoice_view.php - to be updated/merged to your current version and dropped in var/www/html/customers/
reformats the invoice

4. invoice.css - to be updated/merged to your current version and dropped in var/www/html/customers/templates/default/css

5. my_batch_billing.php - to use instead of a2billing_batch_billing.php - no need to diff, just use instead of
this really a postpaid script...
there are a number of changes in there - main one is that instead of billing the calls based on the negative credit, it actually fetches from the db the calls for the billing period. It groups these calls by ratecards and generates one line in cc_invoice_item, and sums the total duration and cost - later, the A2B_invoice_view will display this correctly.
also, when there are charges and call, it generates ONE invoice with multiple invoice item and not multiple invoices each with one line.
very important as well, it auto-refills the account of the invoice amount, hence transferring responsibility of the amount due to collections (ie, the credit limit no longer controls this)
also, line 87, you'll need to update the language and adjust message.po with any description you need. also, line 62, the months are manually translated (used by email to customer)
it also emails the customer with the total amount - note that you can use new keywords in the email template, $invper$ (invoice period) and $invamt$
this scripts also prints some stats about performance and what has been billed.

dont forget to look in /var/log/httpd/error_log when you dont get the expected results (for online modules).

Here you go......


Attachments: [10.02 KiB]
Downloaded 729 times

Author:  RobinA [ Wed Nov 11, 2009 2:31 pm ]
Post subject:  Re: Simple invoicing questions


Thanks for the wonderful feedback. I will try to tackle that later today. I'm not familiar svn, therefore it will be a bit of learning curve. I've been wrestling with an upgrade from 1.3.4 to 1.4.2 and the database is refusing to upgrade. Maybe I'm running the wrong script.

I'll let you know my progress on the invoicing.


Page 1 of 2 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group