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

$formname = 'Container ETA Alert';
$ztit = $_SESSION["tit_" . $dbname];
$maindb = 'shipmain';
$printfile = "";
$file = 'shipeta.php';
$trandbexist = 1;
$grid = '';
$keyfld = "vouchno";
$keycond = "";
$focusfield = "party";
$bseries = $_SESSION["user_series"];
$zroot = $_SESSION["zdir"];

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

$usertype = $_SESSION["usertype"];
$user = $_SESSION['username_' . $dbname];



if ($addflag != 1) {
    $getvouch = '';
    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }
}

$senable = "";
$cenable = "";


include("includes/linkshead.php");
?>
</head>

<body>

    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-11 " style="margin-left: 20px;">
                <div class="panel panel-default">
                    <div class="panel-body " style="width:100%">
                        
                        <table style="background: white;width: 100%;border-radius: 7px;" class="table table-condensed table-bordered table-hover table">
                            <thead>
                                <tr class="mySearchTr">
                                    <th width="3%;">Sr</th>
                                    <th width="5%;">Voucher</th>
                                    <th width="6%;">Invoice No.</th>
                                    <th width="6%;">Date</th>
                                    <th width="20%;">Party Name</th>
                                    <th width="8%;">Pay type</th>
                                    <th width="8%;" class="text-right">Total Qty</th>
                                    <th width="8%;" class="text-right">Sub Total</th>
                                    <th width="7%;" class="text-right">Less Discount</th>
                                    <th width="7%;" class="text-right">Cartage/Courier</th>
                                    <th width="10%;" class="text-right">Net Amount</th>
                                    <th width="7%;" class="text-center">Edit</th>
                                </tr>
                            </thead>
                            <tbody class="mytable table-bordered">
                                <?php
                                $date = date("Y-m-d");
                                $srchresult = mysqli_query($conn, "SELECT *,DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt FROM salemain WHERE vouchno in (SELECT vouchno FROM saletran WHERE rate <= 0 ) order by vouchno") or die(mysqli_error($conn));

                                $ctr = 0;
                                $mctr = 0;
                                while ($pmain = mysqli_fetch_array($srchresult)) {
                                    if ($pmain['paidby'] == "C") {
                                        $ptyped = "CASH";
                                    } else {
                                        $ptyped = "CREDIT";
                                    }


                                    $gparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` where `accode` = '$pmain[party]'") or die(mysqli_error($conn));
                                    $sparty = mysqli_fetch_array($gparty);

                                    $godown = $sgodw['gcode'];
                                    $voucher = $pmain['vouchno'];
                                    $invno = $pmain['invno'];
                                    $mydt = $pmain['mydt'];
                                    $party = $sparty['name'];
                                    $billamt = $pmain['billamt'];
                                    $subtot = $pmain['grossamt'];
                                    $totvat = $pmain['totvat'];
                                    $totdisc = $pmain['totdisc'];
                                    $totqty = $pmain['totalqty'];
                                    $packchgs = $pmain['packchgs'];

                                    $pctr++;
                                    echo "<tr data-href='sale.php?mode=edit&vouchno=$voucher' class='clickable-row2' style='cursor: pointer;' [target]='_blank'>";
                                    echo "<td>$pctr</td>";
                                    echo "<td>$voucher</td>";
                                    echo "<td>$invno</td>";
                                    echo "<td>$mydt</td>";
                                    echo "<td>$party</td>";
                                    echo "<td>$ptyped</td>";
                                    echo "<td class='text-right'>$totqty</td>";
                                    echo "<td class='text-right'>$subtot</td>";
                                    echo "<td class='text-right'>$totdisc</td>";
                                    echo "<td class='text-right'>$packchgs</td>";
                                    echo "<td class='text-right'>$billamt</td>";
                                    echo "<td class='text-center'><a href='sale.php?vouchno=$voucher&mode=edit' target='_blank'><i class='fa fa-pencil fa-2x'></i></a></td>";
                                    echo "</tr>";
                                }
                                ?>
                            </tbody>
                        </table>

                    </div>
                </div>
            </div>
        </div>
    </form>

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

</body>

</html>