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

$maindb = "visamain";
$trandb = "visatran";
$trandb1 = "category";
$formname = "Blank Amount Register";
$file = "register_fr.php";
$entfile = "entry.php";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);


$getpmain = mysqli_query($conn, "SELECT a.*, DATE_FORMAT(a.`vouchdt`, '%d-%m-%Y') as vouchdt, DATE_FORMAT(a.`hijridate`, '%d-%m-%Y')
                            as hijridt, b.`vouchno`, b.`passport`,b.paxname,b.mofano,b.mofano2  FROM $maindb a left join $trandb b on 
                            a.vouchno = b.vouchno and a.visatype = b.visatype where a.total <= 0 ORDER BY a.`vouchdt` DESC") or die(mysqli_error($conn));

$get = mysqli_num_rows($getpmain);
include("includes/linkshead.php");
?>
</head>
<style>
    .tblhead>th {
        background-color: #F5F5F5;
        color: #C45254;
        width: 10%;
    }
    .scroll{
        height:1000px;
        overflow-y: auto;
    }
    .stick{
        position: sticky;
        position: -webkit-sticky;
        top: 0;
        background: #7f949d;
        z-index: 10;

    }
</style>

<body>
    <div class="container">
        <!-- <?php include("includes/head_rep.php"); ?> -->

        <?php
        $ctr = 1;
        $ctr2 = 0;
        ?>
        <div class="row">
            <div class="col-lg-12 pad scroll" >
                <table class="table table-condensed table-bordered">
                    
                    <tr class="mySearchTr clickable-row stick">
                        <th class="">Sr</th>
                        <th class="">Date</th>
                        <th class="">File No</th>
                        <th class="">Agent</th>
                        <th class="">Pax Name</th>
                        <th class="">Visa No</th>
                        <th class="">Passport No</th>
                        <th class="">Mofa No.</th>
                        <th class="">Mofa No.2</th>
                        <th class="text-right">Mofa</th>
                        <th class="text-right">Stamping</th>
                        <th class="text-right">Immigration</th>
                        <th class="text-right">M/s.</th>
                        <th class="text-right">Misc.</th>
                        <th class="text-right">Total</th>
                        <th class="text-right">Discount</th>
                        <th class="text-right">Final Amt.</th>
                    </tr>
                    <?php
                    $ftot = 0;
                    $mistot = 0;
                    $misctot = 0;
                    $stot = 0;
                    $moftot = 0;
                    $itot = 0;
                    $ttot = 0;
                    $dtot = 0;

                    while ($pmain = mysqli_fetch_array($getpmain)) {
                        $imig = $pmain['imig'];
                        $stamp = $pmain['stamp'];
                        $mis = $pmain['mis'];
                        $mofano = $pmain['mofa'];
                        $misc = $pmain['misc'];
                        $total = $pmain['total'];
                        $disc = $pmain['disc'];
                        $tot = $pmain['tot'];

                        // Echo"<tr data-href='entry.php' class='clickable-row2' style='cursor: pointer;' [target]='_blank'>";
                        
                        echo "<tr>";
                        echo "<td>$ctr</td>";
                        echo "<td>$pmain[vouchdt]</td>";
                        echo "<td><a target='_blank' href='entry.php?mode=edit&myvouch=$pmain[myvouch]'>$pmain[manualno]</a></td>";
                        echo "<td>$pmain[broker]</td>";
                        echo "<td>$pmain[paxname]</td>";
                        echo "<td>$pmain[visano]</td>";
                        echo "<td>$pmain[passport]</td>";
                        echo "<td>$pmain[mofano]</td>";
                        echo "<td>$pmain[mofano2]</td>";

                        echo "<td class='text-right'>$pmain[mofa]</td>";
                        echo "<td class='text-right'>$pmain[stamp]</td>";
                        echo "<td class='text-right'>$pmain[imig]</td>";
                        echo "<td class='text-right'>$pmain[mis]</td>";

                        echo "<td class='text-right'>$pmain[misc]</td>";
                        echo "<td class='text-right'>$pmain[total]</td>";
                        echo "<td class='text-right'>$pmain[disc]</td>";
                        echo "<td class='text-right'>$pmain[tot]</td>";
                        echo "</tr>";

                        $ftot = $ftot + $tot;
                        $mistot = $mistot + $mis;
                        $misctot = $misctot + $misc;
                        $moftot = $mofano + $moftot;
                        $stot = $stamp + $stot;
                        $ttot = $ttot + $total;
                        $dtot = $dtot + $disc;
                        $itot = $itot + $imig;
                        $ctr++;
                    }
                    echo "<tr>";
                    echo "<td></b></td>";
                    echo "<td></b></td>";
                    echo "<td></b></td>";
                    echo "<td></b></td>";
                    echo "<td class='text-right'></b></td>";
                    echo "<td></b></td>";

                    echo "<td class='text-right text-danger'><b>Total</b></td>";
                    echo "<td class='text-right text-danger'><b>$moftot</b></td>";
                    echo "<td class='text-right text-danger'><b>$stot</b></td>";
                    echo "<td class='text-right text-danger'><b>$itot</b></td>";

                    echo "<td class='text-right text-danger'><b>$mistot</b></td>";

                    echo "<td class='text-right text-danger'><b>$misctot</b></td>";
                    echo "<td class='text-right text-danger'><b>$ttot</b></td>";
                    echo "<td class='text-right text-danger'><b>$dtot</b></td>";
                    echo "<td class='text-right text-danger'><b>$ftot</b></td>";
                    echo "<td><b></b></th>";

                    echo "</tr>";
                    // echo "<br>";
                    echo "</table>";


                    //                     if (isset($_POST["excel"])) {
                    //                         $contents .= "Sr., Date, File No., Agent, Sponsor, Visa Type, Visa No., Visa Qty, Id no., Place, Hijri, Pax Name, Sex, Passport no, DOB, POB, POI, Stay Period, DOI, Stamp Date, Immigration status, Category, Mofa no., Mofa no.2, Mofa, Stamping, Immigration, M/s, Miscellaneous, Total, Discount, Final Amt\n";
                    //                         $totamt = 0;

                    //                         echo ucwords($columnHeader) . "\n" . $setData . "\n";
                    //                         mysqli_select_db($conn, $zdb);
                    //                         $getpmain = mysqli_query($conn, "SELECT a.*, DATE_FORMAT(a.`vouchdt`, '%d-%m-%Y') as vouchdt, DATE_FORMAT(a.`hijridate`, '%d-%m-%Y')
                    //                             as hijridt, b.* FROM `$maindb` a left join `$trandb` b on 
                    //                             a.vouchno = b.vouchno and a.visatype = b.visatype where a.`vouchdt` >= '$mfrmdate' AND a.`vouchdt` <= '$mtodate'
                    //                             $visatypecond $passportcond $manualnocond $visanocond $partynamecond $sponsercond $contactcond $mobilecond $agentcond
                    //                             ")or die(mysqli_error($conn));

                    //                         while ($pmain = mysqli_fetch_array($getpmain)) {
                    //                             $imig = $pmain['imig'];
                    //                             $stamp = $pmain['stamp'];
                    //                             $mis = $pmain['mis'];
                    // //                            $mofano = $pmain['mofa'];
                    //                             $misc = $pmain['misc'];
                    //                             $total = $pmain['total'];
                    //                             $disc = $pmain['disc'];
                    //                             $tot = $pmain['tot'];
                    //                             $vouchdt = $pmain['vouchdt'];
                    //                             $manualno = $pmain['manualno'];
                    //                             $broker = $pmain['broker'];
                    //                             $sponsor = $pmain['sponsor'];
                    //                             $visatype = $pmain['visatype'];
                    //                             $visano = $pmain['visano'];
                    //                             $visaqty = $pmain['visaqty'];
                    //                             $idno = $pmain['idno'];
                    //                             $place = $pmain['sector'];
                    //                             $hijridate = $pmain['hijridate'];
                    //                             $paxname = $pmain['paxname'];
                    //                             $sex = $pmain['sex'];
                    //                             $passport = $pmain['passport'];
                    //                             $dob = $pmain['dob'];
                    //                             $plbirthr = $pmain['plbirth'];
                    //                             $plbirth = str_replace(",", "  ", "$plbirthr");
                    //                             $poi = $pmain['issplace'];
                    //                             $stayperiod = $pmain['periodstay'];
                    //                             $doi = $pmain['issdate'];
                    //                             $stampdate = $pmain['stampdate'];
                    //                             $immgstatus = $pmain['delvstatus'];
                    //                             $category = $pmain['category'];
                    //                             $mofano = $pmain['mofano'];
                    //                             $mofano2 = $pmain['mofano2'];
                    //                             $mofa = $pmain['mofa'];

                    //                             $ctr++;
                    //                             $contents .= $ctr . ",";
                    //                             $contents .= "$vouchdt" . ",";
                    //                             $contents .= "$manualno" . ",";
                    //                             $contents .= "$broker" . ",";
                    //                             $contents .= "$sponsor" . ",";
                    //                             $contents .= "$visatype" . ",";
                    //                             $contents .= "$visano" . ",";
                    //                             $contents .= "$visaqty" . ",";
                    //                             $contents .= "$idno" . ",";
                    //                             $contents .= "$place" . ",";
                    //                             $contents .= "$hijridate" . ",";
                    //                             $contents .= "$paxname" . ",";
                    //                             $contents .= "$sex" . ",";
                    //                             $contents .= "$passport" . ",";
                    //                             $contents .= "$dob" . ",";
                    //                             $contents .= "$plbirth" . ",";
                    //                             $contents .= "$poi" . ",";
                    //                             $contents .= "$stayperiod" . ",";
                    //                             $contents .= "$doi" . ",";
                    //                             $contents .= "$stampdate" . ",";
                    //                             $contents .= "$immgstatus" . ",";
                    //                             $contents .= "$category" . ",";
                    //                             $contents .= "$mofano" . ",";
                    //                             $contents .= "$mofano2" . ",";
                    //                             $contents .= "$mofa" . ",";
                    //                             $contents .= "$stamp" . ",";
                    //                             $contents .= "$imig" . ",";
                    //                             $contents .= "$mis" . ",";
                    //                             $contents .= "$misc" . ",";
                    //                             $contents .= "$total" . ",";
                    //                             $contents .= "$disc" . ",";
                    //                             $contents .= "$tot" . "\n";
                    //                         }

                    //                         $gtot = $totamt + $totamt1 + $totamt2 + $totamt3;


                    //                         $contents = strip_tags($contents);
                    //                         if ($_POST["dtype"] == 1) {
                    //                             header("Content-Disposition: attachment; filename=$formname" . "_Summary" . date('d-m-Y') . ".csv");
                    //                             print $contents;
                    //                         } else {
                    //                             header("Content-Disposition: attachment; filename=$formname" . "_Detail" . date('d-m-Y') . ".csv");
                    //                             print $contents;
                    //                         }
                    //                     }
                    ?>