<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">Sub 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">
                            Receipt 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">

                            <?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'] = "";
                            } ?>

                        </div>
                        <form method="post" action="<?php echo base_url(); ?>index.php/Demand/sub_day_book" id="member_add_" enctype='multipart/form-data'>
                            <div class="row">
                                <div class="col-sm-3">
                                    <div>Division</div>
                                    <select name="division" id="division_id" class="form-control">
                                        <option value="">All</option>
                                        <?php foreach ($divisions as $div) { ?>
                                            <option value="<?php echo $div['division']; ?>"><?php echo $div['division']; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <div>Section</div>
                                    <select name="section" id="section_id" class="form-control">
                                        <option value="">All</option>
                                        <?php foreach ($sections as $sec) { ?>
                                            <option value="<?php echo $sec['section']; ?>"><?php echo $sec['section']; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>

                                <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 >= 2023; $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>


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

                        <?php if (isset($members) && count($members) > 0) { ?>
                            <div class="row">
                                <div class="col-sm-12">
                                    <br><br>
                                    <div class="tile">
                                        <div class="tile-body" style="overflow-x: scroll;">
                                            <table id="receipt_detail" class="table table-striped table-bordered" style="width:100%;font-size:14px;">

                                                <thead>
                                                    <tr>
                                                        <th class="text-center">M.No</th>
                                                        <th class="text-center">R.No</th>
                                                        <th class="text-center">Member Name</th>
                                                        <th class="text-center">Loan No.</th>
                                                        <th class="text-center">Share</th>
                                                        <th class="text-center">Books</th>
                                                        <th class="text-center">E.F</th>
                                                        <th class="text-center">Thrift</th>
                                                        <th class="text-center">Principal</th>
                                                        <th class="text-center">Int</th>
                                                        <!-- <th class="text-center">P.Int</th> -->
                                                        <!-- <th class="text-center">Fl Pri</th>
                                                        <th class="text-center">FL Int</th>
                                                        <th class="text-center">FP.Int</th> -->
                                                        <th class="text-center">Others</th>
                                                        <th class="text-center">Ins</th>
                                                        <th class="text-center">Due By</th>
                                                        <!-- <th class="text-center">Due To</th> -->
                                                        <th class="text-center">Total</th>
                                                        <th class="text-center">Paid On</th>
                                                        <th class="text-center">Action</th>
                                                        <th class="text-center">Message</th>
                                                        <th class="text-center">Rec</th>
                                                    </tr>
                                                </thead>
                                                <!-- Here's where we iterate through our $articles query object, printing out article info -->
                                                <tbody>
                                                    <?php $sno = 0;
                                                    $tot_td = 0;
                                                    $tot_loan_pri = 0;
                                                    $tot_loan_int = 0;
                                                    $tot_last_pri = 0;
                                                    $tot_last_int = 0;
                                                    $tot_f_pri = 0;
                                                    $tot_f_int = 0;
                                                    $tot_f_old_pri = 0;
                                                    $tot_f_old_int = 0;
                                                    $tot_others = 0;
                                                    $tot_insurance = 0;
                                                    $tot_tot = 0; ?>
                                                    <?php
                                                    // echo "<pre>";
                                                    // print_r($members); 
                                                    // die();
                                                    ?>
                                                    <form method="post" action="<?php echo base_url(); ?>index.php/Demand/sub_day_book" id="rec_form" enctype='multipart/form-data'>
                                                        <?php foreach ($members as $key => $member) : ?>
                                                            <?php if ($member->tot_pay > 0 || $member->status == "Cancelled") { ?>

                                                                <tr>
                                                                    <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][added_on]"; ?>" value="<?php echo date("Y/m/d"); ?>" id="recover_<?php echo $sno; ?>" data-id="<?php echo $sno; ?>" class="form-control">
                                                                    <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][month]"; ?>" value="<?php echo $month; ?>" id="recover_<?php echo $sno; ?>" data-id="<?php echo $sno; ?>" class="form-control">
                                                                    <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][year]"; ?>" value="<?php echo $year; ?>" id="recover_<?php echo $sno; ?>" data-id="<?php echo $sno; ?>" class="form-control">

                                                                    <td class="text-center">
                                                                        <?= $member->me_no ?>

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

                                                                        <a href="<?php echo base_url(); ?>index.php/Demand/reciept?id=<?php echo $member->payment_id; ?>" target='_blank'><?= $member->rec_no ?></a>

                                                                    </td>
                                                                    <td>
                                                                        <?= $member->mem_name ?>

                                                                    </td>
                                                                    <td class="text-right">
                                                                        <?= $member->loan_no ?>

                                                                    </td>
                                                                    <td class="text-right">
                                                                        <?= $member->share_amt ?>

                                                                    </td>
                                                                    <td class="text-right">
                                                                        <?= $member->books ?>

                                                                    </td>
                                                                    <td class="text-right">
                                                                        <?= $member->ent_fees ?>

                                                                    </td>
                                                                    <td class="text-right">
                                                                        <?= $member->thrift_amt +  $member->old_thrift ?>

                                                                    </td>
                                                                    <td class="text-right">
                                                                        <?php echo $member->loan_pri_amt + $member->last_principal + $member->ex_os + $member->os_pay; ?>
                                                                    </td>

                                                                    <td class="text-right">

                                                                        <?php echo $member->loan_int_amt + $member->last_int + $member->p_int + $member->old_p_int; ?>

                                                                    </td>
                                                                    <!-- <td class="text-right">

                                                                        <?php echo $member->p_int + $member->old_p_int; ?>

                                                                    </td> -->
                                                                    <!-- <td>
                                                                        <?php echo $member->f_pri + $member->f_old_pri + $member->f_ex_os + $member->f_os_pay; ?>
                                                                    </td>

                                                                    <td>

                                                                        <?php echo $member->f_int + $member->f_old_int + $member->f_p_int; ?>

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

                                                                        <?php echo $member->f_old_p_int + $member->f_p_int; ?>

                                                                    </td> -->
                                                                    <td class="text-right">
                                                                        <?= $member->others ?>

                                                                    </td>
                                                                    <td class="text-right">
                                                                        <?= $member->insurance + $member->old_ins; ?>

                                                                    </td>
                                                                    <td class="text-right">
                                                                        <?= $member->due_by ?>

                                                                    </td>
                                                                    <!-- <td class="text-right">
                                                                        <?= $member->due_to ?>

                                                                    </td> -->

                                                                    <td class="text-right">
                                                                        <?php if ($member->status == "Cancelled") { ?>
                                                                            <?php echo 'Cancelled'; ?>
                                                                        <?php } else { ?>
                                                                            <?= $member->tot_pay ?>
                                                                        <?php } ?>
                                                                    </td>
                                                                    <td>

                                                                        <div id="divpo_<?php echo $member->payment_id; ?>">
                                                                            <?php echo date("d-m-Y", strtotime($member->paid_on)); ?>
                                                                        </div>
                                                                        <div id="input_<?php echo $member->payment_id; ?>" style="display:none;">
                                                                            <div class="form-group">
                                                                                <div class="col-xs-5 date">
                                                                                    <div class="input-group input-append date " id="">
                                                                                        <input type="date" class="form-control" name="paid_on_date_<?php echo $member->payment_id; ?>" id="paid_on_date_<?php echo $member->payment_id; ?>" value="<?php echo date("d-m-Y", strtotime($member->paid_on)); ?>" />

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

                                                                    </td>
                                                                    <td class="text-center">
                                                                        <div id="edit_<?php echo $member->payment_id; ?>">
                                                                            <a onclick="editpodate('<?php echo $member->payment_id; ?>')" class='btn btn-primary btn-xs' style="color:white;" target='_blank'><span class="fa fa-edit"></span><span class="sr-only">View</span></a>
                                                                        </div>
                                                                        <div id="save_<?php echo $member->payment_id; ?>" style="display:none;">
                                                                            <a onclick="savepodate('<?php echo $member->payment_id; ?>')" class='btn btn-success btn-xs' target='_blank' style="color:white;"><span class="fa fa-check"></span><span class="sr-only">View</span></a>
                                                                        </div>
                                                                    </td>
                                                                    <td class="text-center">
                                                                        <a href="<?php echo base_url(); ?>index.php/Admin/sms" style="color:white;" class='btn btn-primary btn-xs'><span class="fas fa-comment-alt"></span><span class="sr-only">View</span></a>

                                                                    </td>
                                                                    <td class="text-center">
                                                                        <a href="<?php echo base_url(); ?>index.php/demand/reciept?id=<?php echo $member->payment_id; ?>" style="color:white;" class='btn btn-primary btn-xs'><span class="fa fa-search"></span><span class="sr-only">View</span></a>
                                                                    </td>
                                                                </tr>
                                                                <?php
                                                                $tot_ef += $member->ent_fees;
                                                                $tot_sh += $member->share_amt;
                                                                $tot_td += $member->thrift_amt +  $member->old_thrift;
                                                                $tot_books += $member->books;
                                                                $tot_loan_pri += $member->loan_pri_amt + $member->ex_os + $member->os_pay;
                                                                $tot_loan_int += $member->loan_int_amt;
                                                                $tot_p_int += +$member->p_int + $member->old_p_int  + $member->f_p_int;
                                                                $tot_last_pri += $member->last_principal;
                                                                $tot_last_int += $member->last_int;
                                                                $tot_f_pri += $member->f_pri + $member->f_ex_os;
                                                                $tot_f_int += $member->f_int + $member->f_p_int;
                                                                $tot_f_old_pri += $member->f_old_pri;
                                                                $tot_f_old_int += $member->f_old_int;
                                                                $tot_others += $member->others;
                                                                $tot_due_by += $member->due_by;
                                                                $tot_due_to += $member->due_to;
                                                                $tot_insurance += $member->insurance;
                                                                $tot_tot += $member->tot_pay;
                                                                ?>
                                                            <?php } ?>
                                                        <?php endforeach; ?>
                                                </tbody>

                                                <tfoot>
                                                    <tr>

                                                        <th class="text-center">

                                                        </th>
                                                        <th>

                                                        </th>
                                                        <th style="text-align:right">Total:</th>
                                                        <th style="text-align:right">

                                                        </th>
                                                        <th style="text-align:right">

                                                        </th>
                                                        <th style="text-align:right">

                                                        </th>
                                                        <th style="text-align:right">

                                                        </th>
                                                        <th style="text-align:right">


                                                        </th>
                                                        <th style="text-align:right">


                                                        </th>

                                                        <th style="text-align:right">



                                                        </th>
                                                        <th style="text-align:right">


                                                        </th>
                                                        <th style="text-align:right">



                                                        </th>
                                                        <!-- <th style="text-align:right">


                                                        </th> -->
                                                        <!-- <th style="text-align:right">


                                                        </th>
                                                        <th style="text-align:right">



                                                        </th>
                                                        <th style="text-align:right">


                                                        </th> -->
                                                        <th style="text-align:right">


                                                        </th>
                                                        <th style="text-align:right">

                                                        </th>

                                                        <th style="text-align:right">


                                                        </th>
                                                        <th style="text-align:right">

                                                        </th>
                                                        <th>

                                                        </th>
                                                        <th>

                                                        </th>
                                                    </tr>
                                                </tfoot>
                                            </table>

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




                    </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 = $('#receipt_detail').DataTable({


        "footerCallback": function(row, data, start, end, display) {
            var api = this.api();

            // Remove the formatting to get integer data for summation
            var intVal = function(i) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '') * 1 :
                    typeof i === 'number' ?
                    i : 0;
            };
            // Total over all pages
            share_total = api
                .column(3)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            bk_total = api
                .column(4)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            ef_total = api
                .column(5)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            thrift_total = api
                .column(6)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            pri_total = api
                .column(7)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            int_total = api
                .column(8)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            p_int_total = api
                .column(9)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            fpri_total = api
                .column(10)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            fint_total = api
                .column(11)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            fp_int_total = api
                .column(12)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);

            others_total = api
                .column(13)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            insurance_total = api
                .column(14)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            due_by_total = api
                .column(15)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            // due_to_total = api
            //     .column(14)
            //     .data()
            //     .reduce(function(a, b) {
            //         return intVal(a) + intVal(b);
            //     }, 0);
            total = api
                .column(16)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            // Total over this page
            sharepageTotal = api
                .column(3, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            bkpageTotal = api
                .column(4, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            efpageTotal = api
                .column(5, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            thriftpageTotal = api
                .column(6, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            pripageTotal = api
                .column(7, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            intpageTotal = api
                .column(8, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            p_intpageTotal = api
                .column(9, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            fpripageTotal = api
                .column(10, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            fintpageTotal = api
                .column(11, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            fp_intpageTotal = api
                .column(12, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            // fipageTotal = api
            //     .column(9, {
            //         page: 'current'
            //     })
            //     .data()
            //     .reduce(function(a, b) {
            //         return intVal(a) + intVal(b);
            //     }, 0);
            // fppageTotal = api
            //     .column(10, {
            //         page: 'current'
            //     })
            //     .data()
            //     .reduce(function(a, b) {
            //         return intVal(a) + intVal(b);
            //     }, 0);

            otherspageTotal = api
                .column(13, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            insurancepageTotal = api
                .column(14, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            duebypageTotal = api
                .column(15, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            // duetopageTotal = api
            //     .column(14, {
            //         page: 'current'
            //     })
            //     .data()
            //     .reduce(function(a, b) {
            //         return intVal(a) + intVal(b);
            //     }, 0);
            totalpageTotal = api
                .column(16, {
                    page: 'current'
                })
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);
            // Total over this page


            // Update footer
            $(api.column(3).footer()).html(
                '<span style="color:blue;display:none">' + sharepageTotal + '<br> </span> <span id="second_total"> ' + share_total + '</span>'
            );
            $(api.column(4).footer()).html(
                '<span style="color:blue;display:none">' + bkpageTotal + '<br> </span> <span id="second_total1"> ' + bk_total + '</span>'
            );
            $(api.column(5).footer()).html(
                '<span style="color:blue;display:none">' + efpageTotal + '<br> </span> <span id="second_total2"> ' + ef_total + '</span>'
            );
            $(api.column(6).footer()).html(
                '<span style="color:blue;display:none">' + thriftpageTotal + '<br> </span> <span id="second_total3"> ' + thrift_total + '</span>'
            );
            $(api.column(7).footer()).html(
                '<span style="color:blue;display:none">' + pripageTotal + '<br> </span> <span id="second_total4"> ' + pri_total + '</span>'
            );
            $(api.column(8).footer()).html(
                '<span style="color:blue;display:none">' + intpageTotal + '<br> </span> <span id="second_total5"> ' + int_total + '</span>'
            );
            $(api.column(9).footer()).html(
                '<span style="color:blue;display:none">' + p_intpageTotal + '<br> </span> <span id="second_total6"> ' + p_int_total + '</span>'
            );
            $(api.column(10).footer()).html(
                '<span style="color:blue;display:none">' + fpripageTotal + '<br> </span> <span id="second_total7"> ' + fpri_total + '</span>'
            );
            $(api.column(11).footer()).html(
                '<span style="color:blue;display:none">' + fintpageTotal + '<br> </span> <span id="second_total8"> ' + fint_total + '</span>'
            );
            $(api.column(12).footer()).html(
                '<span style="color:blue;display:none">' + fp_intpageTotal + '<br> </span> <span id="second_total9"> ' + fp_int_total + '</span>'
            );
            $(api.column(13).footer()).html(
                '<span style="color:blue;display:none">' + otherspageTotal + '<br> </span> <span id="second_total10"> ' + others_total + '</span>'
            );
            $(api.column(14).footer()).html(
                '<span style="color:blue;display:none">' + insurancepageTotal + '<br> </span> <span id="second_total11"> ' + insurance_total + '</span>'
            );
            $(api.column(15).footer()).html(
                '<span style="color:blue;display:none">' + duebypageTotal + '<br> </span> <span id="second_total12"> ' + due_by_total + '</span>'
            );
            // $(api.column(14).footer()).html(
            //     '<span style="color:blue;display:none">' + duetopageTotal + '<br> </span> <span id="second_total11"> ' + due_to_total + '</span>'
            // );
            $(api.column(16).footer()).html(
                '<span style="color:blue;display:none">' + totalpageTotal + '<br> </span> <span id="second_total13"> ' + total + '</span>'
            );
        },



        "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'
                },
            ]
        }

    });

    $("div.dataTables_filter input").keyup(function(e) {
        if (table.search() != "") {
            $("span").show();
            $("#second_total").hide();
            $("#second_total1").hide();
            $("#second_total2").hide();
            $("#second_total3").hide();
            $("#second_total4").hide();
            $("#second_total5").hide();
            $("#second_total6").hide();
            $("#second_total7").hide();
            $("#second_total8").hide();
            $("#second_total9").hide();
            $("#second_total10").hide();
            $("#second_total11").hide();
            $("#second_total12").hide();
        } else {
            $("span").hide();
            $("#second_total").show();
            $("#second_total1").show();
            $("#second_total3").show();
            $("#second_total4").show();
            $("#second_total5").show();
            $("#second_total6").show();
            $("#second_total7").show();
            $("#second_total8").show();
            $("#second_total9").show();
            $("#second_total10").show();
            $("#second_total11").show();
            $("#second_total12").show();
        }
    });
</script>
</script>

<script>
    $('#import_form').on('submit', function(event) {
        event.preventDefault();
        $.ajax({
            url: "<?php echo base_url(); ?>index.php/Demand/import",
            method: "POST",
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData: false,
            success: function(data) {
                $('#file').val('');
                load_data();
                alert(data);
            }
        })
    });

    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 editpodate(id) {
        $("#edit_" + id).hide();
        $("#save_" + id).show();
        $("#divpo_" + id).hide();
        $("#input_" + id).show();
    }

    function savepodate(id) {
        var paid_on = $("#paid_on_date_" + id).val();
        if (paid_on != "") {
            $.ajax({
                type: 'POST',
                url: "<?php echo base_url() ?>index.php/Demand/savepodate",
                data: {
                    id: id,
                    paid_on: paid_on
                },
                dataType: 'html',
                success: function(data) {
                    alert("Paid date updated successfully");
                    $("#edit_" + id).show();
                    $("#save_" + id).hide();
                    $("#divpo_" + id).show();
                    $("#input_" + id).hide();
                    $("#divpo_" + id).html(paid_on);
                }
            });
        } else {
            alert("Paid date should be filled out");
        }
    }

    $(document).ready(function() {

        $('#division_id').on('change', function() {
            var division = this.value;
            $.ajax({
                type: 'POST',
                url: "<?php echo base_url() ?>index.php/Member/getsection",
                data: {
                    division: division
                },
                dataType: 'html',
                success: function(data) {

                    $('#section_id').html(data);
                }
            });
        });
        $('.alert').fadeOut(3000);
        $('.datePicker')
            .datepicker({
                format: 'dd-mm-yyyy'
            })
            .on('changeDate', function(e) {
                // Revalidate the date field
                // $('#eventForm').formValidation('revalidateField', 'date');
            });


        // $('#eventForm').formValidation({
        //     framework: 'bootstrap',
        //     icon: {
        //         valid: 'glyphicon glyphicon-ok',
        //         invalid: 'glyphicon glyphicon-remove',
        //         validating: 'glyphicon glyphicon-refresh'
        //     },
        //     fields: {
        //         name: {
        //             validators: {
        //                 notEmpty: {
        //                     message: 'The name is required'
        //                 }
        //             }
        //         },
        //         date: {
        //             validators: {
        //                 notEmpty: {
        //                     message: 'The date is required'
        //                 },
        //                 date: {
        //                     format: 'MM/DD/YYYY',
        //                     message: 'The date is not a valid'
        //                 }
        //             }
        //         }
        //     }
        // });
    });
</script>