'userid', 'title' => getLanguageText('TEXT-USER-ID'), 'col' => 8, 'total' => 'N', 'format' => 'text', 'align' => 'L'), array('fname' => 'trx_date', 'title' => getLanguageText('TEXT-DATE'), 'col' => 50, 'total' => 'N', 'format' => 'text', 'align' => 'L'), array('fname' => 'transaction_type', 'title' => getLanguageText('TEXT-TYPE'), 'col' => 70, 'total' => 'N', 'format' => 'text', 'align' => 'L'), array('fname' => 'transaction_status', 'title' => getLanguageText('TEXT-STATUS'), 'col' => 100, 'total' => 'N', 'format' => 'text', 'align' => 'L'), array('fname' => 'account', 'title' => getLanguageText('TEXT-ACCOUNT'), 'col' => 120, 'total' => 'N', 'format' => 'text', 'align' => 'L'), array('fname' => 'name', 'title' => getLanguageText('TEXT-NAME'), 'col' => 160, 'total' => 'N', 'format' => 'text', 'align' => 'L'), array('fname' => 'amt', 'title' => getLanguageText('TEXT-AMOUNT'), 'col' => 200, 'total' => 'Y', 'format' => 'currency', 'align' => 'R'), array('fname' => '', 'title' => '', 'col' => 225, 'align' => 'L'), array('fname' => 'method', 'title' => getLanguageText('TEXT-METHOD'), 'col' => 230, 'total' => 'N', 'format' => 'text', 'align' => 'L'), array('fname' => 'pamt', 'title' => getLanguageText('TEXT-PAYMENT'), 'col' => 245, 'total' => 'Y', 'format' => 'currency', 'align' => 'R'), array('fname' => 'End Of Row', 'col' => 265, 'align' => 'C'), ); $start_row = 25; $curr_row = $max_rows + 10; $incr = 4; $document_name = getLanguageText('TEXT-TRANSACTION-DETAIL-REPORT'); // // 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']; $report_subtitle = ''; if (array_key_exists('selected_schedule_num',$_GET) && intval($_GET['selected_schedule_num']) > 0) { $snum = $_GET['selected_schedule_num']; $report_subtitle = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $snum"); $report_subtitle .= ": "; } $report_subtitle .= $_GET['start_date'] . " - " . $_GET['end_date']; $query = $_GET['query']; if (stripos("update",$query) !== FALSE) exit(); if (stripos("insert",$query) !== FALSE) exit(); if (stripos("delete",$query) !== FALSE) exit(); if (!preg_match("/^select /i",$query)) exit(); if (preg_match("/select .*select/i",$query)) exit(); $transactions = db_query($query); $pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee")); $page = 0; $prev_trx = 0; $totals = array(); $count = 0; while ($row = db_fetch_array($transactions)) { if ($curr_row > ($max_rows - $incr * 2)) { // Put page titles on the page whenever a page is full if ($page > 0) $pdf->addPage(); $curr_row = 8; $pdf->SetFont($document_font,"B",$document_font_size + 2); $pdf->SetXY(10,$curr_row); $pdf->Cell(250,$incr,"$school_name :: $document_name",'0',1,'L',false,'',1); if (strlen($report_subtitle)) { $curr_row += $incr + 1; $pdf->SetXY(10,$curr_row); $pdf->Cell(250,$incr,$report_subtitle,'0',1,'L',false,'',1); } $curr_row += $incr + 4; $pdf->SetFont($document_font,"B",$document_font_size); $pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc")); for ($cnum = 0; $cnum < count($columns) - 1; $cnum++) { $curr_col = $columns[$cnum]['col']; $width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col']; $title = $columns[$cnum]['title']; $align = $columns[$cnum]['align']; $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$title,'0',1,$align,true,'',1); } $pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee")); $pdf->SetFont($document_font,"",$document_font_size); $curr_row += $incr; $page++; } $bg = false; if ($count % 2) $bg = true; $count++; // Format output $row['account'] = $row['first_name'] . ' ' . $row['last_name']; $pnum = $row['people_num']; $row['name'] = ''; if ($pnum > 0) $row['name'] = db_getVal("SELECT concat_ws(' ',first_name,last_name) FROM people WHERE school_num = $base_school_num AND record_num = $pnum"); $row['method'] = $row['payment_method']; if (strlen($row['method']) == 0) $row['method'] = $row['transaction_type']; if ($row['method'] == 'Check') $row['method'] .= " #" . $row['payment_reference']; $row['amt'] = $row['transaction_amount']; $row['method'] = ''; $row['pamt'] = ''; // Get user_account_detail records $unum = $row['user_num']; $rnum = $row['record_num']; $query = "SELECT * FROM user_account_detail WHERE school_num = $school_num AND user_num = $unum AND posted_to_transaction = $rnum"; $details = db_query($query); if (db_num_rows($details)) { while ($drow = db_fetch_assoc($details)) { $ptrxNum = $drow['transaction_num']; $row['pamt'] = $drow['posted_amount']; if (abs($drow['posted_amount']) < 0.01) continue; $row['method'] = db_getVal("SELECT payment_method FROM user_account WHERE school_num = $school_num AND record_num = $ptrxNum"); if (strlen($row['method']) == 0) $row['method'] = db_getVal("SELECT transaction_type FROM user_account WHERE school_num = $school_num AND record_num = $ptrxNum"); for ($cnum = 0; $cnum < count($columns) - 1; $cnum++) { $curr_col = $columns[$cnum]['col']; $width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col']; $fname = $columns[$cnum]['fname']; $align = $columns[$cnum]['align']; $pdf->SetXY($curr_col,$curr_row); if (strlen($fname)) { $text = isset($row[$fname]) ? $row[$fname] : ''; if ($columns[$cnum]['format'] == 'currency' && $text !== '') $text = formatCurrency($text); $pdf->Cell($width,$incr,$text,'0',1,$align,$bg,'',1); } else $pdf->Cell($width,$incr,' ','0',1,$align,$bg,'',1); if (isset($columns[$cnum]['total']) && $columns[$cnum]['total'] == 'Y') { if (!isset($totals[$cnum])) $totals[$cnum] = 0; if (isset($row[$fname]) && is_numeric($row[$fname])) $totals[$cnum] += floatval($row[$fname]); } } $row = array(); $curr_row += $incr; } } else { for ($cnum = 0; $cnum < count($columns) - 1; $cnum++) { $curr_col = $columns[$cnum]['col']; $width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col']; $fname = $columns[$cnum]['fname']; $align = $columns[$cnum]['align']; $pdf->SetXY($curr_col,$curr_row); if (strlen($fname)) { $text = isset($row[$fname]) ? $row[$fname] : ''; if ($columns[$cnum]['format'] == 'currency' && $text !== '') $text = formatCurrency($text); $pdf->Cell($width,$incr,$text,'0',1,$align,$bg,'',1); } else $pdf->Cell($width,$incr,' ','0',1,$align,$bg,'',1); if (isset($columns[$cnum]['total']) && $columns[$cnum]['total'] == 'Y') { if (!isset($totals[$cnum])) $totals[$cnum] = 0; if (isset($row[$fname]) && is_numeric($row[$fname])) $totals[$cnum] += floatval($row[$fname]); } } $curr_row += $incr; } } $pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc")); $pdf->SetFont($document_font,"B",$document_font_size); for ($cnum = 0; $cnum < count($columns) - 1; $cnum++) { $curr_col = $columns[$cnum]['col']; $width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col']; $align = $columns[$cnum]['align']; $text = ""; if (isset($columns[$cnum]['total']) && $columns[$cnum]['total'] == 'Y') { $text = isset($totals[$cnum]) ? $totals[$cnum] : 0; if (isset($columns[$cnum]['format']) && $columns[$cnum]['format'] == 'currency') $text = formatCurrency($text); } $pdf->SetXY($curr_col,$curr_row); $pdf->Cell($width,$incr,$text,'0',1,$align,true,'',1); } // 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=account-transactions.pdf"); header('Content-Transfer-Encoding: binary'); $pdf->Output("account-transactions.pdf","D"); return; ?>