Support A2Billing :

provided by Star2Billing S.L.

Support A2Billing :
It is currently Thu Mar 28, 2024 12:24 pm
Hosted Voice Broadcast


All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Low balance email reminder
PostPosted: Tue Jan 01, 2008 5:20 pm 
Offline

Joined: Mon Nov 26, 2007 5:12 am
Posts: 14
Hey guys,

I've been researching this topic on the forum and using Google and I can't seem to find a concrete answer. I currently have low balance email reminders enabled and working on my A2billing installation 1.3.0. The problem is it doesn't seem to be working correctly. I initially had the min. balance set at $5. I then changed it to $1 by editing a2billing.conf. This didn't seem to work as the old limit is still in effect ($5) furthermore I get reminder emails once per hours. This amounts to spam if the user doesn't top up their card immediately. I've already gotten 25 reminder emails from my system. I checked all 3 agi.conf and they all have the option to send email reminders set to "no" in addition their min_credit etc are all set to less than $5. Am I missing something, somewhere?

Thanks


Top
 Profile  
 
 Post subject: Re: Low balance email reminder
PostPosted: Wed Mar 19, 2008 8:45 pm 
Offline

Joined: Thu Sep 13, 2007 12:46 pm
Posts: 254
Location: Naples, Fl ( USA )
I think this might help someone trying to have a2billing send Email to customers with low balances. I worked on this until I got it to work because the original code did not work at all. I hope it helps someone.

Code wrote:
#!/usr/bin/php -q
<?php
/***************************************************************************
* a2billing_check_account.php
*
* 13 April 2007
* Purpose: To check account of each Users and send an email if the balance is less than the first argument.
* Copyright 2007 User : Belaid Arezqui
* ADD THIS SCRIPT IN A CRONTAB JOB
*
* The sample above will run the script every day of each month at 6AM
crontab -e
0 6 1 * * php /var/lib/asterisk/agi-bin/libs_a2billing/crontjob/a2billing_check_account.php


field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)

****************************************************************************/
//exit();
// CHECK ALL AND ENSURE IT WORKS / NOT URGENT

set_time_limit(0);
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));


include (dirname(__FILE__)."/../db_php_lib/Class.Table.php");
include (dirname(__FILE__)."/../Class.A2Billing.php");
include (dirname(__FILE__)."/../Misc.php");



$verbose_level=0;
$groupcard=5000;

$min_credit = 5.00;

$A2B = new A2Billing();
$A2B -> load_conf($agi, NULL, 0, $idconfig);

write_log(LOGFILE_CRONT_CHECKACCOUNT, basename(__FILE__).' line:'.__LINE__."[#### BATCH BEGIN ####]");

if (!$A2B -> DbConnect()){
echo "[Cannot connect to the database]\n";
write_log(LOGFILE_CRONT_CHECKACCOUNT, basename(__FILE__).' line:'.__LINE__."[Cannot connect to the database]");
exit;
}
//$A2B -> DBHandle
$instance_table = new Table();


$QUERY = "SELECT mailtype, fromemail, fromname, subject, messagetext, messagehtml FROM cc_templatemail WHERE mailtype='reminder' ";
$listtemplate = $instance_table -> SQLExec ($A2B -> DBHandle, $QUERY);


if (!is_array($listtemplate)){
echo "[Cannot find a template mail for reminder]\n";
write_log(LOGFILE_CRONT_CHECKACCOUNT, basename(__FILE__).' line:'.__LINE__."[Cannot find a template mail for reminder]");
exit;
}
$gen_card = $listtemplate[4];
//list($mailtype, $frommail, $fromname, $subject, $messagetext, $messagehtml) = $listtemplate[0];
if ($FG_DEBUG == 1) echo "<br><b>mailtype : </b>$mailtype</br><b>from:</b> $from</br><b>fromname :</b> $fromname</br><b>subject</b> : $subject</br><b>ContentTemplate:</b></br><pre>$messagetext</pre></br><hr>";



// CHECK AMOUNT OF CARD ON WHICH APPLY THE CHECK ACCOUNT SERVICE
$QUERY = "SELECT count(*) FROM cc_card WHERE (activated='1' or activated='t') AND credit < $min_credit";

$result = $instance_table -> SQLExec ($A2B -> DBHandle, $QUERY);
$nb_card = $result[0][0];
$nbpagemax=(intval($nb_card/$groupcard));
if ($verbose_level>=1) echo "===> NB_CARD : $nb_card - NBPAGEMAX:$nbpagemax\n";

if (!($nb_card>0)){
if ($verbose_level>=1) echo "[No card to run the Recurring service]\n";
write_log(LOGFILE_CRONT_CHECKACCOUNT, basename(__FILE__).' line:'.__LINE__."[No card to run the check account service]");
exit();
}


write_log(LOGFILE_CRONT_CHECKACCOUNT, basename(__FILE__).' line:'.__LINE__."[Number of card found : $nb_card]");



