function renderFontEffect() { $canvas = new \Imagick(); $canvas->newPseudoImage(500, 300, "canvas:none"); $canvas->setImageFormat('png'); $shadow = clone $canvas; $text = clone $canvas; drawText($text); drawText($shadow, true); $edge = getSilhouette($text); $kernel = \ImagickKernel::fromBuiltIn(\Imagick::KERNEL_OCTAGON, "2"); $edge->morphology(\Imagick::MORPHOLOGY_EDGE_IN, 1, $kernel); $edge->compositeImage($text, \Imagick::COMPOSITE_ATOP, 0, 0); $canvas->compositeImage($shadow, \Imagick::COMPOSITE_COPY, 0, 0); $canvas->compositeImage($text, \Imagick::COMPOSITE_ATOP, 0, 0); header("Content-Type: image/png"); echo $canvas->getImageBlob(); }
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 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(); }
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(); }
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 display($_POST) { extract($_POST); global $PRDMON; #determine the date range based on period selection if (isset($year_to_process)) { switch ($year_to_process) { case "active": $fdate_year = getYearOfFinPrd(1); $fdate_month = $PRDMON[1]; $fdate_day = "1"; $tdate_year = getYearOfFinPrd(12); $tdate_month = $PRDMON[12]; $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year)); break; case "previous": $fdate_year = getYearOfFinPrd(1) - 1; $fdate_month = $PRDMON[1]; $fdate_day = "1"; $tdate_year = getYearOfFinPrd(12) - 1; $tdate_month = $PRDMON[12]; $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year)); break; default: $fdate_year = getYearOfFinPrd(1); $fdate_month = "03"; $fdate_day = "01"; $tdate_year = getYearOfFinPrd(12); $tdate_month = "02"; $tdate_day = date("d", mktime(0, 0, 0, 3, 0, $tdate_year)); } } // ----------------------------------------------------------------------- // Sanity checks // ----------------------------------------------------------------------- require_lib("validate"); $v = new validate(); // Does this employee number actually exist db_conn("cubit"); $sql = "SELECT * FROM employees WHERE empnum='" . (int) $empnum . "' AND div='" . USER_DIV . "'"; $empinf_rslt = db_exec($sql) or errDie("Unable to retrieve employee number from Cubit."); if (pg_num_rows($empinf_rslt) == 0) { $v->addError(0, "Employee number not found in Cubit."); } $v->isOk($fdate_month, "num", 1, 2, "Invalid from date (month)"); $v->isOk($fdate_year, "num", 4, 4, "Invalid from date (year)"); $v->isOk($tdate_month, "num", 1, 2, "Invalid to date (month)"); $v->isOk($tdate_year, "num", 4, 4, "Invalid to date (year)"); if ($fdate_month > 12) { $v->addError(0, "Invalid from date (month)"); } if ($fdate_year < 1970 || $fdate_year > 2050) { $v->addError(0, "Invalid from date (year)"); } if ($tdate_month > 12) { $v->addError(0, "Invalid to date (month)"); } if ($tdate_year < 1970 || $tdate_year > 2050) { $v->addError(0, "Invalid to date (year)"); } if ($fdate_day > getDaysInMonth((int) $fdate_month, $fdate_year)) { $v->addError(0, "Invalid from date (day)"); } if ($tdate_day > getDaysInMonth((int) $tdate_month, $tdate_year)) { $v->addError(0, "Invalid to date (day)"); } $from_time = mktime(0, 0, 0, $fdate_day, $fdate_month, $fdate_year); $to_time = mktime(0, 0, 0, $tdate_day, $tdate_month, $tdate_year); if ($from_time > $to_time) { $v->addError(0, "Invalid date range specified."); } // Return the errors, if any if ($v->isError()) { $confirm = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $confirm .= "<li class='err'>{$e['msg']}</li>"; } return slct($confirm); } $from_date = "{$fdate_year}-{$fdate_month}-{$fdate_day}"; $to_date = "{$tdate_year}-{$tdate_month}-{$tdate_day}"; $gross_taxable_annual_payments = 0.0; $gross_non_taxable_income = 0.0; $gross_retirement_funding_income = 0.0; $gross_non_retirement_funding_income = 0.0; $gross_remuneration = 0.0; db_conn("cubit"); $sql = "SELECT * FROM compinfo"; $compinfo_rslt = db_exec($sql) or errDie("Unable to retrieve company information from Cubit."); $compinfo = pg_fetch_array($compinfo_rslt); db_conn("cubit"); $sql = "SELECT * FROM employees WHERE empnum='{$empnum}'"; $empinfo_rslt = db_exec($sql) or errDie("Unable to retrieve employee information from Cubit."); $empinfo = pg_fetch_array($empinfo_rslt); $header_out = "<b>Employees tax certificate</b>"; $employer_trading_name_out = array(array("<b>Trading or other name:</b> {$compinfo['compname']}")); $employer_irp5_number_out = array(array("<b>IRP 5 number:</b> {$irp5_number}")); $employer_reference_number_out = array(array("<b>Reference number:</b> {$empinfo['taxref']}")); $employer_tax_year_out = array(array("<b>Tax year:</b> " . ($fdate_year + 1))); $employer_diplomatic_indemnity_out = array(array("<b>Diplomatic indemnity:</b> {$compinfo['diplomatic_indemnity']}")); $employer_business_address_out = array(array("<b>Employer business address:</b>"), array("{$compinfo['addr1']}"), array("{$compinfo['addr2']}"), array("{$compinfo['addr3']}")); $employer_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$compinfo['addr4']}")); $employer_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right")); // Extract the employee's birth date from her id number $bd_year = 1900 + substr($empinfo["idnum"], 0, 2); $bd_month = substr($empinfo["idnum"], 2, 2); $bd_day = substr($empinfo["idnum"], 4, 2); // Period employed from // strip out the dashes from the date $prd_employed_frm = explode("-", $empinfo["hiredate"]); $prd_employed_frm = implode($prd_employed_frm); // Period employed to if (empty($empinfo["firedate"])) { $prd_employed_to = getFinYear() . "0228"; } else { $prd_employed_to = explode("-", $firedate); $prd_employed_to = implode("", $prd_employed_to); } $employee_nature_out = array(array("<b>Nature of Person:</b> {$empinfo['nature']}")); $employee_surname_out = array(array("<b>Employee surname or trading name:</b> {$empinfo['sname']}")); $employee_first_names_out = array(array("<b>First two names:</b> {$empinfo['fnames']}")); $fnames = explode(" ", $empinfo["fnames"]); $initials = ""; foreach ($fnames as $name) { $initials .= strtoupper($name[0]); } $employee_initials_out = array(array("<b>Initials:</b> {$initials}")); $employee_identity_number_out = array(array("<b>Identity number:</b> {$empinfo['idnum']}")); $employee_passport_number_out = array(array("<b>Passport number:</b> {$empinfo['passport_number']}")); $employee_date_of_birth_out = array(array("<b>Date of birth:</b> {$bd_year}-{$bd_month}-{$bd_day}")); $employee_cc_number_out = array(array("<b>Company/CC/Trust number:</b> {$empinfo['cc_number']}")); $employee_tax_number_out = array(array("<b>Income Tax number:</b> {$empinfo['tax_number']}")); $employee_residential_out = array(array("<b>Employees residential address:</b>"), array("{$empinfo['res1']}"), array("{$empinfo['res2']}"), array("{$empinfo['res3']}")); $employee_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$empinfo['res4']}")); $employee_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right")); $employee_number_out = array(array("<b>Employee Number:</b> {$empinfo['empnum']}")); $tax_prd_employed_frm_out = array(array("<b>Period employed from:</b> {$prd_employed_frm}")); $tax_prd_employed_to_out = array(array("<b>Period employed to:</b> {$prd_employed_to}")); $tax_over_deduction_out = array(array("<b>Voluntary over-deduction:</b> {$over_deduction}")); switch ($empinfo["payprd"]) { case "m": $pay_periods = 12; break; case "f": $pay_periods = 24; break; case "w": $pay_periods = 48; break; } $tax_prd_in_year_out = array(array("<b>Pay periods in year:</b> {$pay_periods}")); if ($year_to_process == "active") { $cyear = EMP_YEAR; } else { $cyear = EMP_YEAR - 1; } db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE emp='{$empinfo['empnum']}' AND description='Basic Salary' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve the number of periods worked from Cubit."); $pay_periods_worked = pg_num_rows($rslt); $tax_prd_worked_out = array(array("<b>Number of periods worked:</b> {$pay_periods_worked}")); $tax_fixed_rate_income_out = array(array("<b>Fixed rate income:</b> {$empinfo['fixed_rate']}")); $tax_directive_number_out = array(array("<b>Directive number:</b> {$directive_number}")); // Income sources -------------------------------------------------------- $income_sources_out = array(); $income_taxable_total = 0; $income_commission_total = 0; $income_bonus_total = 0; $income_reimburse_total = 0; $income_travelallowance_total = 0; $income_subsis_total = 0; $income_otherallowance_total = 0; $deduction_motorcar_total = 0; $deduction_medical_total = 0; // $deduction_medicalaid_total = 0; db_conn("cubit"); $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Basic Salary' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_taxable_total += $empinc_data["amount"]; } $income_sources_out[] = array("<b>CODE</b>" => "3601", "<b>DESCRIPTION</b>" => "Income Taxable", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_taxable_total); $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Bonus' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_bonus_total += $empinc_data["amount"]; } $income_sources_out[] = array("<b>CODE</b>" => "3605", "<b>DESCRIPTION</b>" => "Bonus", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_bonus_total); $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Commission' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_commission_total += $empinc_data["amount"]; } $income_sources_out[] = array("<b>CODE</b>" => "3606", "<b>DESCRIPTION</b>" => "Commission", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_commission_total); #handle travel allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description = 'Travel Allowance' AND type = 'INCT' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_travelallowance_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3701", "<b>DESCRIPTION</b>" => "Travel Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_travelallowance_total); #handle reimbursements .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description!='Basic Salary' AND ex = 'RBS' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_reimburse_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3702", "<b>DESCRIPTION</b>" => "Reimbursements", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_reimburse_total); #handle subsistance allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND ex = 'SUBS' AND type = '2' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_subsis_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3704", "<b>DESCRIPTION</b>" => "Subsistance Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_subsis_total); #handle other allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND description != 'Travel Allowance' AND ex != 'SUBS' AND ex != 'RBS' AND type = '2' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_otherallowance_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3713", "<b>DESCRIPTION</b>" => "Other Allowances", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_otherallowance_total); #handle motorcar DEDUCTIONS in income table ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND (description = 'Motorcar 1 Contribution for Use' OR description = 'Motorcar 2 Contribution for Use') AND (type = 'DEDA' OR type = 'DEDB') AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $deduction_motorcar_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3802", "<b>DESCRIPTION</b>" => "Use Of Motor Vehicle", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_motorcar_total); #handle medical DEDUCTIONS in income table ... //$sql = "SELECT amount FROM emp_com WHERE emp='$empnum' AND description = 'Medical Contribution' AND type = 'DEDM'"; $sql = "SELECT amount FROM emp_com WHERE emp='{$empnum}' AND description = 'Medical Contribution' AND type = 'COMM' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $deduction_medical_total += $empinc_data['amount']; } //"<b>CODE</b>" => "3816", $income_sources_out[] = array("<b>CODE</b>" => "3810", "<b>DESCRIPTION</b>" => "Medical Contribution", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_medical_total); #handle medical aid DEDUCTIONS in income table ... // $sql = "SELECT amount FROM emp_ded WHERE emp='$empnum' AND description = 'Medical Contribution' AND type = 'DEDM'"; // $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); // while ($empinc_data = pg_fetch_array($rslt)) { // $deduction_medicalaid_total += $empinc_data['amount']; // } // $income_sources_out[] = array ( // "<b>CODE</b>" => "3802", // "<b>DESCRIPTION</b>" => "Medical aid contributions", // "<b>RF IND</b>" => "", // "<b>AMOUNT</b>" => (int)$deduction_medicalaid_total // ); // old // $sql = "SELECT * FROM emp_inc WHERE emp='$empnum' AND description!='Basic Salary'"; // $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); // while ($empinc_data = pg_fetch_array($rslt)) { // $income_sources_out[] = array ( // "<b>CODE</b>"=>"$empinc_data[code]", // "<b>DESCRIPTION</b>"=>"$empinc_data[description]", // "<b>RF IND</b>"=>"", // "<b>AMOUNT</b>"=>(int)$empinc_data["amount"] // ); // } if (!empty($nincome_description) || !empty($nincome_amount) && $nincome_code != 0) { $income_sources_out[] = array("<b>CODE</b>" => "{$nincome_code}", "<b>DESCRIPTION</b>" => "{$nincome_description}", "<b>RF IND</b>" => "{$nincome_rfind}", "<b>AMOUNT</b>" => (int) $nincome_amount); } if (isset($income_code)) { foreach ($income_code as $id => $value) { if ($income_code[$id] != 0) { $income_sources_out[] = array("<b>CODE</b>" => "{$income_code[$id]}", "<b>DESCRIPTION</b>" => "{$income_description[$id]}", "<b>RF IND</b>" => "{$income_rfind[$id]}", "<b>AMOUNT</b>" => (int) $income_amount[$id]); } else { $income_sources_out[] = array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => ""); } } } $income_sources_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>RF IND</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70)); // Gross renumeration ---------------------------------------------------- // Taxable annual payments db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE (code='3695' OR code='3601' OR description='Bonus') AND emp = '{$empnum}' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit."); while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_taxable_annual_payments += $emp_inc_data["amount"]; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE (code='3695' OR code='3601') AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { $gross_taxable_annual_payments += $emp_income_sources_data["amount"]; } // Non taxable annual payments db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND emp = '{$empnum}' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit."); while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_non_taxable_income += $emp_inc_data["amount"]; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { if ($emp_income_sources_data["rf_ind"] == "Y") { $gross_non_taxable_income += $emp_income_sources_data["amount"]; } } // Gross retirement funding income db_conn("cubit"); $sql = "SELECT emp_pension, emp_ret FROM employees WHERE empnum='{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross retrirement funding from Cubit."); $emp_data = pg_fetch_array($rslt); // RF IND $rfind_y = 0; if (isset($income_rfind)) { foreach ($income_rfind as $id => $value) { if ($income_rfind[$id] == "Y") { $rfind_y += $income_amount[$id]; } } } //wth emp_pension is a PERCENTAGE, not some amount to add // $gross_retirement_funding_income += $emp_data["emp_pension"] + $emp_data["emp_ret"] + $rfind_y; $gross_retirement_funding_income += $gross_taxable_annual_payments / 100 * $emp_data["emp_pension"] + $emp_data["emp_ret"] + $rfind_y; // Gross non retirement funding income db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE ((code != '3601' AND code != '3603' AND code != '3604' AND code != '3610' AND code != '3615') OR description = 'Basic Salary') AND emp = '{$empnum}' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit."); // RF IND $rfind_n = 0; if (isset($income_rfind)) { foreach ($income_rfind as $id => $value) { if ($income_rfind[$id] == "N") { $rfind_n += $income_amount[$id]; } } } while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_non_retirement_funding_income += $emp_inc_data["amount"] + $rfind_n; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE (code != '3601' AND code != '3603' AND code != '3604' AND code != '3610' AND code!='3615') AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { if ($emp_income_sources_data["rf_ind"] == "N") { $gross_non_retirement_funding_income += $emp_income_sources_data["amount"]; } } // Gross Remuneration $gross_remuneration = $gross_retirement_funding_income + $gross_non_retirement_funding_income; $gross_remuneration_out = array(array("<b>CODE</b>" => "3695", "<b>DESCRIPTION</b>" => "GROSS TAXABLE ANNUAL PAYMENTS", "<b>AMOUNT</b>" => (int) $gross_taxable_annual_payments), array("<b>CODE</b>" => "3696", "<b>DESCRIPTION</b>" => "GROSS NON-TAXABLE INCOME", "<b>AMOUNT</b>" => (int) $gross_non_taxable_income), array("<b>CODE</b>" => "3697", "<b>DESCRIPTION</b>" => "GROSS RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_retirement_funding_income), array("<b>CODE</b>" => "3698", "<b>DESCRIPTION</b>" => "GROSS NON-RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_non_retirement_funding_income), array("<b>CODE</b>" => "3699", "<b>DESCRIPTION</b>" => "GROSS REMUNERATION", "<b>AMOUNT</b>" => (int) $gross_remuneration)); $gross_remuneration_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 410), "<b>AMOUNT</b>" => array("width" => 70)); // Deductions ------------------------------------------------------------ $deductions_out = array(); $deduction_pension_total = 0; $deduction_provident_total = 0; $deduction_medicalaid_total = 0; $deduction_medical_total2 = 0; $deduction_retirementann_total = 0; $deduction_premiumpol_total = 0; db_conn("cubit"); $sql = "SELECT * FROM emp_deductions WHERE empnum='{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($ded_data = pg_fetch_array($rslt)) { $deductions_out[] = array("<b>CODE</b>" => "{$ded_data['code']}", "<b>DESCRIPTION</b>" => "{$ded_data['description']}", "<b>CLEARANCE NO</b>" => "{$ded_data['clearance_no']}", "<b>AMOUNT</b>" => (int) $ded_data["amount"]); } #handle pension deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Pension' AND type = 'DEDP' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_pension_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4001", "<b>DESCRIPTION</b>" => "Current pension fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_pension_total); #handle provident deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Provident' AND type = 'DEDV' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_provident_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4003", "<b>DESCRIPTION</b>" => "Current provident fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_provident_total); #handle medical DEDUCTIONS in income table ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Medical Contribution' AND type = 'DEDM' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $deduction_medical_total2 += $empinc_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4005", "<b>DESCRIPTION</b>" => "Medical Contribution", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_medical_total2); #handle retirement annuity deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Retirement Annuity Fund' AND type = 'DEDR' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_retirementann_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4006", "<b>DESCRIPTION</b>" => "Current retirement annuity fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_retirementann_total); $sql = "SELECT * FROM emp_ded WHERE emp='{$empnum}' AND description!='UIF' AND description!='SDL' AND description!='PAYE' AND description!='Motorcar 1 Contribution for Use' AND description!='Motorcar 2 Contribution for Use' AND description!='Medical Contribution' AND description!='Pension' AND description!='Provident' AND description!='Retirement Annuity Fund' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_premiumpol_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4018", "<b>DESCRIPTION</b>" => "Premiums paid on loss of income policies", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_premiumpol_total); //old all encapsulating search ... only first to description checks were orginal ... // $sql = "SELECT * FROM emp_ded WHERE emp='$empnum' AND description!='UIF' AND description!='SDL' AND description!='Motorcar 1 Contribution for Use' AND description!='Motorcar 2 Contribution for Use' AND description!='Medical Contribution' AND description!='Pension' AND description!='Provident' AND description!='Retirement Annuity Fund'"; // $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); // while ($empded_data = pg_fetch_array($rslt)) { // if ($empded_data["type"] != "PAYE") { // $deductions_out[] = array ( // "<b>CODE</b>"=>"$empded_data[code]", // "<b>DESCRIPTION</b>"=>"$empded_data[description]", // "<b>CLEARANCE NO</b>"=>"", // "<b>AMOUNT</b>"=>(int)$empded_data["amount"] // ); // } // } // cant just remove whatever deductions is on system if they havent actually been applied to salary (ie. salary processed) // this value will come from same place as the rest of the income/deductions ... wth // db_conn("cubit"); // $sql = "SELECT * FROM empdeduct WHERE empnum='$empnum'"; // $empded_rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.'"); // // while ($empded_data = pg_fetch_array($empded_rslt)) { // db_conn("cubit"); // $sql = "SELECT deduction, code FROM salded WHERE id='$empded_data[dedid]' AND deduction!='UIF'"; // $rslt = db_exec($sql) or errDie("Unable to retrieve deduction information from Cubit."); // $ded_data = pg_fetch_array($rslt); // // $deductions_out[] = array ( // "<b>CODE</b>"=>"$ded_data[code]", // "<b>DESCRIPTION</b>"=>"$ded_data[deduction]", // "<b>CLEARANCE NO</b>"=>"$empded_data[clearance_no]", // "<b>AMOUNT</b>"=>(int)$empded_data["amount"], 2 // ); // } if (!isset($deductions_out[0])) { $deductions_out = array(array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => "")); } $deductions_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>CLEARANCE NO</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70)); // Employees Tax deductions----------------------------------------------- $tax_amt = 0; // Retrieve PAYE amount from Cubit db_conn("cubit"); $sql = "SELECT * FROM emp_ded WHERE type='PAYE' AND emp = '{$empnum}' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve PAYE deductions from Cubit"); $paye_amount = 0; while ($empded_data = pg_fetch_array($rslt)) { // add 375 to site if salary, -375 if reverse salary $tax_amt += 375 * ($empded_data["amount"] > 0 ? 1 : -1); $paye_amount += $empded_data["amount"]; } if ($tax_amt > $paye_amount) { $tax_amt = $paye_amount; $paye_amount = 0; } else { $paye_amount -= $tax_amt; } $tax_deductions_amount = $paye_amount + $tax_amt; $employees_tax_deductions_out = array(array("<b>CODE</b>" => "4101", "<b>DESCRIPTION</b>" => "STANDARD INCOME TAX ON EMPLOYEES-SITE", "<b>AMOUNT</b>" => sprint($tax_amt, 2)), array("<b>CODE</b>" => "4102", "<b>DESCRIPTION</b>" => "PAY AS YOU EARN - PAYE", "<b>AMOUNT</b>" => sprint($paye_amount, 2)), array("<b>CODE</b>" => "4103", "<b>DESCRIPTION</b>" => "TOTAL EMPLOYEES TAX", "<b>AMOUNT</b>" => sprint($tax_deductions_amount, 2))); $employees_tax_deductions_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 410), "<b>AMOUNT</b>" => array("width" => 70)); // ----------------------------------------------------------------------- // Do the actual rendering of the pdf // ----------------------------------------------------------------------- $pdf =& new Cezpdf(); global $set_mainFont; $pdf->selectFont($set_mainFont); $pdf->addInfo("Title", "IRP 5 for {$empinfo['fnames']} {$empinfo['sname']}"); $pdf->addInfo("Author", USER_NAME); $irp5_pos = drawText(&$pdf, "<b>IRP 5</b>", 14, 520 - $pdf->getTextWidth(14, "<b>IRP 5</b>"), 0); $header_pos = drawText(&$pdf, $header_out, 12, 520 - $pdf->getTextWidth(12, $header_out), $irp5_pos['y'] + 14); // Employer information -------------------------------------------------- $employer_information_head = drawText(&$pdf, "<b>EMPLOYER INFORMATION</b>", 8, 0, $irp5_pos['y'] + 14); $employer_trading_name_pos = drawTable2(&$pdf, $employer_trading_name_out, 0, $employer_information_head['y'] + 2, 520, 1); $employer_irp5_number_pos = drawTable2(&$pdf, $employer_irp5_number_out, 0, $employer_trading_name_pos['y'], 260, 1); $employer_reference_number_pos = drawTable2(&$pdf, $employer_reference_number_out, 0, $employer_irp5_number_pos['y'], 260, 1); $employer_tax_year_pos = drawTable2(&$pdf, $employer_tax_year_out, 0, $employer_reference_number_pos['y'], 260, 1); $employer_diplomatic_indemnity_pos = drawTable2(&$pdf, $employer_diplomatic_indemnity_out, 0, $employer_tax_year_pos['y'], 260, 1); $employer_business_address_pos = drawTable2(&$pdf, $employer_business_address_out, $employer_irp5_number_pos['x'] + 20, $employer_trading_name_pos['y'], 240, 4); $employer_postal_code_pos = drawTable2(&$pdf, $employer_postal_code_out, $employer_irp5_number_pos['x'] + 20, $employer_business_address_pos['y'], 240, 1, $employer_postal_code_cols); // Employee information -------------------------------------------------- $employee_information_head = drawText(&$pdf, "<b>EMPLOYEE INFORMATION</b>", 8, 0, $employer_postal_code_pos['y'] + 15); $employee_nature_pos = drawTable2(&$pdf, $employee_nature_out, 0, $employee_information_head['y'], 100, 1); $employee_surname_pos = drawTable2(&$pdf, $employee_surname_out, $employee_nature_pos['x'] + 20, $employee_information_head['y'], 400, 1); $employee_first_names_pos = drawTable2(&$pdf, $employee_first_names_out, 0, $employee_nature_pos['y'], 400, 1); $employee_initials_pos = drawTable2(&$pdf, $employee_initials_out, $employee_first_names_pos['x'] + 20, $employee_nature_pos['y'], 100, 1); $employee_identity_number_pos = drawTable2(&$pdf, $employee_identity_number_out, 0, $employee_first_names_pos['y'], 260, 1); $employee_residential_pos = drawTable2(&$pdf, $employee_residential_out, $employee_identity_number_pos['x'] + 20, $employee_first_names_pos['y'], 240, 4); $employee_postal_code_pos = drawTable2(&$pdf, $employee_postal_code_out, $employee_identity_number_pos['x'] + 20, $employee_residential_pos['y'], 240, 1, $employee_postal_code_cols); $employee_number_pos = drawTable2(&$pdf, $employee_number_out, $employee_identity_number_pos['x'] + 20, $employee_postal_code_pos['y'], 240, 1); $employee_passport_number_pos = drawTable2(&$pdf, $employee_passport_number_out, 0, $employee_identity_number_pos['y'], 260, 1); $employee_date_of_birth_pos = drawTable2(&$pdf, $employee_date_of_birth_out, 0, $employee_passport_number_pos['y'], 260, 1); $employee_cc_number_pos = drawTable2(&$pdf, $employee_cc_number_out, 0, $employee_date_of_birth_pos['y'], 260, 1); $employee_tax_number_pos = drawTable2(&$pdf, $employee_tax_number_out, 0, $employee_cc_number_pos['y'], 260, 1); // Tax calculation information ------------------------------------------- $tax_calculation_head = drawText(&$pdf, "<b>TAX CALCULATION INFORMATION</b>", 8, 0, $employee_number_pos['y'] + 15); $tax_prd_employed_frm_pos = drawTable2(&$pdf, $tax_prd_employed_frm_out, 0, $tax_calculation_head['y'], 160, 1); $tax_prd_employed_to_pos = drawTable2(&$pdf, $tax_prd_employed_to_out, $tax_prd_employed_frm_pos['x'] + 20, $tax_calculation_head['y'], 160, 1); $tax_over_deduction_pos = drawTable2(&$pdf, $tax_over_deduction_out, $tax_prd_employed_to_pos['x'] + 20, $tax_calculation_head['y'], 160, 1); $tax_prd_in_year_pos = drawTable2(&$pdf, $tax_prd_in_year_out, 0, $tax_prd_employed_frm_pos['y'], 115, 1); $tax_prd_worked_pos = drawTable2(&$pdf, $tax_prd_worked_out, $tax_prd_in_year_pos['x'] + 20, $tax_prd_employed_frm_pos['y'], 115, 1); $tax_fixed_rate_income_pos = drawTable2(&$pdf, $tax_fixed_rate_income_out, $tax_prd_worked_pos['x'] + 20, $tax_prd_employed_frm_pos['y'], 115, 1); $tax_directive_number_pos = drawTable2(&$pdf, $tax_directive_number_out, $tax_fixed_rate_income_pos['x'] + 20, $tax_prd_employed_frm_pos['y'], 115, 1); // Income sources -------------------------------------------------------- $income_sources_head = drawText(&$pdf, "<b>INCOME SOURCE</b>", 8, 0, $tax_prd_in_year_pos['y'] + 15); $income_sources_pos = drawTable2(&$pdf, $income_sources_out, 0, $income_sources_head['y'] + 2, 520, 20, $income_sources_cols, 1); $gross_remuneration_head = drawText(&$pdf, "<b>GROSS REMUNERATION</b>", 8, 0, $income_sources_pos['y'] + 15); $gross_remuneration_pos = drawTable2(&$pdf, $gross_remuneration_out, 0, $gross_remuneration_head['y'] + 2, 520, 5, $gross_remuneration_cols, 1); $deductions_head = drawText(&$pdf, "<b>DEDUCTIONS</b>", 8, 0, $gross_remuneration_pos['y'] + 15); $deductions_pos = drawTable2(&$pdf, $deductions_out, 0, $deductions_head['y'] + 2, 520, 15, $deductions_cols, 1); $employees_tax_deductions_head = drawText(&$pdf, "<b>EMPLOYEES TAX DEDUCTIONS</b>", 8, 0, $deductions_pos['y'] + 15); $employees_tax_deductions_pos = drawTable2(&$pdf, $employees_tax_deductions_out, 0, $employees_tax_deductions_head['y'] + 2, 520, 3, $employees_tax_deductions_cols, 1); // Footer note ----------------------------------------------------------- $certificate_attatch = drawText(&$pdf, "Attach this certificate to your income tax return or retain it. / ", 6, 0, $employees_tax_deductions_pos['y'] + 10); $pdf->ezStream(); }
function drawPath($myDoc, $name, $n, $weights) { global $doc, $SCALE, $dx, $dy; $path = $doc->createElement("path"); $myD = ""; if (isset($name) && $name != "") { $tree = $myDoc->getWeightedSubTree($name, $weights); } else { $tree = $myDoc->getWeightedTree($weights); } /*N $totalWeight = 0; for ($i=0; $i < count($tree); $i++) { $totalWeight = $totalWeight + $weights[$tree[$i]->name]; }*/ drawAxis(count($tree)); $angle = 0; for ($i = 0; $i < count($tree); $i++) { /*N $delta = $weights[$tree[$i]->name]*2*pi()/$totalWeight; $angle_text = $angle + $delta/2; $angle = $angle + $delta; drawSingleAxis($angle);*/ $myD .= $i == 0 ? "M" : "L"; //N: should be commented $angle = ($i + 1) * 2 * pi() / count($tree); $x = $tree[$i]->score * $SCALE * cos($angle); $x = $x + $dx; $y = $tree[$i]->score * $SCALE * sin($angle); $y = $y + $dy; $myD .= " {$x} {$y} "; //2.1 = 2 + 0.1 of padding before actual text display //N: drawText(2.1*$SCALE*cos($angle_text), 2.1*$SCALE*sin($angle_text), $tree[$i]); drawText(2.1 * $SCALE * cos($angle), 2.1 * $SCALE * sin($angle), $tree[$i]); } $myD .= "z"; $path->setAttribute("d", $myD); $path->setAttribute("fill", getColor($n)); $path->setAttribute("fill-opacity", "0.2"); $path->setAttribute("stroke-width", "3"); $path->setAttribute("stroke", getColor($n)); return $path; }
$trans = imagecolorallocatealpha($img, 0, 0, 0, 127); // transparent 'color' imagesavealpha($img, true); // make image transparent imagefill($img, 0, 0, $trans); // fill the image with it $y = 15; drawText($img, POS_SERVER, $y, 'SERVERS'); drawText($img, POS_MAP, $y, 'MAP'); drawText($img, POS_PLAYERS - 25, $y, 'PLAYERS'); $y += SPACING * 1.5; // loop through the servers while ($row = mysql_fetch_array($result)) { $name = explode("|", $row['servername']); $name = str_replace("[EU] Lethal-Zone.eu TF2 ", "", $name[0]); drawText($img, POS_SERVER, $y, $name); //imagefill( $img, POS_MAP, $y, $white ); drawText($img, POS_MAP, $y, substr($row['currentmap'], 0, 16)); //imagefill( $img, POS_PLAYERS, $y, $white ); drawText($img, POS_PLAYERS, $y, sprintf('%02d', $row['currentplayers']) . "/" . sprintf('%02d', $row['maxplayers'])); $y += SPACING; } drawText($img, 5, $y + 5, "Type !rules ingame to see our rules", 10); //create image imagepng($img, FILENAME); //destroy image ImageDestroy($img); echo "Succes, image saved as " . FILENAME; ?>
} else { define('LOC_X', isset($_GET['x']) ? (int) $_GET['x'] : 0); define('LOC_Y', isset($_GET['x']) ? (int) $_GET['y'] : 0); } $disablecache = Neuron_Core_Tools::getInput('_GET', 'nocache', 'varchar'); $cache = Neuron_Core_Cache::__getInstance('snapshots/'); $name = isset($_GET['slogan']) ? $_GET['slogan'] : ''; $cachename = 'img' . LOC_X . '_' . LOC_Y . '_' . IMG_WIDTH . '_' . IMG_HEIGHT . '_' . IMG_ZOOM . '_' . strlen($name); if ($cache->hasCache($cachename) && !$disablecache) { header("Content-type: image/png"); echo $cache->getCache($cachename); } else { if (IMG_WIDTH > 0 && IMG_HEIGHT > 0) { /* $im = imagecreate (IMG_WIDTH, IMG_HEIGHT); $background_color = imagecolorallocate($im, 200, 200, 200); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "Dolumar " . date ('d/m/Y H:i:s') . ', '.LOC_X.', '.LOC_Y.'. Zoom: '.IMG_ZOOM.'%', $text_color); */ $im = Dolumar_Map_Map::getSnapshot(LOC_X, LOC_Y, IMG_WIDTH, IMG_HEIGHT, IMG_ZOOM); if (!isset($_GET['logo']) || $_GET['logo'] != false) { $logo_uri = BASE_PATH . 'client/images/topmenu_center.png'; $logo = imagecreatefrompng($logo_uri); $logosize = getimagesize($logo_uri); $logozoom = 65; $newsize = array(ceil($logosize[0] * $logozoom / 100), ceil($logosize[1] * $logozoom / 100)); // Check the dimension of the map $dim = IMG_WIDTH / IMG_HEIGHT; if ($dim > 2) { // left center
drawText("a", 16, $getUser['r']['username'], alloColor($getUser['r']['usrname_color'], true)); } # %Username% drawText("a", 36, getTrans("hasCollected"), NULL, true); # has collected %c% wows. drawText("a", 56, getTrans("clickHere"), NULL, true); # Click here to give a wow! if ($_GET['mask'] == 1) { # Apply a mask if it's set # Create the mask $mask = imagecreatetruecolor(240, 66); imagefilledrectangle($mask, 0, 0, 240, 66, alloColor("FFFFFF")); # Shadow drawText("a", 17, $getUser['r']['username'], alloColor(0, 0, 0, 80), false, NULL, 12, 0, $im); # Text in the mask drawText("a", 16, $getUser['r']['username'], alloColor("000001"), false, NULL, 12, 0, $mask); # Apply the mask imageAlphaMask($im, $mask); } # Need to turn on alpha again imagealphablending($im, false); imagesavealpha($im, true); # Output the image and quit doImage(); #~~~~~~~~~~~# # Functions # #~~~~~~~~~~~# # Function for allocating colors (1 required variable, 4 optional variables) # Returns a color identifier function alloColor($r, $g = NULL, $b = NULL, $alpha = 0, $image = NULL) {
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 display($_POST) { extract($_POST); global $PRDMON; #determine the date range based on period selection if (isset($year_to_process)) { switch ($year_to_process) { case "active": $fdate_year = getYearOfFinPrd(1); $fdate_month = $PRDMON[1]; $fdate_day = "1"; $tdate_year = getYearOfFinPrd(12); $tdate_month = $PRDMON[12]; $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year)); break; case "previous": $fdate_year = getYearOfFinPrd(1) - 1; $fdate_month = $PRDMON[1]; $fdate_day = "1"; $tdate_year = getYearOfFinPrd(12) - 1; $tdate_month = $PRDMON[12]; $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year)); break; default: $fdate_year = getYearOfFinPrd(1); $fdate_month = "03"; $fdate_day = "01"; $tdate_year = getYearOfFinPrd(12); $tdate_month = "02"; $tdate_day = date("d", mktime(0, 0, 0, 3, 0, $tdate_year)); } } // ----------------------------------------------------------------------- // Sanity checks // ----------------------------------------------------------------------- require_lib("validate"); $v = new validate(); // Does this employee number actually exist db_conn("cubit"); $sql = "SELECT * FROM employees WHERE empnum='" . (int) $empnum . "' AND div='" . USER_DIV . "'"; $empinf_rslt = db_exec($sql) or errDie("Unable to retrieve employee number from Cubit."); if (pg_num_rows($empinf_rslt) == 0) { $v->addError(0, "Employee number not found in Cubit."); } $v->isOk($fdate_month, "num", 1, 2, "Invalid from date (month)"); $v->isOk($fdate_year, "num", 4, 4, "Invalid from date (year)"); $v->isOk($tdate_month, "num", 1, 2, "Invalid to date (month)"); $v->isOk($tdate_year, "num", 4, 4, "Invalid to date (year)"); if ($fdate_month > 12) { $v->addError(0, "Invalid from date (month)"); } if ($fdate_year < 1970 || $fdate_year > 2050) { $v->addError(0, "Invalid from date (year)"); } if ($tdate_month > 12) { $v->addError(0, "Invalid to date (month)"); } if ($tdate_year < 1970 || $tdate_year > 2050) { $v->addError(0, "Invalid to date (year)"); } if ($fdate_day > getDaysInMonth((int) $fdate_month, $fdate_year)) { $v->addError(0, "Invalid from date (day)"); } if ($tdate_day > getDaysInMonth((int) $tdate_month, $tdate_year)) { $v->addError(0, "Invalid to date (day)"); } $from_time = mktime(0, 0, 0, $fdate_day, $fdate_month, $fdate_year); $to_time = mktime(0, 0, 0, $tdate_day, $tdate_month, $tdate_year); if ($from_time > $to_time) { $v->addError(0, "Invalid date range specified."); } if (isset($income_code)) { foreach ($income_code as $id => $value) { $v->isOk($income_code[$id], "numeric", 1, 4, "Invalid income code."); $v->isOk($income_description[$id], "string", 1, 80, "Invalid income description."); $v->isOk($income_rfind[$id], "string", 1, 30, "Invalid RF IND."); $v->isOk($income_amount[$id], "float", 1, 9, "Invalid income amount."); } } // Return the errors, if any if ($v->isError()) { $confirm = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $confirm .= "<li class='err'>{$e['msg']}</li>"; } return slct($confirm); } $from_date = "{$fdate_year}-{$fdate_month}-{$fdate_day}"; $to_date = "{$tdate_year}-{$tdate_month}-{$tdate_day}"; $gross_taxable_annual_payments = 0.0; $gross_non_taxable_income = 0.0; $gross_retirement_funding_income = 0.0; $gross_non_retirement_funding_income = 0.0; $gross_remuneration = 0.0; db_conn("cubit"); $sql = "SELECT * FROM compinfo"; $compinfo_rslt = db_exec($sql) or errDie("Unable to retrieve company information from Cubit."); $compinfo = pg_fetch_array($compinfo_rslt); db_conn("cubit"); $sql = "SELECT * FROM employees WHERE empnum='{$empnum}'"; $empinfo_rslt = db_exec($sql) or errDie("Unable to retrieve employee information from Cubit."); $empinfo = pg_fetch_array($empinfo_rslt); $header_out = "<b>Return of payment for work & services from which no employees tax was deducted</b>"; $employer_trading_name_out = array(array("<b>Trading or other name:</b> {$compinfo['compname']}")); $employer_irp5_number_out = array(array("<b>IT 3(a) number:</b> {$irp5_number}")); $employer_reference_number_out = array(array("<b>Reference number:</b> {$empinfo['taxref']}")); $employer_tax_year_out = array(array("<b>Tax year:</b> {$fdate_year}")); $employer_diplomatic_indemnity_out = array(array("<b>Diplomatic indemnity:</b> {$compinfo['diplomatic_indemnity']}")); $employer_business_address_out = array(array("<b>Employer business address:</b>"), array("{$compinfo['addr1']}"), array("{$compinfo['addr2']}"), array("{$compinfo['addr3']}")); $employer_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$compinfo['addr4']}")); $employer_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right")); // Extract the employee's birth date from her id number $bd_year = 1900 + substr($empinfo["idnum"], 0, 2); $bd_month = substr($empinfo["idnum"], 2, 2); $bd_day = substr($empinfo["idnum"], 4, 2); $employee_nature_out = array(array("<b>Nature of Person:</b> {$empinfo['nature']}")); $employee_surname_out = array(array("<b>Employee surname or trading name:</b> {$empinfo['sname']}")); $employee_first_names_out = array(array("<b>First two names:</b> {$empinfo['fnames']}")); $fnames = explode(" ", $empinfo["fnames"]); $initials = ""; foreach ($fnames as $name) { $initials .= strtoupper($name[0]); } $employee_initials_out = array(array("<b>Initials:</b> {$initials}")); $employee_identity_number_out = array(array("<b>Identity number:</b> {$empinfo['idnum']}")); $employee_passport_number_out = array(array("<b>Passport number:</b> {$empinfo['passport_number']}")); $employee_date_of_birth_out = array(array("<b>Date of birth:</b> {$bd_year}-{$bd_month}-{$bd_day}")); $employee_cc_number_out = array(array("<b>Company/CC/Trust number:</b> {$empinfo['cc_number']}")); $employee_tax_number_out = array(array("<b>Income Tax number:</b> {$empinfo['tax_number']}")); $employee_residential_out = array(array("<b>Employees residential address:</b>"), array("{$empinfo['res1']}"), array("{$empinfo['res2']}"), array("{$empinfo['res3']}")); $employee_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$empinfo['res4']}")); $employee_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right")); $employee_number_out = array(array("<b>Employee Number:</b> {$empinfo['empnum']}")); $tax_prd_employed_frm_out = array(array("<b>Period employed from:</b> {$prd_employed_frm}")); $tax_prd_employed_to_out = array(array("<b>Period employed to:</b> {$prd_employed_to}")); $tax_directive_number_out = array(array("<b>Directive number:</b> {$directive_number}")); // Income sources -------------------------------------------------------- $income_sources_out = array(); $income_taxable_total = 0; $income_reimburse_total = 0; $income_travelallowance_total = 0; $income_subsis_total = 0; $income_otherallowance_total = 0; $deduction_motorcar_total = 0; db_conn("cubit"); $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Basic Salary'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_taxable_total += $empinc_data["amount"]; } $income_sources_out[] = array("<b>CODE</b>" => "3601", "<b>DESCRIPTION</b>" => "Income Taxable", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_taxable_total); #handle travel allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description = 'Travel Allowance' AND type = 'INCT'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_travelallowance_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3701", "<b>DESCRIPTION</b>" => "Travel Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_travelallowance_total); #handle reimbursements .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description!='Basic Salary' AND ex = 'RBS'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_reimburse_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3702", "<b>DESCRIPTION</b>" => "Reimbursements", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_reimburse_total); #handle subsistance allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND ex = 'SUBS' AND type = '2'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_subsis_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3704", "<b>DESCRIPTION</b>" => "Subsistance Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_subsis_total); #handle other allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND description != 'Travel Allowance' AND ex != 'SUBS' AND ex != 'RBS' AND type = '2'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_otherallowance_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3713", "<b>DESCRIPTION</b>" => "Other Allowances", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_otherallowance_total); #handle motorcar DEDUCTIONS in income table ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND (description = 'Motorcar 1 Contribution for Use' OR description = 'Motorcar 2 Contribution for Use') AND (type = 'DEDA' OR type = 'DEDB')"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $deduction_motorcar_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3802", "<b>DESCRIPTION</b>" => "Use Of Motor Vehicle", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_motorcar_total); if (!empty($nincome_code) || !empty($nincome_description) || !empty($nincome_rfind) || !empty($nincome_amount)) { $income_sources_out[] = array("<b>CODE</b>" => "{$nincome_code}", "<b>DESCRIPTION</b>" => "{$nincome_description}", "<b>RF IND</b>" => "{$nincome_rfind}", "<b>AMOUNT</b>" => (int) $nincome_amount); } if (isset($income_code)) { foreach ($income_code as $id => $value) { if ($income_code[$id] != 0) { $income_sources_out[] = array("<b>CODE</b>" => "{$income_code[$id]}", "<b>DESCRIPTION</b>" => "{$income_description[$id]}", "<b>RF IND</b>" => "{$income_rfind[$id]}", "<b>AMOUNT</b>" => (int) $income_amount[$id]); } else { $income_sources_out[] = array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => ""); } } } $income_sources_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>RF IND</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70)); // Gross renumeration ---------------------------------------------------- // Taxable annual payments db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE code='3695' AND emp = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit."); while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_taxable_annual_payments += $emp_inc_data["amount"]; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE code='3695' AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { $gross_taxable_annual_payments += $emp_income_sources_data["amount"]; } // Non taxable annual payments db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND emp = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit."); while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_non_taxable_income += $emp_inc_data["amount"]; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { $gross_non_taxable_income += $emp_income_sources_data["amount"]; } // Gross retirement funding income db_conn("cubit"); $sql = "SELECT emp_pension, emp_ret FROM employees WHERE empnum='{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross retrirement funding from Cubit."); $emp_data = pg_fetch_array($rslt); $gross_retirement_funding_income += $gross_non_taxable_income / 100 * $emp_data["emp_pension"] + $emp_data["emp_ret"]; // Gross non retirement funding income db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE (code!='3603' OR code!='3604' OR code!='3610' OR code!='3615') AND emp = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit."); while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_non_retirement_funding_income += $emp_inc_data["amount"]; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE (code != '3603' OR code != '3604' OR code != '3610' OR code != '3615') AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { $gross_non_retirement_funding_income += $emp_income_sources_data["amount"]; } // Gross Remuneration $gross_remuneration = $gross_retirement_funding_income + $gross_non_retirement_funding_income; $gross_remuneration_out = array(array("<b>CODE</b>" => "3696", "<b>DESCRIPTION</b>" => "GROSS NON-TAXABLE INCOME", "<b>AMOUNT</b>" => (int) $gross_non_taxable_income), array("<b>CODE</b>" => "3697", "<b>DESCRIPTION</b>" => "GROSS RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_retirement_funding_income), array("<b>CODE</b>" => "3698", "<b>DESCRIPTION</b>" => "GROSS NON-RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_non_retirement_funding_income), array("<b>CODE</b>" => "3699", "<b>DESCRIPTION</b>" => "GROSS REMUNERATION", "<b>AMOUNT</b>" => (int) $gross_remuneration)); $gross_remuneration_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 410), "<b>AMOUNT</b>" => array("width" => 70)); // Deductions ------------------------------------------------------------ $deductions_out = array(); $deduction_pension_total = 0; $deduction_provident_total = 0; $deduction_medicalaid_total = 0; $deduction_retirementann_total = 0; $deduction_premiumpol_total = 0; db_conn("cubit"); #handle pension deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Pension' AND type = 'DEDP'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_pension_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4001", "<b>DESCRIPTION</b>" => "Current pension fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_pension_total); #handle provident deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Provident' AND type = 'DEDV'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_provident_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4003", "<b>DESCRIPTION</b>" => "Current provident fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_provident_total); #handle retirement annuity deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Retirement Annuity Fund' AND type = 'DEDR'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_retirementann_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4006", "<b>DESCRIPTION</b>" => "Current retirement annuity fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_retirementann_total); $sql = "SELECT * FROM emp_ded WHERE emp='{$empnum}' AND description!='UIF' AND description!='SDL' AND description!='PAYE' AND description!='Motorcar 1 Contribution for Use' AND description!='Motorcar 2 Contribution for Use' AND description!='Medical Contribution' AND description!='Pension' AND description!='Provident' AND description!='Retirement Annuity Fund'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_premiumpol_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4018", "<b>DESCRIPTION</b>" => "Premiums paid on loss of income policies", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_premiumpol_total); // db_conn("cubit"); // $sql = "SELECT * FROM empdeduct WHERE empnum='$empnum'"; // $empded_rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.'"); // // while ($empded_data = pg_fetch_array($empded_rslt)) { // db_conn("cubit"); // $sql = "SELECT deduction, code FROM salded WHERE id='$empded_data[dedid]'"; // $rslt = db_exec($sql) or errDie("Unable to retrieve deduction information from Cubit."); // $ded_data = pg_fetch_array($rslt); // // $deductions_out[] = array ( // "<b>CODE</b>"=>"$ded_data[code]", // "<b>DESCRIPTION</b>"=>"$ded_data[deduction]", // "<b>CLEARANCE NO</b>"=>"$empded_data[clearance_no]", // "<b>AMOUNT</b>"=>(int)$empded_data["amount"], 2 // ); // } if (!isset($deductions_out[0])) { $deductions_out = array(array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => "")); } $deductions_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>CLEARANCE NO</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70)); // Employees Tax deductions----------------------------------------------- $site_amount = 0; // Retrieve PAYE amount from Cubit db_conn("cubit"); $sql = "SELECT * FROM emp_ded WHERE type='PAYE' AND emp = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve PAYE deductions from Cubit"); $paye_amount = 0; while ($empded_data = pg_fetch_array($rslt)) { $paye_amount += $empded_data["amount"]; } // Total tax deductions $tax_deductions_amount = $site_amount + $paye_amount; $non_deduction_of_tax_out = array(array("<b>CODE</b>" => "01", "<b>DESCRIPTION</b>" => "DIRECTORS REMUNERATION - PRIVATE COMPANY / CC"), array("<b>CODE</b>" => "02", "<b>DESCRIPTION</b>" => "LESS THAN THE TAX THRESHOLD"), array("<b>CODE</b>" => "03", "<b>DESCRIPTION</b>" => "INDEPENDENT CONTRACTOR"), array("<b>CODE</b>" => "04", "<b>DESCRIPTION</b>" => "NON TAXABLE EARNINGS")); $non_deduction_of_tax_cols = array("<b>CODE</b>" => array("width" => 40)); if (!isset($reason_code)) { $reason_code = ""; } $reason_out = array(array("{$reason_code}")); // ----------------------------------------------------------------------- // Do the actual rendering of the pdf // ----------------------------------------------------------------------- $pdf =& new Cezpdf(); global $set_mainFont; $pdf->selectFont($set_mainFont); $pdf->addInfo("Title", "IT 3(a) for {$empinfo['fnames']} {$empinfo['sname']}"); $pdf->addInfo("Author", USER_NAME); $irp5_pos = drawText(&$pdf, "<b>IT 3(a)</b>", 14, 520 - $pdf->getTextWidth(14, "<b>IT 3(a)</b>"), 0); $header_pos = drawText(&$pdf, $header_out, 10, 520 - $pdf->getTextWidth(10, $header_out), $irp5_pos['y'] + 14); // Employer information -------------------------------------------------- $employer_information_head = drawText(&$pdf, "<b>EMPLOYER INFORMATION</b>", 8, 0, $irp5_pos['y'] + 14); $employer_trading_name_pos = drawTable2(&$pdf, $employer_trading_name_out, 0, $employer_information_head['y'] + 2, 520, 1); $employer_irp5_number_pos = drawTable2(&$pdf, $employer_irp5_number_out, 0, $employer_trading_name_pos['y'], 260, 1); $employer_reference_number_pos = drawTable2(&$pdf, $employer_reference_number_out, 0, $employer_irp5_number_pos['y'], 260, 1); $employer_tax_year_pos = drawTable2(&$pdf, $employer_tax_year_out, 0, $employer_reference_number_pos['y'], 260, 1); $employer_diplomatic_indemnity_pos = drawTable2(&$pdf, $employer_diplomatic_indemnity_out, 0, $employer_tax_year_pos['y'], 260, 1); $employer_business_address_pos = drawTable2(&$pdf, $employer_business_address_out, $employer_irp5_number_pos['x'] + 20, $employer_trading_name_pos['y'], 240, 4); $employer_postal_code_pos = drawTable2(&$pdf, $employer_postal_code_out, $employer_irp5_number_pos['x'] + 20, $employer_business_address_pos['y'], 240, 1, $employer_postal_code_cols); // Employee information -------------------------------------------------- $employee_information_head = drawText(&$pdf, "<b>EMPLOYEE INFORMATION</b>", 8, 0, $employer_postal_code_pos['y'] + 15); $employee_nature_pos = drawTable2(&$pdf, $employee_nature_out, 0, $employee_information_head['y'], 100, 1); $employee_surname_pos = drawTable2(&$pdf, $employee_surname_out, $employee_nature_pos['x'] + 20, $employee_information_head['y'], 400, 1); $employee_first_names_pos = drawTable2(&$pdf, $employee_first_names_out, 0, $employee_nature_pos['y'], 400, 1); $employee_initials_pos = drawTable2(&$pdf, $employee_initials_out, $employee_first_names_pos['x'] + 20, $employee_nature_pos['y'], 100, 1); $employee_identity_number_pos = drawTable2(&$pdf, $employee_identity_number_out, 0, $employee_first_names_pos['y'], 260, 1); $employee_residential_pos = drawTable2(&$pdf, $employee_residential_out, $employee_identity_number_pos['x'] + 20, $employee_first_names_pos['y'], 240, 4); $employee_postal_code_pos = drawTable2(&$pdf, $employee_postal_code_out, $employee_identity_number_pos['x'] + 20, $employee_residential_pos['y'], 240, 1, $employee_postal_code_cols); $employee_number_pos = drawTable2(&$pdf, $employee_number_out, $employee_identity_number_pos['x'] + 20, $employee_postal_code_pos['y'], 240, 1); $employee_passport_number_pos = drawTable2(&$pdf, $employee_passport_number_out, 0, $employee_identity_number_pos['y'], 260, 1); $employee_date_of_birth_pos = drawTable2(&$pdf, $employee_date_of_birth_out, 0, $employee_passport_number_pos['y'], 260, 1); $employee_cc_number_pos = drawTable2(&$pdf, $employee_cc_number_out, 0, $employee_date_of_birth_pos['y'], 260, 1); $employee_tax_number_pos = drawTable2(&$pdf, $employee_tax_number_out, 0, $employee_cc_number_pos['y'], 260, 1); // Tax calculation information ------------------------------------------- $tax_calculation_head = drawText(&$pdf, "<b>TAX CALCULATION INFORMATION</b>", 8, 0, $employee_number_pos['y'] + 15); $tax_prd_employed_frm_pos = drawTable2(&$pdf, $tax_prd_employed_frm_out, 0, $tax_calculation_head['y'], 160, 1); $tax_prd_employed_to_pos = drawTable2(&$pdf, $tax_prd_employed_to_out, $tax_prd_employed_frm_pos['x'] + 20, $tax_calculation_head['y'], 160, 1); drawTable2(&$pdf, $tax_directive_number_out, $tax_prd_employed_to_pos['x'] + 20, $tax_calculation_head['y'], 160, 1); // Income sources -------------------------------------------------------- $income_sources_head = drawText(&$pdf, "<b>INCOME SOURCE</b>", 8, 0, $tax_prd_employed_frm_pos['y'] + 15); $income_sources_pos = drawTable2(&$pdf, $income_sources_out, 0, $income_sources_head['y'] + 2, 520, 20, $income_sources_cols, 1); $gross_remuneration_head = drawText(&$pdf, "<b>GROSS REMUNERATION</b>", 8, 0, $income_sources_pos['y'] + 15); $gross_remuneration_pos = drawTable2(&$pdf, $gross_remuneration_out, 0, $gross_remuneration_head['y'] + 2, 520, 4, $gross_remuneration_cols, 1); $deductions_head = drawText(&$pdf, "<b>DEDUCTIONS</b>", 8, 0, $gross_remuneration_pos['y'] + 15); $deductions_pos = drawTable2(&$pdf, $deductions_out, 0, $deductions_head['y'] + 2, 520, 15, $deductions_cols, 1); $non_deduction_of_tax_head = drawText(&$pdf, "<b>REASON FOR NON DEDUCTION OF EMPLOYEES TAX MUST BE STATED</b>", 8, 0, $deductions_pos['y'] + 15); $non_deduction_of_tax_pos = drawTable2(&$pdf, $non_deduction_of_tax_out, 0, $non_deduction_of_tax_head['y'] + 2, 420, 4, $non_deduction_of_tax_cols, 1); $reason_text = drawText(&$pdf, "<b>Reason Code</b>", 7, $non_deduction_of_tax_pos['x'] + 10, $non_deduction_of_tax_pos['y']); $reason_pos = drawTable2(&$pdf, $reason_out, $reason_text['x'] + 15, $non_deduction_of_tax_pos['y'] - 10, 40, 1); // Footer note ----------------------------------------------------------- $certificate_attatch = drawText(&$pdf, "Attach this copy to your form IT 3", 6, 0, $non_deduction_of_tax_pos['y'] + 10); $pdf->ezStream(); }
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 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(); }