<!-- File: src/Template/Articles/index.ctp -->
<div id="page-wrapper">
    <div class="header">
        <h1 class="page-header">

        </h1>
        <ol class="breadcrumb">
            <li><a href="#">Report</a></li>
            <li class="active">Due Members</li>
        </ol>

    </div>
    <div id="page-inner">



        <div class="row">
            <div class="col-md-12">
                <!--   Kitchen Sink -->
                <div class="panel panel-default">
                    <div class="panel-heading d-flex justify-content-center">
                        Due Members Details
                    </div>
                    <div class="panel-body">
<div class="app-title">
        <br><br>

<form method="post" action="<?php echo base_url(); ?>index.php/Demand/overdue" id="member_add_" enctype='multipart/form-data'>
<div class="row no-print">
        <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 $sno=0;  $member_ft=0;$tot_loan_amount=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; $tot_recover=0; ?>
<?php if(isset($division)) { ?>
     
   <div class="row mt-3">
        <div class="col-sm-12">
          <div class="tile">
            <div class="tile-body">
            <div class="row mb-2">
        <div class="col-sm-12 text-center">
<h5><b>MM297- VAIYAMPATTY PANCHAYAT UNION EMPLOYEES PRIMARY & MIDDLE SCHOOL TEACHERS CO-OPERATIVE THRIFT & CREDIT SOCIETY LTD., VAIYAMPATTY – 621 315</b></h5>

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

        </div>
        <div class="col-sm-8 text-center">
<b>FORM 29</b>
        </div>
        <div class="col-sm-2 float-left"  >
     <b>   <?php echo date("d-m-Y"); ?></b>
        </div>
        </div>
        <p>See Sub Rule (2) of the Tamil Nadu Co-Op. Societies Act) (form of requisition under Sub-Section (2) of Section 49 of the Tamil Nadu Co-Op. Societies Act 1983) Tamil Nadu Act 30 of 1983 from a society to an employer or Officer disbursing the salary of a member of such society for deducting the amount to it from
the salary payable to such member</p>

<p><b>Sir,</b></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;With reference to the agreement executed by the following members of our society authorising you to deduct from their salary the amounts due from them to the society. We request you to be good enough to recover from their salary for the month of <?php echo $month." ".$year; ?> the following amounts due from them to the society. We request that the amount recovered may be remitted to our society on or before 5th of next month. The duplicate copy of this demand list may be returned furnishing the details of recoveries effect.	</p>													

            <div class="row mb-2">
       <div class="col-sm-4">
<b>Demand-<?php echo $month." - ".$year; ?></b>
        </div>
        <div class="col-sm-5 text-center">
<b></b>
        </div>
        <div class="col-sm-3 float-left"  >
<b><p id="div_sec"><?php echo $division; ?></p></b>
        </div>
        </div>
             <div class="row ">
       <div class="col-sm-8">
<h5><b><?php echo $address; ?></b></h5>
        </div>
        <div class="col-sm-2 text-center">

        </div>
        <div class="col-sm-2 float-left"  >

        </div>
        </div>
        <table id="table_id" class="table table-bordered table-responsive" style="width:100%;">
    <thead>
        <tr>
        <th class="text-center">S.No.</th>
        <th class="text-center">M. No.</th>
          <th class="text-center">PF. No.</th>
          <th class="text-center">Name</th>
            <th class="text-center">Dsgn</th>
        <th class="text-center">Loan No.</th>
        <th class="text-center">Loan OS</th>
         <th class="text-center">Dues</th>
        <th class="text-center">Pri</th>
        <th class="text-center">%</th>
        <th class="text-center">Int</th>
        <th class="text-center">TD</th>
        <th class="text-center">Ins</th>
          <th class="text-center">Others</th>
        <th class="text-center">Total</th>
        <th class="text-center">Recovered</th>
        </tr>
</thead>
    <!-- Here's where we iterate through our $articles query object, printing out article info -->
<tbody>
     
    
            <!--<tr style="height:30px;"><td></td><td></td><td></td><td style="color:red;padding:5px; margin:0px;" ><h6 style="padding:0px; margin:0px;"><strong><?php echo $s_n['section']; ?></strong</h6></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> -->

<?php foreach ($members as $key=>$member): ?>

<?php
// print_r($member);die();
//write query to get thrift from thrfit table by memeber no

