| 1 |
#!/usr/bin/php -q |
|---|
| 2 |
<?php |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
set_time_limit(0); |
|---|
| 27 |
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING)); |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
include_once (dirname(__FILE__)."/lib/Class.Table.php"); |
|---|
| 31 |
include (dirname(__FILE__)."/lib/Class.A2Billing.php"); |
|---|
| 32 |
include (dirname(__FILE__)."/lib/Misc.php"); |
|---|
| 33 |
include (dirname(__FILE__)."/lib/A2B_invoice.php"); |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
$verbose_level=2; |
|---|
| 37 |
|
|---|
| 38 |
$groupcard = 5000; |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
$enableminimalamount = 'off'; |
|---|
| 43 |
$minimalamount = 0; |
|---|
| 44 |
$customtemplate = ''; |
|---|
| 45 |
$choose_currency == ''; |
|---|
| 46 |
$billcalls = 'on'; |
|---|
| 47 |
$billcharges = 'on'; |
|---|
| 48 |
$nowdate = date('Y-m-d H:i:s'); |
|---|
| 49 |
$billday = date("j"); |
|---|
| 50 |
|
|---|
| 51 |
$A2B = new A2Billing(); |
|---|
| 52 |
$A2B -> load_conf($agi, NULL, 0, $idconfig); |
|---|
| 53 |
|
|---|
| 54 |
write_log(LOGFILE_CRONT_INVOICE, basename(__FILE__).' line:'.__LINE__."[#### CRONT INVOICE BEGIN ####]"); |
|---|
| 55 |
|
|---|
| 56 |
if (!$A2B -> DbConnect()){ |
|---|
| 57 |
echo "[Cannot connect to the database]\n"; |
|---|
| 58 |
write_log(LOGFILE_CRONT_INVOICE, basename(__FILE__).' line:'.__LINE__."[Cannot connect to the database]"); |
|---|
| 59 |
exit; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
$instance_table = new Table(); |
|---|
| 63 |
$currencies_list = get_currencies($A2B -> DBHandle); |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
$QUERY = "SELECT count(*) FROM cc_card "; |
|---|
| 68 |
$result = $instance_table -> SQLExec ($A2B -> DBHandle, $QUERY); |
|---|
| 69 |
|
|---|
| 70 |
$nb_card = $result[0][0]; |
|---|
| 71 |
|
|---|
| 72 |
$nbpagemax = (intval($nb_card/$groupcard)); |
|---|
| 73 |
|
|---|
| 74 |
if ($verbose_level>=1) echo "===> NB_CARD : $nb_card - NBPAGEMAX:$nbpagemax\n"; |
|---|
| 75 |
|
|---|
| 76 |
if (!($nb_card>0)){ |
|---|
| 77 |
if ($verbose_level>=1) echo "[No card to create the Invoice]\n"; |
|---|
| 78 |
exit(); |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
$invoice = new A2B_Invoice($A2B -> DBHandle, $verbose_level); |
|---|
| 82 |
|
|---|
| 83 |
for ($page = 0; $page <= $nbpagemax; $page++) |
|---|
| 84 |
{ |
|---|
| 85 |
if ($verbose_level >= 1) echo "$page <= $nbpagemax \n"; |
|---|
| 86 |
|
|---|
| 87 |
$Query_Customers = "SELECT id, invoiceday FROM cc_card"; |
|---|
| 88 |
|
|---|
| 89 |
if ($A2B->config["database"]['dbtype'] == "postgres") |
|---|
| 90 |
{ |
|---|
| 91 |
$Query_Customers .= " LIMIT $groupcard OFFSET ".$page*$groupcard; |
|---|
| 92 |
} |
|---|
| 93 |
else |
|---|
| 94 |
{ |
|---|
| 95 |
$Query_Customers .= " LIMIT ".$page*$groupcard.", $groupcard"; |
|---|
| 96 |
} |
|---|
| 97 |
$resmax = $instance_table -> SQLExec ($A2B ->DBHandle, $Query_Customers); |
|---|
| 98 |
|
|---|
| 99 |
if (is_array($resmax)){ |
|---|
| 100 |
$numrow = count($resmax); |
|---|
| 101 |
if($verbose_level >= 2) print_r($resmax[0]); |
|---|
| 102 |
}else{ |
|---|
| 103 |
$numrow = 0; |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
if($verbose_level >= 1) echo "\n Total Customers Found: ".$numrow; |
|---|
| 107 |
|
|---|
| 108 |
if ($numrow == 0) { |
|---|
| 109 |
if ($verbose_level>=1) echo "\n[No card to create the Invoice]\n"; |
|---|
| 110 |
exit(); |
|---|
| 111 |
}else{ |
|---|
| 112 |
foreach($resmax as $Customer){ |
|---|
| 113 |
|
|---|
| 114 |
$invoiceday = (is_numeric ($Customer[1]) && $Customer[1]>=1) ? $Customer[1] : 1; |
|---|
| 115 |
|
|---|
| 116 |
if ($billday != $invoiceday) { |
|---|
| 117 |
if ($verbose_level>=1) echo "\nIt is not Customer ".$Customer[0]." billday"; |
|---|
| 118 |
continue; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
$invoice->RetrieveInformation($Customer[0], $billcalls == "on", $billcharges == "on", $nowdate); |
|---|
| 122 |
$invoice->CreateInvoice($choose_currency); |
|---|
| 123 |
$invoice->BillInvoice(($enableminimalamount == 'on'), $minimalamount, $customtemplate); |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
//if ($sendemail == 'Yes') |
|---|
| 127 |
// $invoice->SendEMail($smarty); |
|---|
| 128 |
} |
|---|
| 129 |
} |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
?> |
|---|
| 133 |
|
|---|