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

$maindb = "leadenq";
//$trandb = "saletran";
$formname = "Perfomance Register";
$file = "perfreg.php";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$zroot = $_SESSION["zdir"];

mysqli_select_db($conn,$zdb);

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


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

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




if (empty($_POST["frmdt"])) {
browse("From Date Cannot Be Empty");
header("refresh:1; perfreg.php");
}
if (empty($_POST["todt"])) {
browse("To Date Cannot Be Empty");
header("refresh:1; perfreg.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 * FROM `$zroot`.`passmain` where code != '' $staffcond ")or die(mysqli_error($conn));


include("includes/linkshead.php");
?>
<!--<script src="MyScript/item.js" type="text/javascript"></script>-->    
</head>
<body>
    <div class="container">
        <div class="row">
            <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 table-condensed table-hover">
                    <thead>
                        <tr style="height:10px;background-color: #64CCFC;">
                            <th style="width:10%">Sr</th>
                            <th style="width:20%">Staff Name</th>
                            <th style="width:14%">Total Leads</th>
                            <th style="width:14%">Total Confirmed</th>
                            <th style="width:14%">Cancelled</th>
                            <th style="width:14%">Postponed</th>
                            <th style="width:14%">Feed Back</th>
                            
                            <!--<th class="numeric">New Remark</th>-->                            
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $ctr = 0;

                        while ($pmain = mysqli_fetch_array($getpmain)) {
                            $getrecords = mysqli_query($conn,"SELECT count(*) as totleads FROM `leadenq` where `username` = '$pmain[user]'")or die(mysqli_error($conn));
                            $records = mysqli_fetch_array($getrecords);
                            
                            $getconfirmrecords = mysqli_query($conn,"SELECT count(*) as confirm FROM `leadenq` where `username` = '$pmain[user]' and `status` ='Confirmed'")or die(mysqli_error($conn));
                            $recordconfirm = mysqli_fetch_array($getconfirmrecords);
                            
                            $getcancelled = mysqli_query($conn,"SELECT count(*) as cancel FROM `leadenq` where `username` = '$pmain[user]' and `status` ='Cancelled'")or die(mysqli_error($conn));
                            $cancel = mysqli_fetch_array($getcancelled);
                            
                            $getpostponed = mysqli_query($conn,"SELECT count(*) as postponed FROM `leadenq` where `username` = '$pmain[user]' and `status` ='Postponed'")or die(mysqli_error($conn));
                            $postponed = mysqli_fetch_array($getpostponed);
                            
                        $ctr++;
                        Echo "<tr>";
                        Echo "<td style='width:10%'>$ctr</td>";
                        Echo "<td style='width:10%'>$pmain[user]</td>";
                        Echo "<td style='width:10%'>$records[totleads]</td>";
                        Echo "<td style='width:10%'>$recordconfirm[confirm]</td>";
                        Echo "<td style='width:13%'>$cancel[cancel]</td>";
                        Echo "<td style='width:13%'>$postponed[postponed]</td>";
                        Echo "<td style='width:10%'>$records[status]</td>";
                        Echo "</tr>";
                        }

//                            
                        ?>
                    </tbody>
                </table>
            </div>
        </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;
//}
}
?>

