<?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);


$status = $_REQUEST["status"];

$statuscond = "";
if (!empty($status)) {
    $statuscond = "AND status = '$status' ";
}

$getstatus = mysqli_query($conn, "SELECT `code`,`name` FROM `status` WHERE code = '$status' ") or die(mysqli_error($conn));
$fetstatus = mysqli_fetch_object($getstatus);

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

<style>
    /* Sticky Header CSS */
    .sticky-header th {
        position: sticky;
        top: 0;
        z-index: 20;
        background: #5f2b54 !important;
        color: white;
    }


/* Fix for sticky header (required) */
table {
    border-collapse: separate !important;
    border-spacing: 0;
}

/* Sticky Header */
.sticky-header th {
    position: sticky;
    top: 0;
    z-index: 50;
    background: #5f2b54 !important;
    color: white;
}

</style>
</head>

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

        <div class="row">
            <div class="panel-heading text-center">
                <h3 class="panel-title">Shipment <?= $fetstatus->name ?> </h3>
            </div>

            <?php
            $getOrigin = mysqli_query($conn, "SELECT `code`,`name` FROM `origin` order by name") or die(mysqli_error($conn));
            while ($fetOrigin = mysqli_fetch_array($getOrigin)) {

                ?>

           

                <div class="col-lg-12 ">
                    <div class="panel-heading">
                        <h3 class="panel-title">Origin : <?= $fetOrigin['name'] ?></h3>
                    </div>
                    <div class="table-responsive" style="max-height:400px; overflow-y:auto;">
                        <table class="table table-condensed table-striped table-bordered table-hover" style="width:100%;">
                            <thead class="mySearchTr sticky-header">
                                <tr>
                                    <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:3%">Cartons</th>
                                    <th style="width:10%">Supplier</th>
                                    <th style="width:10%">Description</th>
                                    <th style="width:6%" 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: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;
                                $totalCBM    = 0;
                                $totalWeight = 0;
                                $totalPCS    = 0;
                                
                                $getpmain = mysqli_query($conn, "SELECT *,DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt 
                                                                 FROM $maindb WHERE vouchno != '' AND  origin = '$fetOrigin[name]' $statuscond ") or die(mysqli_error($conn));

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

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

                                    $bgcolor = "";

                                    $ctr++;
                                    echo "<tr class='clickable-row2' data-href='shipment.php?vouchno=$pmain[vouchno]&mode=edit'>";
                                    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>$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[containerno]</td>";
                                    echo "<td>$saildt</td>";
                                    echo "<td>$pmain[destination]</td>";
                                    echo "<td>$estimdt</td>";
                                    echo "</tr>";
                                    
                                    $totalCBM    += $pmain['totcbm'];
                                    $totalWeight += $pmain['weight'];
                                    $totalPCS    += $pmain['pcs'];

                                }

                                echo "<tr style='background:#e8e8e8; font-weight:bold;'>";
                                echo "<td class='text-center'></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td>Total</td>";
                                echo "<td class='text-right'>$totalPCS</td>";
                                echo "<td class='text-right'>$totalCBM</td>";
                                echo "<td class='text-right'>$totalWeight</td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "</tr>";
                                
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>

            <?php } ?>
        </div>
    </div>

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

</html>
<?php
?>