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

$maindb = "visatran";
$formname = "Passport Cupboard Manager";
$file = "passcupd.php";

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

if (isset($_POST["view"])) {
    $name = $_POST[name];
    $gtype = $_POST[gtype];


    $staffcond = "";
    $mtypecond = "";
//    browse($gtype);

//    if (!empty($gtype)) {
//        $mtypecond = " AND `pastatus`='$gtype' ";
//    }




    if (empty($_POST["frmdt"])) {
        browse("From Date Cannot Be Empty");
        header("refresh:1; leadreg.php");
    }
    if (empty($_POST["todt"])) {
        browse("To Date Cannot Be Empty");
        header("refresh:1; leadreg.php");
    }
    $mfrmdate = trim($_POST["frmdt"]);
    $mtodate = trim($_POST["todt"]);



// print "SELECT * FROM `$maindb` WHERE `vouchno`!='' $partyname $broker $transpor $item $godown $mtype";
    $gethand = mysqli_query($conn,"SELECT count(*) as inhand FROM $maindb where `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' and `pastatus`='1' ")or die(mysqli_error($conn));
    $getsupp = mysqli_query($conn,"SELECT count(*) as supphand FROM $maindb where `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' and `pastatus`='0'")or die(mysqli_error($conn));
//    $getclient = mysqli_query($conn,"SELECT count(*) as client FROM $maindb where `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' and `pastatus`='2' $mtypecond")or die(mysqli_error($conn));

    $hand = mysqli_fetch_array($gethand);
    $supp = mysqli_fetch_array($getsupp);
//    $clnt = mysqli_fetch_array($getclient);
    include("includes/linkshead.php");
    ?>
    <script>
        $(document).ready(function () {
            $("#supphnd").click(function () {
                var status = "0";

                $.post('get_passcupd.php', {status: status}, function (data) {
    //                alert(data);
                    $(".mytable").html(data);
                });
            });
            
        $("#inhand").click(function () {
                var status = "1";

                $.post('get_passcupd.php', {status: status}, function (data) {
    //                alert(data);
                    $(".mytab2").html(data);
                });
            });
        });
    </script>
    <style type="text/css">
        table td {
            background-color: white;
        }
        .mytable {
            font-style: italic;
        }
        .mytab2 {
            font-style: italic;
        }
    </style>
    <!--<script src="MyScript/item.js" type="text/javascript"></script>-->    
    </head>
    <body>
        <div class="container" style="width:100%">
            <div class="row">
                <!--                            <div class="col-lg-6">
                                                <label class="label-control marg">Date - </label>
                                                <label class="label-control marg"><?php // Echo Date("d-m-Y");      ?></label>
                                            </div>-->

                <div class="col-lg-5">
                    <label class="label-control marg">Print - </label>
                    <label class="label-control marg"><?php Echo $formname; ?></label>
                </div>

                <div class="col-lg-3" style="float: right; margin-top: 5px;">
                    <a onclick="window.close()" class="btn btn-primary">GO Back</a>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12 pad">
                    <table style="width:100%;background: white" class="table-condensed table-hover table-bordered">
                        <thead>
                            <tr style="height:10px;background-color: #64CCFC;">
                                <th style="width:20%;text-align: center;">In Hand</th>
                                <th style="width:20%;text-align: center;">Sent to Supplier</th>
                                <!--<th style="width:20%;text-align: center;">Client</th>-->
                                <th style="width:20%;text-align: center;">Total</th>
                                <!--<th class="numeric">New Remark</th>-->                            
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $total = $hand[inhand] + $supp[supphand] ;
//                            $total = $hand[inhand] + $supp[supphand] + $clnt[client];
                            Echo "<tr>";
                            Echo "<td style='text-align: center;color:blue;' id='inhand'>$hand[inhand]</td>";
                            Echo "<td style='text-align: center;color:green;' id='supphnd'>$supp[supphand]</td>";
//                            Echo "<td style='text-align: center;' >$clnt[client]</td>";
                            Echo "<td style='text-align: center;'>$total</td>";
                            Echo "</tr>";

//                            
                            ?>
                        </tbody>
                    </table>

                </div>
            </div>
            <div class="row mytable">

            </div>
            <div class="row mytab2">
                
            </div>
        </div>

        <?php include("includes/linksfoot.php"); ?>
    </body>
    </html>
    <?php
}

if (isset($_POST["excel"])) {
    $name = $_POST[name];
    $gtype = $_POST[gtype];


    $staffcond = "";
    $mtypecond = "";
//    browse($gtype);
    if (!empty($name)) {
        $staffcond = " AND `username`='$name' ";
    }

    if (!empty($gtype)) {
        $mtypecond = " AND `status`='$gtype' ";
    }




    if (empty($_POST["frmdt"])) {
        browse("From Date Cannot Be Empty");
        header("refresh:1; leadreg.php");
    }
    if (empty($_POST["todt"])) {
        browse("To Date Cannot Be Empty");
        header("refresh:1; leadreg.php");
    }
    $mfrmdate = trim($_POST["frmdt"]);
    $mtodate = trim($_POST["todt"]);



// print "SELECT * FROM `$maindb` WHERE `vouchno`!='' $partyname $broker $transpor $item $godown $mtype";
    $getpmain = mysqli_query($conn,"SELECT *,DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt FROM $maindb where `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate'
             $staffcond $mtypecond")or die(mysqli_error($conn));

    $contents.="Sr,Book No ,Enq Date,Name,Last Name,Destination,Travel Date,Status,Que to Visa,Remark,New Remark\n";

    $ctr = 0;


    while ($pmain = mysqli_fetch_array($getpmain)) {


        $ctr++;

        $exctr = $ctr;
        $exvouchno = $pmain[vouchno];
        $exvouchdt = $pmain[vouchdt];
        $exname = $pmain[name];
        $exlastname = $pmain[lastname];
        $exdestination = $pmain[destination];
        $exdeptdate = $pmain[deptdate];
        $exstatus = $pmain[status];
        $exquotvisa = $pmain[quotvisa];
        $exremarks = $mqty[remarks];
        $exremarks1 = $pmain[remarks1];

        $contents.=$exctr . ",";
        $contents.=$exvouchno . ",";
        $contents.=$exvouchdt . ",";
        $contents.=$exname . ",";
        $contents.=$exlastname . ",";
        $contents.=$exdestination . ",";
        $contents.=$exdeptdate . ",";
        $contents.=$exstatus . ",";
        $contents.=$exquotvisa . ",";
        $contents.=$exremarks . ",";
        $contents.=$exremarks1 . "\n";
    }


    $contents = strip_tags($contents);

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