$sno=$sno+1; ?>

 <input type="hidden" name="<?php echo "postvalue[".$member->mem_no."][month]";?>" value="<?php echo $month; ?>" id="<?php echo $sno;?>" data-id="<?php echo $sno;?>" class="form-control">
 <input type="hidden" name="<?php echo "postvalue[".$member->mem_no."][year]";?>" value="<?php echo $year; ?>" id="<?php echo $sno;?>" data-id="<?php echo $sno;?>" class="form-control">
    <tr style="height:30px;">
  <td class="text-center" style="padding:5px; margin:0px;">
            <?= $sno; ?>
        </td>
        <td class="text-center" style="padding:5px; margin:0px;">
            <?= $member->mem_no ?>
        
        </td>
          <td style="padding:5px; margin:0px;text-align:right;">
            <?= $member->pf_no ?>
        </td>
         <td style="padding:5px; margin:0px;">
            <?= $member->mem_name ?>
        </td>
         <td style="padding:5px; margin:0px;">
            <?= $member->designation ?>
        </td>
        <td style="padding:5px; margin:0px;text-align:right;">
            <?= $member->d_loan_no ?>
        </td>
        <td style="padding:5px; margin:0px;text-align:right;">
        <?php if($member->d_loan_os>0) { ?>
        <?= $member->d_loan_os ?>
        <?php } ?>
       
            </td>
                   <td style="padding:5px; margin:0px;text-align:right;">
            <?php if($member->loan_instalment>0){ echo $member->curr_instalment."/".$member->loan_instalment; } ?>
            <input  type="hidden" name="<?php echo "postvalue[".$member->mem_no."][d_curr_instalment]"?>" value="<?php echo $member->curr_instalment ?>">
            <input  type="hidden" name="<?php echo "postvalue[".$member->mem_no."][d_instalment]"?>" value="<?php echo $member->loan_instalment ?>">
            </td>
            <td style="padding:5px; margin:0px;text-align:right;">
            <?php if($member->d_principal>0) { ?>
            <?php echo $member->d_principal; ?>
            <?php } ?>
           </td>
             <td style="padding:5px; margin:0px;text-align:right;">
            <?php if($member->d_int_rate>0){ ?>
            <?= $member->d_int_rate ?>%
            <?php } ?>
            </td>
            <td style="padding:5px; margin:0px;text-align:right;">
            <?php if($member->d_int>0) { ?>
            <?php echo $member->d_int; ?>
            <?php } ?>
            <input  type="hidden" name="<?php echo "postvalue[".$member->mem_no."][d_int]"?>" value="<?php echo $member->d_int ?>">
            <input  type="hidden" name="<?php echo "postvalue[".$member->mem_no."][p_int]"?>" value="<?php echo $member->p_int ?>">
         
            </td>
     
                    <td style="padding:5px; margin:0px;text-align:right;">
            <?php if($member->d_thrift>0) { ?>
        <?php echo $member->d_thrift; ?>
        <?php } ?>
      
        </td>
             <td style="padding:5px; margin:0px;text-align:right;">
            <?php if($member->d_insurance>0) { ?>
        <?php echo $member->d_insurance; ?>
        <?php } ?>

        </td>
           <td width="50px"s style="padding:5px; margin:0px;text-align:right;">
            <input type="hidden" name="<?php echo "postvalue[".$member->mem_no."][d_others]"?>" id="others_<?php echo $sno;?>" value="<?= $member->d_others ?>"  data-id="<?php echo $sno;?>" class="others_button form-control">
            <?php if($member->d_others>0) { ?>
           <?php echo $member->d_others; ?>
           <?php } ?>
            </td>
          <td style="padding:5px; margin:0px;text-align:right;">
          <?php if($member->d_total>0) { ?>
            <?php echo $member->d_total; ?>
            <?php } ?>
            <input data-initial-total="<?= $member->total ?>" type="hidden" name="<?php echo "postvalue[".$member->mem_no."][d_total]"?>" id="tot_<?php echo $sno;?>" value="<?= $member->d_total ?>"   data-id="<?php echo $sno;?>">
            </td>
            <td></td>
    </tr>
    <?php 
    if($member->d_last_principal>0 || $member->p_int+$member->d_last_int>0 || $member->f_old_pri>0 || $member->f_old_int+$member->f_p_int>0 || $member->old_thrift>0 || $member->old_ins>0){
    ?>
     <tr style="height:30px;color:red;">
     <td></td>
     <td></td>
     <td></td>
     <td><b>PENDING DUES</b></td>
     <td></td>
     <td></td>
     <td></td>
       <td></td>
     <td style="padding:5px; margin:0px;text-align:right;"> <b>
     <?php if($member->d_last_principal>0) { ?>
            <?php echo $member->d_last_principal; ?>
            <?php } ?></b>
            </td>
            <td style="padding:5px; margin:0px;text-align:right;"><b>
            <?php if($member->p_int>0 || $member->d_last_int>0) { ?>
           3%
            <?php } ?>
            </td>
            <td style="padding:5px; margin:0px;text-align:right;"><b>
            <?php if($member->p_int>0 || $member->d_last_int>0) { ?>
            <?php echo $member->p_int+$member->d_last_int; ?>
            <?php } ?></b>
            </td>
          

            <td style="padding:5px; margin:0px;text-align:right;"><b>
            <?php if($member->old_thrift>0) { ?>
        <?php echo $member->old_thrift; ?>
        <?php } ?></b>
            </td>
                     <td style="padding:5px; margin:0px;text-align:right;"><b>
            <?php if($member->old_ins>0) { ?>
        <?php echo $member->old_ins; ?>
        <?php } ?></b>
            </td>
            <td>
            
            </td>
            
            <td>
            
            </td>
            <td></td>
            </tr>
    <?php } ?>
    <?php $member_ft+=$member->d_total; $tot_loan_amount+=$member->d_loan_amount; $tot_os+=$member->d_loan_os; $tot_pri+=$member->d_principal+$member->d_last_principal; $tot_int+=$member->d_int+$member->p_int+$member->d_last_int; $tot_fpri+=$member->f_pri+$member->f_old_pri; $tot_fint+=$member->f_int+$member->f_old_int+$member->f_p_int; $tot_fos+=$member->f_os; $tot_td+=$member->d_thrift+$member->old_thrift; $tot_ins+=$member->d_insurance+$member->old_ins; $tot_others+=$member->d_others; ?>
 
