<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="#">DCB</a></li>
                    <li class="breadcrumb-item active">DCB Details </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">
                        DCB 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/dcp" 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 if (isset($demand) && count($demand) > 0) { ?><br><br>
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="tile">
                                    <div class="tile-body"><br><br>
                                    <?php if($division != "" || $section != "") {?>
                                    <div class="row mb-2">

                                        <div class="col-sm-3">
                                        </div>
                                        <div class="col-sm-5 text-center">
                                            <h3><b> <?php echo $division; ?> </b>   <?php if($section != "") {?> (&nbsp;<b><?php echo $section; ?> </b> &nbsp;)  <?php }?></h3>

                                        </div>
                                        <div class="col-sm-2 text-center">

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

                                        <div class="row mb-2">
                                            <div class="col-sm-3">

                                            </div>
                                            <div class="col-sm-5 text-center">
                                            <h3><b> <?php echo $month; ?> </b> &nbsp;&nbsp;<b><?php echo $year; ?> </b></h3>

                                            </div>
                                            <div class="col-sm-3 float-left">
                                                <b>
                                                </b>
                                            </div>
                                        </div><br><br>
                                        <table id="table_id" class="table table-striped table-bordered " style="width:100%">
                                            <thead>
                                                <tr>
                                                    <th class="text-center"></th>
                                                    <th class="text-center">Principal</th>
                                                    <th class="text-center">Interest</th>
                                                    <th class="text-center">P.Int</th>
                                                    <th class="text-center">Thrift</th>
                                                    <th class="text-center">Insurance</th>
                                                    <th class="text-center">Others</th>
                                                    <th class="text-center">Total</th>


                                                </tr>
                                            </thead>

                                            <tbody>
                                                <!-- <!?php print_r($data);die;?> -->

                                                <?php foreach ($demand as $key => $demand) : ?>
                                                    <tr>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            Demand
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $t_demand_pri = $demand->demand_pri  + $demand->demand_last_principal ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $t_demand_int = $demand->demand_int + $demand->demand_last_int ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $t_demand_p_int = $demand->demand_p_int  +  $demand->demand_old_p_int  ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $t_demand_thrift = $demand->demand_thrift + $demand->old_thrift?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $t_demand_insurance = $demand->demand_insurance + $demand->demand_old_ins ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $t_demand_others = $demand->demand_others + $demand->demand_old_others ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $t_demand_total = $demand->demand_total ?>
                                                        </td>


                                                    </tr>
                                                <?php endforeach; ?>
                                                <?php foreach ($recover as $key => $recovery) : ?>
                                                    <tr>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            Collection
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $r_recover_pri = $recovery->recover_pri + $recovery->recover_last_principal+  $recovery->recover_ex_os + $recovery->recover_os_pay ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $r_recover_int = $recovery->recover_int + $recovery->recover_last_int ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $r_recover_p_int = $recovery->recover_p_int + $recovery->recover_old_p_int  ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $r_recover_thrift = $recovery->recover_thrift + $recovery->recover_old_thrift ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $r_recover_insurance = $recovery->recover_insurance ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $r_recover_others = $recovery->recover_others + $recovery->recover_old_others ?>
                                                        </td>
                                                        <td class="text-center" style="padding:5px; margin:0px;">
                                                            <?= $r_recover_total = $recovery->recover_total ?>
                                                        </td>


                                                    </tr>
                                                <?php endforeach; ?>

                                                <tr>
                                                    <td class="text-center" style="padding:5px; margin:0px;">
                                                        Balance
                                                    </td>
                                                    <td class="text-center" style="padding:5px; margin:0px;">
                                                   <b> <?= $t_demand_pri - $r_recover_pri ?></b>
                                                    </td>
                                                    <td class="text-center" style="padding:5px; margin:0px;">
                                                    <b> <?= $t_demand_int - $r_recover_int ?></b>
                                                    </td>
                                                    <td class="text-center" style="padding:5px; margin:0px;">
                                                    <b>  <?= $t_demand_p_int - $r_recover_p_int ?></b>
                                                    </td>
                                                    <td class="text-center" style="padding:5px; margin:0px;">
                                                    <b>  <?= $t_demand_thrift - $r_recover_thrift ?></b>
                                                    </td>
                                                    <td class="text-center" style="padding:5px; margin:0px;">
                                                    <b> <?= $t_demand_insurance - $r_recover_insurance ?></b>
                                                    </td>
                                                    <td class="text-center" style="padding:5px; margin:0px;">
                                                    <b> <?= $t_demand_others - $r_recover_others ?></b>
                                                    </td>
                                                    <td class="text-center" style="padding:5px; margin:0px;">
                                                    <b> <?= $t_demand_total - $r_recover_total ?> </b>
                                                    </td>


                                                </tr>


                                            </tbody>

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


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


        <script>
            $('#division_id').on('change', function() {
                var division = this.value;
                var section = $('#section_id').val();
                $.ajax({
                    type: 'POST',
                    url: "<?php echo base_url() ?>index.php/Member/member_search",
                    data: {
                        division: division,
                        section: section
                    },
                    dataType: 'html',
                    success: function(data) {
                        $('#filter_id').html(data);
                        var table = $('#table_id1').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");
                    }
                });

                $.ajax({
                    type: 'POST',
                    url: "<?php echo base_url() ?>index.php/Member/getsection",
                    data: {
                        division: division
                    },
                    dataType: 'html',
                    success: function(data) {

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

            });
        </script>