<?php session_start(); 
include("../../include/config.php"); 
include("../../include/connect_url.php"); 
include("../../include/date_time.php"); 
include("../../database/account.php");
include("../../include/lang.php"); 
include("../../include/session_login.php"); 

require_once('tcpdf_include.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 009');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.'  ', PDF_HEADER_STRING );


// 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);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

 
// add a page
$pdf->AddPage();
// set JPEG quality
$pdf->setJPEGQuality(75);

$query_transaction2 = mysql_query("SELECT * FROM tbl_transaction WHERE id='$_GET[t_id]'"); 
while($row= mysql_fetch_assoc($query_transaction2))
{
    $db_transaction2_id = $row['id'];
    $db_transaction2_transaction_no = $row['transaction_no'];
    $db_transaction2_patient_id = $row['patient_id'];
    $db_transaction2_pt_type_id = $row['pt_type_id'];
    $db_transaction2_remark = $row['remark'];
    $db_transaction2_user_id = $row['user_id'];
    $db_transaction2_date = $row['date'];
    $db_transaction2_time = $row['time'];
    $db_transaction2_a_status = $row['a_status'];
}

$query_patient_type2= mysql_query("SELECT * FROM tbl_patient_type WHERE id='$db_transaction2_pt_type_id'");
while($row= mysql_fetch_assoc($query_patient_type2))
{
$db_patient_type2_id= $row['id'];
$db_patient_type2_patient_type= $row['patient_type'];
}

$query_patient2 = mysql_query("SELECT * FROM tbl_patient WHERE id='$db_transaction2_patient_id'"); 
while($row= mysql_fetch_assoc($query_patient2))
{
    $db_patient2_id = $row['id'];
    $db_patient2_patient_no = $row['patient_no'];
    $db_patient2_image = $row['image'];
    $db_patient2_firstname = $row['firstname'];
    $db_patient2_middlename = $row['middlename'];
    $db_patient2_middlename_sub = substr($db_patient2_middlename,0,1);
    $db_patient2_lastname = $row['lastname'];
    $db_patient2_birth_date = $row['birth_date'];
    $db_patient2_gender = $row['gender'];
    $db_patient2_civil_status_id = $row['civil_status_id'];
    $db_patient2_nationality_id = $row['nationality_id'];
    $db_patient2_address = $row['address'];
    $db_patient2_phone_no = $row['phone_no'];
    $db_patient2_mobile_no = $row['mobile_no'];
    $db_patient2_email = $row['email'];
    $db_patient2_ref_name = $row['ref_name'];
    $db_patient2_ref_relationship_id = $row['ref_relationship_id'];
    $db_patient2_ref_address = $row['ref_address'];
    $db_patient2_ref_phone_no = $row['ref_phone_no'];
    $db_patient2_ref_mobile_no = $row['ref_mobile_no'];
    $db_patient2_date = $row['date'];
    $db_patient2_time = $row['time'];
    $db_patient2_a_status = $row['a_status'];
}



$tbl = '<table border="0" align="center" width="100%">
<tr>
<td><b>'.$lang['BILLING STATEMENT'].'</b></td>
</tr>
</table>
';
$pdf->writeHTML($tbl, true, false, false, false, '');





$tbl = '<table border="0" align="left" style="font-size:12px;">
<tr>
<td width="15%">'.$lang['Patient No'].':</td><td width="35%">'.$db_patient2_patient_no.'</td>
<td width="15%">'.$lang['Transaction No'].':</td><td width="35%">'.$db_transaction2_transaction_no.'</td>
</tr>
<tr>
<td>'.$lang['Patient Name'].':</td><td>'.$db_patient2_firstname.' '.$db_patient2_middlename_sub.' '.$db_patient2_lastname.' </td>
<td>'.$lang['Type'].':</td><td>'.$db_patient_type2_patient_type.'</td>
</tr>

<tr>
<td>'.$lang['Address'].':</td><td>'.$db_patient2_address.' </td>
<td>'.$lang['Contact'].':</td><td>'.$db_patient2_mobile_no.'/ '.$db_patient2_phone_no.'</td>
</tr>
</table>
';
$pdf->writeHTML($tbl, true, false, false, false, '');










$tbl = '<table border="1" align="left" style="font-size:12px;">
<tr>
<th width="32%">'.$lang['TRANSACTION CHARGES'].'</th>
<th width="17%">'.$lang['ITEM'].'</th>
<th width="17%">'.$lang['QTY'].'</th>
<th width="17%">'.$lang['PRICE'].'</th>
<th width="17%">'.$lang['TOTAL'].'</th>

</tr>
';
$query_transaction_charge2= mysql_query("SELECT * FROM tbl_transaction_charge WHERE transaction_id='$db_transaction2_id' AND a_status='1'");
while($row= mysql_fetch_assoc($query_transaction_charge2))
{
$db_transaction_charge2_id = $row['id'];
$db_transaction_charge2_transaction_charge_no = $row['transaction_charge_no'];
$db_transaction_charge2_date = $row['date'];
$db_transaction_charge2_time = $row['time'];

$tbl = $tbl . '<tr bgcolor="#eeeeee">
            <td align="left">'.$lang['Trans. Charge #'].' :'.$db_transaction_charge2_transaction_charge_no.' * '.$db_transaction_charge2_date.' '.$db_transaction_charge2_time.'</td>
            <td align="right"></td>
            <td align="right"></td>
            <td align="right"></td>
            <td align="right"></td>
            
          </tr>';
          
$query_transaction_charge_item2= mysql_query("SELECT * FROM tbl_transaction_charge_item WHERE transaction_charge_id='$db_transaction_charge2_id' AND a_status='1'");
while($row= mysql_fetch_assoc($query_transaction_charge_item2))
{
$db_transaction_charge_item2_id = $row['id'];
$db_transaction_charge_item2_item_id = $row['item_id'];
$db_transaction_charge_item2_qty = $row['qty'];
$db_transaction_charge_item2_price = $row['price'];

$db_transaction_charge_item2_total = $row['total'];


$db_transaction_charge_item2_total_all = $row['total'];

$db_transaction_charge_item2_total_all_nf += str_replace(' ','', str_replace(',00','', $db_transaction_charge_item2_total_all));
    //number format
    include("../../include/number_format.php");




$query_item2= mysql_query("SELECT * FROM tbl_item WHERE id='$db_transaction_charge_item2_item_id'");
while($row= mysql_fetch_assoc($query_item2))
{
$db_item2_id = $row['id'];
$db_item2_item = $row['item'];
}

$tbl = $tbl . '<tr >
            <td align="right"></td>
            <td align="left">'.$db_item2_item.'</td>
            <td align="right">'.$db_transaction_charge_item2_qty.'</td>
            <td align="right">'.$db_currency_code1.''.$db_transaction_charge_item2_price.'</td>
            <td align="right">'.$db_currency_code1.''.$db_transaction_charge_item2_total.'</td>
          </tr>';
}  
          
          
          
          
}
if($db_transaction_charge_item2_total_all_nf_nf){$db_transaction_charge_item2_total_all_nf_nf_comp = "$db_currency_code1$db_transaction_charge_item2_total_all_nf_nf";}else{$db_transaction_charge_item2_total_all_nf_nf_comp=" -";}

$tbl = $tbl . '<tr >
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td align="right"><br /><br /><b>'.$lang['TOTAL'].':</b> '.$db_transaction_charge_item2_total_all_nf_nf_comp.'</td>
          </tr>';

     

$tbl = $tbl . '</table>';
$pdf->writeHTML($tbl, true, false, false, false, '');






if($db_transaction2_pt_type_id==1){
$tbl = '<table border="1" align="left" style="font-size:12px;">
<tr>
<th width="32%">'.$lang['ROOM CHARGES'].'</th>
<th width="17%"></th>
<th width="17%"></th>
<th width="17%" ></th>
<th width="17%"></th>

</tr>
';
$query_transaction_room2= mysql_query("SELECT * FROM tbl_transaction_room WHERE transaction_id='$db_transaction2_id' AND a_status='1'");
while($row= mysql_fetch_assoc($query_transaction_room2))
{
$db_transaction_room2_id = $row['id'];
$db_transaction_room2_room_id = $row['room_id'];
$db_transaction_room2_bed_id = $row['bed_id'];
$db_transaction_room2_price = $row['price'];

$db_transaction_room2_date = $row['date'];
$db_transaction_room2_time = $row['time'];

$query_room2= mysql_query("SELECT * FROM tbl_room WHERE id='$db_transaction_room2_room_id'");
while($row= mysql_fetch_assoc($query_room2))
{
$db_room2_id = $row['id'];
$db_room2_room = $row['room'];
}

$query_bed2= mysql_query("SELECT * FROM tbl_bed WHERE id='$db_transaction_room2_bed_id'");
while($row= mysql_fetch_assoc($query_bed2))
{
$db_bed2_id = $row['id'];
$db_bed2_bed = $row['bed'];
}


$tbl = $tbl . '<tr bgcolor="#eeeeee">
            <td align="left"> '.$db_room2_room.' / '.$db_bed2_bed.' * '.$db_transaction_room2_date.' '.$db_transaction_room2_time.'</td>
            <td align="right"></td>
            <td align="right"></td>
            <td align="right">'.$db_currency_code1.''.$db_transaction_room2_price.'</td>
            <td align="right">'.$db_currency_code1.''.$db_transaction_room2_price.'</td> 
          </tr>';      
}

$tbl = $tbl . '<tr >
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td align="right"><br /><br /><b>'.$lang['TOTAL'].':</b> '.$db_currency_code1.''.$db_transaction_room2_price.'</td>
          </tr>';

$tbl = $tbl . '</table>';
$pdf->writeHTML($tbl, true, false, false, false, '');

}





$tbl = '<table border="0" align="left" style="font-size:12px;">
<tr style="font-size:12px;">
<td><b>'.$lang['Rendered By'].':</b></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr style="font-size:14px;">
<td><br /><hr width="100%"><b>'.$db_user_firstname.' '.$db_user_middlename_sub.' '.$db_user_lastname.'</b><br>'.$lang['Billing Clerk'].'</td>
<td><br /></td>
<td><br /></td>
<td ><br /></td>
</tr>
</table>
';
$pdf->writeHTML($tbl, true, false, false, false, '');




//Closed
$pdf->Output('print.pdf', 'I');

