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']; $document_name = getLanguageText('TEXT-ORDERS-SUMMARY'); // Set the status condition if required $ReportTitle = getLanguageText('TEXT-ORDERS-SUMMARY') . " - (" . $GlobalText['Student'] . ") - $schedule_name"; $orderby = "ORDER BY last_name, first_name"; $mode = "student"; if (array_key_exists('sortby',$_GET)) { switch ($_GET['sortby']) { case 'student': default: $ReportTitle = getLanguageText('TEXT-ORDERS-SUMMARY') . " (" . $GlobalText['Student'] . ") - $schedule_name"; $orderby = "ORDER BY last_name, first_name"; $mode = "student"; break; case 'student-class': $ReportTitle = getLanguageText('TEXT-ORDERS-SUMMARY') . " (" . $GlobalText['Class'] . ") - $schedule_name"; $orderby = "ORDER BY sequence,last_name, first_name"; $mode = "student-class"; break; case 'account': $ReportTitle = getLanguageText('TEXT-ORDERS-SUMMARY') . " (" . getLanguageText('TEXT-ACCOUNT') . ") - $schedule_name"; $orderby = "ORDER BY userid,last_name, first_name"; $mode = "account"; break; case 'date': $ReportTitle = getLanguageText('TEXT-ORDERS-SUMMARY') . " (" . getLanguageText('TEXT-DATE') . ") - $schedule_name"; $orderby = "ORDER BY added_date, last_name, first_name"; $mode = "student"; break; } } $pwhere = "AND p.people_type IN ('Staff','Student','Customer') "; if (isset($show) && $show == "All") $pwhere = ""; unset($delivered); if (array_key_exists('delivered',$_GET) && strlen($_GET['delivered'])) $delivered = $_GET['delivered']; if (array_key_exists('delivered',$_POST) && strlen($_POST['delivered'])) $delivered = $_POST['delivered']; $dwhere = ""; if (isset($delivered)) { $dwhere = "AND delivered = '$delivered' "; if ($delivered == 'Y') $ReportTitle .= " - " . getLanguageText('TEXT-DELIVERED'); else $ReportTitle .= " - " . getLanguageText('TEXT-NOT-DELIVERED'); } $show_where = ""; if (isset($show_status) && strlen($show_status)) $show_where = "AND hloh.status = '$show_status' "; // Get orders for this schedule $query = "SELECT p.last_name,p.first_name,class_num,sequence,people_type,hloh.price_category,hloh.order_total,hloh.status,p.user_num,hloh.record_num,userid,hloh.payment_method,hloh.added_date,sum(ua.transaction_amount) as balance,delivered " . "FROM people AS p LEFT JOIN classes AS c ON p.class_num = c.record_num, hotlunch_order_header AS hloh, " . "users AS u LEFT JOIN user_account AS ua ON ua.school_num = $school_num AND ua.user_num = u.record_num AND (ua.deleted != 'Y' OR ua.deleted IS NULL) " . "WHERE p.school_num = $base_school_num " . "AND hloh.school_num = $school_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "AND p.record_num = hloh.ordered_by_num " . $pwhere . $dwhere . $show_where . "AND hloh.schedule_num = $schedule_num " . "AND p.user_num = u.record_num " . "GROUP BY 1,2,3,4,5,6,7,8,9,10,11 " . $orderby; $results = db_query($query); if (db_num_rows($results) == 0) { echo($query); exit(); header("Location: /?error_code=NOORDERS"); exit(); } $curr_row = $max_rows + 1; $page = 1; // Process all the orders found for this page while ($row = db_fetch_array($results)) { if ($curr_row > $max_rows) { if ($page > 1) $pdf->addPage(); $curr_row = $start_row; $pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc")); $pdf->SetFont($document_font,"B",$document_font_size + 1); $pdf->SetXY($title_col,$curr_row); $pdf->Cell(260,$incr,$ReportTitle,'0',1,'L',true,'',1); $curr_row += $incr + 2; $page++; $count = 0; $pdf->SetXY($title_col,$curr_row); $pdf->SetFont($document_font,"",$document_font_size); // Titles $cnum = 0; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,getLanguageText('TEXT-NAME'),'0',1,'L',true,'',1); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,getLanguageText('TEXT-TYPE'),'0',1,'L',true,'',1); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,getLanguageText('TEXT-ORDER')." ",'0',1,'R',true,'',1); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); switch ($mode) { case 'account': $pdf->Cell($width,$incr,getLanguageText('TEXT-ACCOUNT'),'0',1,'L',true,'',1); break; case 'student-class': $pdf->Cell($width,$incr,$GlobalText['Class'],'0',1,'L',true,'',1); break; case 'student': $pdf->Cell($width,$incr,getLanguageText('TEXT-ACCOUNT'),'0',1,'L',true,'',1); break; } $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,getLanguageText('TEXT-CATEGORY'),'0',1,'L',true,'',1); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,getLanguageText('TEXT-STATUS'),'0',1,'L',true,'',1); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,getLanguageText('TEXT-ORDER-DATE'),'0',1,'L',true,'',1); $curr_row += $incr; } $name = $row['last_name'] . ', ' . $row['first_name']; $pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee")); $bg = true; if ($count % 2) $bg = false; $cnum = 0; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$name,'0',1,'L',$bg,'',1); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$row['people_type'],'0',1,'L',$bg,'',1); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$school_record['currency_symbol'] . number_format($row['order_total'],2) . " ",'0',1,'R',$bg,'',1); $total += $row['order_total']; // Display account or name depending on sort order switch ($mode) { case 'account': $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$row['userid'],'0',1,'L',$bg,'',1); break; case 'student-class': // Get the class info $class = $row['class_num']; $class_info = getClassInfo($class,'internal'); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$class_info,'0',1,'L',$bg,'',1); break; case 'student': // Get the name on this account $unum = $row['user_num']; $uname = db_getVal("select concat(first_name,' ',last_name) from users where school_num = $base_school_num and record_num = $unum"); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$uname,'0',1,'L',$bg,'',1); break; } // $cnum++; // $curr_col = $columns[$cnum]; // $width = $columns[$cnum + 1] - $columns[$cnum]; // $pdf->SetXY($curr_col,$curr_row); // $pdf->Cell($width,$incr,$school_record['currency_symbol'] . number_format($row['balance'],2) . " ",'0',1,'R',$bg,'',1); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$row['price_category'],'0',1,'L',$bg,'',1); $dtext = ""; if (isset($hotlunch_schedule['schedule_type']) && $hotlunch_schedule['schedule_type'] != 'Hot Lunch' && in_array($siteType,array('hotlunch','yearbook','tickets','fundraising'))) { $dtext = " (" . $row['delivered'] . ")"; } $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$row['status'].' - '.$row['payment_method'] . $dtext,'0',1,'L',$bg,'',1); $cnum++; $curr_col = $columns[$cnum]; $width = $columns[$cnum + 1] - $columns[$cnum]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,dateString('date',strtotime($row['added_date'])),'0',1,'L',$bg,'',1); $curr_row += $incr; $count++; } // Total $pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc")); $pdf->SetFont($document_font,"B",$document_font_size); $pdf->SetXY($title_col,$curr_row); $pdf->Cell(260,$incr," ",'0',1,'L',true,'',1); $width = $columns[1] - $columns[0]; $curr_col = $columns[0]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,"Total:",'0',1,'R',true,'',1); $width = $columns[3] - $columns[2]; $curr_col = $columns[2]; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$school_record['currency_symbol'] . number_format($total,2) . " ",'0',1,'R',true,'',1); // Output the completed PDF $filename = "order-summary.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"); ?>