Jump to content

Recommended Posts

I"m thinking that if you simply changed the query that grabs the data so that it grabs everyone the pdf reporting should be the same.  If you thought about it beforehand that is.

There's an awful lot of thought that goes into this business.  Try a little.

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576240
Share on other sites

1 minute ago, ginerjm said:

I"m thinking that if you simply changed the query that grabs the data so that it grabs everyone the pdf reporting should be the same.  If you thought about it beforehand that is.

There's an awful lot of thought that goes into this business.  Try a little.

Is there like merge library that can take the links into one file? Like pdf merge online?

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576241
Share on other sites

41 minutes ago, ginerjm said:

I do not believe you can merge these files.  One merges the DATA into one report.  That's the thinking you need to do.  If necessary you could simply do a page break in it after each person's info is printed.

Thanks, can you help on this. I have the file that generates each link

'fpdf.php?oracleid=$userid&sdate=$thefirstday&edate=$curdate'

and this will go to fpdf file that has this:

public function __construct($conn, $oracleid, $sdate, $edate)
    {
        parent::__construct();
        $this->today = date('jS M Y');
        $this->db = $conn;
        $this->oracleid = $oracleid;
        $this->sdate = new DateTime($sdate);
        $this->edate = new DateTime($edate);
        $res = $this->db->prepare("SELECT staffname
                                   FROM staff
                                   WHERE oracleid = ?
                                  ");
        $res->execute([$oracleid]);
        $this->staffname = $res->fetchColumn();
    }

so how to pass all records if fpdf is taking one at each time?

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576244
Share on other sites

I"m going to let you think this out.

I'm going to assume that you wrote a report that shows one person's data.  So now you simply expand the query to generate multiple rows of data and use that in a loop to output each record on the pdf.  Make sense?

So look at YOUR code and do some re-thinking.  As I said earlier - if you simply want to generate a person's data as one page of a report then add a page break after doing one guy and let the loop do all the work.

It's all about doing your design homework before you sit down and begin coding.   

And please don't re-post this when you make your next post.  Such a waste.

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576245
Share on other sites

can i just get small hint? the loop should be in the php file not the fpdf file, right? how to pass a loop to the given fpdf function, i am saying this because at the moment i am having a link for each staff. The reason why i am getting one by one (staff) is because in the long run each will have 100's of records.

 

public function __construct($conn, $oracleid, $sdate, $edate)

we have around 55 staff members and each will have 100's of records that is why i have a link for each staff. is there a way to have them all in one link? the way the attendance system goes, by range of dates based on each staff on his own. not all staff have same login and logoff times.

Edited by ramiwahdan
Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576246
Share on other sites

Here is what i tried:

include('session.php');
	include('dbcon.php');
	require('fpdf/fpdf.php');
	
	$userid = $_GET['GetID'];
	$isdone = -1;
	
	$query = "select * from attendance_records where OracleID = '".$userid."' and isdone= '".$isdone."'";
	$result = mysqli_query($con, $query);

	// Define your columns like so:
	$columns = array(array("name" => "OracleID","width" => 20),
               array("name" => "Name","width" => 35),
               array("name" => "Des", "width" => 35));

$pdf = new FPDF();
$pdf->AddPage();

// Table header
$pdf->SetFillColor(232, 232, 232);
$pdf->SetFont('Arial', 'B', 8);
foreach ($columns as $column)
{
    $pdf->Cell($column['width'], 6, strtoupper($column['name']), 1, 0, 'L', 1);
}
$pdf->Ln();

$pdf->SetFont('Arial', '', 8);

	$qry = "select staffname, joindate from staff where OracleID = '".$userid."'";
	$answ = mysqli_query($con, $qry);

	$rowanswer = mysqli_fetch_assoc($answ);
	$thefirstdate = $rowanswer['joindate'];
	$thefirstdate2 = date("d-m-Y",strtotime($rowanswer['joindate']));
	$staffname = $rowanswer['staffname'];

	$t=time();
	$curdate = date("d-m-Y",$t);
	$curTime = date("g:i:s A",$t);							

?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.css">

</head>

<body>

	<div class="container">
		<div class="row">
			<div class="col m-auto">
				<div class="card mt-5">
					<table class="table table-bordered">
												
						<?php
						
							$query2 = "SELECT sec_to_time(SUM(timestampdiff(SECOND, ClockingInDate, ClockingOutDate))) as total from attendance_records where OracleID = '".$userid."' and isdone= '".$isdone."'";
							$result2 = mysqli_query($con, $query2);
							$query3 = "SELECT sec_to_time(SUM(timestampdiff(SECOND, PermissionOutDate, PermissionInDate))) as total2 from attendance_records where OracleID = '".$userid."' and isdone= '".$isdone."'";
							$result3 = mysqli_query($con, $query3);
							$num_row = mysqli_num_rows($result);

							$counter = 0;
							$previd = 0;
							$thecount = 0;
							
							while ($row = mysqli_fetch_assoc($result))
							{
								
								$name = $row['Name'];
								$des = $row['Des'];
								$theday = $row['theday'];
								$clockingindate = $row['ClockingInDate'];
								$peroutdate = $row['PermissionOutDate'];
								$perindate = $row['PermissionInDate'];
								$clockingoutdate = $row['ClockingOutDate'];
								$perduration = $row['PerDuration'];
								$duration = $row['Duration'];
								$fullday = $row['fullday'];
								$reason = $row['reason'];
								$counter = $counter + 1;
						
							if ($peroutdate != Null)
							{
								if ($fullday == -1)
								{
									
									$fullday = "Yes";
									
									if ($perindate == Null)
									{
									
									$perindate = "All Day";
									
									}
								
									if ($perduration == Null)
									{
									
									$perduration = "All Day";
									
									}
									
								}
								else
								{
									
									$fullday = "No";
									
								}
							}
							else{
								
								$fullday = Null;
								$perindate = Null;
								$perduration = Null;
								
							}
				
							if ($row['OracleID'] != $previd) {                              // id changed so output total
								if ($previd != 0) {
									
									 echo "
									<tr>
									  <td>OracleID</td>
									  <td>{$row['OracleID']}</td>
									  <td>Name</td>
									  <td>{$row['Name']}</td>
									  <td>Designation</td>
									  <td>{$row['Des']}</td>
									  <td>Joining Date</td>
									  <td>$thefirstdate2</td>
									</tr>
									"; 
									
									foreach ($columns as $column)
									{
										$pdf->Cell($column['width'], 6, $row[$column['name']], 1);
									}
									$pdf->Ln();
						
								}
								else{
								
									echo "
									<tr>
									  <td>OracleID</td>
									  <td>{$row['OracleID']}</td>
									  <td>Name</td>
									  <td>{$row['Name']}</td>
									  <td>Designation</td>
									  <td>{$row['Des']}</td>
									  <td>Joining Date</td>
									  <td>$thefirstdate2</td>
									</tr>
									"; 
									
									foreach ($columns as $column)
									{
										$pdf->Cell($column['width'], 6, $row[$column['name']], 1);
									}
									$pdf->Ln();
									
								}
								$previd = $row['OracleID'];
								$pdf->AddPage();
							}								
						
							 echo "<th colspan='9'></th>";
		
							$thecount = $thecount + 1;
							
							echo "
						<tr>
						
                            <td>Day</td>
							<td>Clocking In</td>
							<td>Permission Out</td>
							<td>Full Day?</td>
							<td>Permission Reason</td>
							<td>Permission In</td>
							<td>Clocking Out</td>
							<td>Permission Duration</td>
							<td>Normal Duration</td>
							
						</tr>
						
							<tr>
							<td>$theday</td>
							<td>$clockingindate</td>
							<td>$peroutdate</td>
							<td>$fullday</td>
							<td>$reason</td>
							<td>$perindate</td>
							<td>$clockingoutdate</td>
							<td>$perduration</td>
							<td>$duration</td>
						   </tr>
					  
                ";
						
							}

								$row2 = mysqli_fetch_assoc($result2);
								$totals= $row2['total'];
								
								$row3 = mysqli_fetch_assoc($result3);
								$totals2 = $row3['total2'];
								
								
								if ($num_row > 0)
								{
									
									if ($perduration == "All Day")
									{
										
										if ($totals2 == Null)
										{
										
										$totals2 = "All Day";
										
										}
									
									}
									
								}	
								
								echo '<tr>';
								echo '<td><td><td><td><td><td><td><b>Total Permission Time:</b></td></td></td></td></td></td></td>';
								echo '<td>';
								echo $totals2; 
								echo '</td>';
								echo '</tr>';					
						
								echo "<tr><td colspan='7'><h3><a href='fpdf.php?oracleid=$userid&sdate=$thefirstdate2&edate=$curdate' target='_blank'>Print Attendance Reports for $staffname</a></h3></td><td><b>Total Attendance Time:</b></td><td>$totals</td></tr>";
						
						
						
						?>
						
					</table>
					<a href="singlereportbyid.php" width="100%">Click here to go back to Main Menu</a>
			
				</div>
			</div>
		</div>
	</div>
<?php

$pdf->Output();

?>
</body>

</html>

it gives error that table already exist.

Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file

why?

Edited by ramiwahdan
Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576270
Share on other sites

1 hour ago, ramiwahdan said:

why?

Because ->Output() will be sending header data tell the browser to expect PDF output. You cannot send headers after output has been sent.

This is why, on March 27, I told you

Quote

Don't mix the screen output code with FPDF code. Put the FPDF into a separate script. Display the web page and put a link to the pdf page

 

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576272
Share on other sites

1 minute ago, Barand said:

Because ->Output() will be sending header data tell the browser to expect PDF output. You cannot send headers after output has been sent.

This is why, on March 27, I told you

 

doing so i will be generating one link for each staff and that is what i have, but i want to generate 1 pdf file fir all?\, how? 

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576273
Share on other sites

4 minutes ago, Barand said:

Try outputting the pdf to a file instead of the screen.

this will download the file after clicking a link but still i have to click for all staff to download each one. What i mean, the fpdf file i have (you helped me with), takes one staff at a time, how to make it inside a loop?

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576275
Share on other sites

8 minutes ago, Barand said:

You change your query.

  • Remove "WHERE oracleie = ?"
  • Add "ORDER BY oracleid"
  • Create new page after each id's totals

After removing "Remove "WHERE oracleie = ?"" now attendance is empty, I will change this in the fpdf file, how to link all id's from the php file? Thanks for all the help.

Edited by ramiwahdan
Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576279
Share on other sites

I"ll try and contribute again and hope to get my point across.

Write your query to select all of the people you want to report out.  When you finally run that query, pass the results variable to your fpdf code script.  Begin a loop there on those results that does the fetch for each record and let your fpdf code process it.

When you loop finishes - close out your fpdf and send it to the client.  Remember you CANNOT SEND ANYTHING TO THE CLIENT EXCEPT THIS CLOSED FPDF CONTENT.  That's why you use two scripts - one to collect any arguments and do the query and report back any errors and the other to take the set of data and generate the fpdf output and actually do the outputting to the client.

Whew!

(Please don't re-post this post.  Read it, digest it and go do the work.)

 

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576282
Share on other sites

1 minute ago, Barand said:

If you are putting the reports for everyone in a single file you don't need to pass an id. You are going to process all of them.

exactly i don't pass id, so how to reference the fpdf file then to do the functions to generate the reports of attendance and absents? what i need to pass and what needs to change in that fpdf file.

public function __construct($conn, $oracleid, $sdate, $edate)

is then wrong since i am not pass each oracle id! is that correct? 

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576284
Share on other sites

I tried to add add page to the php not working. now i have empty page.

include('fpdf.php');

foreach ($res as $row) {
				
                if ($row['oracleid'] != $previd) {                              // id changed so output total
                    if ($previd != 0) {
						$theid = $row['oracleid'];
						
						echo "<tr><td colspan='6'></td><td>Total Permission Time:</td><td>$total2</td></tr>";
						echo '<tr>';
						echo "<tr><td colspan='7'><h3><a href='fpdf.php?oracleid=$userid&sdate=$thefirstday&edate=$curdate' target='_blank'>Print Attendance Reports for $name</a></h3></td><td>Total Attendance Time:</td><td>$total</td></tr>";				
						echo "<tr><td colspan='9' bgcolor='red'></td>";
						echo "<tr><td colspan='9' bgcolor='red'></td>";
						
						$pdf->AddPage();
						

added at the end the output


					$pdf->output('D','filename.pdf');
				
	?>

i can't use the fpdf inside the php?

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576288
Share on other sites

i really am struggling with this, I just need to know if i am not passing anything to the fpdf functions how to pass all information to it? if i put the fpdf included in the php, the page is blank! can someone help?

php:

<?Php 

include('session.php');
include('dbcon.php');

?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.css">

</head>

<body>
	
	<div class="container">
		<div class="row">
			<div class="col m-auto">
				<div class="card mt-5">
					<table class="table table-bordered">
					
<?php
	
$servername = "localhost";
$username = "?";
$password = "?";

    $conn = new PDO("mysql:host=$servername;dbname=timeclock", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$res = $conn->query("SELECT oracleid
                         , name 
                         , des
						 , theday
                         , clockingindate   as clockin
						 , permissionoutdate as perout
						 , permissionindate as perin
                         , clockingoutdate  as clockout
						 , fullday
						 , reason
						 , timediff(permissionindate,permissionoutdate ) as perduration
                         , timediff(clockingoutdate, clockingindate) as duration
                         , total
						 , total2
                    FROM attendance_records
                         JOIN (
                                SELECT oracleid
                                     , sec_to_time(sum(timestampdiff(SECOND, clockingindate, clockingoutdate))) as total
									 , sec_to_time(sum(timestampdiff(SECOND, permissionoutdate, permissionindate))) as total2
                                FROM attendance_records
								where isdone =-1
                                GROUP BY oracleid
                              ) tots USING (oracleid)
							  where isdone =-1
                    ORDER BY oracleid, clockingindate
                    ");

?>

		<?php
		
			$t=time();
			$curdate = date("d-m-Y",$t);
			$curTime = date("g:i:s A",$t);

			$arr = array();
            $previd = 0;
			$previd2 = 0;
			
            foreach ($res as $row) {
				
                if ($row['oracleid'] != $previd) {                              // id changed so output total
                    if ($previd != 0) {
						$theid = $row['oracleid'];
						
						echo "<tr><td colspan='6'></td><td>Total Permission Time:</td><td>$total2</td></tr>";
						echo '<tr>';
						echo "<tr><td colspan='7'><h3><a href='fpdf.php?oracleid=$userid&sdate=$thefirstday&edate=$curdate' target='_blank'>Print Attendance Reports for $name</a></h3></td><td>Total Attendance Time:</td><td>$total</td></tr>";				
						echo "<tr><td colspan='9' bgcolor='red'></td>";
						echo "<tr><td colspan='9' bgcolor='red'></td>";
						
						$previd2 = $row['oracleid'];
						array_push($arr,$previd2);
						$qry = "select joindate from staff where OracleID = '".$theid."'";
						$answ = mysqli_query($con, $qry);
						$rowanswer = mysqli_fetch_assoc($answ);
						
						$thejoindate = date("d-m-Y",strtotime($rowanswer['joindate']));
						
						echo "
						<tr>
						  <td>OracleID</td>
						  <td>{$row['oracleid']}</td>
						  <td>Name</td>
						  <td>{$row['name']}</td>
						  <td>Designation</td>
						  <td>{$row['des']}</td>
						  <td>Joining Date</td>
						  <td>{$thejoindate}</td>
						</tr>
						"; 
						
						$userid = $row['oracleid'];						
						
                    }
					else{
						
						$userid = $row['oracleid'];
						$qry = "select joindate from staff where OracleID = '$userid'";
						$answ = mysqli_query($con, $qry);
						$rowanswer = mysqli_fetch_assoc($answ);
						$thefirstday = $rowanswer['joindate'];	
						$thefirstday2 = date("d-m-Y",strtotime($rowanswer['joindate']));
						
						$thejoindate = date("d-m-Y",strtotime($rowanswer['joindate']));
						
						$previd2 = $row['oracleid'];
						array_push($arr,$previd2);
						
								echo "
								<tr>
								  <td>OracleID</td>
								  <td>{$row['oracleid']}</td>
								  <td>Name</td>
								  <td>{$row['name']}</td>
								  <td>Designation</td>
								  <td>{$row['des']}</td>
								  <td>Joining Date</td>
								  <td>{$thejoindate}</td>
								</tr>
								";		

							}
                    $previd = $row['oracleid'];
					$name = $row['name'];

                }
								
				$fullday = $row['fullday'];
				$perindate = $row['perin'];
				$perduration = $row['perduration'];
				$peroutdate = $row['perout'];
						
							if ($peroutdate != Null)
							{
								if ($fullday == -1)
								{
									
									$fullday = "Yes";
									
									if ($perindate == Null)
									{
									
									$perindate = "All Day";
									
									}
								
									if ($perduration == Null)
									{
									
									$perduration = "All Day";
									
									}
									
								}
								else
								{
									
									$fullday = "No";
									
								}
							}
							else{
								
								$fullday = Null;
								$perindate = Null;
								$perduration = Null;
								
							}

				?>
						
				<th colspan='9'></th>
						  
				<?php
				
				echo "
						<tr>
						
                            <td>Day</td>
							<td>Clocking In</td>
							<td>Permission Out</td>
							<td>Full Day?</td>
							<td>Permission Reason</td>
							<td>Permission In</td>
							<td>Clocking Out</td>
							<td>Permission Duration</td>
							<td>Normal Duration</td>
							
						</tr>
						
						<tr>
						  <td>{$row['theday']}</td>
                          <td>{$row['clockin']}</td>
						  <td>{$row['perout']}</td>
						  <td>{$fullday}</td>
						  <td>{$row['reason']}</td>
						  <td>{$perindate}</td>
                          <td>{$row['clockout']}</td>
						  <td>{$perduration}</td>
                          <td>{$row['duration']}</td>
                       </tr>
					  
                ";
                
				$total = $row['total'];
				$total2 = $row['total2'];
				
			
									if ($perduration == "All Day")
									{
										
										if ($total2 == Null)
										{
										
										$total2 = "All Day";
										
										}
									
									}
											
			}
			
						echo "<tr><td colspan='4'</td><td><td><td>Total Permission Time:</td></td></td><td>$total2</td></tr>";
						echo '<tr>';
						echo "<tr><td colspan='7'><h3><a href='fpdf.php?oracleid=$userid&sdate=$thefirstday&edate=$curdate' target='_blank'>Print Attendance Reports for $name</a></h3></td><td>Total Attendance Time:</td><td>$total</td></tr>";
						echo "</td></tr>";
					
					$ids = join("','",$arr);
					$qry = "select OracleID, StaffName,joindate from staff WHERE OracleID NOT IN ('$ids')";
					$answ = mysqli_query($con, $qry);
					
					while ($row2 = mysqli_fetch_assoc($answ))
					{
						$thestaffname = $row2['StaffName'];
						$absentstaff = $row2['OracleID'];
						$absentstaffjoined = $row2['joindate'];
						echo "<tr><td colspan='9' bgcolor='red'></td>";
						echo "<tr><td colspan='9' bgcolor='red'></td>";
						echo "<tr>";
						echo "<td colspan='7'><h3><a href='fpdf.php?oracleid=$absentstaff&sdate=$absentstaffjoined&edate=$curdate' target='_blank'>Print Attendance Reports for $thestaffname</a></h3></td>";
						echo "</tr>";
					}	
				
	?>
						
					</table>
					<a href="viewreports.php" width="100%">Click here to go back to Main Menu</a>
			
				</div>
			</div>
		</div>
	</div>

</body>

</html>

and fpdf:

<?php
require('fpdf/fpdf.php');

                                 // ADD YOUR OWN PDO CONNECTION CODE //
								 
$servername = "localhost";
$username = "??";
$password = "??";
		
	$conn = new PDO("mysql:host=$servername;dbname=timeclock", $username, $password);
	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

class attendPDF extends FPDF
{
    protected $today;
    protected $headbase;
    protected $conn;
    protected $oracleid;
    protected $staffname;
    protected $sdate;
    protected $edate;
                                                                                                    
    //constructor
    public function __construct($conn, $oracleid, $sdate, $edate)
    {
        parent::__construct();
        $this->today = date('jS M Y');
        $this->db = $conn;
        $this->oracleid = $oracleid;
        $this->sdate = new DateTime($sdate);
        $this->edate = new DateTime($edate);
        $res = $this->db->prepare("SELECT staffname
                                   FROM staff
                                   WHERE oracleid = ?
                                  ");
        $res->execute([$oracleid]);
        $this->staffname = $res->fetchColumn();
    }

    //Page header
    public function Header()
    {        
        //Helvetica bold 12
		$this->Image('./img/bg.png',-20,-2,210);
        $this->SetFont('Helvetica', '', 14);
        $this->Cell(0, 20, "Attendance Report", 0, 1, 'C');
        //Title
        $sd = $this->sdate->format('l jS F Y');
        $ed = $this->edate->format('l jS F Y');
        
        $this->SetFont('Helvetica', '', 12);
        $this->Cell(60,15,$this->oracleid . ' - ' . $this->staffname,1,0,'L');
        $this->Cell(120, 15, "$sd - $ed" , 1, 0, 'C') ;
        $this->Ln();
        $this->headbase = $this->GetY();
    }
    
    //Page footer
    public function Footer()
    {
        $this->setY(-22);
        $this->setX(15);
        $this->SetFont('Helvetica', '', 10);
        $this->Cell(0,5,'( '.$this->today.' )', 'T');
    }
    
    public function attendanceReport()
    {
        $widths = [60, 60, 60];
        $aligns = [ 'L', 'L', 'C' ];
        $heads  = ['Clocked In Time', 'Clocked Out Time', 'Duration'];
        $this->SetY(50);
        $this->SetFont('Helvetica', 'B', 12);
        $this->Cell(0, 10, 'Attendances', 0, 1);
        $this->SetFontSize(10);
        foreach ($heads as $k => $h) {
            $this->Cell($widths[$k], 10, $h, 1, 0, $aligns[$k], 1);
        }
        $this->Ln();
        $this->setFont('', '');
        $res = $this->db->prepare("SELECT date_format(clockingindate, '%a %d/%m/%Y %l:%i %p') as clkin
                                        , date_format(clockingoutdate, '%a %d/%m/%Y %l:%i %p') as clkout
                                        , timediff(clockingoutdate, clockingindate) as duration
                                   FROM attendance_records
                                   WHERE oracleid = ?
                                         AND DATE(clockingindate) BETWEEN ? AND ?
                                   ORDER BY clockingindate     
                                  ");
        $res->execute([ $this->oracleid, $this->sdate->format('Y-m-d'), $this->edate->format('Y-m-d') ] );
        while ( $r = $res->fetch(PDO::FETCH_NUM) ) {
            foreach ($r as $k => $v) {
                $this->Cell($widths[$k], 6, $v, 0, 0, $aligns[$k]);
            }
            $this->Ln();
        }
    }
    
    public function absenceReport()
    {
        $this->SetY(50);
        $this->SetFont('Helvetica', 'B', 12);
        $this->Cell(0, 10, 'Absences', 0, 1);
        $this->SetFontSize(15);
        $this->Cell(0, 10, 'Dates Absent', 1, 0, 'L', 1);
        $this->setFont('', '');
        $this->Ln();
        // set up a temporary date table - each working day in the reporting period
        $this->db->exec("CREATE TEMPORARY TABLE date(date date)");
        $incr = DateInterval::createFromDateString('next weekday');
        $sd = clone $this->sdate;
        $ed = clone $this->edate;
        $sd->modify('+1 days');                            // adjust for Islamic working week
        $ed->modify('+2 days');                            // adjust for Islamic working week
        $range = new DatePeriod($sd, $incr, $ed);
        foreach ($range as $d) {
            $dt = $d->sub(new DateInterval('P1D'))->format('Y-m-d');              // adjust for Islamic working week
            $dates[] = "('$dt')";
        }
        $this->db->exec("INSERT INTO date VALUES " . join(',', $dates));
        // get days absent
        $res = $this->db->prepare("SELECT DATE_FORMAT(date, '%W %d/%m/%Y' ) as date
                                   FROM staff s
                                        CROSS JOIN 
                                        date d
                                        LEFT JOIN
                                        attendance_records a ON s.oracleid = a.oracleid
                                                            AND d.date = DATE(a.clockingindate)
                                        WHERE s.oracleid = ? AND a.oracleid IS NULL 
                                  ");
        $res->execute( [ $this->oracleid ] );
        foreach ($res as $r) {
            $this->Cell(0, 10, $r['date'], 0, 1);
        }
    }
}# end class

if (!isset($_GET['oracleid']) || !isset($_GET['sdate']) || !isset($_GET['edate'])) {
    exit;
}

//
// GENERATE REPORT
//
	
	$pdf = new attendPDF($conn, $_GET['oracleid'], $_GET['sdate'], $_GET['edate']);
	$pdf->AliasNbPages();
	$pdf->setAutoPageBreak(1,25);
	$pdf->setMargins(15,15,15);
	$pdf->SetDrawColor(102);
	$pdf->SetFillColor(220);

	$pdf->AddPage();
	$pdf->attendanceReport();
	$pdf->AddPage();
	$pdf->absenceReport();
	$pdf->output('D','filename.pdf');

?>

where i can modify the code so that it will take all to one pdf file page?

Link to comment
https://forums.phpfreaks.com/topic/310457-merge-fpdf-files/#findComment-1576298
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.