// BROWSE THROUGH THE CARD TO APPLY THE CHECK ACCOUNT SERVICE
$sql = "SELECT id, credit, username, email FROM cc_card WHERE (activated='1' or activated='t') AND credit < $min_credit ORDER BY id ";
if ($verbose_level>=1) echo "==> SELECT CARD QUERY : $sql\n";
$result_card = $instance_table -> SQLExec ($A2B -> DBHandle, $sql);

foreach ($result_card as $mycard){
if ($verbose_level>=1) print_r ($mycard);
if ($verbose_level>=1) echo "------>>> ID = ".$mycard[0]." - CARD =".$mycard[2]." - BALANCE =".$mycard[1]." \n";

// SEND NOTIFICATION
if (strlen($mycard[3])>0){ // ADD CHECK EMAIL
$mail_tile = $mail_content = "LOW BALANCE : You have less than $min_credit dollars";
$mail_content = $listtemplate[0][4];
$mail_content = str_replace('$gen_card',$mycard[2],$mail_content);
$mail_content = str_replace('$balance',$mycard[1],$mail_content);
mail($mycard[3], $mail_tile, $mail_content,"[email protected]");
write_log(LOGFILE_CRONT_CHECKACCOUNT, basename(__FILE__).' line:'.__LINE__."[SENT EMAIL TO: ]".$mycard[3]);

}
}

if ($verbose_level>=1) echo "#### END RECURRING CHECK ACCOUNT \n";
write_log(LOGFILE_CRONT_CHECKACCOUNT, basename(__FILE__).' line:'.__LINE__."[#### BATCH PROCESS END ####]");


?>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 19, 2008 10:24 pm 
Offline
Moderator
User avatar

Joined: Thu Jun 22, 2006 2:19 pm
Posts: 2890
Location: Devon, UK
Wow, graher01, it's great to see you contributing. :)

Can I ask that in future you supply your changes in patch/diff format, as it's much easier to see what was changed that way. Also the forum frequently ruins the formatting. It's as easy as this:
Code:
cp a2billing.php a2billing.php.orig
# edit a2billing.php
diff -u a2billing.php.orig a2billing.php > mypatch.diff.txt
You can attach that .txt to a forum post. If you want to attach code to an enhancement/defect on Trac then it's best to use just .diff as the extension, as Trac will then display it with markup making the changes even more obvious.

Additionally I've a few comments about your changes themselves.
Was there a reason you removed part of the code that splits the task into pages of 5,000 customers? It's intended to give the SQL server and the mailserver an easier time by sleeping after each page.
I'm not sure your 4th parameter to mail() is correct. It specifies a header line, so must be a valid SMTP header. Perhaps you meant "From: [email protected]"?
I think you meant '$card_gen' rather than '$gen_card'.

Good work though. I'm always pleased to see another contributor.


Attachments:
File comment: How I feel your patch should look.
check_account.diff.txt [2.72 KiB]
Downloaded 1248 times
Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 1:11 am 
Offline

Joined: Thu Sep 13, 2007 12:46 pm
Posts: 254
Location: Naples, Fl ( USA )
stavros wrote:
Wow, graher01, it's great to see you contributing. :)

I think you meant '$card_gen' rather than '$gen_card'.

Good work though. I'm always pleased to see another contributor.


I can contribute more once I figure out what I am doing. I am a C++ and Visual Object programer but PHP is a learning experience for me. I am learning and you will see more contribution once it is worth it.

I am glad to make a difference.

thanks


Top
 Profile  
 
 Post subject: Re: Low balance email reminder
PostPosted: Thu Mar 20, 2008 6:05 pm 
Offline
Moderator
User avatar

Joined: Thu Jun 22, 2006 2:19 pm
Posts: 2890
Location: Devon, UK
duhty wrote:
Am I missing something, somewhere?
Sorry duhty, we've been happily chatting away in your thread and I've only just noticed your question.
The way things currently stand the IVR will send an email after a call if the balance has dropped below min_credit_2call. The cron job will send an email each time it is triggered if the balance is below 5. If you want the cron job to send reminders less frequently you configure this with 'crontab -e', eg:
Code:
# Remind users of low balance every 2 days at 12:00
0 12 */2 * * php /var/lib/asterisk/agi-bin/libs_a2billing/crontjob/a2billing_check_account.php
# or perhaps
# Remind users of low balance every 12 hours
# 0 */12 * * * php /var/lib/asterisk/agi-bin/libs_a2billing/crontjob/a2billing_check_account.php


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 10:47 pm 
Offline

Joined: Mon Oct 01, 2007 10:44 pm
Posts: 230
Location: Bovey, Devon, UK
Some Comments

As post pay customers will have a negative balance, the where clause should have a check for account type.

Further thoughts. To prevent repeated warnings, a db flag needs to be set to show that a warning has been sent. Part of the code should see if credit has been applied and flag reset.

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 10:54 pm 
Offline
Moderator
User avatar

