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

$zdb = $_SESSION["zdbyear_" . $dbname];
$admin = $_SESSION["admin_" . $dbname];

$formname = "Daily Ps";
$file = "dailyreceipts_fr.php";

$maindb = "cashrecp";

mysqli_select_db($conn, $zdb);

$mtodate = $_GET["todt"];
$notfound = $_POST["notfnd"];


if (empty($mtodate)) {
    browse("To Date Cannot Be Empty");
    echo "<script>window.close();</script>";
    exit();
}


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


    $gettran = mysqli_query($conn, "SELECT sum(abs(a.amount)) as amt, a.accode, b.name, b.city, b.mobile FROM `actran` a 
                                                  LEFT JOIN accmast b ON a.accode = b.accode 
                                                  WHERE a.`date` = '$mtodate' AND a.source = 'CP' AND a.amount < 0 AND a.grpcode != '012' 
                                                  GROUP BY a.accode ") or die(mysqli_error($conn));

    include("includes/linkshead.php");
    // $mfdt = date("d-m-Y", strtotime($mfrmdate));
    $mtdt = date("d-m-Y", strtotime($mtodate));
    ?>
    <style>
        table th{
            background-color: #337AB7;
        }
    </style> 
</head>

    <body id="ledger">   
        
        <form name="myform" method="post">
            <div class="row" style="padding : 1%">
                <div class="col-lg-1"></div>
                <div class="col-lg-8">
                    <?php include ("includes/head_rep.php"); ?>

                    <div class="box">
                        <div id="sortableTable" class="body collapse in">
                            <table class="table table-bordered sortableTable responsive-table">

                                <thead>
                                    <tr>
                                        <th style="width:5%">Sr.</th>
                                        <th style="width:25%">Name</th>
                                        <th style="width:10%">Mobile No.</th>
                                        <th style="width:10%">City</th>
                                        <th style="width:10%" class="text-right">Amount</th>
                                    </tr>
                                </thead>
                                <tbody class="tbody">

                                    <?php
                                    $totbillamt = 0;

                                    while ($fetacc = mysqli_fetch_array($gettran)) {

                                        $accode = $fetacc['accode'];
                                        $name = $fetacc['name'];
                                        $city = $fetacc['city'];
                                        $mobile = $fetacc['mobile'];
                                        $billamt = $fetacc['amt'];

                                        $mnctr++;

                                        echo "<tr>";
                                        echo "<td>$mnctr</td>";
                                        echo "<td>$name</td>";
                                        echo "<td>$mobile</td>";
                                        echo "<td>$city</td>";
                                        echo "<td class='text-right'>" . number_format($billamt, 2) . "</td>";
                                        echo "</tr>";

                                        $totbillamt += $billamt;

                                    }

                                    echo "<tr>";
                                    echo "<td></td>";
                                    echo "<td></td>";
                                    echo "<td></td>";
                                    echo "<td class='text-right'>Total</td>";
                                    echo "<td class='text-right'>" . number_format($totbillamt, 2) . "</td>";
                                    echo "</tr>";
                              
                                ?>
                                </tbody>
                            </table>    
                        </div>
                    </div>
                </div>
            </div>
            <?php include("includes/linksfoot.php"); ?>
        </form>
    </body>
    </html>
    <?php
}

?>