Simple Call Accounting
I work for an engineering firm and we have a couple thousand account codes for various projects. I would like to implement call accounting but cannot create pin sets because of the large number of existing account codes. Basically I need to have the dial plan prompt certain extensions for an account code followed by the # key after they dial the number they want and have that code put in the accountcode field in the CDR record. I don't need to verify that it is the correct code, and the user should be able to hit # without entering any number if they choose. Any help is appreciated.
Glenn
Sorry, I kept seeing this but didn't get to answering it for you.
Try this:
Open up /etc/asterisk/extensions.conf
Go down to the section
[macro-dialout-trunk]
look for the entry:
exten => s,n,GotoIf($["${custom}" = "AMP"]?customtrunk)
exten => s,n,Dial(${OUT_${DIAL_TRUNK}}/${OUTNUM},300,${DIAL_TRUNK_OPTIONS})
BETWEEN those two lines, insert the code below
exten => s,n,Playback(please-enter-the&accounting)
exten => s,n,Read(account|number|3)
exten => s,n,SetAccount(${account})
I have it set up for max 3 digits (you can change the 3 to any number or just remove |3 for no maximum)
You can just press # to get through.
Try it out, let me know. The data should show up in the ACCOUNTCODE column in the CDR table.
Its VERY easy to change that to look at a generic text file of numbers to IF you want to make sure they are coded to something that is actually a valid account number.
Thank you for your help... This is working but I was a little short sighted I am afraid. I need to have this prompt only for long distance calls, for example anything dialed with a 1NXXNXXXXXX or 91NXXNXXXXXX. I will have IAX and SIP trunks for intra-company extension only dialing in the near future and I will also be using those routes for route optimization to save on long distance so I don't think I can filter this based on trunks, and I dont need call accounting between offices (yet).
Also, can I take this code that you posted and create a feature code to enter the account code during a call already in progress? That would make it possible to track billable phone time between employees in separate geographical offices that may be consulting each other on the same project. Thank you again for your help.
Glenn
Of course you can use the code for whatever you need. Maybe throw a comment in there somewhere that you got it from the trixbox.org forum or something :)
Thats how this whole open source thing works, sharing the building blocks of code for others to develop upon.
I can add a couple of lines into that code to filter out a certain dial sequence if you want.
I've tried adding the following lines to the [macro-dialout-trunk-predial-hook] section of extensions.conf:
exten => s,1,Playback(please-enter-the&accounting)
exten => s,2,Read(account|number|5)
exten => s,3,Set(CDR(accountcode)=${account})I get the following output in the cli:
-- User entered '12345'
-- Executing [s@macro-dialout-trunk-predial-hook:3] Set("SIP/1511-08ee3708", "CDR(accountcode)=12345") in new stackWhich looks to me like it is working, but when I go to the CDR report, I don't see the Account Code column, nor the entered data anywhere. Is this something simple that I'm missing?
Also, if I use this as the code:
exten => s,1,Playback(please-enter-the&accounting)
exten => s,2,Read(account|number|5)
exten => s,3,SetAccount(${account})I get this as the result (and a busy tone on the phone):
-- User entered '12345' == Spawn extension (macro-dialout-trunk-predial-hook, s, 3) exited non-zero on 'SIP/1511-092c7cf8' in macro 'dialout-trunk-predial-hook'
Here is the updated code I use to accomplish the original desired functionality. The "Read" function also does what "Playback" does so Playback is no longer needed. I decided to include a line to test for the number of digits dialed so that users are not prompted for an account code for a local call. Place this in the extensions_custom.config file and it will not be over written when you update FreePBX modules. You must include the context heading.
[macro-dialout-trunk-predial-hook]
exten => s,1,Set(str=${LEN(${OUTNUM})})
exten => s,n,GotoIF($[${str} < 11]?localcall) --> tests for 11 digits, skips prompt for account code if less than 11 digits are dialed
exten => s,n,GotoIF($[ ${REALCALLERIDNUM} = 7398 ]?localcall) --> this line lets me disable this for a specific extension number
exten => s,n,GotoIF($[ ${REALCALLERIDNUM} = 4549 ]?localcall)
exten => s,n,GotoIF($[ ${REALCALLERIDNUM} = 3300 ]?localcall)
exten => s,n,Read(account,jobnum,8,,,5) --> Look up the Read function for the details, the word 'jobnum' is the name of my custom recording file that is played to prompt the user to enter the account code
exten => s,n,Set(CDR(accountcode)=${account})
exten => s,n(localcall),Noop
Here is the code without the explanation text...
[macro-dialout-trunk-predial-hook]
exten => s,1,Set(str=${LEN(${OUTNUM})})
exten => s,n,GotoIF($[${str} < 11]?localcall)
exten => s,n,GotoIF($[ ${REALCALLERIDNUM} = 7398 ]?localcall)
exten => s,n,GotoIF($[ ${REALCALLERIDNUM} = 4549 ]?localcall)
exten => s,n,GotoIF($[ ${REALCALLERIDNUM} = 3300 ]?localcall)
exten => s,n,Read(account,jobnum,8,,,5)
exten => s,n,Set(CDR(accountcode)=${account})
exten => s,n(localcall),Noop
You cannot see the accountcode field in the CDR reports generated under the Reports tab of the FreePBX console. You have to look at the master CDR file and use another program to create custom reports so that you can see all the fields. Hope this explanation makes sense, let me know if you need clarification.
Thanks! This thread provided the clue crucial to solving my own integration problem.
This might be 6 weeks late, but perhaps naughtyusmaximus might still be interested to know that the GPL Asterisk2Billing project can rate and bill your CDRs, amongst many other features. It makes an excellent complement to any Asterisk based system.
If you're thinking of trying A2B, once you've got it installed, use the simple instructions I just posted for integrating A2B with trixbox.


Member Since:
2007-08-06