I want to print a class bill and i keep getting:
TCPDF ERROR: Wrong page number on setPage() function
Below is my code:
<?php
ob_start();
require_once '../includes/header.php';
require_once '../tcpdf/tcpdf.php';
require_once '../classes/InstitutionDetail.php';
require_once '../classes/ClassMembership.php';
require_once '../classes/Pupil.php';
require_once '../classes/Admission.php';
require_once '../classes/User.php';
require_once '../classes/Photo.php';
require_once '../classes/Bill.php';
require_once '../classes/Payments.php';
confirm_logged_in();
$institutionDetail = new InstitutionDetail();
$classMembership = new ClassMembership();
$pupil = new Pupil();
$admission = new Admission();
$user = new User();
$photo = new Photo();
$bill = new Bill();
$payment = new Payments();
$getUserDetails = $user->getUserByUsername($_SESSION["username"]);
$splitAccessPages = explode("//", $getUserDetails["access_pages"]);
for ($i = 0; $i < count($splitAccessPages); $i++) {
if (!in_array("print_class_bills", $splitAccessPages, TRUE)) {
redirect_to("logout_access.php");
}
}
//$getAcademicTerm = $academicTerm->getActivatedTerm();
//$get_academic_term = $getAcademicTerm["academic_year"] . "/" . $getAcademicTerm["term"];
if (!isset($_SESSION["chosen_term"], $_SESSION["selected_class_name"])) {
// redirect_to("student_bill.php");
$_SESSION["chosen_term"] = "";
$_SESSION["selected_class_name"] = "";
}
$getInstitutionDetail = $institutionDetail->getInstitutionDetails();
$getSchool_name = $getInstitutionDetail["school_name"];
$getSchoolMotor = $getInstitutionDetail["school_motor"];
$getPostalAddress = $getInstitutionDetail["postal_address"];
$getTelephoneNumbers = $getInstitutionDetail["telephone_1"] . " " . $getInstitutionDetail["telephone_2"] . " " . $getInstitutionDetail["telephone_3"];
class MYPDF extends TCPDF {
//Page header
public function Header() {
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-90);
// Set font
$this->SetFont('helvetica', '', 8);
// Page number
// date_default_timezone_set("Africa/Accra");
// $this->Cell(0, 10, date("d/m/Y h:i:sa") . " " . 'Page ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
$takeNote = "<strong><u>FOOTNOTES:</u></strong>";
$divSaparatefoot = '<div style="width:auto; background-color:mintcream; height:25px; border-bottom:3px solid #ddd;padding-bottom:3px;">'.'</div>';
// $horizontalLine = "<hr style=background:burlywood; height: 5px; />";
$space = "<p></p>";
$msg = "1. When <strong>Total Fees</strong> indicate <strong>credit</strong>, it means that, the school owes the student the said amount.";
$info = "2. All fees must be paid on or before the <strong>re-opening date</strong>.";
$bankNote = "<strong>Bankers:</strong>";
$company = "<strong><em>Software by ANIDROL GHANA:+233 26-764-2898 /+233 24-774-5156</em></strong>";
$institutionDetail = new InstitutionDetail();
$getInstitutionDetail = $institutionDetail->getInstitutionDetails();
$getBank_1 = "1. <strong>" . $getInstitutionDetail["bank_1"] . "</strong> Branch: <strong>" . $getInstitutionDetail["bank_1_branch"] . "</strong> Account Number: <strong>" . $getInstitutionDetail["bank_1_account_number"] . "<strong>";
$getBank_2 = "2. <strong>" . $getInstitutionDetail["bank_2"] . "</strong> Branch: <strong>" . $getInstitutionDetail["bank_2_branch"] . "</strong> Account Number: <strong>" . $getInstitutionDetail["bank_2_account_number"] . "<strong>";
$getBank_3 = "3. <strong>" . $getInstitutionDetail["bank_3"] . "</strong> Branch: <strong>" . $getInstitutionDetail["bank_3_branch"] . "</strong> Account Number: <strong>" . $getInstitutionDetail["bank_3_account_number"] . "<strong>";
$this->writeHTML($divSaparatefoot, true, 0, true, 0);
$this->writeHTML($takeNote, true, 0, true, 0);
$this->writeHTML($space, true, 0, true, 0);
$this->writeHTML($msg, true, 0, true, 0);
$this->writeHTML($info, true, 0, true, 0);
$this->writeHTML($space, true, 0, true, 0);
$this->writeHTML($bankNote, true, 0, true, 0);
$this->writeHTML($getBank_1, true, 0, true, 0);
$this->writeHTML($getBank_2, true, 0, true, 0);
$this->writeHTML($getBank_3, true, 0, true, 0);
$this->writeHTML($company, true, 0, true, 0, 'R');
}
}
$pdf = new MYPDF("", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set some language-dependent strings (optional)
if (#file_exists(dirname(__FILE__) . "/lang/eng.php")) {
require_once(dirname(__FILE__) . "/lang/eng.php");
$pdf->setLanguageArray($l);
}
// set font
$pdf->SetFont('times', '', 11);
$getClassStudentById = $classMembership->getClassStudentsById($_SESSION["chosen_term"], $_SESSION["selected_class_name"]);
foreach ($getClassStudentById as $value) {
$pdf->startPageGroup();
$pdf->AddPage();
$pdf->setJPEGQuality(75);
$getSingleBillAmount = $bill->getSingleBillingAmount($value["pupil_id"]);
$singleBillAmount = $getSingleBillAmount["billAmount"];
$getTermFees = $bill->getTermFees($value["pupil_id"], $_SESSION["chosen_term"]);
$getPTAAll = $bill->getPTAFeesAll($value["pupil_id"]);
// $termFeesOnly = number_format($getTermFees["termFees"], 2, ".", ",");
$getPTA = $bill->getPTAFees($value["pupil_id"], $_SESSION["chosen_term"]);
$termFees = number_format(($getTermFees["termFees"] + $getPTA["ptaFees"]), 2, ".", ",");
if ($termFees <= 0) {
if ($termFees == 0) {
$termFeesFormated = "";
} else {
$termFeesFormated = "GH¢" . str_replace("-", "", $termFees) . " Credit";
}
} else {
$termFeesFormated = "GH¢" . $termFees;
}
$getFeesPayable = $bill->getStudentAccount($value["pupil_id"]);
$getTotalFeesPaid = $bill->getTotalFeesPaid($value["pupil_id"]);
$getPTAFeesPaid = $bill->getPTAFeesPaid($value["pupil_id"]);
// $getBalance = number_format((($getFeesPayable["allFeesPayable"] + $singleBillAmount + $getPTAAll["ptaFeesAll"]) - ($getTotalFeesPaid["allFeesPaid"])), 2, ".", ",");
$getBalance = number_format((($getFeesPayable["allFeesPayable"] + $singleBillAmount + $getPTAAll["ptaFeesAll"]) - ($getTotalFeesPaid["allFeesPaid"] + $getPTAFeesPaid["ptaFeesPaid"] + $termFees)), 2, ".", ",");
if ($getBalance <= 0) {
if ($getBalance == 0) {
$balanceBroughtForward = "-";
} else {
$balanceBroughtForward = "GH¢" . str_replace("-", "", $getBalance) . " Credit";
}
} else {
$balanceBroughtForward = "GH¢" . $getBalance . " Debit";
}
// $totalFees = number_format(((($getFeesPayable["allFeesPayable"] - $getTotalFeesPaid["allFeesPaid"]) + $singleBillAmount) + $termFees), 2, ".", ",");
$totalFees = number_format((($getFeesPayable["allFeesPayable"] + $singleBillAmount + $getPTAAll["ptaFeesAll"] + $termFees) - ($getTotalFeesPaid["allFeesPaid"] + $getPTAFeesPaid["ptaFeesPaid"] + $termFees)), 2, ".", ",");
if ($totalFees <= 0) {
if ($totalFees == 0) {
$balanceCarriedForward = "-";
} else {
$balanceCarriedForward = "GH¢" . str_replace("-", "", $totalFees) . " Credit";
}
} else {
$balanceCarriedForward = "GH¢" . $totalFees;
}
// table
$getStudentPhoto = $photo->getPhotoById($value["pupil_id"]);
$studentPhoto = "../" . $getStudentPhoto["photo_url"];
$getLogoID = $photo->getSchoolLogoID();
$getSchoolLogo = $photo->getSchoolLogo($getLogoID["logo_id"]);
$schoolLogo = "../" . $getSchoolLogo["photo_url"];
$heading = "<span>GHANA EDUCATION SERVICE</span>"
. "<h1>" . $getSchool_name . "</h1>"
. "<span>" . $getPostalAddress . "</span><br />"
. "<span>" . $getTelephoneNumbers . "</span>";
$pdf->Image($studentPhoto, 155, 60, 35, 35, '', '', '', true, 150, '', false, false, 0, false, false, false);
$pdf->Image($schoolLogo, 5, 7, 34, 37, '', '', '', true, 150, '', false, false, 0, false, false, false);
$tbl_head_heading = '<table cellspacing = "0" cellpadding = "5">';
$tbl_foot_heading = '</table>';
$tbl_heading = '';
$tbl_heading .= '
<tbody>
<tr>
<td style="text-align: center; background-color: #666; color: #fff;" colspan="4">' . $heading . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_heading . $tbl_heading . $tbl_foot_heading, true, false, true, false, '');
$className ='<div style="width:auto; background-color:grey;">'.'<b>'. '<strong style="color:#fff; font-size:12px">'. htmlentities(strtoupper($_SESSION["chosen_term"] . " " . "Term Student Bill")) . '</strong>'.'</b>'.'</div>';
$pdf->writeHTML($className, true, 0, true, 0, 'C');
// $horizontalLineII = '<hr style="">'.'</hr>';
$divSaparate = '<div style="width:auto; background-color:mintcream; height:25px; border-bottom:3px solid #ddd;padding-bottom:3px;">'.'</div>';
$pdf->writeHTML($divSaparate);
//$pdf->writeHTML($horizontalLineII);
$headingSpace = "<div></div>";
$pdf->writeHTML($headingSpace, true, 0, true, 0);
//$horizontalLine = "<hr style='background-color:burlywood; height: 5px;'>"."</hr>";
$divSaparateLine = '<div style="width:auto; background-color:mintcream; height:25px; border-bottom:3px solid #ddd;padding-bottom:3px;">'.'</div>';
$getStudentData = $pupil->getPupilById($value["pupil_id"]);
$getStudentName = $getStudentData["other_names"] . " " . $getStudentData["family_name"];
$getStudentID = $getStudentData["pupil_id"];
$getGender = $getStudentData["sex"];
$getBoardingStatus = $value["boarding_status"];
$getClassName = $value["class_name"];
$tbl_head_title = '<table cellspacing = "10" cellpadding = "0" border = "0">';
$tbl_foot_title = '</table>';
$tbl_title = '';
$tbl_title .= '
<tbody>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Name:</strong></td>
<td style="text-align: left; font-weight:bold;margin:5px; border-bottom:1.5px solid #ddd;padding-bottom:3px;">' . $getStudentName . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>ID Number:</strong></td>
<td style="text-align: left; border-bottom:1.5px solid #ddd;padding-bottom:3px; width:100px;">' . $getStudentID . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%; "><strong>Gender:</strong></td>
<td style="text-align: left; border-bottom:1.5px solid #ddd;padding-bottom:3px; width:100px;">' . $getGender . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Status:</strong></td>
<td style="text-align: left; border-bottom:1.5px solid #ddd;padding-bottom:3px; width:100px;">' . $getBoardingStatus . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Class:</strong></td>
<td style="text-align: left; font-weight:bold; border-bottom:1.5px solid #ddd;padding-bottom:3px; width:100px;">' . $getClassName . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Balance b/f:</strong></td>
<td style="text-align: left;">' . $balanceBroughtForward . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Term Fees:</strong></td>
<td style="text-align: left;">' . $termFeesFormated . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Total Fees:</strong></td>
<td style="text-align: left;">' . $balanceCarriedForward . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_title . $tbl_title . $tbl_foot_title, FALSE, false, true, false, '');
$pdf->writeHTML($divSaparateLine, true, 0, true, 0);
// list of bill items
$tbl_head_description = '<table cellspacing = "2" cellpadding = "5" border = "0">';
$tbl_foot_description = '</table>';
$tbl_description = '';
$tbl_description .= '
<tbody>
<tr style="color: #000;">
<td style="width: 8.5%;"> </td>
<td style="width: 67%; text-align: left;">' . "<strong>BILL ITEMS</strong>" . '</td>
<td style="text-align: right; width: 16%;">' . "<strong>GH¢</strong>" . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_description . $tbl_description . $tbl_foot_description, FALSE, false, true, false, '');
$classBillItemsForStudent = $bill->getClassBillForStudent($value["class_name"], $_SESSION["chosen_term"]);
foreach ($classBillItemsForStudent as $classBillItemStudent) {
if ($getBoardingStatus === "Day Student") {
$schoolFees = $classBillItemStudent["day_amount"];
} else {
$schoolFees = $classBillItemStudent["boarding_amount"];
}
$tbl_head_item = '<table cellspacing = "1" cellpadding = "0" border = "0">';
$tbl_foot_item = '</table>';
$tbl_item = '';
$tbl_item .= '
<tbody>
<tr style="color: #000;">
<td style="width: 10%;"> </td>
<td style="width: 70%;">' . $classBillItemStudent["bill_item"] . '</td>
<td style="text-align: right; width: 10%;">' . number_format($schoolFees, 2, ".", ",") . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_item . $tbl_item . $tbl_foot_item, FALSE, false, true, false, '');
}
if ($getGender === "Male") {
$classBillItemsForMale = $bill->getClassBillForMale($value["class_name"], $_SESSION["chosen_term"]);
foreach ($classBillItemsForMale as $classBillItemMale) {
if ($getBoardingStatus === "Day Student") {
$schoolFeesMale = $classBillItemMale["day_amount"];
} else {
$schoolFeesMale = $classBillItemMale["boarding_amount"];
}
$tbl_head_item = '<table cellspacing = "1" cellpadding = "0" border = "0">';
$tbl_foot_item = '</table>';
$tbl_item = '';
$tbl_item .= '
<tbody>
<tr style="color: #000;">
<td style="width: 10%;"> </td>
<td style="width: 70%;">' . $classBillItemMale["bill_item"] . '</td>
<td style="text-align: right; width: 10%;">' . number_format($schoolFeesMale, 2, ".", ",") . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_item . $tbl_item . $tbl_foot_item, FALSE, false, true, false, '');
}
} else {
$classBillItemsForFemale = $bill->getClassBillForFemale($value["class_name"], $_SESSION["chosen_term"]);
foreach ($classBillItemsForFemale as $classBillItemFemale) {
if ($getBoardingStatus === "Day Student") {
$schoolFeesFemale = $classBillItemFemale["day_amount"];
} else {
$schoolFeesFemale = $classBillItemFemale["boarding_amount"];
}
$tbl_head_item = '<table cellspacing = "1" cellpadding = "0" border = "0">';
$tbl_foot_item = '</table>';
$tbl_item = '';
$tbl_item .= '
<tbody>
<tr style="color: #000;">
<td style="width: 10%;"> </td>
<td style="width: 70%;">' . $classBillItemFemale["bill_item"] . '</td>
<td style="text-align: right; width: 10%;">' . number_format($schoolFeesFemale, 2, ".", ",") . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_item . $tbl_item . $tbl_foot_item, FALSE, false, true, false, '');
//$get_term_from_session = $_SESSION["chosen_term"];
//$get_session_class = $_SESSION["selected_class_name"];
// $get_class_memebership = $classMembership ->getClassMembersByClassName($_SESSION["selected_class_name"]);
//
// if( $get_class_memebership){
//
// }
$getTotalBillForClass = $bill ->getTotalStudentCharges( $_SESSION["selected_class_name"],$_SESSION["chosen_term"]);
$tbl_head_itema = '<table cellspacing = "1" cellpadding = "0" border = "0">';
$tbl_foot_itema = '</table>';
$tbl_itema = '';
$tbl_itema.= '
<tbody>
<tr style="color: #000;">
<td style="width: 10%;"> </td>
<td style="width: 70%;">' . 'TOTAL:' . '</td>
<td style="text-align: right; width: 10%;">' . number_format($getTotalBillForClass, 2, ".", ",") . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_itema . $tbl_itema . $tbl_foot_itema, FALSE, false, true, false, '');
}
}
}
$pdf->lastPage();
ob_end_clean();
$pdf->Output();
Any time i try to generate a bill i keep getting that error and i dont know where i am wrong too...Can any body please help...
Related
When reading and displaying data which is in cyrilic from a Microsoft SQL Server, PHP fails to display it correctly. You can see part of the text displayed (only the non cyrilic stuff)
Here is what I have tried:
setting the values in the table nchar, varchar, text and char
adding a utf-8 tag in the html code
using the PHP driver for SQL with the ODBC driver
tried these collations: Cyrillic_General_100_CI_AI_SC_UTF8, cyrillic general with utf-8 and the windows code page (1251) with cyrillic general
<html>
<style>
table { width: 20em; border-collapse: collapse; }
th {
border-bottom: 2px solid #000;
padding: 0.5em 0 0.1em 0;
font-size: 1.2em;
}
td {
border-bottom: 2px solid #ccc;
padding: 0.5em 0 0.1em 0;
}
th:nth-child(n + 2),
td:nth-child(n + 2) {
text-align: center;
}
[data-has-link="no"] { background-color: #F77; }
[data-has-link="yes"] { background-color: #7F7; }
#score, #name { width: 50%; }
</style>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="jo.js"></script>
<title>AV.31.U</title>
</head>
<body>
<table style="width: 100%; height:50%" border="1" cellpadding="3">
<caption>AV.31.U</caption>
<thead>
<tr>
<td><div id="current_date"></p>
<script>
$(function() {
var $table = $('table');
$table.find('#current_date').text(getCurrentDate());
colorRows($table); // Color the rows!
});
function getCurrentDate () {
return new Date().toLocaleDateString('en-GB', {
year: 'numeric',
month: 'numeric',
day: 'numeric'
});
}
function colorRows($table) {
var hasLink;
$table.find('tbody > tr').each(function(rowIndex) {
const $row = $(this);
$row.find('td').each(function(colIndex) {
const $cell = $(this).removeAttr('data-has-link');
const cellValue = $cell.text().trim();
if (isFinite(cellValue)) {
// Color cell based on individual data
const hasLink = cellHasLink(parseInt(cellValue, 10));
if (hasLink !== 'maybe') {
$cell.attr('data-has-link', hasLink);
}
}
});
// Color row based on 7th column
var i = parseInt($row.find('td:nth-child(7)').text(), 10);
$row.attr('data-has-link', cellHasLink(i));
});
}
function cellHasLink(value) {
switch (value) {
case 0 : return 'no';
case 1 : return 'yes';
default : return 'maybe';
}
}
</script></td>
<td colspan="6">Home</td>
<td> </td>
</tr>
<tr>
<th>Наименование</th>
<th>Описание</th>
<th>Версия</th>
<th>Верс. опис.</th>
<th>Модел</th>
<th>Видео</th>
<th>Видео отвори</th>
<th>Снимк.</th>
<th>Снимк. отвори</th>
<th>Специф.</th>
<th>Специф. отвори</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$username = 'censored';
$password = 'censored';
$servername = 'censored';
$database = 'SQL_KASI';
ini_set('display_errors', '1');
error_reporting(E_ALL);
$db = odbc_connect("Driver={SQL Server};Server=$servername;Database=$database;", $username, $password) or die ("could not connect<br />");
$stmt = "Select * from machine_vertical";
$result = odbc_exec($db, $stmt);
if ($result == FALSE) die ("could not execute statement $stmt<br />");
while (odbc_fetch_row($result)) // while there are rows
{
print "<tr>\n";
print " <td>" . odbc_result($result, "mach_name") . "\n";
print " <td>" . odbc_result($result, "mach_descr") . "\n";
print " <td>" . odbc_result($result, "mach_version") . "\n";
print " <td>" . odbc_result($result, "mach_version_descr") . "\n";
print " <td>" . odbc_result($result, "mach_model") . "\n";
print " <td>" . odbc_result($result, 'mach_video_yn') . "\n";
print " <td>" . odbc_result($result, "mach_video_open") . "\n";
print " <td>" . odbc_result($result, "mach_pic_yn") . "\n";
print " <td>" . odbc_result($result, 'mach_pic_open') . "\n";
print " <td>" . odbc_result($result, "mach_spec_yn") . "\n";
print " <td>" . odbc_result($result, "mach_spec_open") . "\n";
print "</tr>\n";
}
odbc_free_result($result);
odbc_close($db);
?>
</tr>
</tbody>
</table>
</body>
</html>
How to copy a certain tcpdf page to a new tcpdf object? Below is my scenario.
I have a php script which loops 50 times. Before loop I create a tcpdf object and in every loop I keep on adding new page with new page content. After the loop ends I have a pdf with 50 pages which is downloaded to the server.
Now in addition with the 50 pages pdf I also want separate pdfs of every page.
So how can I assign a page to new tcpdf object and download it?
Code
<?
include_once("_includes.php");
$db = new _database_class($GLOBALS["DB_CONNECTION_TYPE"]);
$vw = new _database_view($db);
$utl = new _utility_class($db, $vw);
$__ID = 166;
$INSTITUTE_ID = 2;
$USER_ID = 1;
$PROCESS_ID = 123;
$billingBatchInvoices = $vw->getBillingBatchInvoices($__ID);
$bankInfo = $vw->getBankInfo(1);
$bankBranchInfo = $vw->getBankBranchInfo(1);
class MYPDF extends TCPDF
{
function SetDash($black = null, $white = null)
{
if ($black !== null)
{
$s = sprintf('[%.3F %.3F] 0 d', $black * $this->k, $white * $this->k);
}
else
{
$s = '[] 0 d';
}
$this->_out($s);
}
public function Header()
{
}
public function Footer()
{
}
}
$GLOBALS["style"] = array(
'border' => 0,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array(0, 0, 0),
'bgcolor' => false, //array(255,255,255)
'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points
);
$pdf = new MYPDF("L", "mm", "A4", true, 'UTF-8', false);
$pdf->SetCreator('XNREL');
$pdf->SetAuthor('XNREL');
$pdf->SetTitle('Invoice');
$pdf->SetSubject('Invoice');
$pdf->SetKeywords('Invoice');
$pdf->SetAutoPageBreak(true, 0);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setLanguageArray($l);
$pdf->setPrintHeader(true);
$pdf->setPrintFooter(true);
//header and footer information
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$COPY[1] = "Bank Copy";
$COPY[2] = "School's Copy";
$COPY[3] = "Parent's Copy";
$result = $vw->getLookupValue("PS_QUEUED", "PROCESS_STATUS", $INSTITUTE_ID);
$status = $result['LOOKUP_VALUE_ID'];
$bindArray = array(
":PROCESS_ID" => $PROCESS_ID,
":INSTITUTE_ID" => $INSTITUTE_ID,
":COLUMN_VALUE" => $__ID,
":COLUMN_REF" => "BILLING_ID",
":TABLE_REF" => "BILLING",
":PROCESS_STATUS" => $status,
":CREATED_BY" => $USER_ID
);
$query = "SELECT PROCESS_ID FROM SYS_PROCESS_LOG WHERE PROCESS_ID=:PROCESS_ID AND INSTITUTE_ID=:INSTITUTE_ID AND COLUMN_VALUE=:COLUMN_VALUE AND COLUMN_REF=:COLUMN_REF AND TABLE_REF=:TABLE_REF AND PROCESS_STATUS=:PROCESS_STATUS AND CREATED_BY=:CREATED_BY";
$found = $db->fetchRS($query, $bindArray);
$bindArray = array(
":INSTITUTE_ID" => $INSTITUTE_ID
);
$query = "SELECT DATE_FORMAT FROM CAS_INSTITUTE WHERE INSTITUTE_ID=:INSTITUTE_ID";
$result = $db->fetchRecord($query, $bindArray);
$lookup = $vw->getLookupValueInfo($result['DATE_FORMAT']);
$S_USER_DATE_FORMAT = $lookup['LOOKUP_VALUE_CODE'];
$result = $vw->getLookupValue("PS_IN_PROGRESS", "PROCESS_STATUS", $INSTITUTE_ID);
$status = $result['LOOKUP_VALUE_ID'];
$bindArray = array(
":PROCESS_ID" => $PROCESS_ID,
":INSTITUTE_ID" => $INSTITUTE_ID,
":COLUMN_VALUE" => $__ID,
":COLUMN_REF" => "BILLING_ID",
":TABLE_REF" => "BILLING",
":PROCESS_STATUS" => $status,
":STARTED_AT" => date("Y-m-d H:i:s")
);
$query = "UPDATE SYS_PROCESS_LOG SET PROCESS_STATUS=:PROCESS_STATUS, STARTED_AT=TO_DATE(:STARTED_AT,'G_DATEFORMAT_3') WHERE PROCESS_ID=:PROCESS_ID AND INSTITUTE_ID=:INSTITUTE_ID AND COLUMN_VALUE=:COLUMN_VALUE AND COLUMN_REF=:COLUMN_REF AND TABLE_REF=:TABLE_REF";
$db->executeQuery($query, $bindArray);
$looper=1;
foreach ($billingBatchInvoices as $billingBatchInvoice)
{
$invoiceInfo = $vw->getInvoiceInfo($billingBatchInvoice['CUSTOMER_BILLING_ID']);
$invoiceItems = $vw->getInvoiceItems($billingBatchInvoice['CUSTOMER_BILLING_ID']);
$pdf->AddPage('L');
$GLOBALS["C_X"] = 5;
for ($i = 1; $i <= 3; $i++)
{
$GLOBALS["C_Y"] = 10;
$fontSize = 35;
$pdf->Image('../resources/common/img/logo/logo.png', $GLOBALS["C_X"] + 6.5, $GLOBALS["C_Y"] + 0.5, 15);
$html = '<table style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif;" border="1" cellpadding="5">';
$html = $html . '<tr>
<td width="95" style="text-align:center"></td>
<td width="205" height="40" style="text-align:center">' .
$bankInfo['INSTITUTE_DESC']
. '</td>
</tr>
</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$fontSize = 30;
$GLOBALS["C_Y"] = $pdf->GetY() + 1;
$html = '<table bgcolor="#000000" style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif; color:#FFFFFF; " border="1" cellpadding="5">';
$html = $html . '
<tr>
<td width="300" style="text-align:center">' . $COPY[$i] . '</td>
</tr>
</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$GLOBALS["C_Y"] = $pdf->GetY() + 1;
// $GLOBALS["C_Y"] = $pdf->GetY();
// $pdf->Image('../resources/common/img/Silkbank.jpg', $GLOBALS["C_X"] + 1, $GLOBALS["C_Y"] + 1, 85.5);
$fontSize = 25;
// $GLOBALS["C_Y"] = $pdf->GetY() + 10.5;
$html = '<table style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif;" border="1" cellpadding="5">';
$html = $html . '
<tr>
<td width="300" style="text-align:left">Bank: ' . $bankInfo['BANK_DESC'] . '</td>
</tr>
<tr>
<td width="300" style="text-align:left">Branch: ' . $bankBranchInfo['BRANCH_DESC'] . '</td>
</tr>
<tr>
<td width="300" style="text-align:left">A/C Title: ' . $bankBranchInfo['ACCOUNT_TITLE'] . '</td>
</tr>
<tr>
<td width="300" style="text-align:left">A/C No.: ' . $bankBranchInfo['ACCOUNT_NO'] . '</td>
</tr>
</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$GLOBALS["C_Y"] = $pdf->GetY() + 2;
$html = '<table style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif;" border="1" cellpadding="5">';
$html = $html . '
<tr>
<td width="95" style=""><strong>Invoice #</strong></td>
<td width="205" style=""><strong>' . $invoiceInfo['INVOICE_NO'] . '</strong></td>
</tr>
<tr>
<td width="95" style=""><strong>Name</strong></td>
<td width="205" style="">' . $invoiceInfo['PERSON_FIRST_NAME'] . ' ' . $invoiceInfo['PERSON_LAST_NAME'] . ' - ' . $invoiceInfo['PIN'] . '</td>
</tr>
<tr>
<td width="95" style=""><strong>Class / Campus</strong></td>
<td width="205" style="">' . $invoiceInfo['CLASS_DESC'] . ' - ' . $invoiceInfo['CAMPUS_DESC'] . '</td>
</tr>
<tr>
<td width="95" style=""><strong>Issue Date</strong></td>
<td width="205" style="">' . $utl->convertDBDateToUserDate($invoiceInfo['BILL_DATE'], $S_USER_DATE_FORMAT) . '</td>
</tr>
<tr>
<td width="95" style=""><strong>Due Date</strong></td>
<td width="205" style="">' . $utl->convertDBDateToUserDate($invoiceInfo['DUE_DATE'], $S_USER_DATE_FORMAT) . '</td>
</tr>
</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$GLOBALS["C_Y"] = $pdf->GetY() + 2;
$html = '<table style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif;" border="1" cellpadding="5">';
$html = $html . '
<tr bgcolor="#CCCCCC";>
<td width="25" style="text-align:center"><strong>No</strong></td>
<td width="185" style=""><strong>Processing Fee</strong></td>
<td width="90" style="text-align:right"><strong>Amount</strong></td>
</tr>';
$C = 1;
foreach ($invoiceItems as $ROW)
{
$html = $html . '
<tr>
<td width="25" style="text-align:center">' . $C . '</td>
<td width="185" style="">' . $ROW['ITEM'] . '</td>
<td width="90" style="text-align:right">' . number_format($ROW['ITEM_AMOUNT']) . '/-</td>
</tr>';
$C++;
}
$html = $html . '
<tr>
<td width="210" colspan="1" style="text-align:right"><strong>Total (Rs.)</strong></td>
<td width="90" style="text-align:right"><strong>' . number_format($invoiceInfo['AMOUNT']) . '/-</strong></td>
</tr>
<tr>
<td colspan="2" width="300" colspan="1"><strong>Total Amount in Words:</strong> ' . ucwords(strtolower($utl->converNumberToWords($invoiceInfo['AMOUNT']))) . ' Only</td>
</tr>';
$html = $html . '</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$GLOBALS["C_Y"] = $pdf->GetY() + 2;
$html = '<table style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif;" border="1" cellpadding="5">';
$html = $html . '<tr>
<td width="300" style="">
<strong>Payment Terms:</strong>
</td>
</tr>
<tr>
<td width="300" style="">
1. Deposit fee between 9:00-4:30pm Mon-Fri.
</td>
</tr>
<tr>
<td width="300" style="">
2. Deposit payment within 10 days of due date.
</td>
</tr>
<tr>
<td width="300" style="">
<small>This is a computer generated document and does not require signature</small>
</td>
</tr>
</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$GLOBALS["C_X"] = $GLOBALS["C_X"] + 100;
if ($i <> 3)
{
$pdf->SetDash(2, 2);
$pdf->Line($GLOBALS["C_X"] - 6, 0, $GLOBALS["C_X"] - 6, 250);
}
}
$pdfnew = new MYPDF("L", "mm", "A4", true, 'UTF-8', false);
$pdfnew->AddPage('L');
$pdf->copyPage($pdf->getPage($looper));
$pdfnew->Output($invoiceInfo['PIN'] . "-Invoice-Voucher.pdf", "F");
$looper++;
}
$result = $vw->getLookupValue("PS_SUCCESS", "PROCESS_STATUS", $INSTITUTE_ID);
$status = $result['LOOKUP_VALUE_ID'];
$bindArray = array(
":PROCESS_ID" => $PROCESS_ID,
":INSTITUTE_ID" => $INSTITUTE_ID,
":COLUMN_VALUE" => $__ID,
":COLUMN_REF" => "BILLING_ID",
":TABLE_REF" => "BILLING",
":PROCESS_STATUS" => $status,
":ENDED_AT" => date("Y-m-d H:i:s")
);
$query = "UPDATE SYS_PROCESS_LOG SET PROCESS_STATUS=:PROCESS_STATUS, ENDED_AT=TO_DATE(:ENDED_AT,'G_DATEFORMAT_3') WHERE PROCESS_ID=:PROCESS_ID AND INSTITUTE_ID=:INSTITUTE_ID AND COLUMN_VALUE=:COLUMN_VALUE AND COLUMN_REF=:COLUMN_REF AND TABLE_REF=:TABLE_REF";
$db->executeQuery($query, $bindArray);
$pdf->Output("Batch-Invoice-Voucher.pdf", "F");
?>
Create another object INSIDE the loop, add the page to that.
Possibly you want these in an array too, so you could define $separatePages = []; before the loop, and create the single page inside the loop, and add it to the array, so you have it after the looping is complete.
$pdf = new MYPDF("L", "mm", "A4", true, 'UTF-8', false);
$pagesArray = [];
// existing code
foreach ($billingBatchInvoices as $billingBatchInvoice) {
// existing code
// create new pdf
$page = new MYPDF("L", "mm", "A4", true, 'UTF-8', false);
// add to page the same way as you did main pdf
$pagesArray[] = $page;
}
I'm using HTML tables to display the name of a user, quiz id, and score.
And this is my code.
<?php
echo '<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>';
$data = array();
$userid = 1;
$data[$userid] = array();
$name = 'Davy Jones';
$data[$userid]['name'] = $name;
$quiz = array(
'Qz1' => array(
'easy' => 1,
'normal' => 2,
'hard' => 3,
),
'Qz2' => array(
'easy' => 4,
'normal' => 5,
'hard' => 6,
),
);
$data[$userid]['quizzes'] = $quiz;
echo '<table style="width: 40%">';
echo '<tr>
<td>Name</td>
<td>Easy</td>
<td>Normal</td>
<td>Hard</td>
</tr>
<tr>
<td></td>
<td>Score</td>
<td>Score</td>
<td>Score</td>
</tr>';
foreach ($data as $key => $value) {
$quizzes = $value["quizzes"];
echo $value['name'].'<br>';
foreach ($quizzes as $key => $value2) {
echo $key.' '.$value2['easy'].'<br>';
echo $key.' '.$value2['normal'].'<br>';
echo $key.' '.$value2['hard'].'<br>';
}
}
echo '</table>';
For now I have this type of display.
I don't know how to manipulate the table and get this type of result.
Name Easy Normal Hard
Score Score Score
Qz1 Qz2 Qz1 Qz2 Qz1 Qz2
Davy Jones 1 4 2 5 3 6
Any ideas would be most appreciated.
You could use colspan for the table headings to span them across two columns for the information below them and then echo the appropriate variables and information in the cells:
http://jsfiddle.net/omzc6211/
Try to modify your code this way:
<?php
echo '
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>';
$data = array();
$userid = 1;
$data[$userid] = array();
$name = 'Davy Jones';
$data[$userid]['name'] = $name;
$quiz = array(
'Qz1' => array(
'easy' => 1,
'normal' => 2,
'hard' => 3,
),
'Qz2' => array(
'easy' => 4,
'normal' => 5,
'hard' => 6,
),
);
$data[$userid]['quizzes'] = $quiz;
echo '<table style="width: 40%">';
$quizTypes = array(
'easy',
'normal',
'hard'
);
$colspan = count($quiz);
echo '
<tr>
<td>Name</td>
<td colspan=' . $colspan . '>Easy</td>
<td colspan=' . $colspan . '>Normal</td>
<td colspan=' . $colspan . '>Hard</td>
</tr>
<tr>
<td></td>
<td colspan=' . $colspan . '>Score</td>
<td colspan=' . $colspan . '>Score</td>
<td colspan=' . $colspan . '>Score</td>
</tr>
';
foreach ($data as $user)
{
echo '<tr>';
echo '<td>' . $user['name'] . '</td>';
foreach ($quizTypes as $quizType)
{
foreach ($user["quizzes"] as $quizData)
{
echo '<td>' . (array_key_exists($quizType, $quizData) ? $quizData[$quizType] : '-') . '</td>';
}
}
echo '</tr>';
}
echo '</table>';
As suggested in the accepted answer you should use colspan, but here's the code for your very case:
<?php
echo '<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>';
$data = array();
$userid = 1;
$data[$userid] = array();
$name = 'Davy Jones';
$data[$userid]['name'] = $name;
$quiz = array(
'Qz1' => array(
'easy' => 1,
'normal' => 2,
'hard' => 3,
),
'Qz2' => array(
'easy' => 4,
'normal' => 5,
'hard' => 6,
),
);
$data[$userid]['quizzes'] = $quiz;
echo '<table style="width: 40%">';
echo '<tr>
<td>Name</td>
<td colspan="2">Easy</td>
<td colspan="2">Normal</td>
<td colspan="2">Hard</td>
</tr>
<tr>
<td></td>
<td colspan="2">SCORES</td>
<td colspan="2">SCORES</td>
<td colspan="2">SCORES</td>
</tr>';
foreach ($data as $key => $value) {
$quizzes = $value["quizzes"];
$keys = "";
$easy = "";
$normal = "";
$hard = "";
foreach ($quizzes as $key => $value2) {
$keys .= '<td>'.$key.'</td>';
$easy .= '<td>'.$value2['easy'].'</td>';
$normal .= '<td>'.$value2['normal'].'</td>';
$hard .= '<td>'.$value2['hard'].'</td>';
}
echo '<tr><td></td>' . $keys . $keys . $keys . '</tr>';
echo '<tr><td>'.$value['name'].'</td>' . $easy . $normal . $hard . '</tr></table>';
}
?>
I have to check a string and replace if the attribute is equal to "Destaque:" in the case where the attribute matches it fails to print the line, but I'm confused with the functions, can someone help me?
<?php
class Produto_Atributo
{
function __construct()
{
}
function produtoAtributo($codigo)
{
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$banco_magento = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "SELECT * FROM tw_produto_atributo where entity_id=" . $codigo;
$resultadoSql = $banco_magento->fetchAll($sql);
$count = 0;
foreach ($resultadoSql as $linha) {
$classe = '';
if ($count % 2 == 0) {
$classe = 'par';
}
else {
$classe = 'impar';
}
$_atributo = $this->recuperarAtributo($linha['attribute_id']);
$_optionText = $this->recuperarOptionid($_atributo, $linha['option_id']);
$descricao=$linha['ds_conteudo'] ;
$order = array("\n");
$replace = '<br />';
$newstr = str_replace($order, $replace, $descricao);
if (isset($linha['ds_conteudo']) && $linha['ds_conteudo'] != '') {
echo '<tr class="active '.$classe.'">
<td class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important; "> ' . ucwords( strtolower($_optionText)) . '</td>
<td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $newstr. '</td>
</tr>';
} else {
echo '<tr class="'.$classe.'">
<td class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important;">'if($_atributo->getFrontend_label()==!"Destaque:"){$_atributo->getFrontend_label();}else {'Loko'.$_atributo->getFrontend_label();} '</td>
<td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $_optionText . '</td>
</tr>';
}
$count = $count + 1;
}
}
function recuperarAtributo($atributo)
{
$cod = $atributo;
$attr = Mage::getModel('eav/entity_attribute')->getCollection()->addFieldToFilter('attribute_id', array('eq' => $cod))->getFirstItem();
return $attr;
}
function recuperarOptionid($atributo, $option_id)
{
return ($atributo->getSource()->getOptionText($option_id));
}
}
already got hahah
was very simple, here's the answer:
if (isset($linha['ds_conteudo']) && $linha['ds_conteudo'] != '') {
echo '<tr class="active '.$classe.'">
<td class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important; "> ' . ucwords( strtolower($_optionText)) . '</td>
<td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $newstr. '</td>
</tr>';
} else {
if($_atributo->getFrontend_label()<>"Destaque:"){
echo '<tr class="'.$classe.'">
<td class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important;">' . $_atributo->getFrontend_label() . '</td>
<td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $_optionText . '</td>
</tr>';
}
}
My output of my PDF page when it prints more than one page it does not print correctly. Please look at the example
Here is an example of the PDF file expenses.pdf.
If you notice where the page starts printing on page 2 it overwrites itself.
Also it does not cut off the page on the first page above the category so it carry's the info onto the 2nd page.
Also there are only 19 items in this list yet it prints 5 pages and repeats the items.
class PDF extends tcpdf
{
// Page header
function Header()
{
$this->SetFont('Times', 'BI', 20, '', 'false');
// Move to the right
$this->Ln(5);
$this->Cell(60);
$this->Cell($w, $h=0, $txt='EXPENCE REPORT', $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0,
$ignore_min_height=false, $calign='T', $valign='M');
$this->Line (0, 13, 210, 13, $style=array());
// Line break
$this->Ln(5);
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
$pdf = new PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage ($orientation='', $format='', $keepmargins=false, $tocpage=false);
$pdf->SetAutoPageBreak ($auto, $margin=16);
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(true);
$pdf->setFontSubsetting(true);
// set margins
$pdf->SetMargins(10, PDF_MARGIN_TOP, 10);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->SetFont('helvetica', '', 14, '', true);
$tbl_header = '<table cellspacing="3" style="width: 100%; text-align: center; font-size: 8pt;">';
$tbl_footer = '</table>';
$tbl = '';
$sql = "SELECT `expensetype`.`typeid`, `expensetype`.`exptype`, `expenses`.`expid`,`expenses`.`expdate`, `expenses`.`checktype`, `expenses`.`payee`,`expenses`.`details`, `expenses`.`amount` FROM `expensetype` INNER JOIN `expenses` ON
`expensetype`.`typeid` = `expenses`.`typeid`WHERE (`expenses`.`pid` = " . $pid . ")";
$result = $db->query($sql);
$expensetype = null;
foreach($result as $expense) {
if($expensetype != $expense['typeid']) {
$exptype = $expense['exptype'];
$tbl .= '
<tr>
<td height="10" style="width: 100%;"></td>
</tr>
<tr style="background-color:#E1E0E0">
<td height="20" style="width: 25%; text-align: left">Category:</td>
<td height="20" style="width: 75%; text-align: left">'.$exptype.'</td>
</tr>';
$tbl .= '
<tr style="background-color:#CEC7C7">
<th style="width: 20%">Date:</th>
<th style="width: 30%">Payee:</th>
<th style="width: 30%">Detalls:</th>
<th style="width: 20%">Amount:</th>
</tr>';
$pdf->SetXY(2, 20);
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');
}
$expdate=phpdate($expense['expdate']);
$tbl .= '
<tr>
<td style="width: 20%; text-align: center">'.$expdate.'</td>
<td style="width: 30%; text-align: center">'.$expense['payee'].'</td>
<td style="width: 30%; text-align: center">'.$expense['details'].'</td>
<td style="width: 20%; text-align: center">'.$expense['amount'].'</td>
</tr>';
if($expensetype != $expense['typeid']) {
$expensetype = $expense['typeid'];
}
}
$pdf->SetXY(2, 20);
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');
// $tbl .= '
//<tr>
//<th style="width: 85%; text-align: right;">Total Amount:' .$totalamount.' </th>
//</tr>';
ob_end_clean();
$pdf->Output();
This is what the script looks like now
$sql = "SELECT `expensetype`.`typeid`, `expensetype`.`exptype`, `expenses`.`expid`,`expenses`.`expdate`, `expenses`.`checktype`, `expenses`.`payee`,`expenses`.`details`, `expenses`.`amount` FROM `expensetype` INNER JOIN `expenses` ON
`expensetype`.`typeid` = `expenses`.`typeid`WHERE (`expenses`.`pid` = " . $pid . ")";
$result = $db->query($sql);
$expensetype = null;
foreach($result as $expense) {
$tbl = '';
if($expensetype != $expense['typeid']) {
$exptype = $expense['exptype'];
$tbl .= '
<tr>
<td height="10" style="width: 100%;"></td>
</tr>
<tr style="background-color:#E1E0E0">
<td height="20" style="width: 25%; text-align: left">Category:</td>
<td height="20" style="width: 75%; text-align: left">'.$exptype.'</td>
</tr>';
$tbl .= '
<tr style="background-color:#CEC7C7">
<th style="width: 20%">Date:</th>
<th style="width: 30%">Payee:</th>
<th style="width: 30%">Detalls:</th>
<th style="width: 20%">Amount:</th>
</tr>';
$pdf->SetXY(2, 20 + $pdf->GetY());
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');
}
$expdate=phpdate($expense['expdate']);
$tbl = '';
$tbl .= '
<tr>
<td style="width: 20%; text-align: center">'.$expdate.'</td>
<td style="width: 30%; text-align: center">'.$expense['payee'].'</td>
<td style="width: 30%; text-align: center">'.$expense['details'].'</td>
<td style="width: 20%; text-align: center">'.$expense['amount'].'</td>
</tr>';
$pdf->SetXY(2, 20 + $pdf->GetY());
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');
if($expensetype != $expense['typeid']) {
$expensetype = $expense['typeid'];
}
}
$pdf->Output();
Main cause is that you don't reinitialize the variable $tbl, that holds the body of your table every loop.
foreach($result as $expense) {
$tbl = '';
should make your output more in the line that you want.
Now you've got solved the problem of
Also there are only 19 items in this list yet it prints 5 pages and
repeats the items.
The overwriting occurs because you position your output absolut on the page with:
$pdf->SetXY(2, 20);
That's ok for the first time. Your next content (next loop) has to consider the actual Y position. You can get this with the `GetY()' method.
$pdf->SetXY(2, 20 + $pdf->GetY());
should take care of that.