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

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

if ($_REQUEST["curdt"]) {
    $curdt = $_REQUEST["curdt"];

    $todaydt = $curdt;

//  SALE 
    $getsl = mysqli_query($conn, "SELECT `vouchno`, `vouchdt`, `party`, `invno`, `netamt` FROM `salemain` WHERE vouchno !='' AND vouchdt = '$todaydt' order by vouchno")or die(mysqli_error($conn));

//   MATERIAL GIVEN TO KARIGAR
    $getmatkar = mysqli_query($conn, "SELECT `vouchno`, `vouchdt`, `invno`, `netamt`, `party` FROM `rawmain` WHERE vouchno !='' AND vouchdt = '$todaydt' order by vouchno")or die(mysqli_error($conn));

//   CASH RECEIPT
    $getcashrcp = mysqli_query($conn, "SELECT `vouchno` , `vouchdt`, `recpno`, `party`, `amount` FROM `cashrecp` WHERE vouchno !='' AND vouchdt = '$todaydt' order by vouchno")or die(mysqli_error($conn));

//   CASH PAYMENT
    $getcashpay = mysqli_query($conn, "SELECT `vouchno` , `vouchdt`, `recpno`, `party`, `amount` FROM `cashpay` WHERE vouchno !='' AND vouchdt = '$todaydt' order by vouchno")or die(mysqli_error($conn));

//  SALE GST MULTI
    $getslgst = mysqli_query($conn, "SELECT `vouchno`, `vouchdt`, `invno`, `party`, `netamt` FROM `gstmain` WHERE vouchno !='' AND vouchdt = '$todaydt' order by vouchno")or die(mysqli_error($conn));

//  GOODS RECEIVED FROM KARIGAR
    $getgdrecv = mysqli_query($conn, "SELECT `vouchno`, `vouchdt`, `invno`, `netamt`, `party` FROM `purgstmain` WHERE vouchno !='' AND vouchdt = '$todaydt' order by vouchno")or die(mysqli_error($conn));

//   BANK RECEIPT
    $getbankrecp = mysqli_query($conn, "SELECT `vouchno` , `vouchdt`, `recpno`, `bankname`, `amount`,party FROM `bankrecp` WHERE vouchno !='' AND vouchdt = '$todaydt' order by vouchno")or die(mysqli_error($conn));

//   BANK PAYMENT
    $getbankpay = mysqli_query($conn, "SELECT `vouchno`, `vouchdt`, `recpno`, `bankname`, `amount`,party FROM `bankpay` WHERE vouchno !='' AND vouchdt = '$todaydt' order by vouchno")or die(mysqli_error($conn));

//   CUSTOMER TO KARIGAR
    $getcustokar = mysqli_query($conn, "SELECT `vouchno`, `vouchdt`, `karigar`, `party`, `amount` FROM `custtokari` WHERE vouchno !='' AND vouchdt = '$todaydt' order by vouchno")or die(mysqli_error($conn));
    ?>

      


<!--    

    <div class="zoom" <?= $cashrecp; ?> onclick="location.href = 'cashrecp.php?mode=last';">
        <div style="height: 305px; overflow-x: auto">

            <table class="table table-bordered" style="">
                <thead class="thead-dark">
                    <tr >
                <h6 class="chead" >Cash Receipt</h6>
                </tr>
                <tr>
                    <th scope="col" class="text-left">Sr</th>
                    <th scope="col" class="text-center">Voucher</th>
                    <th scope="col" class="text-center">Account</th>
                    <th scope="col" class="text-right">Amount</th>
                </tr>
                </thead>

                <tbody>
                    <?php
                    $tctr = 0;
                    $totamt = 0;
                    while ($cpmain = mysqli_fetch_array($getcashrcp)) {
                        $tctr++;
                        $vouchno = $cpmain['vouchno'];
                        $recpno = $cpmain['recpno'];
                        $amount = $cpmain['amount'];

                        $getac = mysqli_query($conn, "SELECT accode, name FROM `accmast` WHERE accode = '$cpmain[party]' AND grpcode > '002' AND grpcode !=''")or die(mysqli_error($conn));
                        $fetac = mysqli_fetch_array($getac);
                        $acname = $fetac['name'];


                        Echo "<tr>";
                        Echo "<td class='subtd'>$tctr</td>";
                        Echo "<td class='subtd'><a href='cashrecp.php?mode=edit&vouchno=$vouchno' style='color: white;'>$vouchno</a></td>";
                        Echo "<td class='subtd'>$acname</td>";
                        Echo "<td class='subtd text-right'>$amount</td>";
                        Echo "</tr>";

                        $totamt = $totamt + $amount;
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <div>
            <table class="table table-bordered" style="">
                <thead class="">
                    <tr class="ttotal">
                        <td class="tottd text-center" ><?php echo $tctr; ?></td> 
                        <td class="tottd">Total</td> 
                        <td class="tottd"><?php echo $totamt; ?></td> 
                    </tr>
                </thead>
            </table>

        </div>
    </div>  
    <div class="zoom" <?= $cashpay; ?> onclick="location.href = 'cashpay.php?mode=last';">
        <div style="height: 305px; overflow-x: auto">

            <table class="table table-bordered" style="">
                <thead class="thead-dark">
                    <tr >
                <h6 class="chead" >Cash Payment</h6>
                </tr>
                <tr>
                    <th scope="col" class="text-left">Sr</th>
                    <th scope="col" class="text-center">Voucher</th>
                    <th scope="col" class="text-center">Account</th>
                    <th scope="col" class="text-right">Amount</th>
                </tr>
                </thead>

                <tbody>
                    <?php
                    $tctr = 0;
                    $totamt = 0;
                    while ($cpmain = mysqli_fetch_array($getcashpay)) {
                        $tctr++;
                        $vouchno = $cpmain['vouchno'];
                        $recpno = $cpmain['recpno'];
                        $amount = $cpmain['amount'];

                        $getac = mysqli_query($conn, "SELECT accode, name FROM `accmast` WHERE accode = '$cpmain[party]' AND grpcode > '002' AND grpcode !=''")or die(mysqli_error($conn));
                        $fetac = mysqli_fetch_array($getac);
                        $acname = $fetac['name'];


                        Echo "<tr>";
                        Echo "<td class='subtd'>$tctr</td>";
                        Echo "<td class='subtd'><a href='cashpay.php?mode=edit&vouchno=$vouchno' style='color: white;'>$vouchno</a></td>";
                        Echo "<td class='subtd'>$acname</td>";
                        Echo "<td class='subtd text-right'>$amount</td>";
                        Echo "</tr>";

                        $totamt = $totamt + $amount;
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <div>
            <table class="table table-bordered" style="">
                <thead class="">
                    <tr class="ttotal">
                        <td class="tottd text-center" ><?php echo $tctr; ?></td> 
                        <td class="tottd">Total</td> 
                        <td class="tottd"><?php echo $totamt; ?></td> 
                    </tr>
                </thead>
            </table>

        </div>
    </div>  -->
    <div class="zoom" <?= $salegstmulti; ?> onclick="location.href = 'salegstmulti.php?mode=last';">
        <div style="height: 305px; overflow-x: auto">

            <table class="table table-bordered" style="">
                <thead class="thead-dark">
                    <tr >
                <h6 class="chead" >Sale GST Multi</h6>
                </tr>
                <tr>
                    <th scope="col" class="text-left">Sr</th>
                    <th scope="col" class="text-center">Invoice</th>
                    <th scope="col" class="text-center">Party</th>
                    <th scope="col" class="text-right">Amount</th>
                </tr>
                </thead>
                <tbody>
                    <?php
                    $ctr = 0;
                    $totnetamt = 0;
                    $totctr = 0;
                    while ($gmain = mysqli_fetch_array($getslgst)) {
                        $getgp = mysqli_query($conn, "SELECT accode, name FROM `accmast` WHERE accode = '$gmain[party]' AND grpcode = '010'")or die(mysqli_error($conn));
                        $fetgp = mysqli_fetch_array($getgp);
                        $partyname = $fetgp['name'];

                        $ctr++;
                        $vouchno = $gmain['vouchno'];
                        $originalDate = $gmain['vouchdt'];
                        $vouchdt = date("d-m-Y", strtotime($originalDate));

                        $invno = $gmain['invno'];
                        $netamt = $gmain['netamt'];

                        Echo "<tr>";
                        Echo "<td class='subtd'>$ctr</td>";
                        Echo "<td class='subtd'><a href='salegstmulti.php?mode=edit&vouchno=$vouchno' style='color: white;'>$invno</a></td>";
                        Echo "<td class='subtd'>$partyname</td>";
                        Echo "<td class='subtd text-right'>$netamt</td>";
                        Echo "</tr>";

                        $totnetamt = $totnetamt + $netamt;
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <div >
            <table class="table table-bordered" style="">
                <thead class="">
                    <tr class="ttotal">
                        <td class="tottd text-center" ><?php echo $ctr; ?></td> 
                        <td class="tottd">Total</td> 
                        <td class="tottd"><?php echo $totnetamt; ?></td> 
                    </tr>
                </thead>
            </table>
        </div>
    </div>  
    <div class="zoom" <?= $purchase; ?> onclick="location.href = 'purchgst.php?mode=last';">
        <div style="height: 305px; overflow-x: auto">

            <table class="table table-bordered" style="">
                <thead class="thead-dark">
                    <tr >
                <h6 class="chead" >Goods Received From Karigar</h6>
                </tr>
                <tr>
                    <th scope="col" class="text-left">Sr</th>
                    <th scope="col" class="text-center">Invoice</th>
                    <th scope="col" class="text-center">Karigar</th>
                    <th scope="col" class="text-right">Amount</th>
                </tr>
                </thead>
                <tbody>
                    <?php
                    $ctr = 0;
                    $totnetamt = 0;
                    $totctr = 0;
                    while ($gdmain = mysqli_fetch_array($getgdrecv)) {
                        $ctr++;
                        $vouchno = $gdmain['vouchno'];
                        $originalDate = $gdmain['vouchdt'];
                        $vouchdt = date("d-m-Y", strtotime($originalDate));

                        $getkr = mysqli_query($conn, "SELECT accode, name FROM accmast WHERE accode = '$gdmain[party]' AND `grpcode`='009' AND active = '1' ")or die(mysqli_error);
                        $fetkr = mysqli_fetch_array($getkr);
                        $karigar = $fetkr['name'];
                        $invno = $gdmain['invno'];
                        $netamt = $gdmain['netamt'];

                        Echo "<tr>";
                        Echo "<td class='subtd'>$ctr</td>";
                        Echo "<td class='subtd'><a href='purchase.php?mode=edit&vouchno=$vouchno' style='color: white;'>$invno</a></td>";
                        Echo "<td class='subtd'>$karigar</td>";
                        Echo "<td class='subtd text-right'>$netamt</td>";
                        Echo "</tr>";

                        $totnetamt = $totnetamt + $netamt;
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <div >
            <table class="table table-bordered" style="">
                <thead class="">
                    <tr class="ttotal">
                        <td class="tottd text-center" ><?php echo $ctr; ?></td> 
                        <td class="tottd">Total</td> 
                        <td class="tottd"><?php echo $totnetamt; ?></td> 
                    </tr>
                </thead>
            </table>
        </div>
    </div>  
<!--    <div class="zoom" <?= $bankrecp; ?> onclick="location.href = 'bankrecp.php?mode=last';">
        <div style="height: 305px; overflow-x: auto">

            <table class="table table-bordered" style="">
                <thead class="thead-dark">
                    <tr>
                <h6 class="chead" >Bank Receipt</h6>
                </tr>
                <tr>
                    <th scope="col" class="text-left">Sr</th>
                    <th scope="col" class="text-center">Voucher</th>
                    <th scope="col" class="text-center">Bank</th>
                    <th scope="col" class="text-center">Account</th>
                    <th scope="col" class="text-right">Amount</th>
                </tr>
                </thead>

                <tbody>
                    <?php
                    $tctr = 0;
                    $totamt = 0;
                    while ($cpmain = mysqli_fetch_array($getbankrecp)) {
                        $tctr++;
                        $vouchno = $cpmain['vouchno'];
                        $recpno = $cpmain['recpno'];
                        $amount = $cpmain['amount'];

                        $getac = mysqli_query($conn, "SELECT accode, name FROM `accmast` WHERE accode = '$cpmain[bankname]'")or die(mysqli_error($conn));
                        $fetac = mysqli_fetch_array($getac);
                        $acname = $fetac['name'];
                        $getac2 = mysqli_query($conn, "SELECT accode, name FROM `accmast` WHERE accode = '$cpmain[party]'")or die(mysqli_error($conn));
                        $fetac2 = mysqli_fetch_array($getac2);
                        $acname2 = $fetac2['name'];


                        Echo "<tr>";
                        Echo "<td class='subtd'>$tctr</td>";
                        Echo "<td class='subtd'><a href='bankrecp.php?mode=edit&vouchno=$vouchno' style='color: white;'>$vouchno</a></td>";
                        Echo "<td class='subtd'>$acname</td>";
                        Echo "<td class='subtd'>$acname2</td>";
                        Echo "<td class='subtd text-right'>$amount</td>";
                        Echo "</tr>";

                        $totamt = $totamt + $amount;
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <div >
            <table class="table table-bordered" style="">
                <thead class="">
                    <tr class="ttotal">
                        <td class="tottd text-center" ><?php echo $tctr; ?></td> 
                        <td class="tottd"></td> 
                        <td class="tottd">Total</td> 
                        <td class="tottd"><?php echo $totamt; ?></td> 
                    </tr>
                </thead>
            </table>

        </div>
    </div>
    <div class="zoom" <?= $bankpay; ?> onclick="location.href = 'bankpay.php?mode=last';">
        <div style="height: 305px; overflow-x: auto">

            <table class="table table-bordered" style="">
                <thead class="thead-dark">
                    <tr >
                <h6 class="chead" >Bank Payment</h6>
                </tr>
                <tr>
                    <th scope="col" class="text-left">Sr</th>
                    <th scope="col" class="text-center">Voucher</th>
                    <th scope="col" class="text-center">Bank</th>
                    <th scope="col" class="text-center">Account</th>
                    <th scope="col" class="text-right">Amount</th>
                </tr>
                </thead>

                <tbody>
                    <?php
                    $tctr = 0;
                    $totamt = 0;
                    while ($cpmain = mysqli_fetch_array($getbankpay)) {
                        $tctr++;
                        $vouchno = $cpmain['vouchno'];
                        $amount = $cpmain['amount'];

                        $getac = mysqli_query($conn, "SELECT accode, name FROM `accmast` WHERE accode = '$cpmain[bankname]' AND grpcode = '001' AND grpcode !=''")or die(mysqli_error($conn));
                        $fetac = mysqli_fetch_array($getac);
                        $acname = $fetac['name'];
                        $getac2 = mysqli_query($conn, "SELECT accode, name FROM `accmast` WHERE accode = '$cpmain[party]'")or die(mysqli_error($conn));
                        $fetac2 = mysqli_fetch_array($getac2);
                        $acname2 = $fetac2['name'];


                        Echo "<tr>";
                        Echo "<td class='subtd'>$tctr</td>";
                        Echo "<td class='subtd'><a href='bankpay.php?mode=edit&vouchno=$vouchno' style='color: white;'>$vouchno</a></td>";
                        Echo "<td class='subtd'>$acname</td>";
                        Echo "<td class='subtd'>$acname2</td>";
                        Echo "<td class='subtd text-right'>$amount</td>";
                        Echo "</tr>";

                        $totamt = $totamt + $amount;
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <div >
            <table class="table table-bordered" style="">
                <thead class="">
                    <tr class="ttotal">
                        <td class="tottd text-center" ><?php echo $tctr; ?></td> 
                        <td class="tottd"></td> 
                        <td class="tottd">Total</td> 
                        <td class="tottd"><?php echo $totamt; ?></td> 
                    </tr>
                </thead>
            </table>

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