<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="#">Check List</a></li>
                    <li class="breadcrumb-item active">Partial Pay  </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">
                        Partial Pay  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/p_pay_details" 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-3">
                                    <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>
                                    <?php $m = date('F'); ?>
                                    <select name="month" class="form-control">
                                        <option value="">Select Month</option>
                                        <option <?php if ($m == "January") {
                                                    echo "";
                                                } ?> value="January">January</option>
                                        <option <?php if ($m == "February") {
                                                    echo "";
                                                } ?> value="February">February</option>
                                        <option <?php if ($m == "March") {
                                                    echo "";
                                                } ?> value="March">March</option>
                                        <option <?php if ($m == "April") {
                                                    echo "";
                                                } ?> value="April">April</option>
                                        <option <?php if ($m == "May") {
                                                    echo "";
                                                } ?> value="May">May</option>
                                        <option <?php if ($m == "June") {
                                                    echo "";
                                                } ?> value="June">June</option>
                                        <option <?php if ($m == "July") {
                                                    echo "";
                                                } ?> value="July">July</option>
                                        <option <?php if ($m == "August") {
                                                    echo "";
                                                } ?> value="August">August</option>
                                        <option <?php if ($m == "September") {
                                                    echo "";
                                                } ?> value="September">September</option>
                                        <option <?php if ($m == "October") {
                                                    echo "";
                                                } ?> value="October">October</option>
                                        <option <?php if ($m == "November") {
                                                    echo "";
                                                } ?> value="November">November</option>
                                        <option <?php if ($m == "December") {
                                                    echo "";
                                                } ?> value="December">December</option>
                                    </select>
                                </div>
                                <div class="col-sm-2">Year
                                    <?php $y = date('Y'); ?>
                                    <select name="year" class="form-control">
                                        <option value="">Select Year</option>
                                        <?php for ($j = $y; $j >= 2019; $j--) { ?>
                                            <option <?php if ($j == $y) {
                                                        echo "";
                                                    } ?> value="<?php echo $j; ?>"><?php echo $j; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                                <div class="col-sm-2 mt-4"><button type="submit" class="btn btn-primary" >Submit</button></div>
                        </form>
                    </div>
                    <?php $member_ft = 0;
                    $tot_os = 0;
                    $tot_pri = 0;
                    $tot_int = 0;
                    $tot_fpri = 0;
                    $tot_fint = 0;
                    $tot_fos = 0;
                    $tot_td = 0;
                    $tot_others = 0;
                    $tot_ins = 0;
                    $tot_recover = 0; ?>
                    <?php if (isset($members) && count($members) > 0) { ?><br><br>
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="tile">
                                        <div class="tile-body">
                                            <table id="table_id" class="table table-striped table-bordered table-responsive" style="width:100%">
                                                <thead>

                                                    <tr>
                                                    <th class="text-center">Member Number</th>
                                                    <th class="text-center">Receipt Number</th>
                                                    <th class="text-center">Member Name</th>
                                                    <th class="text-center">Share</th>
                                                    <th class="text-center">Books & Forms</th>
                                                    <th class="text-center">Entry Fees</th>
                                                    <th class="text-center">Thrift</th>
                                                    <th class="text-center">Principal</th>
                                                    <th class="text-center">Interest</th>
                                                    <th class="text-center">Others</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>
                                                    </tr>
                                                    </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();
                                                ?>
                                                    <?php foreach ($members as $key => $member) : ?>
                                                        <?php if ($member->tot_pay > 0) { ?>
                                                            <?php
                                                            $sno = $sno + 1;
                                                            ?>
                                                            <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">
                                                                    <?= $member->rec_no ?>

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

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

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

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

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

                                                                </td>
                                                                <td>
                                                                    <?php echo $member->loan_pri_amt + $member->last_principal + $member->ex_os + $member->os_pay; ?>
                                                                </td>

                                                                <td>

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

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

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

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

                                                                </td>

                                                                <td>
                                                                    <?= $member->tot_pay ?>

                                                                </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>
                                                               
                                                            </tr>
                                                            <?php
                                                             $tot_ef += $member->ent_fees;
                                                             $tot_sh += $member->share_amt;
                                                            $tot_td += $member->thrift_amt;
                                                            $tot_books += $member->books;
                                                            $tot_loan_pri += $member->loan_pri_amt + $member->ex_os + $member->os_pay;
                                                            $tot_loan_int += $member->loan_int_amt + $member->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>
                                                    </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>

$('.alert').fadeOut(3000);

    var table = $('#table_id').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 );
                others_total = api
                .column(9 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
               due_by_total = api
                .column( 10 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
                due_to_total = api
                .column( 11 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
                total = api
                .column(12 )
                .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 );
                otherspageTotal = api
                .column( 9, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
                duebypageTotal = api
                .column( 10, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
                duetopageTotal = api
                .column( 11, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
                totalpageTotal = api
                .column( 12, { 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> ' + share_total
            );
            $( api.column( 4).footer() ).html(
                '<span style="color:blue;display:none">' + bkpageTotal + '<br> </span> ' + bk_total
            );
            $( api.column( 5).footer() ).html(
                '<span style="color:blue;display:none">' + efpageTotal + '<br> </span> ' + ef_total
            );
            $( api.column( 6).footer() ).html(
                '<span style="color:blue;display:none">' + thriftpageTotal + '<br> </span> ' + thrift_total
            );
            $( api.column( 7).footer() ).html(
                '<span style="color:blue;display:none">' + pripageTotal + '<br> </span> ' + pri_total
            );
            $( api.column( 8).footer() ).html(
                '<span style="color:blue;display:none">' + intpageTotal + '<br> </span> ' + int_total
            );
            $( api.column( 9).footer() ).html(
                '<span style="color:blue;display:none">' + otherspageTotal + '<br> </span> ' + others_total
            );
            $( api.column( 10).footer() ).html(
                '<span style="color:blue;display:none">' + duebypageTotal + '<br> </span> ' + due_by_total
            );
            $( api.column( 11).footer() ).html(
                '<span style="color:blue;display:none">' + duetopageTotal + '<br> </span> ' + due_to_total
            );
            $( api.column( 12).footer() ).html(
                '<span style="color:blue;display:none">' + totalpageTotal + '<br> </span> ' + total
            );
        },


        "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();

        }else{
            $("span").hide();

        }
} );
</script>