<?php

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

//$formname = 'Annexure 2 ';
$maindb = 'visamain';
$trandb = 'visatran';
$file = 'agentinv.php';
$formname = "pdf";
$keyfld = "vouchno";
//$source = "CP";
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);
$mht = 'height:20px;';
$admin = $_SESSION["admin_" . $dbname];

$broker = $_POST["agent"];
$mfrmdate = $_POST["frmdate"];
$mtodate = $_POST["todate"];

$fdate = date("d-m-Y", strtotime($mfrmdate));
$tdate = date("d-m-Y", strtotime($mtodate));

$mainqry = mysqli_query($conn, "SELECT a.*,DATE_FORMAT(a.`vouchdt`, '%d-%m-%Y') as vouchdt, b.paxname, b.passport
                                from $maindb a, $trandb b  where a.`broker` = '$broker' and a.myvouch = b.myvouch 
                                       and a.`vouchdt` >= '$mfrmdate' AND a.`vouchdt` <= '$mtodate' ")or die(mysqli_error($conn));

$tranqry = mysqli_query($conn, "SELECT sum(a.mofa)as smofa, 
                                sum(a.stamp)as sstamp, sum(a.imig)as simig, sum(a.misc)as smisc, 
                                sum(a.total)as stotal, sum(a.disc)as sdisc, sum(a.tot) as stot
                                from $maindb a, $trandb b  where a.`broker` = '$broker' and a.myvouch = b.myvouch 
                                and a.`vouchdt` >= '$mfrmdate' AND a.`vouchdt` <= '$mtodate' ")or die(mysqli_error($conn));

$nation = 'INDIAN';
//$paxname = $fetdata['paxname'];
//$mydt = $fetdata['mydt'];
//$paxname = $fetdata['paxname'];
//$paxname = $fetdata['paxname'];

$getcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE `code`= '1'")or die(mysqli_error($conn));
$comp = mysqli_fetch_array($getcomp);
//$gettran = mysqli_query($conn, 
//print table($getcomp);

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');
    }

}

//browse('udar');

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

$pdf->AliasNbPages();
$pdf->AddPage();

