<?php        // print_r($members);die(); 
?>
<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">Create Cash Book</li>
                </ol>
            </div>
        </div>
    </div>
</div>

<!-----------------------------   Income-Others Credited Amount ------------------>


<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">
                            Payment Details
                        </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">
                            <a href="" class="btn btn-primary btn-rounded mb-4" data-toggle="modal" data-target="#add_income">Add Income</a>
                            <a href="" class="btn btn-primary btn-rounded mb-4" data-toggle="modal" data-target="#add_expense">Add Expense</a>
                            <form method="post" action="<?php echo base_url(); ?>index.php/Member/cash_book_details" id="member_add_" enctype='multipart/form-data'>
                                <div class="row">

                                    <div class="col-sm-2">
                                        <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">Year
                                        <?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">
                                        <div>
                                            Date
                                        </div>
                                        <input type="date" name="added_on" id="added_on_id" value="<?php echo date("Y/m/d"); ?>" onchange="disable_month_year();" class="form-control">
                                    </div>
                                    <div class="col-sm-1 mt-4"><button type="submit" class="btn btn-primary">Submit</button></div>
                                </div>
                            </form><br>
                            <?php if (isset($cash_book) && count($cash_book) > 0) { ?>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="tile">
                                            <div class="tile-body" id="filter_id">
                                                <table id="table_ids1" class="table table-striped table-bordered" style="width:100%">
                                                    <thead>
                                                        <tr>
                                                            <th class="text-center">S No.</th>
                                                            <th class="text-center">Mem No</th>
                                                            <th class="text-center">Type</th>
                                                            <th class="text-center">Heading</th>
                                                            <th class="text-center">Sub Heading</th>
                                                            <th class="text-center">Amount</th>
                                                            <th class="text-center">Narration</th>
                                                            <th class="text-center">Date</th>
                                                            <th class="text-center">Action</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $sno = 1; ?>
                                                        <?php foreach ($cash_book as $data) : ?>
                                                            <tr <?php if ($data['is_cancelled'] == "1") {
                                                                    echo "style='background:yellow;'";
                                                                } ?>>
                                                                <td class="text-center">
                                                                    <?= $sno; ?>
                                                                </td>
                                                                <td class="text-center">
                                                                    <?php echo $data['mem_no'] . " " . $members_temp[$data['mem_no']]['mem_name']; ?>
                                                                </td>
                                                                <td class="text-center">
                                                                    <?php if ($data['type'] == "0") {
                                                                        echo "Income";
                                                                    } else {
                                                                        echo "Expense";
                                                                    } ?>
                                                                </td>
                                                                <td class="text-center">
                                                                    <div class="rec_div<?= $sno; ?>">
                                                                        <?= $category[$data['category']] ?>
                                                                    </div>
                                                                    <div style="display:none;" class="edit_div<?= $sno; ?>">
                                                                        <select name="category_edit" id="category_edit<?= $sno; ?>" onchange="get_sub_category_edit('<?= $sno; ?>');" class="form-control">
                                                                            <option value="">Select</option>
                                                                            <?php foreach ($category_array as $caste) { ?>
                                                                                <option <?php if ($data['category'] == $caste['id']) {
                                                                                            echo "selected";
                                                                                        } ?> value="<?php echo $caste['id']; ?>"><?php echo $caste['category']; ?></option>
                                                                            <?php } ?>
                                                                        </select>
                                                                    </div>
                                                                </td>
                                                                <td class="text-center">
                                                                    <div class="rec_div<?= $sno; ?>">
                                                                        <?= $sub_category[$data['sub_category']] ?>
                                                                    </div>
                                                                    <div style="display:none;" class="edit_div<?= $sno; ?>">
                                                                        <select name="sub_category_edit" id="sub_category_edit<?= $sno; ?>" class="form-control">
                                                                            <option value="">Select</option>
                                                                            <?php foreach ($sub_category_array as $caste) { ?>
                                                                                <option <?php if ($data['sub_category'] == $caste['id']) {
                                                                                            echo "selected";
                                                                                        } ?> value="<?php echo $caste['id']; ?>"><?php echo $caste['sub_category']; ?></option>
                                                                            <?php } ?>
                                                                        </select>
                                                                    </div>
                                                                </td>
                                                                <td class="text-center">
                                                                    <div class="rec_div<?= $sno; ?>">
                                                                        <?= $data['amount'] ?>
                                                                    </div>
                                                                    <div style="display:none;" class="edit_div<?= $sno; ?>">
                                                                        <input type="text" class="form-control" name="amount_edit" id="amount_edit<?= $sno; ?>" value="<?= $data['amount'] ?>">
                                                                    </div>
                                                                </td>
                                                                <td class="text-center">
                                                                    <div class="rec_div<?= $sno; ?>">
                                                                        <?= $data['explanation'] ?>
                                                                    </div>
                                                                    <div style="display:none;" class="edit_div<?= $sno; ?>">
                                                                        <input type="text" class="form-control" name="explanation_edit" id="explanation_edit<?= $sno; ?>" value="<?= $data['explanation'] ?>">
                                                                    </div>
                                                                </td>
                                                                <td class="text-center">
                                                                    <div class="rec_div<?= $sno; ?>">
                                                                        <?= date("d-m-Y", strtotime($data['paid_date'])); ?>
                                                                    </div>
                                                                    <div style="display:none;" class="edit_div<?= $sno; ?>">
                                                                        <input type="date" class="form-control" name="paid_date_edit" id="paid_date_edit<?= $sno; ?>" value="<?php echo date('Y-m-d', strtotime($data["paid_date"])) ?>">
                                                                    </div>
                                                                </td>
                                                                <td class="text-center">
                                                                    <button type="button" id="edit<?= $sno; ?>" class="btn btn-warning btn-xs" onclick="edit('<?= $sno; ?>');"><span class="fa fa-edit"></span><span class="sr-only"></span></button>
                                                                    <button type="button" style="display:none;" id="save<?= $sno; ?>" class="btn btn-primary" onclick="save('<?= $sno; ?>','<?= $data['id'] ?>');"><span class="fa fa-save"></span></button>
                                                                    <a href="<?php echo base_url() ?>index.php/Member/cancel_cash_book?id=<?php echo $data['id']; ?>" id="cancel<?= $sno; ?>" class="btn btn-danger btn-xs"><span class="fas fa-times"></span><span class="sr-only"></span></a>
                                                                    <a href="<?php echo base_url() ?>index.php/Member/remove_cash_book?id=<?php echo $data['id']; ?>" id="delete<?= $sno; ?>" class="btn btn-danger btn-xs"><span class="fa fa-trash"></span><span class="sr-only"></span></a>
                                                                </td>

                                                            </tr>
                                                            <?php $sno++; ?>
                                                        <?php endforeach; ?>
                                                    </tbody>

                                                </table>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php } ?>
                            <div class="modal fade" id="add_income" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header text-center">
                                            <h4 class="modal-title w-100 font-weight-bold">Add Data</h4>
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close" id="something">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                        </div>
                                        <div class="modal-body mx-3">
                                            <form method="post" action="<?php echo base_url(); ?>index.php/Member/insert_cash_book" id="member_add_" enctype='multipart/form-data'>
                                                <div class="md-form mb-4">
                                                    <label data-error="wrong" data-success="right" for="form2">Member Number</label>
                                                    <select name="member_number" id="member_number" class="form-control">
                                                        <option value="">Select</option>
                                                        <?php foreach ($members as $mem) { ?>
                                                            <option value="<?php echo $mem['me_no']; ?>"><?php echo $mem['mem_name']; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <div class="md-form mb-4">
                                                    <label data-error="wrong" data-success="right" for="form2">Statement</label>
                                                    <select name="statement" id="category_id" class="form-control">
                                                        <option value="">Select</option>
                                                        <?php foreach ($category_array as $caste) {
                                                            if ($caste['type'] == "0" || $caste['type'] == "1") {
                                                        ?>
                                                                <option value="<?php echo $caste['id']; ?>"><?php echo $caste['category']; ?></option>
                                                        <?php
                                                            }
                                                        } ?>
                                                    </select>
                                                </div>
                                                <div class="md-form mb-5">
                                                    <label data-error="wrong" data-success="right" for="form3">Sub Statement</label>
                                                    <select name="sub_category" id="sub_category" class="form-control">
                                                        <option value="">Select</option>
                                                        <?php foreach ($sub_category_array as $caste) { ?>
                                                            <option value="<?php echo $caste['sub_id']; ?>"><?php echo $caste['sub_category']; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <div class="md-form mb-5">
                                                    <label data-error="wrong" data-success="right" for="form3">Narration </label>
                                                    <input type="text" class="form-control validate" name="explanation">
                                                </div>
                                                <!-- <div class="md-form mb-4">
                                                    <label data-error="wrong" data-success="right" for="form2">Type</label>
                                                    <select name="type" class="form-control" id="type" onchange="set_cheque_details();">
                                                        <option value="">Select</option>
                                                        <option value="Cash">Cash</option>
                                                        <option value="Cheque">Cheque</option>
                                                    </select>
                                                </div> -->
                                                <div class="md-form mb-4">
                                                    <label data-error="wrong" data-success="right" for="form2">Bank</label>
                                                    <select name="bank" class="form-control" id="bank">
                                                        <option value="">--Select--</option>
                                                        <?php foreach ($banks as $bank) { ?>
                                                            <option value="<?php echo  $bank['bank']; ?>"><?php echo  $bank['bank']; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <!-- <div class="col-sm-9 cheque_details">
                                                    <div class="row">
                                                        <div class="col-8 col-sm-6">
                                                            <label data-error="wrong" data-success="right" for="form3">Cheque No:</label>
                                                            <input type="text" name="cheque_no" id="cheque_no" class="form-control">
                                                        </div>
                                                    </div>
                                                </div> -->
                                                <div class="md-form mb-5">
                                                    <label data-error="wrong" data-success="right" for="form3">Amount</label>
                                                    <input type="number" id="amount" class="form-control validate" name="amount">
                                                </div>

                                                <!-- <div class="md-form mb-5" id="cheque">
                                                    <label data-error="wrong" data-success="right" for="form3">Voucher No:</label>
                                                    <input type="number" id="voc_no" class="form-control validate" name="voc_no">
                                                </div> -->
                                                <div class="md-form mb-5">
                                                    <label data-error="wrong" data-success="right" for="form3">Paid Date</label>
                                                    <input type="date" id="date" class="form-control validate" name="date">
                                                </div>
                                        </div>
                                        <div class="modal-footer d-flex justify-content-center">
                                            <input type="hidden" name="payment_type" value="0">
                                            <button class="btn btn-primary" onclick="check();">Add <i class="fas fa-paper-plane-o ml-1"></i></button>
                                        </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                            <div class="modal fade" id="add_expense" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header text-center">
                                            <h4 class="modal-title w-100 font-weight-bold">Add Data</h4>
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close" id="something">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                        </div>
                                        <div class="modal-body mx-3">
                                            <form method="post" action="<?php echo base_url(); ?>index.php/Member/insert_cash_book" id="member_add_" enctype='multipart/form-data'>
                                                <div class="md-form mb-4">
                                                    <label data-error="wrong" data-success="right" for="form2">Member Number</label>
                                                    <select name="member_number" id="member_number" class="form-control">
                                                        <option value="">Select</option>
                                                        <?php foreach ($members as $mem) { ?>
                                                            <option value="<?php echo $mem['me_no']; ?>"><?php echo $mem['mem_name']; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <div class="md-form mb-4">
                                                    <label data-error="wrong" data-success="right" for="form2">Statement</label>
                                                    <select name="statement" onchange="get_sub_category_expense();" id="category_id1" class="form-control">
                                                        <option value="">Select</option>
                                                        <?php foreach ($category_array as $caste) {
                                                            if ($caste['type'] == "0" || $caste['type'] == "3") { ?>
                                                                <option value="<?php echo $caste['id']; ?>"><?php echo $caste['category']; ?></option>
                                                        <?php }
                                                        } ?>
                                                    </select>
                                                </div>
                                                <div class="md-form mb-5">
                                                    <label data-error="wrong" data-success="right" for="form3">Sub Statement</label>
                                                    <select name="sub_category" id="sub_category1" class="form-control">
                                                        <option value="">Select</option>
                                                        <?php foreach ($sub_category_array as $caste) { ?>
                                                            <option value="<?php echo $caste['sub_id']; ?>"><?php echo $caste['sub_category']; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <div class="md-form mb-5">
                                                    <label data-error="wrong" data-success="right" for="form3">Narration </label>
                                                    <input type="text" class="form-control validate" name="explanation">
                                                </div>
                                                <div class="md-form mb-4">
                                                    <label data-error="wrong" data-success="right" for="form2">Type</label>
                                                    <select name="type" class="form-control" id="type1" onchange="set_cheque_details1();">
                                                        <option value="">Select</option>
                                                        <option value="Cash">Cash</option>
                                                        <option value="Cheque">Cheque</option>
                                                    </select>
                                                </div>
                                                <div class="md-form mb-4 cheque_details1">
                                                    <label data-error="wrong" data-success="right" for="form2">Bank</label>
                                                    <select name="bank" class="form-control" id="bank1" onchange="display_cheque1();">
                                                        <option value="">--Select--</option>
                                                        <?php foreach ($banks as $bank) { ?>
                                                            <option value="<?php echo  $bank['bank']; ?>"><?php echo  $bank['bank']; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <div class="col-sm-9 cheque_details1">
                                                    <div class="row">
                                                        <div class="col-8 col-sm-6">
                                                            <label data-error="wrong" data-success="right" for="form3">Cheque No:</label>
                                                            <select name="cheque_no" id="cheque_no1" class="form-control">
                                                                <option value="">-- Select --</option>
                                                                <?php foreach ($cheque_details as $cd) { ?>
                                                                    <option value="<?php echo $cd['cheque_no']; ?>"><?php echo $cd['cheque_no'] . "-" . $cd['cheque_amount']; ?></option>
                                                                <?php } ?>
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="md-form mb-4 cheque_details1">
                                                    <label data-error="wrong" data-success="right" for="form2">Cheque Type</label>
                                                    <select name="cheque_type" class="form-control" id="cheque_type1" onchange="set_cheque_amount();">
                                                        <option value="">Select</option>
                                                        <option value="Individual">Individual</option>
                                                        <option value="Cash Group">Cash Group</option>
                                                    </select>
                                                </div>
                                                <div class="md-form mb-5">
                                                    <label data-error="wrong" data-success="right" for="form3">Amount</label>
                                                    <input type="number" id="amount1" class="form-control validate" name="amount">
                                                </div>

                                                <div class="md-form mb-5" id="cheque">
                                                    <label data-error="wrong" data-success="right" for="form3">Voucher No:</label>
                                                    <input type="number" id="voc_no1" class="form-control validate" name="voc_no">
                                                </div>
                                                <div class="md-form mb-5">
                                                    <label data-error="wrong" data-success="right" for="form3">Paid Date</label>
                                                    <input type="date" id="date1" class="form-control validate" name="date">
                                                </div>
                                        </div>
                                        <div class="modal-footer d-flex justify-content-center">
                                            <input type="hidden" name="payment_type" value="1">
                                            <button class="btn btn-primary" onclick="check1();">Add <i class="fas fa-paper-plane-o ml-1"></i></button>
                                        </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
        </div>
    </div>
</section>
</div>
</div>
</section>


<style>
    div.dt-buttons {
        margin-left: 176px;
    }

    div.dataTables_wrapper div.dataTables_length label {
        position: absolute;
    }

    div.dataTables_wrapper div.dataTables_filter {
        text-align: right;
        margin-top: -37px;
    }

    .copyButton {
        background-color: #dc3545;
        border: 1px solid white;
    }

    .excelButton {
        background-color: #dc3545;
        border: 1px solid white;

    }

    .pdfButton {
        background-color: #dc3545;
        border: 1px solid white;

    }

    .printButton {
        background-color: #dc3545;
        border: 1px solid white;

    }

    .colvisButton {
        background-color: #dc3545;
        border: 1px solid white;

    }
</style>




<script src="<?php echo base_url() ?>assets/datatables/dataTables.bootstrap.js"></script>
<script src="<?php echo base_url() ?>assets/datatables/jquery.dataTables.js"></script>
<script>
    var table = $('#table_id12').DataTable({
        "processing": true,
        "dom": 'lBfrtip',
        "lengthMenu": [
            [100, 250, 500, 1000, -1],
            [100, 250, 500, 1000, "All"]
        ],
        "buttons": {
            buttons: [{
                    extend: 'copy',
                    className: 'copyButton'
                },
                {
                    extend: 'excel',
                    className: 'excelButton'
                },
                {
                    extend: 'pdf',
                    className: 'pdfButton'
                },
                {
                    extend: 'print',
                    className: 'printButton'
                },
                {
                    extend: 'colvis',
                    className: 'colvisButton'
                },
            ]
        }

    });



    var table = $('#table_ids11').DataTable({
        "processing": true,
        "dom": 'lBfrtip',
        "lengthMenu": [
            [100, 250, 500, 1000, -1],
            [100, 250, 500, 1000, "All"]
        ],
        "buttons": {
            buttons: [{
                    extend: 'copy',
                    className: 'copyButton'
                },
                {
                    extend: 'excel',
                    className: 'excelButton'
                },
                {
                    extend: 'pdf',
                    className: 'pdfButton'
                },
                {
                    extend: 'print',
                    className: 'printButton'
                },
                {
                    extend: 'colvis',
                    className: 'colvisButton'
                },
            ]
        }

    });


    var table = $('#table_ids2').DataTable({
        "processing": true,
        "dom": 'lBfrtip',
        "lengthMenu": [
            [100, 250, 500, 1000, -1],
            [100, 250, 500, 1000, "All"]
        ],
        "buttons": {
            buttons: [{
                    extend: 'copy',
                    className: 'copyButton'
                },
                {
                    extend: 'excel',
                    className: 'excelButton'
                },
                {
                    extend: 'pdf',
                    className: 'pdfButton'
                },
                {
                    extend: 'print',
                    className: 'printButton'
                },
                {
                    extend: 'colvis',
                    className: 'colvisButton'
                },
            ]
        }

    });




    var table = $('#table_ids1').DataTable({
        "processing": true,
        "dom": 'lBfrtip',
        "lengthMenu": [
            [100, 250, 500, 1000, -1],
            [100, 250, 500, 1000, "All"]
        ],
        "buttons": {
            buttons: [{
                    extend: 'copy',
                    className: 'copyButton'
                },
                {
                    extend: 'excel',
                    className: 'excelButton'
                },
                {
                    extend: 'pdf',
                    className: 'pdfButton'
                },
                {
                    extend: 'print',
                    className: 'printButton'
                },
                {
                    extend: 'colvis',
                    className: 'colvisButton'
                },
            ]
        }

    });
</script>
<script>
    $(document).ready(function() {
        $(".cheque_details").hide();
        $('.alert').fadeOut(3000);
        var table = $('#table_id').DataTable({
            "processing": true,
            "dom": 'lBfrtip',
            "lengthMenu": [
                [10, 25, 50, -1],
                [10, 25, 50, "All"]
            ],
            "buttons": [
                'copyHtml5',
                'excelHtml5',
                'csvHtml5',
                'pdfHtml5'
            ]
        });

        $(".buttons-html5").addClass("btn btn-primary");
        $('.dt-buttons').addClass("pt-3 pb-0");

        $('#something').click(function() {
            location.reload();
        });
        $('#something1').click(function() {
            location.reload();
        });
        $('#something2').click(function() {
            location.reload();
        });
        $('#something3').click(function() {
            location.reload();
        });
    });
</script>




<script>
    function check() {
        var statement = $('#category_id').val();
        var amount = $('#amount').val();
        var sub_category = $('#sub_category').val();
        var date = $('#date').val();
        if (statement == "") {
            alert("Statement Must Be Filled Out");
            event.preventDefault();
        }
        if (amount == "") {
            alert("Amount Must Be Filled Out");
            event.preventDefault();
        }
        if (date == "") {
            alert("Date  Must Be Filled Out");
            event.preventDefault();
        }
    }

    function check1() {
        var statement = $('#category_id1').val();
        var amount = $('#amount1').val();
        var sub_category = $('#sub_category1').val();
        var date = $('#date1').val();
        if (statement == "") {
            alert("Statement Must Be Filled Out");
            event.preventDefault();
        }
        if (amount == "") {
            alert("Amount Must Be Filled Out");
            event.preventDefault();
        }
        if (date == "") {
            alert("Date  Must Be Filled Out");
            event.preventDefault();
        }
    }

    function set_cheque_details() {
        var type = $("#type").val();
        if (type == "Cheque") {
            $(".cheque_details").show();
        } else {
            $(".cheque_details").hide();
        }
    }

    function set_cheque_details1() {
        var type = $("#type1").val();
        if (type == "Cheque") {
            $(".cheque_details1").show();
        } else {
            $(".cheque_details1").hide();
        }
    }

    function set_cheque_amount() {
        var cheque_type1 = $("#cheque_type1").val();
        var cheque_details = $("#cheque_no1 option:selected").text();
        cheque_details = cheque_details.split("-");
        if (cheque_type1 == "Individual") {
            $("#amount1").val(cheque_details[1]);
        } else {
            $("#amount1").val('');
        }
    }

    function edit(sno) {
        $('.rec_div' + sno).hide();
        $('.edit_div' + sno).show();
        $('#save' + sno).show();
        $('#edit' + sno).hide();
    }

    function save(sno, id) {
        var explanation = $("#explanation_edit" + sno).val();
        var statement = $('#category_edit' + sno).val();
        var amount = $('#amount_edit' + sno).val();
        var sub_category = $('#sub_category_edit' + sno).val();
        var paid_date = $('#paid_date_edit' + sno).val();
        if (statement == "") {
            alert("Statement Must Be Filled Out");
            return false;
        }
        if (amount == "") {
            alert("Amount Must Be Filled Out");
            return false;
        }
        if (paid_date == "") {
            alert("Date  Must Be Filled Out");
            return false;
        }
        $.ajax({
            type: 'POST',
            url: "<?php echo base_url() ?>index.php/Member/update_cash_book",
            data: {
                category: statement,
                amount: amount,
                sub_category: sub_category,
                explanation: explanation,
                paid_date: paid_date,
                id: id
            },
            dataType: 'html',
            success: function(data) {
                if (data == 1) {
                    alert('updated Successfully..');
                    location.reload();
                }
            }
        });
    }

    function get_sub_category_edit(sno) {
        var category_edit = $('#category_edit' + sno).val();
        if (category_edit != '') {
            $.ajax({
                url: "<?php echo base_url(); ?>index.php/Member/get_sub_category",
                method: "POST",
                data: {
                    expense_category: category_edit
                },
                success: function(data) {
                    $('#sub_category_edit').html(data);
                }
            });
        } else {
            $('#sub_category_edit').html('<option value="">Select</option>');
        }
    }

    function get_sub_category_expense(sno) {
        var category_edit = $('#category_id1').val();
        if (category_edit != '') {
            $.ajax({
                url: "<?php echo base_url(); ?>index.php/Member/get_sub_category",
                method: "POST",
                data: {
                    category_id: category_edit
                },
                success: function(data) {
                    $('#sub_category1').html(data);
                }
            });
        } else {
            $('#sub_category1').html('<option value="">Select</option>');
        }
    }

    function list() {
        $income = $('#income').val();
        $income_char = $('#income_char');
        $income_char.val() = $income;
    }

    function others_list() {
        $income = $('#income').val();
        $income_char = $('#income_char');
        $income_char.val() = $income;
    }

    function s_otherslist() {
        $income = $('#income').val();
        $income_char = $('#income_char');
        $income_char.val() = $income;
    }

    $('#category_id').change(function() {
        var category_id = $('#category_id').val();
        if (category_id != '') {
            $.ajax({
                url: "<?php echo base_url(); ?>index.php/Member/get_sub_category",
                method: "POST",
                data: {
                    category_id: category_id
                },
                success: function(data) {
                    $('#sub_category').html(data);
                }
            });
        }
    });

    $(document).ready(function() {
        $('#income').change(function() {
            var temp_array = [];
            var income2;
            var income;
            var income1 = $('#income').val();
            temp_array = income1.split("-");
            income = temp_array[0];
            if (income != '') {
                $.ajax({
                    url: "<?php echo base_url(); ?>index.php/Member/income_t_search",
                    method: "POST",
                    data: {
                        income: income
                    },
                    success: function(data) {
                        $('#itamil_id').html(data);
                    }
                });
            }
        });

        $('#income_others').change(function() {
            var temp_array = [];
            var income2;
            var income;
            var income1 = $('#income_others').val();
            temp_array = income1.split("-");
            income = temp_array[0];
            if (income != '') {
                $.ajax({
                    url: "<?php echo base_url(); ?>index.php/Member/income_t_others_search",
                    method: "POST",
                    data: {
                        income: income
                    },
                    success: function(data) {
                        $('#itamil_id1').html(data);
                    }
                });
            }
        });
        $('#income_sub_category').change(function() {
            var temp_array = [];
            var income2;
            var income;
            var income1 = $('#income_sub_category').val();
            temp_array = income1.split("-");
            income = temp_array[0];
            if (income != '') {
                $.ajax({
                    url: "<?php echo base_url(); ?>index.php/Member/income_sub_t_others_search",
                    method: "POST",
                    data: {
                        income: income
                    },
                    success: function(data) {
                        $('#income_sub_category1').html(data);
                    }
                });
            }
        });

        $('#expense_others1').change(function() {
            var temp_array = [];
            var income2;
            var income;
            var income1 = $('#expense_others1').val();
            temp_array = income1.split("-");
            income = temp_array[0];
            if (income != '') {
                $.ajax({
                    url: "<?php echo base_url(); ?>index.php/Member/income_sub_t_others_search",
                    method: "POST",
                    data: {
                        income: income
                    },
                    success: function(data) {
                        $('#etamil_id1').html(data);
                    }
                });
            }
        });

        $('#expense_others_sub').change(function() {
            var temp_array = [];
            var income2;
            var income;
            var income1 = $('#expense_others_sub').val();
            temp_array = income1.split("-");
            income = temp_array[0];
            if (income != '') {
                $.ajax({
                    url: "<?php echo base_url(); ?>index.php/Member/expense_sub_t_others_search1",
                    method: "POST",
                    data: {
                        income: income
                    },
                    success: function(data) {
                        $('#expense_sub_category1').html(data);
                    }
                });
            }
        });


    });

    $('#expense_category').on('change', function() {
        var temp_array = [];
        var expense;
        var expense_category = this.value;
        temp_array = expense_category.split("-");
        expense = temp_array[1];
        $.ajax({
            type: 'POST',
            url: "<?php echo base_url() ?>index.php/Member/get_expense_category",
            data: {
                expense: expense
            },
            dataType: 'html',
            success: function(data) {

                $('#expense_Statement_category').html(data);
            }
        });
    });

    $('#income_others').on('change', function() {
        var temp_array = [];
        var expense;
        var income_others = this.value;
        temp_array = income_others.split("-");
        expense = temp_array[1];
        $.ajax({
            type: 'POST',
            url: "<?php echo base_url() ?>index.php/Member/get_income_others",
            data: {
                expense: expense
            },
            dataType: 'html',
            success: function(data) {

                $('#income_sub_category').html(data);
            }
        });
    });
    $('#expense_others1').on('change', function() {
        var temp_array = [];
        var expense;
        var income_others = this.value;
        temp_array = income_others.split("-");
        expense = temp_array[1];
        $.ajax({
            type: 'POST',
            url: "<?php echo base_url() ?>index.php/Member/get_expense_category",
            data: {
                expense: expense
            },
            dataType: 'html',
            success: function(data) {

                $('#expense_others_sub').html(data);
            }
        });
    });

    $('#expense_category').change(function() {
        var expense_category = $('#expense_category').val();
        if (expense_category != '') {
            $.ajax({
                url: "<?php echo base_url(); ?>index.php/Member/get_sub_category",
                method: "POST",
                data: {
                    expense_category: expense_category
                },
                success: function(data) {
                    $('#sub_category').html(data);
                }
            });
        } else {
            $('#sub_category').html('<option value="">Select</option>');
        }
    });

    function disable_month_year() {
        var added_on = $("#added_on_id").val();
        if (added_on != "") {
            // $("#division_id").val("");
            // $("#section_id").val("");
            $("#month_id").val("");
            $("#year_id").val("");

            $('#month_id').prop('disabled', 'disabled');
            $('#year_id').prop('disabled', 'disabled');
            $("#division_id").attr("readonly", true);
            $("#section_id").attr("readonly", true);
            $('#division_id').prop('disabled', 'disabled');
            $('#section_id').prop('disabled', 'disabled');
        } else {
            $('#month_id').prop('disabled', false);
            $('#year_id').prop('disabled', false);
            $("#division_id").attr("readonly", false);
            $("#section_id").attr("readonly", false);
            $('#division_id').prop('disabled', false);
            $('#section_id').prop('disabled', false);
        }
    }


    function display_cheque() {
        var cheque = $("#to").val();
        if (cheque == "Cash") {
            $("#cheque").hide();
        } else {
            $("#cheque").show();

        }
    }


    function get_cheque() {
        var cheque_no = $('#cheque_no').val();
        if (cheque_no != '') {
            $.ajax({
                url: "<?php echo base_url(); ?>index.php/Member/get_cheque",
                method: "POST",
                data: {
                    cheque_no: cheque_no
                },
                dataType: 'json',
                success: function(data) {
                    $('#cheque_amount').val(data.cheque_amount);
                    $('#distribute').val(data.distribute);
                    $('#status').val(data.status);

                }
            });
        }
    }
</script>