function list_reports($type, $value, $sortby, $sortdir, $widget_mode) { global $allres, $roffset, $pageSize, $dbconn; global $user, $arruser; $dbconn->SetFetchMode(ADODB_FETCH_BOTH); $filteredView = FALSE; $selRadio = array("", "", "", ""); $query_onlyuser = ""; $url_filter = ""; if (!empty($arruser)) { $query_onlyuser = "******"; } if (!empty($sortby)) { $or_sortby = $sortby; } else { $or_sortby = ""; } if (!empty($sortdir)) { $or_sortdir = $sortdir; } else { $or_sortdir = ""; } if ($sortby == "jobname") { $sortby = "t2.name"; } else { if ($sortby == "profile") { $sortby = "t3.name"; } } if ($sortby == "") { $sortby = "scantime"; } if ($sortdir == "" && !preg_match("/(ASC|DESC)\$/i", $sortby)) { $sortdir = "DESC"; } $queryw = ""; $queryl = ""; $leftjoin = ""; if ($type == "net") { $leftjoin = "LEFT JOIN vuln_nessus_results t5 ON t5.report_id=t1.report_id"; } $querys = "SELECT distinct t1.sid as sid, t1.report_id, t4.name as jobname, t4.scan_submit, t4.meth_target, t1.scantime,\n t1.username, t1.scantype, t1.report_key, t1.report_type as report_type, t3.name as profile, t4.id as jobid, t4.meth_SCHED, t1.name as report_name\n FROM vuln_nessus_reports t1\n LEFT JOIN vuln_jobs t2 ON t1.report_id=t2.report_id\n LEFT JOIN vuln_nessus_settings t3 ON t1.sid=t3.id\n LEFT JOIN vuln_jobs t4 on t1.report_id = t4.report_id {$leftjoin}\n WHERE t1.deleted = '0' AND t1.scantime IS NOT NULL "; //Set up the SQL query based on the search form input (if any) switch ($type) { case "scantime": $selRadio[0] = "CHECKED"; $utc_data = Util::get_utc_from_date($dbconn, $value, Util::get_timezone()); $q = $utc_data[6]; $q = str_replace("-", "", $q); $q = str_replace(":", "", $q); $q = str_replace(" ", "", $q); $queryw = " AND t1.scantime LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$roffset},{$pageSize}"; $stext = "<b>" . _("Search for Date/Time") . "</b> = '*{$value}*'"; $url_filter = "&type={$type}&value={$value}"; break; case "jobname": $selRadio[1] = "CHECKED"; $q = strtolower($value); $queryw = " AND t1.name LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$roffset},{$pageSize}"; $stext = "<b>" . _("Search for Job Name") . "</b> = '*" . html_entity_decode($q) . "*'"; $url_filter = "&type={$type}&value={$value}"; break; case "fk_name": $selRadio[2] = "CHECKED"; $q = strtolower($value); $queryw = " AND t1.fk_name LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$roffset},{$pageSize}"; $stext = _("Search for Subnet/CIDR") . " = '*{$q}*'"; $url_filter = "&type={$type}&value={$value}"; break; case "username": $selRadio[3] = "CHECKED"; $q = strtolower($value); $queryw = " AND t1.username LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$roffset},{$pageSize}"; $stext = "<b>" . _("Search for user") . "</b> = '*{$q}*'"; $url_filter = "&type={$type}&value={$value}"; break; case "net": $selRadio[4] = "CHECKED"; if (!preg_match("/\\//", $value)) { $q = $value; } else { $tokens = explode("/", $value); $bytes = explode(".", $tokens[0]); if ($tokens[1] == "24") { $q = $bytes[0] . "." . $bytes[1] . "." . $bytes[2] . "."; } else { if ($tokens[1] == "16") { $q = $bytes[0] . "." . $bytes[1] . "."; } else { if ($tokens[1] == "8") { $q = $bytes[0] . "."; } else { if ((int) $tokens[1] > 24) { $q = $bytes[0] . "." . $bytes[1] . "." . $bytes[2] . "." . $bytes[3]; } } } } } $queryw = " AND (t4.meth_TARGET LIKE '%{$q}%' OR t5.hostIP LIKE '%{$q}%') {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$roffset},{$pageSize}"; if (!preg_match("/\\//", $value)) { $stext = "<b>" . _("Search for Host") . "</b> = '*" . html_entity_decode($q) . "*'"; } else { $stext = "<b>" . _("Search for Subnet/CIDR") . "</b> = '*{$q}*'"; } $url_filter = "&type={$type}&value={$value}"; break; default: $selRadio[1] = "CHECKED"; $viewAll = FALSE; $queryw = "{$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$roffset},{$pageSize}"; $stext = ""; break; } $reportCount = 0; if (!$filteredView) { $queryc = "SELECT count(t1.report_id)\n FROM vuln_nessus_reports t1 LEFT JOIN vuln_jobs t2 on t1.report_id = t2.report_id\n LEFT JOIN vuln_nessus_settings t3 ON t1.sid=t3.id\n WHERE t1.deleted = '0'"; $reportCount = $dbconn->GetOne($queryc . $queryw); $previous = $roffset - $pageSize; if ($previous < 0) { $previous = 0; } $last = intval($reportCount / $pageSize) * $pageSize; if ($last < 0) { $last = 0; } $next = $roffset + $pageSize; $pageEnd = $roffset + $pageSize; $value = html_entity_decode($value); $w_val = intval($widget_mode); //echo "<center><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tr><td class=\"headerpr\" style=\"border:0;\">"._("Reports")."</td></tr></table></center>"; // output the search form echo "<table cellspacing='0' cellpadding='0' class='w100 transparent'>"; echo "<tr><td class='sec_title'>" . _("Scan Reports Details") . "</td></tr>"; echo "<tr><td style='padding-top:12px;' class='transparent'>"; echo ' <center> <form name="hostSearch" action="index.php" method="GET"> <input type="hidden" name="widget_mode" value="' . $w_val . '"> <input type="text" length="25" name="rvalue" id="rvalue" value="' . Util::htmlentities($value) . '">'; echo "\n<input type=\"radio\" name=\"type\" value=\"scantime\" {$selRadio['0']}>" . _("Date") . "/" . _("Time") . "\n<input type=\"radio\" name=\"type\" value=\"jobname\" {$selRadio['1']}>" . _("Job Name") . "\n<input type=\"radio\" name=\"type\" value=\"net\" {$selRadio['4']}>" . _("Host") . "/" . _("Net") . "\n"; echo <<<EOT <input type="hidden" name="sortby" value="{$sortby}"> <input type="hidden" name="allres" value="{$allres}"> <input type="hidden" name="op" value="search"> EOT; echo "<input type=\"submit\" name=\"submit\" value=\"" . _("Find") . "\" id=\"reports_find_button\" class=\"av_b_secondary small\">"; echo <<<EOT </form> </center> </p> EOT; } else { // get the search result count $queryc = "SELECT count( report_id ) FROM vuln_nessus_reports WHERE t1.deleted = '0' "; $scount = $dbconn->GetOne($queryc . $queryw); echo "<p>{$scount} report"; if ($scount != 1) { echo "s"; } else { } echo " " . _("found matching search criteria") . " | "; echo " <a href='index.php' alt='" . _("View All Reports") . "'>" . _("View All Reports") . "</a></p>"; } echo "<p>"; echo $stext; echo "</p>"; echo "</td></tr></table>"; // get the hosts to display //print_r($querys.$queryw.$queryl); $result = $dbconn->GetArray($querys . $queryw . $queryl); if ($result === false) { $errMsg[] = _("Error getting results") . ": " . $dbconn->ErrorMsg(); $error++; dispSQLError($errMsg, $error); } else { $tdata = array(); foreach ($result as $data) { $data['vSerious'] = 0; $data['vHigh'] = 0; $data['vMed'] = 0; $data['vLow'] = 0; $data['vInfo'] = 0; $vulns_in_report = false; // query for reports for each IP $perms_where = Asset_host::get_perms_where('host.', TRUE); if (!empty($perms_where)) { $query_risk = "SELECT count(lr.risk) as count, lr.risk, lr.hostIP, lr.ctx\n FROM vuln_nessus_results lr, host, host_ip hi\n WHERE host.id=hi.host_id AND inet6_ntoa(hi.ip)=lr.hostIP {$perms_where} AND report_id in (?) AND falsepositive='N'\n GROUP BY lr.risk, lr.hostIP, lr.ctx"; } else { $query_risk = "SELECT count(lr.risk) as count, lr.risk, lr.hostIP, lr.ctx\n FROM vuln_nessus_results lr\n WHERE report_id in (?) AND falsepositive='N'\n GROUP BY lr.risk, lr.hostIP, lr.ctx"; } $result_risk = $dbconn->Execute($query_risk, array($data['report_id'])); while (!$result_risk->EOF) { $vulns_in_report = TRUE; if ($result_risk->fields["risk"] == 7) { $data['vInfo'] += $result_risk->fields['count']; } else { if ($result_risk->fields["risk"] == 6) { $data['vLow'] += $result_risk->fields['count']; } else { if ($result_risk->fields["risk"] == 3) { $data['vMed'] += $result_risk->fields['count']; } else { if ($result_risk->fields["risk"] == 2) { $data['vHigh'] += $result_risk->fields['count']; } else { if ($result_risk->fields["risk"] == 1) { $data['vSerious'] += $result_risk->fields['count']; } } } } } $result_risk->MoveNext(); } $data['clink'] = "respdfc.php?scantime=" . $data['scantime'] . "&scantype=" . $data['scantype'] . "&key=" . $data['report_key'] . $more; $data['plink'] = "respdf.php?scantime=" . $data['scantime'] . "&scantype=" . $data['scantype'] . "&key=" . $data['report_key'] . $more; $data['hlink'] = "reshtml.php?disp=html&output=full&scantime=" . $data['scantime'] . "&scantype=" . $data['scantype'] . $more; $data['rerun'] = "sched.php?action=rerun_scan&job_id=" . $data['jobid'] . $more; $data['xlink'] = "rescsv.php?scantime=" . $data['scantime'] . "&scantype=" . $data['scantype'] . "&key=" . $data['report_key'] . $more; $data['xbase'] = "restextsummary.php?scantime=" . $data['scantime'] . "&scantype=" . $data['scantype'] . $more . "&key=" . $data['report_key']; $list = array(); if ($data["report_type"] == "I") { $perms_where = Asset_host::get_perms_where('host.', TRUE); $dbconn->execute("CREATE TEMPORARY TABLE tmph (id binary(16) NOT NULL,ip varchar(64) NOT NULL,ctx binary(16) NOT NULL, PRIMARY KEY ( id, ip ));"); $dbconn->execute("REPLACE INTO tmph SELECT id, inet6_ntoa(ip), ctx FROM host, host_ip WHERE host.id=host_ip.host_id {$perms_where};"); $result_import = $dbconn->execute("SELECT DISTINCT hostIP, HEX(vuln_nessus_results.ctx) as ctx, hex(id) as host_id FROM vuln_nessus_results LEFT JOIN tmph ON tmph.ctx=vuln_nessus_results.ctx AND hostIP=tmph.ip WHERE report_id = " . $data['report_id']); while (!$result_import->EOF) { if (valid_hex32($result_import->fields["host_id"])) { $list[] = $result_import->fields["host_id"] . "#" . $result_import->fields["hostIP"]; } else { $list[] = $result_import->fields["hostIP"]; } $result_import->MoveNext(); } $dbconn->execute("DROP TABLE tmph;"); } else { $list = explode("\n", trim($data['meth_target'])); } //var_dump($list); if (count($list) == 1) { $list[0] = trim($list[0]); $asset = resolve_asset($dbconn, $list[0], true); $data['target'] = "<span class='tip' title='" . clean_id($list[0]) . "'>" . $asset . "</span>"; } elseif (count($list) == 2) { $list[0] = trim($list[0]); $asset = resolve_asset($dbconn, $list[0], true); $list[0] = "<span class='tip' title='" . clean_id($list[0]) . "'>" . $asset . "</span>"; $list[1] = trim($list[1]); $asset = resolve_asset($dbconn, $list[1], true); $list[1] = "<span class='tip' title='" . clean_id($list[1]) . "'>" . $asset . "</span>"; $data['target'] = $list[0] . ', ' . $list[1]; } else { $list[0] = trim($list[0]); $asset = resolve_asset($dbconn, $list[0], true); $list[0] = "<span class='tip' title='" . clean_id($list[0]) . "'>" . $asset . "</span>"; $list[count($list) - 1] = trim($list[count($list) - 1]); $asset = resolve_asset($dbconn, $list[count($list) - 1], true); $list[count($list) - 1] = "<span class='tip' title='" . clean_id($list[count($list) - 1]) . "'>" . $asset . "</span>"; $data['target'] = $list[0] . " ... " . $list[count($list) - 1]; } if ($data["report_type"] == "I") { $data["jobname"] = $data["report_name"]; } if ($data['vSerious'] == 0 && $data['vHigh'] == 0 && $data['vMed'] == 0 && $data['vLow'] == 0 && $data['vInfo'] == 0 && $vulns_in_report) { $data['vSerious'] = "-"; $data['vHigh'] = "-"; $data['vMed'] = "-"; $data['vLow'] = "-"; $data['vInfo'] = "-"; } $data['target'] = preg_replace("/[0-9a-f]{32}#/i", "", $data['target']); $tdata[] = $data; } if ($sortdir == "ASC") { $sortdir = "DESC"; } else { $sortdir = "ASC"; } $url = $_SERVER['SCRIPT_NAME'] . "?offset=0&sortby=%var%&sortdir={$sortdir}" . $url_filter; $fieldMapLinks = array(); $fieldMapLinks = array(gettext("HTML Results") => array('url' => '%param%', 'param' => 'hlink', 'target' => 'main', 'icon' => 'images/html.png'), gettext("PDF Results") => array('url' => '%param%', 'param' => 'plink', 'target' => '_blank', 'icon' => 'images/pdf.png'), gettext("EXCEL Results") => array('url' => '%param%', 'param' => 'xlink', 'target' => '_blank', 'icon' => 'images/page_white_excel.png')); $fieldMap = array("Date/Time" => array('var' => 'scantime', 'link' => $url), "Job Name" => array('var' => 'jobname', 'link' => $url), "Targets" => array('var' => 'target', 'link' => $url), "Profile" => array('var' => 'profile', 'link' => $url), "Serious" => array('var' => 'vSerious', 'link' => $url), "High" => array('var' => 'vHigh', 'link' => $url), "Medium" => array('var' => 'vMed', 'link' => $url), "Low" => array('var' => 'vLow', 'link' => $url), "Info" => array('var' => 'vInfo', 'link' => $url), "Links" => $fieldMapLinks); if (count($tdata) > 0) { drawTable($fieldMap, $tdata, "Hosts", get_hosts($dbconn)); } else { ?> <table class="table_list"> <tr><td class="nobborder" style="text-align:center;padding: 8px 0px 0px 0px;"><strong><?php echo _("No reports found"); ?> </strong><br/><br/></td></tr> </table> <?php } } // draw the pager again, if viewing all hosts if ($last != 0) { ?> <div class="fright tmargin"> <?php if ($next > $pageSize) { ?> <a href="index.php?sreport=1&<?php echo "sortdir={$or_sortdir}&roffset={$previous}&sortby={$or_sortby}{$url_filter}"; ?> " class="pager">< <?php echo _("PREVIOUS"); ?> </a> <?php } else { ?> <a class='link_paginate_disabled' href="" onclick='return false'>< <?php echo _("PREVIOUS"); ?> </a> <?php } if ($next <= $last) { ?> <a class='lmargin' href="index.php?sreport=1&<?php echo "sortdir={$or_sortdir}&roffset={$next}&sortby={$or_sortby}{$url_filter}"; ?> "> <?php echo _("NEXT"); ?> ></a> <?php } else { ?> <a class='link_paginate_disabled lmargin' href="" onclick='return false'><?php echo _("NEXT"); ?> ></a> <?php } ?> </div> <?php } else { echo "<p> </p>"; } }
function templatePdf($_POST) { extract($_POST); global $set_mainFont; $pdf =& new Cezpdf(); $pdf->selectFont($set_mainFont); // Validate require_lib("validate"); $v = new Validate(); foreach ($invids as $invid) { $v->isOk($invid, "num", 1, 20, "Invalid invoice number."); } // Any errors? if ($v->isError()) { $err = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class=error>{$e['msg']}</li>"; } $OUTPUT = $confirm; require "template.php"; } $ai = 0; foreach ($invids as $invid) { if ($ai) { $pdf->ezNewPage(); } ++$ai; // Invoice info db_conn("cubit"); $sql = "SELECT * FROM nons_invoices WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice info."); if (pg_num_rows($invRslt) == 0) { return "<li class=err>Not found</li>"; } $inv = pg_fetch_array($invRslt); // Only needs to be blank, we're manually adding text $heading = array(array("")); // Company info ---------------------------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'"; $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit."); $comp = pg_fetch_array($ciRslt); $bnkData = qryBankAcct(cust_bank_id($inv["cusid"])); $compinfo = array(); $compinfo[] = array($comp["addr1"], "{$comp['paddr1']}"); $compinfo[] = array($comp["addr2"], "{$comp['paddr2']}"); $compinfo[] = array($comp["addr3"], "{$comp['paddr3']}"); $compinfo[] = array($comp["addr4"], "{$comp['postcode']}"); $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>"); $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}"); $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}"); $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}"); // Date ------------------------------------------------------------------ $date = array(array("<b>Date</b>"), array($inv['odate'])); // Document info --------------------------------------------------------- db_conn('cubit'); $Sl = "SELECT * FROM settings WHERE constant='SALES'"; $Ri = db_exec($Sl) or errDie("Unable to get settings."); $data = pg_fetch_array($Ri); if ($data['value'] == "Yes") { $sp = "<b>Sales Person: </b>{$inv['salespn']}"; } else { $sp = ""; } $docinfo = array(array("<b>Invoice No:</b> {$inv['invnum']}"), array("<b>Proforma Inv No:</b> {$inv['docref']}"), array("{$sp}")); // Customer info --------------------------------------------------------- if ($inv["cusid"] != 0) { db_conn("cubit"); $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusid']}'"; $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit."); $cusData = pg_fetch_array($cusRslt); } else { $cusData["surname"] = $inv["cusname"]; $cusData["addr1"] = $inv["cusaddr"]; $cusData["paddr1"] = ""; $cusData["accno"] = ""; } $cusinfo = array(array("<b>{$cusData['surname']}</b>")); $cusaddr = explode("\n", $cusData['paddr1']); foreach ($cusaddr as $v) { $cusinfo[] = array(pdf_lstr($v, 40)); } $cusinfo[] = array("<b>Account no: </b>{$cusData['accno']}"); $cusdaddr = array(array("<b>Physical Address:</b>")); $cusaddr = explode("\n", $cusData['addr1']); foreach ($cusaddr as $v) { $cusdaddr[] = array(pdf_lstr($v, 40)); } // Registration numbers -------------------------------------------------- $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}")); // Items display --------------------------------------------------------- $items = array(); db_conn("cubit"); $sql = "SELECT * FROM nons_inv_items WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'"; $stkdRslt = db_exec($sql); while ($stkd = pg_fetch_array($stkdRslt)) { // Check Tax Excempt db_conn("cubit"); $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatex']}'"; $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); $vatex = pg_fetch_result($zRslt, 0); if ($vatex == "Yes") { $ex = "#"; } else { $ex = ""; } $items[] = array("Description" => pdf_lstr($ex . $stkd['description'], 65), "Qty" => $stkd['qty'], "Unit Price" => CUR . $stkd['unitcost'], "Amount" => CUR . $stkd['amt']); } // Comment --------------------------------------------------------------- db_conn("cubit"); $sql = "SELECT value FROM settings WHERE constant='DEFAULT_COMMENTS'"; $commentRslt = db_exec($sql) or errDie("Unable to retrieve the default comment from Cubit."); $default_comment = pg_fetch_result($commentRslt, 0); $comment = array(array("<i>VAT Exempt Indicator: #</i>"), array(base64_decode($default_comment))); // Box to sign in -------------------------------------------------------- $sign = array(array("<i>Thank you for your support</i>"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array(" <b>Date:</b> ____________________")); // Totals ---------------------------------------------------------------- $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => CUR . "{$inv['subtot']}"), array("1" => "<b>VAT @ " . TAX_VAT . "%:</b> ", "2" => CUR . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => CUR . "{$inv['total']}")); $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right")); $ic = 0; while (++$ic * 20 < count($items)) { } // Draw the pages, determine by the amount of items how many pages // if items > 20 start a new page $items_print = array(); for ($i = 0; $i < $ic; $i++) { if ($i) { $pdf->ezNewPage(); } // Page number ------------------------------------------------------- $pagenr = array(array("<b>Page number</b>"), array($i + 1)); // Heading $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5); drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 0, $heading_pos['y'] / 2 + 6); drawText(&$pdf, "<b>Tax Invoice</b>", 18, $heading_pos['x'] - 120, $heading_pos['y'] / 2 + 9); $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8); $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 4); $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 4); $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 4); $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $compinfo_pos['y'], 320, 10); $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cusinfo_pos['x'], $compinfo_pos['y'], 200, 10); $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2); $items_start = $i * 20; if ($items_start >= count($items) - 20) { $items_end = count($items) - 1; } else { $items_end = ($i + 1) * 20; } $items_print = array(); for ($j = $items_start; $j <= $items_end; $j++) { $items_print[$j] = $items[$j]; } // Adjust the column widths $cols = array("Description" => array("width" => 310), "Qty" => array("width" => 50), "Unit Price" => array("width" => 80, "justification" => "right"), "Amount" => array("width" => 80, "justification" => "right")); $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 20, $cols, 1); $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2); $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5); $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols); } } $pdf->ezStream(); }
function showLateThings() { $c = new Crm(); $tempArr = $c->futureORlateThings("l"); if (count($tempArr) == 0) { return "Записей нет."; } $tableNames = $c->getCollNames(); return drawTable($tableNames, $tempArr); }
?> <table class="table table-selectable" style="margin-bottom: 0;"> <thead> <tr> <th>#</th> <th>Username</th> <th>Matches won</th> <th>Matches lost</th> <th>Total matches</th> </tr> </thead> <tbody> <?php for ($i = 0; $i < count($array); $i++) { if (isset($array[$i])) { drawTable($array, $i); } else { break; } } ?> </tbody> </table> <?php } else { drawInfo("<i class=\"fa fa-info-circle\"></i> No player data found."); } ?> </div> </div> </div>
function genpdf($quoid) { global $_GET; extract($_GET); global $set_mainFont; $showvat = TRUE; $pdf =& new Cezpdf(); $pdf->selectFont($set_mainFont); // Validate require_lib("validate"); $v = new Validate(); $v->isOk($quoid, "num", 1, 20, "Invalid quote number."); // Any errors? if ($v->isError()) { $err = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class='err'>{$e['msg']}</li>"; } $OUTPUT = $confirm; require "../template.php"; } // Invoice info db_conn("cubit"); $sql = "SELECT * FROM quotes WHERE quoid='{$quoid}' AND DIV='" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to retrieve quote info."); if (pg_num_rows($invRslt) < 1) { return "<li class='err'>Not found</li>"; } $inv = pg_fetch_array($invRslt); db_conn("cubit"); $sql = "SELECT symbol FROM currency WHERE fcid='{$inv['fcid']}'"; $curRslt = db_exec($sql) or errDie("Unable to retrieve currency from Cubit."); $curr = pg_fetch_result($curRslt, 0); if (!$curr) { $curr = CUR; } // Check if stock was selected db_conn("cubit"); $sql = "SELECT stkid FROM quote_items WHERE quoid='{$quoid}' AND DIV='" . USER_DIV . "'"; $cRslt = db_exec($sql) or errDie("Unable to retrieve quote info."); if (pg_num_rows($cRslt) < 1) { $error = "<li class='err'>Quote number <b>{$quoid}</b> has no items</li>"; $OUTPUT = $error; } // Only needs to be blank, we're manually adding text $heading = array(array("")); // Company info ---------------------------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'"; $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit."); $comp = pg_fetch_array($ciRslt); // Banking information --------------------------------------------------- $bnkData = qryBankAcct(getdSetting("BANK_DET")); $compinfo = array(); $compinfo[] = array($comp["addr1"], $comp["paddr1"]); $compinfo[] = array(pdf_lstr($comp["addr2"], 35), pdf_lstr($comp["paddr2"], 35)); $compinfo[] = array(pdf_lstr($comp["addr3"], 35), pdf_lstr($comp["paddr3"], 35)); $compinfo[] = array(pdf_lstr($comp["addr4"], 35), "{$comp['postcode']}"); $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>"); $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}"); $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}"); $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}"); // Date ------------------------------------------------------------------ $date = array(array("<b>Date</b>"), array($inv['odate'])); // Document info --------------------------------------------------------- db_conn('cubit'); $Sl = "SELECT * FROM settings WHERE constant='SALES'"; $Ri = db_exec($Sl) or errDie("Unable to get settings."); $data = pg_fetch_array($Ri); db_conn('cubit'); $Sl = "SELECT * FROM settings WHERE constant='SALES'"; $Ri = db_exec($Sl) or errDie("Unable to get settings."); $data = pg_fetch_array($Ri); if ($data['value'] == "Yes") { $sp = "<b>Sales Person: </b>{$inv['salespn']}"; } else { $sp = ""; } $docinfo = array(array("<b>Quote No:</b> {$inv['quoid']}"), array("<b>Proforma Inv No:</b> {$inv['docref']}"), array("<b>Sales Order No:</b> {$inv['ordno']}"), array("{$sp}")); if (isset($salespn)) { $docinfo[] = array("<b>Sales Person:</b> {$salespn}"); } // Retrieve the customer information ------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusnum']}'"; $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit."); $cusData = pg_fetch_array($cusRslt); // Customer info --------------------------------------------------------- $invoice_to = array(array("")); $cusinfo = array(array("<b>{$inv['surname']}</b>")); $cusaddr = explode("\n", $cusData['addr1']); foreach ($cusaddr as $v) { $cusinfo[] = array(pdf_lstr($v, 40)); } $cusinfo[] = array("<b>Account no: </b>{$cusData['accno']}"); $cuspaddr = array(array("<b>Postal Address</b>")); $paddr = explode("\n", $cusData["paddr1"]); foreach ($paddr as $addr) { $cuspaddr[] = array($addr); } $cusdaddr = array(array("<b>Delivery Address:</b>")); if ($inv['branch'] == 0) { $branchname = "Head Office"; $cusaddr = explode("\n", $cusData['addr1']); } else { $get_addr = "SELECT * FROM customer_branches WHERE id = '{$inv['branch']}' LIMIT 1"; $run_addr = db_exec($get_addr); if (pg_numrows($run_addr) < 1) { $cusaddr = array(); $branchname = "Head Office"; } else { $barr = pg_fetch_array($run_addr); $cusaddr = explode("\n", $barr['branch_descrip']); $branchname = $barr['branch_name']; } } $cusdaddr[] = array(pdf_lstr("Branch : {$branchname}", 30)); $del_addr = explode("\n", $inv["del_addr"]); foreach ($del_addr as $addr) { $cusdaddr[] = array(pdf_lstr($addr, 30)); } // Registration numbers -------------------------------------------------- $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}")); // Items display --------------------------------------------------------- $items = array(); db_conn("cubit"); $sql = "SELECT * FROM quote_items WHERE quoid='{$quoid}' AND DIV='" . USER_DIV . "'"; $stkdRslt = db_exec($sql); while ($stkd = pg_fetch_array($stkdRslt)) { // Get warehouse db_conn("exten"); $sql = "SELECT * FROM warehouses WHERE whid='{$stkd['whid']}' AND DIV='" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); // Get stock in this warehouse db_conn("cubit"); $sql = "SELECT * FROM stock WHERE stkid='{$stkd['stkid']}' AND DIV='" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); $sp = ""; // Check Tax Excempt db_conn("cubit"); $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatcode']}'"; $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); $vatex = pg_fetch_result($zRslt, 0); if ($vatex == "Yes") { $ex = "#"; } else { $ex = ""; } $sql = "SELECT * FROM vatcodes WHERE id='{$stkd['vatcode']}'"; $runsql = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); if (pg_numrows($runsql) < 1) { return "Invalid VAT code entered"; } $vd = pg_fetch_array($runsql); if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") { $showvat = FALSE; } // keep track of discounts //$disc += $stkd['disc']; if ($stkd["account"] > 0) { $description = $stkd["description"]; } else { $description = $stk["stkdes"]; } // Remove any new lines from the description $ar_desc = explode("\n", $description); $description = implode(" ", $ar_desc); $items[] = array("Code" => makewidth($pdf, 75, 12, $stk['stkcod']), "Description" => makewidth($pdf, 175, 12, $ex . $description), "Qty" => $stkd['qty'], "Unit Price" => $curr . $stkd['unitcost'], "Unit Discount" => $curr . $stkd['disc'], "Amount" => $curr . $stkd['amt']); } $inv["comm"] = fixparag(&$pdf, 3, 520, 11, $inv["comm"]); /*$inv["comm"] = preg_replace("/[\n]/", " ", $inv["comm"]); $lines = array(); $txtleft = $inv["comm"]; $done = false; while (count($lines) < 3 && !$done) { $mc = maxwidth(&$pdf, 520, 11, $txtleft); // run until end of a word. while ($txtleft[$mc - 1] != ' ' && $mc < strlen($txtleft)) ++$mc; if ($mc == strlen($txtleft)) { $done = true; } $lines[] = substr($txtleft, 0, $mc); $txtleft = substr($txtleft, $mc); } if (strlen($txtleft) > 0) { $lines[2] .= "..."; } $inv["comm"] = preg_replace("/ /", " ", implode("\n", $lines));*/ // Comment --------------------------------------------------------------- $comment = array(array("<i>VAT Exempt Indicator : #</i>"), array($inv["comm"])); // Box for signature ----------------------------------------------------- $sign = array(array("<b>Terms:</b> {$inv['terms']} days"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array(" <b>Date:</b> ____________________")); // Totals ---------------------------------------------------------------- if (!isset($showvat)) { $showvat = TRUE; } if ($showvat == TRUE) { $vat14 = AT14; } else { $vat14 = ""; } $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => $curr . "{$inv['subtot']}"), array("1" => "<b>Trade Discount:</b> ", "2" => $curr . "{$inv['discount']}"), array("1" => "<b>Delivery Charge:</b> ", "2" => $curr . "{$inv['delivery']}"), array("1" => "<b>VAT {$vat14}:</b> ", "2" => $curr . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => $curr . "{$inv['total']}")); $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right")); $ic = 0; while (++$ic * 22 < count($items)) { } // Draw the pages, determine by the amount of items how many pages // if items > 20 start a new page $items_print = array(); for ($i = 0; $i < $ic; $i++) { if ($i) { $pdf->ezNewPage(); } // Page number ------------------------------------------------------- $pagenr = array(array("<b>Page number</b>"), array($i + 1)); // Heading $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5); drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 0, $heading_pos['y'] / 2 + 6); drawText(&$pdf, "<b>Quote</b>", 20, $heading_pos['x'] - 120, $heading_pos['y'] / 2 + 9); // Should we display reprint on the invoice if ($type == "invreprint") { drawText(&$pdf, "<b>Reprint</b>", 12, $heading_pos['x'] - 70, $heading_pos['y'] / 2 + 22); } $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8); $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 3); $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 3); $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 5); $invoice_to_pos = drawTable(&$pdf, $invoice_to, 0, $compinfo_pos['y'], 520, 2); drawText(&$pdf, "<b>Quote To:</b>", 12, 520 / 2 - 45, $invoice_to_pos['y'] - 7); $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $invoice_to_pos['y'], 173, 8); $cuspaddr_pos = drawTable(&$pdf, $cuspaddr, $cusinfo_pos['x'], $invoice_to_pos['y'], 173, 8); $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cuspaddr_pos['x'], $invoice_to_pos['y'], 174, 8); $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2); $items_start = $i * 22; if ($i) { $items_start++; } if ($items_start >= count($items) - 22) { $items_end = count($items) - 1; } else { $items_end = ($i + 1) * 22; } $items_print = array(); for ($j = $items_start; $j <= $items_end; $j++) { $items_print[$j] = $items[$j]; } $cols = array("Code" => array("width" => 80), "Description" => array("width" => 180), "Qty" => array("width" => 33), "Unit Price" => array("width" => 80, "justification" => "right"), "Unit Discount" => array("width" => 67, "justification" => "right"), "Amount" => array("width" => 80, "justification" => "right")); $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 22, $cols, 1); $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2); $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5); $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols); } return $pdf->output(); }
<table> <tr valign="top"> <td> <?php drawTable($this->default_language, jgettext('Default language'), $cutAfter, false); ?> </td> <td> <?php drawTable($this->translated_language, jgettext('Translated language'), $cutAfter, false); ?> </td> <td> <?php drawTable($this->corrected_language, jgettext('Corrected language'), $cutAfter, true); ?> </td> </tr> </table> <?php function drawTable($langFile, $title, $cutAfter, $displayFormField) { ?> <table class="adminlist"> <tr> <th colspan="2"><?php echo $title; ?> </th>
function cusDetailsAll() { extract($_REQUEST); global $set_mainFont; $fields = array(); $fields["stmnt_type"] = "detailed"; extract($fields, EXTR_SKIP); if (!isset($report_type)) { $report_type = "all"; } switch ($report_type) { case "all": $search = ""; break; case "bal": $search = "balance != '0.00' AND "; break; default: $search = "true"; } $search2 = ""; if (isset($filt_class) and strlen($filt_class) > 0 and $filt_class != "0") { $search2 .= " class = '{$filt_class}' AND "; } if (isset($filt_cat) and strlen($filt_cat) > 0 and $filt_cat != "0") { $search2 .= " category = '{$filt_cat}' AND "; } $from_date = dateFmt($from_year, $from_month, $from_day); $to_date = dateFmt($to_year, $to_month, $to_day); $fdate = $from_date; $pdf =& new Cezpdf(); $pdf->selectFont($set_mainFont); // Heading -------------------------------------------------------------- $heading = array(array('')); #check for sort ... if (isset($sort) and $sort == "branch") { $sortinga = "ORDER BY branch"; $sorting = "branch,"; } else { $sortinga = ""; $sorting = ""; } // Customer info --------------------------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM customers WHERE {$search} {$search2} div='" . USER_DIV . "' ORDER BY surname"; $custmnt_rslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit."); if (pg_numrows($custmnt_rslt) < 1) { return "<li class='err'>No Customers Found Matching Criteria.</li>"; } while ($cust_data = pg_fetch_array($custmnt_rslt)) { $totout = 0; $cusnum = $cust_data["cusnum"]; // Company info ---------------------------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'"; $ciRlst = db_exec($sql) or errDie("Unable to retrieve the company information from Cubit."); $compinf = pg_fetch_array($ciRlst); $compinfo = array(array(COMP_NAME), array("{$compinf['addr1']}"), array("{$compinf['addr2']}"), array("{$compinf['addr3']}"), array("{$compinf['addr4']}"), array(""), array("<b>Tel:</b> {$compinf['tel']}"), array("<b>Fax:</b> {$compinf['fax']}"), array("<b>VAT REG:</b> {$compinf['vatnum']}"), array("<b>COMPANY REG:</b> {$compinf['regnum']}")); $info = array(); /* base for balance brought forward */ $info[0] = array("Date" => "", "Ref no" => "", "Details" => "<b>Balance Brought Forward: </b>", "Amount" => "", "Balance" => ""); #check for sort ... if (isset($sort) and $sort == "branch") { $sortinga = "ORDER BY branch, date"; $sorting = "branch,"; } else { $sortinga = "ORDER BY date"; $sorting = ""; } // Should payments or credit notes be displayed $payment_sql = ""; if ($stmnt_type == "open") { $payment_sql = "\n\t\t\tAND type NOT LIKE 'Payment for%'\n\t\t\tAND type NOT LIKE '%Credit Note%for invoice%'"; } // Retrieve statement information $sql = "\n\t\tSELECT date, invid, type, amount, docref, branch FROM cubit.stmnt\n\t\tWHERE cusnum='{$cusnum}' {$payment_sql} AND\n\t\t\tdate BETWEEN '{$from_date}' AND '{$to_date}'\n\t\tORDER BY date, id ASC"; $stmnt_rslt = db_exec($sql) or errrDie("Unable to retrieve statement."); // Retrieve balance before the 'from date' $sql = "\n\t\tSELECT sum(amount) FROM cubit.stmnt\n\t\tWHERE cusnum='{$cusnum}' AND date < '{$from_date}'"; $balance_rslt = db_exec($sql) or errDie("Unable to retrieve balance."); $balance = pg_fetch_result($balance_rslt, 0); // $oldest_date = mktime(0, 0, 0, date("m"), 1, date("Y")); $oldest_date = mktime(0, 0, 0, $from_month, $from_day - 1, $from_year); if (pg_numrows($stmnt_rslt) < 1) { $info[] = array("Date" => "", "Ref no" => "", "Details" => "No invoices for this month", "Amount" => ""); // Fill the info array } else { while ($stmnt_data = pg_fetch_array($stmnt_rslt)) { // Deduct payments and credit notes from balances only // if this is an open item statement if ($stmnt_type == "open" && ($stmnt_data["type"] == "Invoice" || $stmnt_data["type"] == "Non-Stock Invoice")) { $sql = "\n\t\t\t\t\tSELECT sum(amount) FROM cubit.stmnt\n\t\t\t\t\tWHERE type LIKE 'Payment for % {$stmnt_data['invid']}'\n\t\t\t\t\t\tOR type LIKE '%Credit Note%for invoice%{$stmnt_data['invid']}'"; $payment_rslt = db_exec($sql) or errDie("Unable to retrieve payments."); $payment = pg_fetch_result($payment_rslt, 0); // If the amount has been paid/credit note'ed in full // then no need to display this line if ($stmnt_data["amount"] == $payment * -1) { continue; } $stmnt_data["amount"] += $payment; } // Increase the balance $balance += $stmnt_data["amount"]; // What should we prepend the ref num with, either invoice or credit note if (preg_match("/Invoice/", $stmnt_data["type"])) { $refnum = "INV"; } elseif (preg_match("/Credit Note/", $stmnt_data["type"])) { $refnum = "CR"; } else { $refnum = ""; } $refnum .= " " . $stmnt_data["invid"]; $info[] = array("Date" => makewidth(&$pdf, 60, 12, $stmnt_data['date']), "Ref no" => makewidth(&$pdf, 70, 12, $refnum), "Details" => makewidth(&$pdf, 200, 12, "{$stmnt_data['type']} {$stmnt_data['branch']}"), "Amount" => makewidth(&$pdf, 75, 12, "{$cust_data['currency']}{$stmnt_data['amount']}"), "Balance" => makewidth(&$pdf, 75, 12, "{$cust_data['currency']}" . sprint($balance) . "")); } } if (isset($from_date) && isset($to_date)) { # get overlapping amount // $sql = " // SELECT sum(amount) as amount FROM cubit.stmnt // WHERE cusnum='$cusnum' AND date>'$to_date'"; // $balRslt = db_exec ($sql) or errDie ("Unable to retrieve invoices statement from database."); // $bal = pg_fetch_array ($balRslt); $get_bal = "SELECT sum(amount) FROM stmnt WHERE cusnum = '{$cust_data['cusnum']}'"; $run_bal = db_exec($get_bal) or errDie("Unable to get customer balance."); if (pg_numrows($run_bal) < 1) { $cust_data['balance'] = sprint(0); } else { $cust_data['balance'] = sprint(pg_fetch_result($run_bal, 0, 0)); } $get_bal = "SELECT sum(amount) FROM stmnt WHERE cusnum = '{$cust_data['cusnum']}' AND date>'{$from_date}'"; $run_bal = db_exec($get_bal) or errDie("Unable to get customer balance."); if (pg_numrows($run_bal) < 1) { $bal['amount'] = sprint(0); } else { $bal['amount'] = sprint(pg_fetch_result($run_bal, 0, 0)); } $cust_data['balance'] = $cust_data['balance'] - $bal['amount']; } /* alter the balance brought forward entry's (info[0]) amount */ if ($cust_data['location'] == 'int') { $cust_data['balance'] = $cust_data['fbalance']; } $balbf = $cust_data['balance'] - $totout; $balbf = sprint($balbf); // $balbf = "test"; $info[0]["Date"] = date("d-m-Y", $oldest_date); // - 24*60*60); $info[0]["Amount"] = "{$cust_data['currency']}{$balbf}"; $custinfo = array(array("{$cust_data['surname']}")); // Add the address to the array $custaddr_ar = explode("\n", $cust_data["paddr1"]); foreach ($custaddr_ar as $addr) { $custinfo[] = array(pdf_lstr("{$addr}", 70)); } $custinfo[] = array(""); $custinfo[] = array("<b>Account Number:</b> {$cust_data['accno']}"); //$custinfo[] = array("<b>Balance Brought Forward: </b>$cust_data[currency]$balbf"); // Comments -------------------------------------------------------------- if (isset($comment)) { db_conn("cubit"); $sql = "SELECT comment FROM saved_statement_comments WHERE id='{$comment}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve comments from Cubit."); $default_comment = base64_decode(pg_fetch_result($rslt, 0)); } elseif (isset($b64_comments)) { $default_comment = base64_decode($b64_comments); } else { db_conn("cubit"); $sql = "SELECT value FROM settings WHERE constant='DEFAULT_STMNT_COMMENTS'"; $cmntRslt = db_exec($sql) or errDie("Unable to retrieve comments from Cubit."); $default_comment = base64_decode(pg_fetch_result($cmntRslt, 0)); } $comments = array(); $default_comment = wordwrap($default_comment, 55, "\n"); $default_comment_ar = explode("\n", $default_comment); $i = 1; foreach ($default_comment_ar as $val) { if ($i == 4) { $comments[] = array(pdf_lstr($val, 55)); break; } else { $comments[] = array($val); } $i++; } #handle unset bank information if ($cust_data['bankid'] == "0") { $get_bid = "SELECT * FROM bankacct LIMIT 1"; $run_bid = db_exec($get_bid) or errDie("Unable to get default bank information."); if (pg_numrows($run_bid) < 1) { #no bank accounts in cubit ???? $bank_data = array(); $bank_data['bankname'] = ""; $bank_data['branchname'] = ""; $bank_data['branchcode'] = ""; $bank_data['accnum'] = ""; } else { $cust_data['bankid'] = pg_fetch_result($run_bid, 0, 0); $bank_data = qryBankAcct($cust_data['bankid']); } } else { $bank_data = qryBankAcct($cust_data['bankid']); } $banking = array(array("{$bank_data['bankname']}"), array("<b>Branch: </b>{$bank_data['branchname']}"), array("<b>Branch Code: </b>{$bank_data['branchcode']}"), array("<b>Account Number: </b>{$bank_data['accnum']}")); $get_bal = "SELECT sum(amount) FROM stmnt WHERE cusnum = '{$cust_data['cusnum']}'"; $run_bal = db_exec($get_bal) or errDie("Unable to get customer balance."); if (pg_numrows($run_bal) < 1) { $cust_data['balance'] = sprint(0); } else { $cust_data['balance'] = sprint(pg_fetch_result($run_bal, 0, 0)); } // Totals ---------------------------------------------------------------- $totals = array(array(""), array("<b>Total Outstanding Balance</b> : {$cust_data['currency']} " . sprint($cust_data["balance"]))); // Age analysis ---------------------------------------------------------- if ($cust_data['location'] == 'int') { $cust_data['balance'] = $cust_data['fbalance']; } $balbf = $cust_data['balance'] - $totout; $balbf = sprint($balbf); $cust_data['balance'] = sprint($cust_data['balance']); // $from_date = date ("Y-m-d",mktime (0,0,0,date("m"),"01",date("Y"))); $from_date = "{$from_year}-{$from_month}-{$from_day}"; # Check type of age analisys if (div_isset("DEBT_AGE", "mon")) { $curr = ageage($cust_data['cusnum'], 0, $cust_data['fcid'], $cust_data['location']); $age30 = ageage($cust_data['cusnum'], 1, $cust_data['fcid'], $cust_data['location']); $age60 = ageage($cust_data['cusnum'], 2, $cust_data['fcid'], $cust_data['location']); $age90 = ageage($cust_data['cusnum'], 3, $cust_data['fcid'], $cust_data['location']); $age120 = ageage($cust_data['cusnum'], 4, $cust_data['fcid'], $cust_data['location']); } else { $curr = cust_age($cust_data['cusnum'], 29, $cust_data['fcid'], $cust_data['location'], $to_month, $to_date, $from_date); $age30 = cust_age($cust_data['cusnum'], 59, $cust_data['fcid'], $cust_data['location'], $to_month, $to_date, $from_date); $age60 = cust_age($cust_data['cusnum'], 89, $cust_data['fcid'], $cust_data['location'], $to_month, $to_date, $from_date); $age90 = cust_age($cust_data['cusnum'], 119, $cust_data['fcid'], $cust_data['location'], $to_month, $to_date, $from_date); $age120 = cust_age($cust_data['cusnum'], 149, $cust_data['fcid'], $cust_data['location'], $to_month, $to_date, $from_date); } $custtot = $curr + $age30 + $age60 + $age90 + $age120; // if(sprint($custtot) != sprint($cust_data['balance'])) { // $curr = sprint($curr + $cust_data['balance'] - $custtot); // $custtot = sprint($cust_data['balance']); // } $age = array(array("Current" => "<b>Current</b>", "30 Days" => "<b>30 Days:</b>", "60 Days" => "<b>60 Days</b>", "90 Days" => "<b>90 Days</b>", "120 Days" => "<b>120 Days</b>"), array("Current" => $curr, "30 Days" => $age30, "60 Days" => $age60, "90 Days" => $age90, "120 Days" => $age120)); // Table layout ---------------------------------------------------------- $ic = 0; while (++$ic * 25 < count($info)) { } // Draw the pages, determine by the amount of items how many pages // if items > 25 start a new page $info_print = array(); for ($i = 0; $i < $ic; $i++) { if ($i) { $pdf->ezNewPage(); } if (isset($from_date) && isset($to_date)) { $date = "{$from_date} to {$to_date}"; $dalign_x = 130; } else { $date = date("d-m-Y"); $dalign_x = 105; } // Heading $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5); drawText(&$pdf, "<b>Page " . ($i + 1) . "</b>", 8, $heading_pos['x'] / 2 - 8, 10); drawText(&$pdf, "<b>{$compinf['compname']}</b>", 18, 8, $heading_pos['y'] / 2 + 6); drawText(&$pdf, "<b>Statement</b>", 18, $heading_pos['x'] - 120, $heading_pos['y'] / 2); drawText(&$pdf, $date, 10, $heading_pos['x'] - $dalign_x, $heading_pos['y'] / 2 + 18); $custinfo_pos = drawTable(&$pdf, $custinfo, 0, $heading_pos['y'] + 5, 300, 10); $compinfo_pos = drawTable(&$pdf, $compinfo, $custinfo_pos['x'], $heading_pos['y'] + 5, 220, 10); $info_start = $i * 25; if ($i) { $info_start++; } if ($info_start >= count($info) - 25) { $info_end = count($info) - 1; } else { $info_end = ($i + 1) * 25; } $info_print = array(); for ($j = $info_start; $j <= $info_end; $j++) { $info_print[$j] = $info[$j]; } // Adjust the column widths $cols = array("Date" => array("width" => 60), "Proforma Inv no" => array("width" => 70), "Ref no" => array("width" => 80), "Amount" => array("width" => 75, "justification" => "right"), "Balance" => array("width" => 75, "justification" => "right")); $info_pos = drawTable(&$pdf, $info_print, 0, $custinfo_pos['y'] + 5, 520, 25, $cols, 1); $comments_pos = drawTable(&$pdf, $comments, 0, $info_pos['y'] + 5, 260, 4); $banking_pos = drawTable(&$pdf, $banking, $comments_pos['x'], $info_pos['y'] + 5, 260, 4); $totals_pos = drawTable(&$pdf, $totals, 0, $comments_pos['y'] + 5, 520, 3); $age_pos = drawTable(&$pdf, $age, 0, $totals_pos['y'], 520, 2); drawText(&$pdf, "<b>Cubit Accounting</b>", 6, 0, $age_pos['y'] + 20); } $pdf->ezNewPage(); } $pdf->ezStream(); }
<td class="myform" align="right">E-Mail </td> <td width="30"></td> <td class="myform" colspan="6"><font color="#000000"><?php echo $mail; ?> </font></td> </tr> <tr><td height="80"></td></tr> <tr> <td class="myform" style="font-size:25px;" align="center" colspan="8">Store</td> </tr> <tr><td height="50"></td></tr> <tr><td width="100%" colspan="8"> <table border="3" cellpadding="0" cellspacing="0" width="100%" align="center" style="border-collapse:collapse;" rules="rows" frame="hsides"> <tr bgcolor="#96638e"> <td class="myform" align="center" height="30" width="200" style="font-size:15px; color:#ffffff;">Image</td> <td class="myform" align="center" width="250" style="font-size:15px; color:#ffffff;">Name</td> <td class="myform" align="center" width="130" style="font-size:15px; color:#ffffff;">Category</td> <td class="myform" colspan="2" align="center" width="450" style="font-size:15px; color:#ffffff;">Address</td> </tr> <?php drawTable($stores); ?> </table> </td></tr> </table> </td></tr> </table> </body> </html>
function gennonspdf($invid) { global $set_mainFont; $showvat = TRUE; $pdf =& new Cezpdf(); $pdf->selectFont($set_mainFont); // Validate require_lib("validate"); $v = new Validate(); $v->isOk($invid, "num", 1, 20, "Invalid invoice number."); // Any errors? if ($v->isError()) { $err = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class='err'>{$e['msg']}</li>"; } $OUTPUT = $confirm; require "../template.php"; } // Invoice info db_conn("cubit"); $sql = "SELECT * FROM nons_invoices WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice info."); //die ($sql); if (pg_num_rows($invRslt) == 0) { return "<li class='err'>Not found</li>"; } $inv = pg_fetch_array($invRslt); db_conn("cubit"); $sql = "SELECT symbol FROM currency WHERE fcid='{$inv['fcid']}'"; $curRslt = db_exec($sql) or errDie("Unable to retrieve currency from Cubit."); $curr = pg_fetch_result($curRslt, 0); if (!$curr) { $curr = CUR; } // Only needs to be blank, we're manually adding text $heading = array(array("")); // Company info ---------------------------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'"; $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit."); $comp = pg_fetch_array($ciRslt); // $bnkData = qryBankAcct(getdSetting("BANK_DET")); $bnkData = qryBankAcct($inv['bankid']); $compinfo = array(); $compinfo[] = array(pdf_lstr($comp["addr1"], 35), pdf_lstr($comp["paddr1"], 35)); $compinfo[] = array(pdf_lstr($comp["addr2"], 35), pdf_lstr($comp["paddr2"], 35)); $compinfo[] = array(pdf_lstr($comp["addr3"], 35), pdf_lstr($comp["paddr3"], 35)); $compinfo[] = array(pdf_lstr($comp["addr4"], 35), "{$comp['postcode']}"); $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>"); $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}"); $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}"); $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}"); // Date ------------------------------------------------------------------ $date = array(array("<b>Date</b>"), array($inv['odate'])); // Document info --------------------------------------------------------- db_conn('cubit'); $Sl = "SELECT * FROM settings WHERE constant='SALES'"; $Ri = db_exec($Sl) or errDie("Unable to get settings."); $data = pg_fetch_array($Ri); if ($data['value'] == "Yes") { $sp = "<b>Sales Person: </b>{$inv['salespn']}"; } else { $sp = ""; } // Customer info --------------------------------------------------------- if ($inv["cusid"] != 0) { db_conn("cubit"); $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusid']}'"; $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit."); $cusData = pg_fetch_array($cusRslt); } else { $cusData["surname"] = $inv["cusname"]; $cusData["addr1"] = $inv["cusaddr"]; $cusData["paddr1"] = $inv["cusaddr"]; $cusData["del_addr1"] = ""; $cusData["accno"] = ""; } $docinfo = array(array("<b>Invoice No:</b> {$inv['invnum']}"), array("<b>Proforma Inv No:</b> {$inv['docref']}"), array("<b>Account no: </b>{$cusData['accno']}"), array("{$sp}")); $invoice_to = array(array("")); $cusinfo = array(array("<b>{$cusData['surname']}</b>")); $cusaddr = explode("\n", $cusData['addr1']); foreach ($cusaddr as $v) { $cusinfo[] = array(pdf_lstr($v, 40)); } // $cusinfo[] = array("<b>Account no: </b>$cusData[accno]"); $cuspaddr = array(array("<b>Postal Address</b>")); $paddr = explode("\n", $cusData["paddr1"]); foreach ($paddr as $addr) { $cuspaddr[] = array("{$addr}"); } $cusdaddr = array(array("<b>Delivery Address:</b>")); $cusaddr = explode("\n", $cusData['del_addr1']); foreach ($cusaddr as $v) { $cusdaddr[] = array(pdf_lstr($v, 40)); } // Registration numbers -------------------------------------------------- $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}")); // Items display --------------------------------------------------------- $items = array(); db_conn("cubit"); $sql = "SELECT * FROM nons_inv_items WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'"; $stkdRslt = db_exec($sql); while ($stkd = pg_fetch_array($stkdRslt)) { // Check Tax Excempt db_conn("cubit"); $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatex']}'"; $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); $vatex = pg_fetch_result($zRslt, 0); if ($vatex == "Yes") { $ex = "#"; } else { $ex = ""; } $sql = "SELECT * FROM vatcodes WHERE id='{$stkd['vatex']}'"; $runsql = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); if (pg_numrows($runsql) < 1) { return "Invalid VAT code entered"; } $vd = pg_fetch_array($runsql); if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") { $showvat = FALSE; } $items[] = array("Description" => makewidth($pdf, 305, 12, $ex . strip_tags($stkd["description"])), "Qty" => $stkd['qty'], "Unit Price" => $curr . $stkd['unitcost'], "Amount" => $curr . $stkd['amt']); } // Comment --------------------------------------------------------------- $comment = array(array("<i>VAT Exempt Indicator: #</i>"), array($inv["remarks"])); // Box to sign in -------------------------------------------------------- $sign = array(array("<b>Terms:</b> {$inv['terms']}"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array(" <b>Date:</b> ____________________")); // Totals ---------------------------------------------------------------- if (!isset($showvat)) { $showvat = TRUE; } if ($showvat == TRUE) { $vat14 = AT14; } else { $vat14 = ""; } $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => $curr . "{$inv['subtot']}"), array("1" => "<b>VAT {$vat14}:</b> ", "2" => $curr . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => $curr . "{$inv['total']}")); $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right")); $ic = 0; while (++$ic * 20 < count($items)) { } // Draw the pages, determine by the amount of items how many pages // if items > 20 start a new page $items_print = array(); for ($i = 0; $i < $ic; $i++) { if ($i) { $pdf->ezNewPage(); } // Page number ------------------------------------------------------- $pagenr = array(array("<b>Page number</b>"), array($i + 1)); // Heading $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5); drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 18, $heading_pos['y'] / 2 + 6); drawText(&$pdf, "<b>Tax Invoice</b>", 18, $heading_pos['x'] - 120, $heading_pos['y'] / 2 + 9); // Should we display reprint on the invoice if (isset($type) and $type == "nonsreprint") { drawText(&$pdf, "<b>Reprint</b>", 12, $heading_pos['x'] - 70, $heading_pos['y'] / 2 + 22); } $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8); $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 4); $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 4); $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 4); $invoice_to_pos = drawTable(&$pdf, $invoice_to, 0, $compinfo_pos['y'], 520, 2); drawText(&$pdf, "<b>Tax Invoice to:</b>", 12, 520 / 2 - 45, $invoice_to_pos['y'] - 7); $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $invoice_to_pos['y'], 173, 8); $cuspaddr_pos = drawTable(&$pdf, $cuspaddr, $cusinfo_pos['x'], $invoice_to_pos['y'], 173, 8); $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cuspaddr_pos['x'], $invoice_to_pos['y'], 174, 8); $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2); $items_start = $i * 20; if ($i) { $items_start++; } if ($items_start >= count($items) - 20) { $items_end = count($items) - 1; } else { $items_end = ($i + 1) * 20; } $items_print = array(); for ($j = $items_start; $j <= $items_end; $j++) { $items_print[$j] = $items[$j]; } // Adjust the column widths $cols = array("Description" => array("width" => 310), "Qty" => array("width" => 50), "Unit Price" => array("width" => 80, "justification" => "right"), "Amount" => array("width" => 80, "justification" => "right")); $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 22, $cols, 1); $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2); $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5); $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols); } return $pdf->output(); }
function list_results($type, $value, $sortby, $sortdir) { global $scanstate, $isReportAdmin, $allres, $offset, $pageSize, $username, $uroles, $dbconn, $hosts; global $user, $arruser; $filteredView = FALSE; $selRadio = array("", "", "", ""); $query_onlyuser = ""; $url_filter = ""; //if (!$isReportAdmin || (!$allres)) { $query_onlyuser="******"; } if (!in_array("admin", $arruser)) { $query_onlyuser = "******"; } if ($sortby == "") { $sortby = "scantime"; } if ($sortdir == "") { $sortdir = "DESC"; } $queryw = ""; $queryl = ""; //$querys="SELECT distinct t1.report_id, t1.name as jobname, t4.meth_target, t1.scantime, // t1.username, t1.scantype, t1.report_key, t1.report_type as report_type, t3.name as profile, t4.id as jobid, t4.meth_SCHED, // t5.vSerious, t5.vHigh, t5.vMed, t5.vLow, t5.vInfo // FROM vuln_nessus_reports t1 // LEFT JOIN vuln_nessus_settings t3 ON t1.sid=t3.id // LEFT JOIN vuln_jobs t4 on t1.report_id = t4.report_id // LEFT JOIN vuln_nessus_report_stats t5 on t1.report_id = t5.report_id // WHERE t1.deleted = '0' "; /* $querys="SELECT distinct t1.report_id, t4.name as jobname, t4.scan_submit, t4.meth_target, t1.scantime, t1.username, t1.scantype, t1.report_key, t1.report_type as report_type, t3.name as profile, t4.id as jobid, t4.meth_SCHED, t5.vSerious, t5.vHigh, t5.vMed, t5.vLow, t5.vInfo FROM vuln_nessus_reports t1 LEFT JOIN vuln_nessus_settings t3 ON t1.sid=t3.id LEFT JOIN vuln_jobs t4 on t1.report_id = t4.report_id LEFT JOIN vuln_nessus_report_stats t5 on t1.report_id = t5.report_id WHERE t1.deleted = '0' ";*/ $leftjoin = ""; if ($type == "net" && trim($value) != "") { $leftjoin = "LEFT JOIN vuln_nessus_results t5 ON t5.report_id=t1.report_id"; } $querys = "SELECT distinct t1.sid as sid, t1.report_id, t4.name as jobname, t4.scan_submit, t4.meth_target, t1.scantime,\n t1.username, t1.scantype, t1.report_key, t1.report_type as report_type, t3.name as profile, t4.id as jobid, t4.meth_SCHED, t1.name as report_name\n FROM vuln_nessus_reports t1\n LEFT JOIN vuln_nessus_settings t3 ON t1.sid=t3.id\n LEFT JOIN vuln_jobs t4 on t1.report_id = t4.report_id {$leftjoin}\n WHERE t1.deleted = '0' AND t1.scantime IS NOT NULL "; // set up the SQL query based on the search form input (if any) switch ($type) { case "scantime": $selRadio[0] = "CHECKED"; $q = $value; $queryw = " AND t1.scantime LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = "<b>" . _("Search for Date/Time") . "</b> = '*{$q}*'"; $url_filter = "&type={$type}&value={$value}"; break; case "jobname": $selRadio[1] = "CHECKED"; $q = strtolower($value); $queryw = " AND t1.name LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = "<b>" . _("Search for Job Name") . "</b> = '*" . html_entity_decode($q) . "*'"; $url_filter = "&type={$type}&value={$value}"; break; case "fk_name": $selRadio[2] = "CHECKED"; $q = strtolower($value); $queryw = " AND t1.fk_name LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = _("Search for Subnet/CIDR") . " = '*{$q}*'"; $url_filter = "&type={$type}&value={$value}"; break; case "username": $selRadio[3] = "CHECKED"; $q = strtolower($value); $queryw = " AND t1.username LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = "<b>" . _("Search for user") . "</b> = '*{$q}*'"; $url_filter = "&type={$type}&value={$value}"; break; case "net": $selRadio[4] = "CHECKED"; if (!preg_match("/\\//", $value)) { $q = $value; } else { $tokens = explode("/", $value); $bytes = explode(".", $tokens[0]); if ($tokens[1] == "24") { $q = $bytes[0] . "." . $bytes[1] . "." . $bytes[2] . "."; } else { if ($tokens[1] == "16") { $q = $bytes[0] . "." . $bytes[1] . "."; } else { if ($tokens[1] == "8") { $q = $bytes[0] . "."; } else { if ((int) $tokens[1] > 24) { $q = $bytes[0] . "." . $bytes[1] . "." . $bytes[2] . "." . $bytes[3]; } } } } } $queryw = " AND (t4.meth_TARGET LIKE '%{$q}%' OR t5.hostIP LIKE '%{$q}%') {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; if (!preg_match("/\\//", $value)) { $stext = "<b>" . _("Search for Host") . "</b> = '*" . html_entity_decode($q) . "*'"; } else { $stext = "<b>" . _("Search for Subnet/CIDR") . "</b> = '*{$q}*'"; } $url_filter = "&type={$type}&value={$value}"; break; default: $selRadio[1] = "CHECKED"; $viewAll = FALSE; $queryw = "{$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = ""; break; } // put link to add new host // if ($isReportAdmin) { // $url_allres="&allres="; // if ($allres=="" || !is_numeric($allres) || (!$allres)) { // $allres=0; // echo "<a href='results.php?offset=0".$url_allres."1'>Show all results</a><br>"; // } else { // $allres=1; // echo "<a href='results.php?offset=0".$url_allres."0'>Display only my Results</a><br>"; // } // $url_allres .="$allres"; // } // echo the search criteria used // set up the pager and search fields if viewing all hosts $reportCount = 0; if (!$filteredView) { $queryc = "SELECT count(t1.report_id) FROM vuln_nessus_reports t1 LEFT JOIN vuln_jobs t2 on t1.report_id = t2.report_id WHERE t1.deleted = '0' AND t2.scan_submit IS NOT NULL "; $reportCount = $dbconn->GetOne($queryc . $queryw); $previous = $offset - $pageSize; if ($previous < 0) { $previous = 0; } $last = $reportCount - $pageSize; if ($last < 0) { $last = 0; } $next = $offset + $pageSize; if ($next > $last) { $next = $last; } $pageEnd = $offset + $pageSize; $value = html_entity_decode($value); echo "<center><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tr><td class=\"headerpr\" style=\"border:0;\">" . _("Reports") . "</td></tr></table></center>"; //echo "<p>There are $reportCount scans defined in the system."; // output the search form echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">"; echo "<tr><td style=\"padding-top:5px;\" class=\"nobborder\">"; echo <<<EOT <!--<form name="hostSearch" onSubmit="return OnSubmitForm();">--> <center> <form name="hostSearch" action="reports.php" method="GET"> <input type="text" length="25" name="value" value="{$value}"> EOT; echo "\n<input type=\"radio\" name=\"type\" value=\"scantime\" {$selRadio['0']}>" . _("Date") . "/" . _("Time") . "\n<input type=\"radio\" name=\"type\" value=\"jobname\" {$selRadio['1']}>" . _("Job Name") . "\n<!--<input type=\"radio\" name=\"type\" value=\"fk_name\" {$selRadio['2']}>Subnet Name-->\n<input type=\"radio\" name=\"type\" value=\"net\" {$selRadio['4']}>" . _("Host") . "/" . _("Net") . "\n<!--<input type=\"radio\" name=\"type\" value=\"username\" {$selRadio['3']}>Username-->\n"; echo <<<EOT <input type="hidden" name="sortby" value="{$sortby}"> <input type="hidden" name="allres" value="{$allres}"> <input type="hidden" name="op" value="search"> EOT; echo '<input type="hidden" name="withoutmenu" value="' . GET('withoutmenu') . '">'; echo "<input type=\"submit\" name=\"submit\" value=\"" . _("Find") . "\" class=\"button\">"; echo <<<EOT </form> </center> </p> EOT; // output the pager //echo "<p align=center><a href='reports.php?offset=0".$url_allres.$url_filter."' class='pager'><< "._("First")."</a> | "; //if($offset != 0) { // echo "<a href='reports.php?offset=$previous".$url_allres.$url_filter."' class='pager'>< "._("Previous")." </a> | "; //} //if($pageEnd >= $reportCount) { $pageEnd = $reportCount; } //echo "[ ".($offset+1)." - $pageEnd of $reportCount ] | "; //if($next < $last) { // echo "<a href='reports.php?offset=$next".$url_allres.$url_filter."' class='pager'>| "._("Next")." ></a> | "; //} //echo "<a href='reports.php?offset=$last".$url_allres.$url_filter."' class='pager'> "._("Last")." >></a></p>"; } else { // get the search result count $queryc = "SELECT count( report_id ) FROM vuln_nessus_reports WHERE t1.deleted = '0' "; $scount = $dbconn->GetOne($queryc . $queryw); echo "<p>{$scount} report"; if ($scount != 1) { echo "s"; } else { } echo " " . _("found matching search criteria") . " | "; echo " <a href='reports.php' alt='" . _("View All Reports") . "'>" . _("View All Reports") . "</a></p>"; } echo "<p>"; echo $stext; echo "</p>"; echo "</td></tr></table>"; // get the hosts to display //print_r($querys.$queryw.$queryl); $result = $dbconn->GetArray($querys . $queryw . $queryl); //echo "[$querys$queryw$queryl]"; if ($result === false) { $errMsg[] = _("Error getting results") . ": " . $dbconn->ErrorMsg(); $error++; dispSQLError($errMsg, $error); } else { $tdata = array(); foreach ($result as $data) { $data['vSerious'] = 0; $data['vHigh'] = 0; $data['vMed'] = 0; $data['vLow'] = 0; $data['vInfo'] = 0; // query for reports for each IP $query_risk = "SELECT distinct risk, port, protocol, app, scriptid, msg, hostIP FROM vuln_nessus_results WHERE report_id = " . $data['report_id']; $query_risk .= " AND falsepositive='N'"; $result_risk = $dbconn->Execute($query_risk); while (!$result_risk->EOF) { if ($result_risk->fields["risk"] == 7) { $data['vInfo']++; } else { if ($result_risk->fields["risk"] == 6) { $data['vLow']++; } else { if ($result_risk->fields["risk"] == 3) { $data['vMed']++; } else { if ($result_risk->fields["risk"] == 2) { $data['vHigh']++; } else { if ($result_risk->fields["risk"] == 1) { $data['vSerious']++; } } } } } $result_risk->MoveNext(); } $more = "&hmenu=Vulnerabilities&smenu=Vulnerabilities"; $data['clink'] = "respdfc.php?scantime=" . $data['scantime'] . "&scantype=" . $data['scantype'] . "&key=" . $data['report_key'] . $more; $data['plink'] = "respdf.php?scantime=" . $data['scantime'] . "&scantype=" . $data['scantype'] . "&key=" . $data['report_key'] . $more; $data['hlink'] = "reshtml.php?hmenu=Vulnerabilities&smenu=Reports&disp=html&output=full&scantime=" . $data['scantime'] . "&scantype=" . $data['scantype']; $data['rerun'] = "sched.php?disp=rerun&job_id=" . $data['jobid'] . $more; $data['xlink'] = "rescsv.php?scantime=" . $data['scantime'] . "&scantype=" . $data['scantype'] . "&key=" . $data['report_key'] . $more; $data['xbase'] = "restextsummary.php?scantime=" . $data['scantime'] . "&scantype=" . $data['scantype'] . $more . "&key=" . $data['report_key']; /* $data['vSerious'] = "<a href=\"respdf.php?scantime=".$data['scantime']."&scantype=".$data['scantype'] ."&key=".$data['report_key']."&critical=1\">".$data['vSerious']."</a>"; $data['vHigh'] = "<a href=\"respdf.php?scantime=".$data['scantime']."&scantype=".$data['scantype'] ."&key=".$data['report_key']."&critical=2\">".$data['vHigh']."</a>"; $data['vMed'] = "<a href=\"respdf.php?scantime=".$data['scantime']."&scantype=".$data['scantype'] ."&key=".$data['report_key']."&critical=3\">".$data['vMed']."</a>"; $data['vLow'] = "<a href=\"respdf.php?scantime=".$data['scantime']."&scantype=".$data['scantype'] ."&key=".$data['report_key']."&critical=6\">".$data['vLow']."</a>"; $data['vInfo'] = "<a href=\"respdf.php?scantime=".$data['scantime']."&scantype=".$data['scantype'] ."&key=".$data['report_key']."&critical=7\">".$data['vInfo']."</a>";*/ //$data['vSerious'] = $data['vSerious']; //$data['vHigh'] = $data['vHigh']; //$data['vMed'] = $data['vMed']; //$data['vLow'] = $data['vLow']; //$data['vInfo'] = $data['vInfo']; //$data['scan_submit'] = $data['scan_submit']; $list = array(); if ($data["report_type"] == "I") { $result = $dbconn->execute("SELECT DISTINCT hostIP FROM vuln_nessus_results WHERE report_id =" . $data['report_id']); while (!$result->EOF) { $list[] = $result->fields["hostIP"]; $result->MoveNext(); } } else { $list = explode("\n", trim($data['meth_target'])); } //var_dump($list); if (count($list) == 1) { $list[0] = trim($list[0]); if ($list[0] != "") { if ($hosts[$list[0]] != "" && $hosts[$list[0]] != $list[0]) { $data['target'] = $hosts[$list[0]] . " (" . $list[0] . ")"; } else { $data['target'] = $list[0]; } } else { $data['target'] = "-"; } } elseif (count($list) == 2) { $list[0] = trim($list[0]); if ($hosts[$list[0]] != "" && $hosts[$list[0]] != $list[0]) { $list[0] = $hosts[$list[0]] . " (" . $list[0] . ")"; } $list[1] = trim($list[1]); if ($hosts[$list[1]] != "" && $hosts[$list[1]] != $list[1]) { $list[1] = $hosts[$list[1]] . " (" . $list[1] . ")"; } $data['target'] = $list[0] . ' ' . $list[1]; } else { $list[0] = trim($list[0]); if ($hosts[$list[0]] != "" && $hosts[$list[0]] != $list[0]) { $list[0] = $hosts[$list[0]] . " (" . $list[0] . ")"; } $list[count($list) - 1] = trim($list[count($list) - 1]); if ($hosts[$list[count($list) - 1]] != "" && $hosts[$list[count($list) - 1]] != $list[count($list) - 1]) { $list[count($list) - 1] = $hosts[$list[count($list) - 1]] . " (" . $list[count($list) - 1] . ")"; } $data['target'] = $list[0] . " ... " . $list[count($list) - 1]; } if ($data["report_type"] == "I") { $data["jobname"] = $data["report_name"]; } $tdata[] = $data; } if ($sortdir == "ASC") { $sortdir = "DESC"; } else { $sortdir = "ASC"; } $url = $_SERVER['SCRIPT_NAME'] . "?offset={$offset}&sortby=%var%&sortdir={$sortdir}" . $url_allres . $url_filter; $fieldMapLinks = array(); $fieldMapLinks = array(gettext("HTML Results") => array('url' => '%param%', 'param' => 'hlink', 'target' => 'main', 'icon' => 'images/html.png'), gettext("PDF Results") => array('url' => '%param%', 'param' => 'plink', 'target' => '_blank', 'icon' => 'images/pdf.png'), gettext("EXCEL Results") => array('url' => '%param%', 'param' => 'xlink', 'target' => '_blank', 'icon' => 'images/page_white_excel.png')); $fieldMap = array("Date/Time" => array('var' => 'scantime', 'link' => $url), "Job Name" => array('var' => 'jobname', 'link' => $url), "Targets" => array('var' => 'target', 'link' => $url), "Profile" => array('var' => 'profile', 'link' => $url), "Serious" => array('var' => 'vSerious', 'link' => $url), "High" => array('var' => 'vHigh', 'link' => $url), "Medium" => array('var' => 'vMed', 'link' => $url), "Low" => array('var' => 'vLow', 'link' => $url), "Info" => array('var' => 'vInfo', 'link' => $url), "Links" => $fieldMapLinks); drawTable($fieldMap, $tdata, "Hosts"); } // draw the pager again, if viewing all hosts if (!$filteredView && $last != 0) { echo "<p align=center>\n<a href=\"reports.php?offset=0" . $url_allres . $url_filter . "\" class=\"pager\"><< " . _("First") . "</a>\n<a href=\"reports.php?offset={$previous}" . $url_allres . $url_filter . "\" class=\"pager\">< " . _("Previous") . " </a>"; echo " [ " . ($offset + 1) . " - {$pageEnd} " . _("of") . " {$reportCount} ] "; echo "<a href=\"reports.php?offset={$next}" . $url_allres . $url_filter . "\" class=\"pager\"> " . _("Next") . " ></a>\n<a href=\"reports.php?offset={$last}" . $url_allres . $url_filter . "\" class=\"pager\"> " . _("Last") . " >></a>\n</p>"; } else { echo "<br>"; } }
function drawPage() { global $credentials; $body = ""; $login = new Credentials("terrapintango.cgpkve9uh8yp.us-east-1.rds.amazonaws.com", $credentials[0], $credentials[1], "tangodb"); $connector = new SQLConnector($login); $connector->connect(); //print_r($result); if (isset($_POST['submit'])) { $fields = $_POST['field']; $fieldsString = implode(", ", $fields); foreach ($fields as $table) { if ($table == "ConfirmedRegistrants") { $query = "SELECT r.fname, r.lname, r.partnerfname, r.email, c.classes, c.passtype, c.price\n FROM records r, classes c, confirmation f\n WHERE r.registerid = c.registerid and r.registerid = f.registerid and\n f.payment_status = 'Completed'"; } else { $query = "select * from {$table}"; } $result = $connector->retrieve($query); $body .= "<h1>" . ucfirst($table) . "</h1>" . drawTable($result); } } else { if (isset($_POST['arbsubmitr'])) { $query = $_POST['arbtext']; $result = $connector->retrieve($query); $body .= "<h1>{$query}</h1>" . drawTable($result); } else { if (isset($_POST['arbsubmiti'])) { $query = $_POST['arbtext']; $error = false; try { $result = $connector->insert($query); } catch (Exception $e) { echo $e->getMessage(); $error = true; } if (!$error) { $body .= "Query successful."; } $body .= "<p><form action='admin.php' method=POST><input type='submit' value='Back'></form></p>"; } else { if (isset($_POST['classprint'])) { header("Location: classBalanceInfo.php"); } else { if (isset($_POST['mapping'])) { echo print_class_info(); } else { if (isset($_POST['edit'])) { header("Location: editdb.php"); } else { $body = <<<BODY <h1> Database Access </h1> <form action="admin.php" method="post"> <p> <strong>Select tables to display</strong><br /> <select name="field[]" multiple="multiple"> <option value="records">Records</option> <option value="classes">Classes</option> <option value="confirmation">Confirmation</option> <option value="ConfirmedRegistrants">Confirmed registrations</option> </select> </p> <p> <input type="submit" name="submit" value="Display Tables"> </p> <p> <input type='text' name='arbtext'> </p> <p> <input type='submit' name='arbsubmitr' value='Submit arbitrary query (Get response)'> <input type='submit' name='arbsubmiti' value='Submit arbitrary query (Do not get response)'> </p> \t\t\t\t\t<p> \t\t\t\t\t\t<input type='submit' name='classprint' value='Class Balance Info'> \t\t\t\t\t</p> <p> \t\t\t\t\t\t<input type='submit' name='mapping' value='Confirmed Schedules'> \t\t\t\t\t</p> <p> \t\t\t\t\t\t<input type='submit' name='edit' value='Edit Classes'> \t\t\t\t\t</p> </form> BODY; } } } } } } echo generatePage($body, "Admin Panel"); }
<div class="row"> <p><a class="btn btn-primary" href="create.php">Create</a></p> <?php if (isset($error)) { echo $error; } else { //echo '<p>Connection successful</p>'; $sql = 'SELECT id, firstname, lastname, phone FROM contacts'; if ($result = $db->query($sql)) { $nrows = $result->num_rows; if (!$nrows) { echo '<p>No contacts found</p>'; } else { echo '<p>Found ' . $nrows . ' contacts</p>'; while ($row = $result->fetch_assoc()) { $contacts[] = $row; } //print_r($contacts); echo drawTable($contacts); } $result->close(); } else { echo 'Wrong query'; } $db->close(); } ?> </div><!-- /row --> </div><!-- /container --> </body> </html>
function posInvoices($pdf) { extract($_GET); global $set_mainFont; $showvat = TRUE; $pdf->selectFont($set_mainFont); // Validate require_lib("validate"); $v = new Validate(); $v->isOk($cusnum, "num", 1, 20, "Invalid customer number."); // Any errors? if ($v->isError()) { $err = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class=error>{$e['msg']}</li>"; } $OUTPUT = $err; require "../template.php"; } // Invoice info db_conn(PRD_DB); $sql = "SELECT * FROM pinvoices WHERE cusnum='{$cusnum}' AND done='y' AND balance>0 AND DIV='" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice info."); if (pg_num_rows($invRslt) < 1) { return $pdf; } $num_rows = pg_num_rows($invRslt); $curr_row = 1; while ($inv = pg_fetch_array($invRslt)) { $curr_row++; // Check if stock was selected db_conn(PRD_DB); $sql = "SELECT stkid FROM pinv_items WHERE invid='{$inv['invid']}' AND DIV='" . USER_DIV . "'"; $cRslt = db_exec($sql) or errDie("Unable to retrieve invoice info."); if (pg_num_rows($cRslt) < 1) { $error = "<li class=err>Invoice number <b>{$inv['invid']}</b> has no items</li>"; $OUTPUT = $error; } // Only needs to be blank, we're manually adding text $heading = array(array("")); // Company info ---------------------------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'"; $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit."); $comp = pg_fetch_array($ciRslt); // Banking information --------------------------------------------------- $sql = "SELECT value FROM set WHERE label='BANK_DET' AND div='" . USER_DIV . "'"; $srslt = db_exec($sql) or errDie("Unable to retrieve banking information from Cubit."); $bankid = pg_fetch_result($srslt, 0); // Select the default bank account if no accounts were found. if (pg_num_rows($srslt) == 0) { $bankid = 2; } db_conn("cubit"); $sql = "SELECT * FROM bankacct WHERE bankid='{$bankid}' AND div='" . USER_DIV . "'"; $bnkRslt = db_exec($sql) or errDie("Unable to retrieve the banking information from Cubit."); $bnkData = pg_fetch_array($bnkRslt); $compinfo = array(); $compinfo[] = array($comp["addr1"], $comp["paddr1"]); $compinfo[] = array(pdf_lstr($comp["addr2"], 35), pdf_lstr($comp["paddr2"], 35)); $compinfo[] = array(pdf_lstr($comp["addr3"], 35), pdf_lstr($comp["paddr3"], 35)); $compinfo[] = array(pdf_lstr($comp["addr4"], 35), "{$comp['postcode']}"); $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>"); $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}"); $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}"); $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}"); // Date ------------------------------------------------------------------ $date = array(array("<b>Date</b>"), array($inv['odate'])); // Document info --------------------------------------------------------- db_conn('cubit'); $Sl = "SELECT * FROM settings WHERE constant='SALES'"; $Ri = db_exec($Sl) or errDie("Unable to get settings."); $data = pg_fetch_array($Ri); $docinfo = array(array("<b>Invoice No:</b> {$inv['invnum']}"), array("<b>Sales Order No:</b> {$inv['ordno']}")); if (isset($salespn)) { $docinfo[] = array("<b>Sales Person:</b> {$salespn}"); } // Retrieve the customer information ------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusnum']}'"; $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit."); $cusData = pg_fetch_array($cusRslt); // Customer info --------------------------------------------------------- $invoice_to = array(array("")); $cusinfo = array(array("<b>{$inv['surname']}</b>")); $cusaddr = explode("\n", $cusData['addr1']); foreach ($cusaddr as $v) { $cusinfo[] = array(pdf_lstr($v, 40)); } $cusinfo[] = array("<b>Account no: </b>{$cusData['accno']}"); $cuspaddr = array(array("<b>Postal Address</b>")); $paddr = explode("\n", $cusData["paddr1"]); foreach ($paddr as $addr) { $cuspaddr[] = array($addr); } $cusdaddr = array(array("<b>Delivery Address:</b>")); $branchname = "Head Office"; $cusaddr = explode("\n", $cusData['addr1']); $cusdaddr[] = array(pdf_lstr("Branch : {$branchname}", 30)); $del_addr = explode("\n", $cusData["del_addr1"]); foreach ($del_addr as $addr) { $cusdaddr[] = array(pdf_lstr($addr, 30)); } // Registration numbers -------------------------------------------------- $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}")); // Items display --------------------------------------------------------- $items = array(); db_conn(PRD_DB); $sql = "SELECT * FROM pinv_items WHERE invid='{$inv['invid']}' AND DIV='" . USER_DIV . "'"; $stkdRslt = db_exec($sql); while ($stkd = pg_fetch_array($stkdRslt)) { // Get warehouse db_conn("exten"); $sql = "SELECT * FROM warehouses WHERE whid='{$stkd['whid']}' AND DIV='" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); // Get stock in this warehouse db_conn("cubit"); $sql = "SELECT * FROM stock WHERE stkid='{$stkd['stkid']}' AND DIV='" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); $sp = ""; // Check Tax Excempt db_conn("cubit"); $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatcode']}'"; $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); $vatex = pg_fetch_result($zRslt, 0); if ($vatex == "Yes") { $ex = "#"; } else { $ex = ""; } $sql = "SELECT * FROM vatcodes WHERE id='{$stkd['vatcode']}'"; $runsql = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); if (pg_numrows($runsql) < 1) { return "Invalid VAT code entered"; } $vd = pg_fetch_array($runsql); if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") { $showvat = FALSE; } // keep track of discounts //$disc += $stkd['disc']; if ($stkd["account"] > 0) { $description = $stkd["description"]; } else { $description = $stk["stkdes"]; } // Remove any new lines from the description $ar_desc = explode("\n", $description); $description = implode(" ", $ar_desc); $items[] = array("Code" => makewidth($pdf, 75, 12, $stk['stkcod']), "Description" => makewidth($pdf, 175, 12, $ex . $description), "Qty" => $stkd['qty'], "Unit Price" => CUR . $stkd['unitcost'], "Unit Discount" => CUR . $stkd['disc'], "Amount" => CUR . $stkd['amt']); } // Comment --------------------------------------------------------------- $comment = array(array("<i>VAT Exempt Indicator : #</i>"), array($inv["comm"])); // Box for signature ----------------------------------------------------- $sign = array(array("<b>Terms:</b> {$inv['terms']} days"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array(" <b>Date:</b> ____________________")); // Totals ---------------------------------------------------------------- if (!isset($showvat)) { $showvat = TRUE; } if ($showvat == TRUE) { $vat14 = AT14; } else { $vat14 = ""; } $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => CUR . "{$inv['subtot']}"), array("1" => "<b>Trade Discount:</b> ", "2" => CUR . "{$inv['discount']}"), array("1" => "<b>Delivery Charge:</b> ", "2" => CUR . "{$inv['delivery']}"), array("1" => "<b>VAT {$vat14}:</b> ", "2" => CUR . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => CUR . "{$inv['total']}")); $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right")); $ic = 0; while (++$ic * 22 < count($items)) { } // Draw the pages, determine by the amount of items how many pages // if items > 20 start a new page $items_print = array(); for ($i = 0; $i < $ic; $i++) { if ($i) { $pdf->ezNewPage(); } // Page number ------------------------------------------------------- $pagenr = array(array("<b>Page number</b>"), array($i + 1)); // Heading $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5); drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 0, $heading_pos['y'] / 2 + 6); drawText(&$pdf, "<b>Tax Invoice</b>", 20, $heading_pos['x'] - 120, $heading_pos['y'] / 2 + 9); $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8); $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 4); $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 4); $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 4); $invoice_to_pos = drawTable(&$pdf, $invoice_to, 0, $compinfo_pos['y'], 520, 2); drawText(&$pdf, "<b>Tax Invoice to:</b>", 12, 520 / 2 - 45, $invoice_to_pos['y'] - 7); $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $invoice_to_pos['y'], 173, 8); $cuspaddr_pos = drawTable(&$pdf, $cuspaddr, $cusinfo_pos['x'], $invoice_to_pos['y'], 173, 8); $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cuspaddr_pos['x'], $invoice_to_pos['y'], 174, 8); $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2); $items_start = $i * 22; if ($i) { $items_start++; } if ($items_start >= count($items) - 22) { $items_end = count($items) - 1; } else { $items_end = ($i + 1) * 22; } $items_print = array(); for ($j = $items_start; $j <= $items_end; $j++) { $items_print[$j] = $items[$j]; } $cols = array("Code" => array("width" => 80), "Description" => array("width" => 180), "Qty" => array("width" => 33), "Unit Price" => array("width" => 80, "justification" => "right"), "Unit Discount" => array("width" => 67, "justification" => "right"), "Amount" => array("width" => 80, "justification" => "right")); $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 22, $cols, 1); $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2); $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5); $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols); } if ($curr_row < $num_rows) { $pdf->ezNewPage(); } } return $pdf; }
function details($_GET) { # Get vars extract($_GET); # validate input require_lib("validate"); $v = new validate(); $v->isOk($cusnum, "num", 1, 20, "Invalid customer number."); # display errors, if any if ($v->isError()) { $err = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class='err'>" . $e["msg"] . "</li>"; } $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>"; $OUTPUT = $confirm; require "../template.php"; } if ($type == "paid") { $ex = "AND balance=0"; } elseif ($type == "unpaid") { $ex = "AND balance>0"; } else { $ex = ""; } # Get invoice info /* Start PDF Layout */ include "../pdf-settings.php"; $get_set = "SELECT filename FROM template_settings WHERE template = 'reprints' LIMIT 1"; $run_set = db_exec($get_set) or errDie("Unable to get template settings."); if (pg_numrows($run_set) < 1) { $setting = "default"; } else { $sarr = pg_fetch_array($run_set); $setting = $sarr['filename']; } // $pdf =& new Cezpdf(); // $pdf ->selectFont($set_mainFont); // // # put a line top and bottom on all the pages // $all = $pdf->openObject(); // $pdf->saveState(); // $pdf->setStrokeColor(0,0,0,1); // // # just a new line // $pdf->ezText("<b>Tax Invoice</b>", $set_txtSize+3, array('justification'=>'centre')); // // $pdf->line(20,40,578,40); // #$pdf->line(20,822,578,822); // $pdf->addText(20,34,6,'Cubit Accounting'); // $pdf->restoreState(); // $pdf->closeObject(); // // # note that object can be told to appear on just odd or even pages by changing 'all' to 'odd' // # or 'even'. // $pdf->addObject($all,'all'); // /* /Start PDF Layout */ // ################################################################## $pdf =& new Cezpdf(); $pdf->selectFont($set_mainFont); # put a line top and bottom on all the pages $all = $pdf->openObject(); $pdf->saveState(); $pdf->setStrokeColor(0, 0, 0, 1); # just a new line $pdf->ezText("<b>Tax Invoice</b>", $set_txtSize + 3, array('justification' => 'centre')); $pdf->line(20, 40, 578, 40); #$pdf->line(20,822,578,822); $pdf->addText(20, 34, 6, 'Cubit Accounting'); $pdf->restoreState(); $pdf->closeObject(); # note that object can be told to appear on just odd or even pages by changing 'all' to 'odd' # or 'even'. $pdf->addObject($all, 'all'); /* /Start PDF Layout */ ################################################################## db_connect(); $sql = "SELECT * FROM invoices WHERE cusnum = '{$cusnum}' AND printed = 'y' AND div = '" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to get invoice information"); $sql = "SELECT * FROM nons_invoices WHERE cusid='{$cusnum}' AND div='" . USER_DIV . "' {$ex}"; $nonsinvRslt = pg_exec($sql) or errDie("Error reading nons stock invoices."); // $none=true; $i = 0; /******************************************************************************* **** **** STOCK INVOICES **** ********************************************************************************/ if ($type == "unpaid" || $type == "all") { while ($inv = pg_fetch_array($invRslt)) { $invid = $inv['invid']; if ($setting == "default") { $none = false; $products = array(); $invdet = array(); $amtdat = array(); $comments = array(); $vatdat = array(); /* --- Start some checks --- */ # check if stock was selected(yes = put done button) db_connect(); $sql = "SELECT stkid FROM inv_items WHERE invid = '{$inv['invid']}' AND div = '" . USER_DIV . "'"; $crslt = db_exec($sql); if (pg_numrows($crslt) < 1) { continue; } # Create a new page for customer if ($i > 0) { $pdf->newPage(); } /* --- End some checks --- */ /* --- Start Products Display --- */ # Products layout $products = ""; $disc = 0; # get selected stock in this invoice db_connect(); $sql = "SELECT * FROM inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); # they product display arrays $products = array(); $prodhead = array('stkcod' => 'ITEM NUMBER', 'stkdes' => 'DESCRIPTION', 'qty' => 'QTY', 'selamt' => 'UNIT PRICE', 'disc' => 'DISCOUNT', 'amt' => 'AMOUNT'); $taxex = 0; while ($stkd = pg_fetch_array($stkdRslt)) { # get warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$stkd['whid']}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); # get selected stock in this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); $sp = ""; # Check Tax Excempt if ($stk['exvat'] == 'yes') { $ex = "#"; } else { $ex = ""; } # keep track of discounts $disc += $stkd['disc']; if ($stkd["account"] > 0) { $description = $stkd["description"]; } else { $description = $stk["stkdes"]; } # put in product $products[] = array('stkcod' => $stk['stkcod'], 'stkdes' => "{$ex} {$sp}" . pdf_lstr($description), 'qty' => $stkd['qty'], 'selamt' => CUR . " {$stkd['unitcost']}", 'disc' => CUR . " {$stkd['disc']}", 'amt' => CUR . " {$stkd['amt']}"); } /* --- Start Some calculations --- */ # subtotal $SUBTOT = sprint($inv['subtot']); # Calculate tradediscm if (strlen($inv['traddisc']) > 0) { $traddiscm = sprint($inv['traddisc'] / 100 * $SUBTOT); } else { $traddiscm = "0.00"; } # Calculate subtotal $VATP = TAX_VAT; $SUBTOT = sprint($inv['subtot']); $VAT = sprint($inv['vat']); $TOTAL = sprint($inv['total']); $inv['delchrg'] = sprint($inv['delchrg']); # Update number of prints $inv['prints']++; db_connect(); $Sql = "UPDATE invoices SET prints = '{$inv['prints']}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $upRslt = db_exec($Sql) or errDie("Unable to update invoice information"); /* # minus discount # $SUBTOT -= $disc; --> already minused # duplicate $SUBTOTAL = $SUBTOT; # minus trade discount $SUBTOTAL -= $traddiscm; # add del charge $SUBTOTAL += $inv['delchrg']; # If vat must be charged if($inv['chrgvat'] == "yes"){ $VATP = TAX_VAT; $VAT = sprintf("%01.2f", (($VATP/100) * ($SUBTOTAL - $taxex))); }else{ $VATP = 0; $VAT = "0.00"; } # total $TOTAL = sprint($SUBTOTAL + $VAT); */ /* --- End Some calculations --- */ /* -- Final PDF output layout -- */ # set y so its away from the top $pdf->ezSetY($set_tlY); # Customer details $pdf->addText($set_tlX, $set_tlY, $set_txtSize - 2, "{$inv['surname']}"); $nl = pdf_addnl($pdf, $set_tlX, $set_tlY, $set_txtSize - 2, $inv['cusaddr']); $pdf->addText($set_tlX, $set_tlY - $set_txtSize * $nl, $set_txtSize - 2, "(Vat No. {$inv['cusvatno']})"); # Company details $pdf->addText($set_pgXCenter, $set_tlY, $set_txtSize - 2, COMP_NAME); $nl = pdf_addnl($pdf, $set_pgXCenter, $set_tlY, $set_txtSize - 2, COMP_PADDRR); $pdf->addText($set_pgXCenter, $set_tlY - ($set_txtSize - 2) * $nl, $set_txtSize - 2, COMP_TEL); $pdf->addText($set_pgXCenter, $set_tlY - ($set_txtSize - 2) * ($nl + 1), $set_txtSize - 2, COMP_FAX); $pdf->addText($set_pgXCenter, $set_tlY - ($set_txtSize - 2) * ($nl + 2), $set_txtSize - 2, "Reg No. " . COMP_REGNO); $pdf->addText($set_pgXCenter, $set_tlY - ($set_txtSize - 2) * ($nl + 3), $set_txtSize - 2, "VAT No. " . COMP_VATNO); if ($inv['chrgvat'] == "inc") { $inv['chrgvat'] = "Inclusive"; } elseif ($inv['chrgvat'] == "exc") { $inv['chrgvat'] = "Exclusive"; } else { $inv['chrgvat'] = "No vat"; } # Invoice details data $invdet[] = array('tit' => 'Invoice No.', 'val' => $inv['invnum']); $invdet[] = array('tit' => 'Order No.', 'val' => $inv['ordno']); $invdet[] = array('tit' => 'Terms', 'val' => "{$inv['terms']} Days"); $invdet[] = array('tit' => 'Invoice Date', 'val' => $inv['odate']); $invdet[] = array('tit' => 'Vat', 'val' => $inv['chrgvat']); # invoice details $pdf->ezTable($invdet, '', "", array('showLines' => 2, 'showHeadings' => 0, 'xPos' => $set_pgWidth - 42)); # just a new line $pdf->ezText("\n", $set_txtSize); # set y so its away from the customer details $pdf->ezSetY($set_tlY - $set_txtSize * ($nl + 3)); # products table $pdf->ezTable($products, $prodhead, '', $set_maxTblOpt); # Total amounts $amtdat[] = array('tit' => 'SUBTOTAL', 'val' => CUR . " {$SUBTOT}"); $amtdat[] = array('tit' => 'Trade Discount', 'val' => CUR . " {$traddiscm}"); $amtdat[] = array('tit' => "VAT @ {$VATP}%", 'val' => CUR . " {$VAT}"); $amtdat[] = array('tit' => "Delivery Charge", 'val' => CUR . " {$inv['delchrg']}"); $amtdat[] = array('tit' => "GRAND TOTAL", 'val' => CUR . " {$TOTAL}"); # just a new line $pdf->ezText("\n", 7); # amounts details table data $pdf->ezTable($amtdat, '', "", array('showLines' => 2, 'showHeadings' => 0, 'xPos' => $set_pgWidth - 42)); # just a new line $pdf->ezSetDy(100); $pdf->ezText("\n", $set_txtSize); $comments[] = array('tit' => "Comments", 'val' => wordwrap($inv['comm'], 16)); # VAT Number Table $pdf->ezTable($comments, '', "", array('showLines' => 5, 'showHeadings' => 0, 'xPos' => 79)); $pdf->ezSetDy(-20); $vatdat[] = array('tit' => "VAT Exempt indicator", 'val' => "#"); // $vatdat[] = array('tit' => "VAT No.", 'val' => COMP_VATNO); # VAT Number Table $pdf->ezTable($vatdat, '', "", array('showLines' => 2, 'showHeadings' => 0, 'xPos' => 79)); $i++; } else { // Invoice info db_conn("cubit"); $sql = "SELECT * FROM invoices WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice info."); if (pg_num_rows($invRslt) < 1) { return "<li class='err'>Not found</li>"; } $inv = pg_fetch_array($invRslt); db_conn("cubit"); $sql = "SELECT symbol FROM currency WHERE fcid='{$inv['fcid']}'"; $curRslt = db_exec($sql) or errDie("Unable to retrieve currency from Cubit."); $curr = pg_fetch_result($curRslt, 0); if (!$curr) { $curr = CUR; } // Check if stock was selected db_conn("cubit"); $sql = "SELECT stkid FROM inv_items WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'"; $cRslt = db_exec($sql) or errDie("Unable to retrieve invoice info."); if (pg_num_rows($cRslt) < 1) { $error = "<li class='err'>Invoice number <b>{$invid}</b> has no items</li>"; $OUTPUT = $error; } // Only needs to be blank, we're manually adding text $heading = array(array("")); // Company info ---------------------------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'"; $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit."); $comp = pg_fetch_array($ciRslt); // Banking information --------------------------------------------------- // $bnkData = qryBankAcct(getdSetting("BANK_DET")); $bnkData = qryBankAcct($inv['bankid']); $compinfo = array(); $compinfo[] = array($comp["addr1"], $comp["paddr1"]); $compinfo[] = array(pdf_lstr($comp["addr2"], 35), pdf_lstr($comp["paddr2"], 35)); $compinfo[] = array(pdf_lstr($comp["addr3"], 35), pdf_lstr($comp["paddr3"], 35)); $compinfo[] = array(pdf_lstr($comp["addr4"], 35), "{$comp['postcode']}"); $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>"); $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}"); $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}"); $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}"); // Date ------------------------------------------------------------------ $date = array(array("<b>Date</b>"), array($inv['odate'])); // Document info --------------------------------------------------------- db_conn('cubit'); $Sl = "SELECT * FROM settings WHERE constant='SALES'"; $Ri = db_exec($Sl) or errDie("Unable to get settings."); $data = pg_fetch_array($Ri); db_conn('cubit'); $Sl = "SELECT * FROM settings WHERE constant='SALES'"; $Ri = db_exec($Sl) or errDie("Unable to get settings."); $data = pg_fetch_array($Ri); if ($data['value'] == "Yes") { $sp = "<b>Sales Person: </b>{$inv['salespn']}"; } else { $sp = ""; } $docinfo = array(array("<b>Invoice No:</b> {$inv['invnum']}"), array("<b>Proforma Inv No:</b> {$inv['docref']}"), array("<b>Sales Order No:</b> {$inv['ordno']}"), array("{$sp}")); if (isset($salespn)) { $docinfo[] = array("<b>Sales Person:</b> {$salespn}"); } // Retrieve the customer information ------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusnum']}'"; $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit."); $cusData = pg_fetch_array($cusRslt); // Customer info --------------------------------------------------------- $invoice_to = array(array("")); $cusinfo = array(array("<b>{$inv['surname']}</b>")); $cusaddr = explode("\n", $cusData['addr1']); foreach ($cusaddr as $v) { $cusinfo[] = array(pdf_lstr($v, 40)); } $cusinfo[] = array("<b>Account no: </b>{$cusData['accno']}"); $cuspaddr = array(array("<b>Postal Address</b>")); $paddr = explode("\n", $cusData["paddr1"]); foreach ($paddr as $addr) { $cuspaddr[] = array($addr); } $cusdaddr = array(array("<b>Delivery Address:</b>")); if ($inv['branch'] == 0) { $branchname = "Head Office"; $cusaddr = explode("\n", $cusData['addr1']); } else { $get_addr = "SELECT * FROM customer_branches WHERE id = '{$inv['branch']}' LIMIT 1"; $run_addr = db_exec($get_addr); if (pg_numrows($run_addr) < 1) { $cusaddr = array(); $branchname = "Head Office"; } else { $barr = pg_fetch_array($run_addr); $cusaddr = explode("\n", $barr['branch_descrip']); $branchname = $barr['branch_name']; } } $cusdaddr[] = array(pdf_lstr("Branch : {$branchname}", 30)); $del_addr = explode("\n", $inv["del_addr"]); foreach ($del_addr as $addr) { $cusdaddr[] = array(pdf_lstr($addr, 30)); } // Registration numbers -------------------------------------------------- $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>", "<b>Delivery Date:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}", "{$inv['deldate']}")); // Items display --------------------------------------------------------- $items = array(); db_conn("cubit"); $sql = "SELECT * FROM inv_items WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'"; $stkdRslt = db_exec($sql); while ($stkd = pg_fetch_array($stkdRslt)) { // Get warehouse db_conn("exten"); $sql = "SELECT * FROM warehouses WHERE whid='{$stkd['whid']}' AND DIV='" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); // Get stock in this warehouse db_conn("cubit"); $sql = "SELECT * FROM stock WHERE stkid='{$stkd['stkid']}' AND DIV='" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); $sp = ""; // Check Tax Excempt db_conn("cubit"); $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatcode']}'"; $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); $vatex = pg_fetch_result($zRslt, 0); if ($vatex == "Yes") { $ex = "#"; } else { $ex = ""; } $sql = "SELECT * FROM vatcodes WHERE id='{$stkd['vatcode']}'"; $runsql = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); if (pg_numrows($runsql) < 1) { return "Invalid VAT code entered"; } $vd = pg_fetch_array($runsql); if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") { $showvat = FALSE; } // keep track of discounts //$disc += $stkd['disc']; if ($stkd["account"] > 0) { $description = $stkd["description"]; } else { $description = $stk["stkdes"]; } // Remove any new lines from the description $ar_desc = explode("\n", $description); $description = implode(" ", $ar_desc); $items[] = array("Code" => makewidth($pdf, 75, 12, $stk['stkcod']), "Description" => makewidth($pdf, 175, 12, $ex . $description), "Qty" => $stkd['qty'], "Unit Price" => $curr . $stkd['unitcost'], "Unit Discount" => $curr . $stkd['disc'], "Amount" => $curr . $stkd['amt']); } $inv["comm"] = fixparag(&$pdf, 3, 520, 11, $inv["comm"]); /*$inv["comm"] = preg_replace("/[\n]/", " ", $inv["comm"]); $lines = array(); $txtleft = $inv["comm"]; $done = false; while (count($lines) < 3 && !$done) { $mc = maxwidth(&$pdf, 520, 11, $txtleft); // run until end of a word. while ($txtleft[$mc - 1] != ' ' && $mc < strlen($txtleft)) ++$mc; if ($mc == strlen($txtleft)) { $done = true; } $lines[] = substr($txtleft, 0, $mc); $txtleft = substr($txtleft, $mc); } if (strlen($txtleft) > 0) { $lines[2] .= "..."; } $inv["comm"] = preg_replace("/ /", " ", implode("\n", $lines));*/ // Comment --------------------------------------------------------------- $comment = array(array("<i>VAT Exempt Indicator : #</i>"), array($inv["comm"])); // Box for signature ----------------------------------------------------- $sign = array(array("<b>Terms:</b> {$inv['terms']} days"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array(" <b>Date:</b> ____________________")); // Totals ---------------------------------------------------------------- if (!isset($showvat)) { $showvat = TRUE; } if ($showvat == TRUE) { $vat14 = AT14; } else { $vat14 = ""; } $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => $curr . "{$inv['subtot']}"), array("1" => "<b>Trade Discount:</b> ", "2" => $curr . "{$inv['discount']}"), array("1" => "<b>Delivery Charge:</b> ", "2" => $curr . "{$inv['delivery']}"), array("1" => "<b>VAT {$vat14}:</b> ", "2" => $curr . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => $curr . "{$inv['total']}")); $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right")); $ic = 0; while (++$ic * 22 < count($items)) { } // Draw the pages, determine by the amount of items how many pages // if items > 20 start a new page $items_print = array(); for ($i = 0; $i < $ic; $i++) { if ($i) { $pdf->ezNewPage(); } // Page number ------------------------------------------------------- $pagenr = array(array("<b>Page number</b>"), array($i + 1)); // Heading $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5); drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 0, $heading_pos['y'] / 2 + 6); drawText(&$pdf, "<b>Tax Invoice</b>", 20, $heading_pos['x'] - 120, $heading_pos['y'] / 2 + 9); // Should we display reprint on the invoice if ($type == "invreprint") { drawText(&$pdf, "<b>Reprint</b>", 12, $heading_pos['x'] - 70, $heading_pos['y'] / 2 + 22); } $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8); $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 3); $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 3); $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 5); $invoice_to_pos = drawTable(&$pdf, $invoice_to, 0, $compinfo_pos['y'], 520, 2); drawText(&$pdf, "<b>Tax Invoice to:</b>", 12, 520 / 2 - 45, $invoice_to_pos['y'] - 7); $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $invoice_to_pos['y'], 173, 8); $cuspaddr_pos = drawTable(&$pdf, $cuspaddr, $cusinfo_pos['x'], $invoice_to_pos['y'], 173, 8); $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cuspaddr_pos['x'], $invoice_to_pos['y'], 174, 8); $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2); $items_start = $i * 22; if ($i) { $items_start++; } if ($items_start >= count($items) - 22) { $items_end = count($items) - 1; } else { $items_end = ($i + 1) * 22; } $items_print = array(); for ($j = $items_start; $j <= $items_end; $j++) { $items_print[$j] = $items[$j]; } $cols = array("Code" => array("width" => 80), "Description" => array("width" => 180), "Qty" => array("width" => 33), "Unit Price" => array("width" => 80, "justification" => "right"), "Unit Discount" => array("width" => 67, "justification" => "right"), "Amount" => array("width" => 80, "justification" => "right")); $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 22, $cols, 1); $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2); $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5); $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols); } } } } if ($type == "paid" || $type == "all") { for ($p = 1; $p < 13; $p++) { db_conn($p); $sql = "SELECT * FROM invoices WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to get invoice information"); while ($inv = pg_fetch_array($invRslt)) { $invid = $inv['invid']; $none = false; $products = array(); $invdet = array(); $amtdat = array(); $comments = array(); $vatdat = array(); /* --- Start some checks --- */ # check if stock was selected(yes = put done button) db_conn($p); $sql = "SELECT stkid FROM inv_items WHERE invid = '{$inv['invid']}' AND div = '" . USER_DIV . "'"; $crslt = db_exec($sql); if (pg_numrows($crslt) < 1) { continue; } # Create a new page for customer if ($i > 0) { $pdf->newPage(); } /* --- End some checks --- */ /* --- Start Products Display --- */ # Products layout $products = ""; $disc = 0; # get selected stock in this invoice db_conn($p); $sql = "SELECT * FROM inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); # they product display arrays $products = array(); $prodhead = array('stkcod' => 'ITEM NUMBER', 'stkdes' => 'DESCRIPTION', 'qty' => 'QTY', 'selamt' => 'UNIT PRICE', 'disc' => 'DISCOUNT', 'amt' => 'AMOUNT'); $taxex = 0; while ($stkd = pg_fetch_array($stkdRslt)) { # get warehouse name db_conn("exten"); $sql = "SELECT whname FROM warehouses WHERE whid = '{$stkd['whid']}' AND div = '" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); # get selected stock in this warehouse db_connect(); $sql = "SELECT * FROM stock WHERE stkid = '{$stkd['stkid']}' AND div = '" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); $sp = ""; # Check Tax Excempt if ($stk['exvat'] == 'yes') { $ex = "#"; } else { $ex = ""; } # keep track of discounts $disc += $stkd['disc']; if ($stkd["account"] > 0) { $description = $stkd["description"]; } else { $description = $stk["stkdes"]; } # put in product $products[] = array('stkcod' => $stk['stkcod'], 'stkdes' => "{$ex} {$sp}" . pdf_lstr($description), 'qty' => $stkd['qty'], 'selamt' => CUR . " {$stkd['unitcost']}", 'disc' => CUR . " {$stkd['disc']}", 'amt' => CUR . " {$stkd['amt']}"); } /* --- Start Some calculations --- */ # subtotal $SUBTOT = sprint($inv['subtot']); # Calculate tradediscm if (strlen($inv['traddisc']) > 0) { $traddiscm = sprint($inv['traddisc'] / 100 * $SUBTOT); } else { $traddiscm = "0.00"; } # Calculate subtotal $VATP = TAX_VAT; $SUBTOT = sprint($inv['subtot']); $VAT = sprint($inv['vat']); $TOTAL = sprint($inv['total']); $inv['delchrg'] = sprint($inv['delchrg']); # Update number of prints $inv['prints']++; db_connect(); $Sql = "UPDATE invoices SET prints = '{$inv['prints']}' WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $upRslt = db_exec($Sql) or errDie("Unable to update invoice information"); /* -- Final PDF output layout -- */ # set y so its away from the top $pdf->ezSetY($set_tlY); # Customer details $pdf->addText($set_tlX, $set_tlY, $set_txtSize - 2, "{$inv['surname']}"); $nl = pdf_addnl($pdf, $set_tlX, $set_tlY, $set_txtSize - 2, $inv['cusaddr']); $pdf->addText($set_tlX, $set_tlY - $set_txtSize * $nl, $set_txtSize - 2, "(Vat No. {$inv['cusvatno']})"); # Company details $pdf->addText($set_pgXCenter, $set_tlY, $set_txtSize - 2, COMP_NAME); $nl = pdf_addnl($pdf, $set_pgXCenter, $set_tlY, $set_txtSize - 2, COMP_PADDRR); $pdf->addText($set_pgXCenter, $set_tlY - ($set_txtSize - 2) * $nl, $set_txtSize - 2, COMP_TEL); $pdf->addText($set_pgXCenter, $set_tlY - ($set_txtSize - 2) * ($nl + 1), $set_txtSize - 2, COMP_FAX); $pdf->addText($set_pgXCenter, $set_tlY - ($set_txtSize - 2) * ($nl + 2), $set_txtSize - 2, "Reg No. " . COMP_REGNO); $pdf->addText($set_pgXCenter, $set_tlY - ($set_txtSize - 2) * ($nl + 3), $set_txtSize - 2, "VAT No. " . COMP_VATNO); if ($inv['chrgvat'] == "inc") { $inv['chrgvat'] = "Inclusive"; } elseif ($inv['chrgvat'] == "exc") { $inv['chrgvat'] = "Exclusive"; } else { $inv['chrgvat'] = "No vat"; } # Invoice details data $invdet[] = array('tit' => 'Invoice No.', 'val' => $inv['invnum']); $invdet[] = array('tit' => 'Order No.', 'val' => $inv['ordno']); $invdet[] = array('tit' => 'Terms', 'val' => "{$inv['terms']} Days"); $invdet[] = array('tit' => 'Invoice Date', 'val' => $inv['odate']); $invdet[] = array('tit' => 'Vat', 'val' => $inv['chrgvat']); # invoice details $pdf->ezTable($invdet, '', "", array('showLines' => 2, 'showHeadings' => 0, 'xPos' => $set_pgWidth - 42)); # just a new line $pdf->ezText("\n", $set_txtSize); # set y so its away from the customer details $pdf->ezSetY($set_tlY - $set_txtSize * ($nl + 3)); # products table $pdf->ezTable($products, $prodhead, '', $set_maxTblOpt); # Total amounts $amtdat[] = array('tit' => 'SUBTOTAL', 'val' => CUR . " {$SUBTOT}"); $amtdat[] = array('tit' => 'Trade Discount', 'val' => CUR . " {$traddiscm}"); $amtdat[] = array('tit' => "VAT @ {$VATP}%", 'val' => CUR . " {$VAT}"); $amtdat[] = array('tit' => "Delivery Charge", 'val' => CUR . " {$inv['delchrg']}"); $amtdat[] = array('tit' => "GRAND TOTAL", 'val' => CUR . " {$TOTAL}"); # just a new line $pdf->ezText("\n", 7); # amounts details table data $pdf->ezTable($amtdat, '', "", array('showLines' => 2, 'showHeadings' => 0, 'xPos' => $set_pgWidth - 42)); # just a new line $pdf->ezSetDy(100); $pdf->ezText("\n", $set_txtSize); $comments[] = array('tit' => "Comments", 'val' => wordwrap($inv['comm'], 16)); # VAT Number Table $pdf->ezTable($comments, '', "", array('showLines' => 5, 'showHeadings' => 0, 'xPos' => 79)); $pdf->ezSetDy(-20); $vatdat[] = array('tit' => "VAT Exempt indicator", 'val' => "#"); // $vatdat[] = array('tit' => "VAT No.", 'val' => COMP_VATNO); # VAT Number Table $pdf->ezTable($vatdat, '', "", array('showLines' => 2, 'showHeadings' => 0, 'xPos' => 79)); $i++; } } } /******************************************************************************* **** **** NON STOCK INVOICES **** ********************************************************************************/ while ($inv = pg_fetch_array($nonsinvRslt)) { $none = false; $invid = $inv["invid"]; $products = array(); $invdet = array(); $amtdat = array(); $comments = array(); $vatdat = array(); # check if stock was selected(yes = put done button) db_connect(); $sql = "SELECT * FROM nons_inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $crslt = db_exec($sql); if (pg_numrows($crslt) < 1) { continue; } if ($i > 0) { $pdf->newPage(); } # Products layout $products = ""; $disc = 0; # get selected stock in this invoice db_connect(); $sql = "SELECT * FROM nons_inv_items WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'"; $stkdRslt = db_exec($sql); # they product display arrays $products = array(); $prodhead = array('stkdes' => 'DESCRIPTION', 'qty' => 'QTY', 'selamt' => 'UNIT PRICE', 'amt' => 'AMOUNT'); while ($stkd = pg_fetch_array($stkdRslt)) { # put in product if ($stkd['vatex'] == 'y') { $stkd['description'] = "# " . $stkd['description']; $ex = "#"; } else { $ex = " "; } $products[] = array('stkdes' => "" . pdf_lstr($stkd['description']), 'qty' => $stkd['qty'], 'selamt' => CUR . " {$stkd['unitcost']}", 'amt' => CUR . " {$stkd['amt']}"); } /* --- Start Some calculations --- */ # Subtotal $VATP = TAX_VAT; $SUBTOT = sprint($inv['subtot']); $VAT = sprint($inv['vat']); $TOTAL = sprint($inv['total']); /* -- Final PDF output layout -- */ # just a new line // $pdf->ezText("<b>Tax Invoice\nReprint<b>", $set_txtSize+3, array('justification'=>'centre')); # set y so its away from the top $pdf->ezSetY($set_tlY); $set_txtSize -= 2; # Customer details $pdf->addText($set_tlX, $set_tlY, $set_txtSize, "{$inv['cusname']}"); $nl = pdf_addnl($pdf, $set_tlX, $set_tlY, $set_txtSize, trim($inv['cusaddr'])); $pdf->addText($set_tlX, $set_tlY - $set_txtSize * $nl, $set_txtSize, "(Vat No. {$inv['cusvatno']})"); $pdf->addText($set_tlX, $set_tlY - $set_txtSize * ($nl + 1), $set_txtSize, "Customer Order Number: {$inv['cordno']}"); if ($nl > 7) { $geninc = $nl - 7; } else { $geninc = 0; } # Company details $pdf->addText($set_pgXCenter, $set_tlY, $set_txtSize, COMP_NAME); $nl = pdf_addnl($pdf, $set_pgXCenter, $set_tlY, $set_txtSize, COMP_ADDRESS); $pdf->addText($set_pgXCenter, $set_tlY - $set_txtSize * $nl, $set_txtSize, COMP_TEL); $pdf->addText($set_pgXCenter, $set_tlY - $set_txtSize * ($nl + 1), $set_txtSize, COMP_FAX); $pdf->addText($set_pgXCenter, $set_tlY - $set_txtSize * ($nl + 2), $set_txtSize, "Reg No. " . COMP_REGNO); $pdf->addText($set_pgXCenter, $set_tlY - $set_txtSize * ($nl + 3), $set_txtSize, "VAT No. " . COMP_VATNO); if ($nl - 7 > $geninc) { // $geninc = $nl - 6; } $set_txtSize += 2; # Invoice details data $invdet[] = array('tit' => 'Invoice No.', 'val' => $inv['invnum']); $invdet[] = array('tit' => 'Invoice Date', 'val' => $inv['sdate']); # invoice details $pdf->ezTable($invdet, '', "", array('showLines' => 2, 'showHeadings' => 0, 'xPos' => $set_pgWidth - 42)); # just a new line $pdf->ezText("\n", $set_txtSize); # set y so its away from the customer details $pdf->ezSetY($set_tlY - $set_txtSize * ($nl + 4 + $geninc)); # products table $pdf->ezTable($products, $prodhead, '', $set_maxTblOpt); # Total amounts $amtdat[] = array('tit' => 'SUBTOTAL', 'val' => CUR . " {$SUBTOT}"); $amtdat[] = array('tit' => "VAT @ {$VATP}%", 'val' => CUR . " {$VAT}"); $amtdat[] = array('tit' => "GRAND TOTAL", 'val' => CUR . " {$TOTAL}"); # just a new line $pdf->ezText("\n", 7); # Amounts details table data $pdf->ezTable($amtdat, '', "", array('showLines' => 2, 'showHeadings' => 0, 'xPos' => $set_pgWidth - 42)); # just a new line $pdf->ezSetDy(80); $pdf->ezText("\n", $set_txtSize); $bank = str_replace("<br>", "\n", BNK_BANKDET); $comments[] = array('tit' => "Comments", 'val' => wordwrap($inv['remarks'], 16)); # VAT Number Table $pdf->ezTable($comments, '', "", array('showLines' => 5, 'showHeadings' => 0, 'xPos' => 89)); $pdf->ezSetDy(-20); $vatdat[] = array('tit' => "VAT Exempt indicator", 'val' => "#"); // $vatdat[] = array('tit' => "VAT No.", 'val' => COMP_VATNO); # VAT Number Table $pdf->ezTable($vatdat, '', "", array('showLines' => 2, 'showHeadings' => 0, 'xPos' => 79)); } if (!isset($none)) { $none = ""; } if ($none) { if ($type == "all") { $type = ""; } $OUTPUT = "<li class=err>Selected customer doesn't have any {$type} invoices</li>\n\t\t\t<input type=button value='[X] Close' onClick='javascript:window.close();'>"; require "../template.php"; } $pdf->ezStream(); /* -- End Final PDF Layout -- */ }
function showTable() { $path = "./cartones.txt"; $fichero = fopen($path, "r"); while (($linea = fgets($fichero)) !== false) { $row = explode(":", $linea); drawTable($row); } fclose($fichero); }
function invNoteDetails($_GET) { extract($_GET); global $set_mainFont; $showvat = TRUE; $pdf =& new Cezpdf(); $pdf->selectFont($set_mainFont); // Validate require_lib("validate"); $v = new Validate(); $v->isOk($invid, "num", 1, 20, "Invalid invoice number."); $v->isOk($prd, "num", 1, 9, "Invalid period."); // Any errors? if ($v->isError()) { $err = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $err .= "<li class='err'>{$e['msg']}</li>"; } $confirm = "<p><input type='button' onClick='javascript.history.back();' value='« Correct Submission'></p>"; $OUTPUT = $confirm; require "../template.php"; } // Invoice info db_conn($prd); $sql = "SELECT * FROM inv_notes WHERE noteid='{$invid}' AND DIV='" . USER_DIV . "'"; $invRslt = db_exec($sql) or errDie("Unable to retrieve invoice info."); if (pg_num_rows($invRslt) < 1) { return "<li class='err'>Not found</li>"; } $inv = pg_fetch_array($invRslt); db_conn("cubit"); $sql = "SELECT symbol FROM currency WHERE fcid='{$inv['fcid']}'"; $curRslt = db_exec($sql) or errDie("Unable to retrieve currency from Cubit."); $curr = pg_fetch_result($curRslt, 0); if (!$curr) { $curr = CUR; } // Check if stock was selected db_conn("cubit"); $sql = "SELECT stkid FROM inv_items WHERE invid='{$invid}' AND DIV='" . USER_DIV . "'"; $cRslt = db_exec($sql) or errDie("Unable to retrieve invoice info."); if (pg_num_rows($cRslt) < 1) { $error = "<li class='err'>Invoice number <b>{$invid}</b> has no items</li>"; $OUTPUT = $error; } // Only needs to be blank, we're manually adding text $heading = array(array("")); // Company info ---------------------------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM compinfo WHERE div='" . USER_DIV . "'"; $ciRslt = db_exec($sql) or errDie("Unable to retrieve company info from Cubit."); $comp = pg_fetch_array($ciRslt); // Banking information --------------------------------------------------- // $bnkData = qryBankAcct(getdSetting("BANK_DET")); $bnkData = qryBankAcct($inv['bankid']); $compinfo = array(); $compinfo[] = array(pdf_lstr($comp["addr1"], 35), pdf_lstr($comp["paddr1"], 35)); $compinfo[] = array(pdf_lstr($comp["addr2"], 35), pdf_lstr($comp["paddr2"], 35)); $compinfo[] = array(pdf_lstr($comp["addr3"], 35), pdf_lstr($comp["paddr3"], 35)); $compinfo[] = array(pdf_lstr($comp["addr4"], 35), "{$comp['postcode']}"); $compinfo[] = array("<b>REG: </b>{$comp['regnum']}", "<b>{$bnkData['bankname']}</b>"); $compinfo[] = array("<b>VAT REG: </b>{$comp['vatnum']}", "<b>Branch: </b>{$bnkData['branchname']}"); $compinfo[] = array("<b>Tel:</b> {$comp['tel']}", "<b>Branch Code: </b>{$bnkData['branchcode']}"); $compinfo[] = array("<b>Fax:</b> {$comp['fax']}", "<b>Acc Num: </b>{$bnkData['accnum']}"); // Date ------------------------------------------------------------------ $date = array(array("<b>Date</b>"), array($inv['odate'])); // Document info --------------------------------------------------------- db_conn('cubit'); $Sl = "SELECT * FROM cubit.settings WHERE constant='SALES'"; $Ri = db_exec($Sl) or errDie("Unable to get settings."); $data = pg_fetch_array($Ri); if ($data['value'] == "Yes") { $sp = "<b>Sales Person: </b>{$inv['salespn']}"; } else { $sp = ""; } // Retrieve the customer information ------------------------------------- db_conn("cubit"); $sql = "SELECT * FROM customers WHERE cusnum='{$inv['cusnum']}'"; $cusRslt = db_exec($sql) or errDie("Unable to retrieve customer information from Cubit."); $cusData = pg_fetch_array($cusRslt); $docinfo = array(array("<b>Credit Note No:</b> {$inv['notenum']}"), array("<b>Invoice No:</b> {$inv['invnum']}"), array("<b>Sales Order No:</b> {$inv['ordno']}"), array("{$sp}")); // Customer info --------------------------------------------------------- $invoice_to = array(array("")); $cusinfo = array(array("<b>{$inv['surname']}</b>")); $addr1 = explode("\n", $cusData["addr1"]); foreach ($addr1 as $addr) { $cusinfo[] = array($addr); } $cuspaddr = array(array("<b>Postal Address</b>")); $paddr = explode("\n", $cusData["paddr1"]); foreach ($paddr as $addr) { $cuspaddr[] = array($addr); } $cusdaddr = array(array("<b>Delivery Address:</b>")); // Temp // $inv["branch"] = 0; if ($inv['branch'] == 0) { $branchname = "Head Office"; $cusaddr = explode("\n", $cusData['addr1']); } else { $get_addr = "SELECT * FROM customer_branches WHERE id = '{$inv['branch']}' LIMIT 1"; $run_addr = db_exec($get_addr); if (pg_numrows($run_addr) < 1) { $cusaddr = array(); $branchname = "Head Office"; } else { $barr = pg_fetch_array($run_addr); $cusaddr = explode("\n", $barr['branch_descrip']); $branchname = $barr['branch_name']; $cusData["del_addr1"] = $barr['branch_descrip']; } } $cusdaddr[] = array(pdf_lstr("Branch : {$branchname}", 30)); $del_addr = explode("\n", $cusData["del_addr1"]); foreach ($del_addr as $addr) { $cusdaddr[] = array(pdf_lstr($addr, 30)); } // Registration numbers -------------------------------------------------- $regnos = array(array("<b>VAT No:</b>", "<b>Order No:</b>"), array("{$inv['cusvatno']}", "{$inv['cordno']}")); // Items display --------------------------------------------------------- $items = array(); db_conn($prd); $sql = "SELECT * FROM inv_note_items WHERE noteid='{$invid}' AND DIV='" . USER_DIV . "'"; $stkdRslt = db_exec($sql); $nsub = 0; while ($stkd = pg_fetch_array($stkdRslt)) { // Get warehouse db_conn("exten"); $sql = "SELECT * FROM warehouses WHERE whid='{$stkd['whid']}' AND DIV='" . USER_DIV . "'"; $whRslt = db_exec($sql); $wh = pg_fetch_array($whRslt); // Get stock in this warehouse db_conn("cubit"); $sql = "SELECT * FROM stock WHERE stkid='{$stkd['stkid']}' AND DIV='" . USER_DIV . "'"; $stkRslt = db_exec($sql); $stk = pg_fetch_array($stkRslt); $sp = ""; // Check Tax Excempt db_conn("cubit"); $sql = "SELECT zero FROM vatcodes WHERE id='{$stkd['vatcode']}'"; $zRslt = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); $vatex = pg_fetch_result($zRslt, 0); if ($vatex == "Yes") { $ex = "#"; } else { $ex = ""; } $sql = "SELECT * FROM vatcodes WHERE id='{$stkd['vatcode']}'"; // print $sql; $runsql = db_exec($sql) or errDie("Unable to retrieve vat code from Cubit."); if (pg_numrows($runsql) < 1) { //return "Invalid VAT code entered."; } $vd = pg_fetch_array($runsql); if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") { $showvat = FALSE; } $selamt = sprint($stkd['amt'] / $stkd['qty']); $nsub += sprint($stkd["amt"]); // keep track of discounts //$disc += $stkd['disc']; // Stock or non stock description? if (!empty($stkd["description"])) { $description = $stkd["description"]; } else { $description = $stk["stkdes"]; } $description = explode("\n", $description); $description = implode(" ", $description); $items[] = array("Stock Code" => makewidth($pdf, 80, 12, $stk["stkcod"]), "Description" => makewidth($pdf, 280, 12, $ex . $description), "Qty Returned" => $stkd['qty'], "Amount" => $stkd['amt']); } // Comment --------------------------------------------------------------- $comment = array(array("<i>VAT Exempt Indicator : #</i>"), array($inv["comm"])); // Box to sign in -------------------------------------------------------- $sign = array(array("<i>Thank you for your support</i>"), array(''), array("<b>Received in good order by:</b> ____________________"), array(''), array(" <b>Date:</b> ____________________")); // Totals ---------------------------------------------------------------- if (!isset($showvat)) { $showvat = TRUE; } if ($showvat == TRUE) { $vat14 = AT14; } else { $vat14 = ""; } $totals = array(array("1" => "<b>Subtotal:</b> ", "2" => $curr . sprint($nsub, 2)), array("1" => "<b>Trade Discount:</b> ", "2" => $curr . "{$inv['traddisc']}"), array("1" => "<b>Delivery Charge:</b> ", "2" => $curr . "{$inv['delchrg']}"), array("1" => "<b>VAT {$vat14}:</b> ", "2" => $curr . "{$inv['vat']}"), array("1" => "<b>Total Incl VAT:</b> ", "2" => $curr . "{$inv['total']}")); $totCols = array("1" => array("width" => 90), "2" => array("justification" => "right")); $ic = 0; while (++$ic * 20 < count($items)) { } // Draw the pages, determine by the amount of items how many pages // if items > 20 start a new page $items_print = array(); for ($i = 0; $i < $ic; $i++) { if ($i) { $pdf->ezNewPage(); } // Page number ------------------------------------------------------- $pagenr = array(array("<b>Page number</b>"), array($i + 1)); // Heading $heading_pos = drawTable(&$pdf, $heading, 0, 0, 520, 5); drawText(&$pdf, "<b>{$comp['compname']}</b>", 18, 18, $heading_pos['y'] / 2 + 6); drawText(&$pdf, "<b>Tax Credit Note</b>", 18, $heading_pos['x'] - 140, $heading_pos['y'] / 2 + 9); // Should we display reprint on the invoice if ($type == "invnotereprint") { drawText(&$pdf, "<b>Reprint</b>", 12, $heading_pos['x'] - 70, $heading_pos['y'] / 2 + 22); } $compinfo_pos = drawTable(&$pdf, $compinfo, 0, $heading_pos['y'], 320, 8); $date_pos = drawTable(&$pdf, $date, $compinfo_pos['x'], $heading_pos['y'], 100, 4); $pagenr_pos = drawTable(&$pdf, $pagenr, $date_pos['x'], $heading_pos['y'], 100, 4); $docinfo_pos = drawTable(&$pdf, $docinfo, $compinfo_pos['x'], $date_pos['y'], 200, 4); $invoice_to_pos = drawTable(&$pdf, $invoice_to, 0, $compinfo_pos['y'], 520, 2); drawText(&$pdf, "<b>Credit Note to:</b>", 12, 520 / 2 - 45, $invoice_to_pos['y'] - 7); $cusinfo_pos = drawTable(&$pdf, $cusinfo, 0, $invoice_to_pos['y'], 173, 8); $cuspaddr_pos = drawTable(&$pdf, $cuspaddr, $cusinfo_pos['x'], $invoice_to_pos['y'], 173, 8); $cusdaddr_pos = drawTable(&$pdf, $cusdaddr, $cuspaddr_pos['x'], $invoice_to_pos['y'], 174, 8); $regnos_pos = drawTable(&$pdf, $regnos, 0, $cusinfo_pos['y'], 520, 2); $items_start = $i * 22; if ($i) { $items_start++; } if ($items_start >= count($items) - 22) { $items_end = count($items) - 1; } else { $items_end = ($i + 1) * 22; } $items_print = array(); for ($j = $items_start; $j <= $items_end; $j++) { $items_print[$j] = $items[$j]; } $cols = array("Stock Code" => array("width" => 80), "Description" => array("width" => 280), "Qty Returned" => array("width" => 80), "Amount" => array("width" => 80, "justification" => "right")); $items_pos = drawTable(&$pdf, $items_print, 0, $regnos_pos['y'] + 2, 520, 23, $cols, 1); $comment_pos = drawTable(&$pdf, $comment, 0, $items_pos['y'], 520, 2); $sign_pos = drawTable(&$pdf, $sign, 0, $comment_pos['y'], 320, 5); $totals_pos = drawTable(&$pdf, $totals, $sign_pos['x'], $comment_pos['y'], 200, 5, $totCols); $pdf->addText(20, 34, 6, 'Cubit Accounting'); } $pdf->ezStream(); }