359 lines
10 KiB
PHP
359 lines
10 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
echo("<br>\n");
|
|
$error_message = "Invalid Access";
|
|
include "form.messages.php";
|
|
exit();
|
|
}
|
|
|
|
|
|
// Check permissions
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier','Financial Team','Schedule Reporting');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
echo("<br>\n");
|
|
$error_message = "Invalid Access";
|
|
include "form.messages.php";
|
|
return;
|
|
}
|
|
|
|
|
|
// Get parameters to script
|
|
if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']);
|
|
if (array_key_exists('menu_num',$_GET)) $menu_num = intval($_GET['menu_num']);
|
|
|
|
if (!isset($schedule_num)) {
|
|
echo("<br>\n");
|
|
$error_message = "Invalid Access";
|
|
include "form.messages.php";
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
// Verify the schedule_num is a valid and active schedule
|
|
$today = date("Y-m-d",time());
|
|
$query = "select * from hotlunch_schedules " .
|
|
"where school_num = $school_num " .
|
|
"and record_num = $schedule_num";
|
|
$results = db_query($query);
|
|
|
|
if (db_num_rows($results) == 0) {
|
|
echo("<br>\n");
|
|
$error_message = "Invalid schedule number";
|
|
include "form.messages.php";
|
|
return;
|
|
}
|
|
|
|
$schedule = db_fetch_array($results);
|
|
$schedule_name = $schedule['schedule_name'];
|
|
|
|
include "supplier_orders.post.php";
|
|
|
|
|
|
// Check if this is a valid menu
|
|
$query = "select * from hotlunch_menu_dates " .
|
|
"where school_num = $school_num " .
|
|
"and schedule_num = $schedule_num " .
|
|
"and record_num = $menu_num";
|
|
$results = db_query($query);
|
|
|
|
if (db_num_rows($results) == 0) {
|
|
echo("<br>\n");
|
|
$error_message = "The requested hot lunch menu is invalid";
|
|
include "form.messages.php";
|
|
return;
|
|
}
|
|
|
|
$hotlunch_menu_date = db_fetch_array($results);
|
|
$menu_date = $hotlunch_menu_date['menu_date'];
|
|
$menu_title = $hotlunch_menu_date['menu_title'];
|
|
$mdate = $menu_date;
|
|
|
|
|
|
|
|
|
|
//
|
|
// 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;
|
|
|
|
$document_name = "Supplier Orders Summary";
|
|
|
|
// Setup parameters for this document
|
|
$max_rows = 170;
|
|
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
$logo_url = $school_record['logo_url'];
|
|
$logo_image = "images/" . $school_record['logo_image'];
|
|
$logo_row = $max_rows + 10;
|
|
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
return;
|
|
}
|
|
|
|
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');
|
|
}
|
|
}
|
|
|
|
// 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);
|
|
|
|
$pdf->addPage();
|
|
|
|
$font_red = hexdec("00");
|
|
$font_green = hexdec("00");
|
|
$font_blue = hexdec("00");
|
|
|
|
$pdf->SetTextColor($font_red,$font_green,$font_blue);
|
|
|
|
$school_name = $school_record['school_name'];
|
|
$school_address = $school_record['address'];
|
|
$school_city = $school_record['city'];
|
|
$school_province = $school_record['province'];
|
|
$school_postal = $school_record['postal'];
|
|
$school_phone = $school_record['phone'];
|
|
|
|
|
|
// Set parameters for this document
|
|
// $max_rows = 170; // Set above
|
|
$max_width = 230;
|
|
|
|
$left_col = 20;
|
|
$ord_col = 130;
|
|
$pkg_col = 145;
|
|
$qty_col = 160;
|
|
$extra_col = 175;
|
|
$est_col = 190;
|
|
$cost_col = 220;
|
|
|
|
$start_row = 30;
|
|
$incr = 5;
|
|
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 2);
|
|
|
|
$curr_row = 10;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(100,$incr + 1,$school_name,'0',1,'L');
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
|
|
$curr_row += $incr + 2;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($max_width,$incr,$schedule_name,'0',1,'L',true);
|
|
|
|
$curr_row += $incr + 1;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($max_width,$incr,"$menu_title - $menu_date",'0',1,'L',true);
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
|
|
// Get set of supplier orders to print
|
|
$query = "select supplier_name,product_name,online_qty,supplier_product_num,supplier_product_qty,soi.package_qty,qty_ordered,estimated_cost,soi.actual_cost,soh.record_num " .
|
|
"from supplier_order_header as soh, supplier_order_items soi , suppliers as s, supplier_products as sp " .
|
|
"where soh.school_num = $school_num " .
|
|
"and soi.school_num = $school_num " .
|
|
"and s.school_num = $supplier_school_num " .
|
|
"and sp.school_num = $supplier_school_num " .
|
|
"and soi.order_num = soh.record_num " .
|
|
"and soh.supplier_num = s.record_num " .
|
|
"and soh.schedule_num = $schedule_num " .
|
|
"and soh.menu_num = $menu_num " .
|
|
"and soi.supplier_product_num = sp.record_num " .
|
|
"order by 1,2";
|
|
$orders = db_query($query);
|
|
|
|
if (db_num_rows($orders) == 0) {
|
|
echo("<p>Error: No Orders Found</p>\n");
|
|
echo("<p>Schedule Num: $schedule_num<br>\n");
|
|
echo("Menu Num: $menu_num</p>\n");
|
|
return;
|
|
}
|
|
|
|
|
|
// Process the orders
|
|
$curr_row = $start_row;
|
|
$prev_supplier = "";
|
|
$page = 1;
|
|
$printHeader = false;
|
|
$printPageHeader = false;
|
|
|
|
while ($order = db_fetch_array($orders)) {
|
|
|
|
extract($order);
|
|
|
|
if ($supplier_name != $prev_supplier) {
|
|
$prev_supplier = $supplier_name;
|
|
|
|
// Determine how many lines this supplier will require
|
|
$query = "select count(*) from supplier_order_items " .
|
|
"where school_num = $school_num " .
|
|
"and order_num = $record_num " .
|
|
"and schedule_num = $schedule_num " .
|
|
"and menu_num = $menu_num";
|
|
$num = db_getVal($query);
|
|
|
|
$last_row = $curr_row + ($num + 3) * $incr;
|
|
if ($curr_row > $start_row && $last_row > $max_rows) {
|
|
$pdf->addPage();
|
|
$page++;
|
|
$curr_row = 10;
|
|
$printPageHeader = true;
|
|
}
|
|
|
|
$printHeader = true;
|
|
|
|
}
|
|
|
|
// Determine if there is enough room on page
|
|
if ($curr_row > $start_row && $curr_row > $max_rows) {
|
|
$pdf->addPage();
|
|
$page++;
|
|
$printPageHeader = true;
|
|
}
|
|
|
|
|
|
// Print page headers because a new page has been added
|
|
if ($printPageHeader) {
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
$curr_row = 10;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(100,$incr,$school_name,'0',1,'L');
|
|
|
|
$curr_row += $incr + 1;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($max_width,$incr,$schedule_name,'0',1,'L',true);
|
|
|
|
$curr_row += $incr + 1;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($max_width,$incr,"$menu_title - $menu_date",'0',1,'L',true);
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row = $start_row;
|
|
|
|
$printPageHeader = false;
|
|
$printHeader = true;
|
|
}
|
|
|
|
// Print supplier header and column headers
|
|
if ($printHeader) {
|
|
$printHeader = false;
|
|
$curr_row += $incr - 2;
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($max_width,$incr,$supplier_name,'1',1,'L',true);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$curr_row += $incr;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(110,$incr,"Product",'1',1,'L',true);
|
|
|
|
$pdf->SetXY($ord_col,$curr_row);
|
|
$pdf->Cell(15,$incr,"Online",'1',1,'R',true);
|
|
|
|
$pdf->SetXY($pkg_col,$curr_row);
|
|
$pdf->Cell(15,$incr,"Pkg",'1',1,'R',true);
|
|
|
|
$pdf->SetXY($qty_col,$curr_row);
|
|
$pdf->Cell(15,$incr,"Order",'1',1,'R',true);
|
|
|
|
$pdf->SetXY($extra_col,$curr_row);
|
|
$pdf->Cell(15,$incr,"Surplus",'1',1,'R',true);
|
|
|
|
$pdf->SetXY($est_col,$curr_row);
|
|
$pdf->Cell(30,$incr,"Estimated",'1',1,'R',true);
|
|
|
|
$pdf->SetXY($cost_col,$curr_row);
|
|
$pdf->Cell(30,$incr,"Actual",'1',1,'R',true);
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(110,$incr,$product_name,'1',1,'L');
|
|
|
|
$pdf->SetXY($ord_col,$curr_row);
|
|
$pdf->Cell(15,$incr,$online_qty,'1',1,'R');
|
|
|
|
$pdf->SetXY($pkg_col,$curr_row);
|
|
$pdf->Cell(15,$incr,$package_qty,'1',1,'R');
|
|
|
|
$pdf->SetXY($qty_col,$curr_row);
|
|
$pdf->Cell(15,$incr,$qty_ordered,'1',1,'R');
|
|
|
|
$extra = ($qty_ordered * $package_qty) - $online_qty;
|
|
$pdf->SetXY($extra_col,$curr_row);
|
|
$pdf->Cell(15,$incr,$extra,'1',1,'R');
|
|
|
|
$pdf->SetXY($est_col,$curr_row);
|
|
$pdf->Cell(30,$incr,$currencySymbol . number_format((float)$estimated_cost,2),'1',1,'R');
|
|
|
|
$actual_cost = db_getVal("SELECT sum(actual_cost) FROM supplier_order_items_actual " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND schedule_num = $schedule_num " .
|
|
"AND menu_num = $menu_num " .
|
|
"AND supplier_product_num = $supplier_product_num");
|
|
$pdf->SetXY($cost_col,$curr_row);
|
|
$pdf->Cell(30,$incr,$currencySymbol . number_format((float)$actual_cost,2),'1',1,'R');
|
|
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
|
|
|
|
// Output the completed PDF
|
|
$filename = "supplier-orders-summary.$mdate.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=$filename");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$pdf->Output($filename,"D");
|
|
|
|
?>
|