Joined: Thu Jun 22, 2006 2:19 pm
Posts: 2890
Location: Devon, UK
middletn wrote:
As post pay customers will have a negative balance, the where clause should have a check for account type.
Or modify the query to match post-pay customers approaching their credit limit.
Quote:
To prevent repeated warnings, a db flag needs to be set to show that a warning has been sent. Part of the code should see if credit has been applied and flag reset.
I was thinking exactly the same. Once that is in place I think adding a new configuration setting 'min_credit_sendreminder' would be useful in both check_account.php and especially the AGI, so we can warn them before they reach 'min_credit_2call'.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 21, 2008 11:31 am 
Offline

Joined: Thu Sep 13, 2007 12:46 pm
Posts: 254
Location: Naples, Fl ( USA )
stavros wrote:
middletn wrote:
As post pay customers will have a negative balance, the where clause should have a check for account type.
Or modify the query to match post-pay customers approaching their credit limit.
Quote:
To prevent repeated warnings, a db flag needs to be set to show that a warning has been sent. Part of the code should see if credit has been applied and flag reset.
I was thinking exactly the same. Once that is in place I think adding a new configuration setting 'min_credit_sendreminder' would be useful in both check_account.php and especially the AGI, so we can warn them before they reach 'min_credit_2call'.


I agree about the min_credit_sendreminder but not the flag to show that it has been sent. it is not necessary as the reminder is sent once daily to not only warn but also give the customer his/her balance. I think that it is useful to know what your balance is so that you can act when it become critical.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 21, 2008 6:03 pm 
Offline
Moderator
User avatar

Joined: Thu Jun 22, 2006 2:19 pm
Posts: 2890
Location: Devon, UK
graher01 wrote:
it is not necessary as the reminder is sent once daily to not only warn but also give the customer his/her balance.
If we modify the AGI to send the reminder when the balance drops below min_credit_sendreminder, rather than min_credit_2call, then we'll need something to prevent a reminder being sent after each call.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 21, 2008 8:35 pm 
Offline

Joined: Thu Sep 13, 2007 12:46 pm
Posts: 254
Location: Naples, Fl ( USA )
stavros wrote:
graher01 wrote:
it is not necessary as the reminder is sent once daily to not only warn but also give the customer his/her balance.
If we modify the AGI to send the reminder when the balance drops below min_credit_sendreminder, rather than min_credit_2call, then we'll need something to prevent a reminder being sent after each call.


For what I can see the reminder is not sent after each call it is being sent at 6AM each day. and it is not based on the min_credit_2call it is base on the on the min_credit which is hard coded in the file. so the min_credit_sendreminder is a welcome variable because it would allow to set the minimum without going to the file it self.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 21, 2008 8:57 pm 
Offline
Moderator
User avatar

Joined: Thu Jun 22, 2006 2:19 pm
Posts: 2890
Location: Devon, UK
Sorry perhaps I forgot to mention that I was intending to modify the AGI to use min_credit_reminder too, hence the need for this extra field. Areski has understandly vetoed the idea for branches/1.3 though, so just what you described is going to happen.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 23, 2008 8:45 am 
Offline
Moderator
User avatar

Joined: Tue Jun 06, 2006 12:14 pm
Posts: 685
Location: florida
stavros wrote:
Sorry perhaps I forgot to mention that I was intending to modify the AGI to use min_credit_reminder too, hence the need for this extra field. Areski has understandly vetoed the idea for branches/1.3 though, so just what you described is going to happen.


Does this mean 1.3 is frozen now, or that only a normal bug fix will be done on 1.3 ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 23, 2008 6:10 pm 
Offline
Moderator
User avatar

Joined: Thu Jun 22, 2006 2:19 pm
Posts: 2890
Location: Devon, UK
Quote:
Does this mean 1.3 is frozen now, or that only a normal bug fix will be done on 1.3 ?
Yes branches/1.3 has been in feature-freeze for quite a while now, and is receiving only bug fixes and very minor backwards-compatible improvements.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 10:07 am 
Offline
Moderator
User avatar

Joined: Tue Jun 06, 2006 12:14 pm
Posts: 685
Location: florida
I realize this is outside the scope of this, but how goes 1.4? Anyone venture to use it in production yet? Or should one only browse the 1.4 to get familiar with it and stick to 1.3 ??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 11:19 am 
Offline

Joined: Thu Oct 19, 2006 9:56 am
Posts: 300
Location: Athens, Greece
krzykat wrote:
I realize this is outside the scope of this, but how goes 1.4? Anyone venture to use it in production yet? Or should one only browse the 1.4 to get familiar with it and stick to 1.3 ??


Reusing old version numbers for new code (+features) is not wise. I admit that some people are reluctant of upgrading when they see a new release number, but it's their fault. Anything that /behaves/ differently must have a different middle version.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Predictive Dialer


All times are UTC


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group