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

ini_set("display_errors", 1);
error_reporting(E_ERROR);

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

$file = 'contalert.php';
$maindb = "containerent";
$formname = "Container Alerts";

    include("includes/linkshead.php");
?>
    <style type="text/css">
        #tabital {
            font-style: italic;
        }

        #font1 {
            font-style: italic;
        }

        #boldfont {
            font-weight: bold;
        }
    </style>
    </head>

    <body>
        <div class="container-fluid">
            <?php
    $getpmain2 = mysqli_query($conn, "SELECT *,DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt,DATE_FORMAT(`dispdt`, '%d-%m-%Y') as dispdt, DATE_FORMAT(`recddate`, '%d-%m-%Y') as recddate
                                              FROM $maindb WHERE dispdt!='0000-00-00' AND expdate = CURDATE() + INTERVAL 1 DAY AND recddate='0000-00-00' order by vouchdt,vouchno") or die(mysqli_error($conn));
            $getno2 = mysqli_num_rows($getpmain2);

            if ($getno2 > 0) {
            ?>
                <div class="row">
                    <div class="col-lg-12 pad">
                        <table class="table table-condesed table-bordered">
                            <tr class="mySearchTr">
                                <!--9221292520-->
                                <th width="100%" class="h4" style="color:white"><b><?= $formname ?></b></th>
                            </tr>
                            <tr>
                                <td style="font-size: 15px;padding:5px" class="HDFont" colspan="2">
                                    Total No. of Record :&nbsp;&nbsp;<b><?php echo $getno2; ?></b>
                                </td>
                            </tr>
                        </table>
                        <table style="background: white;width: 100%" class="table table-condensed table-striped table-hover table-bordered">
                            <thead class="mySearchTr">
                                <tr>
                                    <th width="7%;">Order No</th>
                                    <th width="8%;">Order Date</th>
                                    <th width="10%;">China Vendor</th>
                                    <th width="10%;">India Customer</th>
                                    <th width="10%;">Product</th>
                                    <th class="text-right" width="10%;">CBM</th>
                                    <th class="text-right" width="6%;">Amount</th>
                                    <th width="17%;">Importer</th>
                                    <th width="10%;">Mode</th>
                                    <th width="10%;">Item</th>
                                    <th width="14%;">Dispatch Date</th>
                                    <th width="10%;">30 Days True/False</th>
                                    <th width="10%;">Adv Payments</th>
                                    <th width="10%;">No Of Cartons</th>
                                    <th width="10%;">Received In India Date</th>
                                    <th width="10%;">Due Date</th>
                                    <th width="10%;">10 Days True/False</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $pctr = 0;
                                $totamt = 0;

                while ($pmain = mysqli_fetch_array($getpmain2)) {
                                    $fvendor = mysqli_query($conn, "SELECT * FROM accmast WHERE accode = '$pmain[vendor]'") or die(mysqli_error($conn));
                                    $gvendor = mysqli_fetch_array($fvendor);

                                    $fcustomer = mysqli_query($conn, "SELECT `accode`,`name` FROM accmast WHERE accode = '$pmain[customer]'") or die(mysqli_error($conn));
                                    $gcustomer = mysqli_fetch_array($fcustomer);

                                    $fproduct = mysqli_query($conn, "SELECT `code`,`name` FROM rawmat WHERE code = '$pmain[product]'") or die(mysqli_error($conn));
                                    $gproduct = mysqli_fetch_array($fproduct);

                                    $voucher  = $pmain['vouchno'];
                                    $mydt     = $pmain['mydt'];
                                    $vendor   = $gvendor['name'];
                                    $customer = $gcustomer['name'];
                                    $product  = $gproduct['name'];
                                    $cbm      = $pmain['cbm'];
                                    $amount   = $pmain['amount'];
                                    $importer = $pmain['importer'];

                                    if ($pmain['mode'] == 'Sea') {
                                        $mode = 'SEA';
                                    } else if ($pmain['mode'] == 'Air') {
                                        $mode = 'AIR';
                                    }

                                    $descrip  = $pmain['descrip'];
                                    $advance = $pmain['advance'];
                                    $dispdt = $pmain['dispdt'];
                                    $days30 = (strtotime($pmain['dispdt']) - strtotime($pmain['mydt'])) / (60 * 60 * 24);
                                    $cartonsno = $pmain['cartonsno'];
                                    $recddate = $pmain['recddate'];
                                    $duedate = (strtotime($pmain['recddate']) - strtotime($pmain['dispdt'])) / (60 * 60 * 24);


                                    $pctr++;
                                    echo "<tr data-href='sale.php?mode=edit&vouchno=$voucher' class='clickable-row2' [target]='_blank'>";
                                    echo "<td>$voucher</td>";
                                    echo "<td>$mydt</td>";
                                    echo "<td>$vendor</td>";
                                    echo "<td>$customer</td>";
                                    echo "<td>$product</td>";
                                    echo "<td class='text-right'>$cbm</td>";
                                    echo "<td class='text-right'>$amount</td>";
                                    echo "<td>$importer</td>";
                                    echo "<td>$mode</td>";
                                    echo "<td>$descrip</td>";
                                    echo "<td>$dispdt</td>";
                                    echo "<td>$days30</td>";
                                    echo "<td>$advance</td>";
                                    echo "<td>$cartonsno</td>";
                                    echo "<td>$recddate</td>";
                                    echo "<td>$duedate</td>";
                                    echo "<td></td>";
                                    echo "</tr>";

                                    $totamt += $amount;
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>

            <?php
            } else {
                echo "<div class='row'><div class='col-lg-12 pad'><h3 class='text-center'>No Records Found</h3></div></div>";
            }
            ?>
        </div>
        <?php include("includes/linksfoot.php");
        ?>
    </body>

    </html>