//$pdf->Ln(70);
$pdf->SetFont('Arial', '', 14);
$pdf->SetTextColor(0, 0, 0);
//$pdf->Cell(10, 6, "", 0, 0, 'L');
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(180, 6, "$comp[name]", 0, 0, 'L');
$pdf->Ln();
$pdf->SetFont('Arial', '', 9);
$pdf->Cell(180, 6, "$comp[add1]", 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(180, 6, "$comp[add2]", 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(180, 6, "$comp[add3]", 0, 0, 'L');
$pdf->Ln(10);

$subject = "Statement:- For the period " . $fdate . ' To ' . $tdate;

$pdf->SetFont('Arial', 'B', 11);
//$pdf->Cell(35, 6, "", 0, 0, 'L');
$pdf->Cell(200, 6, $subject, 0, 0, 'C');
$pdf->Ln(10);
$pdf->Cell(35, 6, "Bill To:", 0, 0, 'L');
$pdf->Cell(80, 6, "", 0, 0, 'L');
$pdf->Ln();
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(35, 6, $broker, 0, 0, 'L');
$pdf->Cell(80, 6, "", 0, 0, 'L');
$pdf->Ln();
$pdf->Ln(6);
$pdf->SetFillColor(148,143,227);
$pdf->SetFont('Arial', '', 11);
$pdf->SetTextColor(255,255,255);
$pdf->Cell(10, 6, "Sr", 1,0,'C','R');
$pdf->Cell(25, 6, "Date", 1,0,'C','R');
$pdf->Cell(30, 6, "File No.", 1,0,'C','R');
$pdf->Cell(65, 6, "Pax Name", 1,0,'C','R');
$pdf->Cell(30, 6, "Visa No", 1,0,'C','R');
$pdf->Cell(30, 6, "Passport",1,0,'C','R');
$pdf->SetTextColor(0,0,0);
$pdf->Ln();
$ctr = 0;

while ($pmain = mysqli_fetch_array($mainqry)) {
//    $paxname = $pmain['srno'];
    $ctr++;
    $vouchdt = $pmain['vouchdt'];
    $manualno = $pmain['manualno'];
    $paxname = $pmain['paxname'];
    $visano = $pmain['visano'];
    $passport = $pmain['passport'];

    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(10, 6, "$ctr", 1, 0, 'C');
    $pdf->Cell(25, 6, "$vouchdt", 1, 0, 'C');
    $pdf->Cell(30, 6, "$manualno", 1, 0, 'C');
    $pdf->SetFont('Arial', '', 9);
    $pdf->Cell(65, 6, "$paxname", 1, 0, 'C');
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(30, 6, "$visano", 1, 0, 'C');
    $pdf->Cell(30, 6, "$passport", 1, 0, 'C');
    $pdf->Ln(6);
}
$pdf->Ln(6);


$tmain = mysqli_fetch_array($tranqry);
$mofa = $tmain['smofa'];
$stamp = $tmain['sstamp'];
$imig = $tmain['simig'];
$mis = $tmain['smis'];
$misc = $tmain['smisc'];
$total = $tmain['stotal'];
$disc = $tmain['sdisc'];
$final = $tmain['stot'];

$rfinal = round($final);
$mfinal = rsword($rfinal);

$pdf->Cell(140, 6, "", 0, 0, 'C');
$pdf->Cell(20, 6, "Mofa", 0, 0, 'R');
$pdf->Cell(30, 6, $mofa, 1, 0, 'R');
$pdf->Ln();
$pdf->Cell(140, 6, "", 0, 0, 'C');
$pdf->Cell(20, 6, "Stampping", 0, 0, 'R');
$pdf->Cell(30, 6, $stamp, 1, 0, 'R');
$pdf->Ln();
$pdf->Cell(140, 6, "", 0, 0, 'C');
$pdf->Cell(20, 6, "Immigration", 0, 0, 'R');
$pdf->Cell(30, 6, $imig, 1, 0, 'R');
$pdf->Ln();
$pdf->Cell(140, 6, "", 0, 0, 'C');
$pdf->Cell(20, 6, "M/s", 0, 0, 'R');
$pdf->Cell(30, 6, $mis, 1, 0, 'R');
$pdf->Ln();
$pdf->Cell(140, 6, "", 0, 0, 'C');
$pdf->Cell(20, 6, "Miscellaneous", 0, 0, 'R');
$pdf->Cell(30, 6, $misc, 1, 0, 'R');
$pdf->Ln();
$pdf->Cell(140, 6, "", 0, 0, 'C');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(20, 6, "Total", 0, 0, 'R');
$pdf->Cell(30, 6, $total, 1, 0, 'R');
$pdf->Ln();
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(52, 6, "INVOICE AMOUNT IN WORDS", 0, 0, 'L');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(88, 6, "", 0, 0, 'L');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(20, 6, "Discount", 0, 0, 'R');
$pdf->Cell(30, 6, $disc, 1, 0, 'R');
$pdf->Ln();
//$pdf->MultiCell(52, 6, $mfinal . " Only", '1','L',0);
$pdf->SetFillColor(220,220,220);
$pdf->Cell(130, 6, $mfinal . " Only", 1,0,'L','R');
$pdf->Cell(10, 6, "", 0, 0, 'L');
$pdf->Cell(20, 6, "Final Amount", 0, 0, 'R');
$pdf->Cell(30, 6, $final, 1,0,'R','R');
$pdf->Ln(20);
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(130, 6, "", 0, 0, 'L');
$pdf->Cell(60, 6, "For, $comp[name]", 0, 0, 'C');
$pdf->Ln(20);
$pdf->Cell(130, 6, "", 0, 0, 'L');
$pdf->Cell(60, 6, "Authorised Signatory", 0, 0, 'C');


ob_end_clean();
$pdf->Output("Annexure I Normal-" . $getmdata['vouchno'] . ".pdf", "I");
?>
         
