<style>
    @media print {
        body * {
            visibility: hidden;
        }

        .print-container,
        .print-container * {
            visibility: visible;
        }
    }
</style>



<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <!-- <h1 class="m-0">Deactive Member </h1> -->
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="#">Books</a></li>
                    <li class="breadcrumb-item active">Cash Book</li>
                </ol>
            </div>
        </div>
    </div>
</div>




<section class="content">
    <div class="container-fluid">




        <div class="row">

            <section class="col-lg-12 connectedSortable">

                <div class="card">
                    <div class="card-header " style="background-color:#31708e;color:white">
                        <h3 class="card-title">
                            Cash book
                        </h3>
                        <div class="card-tools">
                            <ul class="nav nav-pills ml-auto">
                            </ul>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="tab-content p-0">

                            <?php if (isset($_SESSION['mem_add']) && $_SESSION['mem_add'] != "") { ?>
                                <div class="alert alert-success">
                                    <strong><?php echo $_SESSION['mem_add']; ?></strong>
                                </div>
                            <?php $_SESSION['mem_add'] = "";
                            } ?>

                            <form method="post" action="<?php echo base_url(); ?>index.php/Demand/day_book" id="member_add_" enctype='multipart/form-data'>
                                <div class="row">
                                    <div class="col-sm-3">
                                        <div>
                                            Date
                                        </div>
                                        <input type="date" name="added_on" id="added_on_id" value="<?php if ($added_on != "") {
                                                                                                        echo date("Y-m-d", strtotime($added_on));
                                                                                                    } else {
                                                                                                        echo date("Y-m-d");
                                                                                                    } ?>" onchange="disable_month_year();" class="form-control ">
                                    </div>
                                    <!-- <div class="col-sm-3">
                                        <div>Month</div>
                                        <select name="month" id="month_id" class="form-control ">
                                            <option value="">Select Month</option>
                                            <option value="January">January</option>
                                            <option value="February">February</option>
                                            <option value="March">March</option>
                                            <option value="April">April</option>
                                            <option value="May">May</option>
                                            <option value="June">June</option>
                                            <option value="July">July</option>
                                            <option value="August">August</option>
                                            <option value="September">September</option>
                                            <option value="October">October</option>
                                            <option value="November">November</option>
                                            <option value="December">December</option>
                                        </select>
                                    </div>
                                    <div class="col-sm-2">

                                        <div>Year</div>
                                        <?php $y = date('Y'); ?>
                                        <select name="year" id="year_id" class="form-control">
                                            <option value="">Select Year</option>
                                            <?php for ($j = $y; $j >= 2022; $j--) { ?>
                                                <option <?php if ($j == $y) {
                                                            echo "";
                                                        } ?> value="<?php echo $j; ?>"><?php echo $j; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div> -->
                                    <div class="col-sm-2 mt-4"><button type="submit" class="btn btn-primary">Submit</button></div>
                                </div>
                            </form>

                            <?php $sno = 0;
                            $member_ft = 0; ?>

                            <?php if ((isset($total_amount) && count($total_amount) > 0) || (isset($income_cashbook) && count($income_cashbook) > 0) || (isset($expense_cashbook) && count($expense_cashbook) > 0) || (isset($cancelled_cashbook) && count($cancelled_cashbook) > 0)) { ?>
                                <div class="print-container">
                                    <br>
                                    <center>
                                        <h1> <?php if ($month != "" &&  $year != "") {
                                                    echo $month . ' + ' . $year;
                                                } else if ($year != "") {
                                                    echo $year;
                                                } else if ($month != "") {
                                                    echo $month;
                                                } else {
                                                    echo date("d-m-Y", strtotime($added_on));
                                                } ?></h1>
                                    </center>
                                    <div class="row">

                                        <div class="col-sm-6" style="padding-right: 0px;">
                                            <div class="tile">
                                                <div class="tile-body">
                                                    <br><br>
                                                    <center>
                                                        <h3>Receipt (Cr.)</h3>
                                                    </center><br>

                                                    <table id="" class="table table-striped table-bordered " style="width:100%">
                                                        <thead>
                                                            <tr>
                                                                <th class="text-center">S.No.</th>
                                                                <th class="text-center">Bank</th>
                                                                <th class="text-center">Particulars</th>
                                                                <th class="text-center">Cash</th>
                                                                <th class="text-center">Adjustments</th>
                                                                <th class="text-center">Total</th>
                                                            </tr>
                                                        </thead>
                                                        <!-- Here's where we iterate through our $articles query object, printing out article info -->
                                                        <tbody>
                                                            <?php $sno = 1;
                                                            $total_adj = 0;
                                                            $total_cash = 0;
                                                            $ex_total_adj = 0;
                                                            $ex_total_cash = 0;
                                                            ?>

                                                            <?php
                                                            foreach ($total_amount as $key => $pay) {
                                                                foreach ($pay as $key1 => $amount) {
                                                                    $cash_amt = 0;
                                                                    $bank_amt = 0;
                                                                    if ($key1 == "Cash") {
                                                                        $cash_amt = $pay['Cash'];
                                                                    } else {
                                                                        $bank_amt = $amount;
                                                                    }
                                                            ?>
                                                                    <tr>

                                                                        <td class="text-center">
                                                                            <?= $sno ?>
                                                                        </td>
                                                                        <td class="text-center">

                                                                        </td>
                                                                        <td class="text-left  text-danger">
                                                                            <b><?= $key; ?></b>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt  ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $bank_amt; ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt + $bank_amt;
                                                                            $total_adj += $bank_amt;
                                                                            $total_cash += $cash_amt;
                                                                            ?>
                                                                        </td>
                                                                    </tr>
                                                                    <?php $sno++; ?>
                                                            <?php
                                                                }
                                                            } ?>
                                                            <?php
                                                            foreach ($income_cashbook as $key => $pay) {
                                                                foreach ($pay as $key1 => $amount) {
                                                                    $cash_amt = 0;
                                                                    $bank_amt = 0;
                                                                    if ($key1 == "Cash") {
                                                                        $cash_amt = $pay['Cash'];
                                                                    } else {
                                                                        $bank_amt = $amount;
                                                                    }
                                                            ?>
                                                                    <tr>
                                                                        <td class="text-center">
                                                                            <?= $sno ?>
                                                                        </td>
                                                                        <td class="text-center">

                                                                        </td>
                                                                        <td class="text-left  text-danger">
                                                                            <b><?= $key; ?></b>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt  ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $bank_amt; ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt + $bank_amt;
                                                                            $total_adj += $bank_amt;
                                                                            $total_cash += $cash_amt;
                                                                            ?>
                                                                        </td>
                                                                    </tr>
                                                                    <?php $sno++; ?>
                                                            <?php
                                                                }
                                                            } ?>
                                                            <?php
                                                            foreach ($banks as $bank) {
                                                                $hno = 1;
                                                                foreach ($expense_cheque_cashbook as $key => $pay) {
                                                                    if (isset($pay[$bank['bank']]) && $pay[$bank['bank']] > 0) {
                                                            ?>
                                                                        <tr style='background:yellow;'>
                                                                            <td class="text-center">
                                                                                <?= $sno ?>
                                                                            </td>
                                                                            <td class="text-center text-danger">
                                                                                <?php if ($hno == 1) {
                                                                                    echo '<b>' . $bank['bank'] . '</b>';
                                                                                } ?>
                                                                            </td>

                                                                            <td class="text-left  text-danger">
                                                                                <b><?= $key; ?></b>
                                                                            </td>
                                                                            <td class="text-center">
                                                                                <?= $pay['Cash']; ?>
                                                                            </td>
                                                                            <td class="text-center">
                                                                                <?= $pay[$bank['bank']]; ?>
                                                                            </td>
                                                                            <td class="text-center">
                                                                                <?= $pay[$bank['bank']];
                                                                                $ex_total_adj += $pay[$bank['bank']];
                                                                                $ex_total_cash += $pay['Cash'];
                                                                                ?>
                                                                            </td>
                                                                        </tr>
                                                                        <?php $sno++;
                                                                        $hno++; ?>
                                                            <?php
                                                                    }
                                                                }
                                                            } ?>

                                                            <?php
                                                            foreach ($cancelled_cashbook as $key => $pay) {
                                                                foreach ($pay as $key1 => $amount) {
                                                                    $cash_amt = 0;
                                                                    $bank_amt = 0;
                                                                    if ($key1 == "Cash") {
                                                                        $cash_amt = $pay['Cash'];
                                                                    } else {
                                                                        $bank_amt = $amount;
                                                                    }
                                                            ?>
                                                                    <tr>
                                                                        <td class="text-center">
                                                                            <?= $sno ?>
                                                                        </td>
                                                                        <td class="text-center">

                                                                        </td>

                                                                        <td class="text-left  text-danger">
                                                                            <b><?= $key; ?></b>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt  ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $bank_amt; ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt + $bank_amt;
                                                                            $total_adj += $bank_amt;
                                                                            $total_cash += $cash_amt;
                                                                            ?>
                                                                        </td>
                                                                    </tr>
                                                                    <?php $sno++; ?>
                                                            <?php
                                                                }
                                                            } ?>
                                                            <?php for ($k = 0; $k < $balance_count; $k++) { ?>
                                                                <tr>
                                                                    <td class="text-center">
                                                                        <?= $sno ?>
                                                                    </td>
                                                                    <td class="text-center">

                                                                    </td>

                                                                    <td class="text-center">

                                                                    </td>
                                                                    <td class="text-center">

                                                                    </td>
                                                                    <td class="text-center">

                                                                    </td>
                                                                    <td class="text-center">

                                                                    </td>
                                                                </tr>
                                                                <?php $sno++; ?>
                                                            <?php } ?>
                                                            <tr>
                                                                <td class="text-center">

                                                                </td>
                                                                <td>

                                                                </td>
                                                                <td class="text-center">

                                                                </td>
                                                                <td class="text-center">
                                                                    <b> <?php echo   $total_cash + $ex_total_cash; ?></b>
                                                                </td>
                                                                <td class="text-center">
                                                                    <b> <?php echo  $total_adj + $ex_total_adj; ?></b>
                                                                </td>
                                                                <td class="text-center">
                                                                    <b> <?php echo $total_cash + $total_adj + $ex_total_cash + $ex_total_adj; ?></b>
                                                                </td>
                                                            </tr>
                                                        </tbody>
                                                    </table>

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

                                        <div class="col-sm-6" style="padding-left: 0px;">
                                            <div class="tile">
                                                <div class="tile-body">
                                                    <br><br>
                                                    <center>
                                                        <h3>Payment (Dr.)</h3>
                                                    </center><br>
                                                    <table id="" class="table table-striped table-bordered " style="width:100%">
                                                        <thead>
                                                            <tr>
                                                                <th class="text-center">S.No.</th>
                                                                <th class="text-center">Bank</th>
                                                                <th class="text-center">Particulars</th>
                                                                <th class="text-center">Cash</th>
                                                                <th class="text-center">Adjustments</th>
                                                                <th class="text-center">Total</th>
                                                            </tr>
                                                        </thead>
                                                        <!-- Here's where we iterate through our $articles query object, printing out article info -->
                                                        <tbody>
                                                            <?php $sno = 1;
                                                            $total_adj = 0;
                                                            $total_cash = 0;
                                                            $ex_total_adj = 0;
                                                            $ex_total_cash = 0;
                                                            ?>

                                                            <?php
                                                            foreach ($banks as $bank) {
                                                                $hno = 1;
                                                                foreach ($total_amount_member as $key => $pay) {

                                                                    if (isset($pay[$bank['bank']]) && $pay[$bank['bank']] > 0) {
                                                                        // echo "<pre>";
                                                                        // print_r($pay);
                                                                        // print_r($bank);
                                                                        // die();
                                                            ?>
                                                                        <tr>
                                                                            <td class="text-center">
                                                                                <?= $sno ?>
                                                                            </td>
                                                                            <td class="text-center text-danger">
                                                                                <?php if ($hno == 1) {
                                                                                    echo '<b>' . $bank['bank'] . '</b>';
                                                                                } ?>
                                                                            </td>
                                                                            <td class="text-left text-danger">
                                                                                <b><?= $key; ?></b>
                                                                            </td>
                                                                            <td class="text-center">
                                                                                <?= $pay['Cash']; ?>
                                                                            </td>
                                                                            <td class="text-center">
                                                                                <?= $pay[$bank['bank']]; ?>
                                                                            </td>
                                                                            <td class="text-center">
                                                                                <?= $pay[$bank['bank']];
                                                                                $total_adj += $pay[$bank['bank']];
                                                                                $total_cash += $pay['Cash'];
                                                                                ?>
                                                                            </td>
                                                                        </tr>
                                                                        <?php $sno++;
                                                                        $hno++; ?>
                                                            <?php
                                                                    }
                                                                }
                                                            } ?>

                                                            <?php
                                                            foreach ($income_cashbook as $key => $pay) {
                                                                foreach ($pay as $key1 => $amount) {
                                                                    $cash_amt = 0;
                                                                    $bank_amt = 0;
                                                                    if ($key1 == "Cash") {
                                                                        $cash_amt = $pay['Cash'];
                                                                    } else {
                                                                        $bank_amt = $amount;
                                                                    }
                                                            ?>
                                                                    <tr>
                                                                        <td class="text-center">
                                                                            <?= $sno ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <b><?= $key1; ?></b>
                                                                        </td>
                                                                        <td class="text-left  text-danger">
                                                                            <b><?= $key; ?></b>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt  ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $bank_amt; ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt + $bank_amt;
                                                                            $total_adj += $bank_amt;
                                                                            $total_cash += $cash_amt;
                                                                            ?>
                                                                        </td>
                                                                    </tr>
                                                                    <?php $sno++; ?>
                                                            <?php
                                                                }
                                                            } ?>

                                                            <?php
                                                            foreach ($expense_cashbook as $key => $pay) {
                                                                foreach ($pay as $key1 => $amount) {
                                                                    $cash_amt = 0;
                                                                    $bank_amt = 0;
                                                                    if ($key1 == "Cash") {
                                                                        $cash_amt = $pay['Cash'];
                                                                    } else {
                                                                        $bank_amt = $amount;
                                                                    }
                                                            ?>
                                                                    <tr>
                                                                        <td class="text-center">
                                                                            <?= $sno ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <b><?= $key1; ?></b>
                                                                        </td>
                                                                        <td class="text-left  text-danger">
                                                                            <b><?= $key; ?></b>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt  ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $bank_amt; ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt + $bank_amt;
                                                                            $ex_total_adj += $bank_amt;
                                                                            $ex_total_cash += $cash_amt;
                                                                            ?>
                                                                        </td>
                                                                    </tr>
                                                                    <?php $sno++; ?>
                                                            <?php
                                                                }
                                                            } ?>
                                                            <?php
                                                            foreach ($cancelled_cashbook as $key => $pay) {
                                                                foreach ($pay as $key1 => $amount) {
                                                                    $cash_amt = 0;
                                                                    $bank_amt = 0;
                                                                    if ($key1 == "Cash") {
                                                                        $cash_amt = $pay['Cash'];
                                                                    } else {
                                                                        $bank_amt = $amount;
                                                                    }
                                                            ?>
                                                                    <tr>
                                                                        <td class="text-center">
                                                                            <?= $sno ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <b><?= $key1; ?></b>
                                                                        </td>
                                                                        <td class="text-left  text-danger">
                                                                            <b><?= $key; ?></b>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt  ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $bank_amt; ?>
                                                                        </td>
                                                                        <td class="text-center">
                                                                            <?= $cash_amt + $bank_amt;
                                                                            ?>
                                                                        </td>
                                                                    </tr>
                                                                    <?php $sno++; ?>
                                                            <?php
                                                                }
                                                            } ?>
                                                            <?php for ($k = 0; $k < $balance_member_count; $k++) { ?>
                                                                <tr>
                                                                    <td class="text-center">
                                                                        <?= $sno ?>
                                                                    </td>
                                                                    <td class="text-center">

                                                                    </td>
                                                                    <td class="text-center">

                                                                    </td>
                                                                    <td class="text-center">

                                                                    </td>
                                                                    <td class="text-center">

                                                                    </td>
                                                                    <td class="text-center">

                                                                    </td>
                                                                </tr>
                                                                <?php $sno++; ?>
                                                            <?php } ?>
                                                            <tr>
                                                                <td class="text-center">

                                                                </td>
                                                                <td>

                                                                </td>
                                                                <td class="text-center">

                                                                </td>
                                                                <td class="text-center">
                                                                    <b> <?php echo   $total_cash + $ex_total_cash; ?></b>
                                                                </td>
                                                                <td class="text-center">
                                                                    <b> <?php echo  $total_adj + $ex_total_adj; ?></b>
                                                                </td>
                                                                <td class="text-center">
                                                                    <b> <?php echo $total_cash + $total_adj + $ex_total_cash + $ex_total_adj; ?></b>
                                                                </td>
                                                            </tr>
                                                        </tbody>
                                                    </table>

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <center>
                                    <form>
                                        <input type="submit" onclick="window.print(); " class="btn btn-primary" value="Print" />
                                    </form>
                                </center>
                            <?php } ?>
                        </div>
                    </div>
                </div>
        </div>
</section>
</div>
</div>
</section>