301 lines
9.7 KiB
PHP
301 lines
9.7 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;
|
|
$left_col = 10;
|
|
$last_col = 265;
|
|
|
|
$scol = 105;
|
|
$columns = array($left_col,$scol);
|
|
$alignment = array('L');
|
|
$headings = array("PRODUCT");
|
|
$field_type = array('%s');
|
|
|
|
|
|
// Get months to process
|
|
$query = "SELECT substring(menu_date,1,7) AS month " .
|
|
"FROM hotlunch_menu_dates AS hlmd, hotlunch_order_items AS hloi, hotlunch_schedules AS hls " .
|
|
"WHERE hlmd.school_num = $school_num " .
|
|
"AND hloi.school_num = $school_num " .
|
|
"AND hls.school_num = $school_num " .
|
|
"AND hlmd.record_num = hloi.menu_num " .
|
|
"AND hls.record_num = hlmd.schedule_num " .
|
|
"AND hls.schedule_type IN ('Hot Lunch','Date Sensitive','Other') " .
|
|
"GROUP BY 1 " .
|
|
"ORDER BY 1 DESC " .
|
|
"LIMIT 0,11";
|
|
$menu_months = db_query($query);
|
|
$i = db_num_rows($menu_months);
|
|
$months = array();
|
|
while ($row = db_fetch_assoc($menu_months)) {
|
|
$i--;
|
|
$months[$i] = $row;
|
|
}
|
|
|
|
$col_width = intval(($last_col - $scol) / (count($months) + 1));
|
|
$col = $scol + $col_width;
|
|
for ($i = 0; $i < count($months); $i++) {
|
|
$columns[] = $col;
|
|
$alignment[] = 'R';
|
|
$headings[] = $months[$i]['month'];
|
|
$field_type[] = '%d';
|
|
$nMenus = 0;
|
|
if (array_key_exists('num', $months[$i])) $nMenus = $months[$i]['num'];
|
|
$col += $col_width;
|
|
}
|
|
|
|
$columns[] = $col;
|
|
$alignment[] = 'R';
|
|
$headings[] = getLanguageText('TEXT-TOTAL');
|
|
$field_type[] = '%d';
|
|
|
|
|
|
$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-PRODUCT-SALES-REPORT');
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
global $curr_row, $incr, $left_col, $start_row, $title_width, $max_width, $supplier_name, $num_products, $contact, $headings, $columns, $alignment, $last_col, $document_font, $document_font_size, $school_name;
|
|
|
|
$curr_row = $start_row;
|
|
|
|
// Display titles
|
|
$this->SetFont($document_font,"B",12);
|
|
$this->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
$this->SetXY($columns[0],$curr_row);
|
|
$this->Cell($max_width,$incr + 1,$school_name . ' - ' . $supplier_name,'0',1,'L',true);
|
|
|
|
$this->SetFont($document_font,"B",$document_font_size);
|
|
$this->SetXY($last_col - 50,$curr_row);
|
|
$this->Cell(50,$incr + 1,$num_products,'0',1,'R',true);
|
|
|
|
$curr_row += $incr + 3;
|
|
$this->SetFont($document_font,"B",$document_font_size);
|
|
|
|
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];
|
|
|
|
$this->SetXY($col,$curr_row);
|
|
$this->Cell($width,$incr,$headings[$i],'0',1,$align,true,'',1);
|
|
}
|
|
}
|
|
|
|
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');
|
|
|
|
$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');
|
|
}
|
|
}
|
|
|
|
|
|
$pdf= new PDF('L', 'mm', 'Letter', 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);
|
|
|
|
$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");
|
|
while ($row = db_fetch_array($suppliers)) {
|
|
extract($row);
|
|
$supplier_num = $record_num;
|
|
|
|
// Get supplier products
|
|
$results = db_query("SELECT * " .
|
|
"FROM supplier_products " .
|
|
"WHERE school_num = $supplier_school_num " .
|
|
"AND supplier_num = $supplier_num " .
|
|
"AND status = 'Active' " .
|
|
"AND product_type = 'Product' " .
|
|
"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) {
|
|
$pdf->addPage();
|
|
$curr_row += $incr + 3;
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
|
|
|
|
$bg = true;
|
|
if ($count % 2) $bg = false;
|
|
|
|
$product_num = $row['record_num'];
|
|
$total = 0;
|
|
$totals = array();
|
|
|
|
for ($i = 1; $i < count($headings) - 1; $i++) {
|
|
$month = $headings[$i];
|
|
$query = "SELECT sum(qty) FROM hotlunch_order_items AS hloi, hotlunch_menu_products AS hlmp, hotlunch_menu_items AS hlmi, hotlunch_menu_dates AS hlmd, hotlunch_order_header AS hloh " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hlmi.school_num = $school_num " .
|
|
"AND hlmd.school_num = $school_num " .
|
|
"AND hlmp.school_num = $school_num " .
|
|
"AND hloi.school_num = $school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hloi.order_num = hloh.record_num " .
|
|
"AND hloi.ordered_by_num = hloh.ordered_by_num " .
|
|
"AND hloh.status NOT IN ('Inactive','Deleted') " .
|
|
"AND hloi.menu_item_num = hlmp.menu_item_num " .
|
|
"AND hloi.active = 'Y' " .
|
|
"AND hlmp.supplier_product_num = $product_num " .
|
|
"AND hlmp.menu_item_num = hlmi.record_num " .
|
|
"AND hlmi.menu_num = hlmd.record_num " .
|
|
"AND hlmd.menu_date LIKE '$month%'";
|
|
$qty = intval(db_getVal($query));
|
|
$totals[$i] = $qty;
|
|
$total += $qty;
|
|
}
|
|
|
|
if ($total == 0) continue;
|
|
|
|
// Print product name
|
|
$col = $columns[0];
|
|
$width = $columns[1] - $columns[0];
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($width,$incr,$row['product_name'],'0',1,'L',$bg,'',1);
|
|
|
|
// Print monthly totals
|
|
for ($i = 1; $i < count($headings) - 1; $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];
|
|
$qty = $totals[$i];
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($width,$incr,number_format($qty,0),'0',1,$align,$bg,'',1);
|
|
}
|
|
|
|
$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->SetFont($document_font,"B",$document_font_size);
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($width,$incr,number_format($total,0),'0',1,$align,$bg,'',1);
|
|
|
|
$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-product-sales.pdf");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$pdf->Output("supplier-product-sales.pdf","D");
|
|
return;
|
|
|
|
?>
|