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

$formname = "Cash Bank Position";
$file = "cashbankposn.php";
$grid = "";
$zroot = $_SESSION["zdbroot"];

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

mysqli_select_db($conn, $zdb);

$seriescond = "";

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

<link href="MyStyle/rep_format.css" type="text/css">
<style type="text/css">
    #tabital {
        font-style: italic;
    }

    #font1 {
        font-style: italic;
    }

    #boldfont {
        font-weight: bold;
    }

    .mtotclr {
        color: #0098DA;
    }

    .ttotclr {
        color: #ed3237;
    }

    .getdtl {
        font-size: 14px;
    }

    .BtnAli {
        align-items: center;
        appearance: none;
        background: transparent;
        border: 3px solid #40916c;
        border-radius: 6px;
        box-sizing: border-box;
        color: #40916c;
        cursor: pointer;
        display: inline-flex;
        font-family: "JetBrains Mono", monospace;
        height: 38px;
        width: 150px;
        justify-content: center;
        line-height: 1;
        list-style: none;
        overflow: hidden;
        padding-left: 16px;
        padding-right: 16px;
        position: relative;
        text-align: left;
        text-decoration: none;
        transition: box-shadow .15s, transform .15s;
        user-select: none;
        -webkit-user-select: none;
        touch-action: manipulation;
        white-space: nowrap;
        will-change: box-shadow, transform;
        font-size: 18px;
    }

    .BtnAli:active {
        box-shadow: #40916c 0 3px 7px inset;
        transform: translateY(2px);
    }

    a {
        color: #000000;
    }
    a:hover {
        color: #000000;
        text-decoration: none;
    }
    
    .table-hover>tbody>tr:hover {
        color: #000000;
        font-weight: bold;
        background-color: #9dd4bb;
    }
</style>

<script src="MyScript/cash_search.js?a=<?= mt_rand() ?>" type="text/javascript"></script>
</head>

<body>

    <div class="container">
        <div class="row" style="padding-top:1%">
            <div class="col-lg-2 col-md-1 col-sm-2 col-xs-2 pad text-center">
                <a href="cash.php?mode=true" class="BtnAli">Add New</a>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                <table class="table1 table-bordered myTable table-hover" style="width:100%">
                    <thead class="mySearchTr">
                        <tr>
                            <center>
                                <h3 style="background-color:#40916c;color:whitesmoke;border: 1px solid black;">CASH /
                                    BANK &nbsp; POSITIONS</h3>
                            </center>
                        </tr>

                        <tr style="height:30px">
                            <th style="color:black;width:20%" colspan="2"><b>Account</b></th>
                            <th style="color:black;width:9%" class="text-right"><b>INR</b></th>
                            <th style="color:black;width:5%" class="text-center"><b>View</b></th>
                        </tr>
                    </thead>

                    <tr class='filters noPrint' style="height:30px">
                        <th style="width:20%;" class="filter-container" colspan="2">
                            <input type="text" class="filter" name="account" placeholder="Account" data-col="account">
                        </th>
                        <th style="width:9%;" class="filter-container">
                            <input type="text" class="filter text-right" name="inr" placeholder="INR" data-col="inr">
                        </th>
                        <th style="width:5%;" class="filter-container"></th>
                    </tr>

                    <tbody>

                        <?php

                        $getdata = mysqli_query($conn, "Select * from accmast where grpcode = '002' or grpcode = '001'") or die(mysqli_error($conn));

                        while ($pmain = mysqli_fetch_array($getdata)) {

                            $maccode = $pmain['accode'];
                            $mopbal = $pmain['openbal'];
                            $mdc = $pmain['dc'];

                            if ($mdc == "D") {
                                $opbal = $mopbal * -1;
                            } else {
                                $opbal = $mopbal;
                            }

                            $getdep = mysqli_query($conn, "SELECT sum(amount) as tamt FROM `actran` where accode = '$maccode'") or die(mysqli_error($conn));
                            $fetdep = mysqli_fetch_array($getdep);

                            $abalamt = $fetdep['tamt'];
                            $balamt = $opbal + $abalamt;

                            // if ($tbal != 0) {
                        
                            $file = "cash.php?accode=$maccode&mode=edit";

                            echo "<tr class='getdtl' style='height:30px;'  >";
                            echo "<td colspan='2' style ='font-size:13px;font-weight:bold'><a href='cashbook_in_out.php?accode=$maccode' target='_blank'>$pmain[name]</a></td>";
                            echo "<td class='getdtl text-right'>$balamt</td>";
                            echo "<td align='center'><a href='$file' target='_blank'><i class='fa fa-1x fa-desktop'></i></a></td>";
                            echo "</tr>";

                            $totbalamt = $totbalamt + $balamt;
                            // }
                        }

                        echo "<tr class='getdtl' style='height:30px;background-color:#c1c1c1'>";
                        echo "<td colspan='2' class='getdtl text-right'><b>Total</b></td>";
                        echo "<td class='getdtl text-right'><b>$totbalamt</b></td>";
                        echo "<td align='center'></td>";
                        echo "</tr>";

                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

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

</body>

</html>