function fbilling_generate_invoice($src, $search_results, $search_summary) { # filename related $extension_id = fbilling_get_data_by_field("extensions", "id", "sip_num", $src); $invoice_dir = "/var/www/html/fbilling_data/invoices/"; $stamp = time(); $creation_date = date("Y-m-d H:i:s"); $invoice_file = "inv_" . $src . "_" . $stamp . ".pdf"; $filename = $invoice_dir . $invoice_file; # pagind related $rows_per_page = 40; $rows = sizeof($search_results); $number_of_pages = ceil($rows / 40); # generate pdf $pdf = new PDF(); $pdf->SetFont('Arial', '', 12); # WARNING, ugly things coming through! # for PDF pagination, we loop through number of pages we have for ($page = 0; $page < $number_of_pages; $page++) { $pdf->AddPage(); # createnew page if ($page == 0) { # we need PDF header on first page $pdf->Cell(150, 10, "Invoice for extension {$src}", 0, 1, 'C'); } else { $pdf->SetFont('Arial', 'B', 10); $pdf->Cell(150, 10, "Continued from page {$page}", 0, 1, 'C'); } $pdf->Ln(); # since we need pagination, we'd rather slice array then run several queries... $pdf->SetFont('Arial', '', 12); $page_rows = array_chunk($search_results, 38); $pdf->generate_table($page_rows[$page]); $pdf->SetFont('Arial', 'B', 8); $pdf->Ln(); $pdf->Cell(150, 10, $page + 1, 0, 1, 'C'); } # after pagination is done, create one last page with summary $pdf->AddPage(); $pdf->SetFont('Arial', 'B', 12); $pdf->Cell(150, 10, "Summary for this invoice", 0, 1, 'C'); # create summary table $pdf->Cell('90', 0, '', 'T'); $pdf->Ln(); #$pdf->Cell('90',0,'','T'); $pdf->Cell('60', 6, "Number of Calls", 'LR'); $pdf->Cell('30', 6, $search_summary['number_of_calls'], 'LR'); $pdf->Ln(); #$pdf->Cell('90',0,'','T'); $pdf->Cell('60', 6, "Total Duration of Calls", 'LR'); $pdf->Cell('30', 6, $search_summary['total_duration'], 'LR'); $pdf->Ln(); #$pdf->Cell('90',0,'','T'); $pdf->Cell('60', 6, "Total Cost", 'LR'); $pdf->Cell('30', 6, round($search_summary['total_cost'], 3), 'LR'); $pdf->Ln(); $pdf->Cell('90', 0, '', 'T'); $pdf->Output($filename, 'F'); // insert into invoice table $fields = array("extension_id", "creation_date", "filename"); $values = array($extension_id[0][0], $creation_date, $invoice_file); fbilling_add("invoices", $fields, $values); return $invoice_file; }
} if ($insert_ok > 0) { echo _("Permission with specified name already exists in database, please provide different name, and try again"); echo "<a href='javascript:history.go(-1)''> Go Back</a>"; return true; } else { $fields = "name = '{$name}', is_active = {$is_active}"; fbilling_edit($cat, $fields, $id); // update permission details fbilling_del('permission_weights', 'permission_id', $id); // delete all weight relationships for this permission $fields = array('permission_id', 'weight_id'); foreach ($weight_id as $w) { $values[] = array($name, $w); } fbilling_add('permission_weights', $fields, $values); // insert new weight relationships for this permission redirect_standard('cat'); } } ?> <script> function check_permission_form() { if (document.forms["permission_form"]["name"]) { if (document.forms["permission_form"]["name"].value==null || document.forms["permission_form"]["name"].value=="") { alert("Please provide valid permission name"); return false; } }
// check if tariff for specified prefix exists $insert_ok = fbilling_check_if_exists($cat, 'prefix_id', $prefix_id); if ($insert_ok > 0) { // if tariff for this prefix exists, check if it belongs to requested tenant $insert_ok = fbilling_check_if_exists($cat, 'tenant_id', $tenant_id); } if ($insert_ok > 0) { // if tariff for this tenant exists, exit echo _("Tariff for requested prefix and tenant exists."); echo "<br /><a href='javascript:history.go(-1)''>Go Back</a>"; // TODO add edit link for existing tariff return true; } $fields = array('prefix_id', 'cost', 'tenant_id', 'trunk_id', 'initial_cost'); $values = array($prefix_id, $cost, $tenant_id, $trunk_id, $initial_cost); fbilling_add($cat, $fields, $values); redirect_standard('cat'); } elseif ($action == 'conf_edit') { // we can change only trunk and costs when editting tariffs, so we will have no duplicates, insert_ok not needed here $fields = "cost = '{$cost}', initial_cost = {$initial_cost}, trunk_id = '{$trunk_id}'"; fbilling_edit($cat, $fields, $id); redirect_standard('cat'); } elseif ($action == 'import') { // startif (action import) echo _("Uploaded CSV file should contain three values per row - Pattern to match, per minute cost, one time cost"); echo "<br />"; echo _("Download sample template file"); echo "<a href=/fbilling_data/fbilling_tariffs_TEMPLATE.csv> Template File</a>"; echo "<br />"; echo "<br />"; ?>