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

$maindb     = "salemain";
$formname   = "Leading Parties";
$file       = "leadparty.php";

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

if(isset($_POST["view"])){
    $party      = $_POST["party"];
    $frmdt      = $_POST["frmdt"];
    $todt       = $_POST["todt"];
    $type       = $_POST["type"];
    
    $partycond    = "";
    $sortacond   = "";
    $sortbcond   = "";
    
    if (!empty($party)) {
        $partycond = " AND `party`='$party' ";
    }
    
    if ($type =="T") {
        $sortacond = " ORDER BY `netamt` DESC ";
    } else {
        $sortbcond = " ORDER BY `name` ";
    }

    $getpmain = mysqli_query($conn, "SELECT SUM(netamt) as netamt, `party` FROM `$maindb` WHERE `vouchno`!='' AND `vouchdt` BETWEEN '$frmdt' AND '$todt' $partycond GROUP BY `party` $sortacond   ")or die(mysqli_error($conn));
}


include("includes/linkshead.php");
?>
<script src="MyScript/item.js" type="text/javascript"></script>
</head>
<body>
    <div class="container">
        <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 goback">GO Back</a>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 pad">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="col-lg-12 pad">
                <table style="width:100%;background: white" class="table table-condensed table-hover">
                    <thead>
                        <tr style="height:10px;background-color: #1ABC9C">
                            <th>Sr</th>
                            <th>Party Name</th>
                            <th style="text-align:right">Total</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $ctr = 0;
                        while ($pmain = mysqli_fetch_array($getpmain)) {
                            $getcustomer = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$pmain[party]' ")or die(mysqli_error($conn));
                            $mcust = mysqli_fetch_array($getcustomer);
                            
                            $ctr++;
                            Echo "<tr>";
                            Echo "<td>$ctr</td>";
                            Echo "<td>$mcust[name]</td>";
                            Echo "<td class='text-right'>$pmain[netamt]</td>";
                            Echo "</tr>";
                            Echo "<tr>";
                        }
                        ?>
                    </tbody>
                </table>
            </div>
                </div>
            </div>
        </div>
        </div>
    </div>
    
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
