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

mysqli_query($conn, "SET NAMES 'utf8'");
mysqli_query($conn, 'SET CHARACTER SET utf8');

header('Content-Type: text/html;charset=UTF-8');
ini_set('default_charset', 'utf-8');

$maindb = 'visamain';
$trandb = 'visatran';
$file = 'pax_pdf.php';
$keyfld = "myvouch";

$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);
$mht = 'height:20px;';
$admin = $_SESSION["admin_" . $dbname];

$myvouch = $_REQUEST["myvouch"];
$ppno = $_REQUEST["passport"];

$result = mysqli_query($conn, "SELECT *, date_format(`vouchdt`,'%d-%m-%Y') as mydt FROM `$maindb` WHERE $keyfld='$myvouch'") or die(mysqli_error($conn));
$get = mysqli_fetch_array($result);

$qry = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `myvouch`='$get[myvouch]' AND passport='$ppno' ORDER BY srno") or die(mysqli_error($conn));
$row = mysqli_fetch_array($qry);

if ($get['visatype'] == 'W') {
    $vtype = "Work";
} elseif ($get['visatype'] == 'F') {
    $vtype = "Family";
} elseif ($get['visatype'] == 'R') {
    $vtype = "Residence";
} elseif ($get['visatype'] == 'V') {
    $vtype = "Visit";
} else {
    $vtype = "";
}

$getpaid = $get['paidby'];
$fetpaid = [
    'C' => 'Cash',
    'R' => 'Credit',
    'U' => 'UPI / RTGS',
];
$paidby = $fetpaid[$getpaid];
$getcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE `code`= '1'")or die(mysqli_error($conn));
$comp = mysqli_fetch_array($getcomp);

require_once("library/TCPDF/tcpdf.php");

$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8' ,false);

$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// $pdf->AliasNbPages();
$pdf->AddPage();

$pdf->SetFont('freeserif', '', 14);
$pdf->SetTextColor(0, 0, 0);
$pdf->Image('images/logoeng.png', 0, 5, 180, 30, 'PNG');
$pdf->ln(15);
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(190, 6, "$comp[add1]" . "$comp[add2]", 0, 0, 'C');
$pdf->Ln();
$pdf->Cell(190, 6, "$comp[add3] " . "$comp[city] " . " $comp[pin]". " " . "Tel: $comp[tel] " . "Mob: +$comp[mobile]", 0, 0, 'C');
$pdf->Ln(20);

$pdf->Image($row['imagepath'], 10, 40, 30, 30, 'JPG');
$pdf->SetFont('freeserif', 'B', 15);
$pdf->Cell(70, $ln, "", 0, 0, 'L');
$pdf->Cell(20, $ln, "File No.:", 0, 0, 'L');
$pdf->Cell(50, $ln, " $get[manualno]", 0, 0, 'L');
$pdf->ln(13);
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(171, $ln, "Date:", 0, 0, 'R');
$pdf->Cell(25, $ln, " $get[mydt]", 0, 0, 'R');
$pdf->ln(7);

