}
        } else {
            $numrow = 0;
        }
        if ($verbose_level >= 1) {
            echo "\n Total Customers Found: " . $numrow;
        }
        if ($numrow == 0) {
            if ($verbose_level >= 1) {
                echo "\n[No card to create the Invoice]\n";
            }
            exit;
        } else {
            foreach ($resmax as $Customer) {
                $invoice->RetrieveInformation($Customer[0], $billcalls == "on", $billcharges == "on", $nowdate);
                $invoice->CreateInvoice($choose_currency);
                $invoice->BillInvoice($enableminimalamount == 'on', $minimalamount, $customtemplate);
                if ($sendemail == "on") {
                    $invoice->SendEMail($smarty);
                }
            }
        }
    }
}
$HD_Form->init();
if (cardid != '' || !is_null($cardid)) {
    $HD_Form->FG_EDITION_CLAUSE = str_replace("%id", "{$cardid}", $HD_Form->FG_EDITION_CLAUSE);
}
$HD_Form->FG_OTHER_BUTTON1 = false;
$HD_Form->FG_OTHER_BUTTON2 = false;
$form_action = "list";
getpost_ifset(array('invoice_type', 'cardid', 'billcalls', 'billcharges', 'id', 'exporttype', 'payment_status', 'templatefile'));
// Because, in order to display pdf, there shall be no html displayed
if ($exporttype == 'pdf') {
    $verbose_level = 0;
}
// Connect to Database
$DBHandle = DbConnect();
try {
    // Create Invoice object
    $invoice = new A2B_Invoice($DBHandle, $verbose_level);
    // Collect Data
    switch ($invoice_type) {
        case "":
        case 1:
            $invoice->RetrieveInformation($cardid, $billcalls == 'on', $billcharges == 'on', date('Y-m-d H:i:s'));
            $invoice->CreateInvoice();
            $invoice_type_name = 'outstanding';
            break;
        case 2:
            $invoice->LoadInvoice($id);
            // Change Payment Status if posted so
            if ($payment_status != "") {
                $QUERY = "UPDATE cc_invoice SET payment_status ='{$payment_status}' WHERE id='{$id}'";
                $DBHandle->Execute($QUERY);
                if ($verbose_level >= 1) {
                    echo "\nQUERY_INVOICESTATUS: " . $QUERY;
                }
            }
            $invoice_type_name = 'billed';
            break;
        default: