<?php

include_once 'classes/common.php';
include_once 'classes/DB.class.php';
include_once 'session/admin-session.php';
require_once('tcpdf/tcpdf.php');
ini_set("display_errors", 0);

$db = new DB();
$com = new common();

$BookPkId = common::StrToDB($_REQUEST['BookPkId']);

/* Getting the Booking Related information */
$BookDetailArr = $db->selectWithCols("rcuesr_room_booking_tbl", "*", "room_book_pk_id='$BookPkId'");

foreach ($BookDetailArr as $BDA) {
    $bill_number = $BDA['bill_number'];
    $applicant_name = common::StrFromDb($BDA['applicant_name']);
    $applicant_post = common::StrFromDb($BDA['applicant_post']);
    $department = common::StrFromDb($BDA['department']);
    $mobile_number = $BDA['mobile_number'];
    $applicant_address = common::StrFromDb($BDA['applicant_address']);
    $id_type = $BDA['id_type'];
    $id_number = $BDA['id_number'];
    $event_option = $BDA['event_option'];
    $total_person = $BDA['total_person'];
    $total_days = $BDA['total_days'];
    $room_number = $BDA['room_number'];
    $arrival_date_time = DATE("d-m-Y", strtotime($BDA['arrival_date_time']));
    $departure_date_time = DATE("d-m-Y", strtotime($BDA['departure_date_time']));
    $purpose_visit = common::StrFromDb($BDA['purpose_visit']);
    $room_rate = $BDA['room_rate'];
    $adl_charges = $BDA['adl_charges'];
    $tax = $BDA['tax'];
    $paid_amount = $BDA['paid_amount'];
    $pan_number = $BDA['pan_number'];
    $gst_number = $BDA['gst_number'];

    $file_name_str = str_replace("/", "-", $bill_number) . ".pdf";
}

class MYPDF extends TCPDF {

    public function Header() {
        /*
        $this->SetFont('helvetica', 'B', 8);
        $view_tbl .= '';
        $this->writeHTML($view_tbl, true, false, true, false, '');
        $this->Cell(0, 0, ' ', 0, false, 'C', 0, '', 0, false, 'M', 'M');
         
         */
    }

    public function Footer() {
/*
        $this->SetY(-50);

        $this->SetFont('helvetica', 'I', 8);

        $view_tbl .= '';
        $this->writeHTML($view_tbl, true, false, true, false, '');
        $this->Cell(0, 0, ' ', 0, false, 'C', 0, '', 0, false, 'T', 'M');
 
 */
    }

}

$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('RCUES');
$pdf->SetTitle('RCUES');
$pdf->SetSubject('RCUES');
$pdf->SetKeywords('RCUES');
$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, '30', PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->AddPage('A4');
$today_date = date("Y-m-d");

 $viewTbl = '<!DOCTYPE html>
<html lang="en">
    <head>
        <style type="text/css">
            table,
            td {
                border: solid 2px black;
                /*  text-align: center;*/
                border-collapse: collapse;
            }

            .bold~tr td {
                border: solid 1px lightgray;
            }

            td {
                padding: 0.5em;
            }

            [colspan="4"][rowspan="2"] {
                height: 6em;
            }
        </style>
    </head>
    <p style="text-align: center">
        REGIONAL CENTER FOR URBAN AND ENVIRONMENT STUDIES</p>
    <p style="text-align: center">GUEST HOUSE ROOM RENT BILL</p>
   
    <table style="width: 100%; font-size: 12px;"  cellpadding="2">
        <tr>
            <td colspan="4" rowspan="5" valign="top" align="left" width="60%">To,<br>';
$viewTbl .= $applicant_name . ' Dept: ' . $department . '<br/>';
$viewTbl .= $applicant_address;
$viewTbl .= '</td>
            <td colspan="1" width="15%">Bill No.</td>
            <td colspan="2" width="25%">' . $bill_number . '</td>
        </tr>
        <tr>
            <td colspan="2">Receipt No.</td>
            <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2">Paid by DD No.</td>
            <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2">Dated</td>
            <td colspan="2">&nbsp;</td>
        </tr>

        <tr>
            <td colspan="4">Bank: </td> 
        </tr>
        <tr>

            <td colspan="4">PAN : ' . $pan_number . '</td>
            <td colspan="3">PAN : AABTR1550R</td>
        </tr><tr>

            <td colspan="4">GST : ' . $gst_number . '</td>
            <td colspan="3">GSTIN : 09AABTR1550RIZZ</td>
        </tr>

        <tr>
            <td style="width: 5%;">Sr.</td>
            <td style="width: 45%;">Particulars</td>
            <td style="width: 11%;">Check in</td>
            <td style="width: 11%;">Check out</td>
            <td style="width: 5%;">Days</td>
            <td style="width: 10%;">Rate</td>
            <td style="width: 10%;">Amount</td>
        </tr>
        <tr>
            <td>1</td>
            <td>' . $purpose_visit . '<br/>' . "Room No: " . $room_number . '</td>
            <td>' . $arrival_date_time . '</td>
            <td>' . $departure_date_time . '</td>
            <td>' . $total_days . '</td>
            <td>' . $room_rate . '</td>
            <td>' . $paid_amount . '</td>
        </tr>
        <tr>
             <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>

        <tr>
            <td colspan="6" align="right">Net Amount</td>

            <td>' . $paid_amount . '</td>
        </tr>


    </table>
    <br>
    <br>
    <p style="margin-left: 50px; font-size: 12px;">Note:- Please Issue Cheque or Draft in favour of Director RCUES</p>
    <p style="text-align: right;padding-right: 84px;font-size: 12px;">Hostel Manager</p>
</html>';

//echo $viewTbl;

$pdf->writeHTML($viewTbl, true, false, true, false, '');

$pdf->Output($file_name_str, "D");

?>