<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$formname = 'TAX INVOICE';
$maindb = 'hotmain';
$maindb2 = 'checkout';
//$trandb = 'saletran';
$file = 'checkout_pdf.php';
$source = "";
$zcomp = $_SESSION["comp_" . $dbname];
$fseries = $_SESSION["series_" . $dbname];

$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);

$mht = 'height:20px;';
$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];

$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d/%m/%Y') AS vouchdt FROM `$maindb` WHERE `vouchno`='$vouchno' ORDER BY `vouchno`") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry);
 
// browse($getmdata['persons']);
// die();

$mainqry2 = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d/%m/%Y') AS vouchdt FROM `$maindb2` WHERE `vouchno`='$vouchno' ORDER BY `vouchno`") or die(mysqli_error($conn));
$getmdata2 = mysqli_fetch_array($mainqry2);

$cmpname = mysqli_query($conn, "SELECT * From $zroot.`company` where code ='$zcomp'")or die(mysqli_error($conn));
$getcmpname = mysqli_fetch_array($cmpname);


require("library/fpdf/fpdf.php");

class pdf extends fpdf {

    function Footer() {

//Position at 1.5 cm from bottom
        $this->SetY(-15);

//Arial italic 8
        $this->SetFont('Arial', 'I', 8);
//Page number
        $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
    }

}

$pdf = new pdf('P', 'mm', 'A4');

$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 18);
$pdf->SetTextColor(0, 0, 0);


$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(193, 1, "$formname", 0, 0, 'C');
$pdf->Ln(5);

$pdf->SetFont('Arial', '', 12);
$pdf->SetTextColor(0, 0, 0);

$pdf->SetDrawColor(206, 169, 98);
$pdf->SetFont('Arial', '', 10);
$pdf->SetDrawColor(0, 0, 0);

$pdf->SetFont('Arial', 'IB', 12);
$pdf->Cell(130, 6, "  $getcmpname[name]", "TL", 0);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(23, 6, "Bill No. ", "T", 0);
$pdf->Cell(5, 6, ": ", "T", 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(35, 6, "$getmdata2[vouchno]", "TR", 0,"L");
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(130, 6, "  $getcmpname[add1]", "L", 0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(23, 6, "Register No. ", 0, 0);
$pdf->Cell(5, 6, ": ", 0, 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(35, 6, "$getmdata2[bookno]", "R", 0,"L");
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(130, 6, "  $getcmpname[add2]  $getcmpname[add3] ", "L", 0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(23, 6, "Room No. ", 0, 0);
$pdf->Cell(5, 6, ": ", 0, 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(35, 6, "$getmdata2[roomno]", "R", 0,"L");
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(130, 6, "  $getcmpname[mobile]", "LB", 0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(23, 6, "Date ", "B", 0);
$pdf->Cell(5, 6, ": ", "B", 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(35, 6, "$getmdata2[vouchdt]", "RB", 0,"L");
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(18, 6, "  Name : ", "LB", 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(175, 6, "$getmdata2[name]", "RB", 0,"L");
$pdf->Ln();

$pdf->SetFont('Arial', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFillColor(169, 185, 124);
$cl = 8;

$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(134, $cl, 'Particulars', 1, 0, 'C', 1);
$pdf->Cell(13, $cl, 'Nos.', 1, 0, 'R', 1);
$pdf->Cell(20, $cl, 'Rate', 1, 0, 'R', 1);
$pdf->Cell(26, $cl, 'Amount', 1, 0, 'R', 1);
$pdf->Ln();

$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(0, 0, 0);

$checkindt = date("d/m/Y H:i a", strtotime($getmdata2["chkin"])); 
$checkoutdt = date("d/m/Y H:i a", strtotime($getmdata2["chkout"])); 

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(134, $cl, "Check In - $checkindt   Check Out - $checkoutdt ", 1, 0, 'L', 1);
$pdf->Cell(13, $cl, "$getmdata2[daysno]", 1, 0, 'R', 1);
$pdf->Cell(20, $cl, "$getmdata2[rate]", 1, 0, 'R', 1);
$pdf->Cell(26, $cl, "$getmdata2[amount]", 1, 0, 'R', 1);
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(134, $cl, "No. of Persons ", 1, 0, 'L', 1);
$pdf->Cell(13, $cl, "$getmdata[persons]", 1, 0, 'R', 1);
$pdf->Cell(20, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(26, $cl, "", 1, 0, 'R', 1);
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(134, $cl, "Extra Charges ", 1, 0, 'L', 1);
$pdf->Cell(13, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(20, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(26, $cl, "$getmdata2[extra]", 1, 0, 'R', 1);
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(134, $cl, "Add Other ", 1, 0, 'L', 1);
$pdf->Cell(13, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(20, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(26, $cl, "$getmdata2[addoth]", 1, 0, 'R', 1);
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(134, $cl, "Discount  ", 1, 0, 'L', 1);
$pdf->SetFont('Arial', '', 9);
$pdf->Cell(13, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(20, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(26, $cl, "$getmdata2[ldisc]", 1, 0, 'R', 1);
$pdf->Ln();

$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(134, $cl, "TOTAL BILL  ", 1, 0, 'L', 1);
$pdf->Cell(13, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(20, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(26, $cl, "$getmdata2[billamt]", 1, 0, 'R', 1);
$pdf->Ln();

$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(134, $cl, "TOTAL ADVANCE  ", 1, 0, 'L', 1);
$pdf->SetFont('Arial', '', 9);
$pdf->Cell(13, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(20, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(26, $cl, "$getmdata2[advance]", 1, 0, 'R', 1);
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(134, $cl, "Receivable  ", 1, 0, 'L', 1);
$pdf->SetFont('Arial', '', 9);
$pdf->Cell(13, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(20, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(26, $cl, "$getmdata2[balance]", 1, 0, 'R', 1);
$pdf->Ln();

$rupees = rsword(round($getmdata2['billamt']));

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(14, $cl, "Rupees", 'LT', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(120, $cl, "$rupees", 'T', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(13, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(20, $cl, "", 1, 0, 'R', 1);
$pdf->Cell(26, $cl, "", 1, 0, 'R', 1);
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(150, $cl, "For", 'T', 0, 'R', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(43, $cl, "$getcmpname[name]", 'T', 0, 'L', 1);
$pdf->Ln(50);

$y_aqui2 = $pdf->Gety();

ob_end_clean();
$pdf->Output("$formname - $lparty[name]-" . $getmdata['vouchno'] . ".pdf", "I");
?>