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

$maindb = "order";
$trandb = "ordertran";

$formname = "Undelivered List";
$file = "menu.php";
$keyfld = "code";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$searchdisabled = 'none';
$adddisabled = 'none';
$editdisabled = 'none';
$deletedisabled = 'none';
$exitdisabled = 'none';
$printdisabled = 'none';
$pdisabled = 'none';
$ndisabled = 'none';
$addflag = 0;
$count = $_GET['count'];

if (isset($_POST["submit"])) {
    for ($i = 1; $i <= $count; $i++) {

        $chkdel = $_POST["deliver_$i"];
        $vouch = $_POST["vouch_$i"];

        if ($chkdel == 1) {
            mysqli_query($conn, "UPDATE `$maindb` SET `delivered` = '1' WHERE `vouchno`='$vouch'") or die(mysqli_error($conn));
        }
    }

    updmess();
    header("Refresh: 1; menu.php");
}
if ($count > 0) {

    $getpmain = mysqli_query($conn, "SELECT *, DATE_FORMAT(`orderdt`, '%d-%m-%Y') AS orderdt FROM 
                             `$maindb` WHERE `delivered` = '' ORDER BY orderdt desc")or die(mysqli_error($conn));

    include("../includes/linkshead.php");
    ?>
    </head>
    <body>
        <style>
            th{
                background-color: #b9408F;
            }
        </style>
        <form action='' method='POST' enctype="multipart/form-data">
            <div class="container" style="width:90%">
                <div class="row">
                    <?php include("../includes/head_rep.php"); ?>
                    <div class="col-lg-12 pad">
                        <table class="table table-condensed table-bordered">
                            <tr class="mySearchTr">
                                <th style="width:5%">Sr</th>
                                <th style="width:10%">Date</th>
                                <th style="width:10%">Order No.</th>
                                <th style="width:30%">Client Name</th>
                                <th style="width:13%">Contact No.</th>
                                <th style="width:12%;text-align: right">Total</th>
                                <th style="width:10%;">Invoice Print</th>
                                <th style="width:10%;">Delivered</th>
                            </tr>
                            <?php
                            $ctr = 0;
                            while ($pmain = mysqli_fetch_array($getpmain)) {
//                                $getsupp = mysql_query("SELECT `user` FROM `site_passmain` WHERE `srno` = '$pmain[userid]'")or die(mysql_error());
//                                $supp = mysql_fetch_array($getsupp);

                                $vouch = $pmain['vouchno'];
                                $ctr++;
                                Echo "<tr>";
                                Echo "<td>$ctr</td>";
                                Echo "<td>$pmain[orderdt]</td>";
                                Echo "<td>$pmain[vouchno]<input type='hidden' name='vouch_$ctr' value='$vouch'></td>";
                                Echo "<td>$pmain[username]</td>";
                                Echo "<td>$pmain[contact]</td>";
                                Echo "<td class='text-right'>$pmain[total]</td>";
                                Echo "<td style='text-align: center;'><a href='invoice_print.php?vouchno=$pmain[vouchno]' target='_blank'<button type='button' class='btn btn-primary active' style='margin-top: 5px; padding-top: 2px;padding-bottom: 2px;'>Print</a></td>";
                                Echo "<td><div class='checkbox' style='text-align: center;'><label><input type='checkbox' value='1' name='deliver_$ctr'></label></div></td>";
                                Echo "</tr>";
                            }
                            ?>
                        </table>
                    </div>
                </div>
                <div class="row pad">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <?php include("../includes/buttons.php"); ?>
                        </div>
                    </div>
                </div>
            </div>
        </form>

        <?php include("../includes/linksfoot.php"); ?>
    </body>
    </html>
    <?php
} else {
    ?>
    <a href="menu.php"><button type="button" name="goback" class="btn btn-default">Go Back</button></a>
    <h1>No Records Found..</h1>
<?php }
?>
