Files
HotLunches/payments.print.php
2026-10-19 15:22:52 -07:00

263 lines
7.4 KiB
PHP

<?php
$ValidAccess = 2010;
require_once("include/globals.php");
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
$action = '';
$naction = '';
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
exit();
}
$batch_num = 0;
if (array_key_exists('batch_num',$_GET)) $batch_num = intval($_GET['batch_num']);
$school_name = $school_record['school_name'];
$report_title = "Hot Lunches On-Line: Deposit Report - " . date("F j, Y",time());
$document_name = "Deposit Report";
// Set the deposit date for unclosed batches
$deposit_date = date("Y-m-d",time());
//
// 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;
// Setup parameters for this document
$max_rows = 250;
$title_width = 180;
$left_col = 10;
$start_row = 10;
$curr_row = $start_row;
$incr = 4;
//
// 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 + 5;
class PDF extends TCPDF {
function Header() {
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title, $report_subtitle;
$report_subtitle = "Account: 9993 5226831";
// Print the header
$this->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$this->SetFont($document_font,"B",$document_font_size + 1);
$this->SetXY($left_col,$start_row);
$this->Cell($title_width,$incr + 1,$report_title,'0',1,'L',true);
if (isset($report_subtitle) && strlen($report_subtitle) > 0) {
$this->SetXY($left_col,$start_row + $incr + 2);
$this->Cell($title_width,$incr + 1,$report_subtitle,'0',1,'L',true);
}
}
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('P', '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);
$pdf->addPage();
//
// Get set of payments for deposit
//
$query = "select * from invoice_payments where batch_num = $batch_num " .
"order by currency,entered";
$payments = db_query($query);
//
// Generate the report
//
$col1 = $left_col;
$col1_width = 150;
$col2 = $col1 + $col1_width;
$col2_width = 30;
$col3 = $col2 + $col2_width;
$col3_width = 40;
$col4 = $col3 + $col3_width;
$col4_width = 30;
$curr_row = $start_row + 3 * $incr;
$count = 0;
$prev_currency = "";
$items = 0;
$total_items = 0;
$cheque_name = '';
$cheque_amount = 0;
while ($row = db_fetch_array($payments)) {
extract($row);
if ($batch_num > 0) $deposit_date = $batch_closed_date;
if ($currency != $prev_currency) {
$pdf->SetFont($document_font,"B",$document_font_size);
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
if ($total > 0) {
$pdf->SetXY($col1,$curr_row);
$pdf->Cell($col1_width,$incr,"TOTAL - $items Items:",'1',1,'L',true);
if ($prev_currency == 'GBP') $total = number_format($total,2) . " $prev_currency";
else $total = "$" . number_format($total,2) . " $prev_currency";
$pdf->SetXY($col2,$curr_row);
$pdf->Cell($col2_width,$incr,$total,'1',1,'R',true);
$curr_row += $incr * 2;
}
$curr_row += $incr;
$pdf->SetXY($col1,$curr_row);
switch ($currency) {
case 'CAD':
$pdf->Cell($title_width,$incr,"Canadian Cheques",'1',1,'L',true);
break;
case 'USD':
$pdf->Cell($title_width,$incr,"US Cheques",'1',1,'L',true);
break;
case 'GBP':
$pdf->Cell($title_width,$incr,"British Cheques",'1',1,'L',true);
break;
}
$count = 0;
$items = 0;
$total = 0;
$prev_currency = $currency;
$curr_row += $incr;
}
$pdf->SetFont($document_font,"",$document_font_size);
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$fill = true;
if ($count % 2) $fill = false;
$count++;
$school_name = db_getVal("SELECT school_name FROM schools WHERE record_num = $school_num");
if (strlen($cheque_name)) $cheque_name .= ", ";
$cheque_name .= $school_name;
$cheque_amount += $amount;
if ($group_with_next != 'Y') {
$pdf->SetXY($col1,$curr_row);
$pdf->Cell($col1_width,$incr,$cheque_name,'1',1,'L',$fill);
// Format the amount
$total += $cheque_amount;
if ($currency == 'GBP') $amount = number_format($cheque_amount,2) . " $currency";
else $amount = "$" . number_format($cheque_amount,2) . " $currency";
$pdf->SetXY($col2,$curr_row);
$pdf->Cell($col2_width,$incr,$amount,'1',1,'R',$fill);
$curr_row += $incr;
$items++;
$total_items++;
$cheque_name = '';
$cheque_amount = 0;
}
}
if ($total > 0) {
$pdf->SetFont($document_font,"B",$document_font_size);
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetXY($col1,$curr_row);
$pdf->Cell($col1_width,$incr,"TOTAL - $items Items:",'1',1,'L',true);
if ($prev_currency == 'GBP') $total = number_format($total,2) . " $prev_currency";
else $total = "$" . number_format($total,2) . " $prev_currency";
$pdf->SetXY($col2,$curr_row);
$pdf->Cell($col2_width,$incr,$total,'1',1,'R',true);
$curr_row += $incr * 2;
}
// Total items for deposit
$pdf->SetXY($col1,$curr_row);
$pdf->Cell(50,$incr,"TOTAL ITEMS: $total_items",'1',1,'L',true);
$filename = "deposit.hl.".$deposit_date.".pdf";
// 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=$filename");
$pdf->Output($filename,"D");
?>