Когда я нажимаю "загрузить", он должен сгенерировать payslip pdf, но показывает ошибку TCPDF: некоторые данные уже выведены, невозможно отправить файл PDF - PullRequest
1 голос
/ 26 марта 2020
    <?php

include ('сессия. php'); ?>

<body>
 <div id="site_content">
 <div id="content"><form method="post" action="#" id="show_salary" name="show_salary">
     <div class="form_settings">
       <h3>Select Month</h3>
       <p><select name="month" id="month">
            <option value="JAN">JAN</option>
            <option value="FEB">FEB</option>
            <option value="MARCH">MARCH</option>
            <option value="APR">APR</option>
            <option value="MAY">MAY</option>
            <option value="JUNE">JUNE</option>
            <option value="JULY">JULY</option>
            <option value="AUG">AUG</option>
            <option value="SEPT">SEPT</option>
            <option value="OCT">OCT</option>
            <option value="NOV">NOV</option>
            <option value="DEC">DEC</option>
        </select>
        <h3>Select Year</h3>
        <select name="year" id="year">
        <?php
             for ($i=2000; $i<=2050; $i++)
            {
         ?>
        <option value="<?php echo $i;?>"><?php echo $i;?></option>
         <?php
            }
         ?>
        </select>
        </p>
<p style="padding-top: 15px">
<input class="submit" type="submit" name="show" id="show" value="Show"/></p>
<input class="submit" type="submit" name="download" id="download" value="Download"/></p>
</div>

<?php
$salmonth=""; $salyear=""; $sname=""; $output=''; $content = ''; 
 $sid=$_GET['sid'];
if(isset($_POST['show']))
{       
 $sqlstaff = "SELECT staff_name FROM staff WHERE staff_id = '$sid'";
 $resultstaff = $con->query($sqlstaff);
 $rowstaff = $resultstaff->fetch_assoc();
 $sname=$rowstaff['staff_name'];
 $salmonth = mysqli_real_escape_string($con,$_POST['month']);
 $salyear = mysqli_real_escape_string($con,$_POST['year']);
 $sqlsal = "SELECT * FROM salary WHERE month = '$salmonth' and year='$salyear' and staff_id = '$sid'";
 $resultsal = $con->query($sqlsal);
 $row = $resultsal->fetch_assoc();
if($resultsal->num_rows >0)  
{    
    $content .= '  
            <h3 align="center">Pay Slip</h3><br />
            <table>
            <tr><th>Name</th><th>Bank</th><th>Branch</th></tr>
            <tr><td>'.$sname.'</td><td>'.$row["bank_name"].'</td><td>'.$row["branch"].'</td></tr>
            <tr><th>Account</th><th>Month</th><th>Year</th></tr>
            <tr><td>'.$row["ac_no"].'</td><td>'.$row["month"].'</td><td>'.$row["year"].'</td></tr>
            <tr><th>Basic</th><th>DA</th><th>HRA</th></tr>
            <tr><td>'.$row["bp"].'</td><td>'.$row["da"].'</td><td>'.$row["hra"].'</td></tr>  
            <tr><th>MA</th><th>Bonus</th><th>Gross</th></tr> 
            <tr><td>'.$row["medical"].'</td><td>'.$row["bonus"].'</td><td>'.$row["gross"].'</td></tr>
            <tr><th>P.Tax</th><th>GPF</th><th>Net</th></tr>  
            <tr><td>'.$row["ptax"].'</td><td>'.$row["gpf"].'</td><td>'.$row["net"].'</td></tr>';  
    $content .= '</table>';
    echo $content;
  }  
  else
  {
      $content.='No salary record';
  }
}
if(isset($_POST['download']))
{
    $output.= $content;
    require_once("tcpdf/tcpdf.php");
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Dipankar Das');
    $pdf->SetTitle('Payslip');
    $pdf->SetSubject('Payslip');
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 011', 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->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->SetFont('helvetica', '', 12);
    $pdf->AddPage();        
    $pdf->writeHTML($output);
    $pdf->Output('payslip.pdf', 'I');
}

?>

...