TCPDF for getting database values

 <?php        
         $pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle('Salary Slip');
$pdf->SetHeaderMargin(30);
$pdf->SetTopMargin(20);
$pdf->setFooterMargin(20);
$pdf->SetAutoPageBreak(true);
$pdf->SetAuthor('Author');
$pdf->SetDisplayMode('real', 'default');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING . "\n" . "\n" . "PAYSLIP FOR THE MONTH OF " . date('M-Y'));

// 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 image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
 $pdf->SetCreator(PDF_CREATOR);
 $pdf->SetFont('dejavusans', '', 10);
            // Add a page
            $pdf->AddPage();


$htmlcontent = "<head>
<style>
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    padding: 5px;
    text-align: left;    
}
</style>
</head>


<div class='row'>
   

    <div class='col-lg-12'>
        <section class='panel'>";

            $htmlcontent .= "<div class='panel-heading pull-right'>Issue Date: ". date('M-d-Y') ."</div>";
            $htmlcontent .= "<div class='panel-body'>
              
                <table style='width:100%'>
                      
                        <tr>
                            
                           <th>Emp Role Id :</th>
                           <td>".  $result->id ."</td>
                           <th>Employee Name :</th>
                           <td>" .  $personal->firstname . "</td>";
                          
                           
                          
              $htmlcontent .="
                        </tr>
                        <tr>
                            <th>Department:</th>
                            <td>" . $prof->department . "</td>
                             <th>Bank Acc/No:</th>
                           <td>" . $other->accno . "</td>";
                 $htmlcontent .="         
                        </tr>
                         <tr>
                            <th>Designation:</th>
                              <td>" . $prof->designation . "</td>
                             <th>PAN No:</th>
                           <td>" . $other->panno . "</td>";
                  $htmlcontent .="         
                        </tr>
                        <tr>
                            <th>Date Of Birth:</th>
                              <td>" .  $personal->dob . "</td>
                             <th>Date Of Joining:</th>
                           <td>" . $other->doj . "</td>
                           
                        </tr>
                </table>
                <br>
                <br>
                <br>";
                  $htmlcontent .="
                <table style='width:100%'>
                    
                       
                        <tr>
                            <th>Earnings </th>
                            <th>Amount :</th>
                            
                            <th>Deductions</th>
                            <th>Amount</th>
                            
                        </tr>
                  
                    <tbody>
                        <tr>
                            <td>
                                <p>Basic</p>
                                <p>House Rent Allowance</p>
                                <p>Conveyance Allowance</p>
                                <p>Advance Statutory Bonus</p>
                                <p>Shift Allowance</p>
                                 <p>Arrear-Taxable Allowance</p>
                                  <p>Other Taxable Allowance</p>
                                   <p>Special Incentive</p>
                                    <p>Arrear Special Incentive</p>
                                     <p>Other Payment</p>
                                
                            </td>
                            <td>
                                
                                <p>" . $earnings->basic . ".00</p>
                                  <p>" . $earnings->hra . ".00</p>
                                 <p>" . $earnings->ca . ".00</p>
                                   <p>" . $earnings->asb . ".00</p>
                                   <p>" . $earnings->shiftallowance . ".00</p>
                                   <p>" . $earnings->arrear . ".00</p>
                                     <p>" . $earnings->otherallowancetax . ".00</p>
                                      <p>" . $earnings->specialincentive . ".00</p>
                                      <p>" . $earnings->arrearspecialincentive . ".00</p>
                                       <p>" . $earnings->otherpayment . ".00</p>
                                
                               
                            </td>
                             <td>
                                <p>Provident Fund</p>
                                <p>Professional Tax</p>
                                <p>Transport Deduction</p>
                                <p>Income Tax</p>
                            
                                
                            </td>
                             <td>
                                
                              <p>" .  $deductions->pf . ".00</p>
                               <p>" . $deductions->ptax . ".00</p>
                               <p>" .   $deductions->transport . ".00</p>
                                 <p>" .   $deductions->incometax . ".00</p>
                               
                            </td>
                        </tr>
                        <tr>
                            <td>Total Earnings:</td>
                            <td>
                                 <p>" . $earn =( $earnings->basic + 
                                 $earnings->hra +
                                 $earnings->ca +
                                 $earnings->asb +
                                 $earnings->shiftallowance +
                                 $earnings->arrear +
                                 $earnings->otherallowancetax +
                                 $earnings->specialincentive +
                                 $earnings->arrearspecialincentive +
                                 $earnings->otherpayment) . ".00</p>
                            </td>
                            <td>Total Deductions:</td>
                            <td>
                                  <p>" . $ded =( $deductions->pf +
                                          $deductions->ptax +
                                          $deductions->transport +
                                         $deductions->incometax) . ".00</p>
                            </td>
                        </tr>
                    </tbody>
                  </table>
                <br>
                <br>";
                  $htmlcontent .="
                <table style='width:100%'>
                     <tr>
                         
                         <th>Net Pay:</th>
                         <td>Rs." . $net=( $earn - $ded) . ".00</td>
                        </tr>
                        <tr>
                            <th>In Words.</th>
                            <td>Rupees</td>
                        </tr>
                </table>
                    
                   
                
            </div>
            <div class='panel-footer'></div>
        </section>
    </div>
     
</div>";
$pdf->writeHTML($htmlcontent, true, 0, true, 0); ob_clean();
$pdf->lastPage();
$pdf->Output('slip.pdf', 'I');
?>

only the table headings appear but not php values

<offtopic>
@roopam_kaur when you post code in the forum, you need to format it. To do so you can either select all the code and click the </> button, or type 3 backticks ``` on a separate line both before and after the code block.
</offtopic>

Can you show the code where the PHP values are created? I can see you using them, but not where they come from. Presumably you have checked to see that they have values in them?

public function generatepdf($employee_id)
          {
              
               
		
$this->load->library('Pdf');


$this->data['result'] = $this->salary_m->getEmployeeRecords($employee_id);
                 $this->data['personal'] = $this->salary_m->getPersonalDetails($employee_id);
                    $this->data['earnings'] = $this->salary_m-> getSalaryDetails($employee_id);
   $this->data['deductions'] = $this->salary_m->getDeductionDetails($employee_id);
      $this->data['other'] = $this->salary_m->getOtherDetails($employee_id);
         $this->data['prof'] = $this->salary_m->getProfessionalDetails($employee_id);



$this->load->view('admin/emp/pdfslip');

having any idea to what is wrong?

Sorry, nothing jumps out.

I’m wondering about variable scope, but I’m not familiar with the method you use to call the code that produces the PDF:

$this->load->view('admin/emp/pdfslip');

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.