$ln = 7;
$pdf->SetFont('freeserif', '', 12);
$pdf->Cell(20, $ln, "Visa Type:", 'LT', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(176, $ln, "$vtype", 'TR', 0, 'L');
$pdf->Ln();

$pdf->SetFont('freeserif', '', 12);
$pdf->Cell(14, $ln, "Agent:", 'L', 0, 'L');
$pdf->SetFont('freeserif', 'B', 11);
$pdf->Cell(65, $ln, "$get[broker]", 0, 0, 'L');
$pdf->SetFont('freeserif', '', 12);
$pdf->Cell(27, $ln, "Sponsor Name:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 11);
$pdf->Cell(90, $ln, "$get[sponsor]", 'R', 0, 'L');
$pdf->Ln();

$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(17, $ln, "Visa No.:", 'L', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(52, $ln, "$get[visano]", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(13, $ln, "ID No:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(35, $ln, "$get[idno]", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(13, $ln, "Email:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(66, $ln, "$get[email]", 'R', 0, 'L');
$pdf->Ln();

$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(12, $ln, "Place:", 'L', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(57, $ln, "$get[sector]", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(17, $ln, "Visa Qty:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(31, $ln, "$get[visaqty]", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(10, $ln, "Hijri:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(69, $ln, "$get[hijridate]", 'R', 0, 'L');
$pdf->Ln();

$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(16, $ln, "Paid By:", 'LB', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(53, $ln, "$paidby", 'B', 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(22, $ln, "Created By:", 'B', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(105, $ln, "$get[createby]", 'RB', 0, 'L');
$pdf->Ln(10);

$DOB = date("d-m-Y", strtotime($row['dob'])); 
$getsex = $row['sex'];
$fetsex = [
    'F' => 'Female',
    'M' => 'Male',
];
$sex = $fetsex[$getsex];
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(21, $ln, "Pax Name:", 'LT', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(80, $ln, "$row[paxname]", 'T', 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(8, $ln, "Sex:" , 'T', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(40, $ln, " $sex", 'T', 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(15, $ln, "Passport:" , 'T', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(32, $ln, " $row[passport]", 'TR', 0, 'L');
$pdf->Ln();

$getdelv = $row['delvstatus'];
$fetdelv = [
    'E' => 'ECR',
    'N' => 'ECNR',
];
$delvstatus = $fetdelv[$getdelv];
// $pdf->SetFont('aefurat', '', 12);
// $pdf->Cell(21, $ln, "Mofa Amt:", 'L', 0, 'L');
// $pdf->SetFont('freeserif', 'B', 12);
// $pdf->Cell(60, $ln, "$row[mofamt_mod]", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(24, $ln, "Immigration:" , 'L', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(20, $ln, "$delvstatus", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(12, $ln, "DOB:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(30, $ln, "$DOB", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(17, $ln, "Religion:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 11);
$pdf->Cell(30, $ln, "$row[religion]", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(12, $ln, "POB:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(51, $ln, "$row[plbirth]", 'R', 0, 'L');
// $pdf->Cell(90, $ln, "Stamp Amt:" . " " . "$row[stampamt_mod]", 'R', 0, 'R');
$pdf->Ln();

$issuedt = date("d-m-Y", strtotime($row['issdate'])); 
$doe = date("d-m-Y", strtotime($row['doe'])); 
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(11, $ln, "POI:", 'L', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(40, $ln,"$row[issplace]", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(18, $ln, "Duration:" , 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(30, $ln, "$row[periodstay]", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(10, $ln, "DOI:" , 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(30, $ln, "$issuedt", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(11, $ln, "DOE:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(46, $ln, "$doe", 'R', 0, 'L');
// $pdf->Cell(90, $ln, "Immigration:" . " " . "$row[imigamt_mod]", 'R', 0, 'R');
$pdf->Ln();

if ($row['stampdate'] != '0000-00-00'){
    $stampdt = date("d-m-Y", strtotime($row['stampdate'])); 
} else {
    $stampdt = "";
}
if ($row['releasedt'] != '0000-00-00'){
    $releasedt = date("d-m-Y", strtotime($row['releasedt'])); 
} else {
    $releasedt = "";
}
if ($row['releasedt'] != '0000-00-00'){
$submissiondt = date("d-m-Y", strtotime($row['submission_date'])); 
} else {
    $submissiondt = "";
}
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(23, $ln, "Stamp Date:", 'L', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(28, $ln, " $stampdt", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(18, $ln, "Released:" , 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(28, $ln, "$releasedt", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(22, $ln, "Submission:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(28, $ln, " $submissiondt", 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(18, $ln, "Category:", 0, 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);

$pdf->Cell(31, $ln, " $row[category]", 'R', 0, 'L');
// $pdf->Cell(90, $ln, "M/s Amt:" . " " . "$row[mis_mod]", 'R', 0, 'R');
$pdf->Ln();

$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(21, $ln, "Mofa No 1:", 'LB', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(30, $ln, "$row[mofano]", 'B', 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(21, $ln, "Mofa No 2:", 'B', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(30, $ln, "$row[mofano2]", 'B', 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(21, $ln, "Mofa Date:", 'B', 0, 'L');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(73, $ln, "$row[mofa_date]", 'RB', 0, 'L');
$pdf->Ln(10);
// $pdf->Cell(90, $ln, "miscellaneous:" . " " . "$row[misc_mod]", 'R', 0, 'R');

$pdf->SetFont('aefurat', '', 12);
if($get['remark'] != ''){
    $pdf->Cell(125, $ln,  "REMARKS" , 0, 0, 'L');
} else {
    $pdf->Cell(125, $ln,  "" , 0, 0, 'L');
}
$pdf->Cell(26, $ln, "Mofa Amt" , 1, 0, 'R');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(45, $ln, "$row[mofamt_mod]", 1, 0, 'R');
$pdf->Ln(8);

$pdf->Cell(125, $ln,  "$get[remark]" , 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(26, $ln, "Stamp Amt" , 1, 0, 'R');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(45, $ln, "$row[stampamt_mod]", 1, 0, 'R');
$pdf->Ln(8);

$pdf->Cell(125, $ln,  "$get[remark2]" , 0, 0, 'L');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(26, $ln, "Immigration" , 1, 0, 'R');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(45, $ln, "$row[imigamt_mod]", 1, 0, 'R');
$pdf->Ln(8);

$pdf->Cell(125, $ln,  " " , 0, 0, 'R');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(26, $ln, "M/s" , 1, 0, 'R');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(45, $ln, "$row[mis_mod]", 1, 0, 'R');
$pdf->Ln(8);

$pdf->Cell(125, $ln,  " " , 0, 0, 'R');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(26, $ln, "Miscellaneous" , 1, 0, 'R');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(45, $ln, "$row[misc_mod]", 1, 0, 'R');
$pdf->Ln(8);

$pdf->Cell(125, $ln,  " " , 0, 0, 'R');
$pdf->SetFont('aefurat', '', 12);
$pdf->Cell(26, $ln, "Total" , 1, 0, 'R');
$pdf->SetFont('freeserif', 'B', 12);
$pdf->Cell(45, $ln, "$row[memcash]", 1, 0, 'R');
$pdf->Ln();


ob_end_clean();
$pdf->Output("Pax PDF" . ".pdf", "D");
