260 lines
8.5 KiB
PHP
260 lines
8.5 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
header("Location: /?action=$action&error_code=NOACCESS");
|
|
exit();
|
|
}
|
|
|
|
|
|
// Check permissions
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team','Supplier');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
header("Location: /?action=$action&error_code=NOACCESS");
|
|
return;
|
|
}
|
|
|
|
|
|
// Get parameters to script
|
|
unset($selected_supplier_num);
|
|
if (array_key_exists('selected_supplier',$_GET)) $selected_supplier_num = intval($_GET['selected_supplier']);
|
|
if (array_key_exists('selected_supplier',$_POST)) $selected_supplier_num = intval($_POST['selected_supplier']);
|
|
|
|
$swhere = "";
|
|
if (isset($selected_supplier_num)) {
|
|
$swhere = "AND record_num = $selected_supplier_num";
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Setup the PDF
|
|
//
|
|
$document_font = $school_record['document_font'];
|
|
if (strlen($document_font) == 0) $document_font = "Helvetica";
|
|
|
|
$document_font_weight = "";
|
|
$document_text_color = "#000000";
|
|
$document_font_size = 9;
|
|
|
|
|
|
// Set parameters for this document
|
|
$max_rows = 185;
|
|
$max_width = 255;
|
|
$last_col = 265;
|
|
|
|
if ($school_record['special_item_prices'] != 'Y') {
|
|
$columns = array(10,175,186,205,225,245,10,$last_col);
|
|
$fields = array('product_name','package_qty','package_cost','standard_online_price','standard_offline_price','margin','product_description');
|
|
$alignment = array('L','C','R','R','R','R','L','L');
|
|
$headings = array(getLanguageText('TEXT-PRODUCT'),
|
|
getLanguageText('TEXT-PACKAGE'),
|
|
getLanguageText('TEXT-COST'),
|
|
getLanguageText('TEXT-ON-LINE'),
|
|
getLanguageText('TEXT-PAPER'),
|
|
getLanguageText('TEXT-MARGIN')
|
|
);
|
|
$field_type = array('%s','%d','%6.'.$school_record['supplier_costs_decimals'].'f','%6.2f','%6.2f','%6.'.$school_record['supplier_costs_decimals'].'f','%s');
|
|
}
|
|
else {
|
|
$columns = array(10,135,145,165,180,195,210,225,240,10,$last_col);
|
|
$fields = array('product_name','package_qty','package_cost','standard_online_price','standard_offline_price','special_price1','special_price2','special_price3','margin','product_description');
|
|
$alignment = array('L','C','R','R','R','R','R','R','R','L','L');
|
|
$headings = array("PRODUCT","PKG","COST","ONLINE","OFFLINE","SPECIAL1","SPECIAL2","SPECIAL3","MARGIN");
|
|
$field_type = array('%s','%d','%6.'.$school_record['supplier_costs_decimals'].'f','%6.2f','%6.2f','%6.2f','%6.2f','%6.2f','%6.'.$school_record['supplier_costs_decimals'].'f','%s');
|
|
}
|
|
|
|
|
|
$start_row = 10;
|
|
$incr = 4.5;
|
|
|
|
$logo_url = $school_record['logo_url'];
|
|
$logo_image = "images/" . $school_record['logo_image'];
|
|
$logo_row = $max_rows + 5;
|
|
|
|
$document_name = getLanguageText('TEXT-SUPPLIER-PRODUCTS-REPORT');
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title, $report_subtitle;
|
|
}
|
|
|
|
function Footer() {
|
|
global $incr, $left_col, $title_width, $max_rows, $document_font, $document_font_size, $document_name, $logo_image, $logo_url, $logo_row, $school_name;
|
|
|
|
// Print the date
|
|
$this->SetFont($document_font,"",$document_font_size - 1);
|
|
$this->SetXY($left_col,$logo_row);
|
|
$date = dateString('datetime');
|
|
$this->Cell($title_width,$incr - 1,"$document_name: $date",'0',1,'R',false,'',1);
|
|
|
|
$this->SetXY($left_col,$logo_row + $incr);
|
|
$this->Cell($title_width,$incr - 1,"$school_name",'0',1,'R','',1);
|
|
|
|
$this->Image($logo_image,10,$logo_row, 50);
|
|
|
|
$this->SetXY(20,$logo_row + 9);
|
|
$this->SetFont($document_font,"B",$document_font_size);
|
|
$this->Cell($title_width,$incr,$logo_url,'0',1,'L',false,'',1);
|
|
}
|
|
}
|
|
|
|
// Force exact physical size for Letter: 8.5 x 11 inches => 279.4mm x 215.9mm (landscape)
|
|
$pageFormat = array(279.4, 215.9);
|
|
|
|
$pdf= new PDF('L', 'mm', $pageFormat, true, 'UTF-8', false);
|
|
|
|
// set default monospaced font
|
|
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
|
|
|
|
//set margins
|
|
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
|
|
|
|
//set auto page breaks
|
|
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
|
|
|
|
//set image scale factor
|
|
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
|
|
|
|
$font_red = hexdec("00");
|
|
$font_green = hexdec("00");
|
|
$font_blue = hexdec("00");
|
|
|
|
$pdf->SetTextColor($font_red,$font_green,$font_blue);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$pdf->addPage();
|
|
|
|
$school_name = $school_record['school_name'];
|
|
|
|
$curr_row = $start_row;
|
|
|
|
|
|
|
|
// Get selected supplier(s)
|
|
$suppliers = db_query("SELECT * FROM suppliers WHERE school_num = $supplier_school_num and status = 'Active' $swhere ORDER BY supplier_name");
|
|
$curr_page = 0;
|
|
while ($row = db_fetch_array($suppliers)) {
|
|
extract($row);
|
|
$supplier_num = $record_num;
|
|
|
|
$contact = "";
|
|
if (strlen($contact_name) || strlen($work_phone)) {
|
|
if (strlen($contact_name)) $contact = $contact_name;
|
|
if (strlen($work_phone)) {
|
|
if (strlen($contact)) $contact .= " - ";
|
|
$contact .= $work_phone;
|
|
}
|
|
}
|
|
|
|
|
|
// Get supplier products
|
|
$results = db_query("SELECT *,standard_online_price - (package_cost / package_qty) as margin " .
|
|
"FROM supplier_products " .
|
|
"WHERE school_num = $supplier_school_num " .
|
|
"AND supplier_num = $supplier_num " .
|
|
"AND status = 'Active' " .
|
|
"ORDER BY sequence");
|
|
$num_products = db_num_rows($results) . ' ' . getLanguageText('TEXT-PRODUCTS');
|
|
|
|
$count = 0;
|
|
$curr_row = $max_rows + 10;
|
|
while ($row = db_fetch_array($results)) {
|
|
if ($curr_row > $max_rows - $incr * 2) {
|
|
if ($curr_page) $pdf->addPage();
|
|
$curr_row = $start_row;
|
|
|
|
// Display titles
|
|
$pdf->SetFont($document_font,"B",12);
|
|
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
$pdf->SetXY($columns[0],$curr_row);
|
|
$pdf->Cell($max_width,$incr + 1,$supplier_name,'0',1,'L',true,'',1);
|
|
|
|
$pdf->SetXY($last_col - 50,$curr_row);
|
|
$pdf->Cell(50,$incr + 1,$num_products,'0',1,'R',true,'',1);
|
|
$curr_row += $incr + 1;
|
|
|
|
if (strlen($contact)) {
|
|
$pdf->SetXY($columns[0],$curr_row);
|
|
$pdf->Cell($max_width,$incr + 1,$contact,'0',1,'L',true,'',1);
|
|
$curr_row += $incr + 1;
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
$curr_row += $incr;
|
|
|
|
for ($i = 0; $i < count($headings); $i++) {
|
|
$col = $columns[$i];
|
|
$align = $alignment[$i];
|
|
if ($columns[$i + 1] > $columns[$i]) $width = $columns[$i + 1] - $columns[$i];
|
|
else $width = $last_col - $columns[$i];
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($width,$incr,$headings[$i],'0',1,$align,true,'',1);
|
|
}
|
|
|
|
$curr_page++;
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
|
|
$bg = true;
|
|
// if ($count % 2) $bg = false;
|
|
if ($count % 2) $pdf->SetFillColor(hexdec("f8"),hexdec("f8"),hexdec("f8"));
|
|
|
|
for ($i = 0; $i < count($fields); $i++) {
|
|
$col = $columns[$i];
|
|
$align = $alignment[$i];
|
|
if ($columns[$i + 1] > $columns[$i]) $width = $columns[$i + 1] - $columns[$i];
|
|
else $width = $last_col - $columns[$i];
|
|
|
|
$field = $fields[$i];
|
|
$value = $row[$field];
|
|
|
|
if ($field == 'product_name' && $print_supplier_code != 'No' && strlen($row['supplier_code'])) $value = $row['supplier_code'] . " - $value";
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($width,$incr,sprintf($field_type[$i],$value),'0',1,$align,$bg,'',1);
|
|
|
|
if ($columns[$i + 1] < $columns[$i]) $curr_row += $incr;
|
|
}
|
|
|
|
$curr_row += $incr + 1;
|
|
$count++;
|
|
}
|
|
}
|
|
|
|
|
|
// Print date on last page
|
|
$pdf->SetFont($document_font,"",$document_font_size - 2);
|
|
$date = date("F j, Y",time());
|
|
|
|
|
|
// Output the completed PDF
|
|
header('Pragma: public');
|
|
header('Expires: 0');
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
header('Cache-Control: private',false);
|
|
header('Content-type: application/pdf');
|
|
header("Content-Disposition: attachment; filename=supplier-products.pdf");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$pdf->Output("supplier-products.pdf","D");
|
|
return;
|
|
|
|
?>
|