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

$maindb = "shipment";
$formname = "Shipment Multiple  Register";
$file = "shipmultireg.php";

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


$customer = $_POST['customer'];
$origin = $_POST['origin'];
$destination = $_POST['destination'];
$containerno = $_POST['containerno'];
$frmdt = $_POST['frmdt'];
$todt = $_POST['todt'];

$customercond = "";
$origincond = "";
$destinationcond = "";
$containernocond = "";


if (!empty($customer)) {
    $customercond = " AND a.`customer`='$customer' ";
}

if (!empty($origin)) {
    $origincond = " AND a.`origin`='$origin' ";
}

if (!empty($destination)) {
    $destinationcond = " AND a.`destination`='$destination' ";
}

if (!empty($containerno)) {
    $containernocond = " AND a.`containerno` LIKE '%$containerno%' ";
}



if (empty($_POST["frmdt"])) {
    browse("From Date Cannot Be Empty");
    echo "<script>window.close()</script>";
}
if (empty($_POST["todt"])) {
    browse("To Date Cannot Be Empty");
    echo "<script>window.close()</script>";
}

$mfrmdate = trim($_POST["frmdt"]);
$mtodate = trim($_POST["todt"]);


if (!empty($mtype)) {
    $mtypecond = " AND `type`='$mtype' ";
}

$getpmain = mysqli_query($conn, "SELECT a.*,DATE_FORMAT(a.`vouchdt`, '%d-%m-%Y') as mydt, b.name as statusnm FROM $maindb a
                                 LEFT JOIN status b ON a.status = b.code
                                 WHERE a.`vouchdt` >= '$mfrmdate' AND a.`vouchdt` <= '$mtodate'
                                 $customercond $origincond $destinationcond $containernocond ") or die(mysqli_error($conn));

$getcust = mysqli_query($conn, "SELECT accode,name,mobile FROM accmast WHERE `accode` >= '$customer' ") or die(mysqli_error($conn));
$fetcust = mysqli_fetch_object($getcust);

$mobileno = $fetcust->mobile;
$custname = $fetcust->name;

if (isset($_POST["view"])) {

    include("includes/linkshead.php");
    ?>
    <script src="MyScript/shipmultireg.js?a=<?= mt_rand() ?>" type="text/javascript"></script>

    <style>
        .custom-btn {
            width: 100px;
            height: 32px;
            color: #fff;
            border-radius: 7px;
            padding: 10px 10px;
            font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
            font-weight: 700;
            background: transparent;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            display: inline-block;
            box-shadow: inset 2px 2px 2px 0px rgba(255, 255, 255, .5),
                7px 7px 20px 0px rgba(0, 0, 0, .1),
                4px 4px 5px 0px rgba(0, 0, 0, .1);
            outline: none;
            font-size: 16px;
            line-height: 1;
            text-align: center;
            margin-top: 3px;
            margin-left: -7px;
        }

        .btn-1 {
            background: #34a853;
            border: none;
        }

        .shiptable tr.selected {
            background-color: #ccffcc !important;
            /* light blue */
        }
    </style>
    </head>

    <body>
        <div class="container-fluid">

            <!-- <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-1">
                    <a onclick="window.close()" class="btn btn-primary">GO Back</a>
                </div>
            </div> -->

            <div class="row">
                <div class="col-lg-12 ">
                    <div class="col-lg-1 pad text-left">
                        <input type="checkbox" style="border:none;position: inherit;height:25px;width:25px;margin:7px"
                            id="shipchkall" value="1">
                    </div>

                    <div class="col-lg-3 pad text-left">
                        <h4><b>Select All/Unselect All</b></h4>
                    </div>

                    <input type="hidden" id="customer" value="<?php echo $custname; ?>">
                    <input type="hidden" id="mobileno" value="<?php echo $mobileno; ?>">

                    <div class="col-lg-1 pad text-left">
                        <input type="button" class='custom-btn btn-1 sendwhatsapp' value="WHATSAPP">
                    </div>

                    <div class="col-lg-5 pad text-right"></div>

                    <table style="width:100%;background: white"
                        class="table table-condensed table-striped table-bordered table-hover">
                        <thead class="mySearchTr">
                            <tr>
                                <th style="width:3%" class="text-center">Select</th>
                                <th style="width:3%" class="text-center">Sr</th>
                                <th style="width:4%">Shipment</th>
                                <th style="width:5%">Booking</th>
                                <th style="width:7%">Marka</th>
                                <th style="width:4%">Status</th>
                                <th style="width:3%">Cartons</th>
                                <th style="width:10%">Supplier</th>
                                <th style="width:10%">Description</th>
                                <th style="width:4%" class="text-right">Pcs</th>
                                <th style="width:6%" class="text-right">Total CBM</th>
                                <th style="width:4%" class="text-right">Weight</th>
                                <th style="width:10%">Origin</th>
                                <th style="width:7%">Container</th>
                                <th style="width:6%">Sailing </th>
                                <th style="width:10%">Destination</th>
                                <th style="width:6%">Estimate</th>
                            </tr>
                        </thead>
                        <tbody class="shiptable">
                            <?php
                            $ctr = 0;
                            $subtot = 0;
                            $totdisc = 0;
                            $totfr = 0;
                            $totqty1 = 0;
                            $totnet = 0;


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

                                $saildt = format_date($pmain['saildate']);
                                $estimdt = format_date($pmain['estimdate']);

                                $bgcolor = "";

                                // Change color based on status
                                if ($pmain['status'] == 5) {
                                    $bgcolor = "color:blue;font-weight:bold"; // light red
                                } elseif ($pmain['status'] == 7) {
                                    $bgcolor = "color:orange;font-weight:bold"; // light yellow
                                } elseif ($pmain['status'] == 9) {
                                    $bgcolor = "color:green;font-weight:bold"; // light green
                                }


                                $ctr++;
                                echo "<tr>";
                                echo "<td style='text-align:center'><input type='checkbox'  style='border:none;position: inherit;height:25px;width:25px;' class='selectchk'></td>";
                                echo "<td class='text-center'>$ctr</td>";
                                echo "<td>GC-$pmain[vouchno]</td>";
                                echo "<td>$pmain[mydt]</td>";
                                echo "<td>$pmain[marka]</td>";
                                echo "<td style='$bgcolor'>$pmain[statusnm]</td>";
                                echo "<td>$pmain[nocart]</td>";
                                echo "<td>$pmain[supplier]</td>";
                                echo "<td>$pmain[description]</td>";
                                echo "<td class='text-right'>$pmain[pcs] $pmain[unit]</td>";
                                echo "<td class='text-right'>$pmain[totcbm]</td>";
                                echo "<td class='text-right'>$pmain[weight]</td>";
                                echo "<td>$pmain[origin]</td>";
                                echo "<td>$pmain[containerno]</td>";
                                echo "<td>$saildt</td>";
                                echo "<td>$pmain[destination]</td>";
                                echo "<td>$estimdt</td>";
                                echo "</tr>";

                            }


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

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

    </html>
    <?php
}
?>