<?php endforeach; ?>
 

<tr style="height:30px;">
    <td >
           
        </td>
        <td class="text-center">
            
        </td>
        <td >
           
        </td>
        <td></td>
     <td></td>
     <td></td>
        <td style="padding:5px; margin:0px;text-align:right;">
       <b> <?php echo $tot_os; ?></b>
            </td>
                <td >
          
          </td>
            <td style="padding:5px; margin:0px;text-align:right;">
         <b>   <?php echo $tot_pri; ?></b>
            </td>
          <td >
           
        </td>
            <td style="padding:5px; margin:0px;text-align:right;">
            <b>  <?php echo $tot_int; ?></b>
            </td>
        
            <td style="padding:5px; margin:0px;text-align:right;">
            <b> <?php echo $tot_td; ?></b>
        </td>
          <td style="padding:5px; margin:0px;text-align:right;">
            <b> <?php echo $tot_ins; ?></b>
        </td>
        <td style="padding:5px; margin:0px;text-align:right;">
        <b>  <?php echo $tot_others; ?></b>
            </td>
            <td style="padding:5px; margin:0px;text-align:right;">
            <b>  <?php echo $member_ft; ?></b>
            </td>
            <td></td>
    </tr>
    </tbody>
    </table>
      <div class="row mt-5 mb-5">
    <div class="col-sm-2">

        </div>
       <div class="col-sm-6">
<b>Secretary</b>
        </div>
        <div class="col-sm-4">
<b>President</b>
        </div>
        </div>
    <div class="row mt-3">
       <div class="col-sm-3">
<b>Society Phone No: 9790225381</b>
        </div>
        <div class="col-sm-5 text-center">
<b></b>
        </div>
        <div class="col-sm-4 float-left"  >
<b></b>
        </div>
        </div>
 
    </div>
   
</div>
</div>
</div>

<?php } ?>
</div>


</div>
</div>
 <script>
       var table = $('#table_id').DataTable({
         "dom": 'lBfrtip',
         "ordering": false,
  "paging": false,
  "searching": false,
         "buttons": [
            {
                extend: 'collection',
                text: 'Export',
                buttons: [
                    'copy',
                    'excel',
                    'csv',
                    'pdf',
                    'print'
                ]
            }
        ]
    });
   
 /*  $('#table_id').dataTable( {
  "ordering": false,
  "paging": false,
  "searching": false,
  "buttons": [
            {
                extend: 'collection',
                text: 'Export',
                buttons: [
                    'copy',
                    'excel',
                    'csv',
                    'pdf',
                    'print'
                ]
            }
        ]
} ); */
$(".dataTables_info").html('');
    $('#division_id').on('change', function(){
        var division = this.value;

        var csrf = $('input[name=_csrfToken]').val();
        $.ajax({
            type: 'GET',
            url: "sectionajax",
            data: {division: division},
            dataType: 'json',
            success: function(data) {

                console.log(data.data);
                if(data.result){
                    $('#section_id').empty();
                    $('#section_id').append($('<option>').text("All").attr('value', ""));
                    $.each(data.data, function(i, value) {
                        console.log(value[0]);
                        // $.each(value[0].section, function(i, value1) {
                        //     console.log("---->", value1);
                            $('#section_id').append($('<option>').text(value[0].section).attr('value', value[0].section));
                        // });
                    });
                }
            }
        })


       
    });


</script>