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

        </h1>
        <ol class="breadcrumb">
            <li><a href="#">Demand</a></li>
            <li class="active">Demand Generate</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">
                        Demand Generate
                    </div>
                    <div class="panel-body">

<div class="app-title">
    <div>
        <h1><i class="fa fa-th-list"></i> Demand Generate</h1>
    </div>

    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>&nbsp;
        <li class="active">Demand</li>
    </ol>
</div>
<form method="post" action="<?php echo base_url(); ?>index.php/Demand/demand_generate" 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_os = 0;
$tot_pri = 0;
$tot_int = 0;
$tot_od_int = 0;
$tot_fpri = 0;
$tot_fint = 0;
$tot_fod_int = 0;
$tot_fos = 0;
$tot_td = 0;
$tot_total = 0; ?>

<?php if (isset($members) && count($members) > 0) { ?>
    <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-2">
                            <b></b>
                        </div>
                        <div class="col-sm-8 text-center">
                            <b>FORM 29</b>
                        </div>
                        <div class="col-sm-2 float-left">

                        </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>Sir,</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-2">
                            <b>Demand-<?php echo $month . " - " . $year; ?></b>
                        </div>
                        <div class="col-sm-8 text-center">
                            <h5><b>R693 - TRICHY DISTRICT AGRICULTURAL DEPARTMENT OFFICERS CO-OPERATIVE THRIFT & CREDIT SOCIETY LIMITED</b></h5>

                        </div>
                        <div class="col-sm-2 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>
                    <?php foreach ($members as $key => $member) :
                        $member = (object) $member;
                    ?>
                        <?php $member_ft += $member->total;
                        $tot_os += $member->loan_os_amt;
                        $tot_pri += $member->loan_principle_amt + $member->old_due_pri;
                        $tot_int += $member->loan_int_amt + $member->old_pri_int + $member->old_due_int;
                        $tot_fpri += $member->f_pri + $member->f_old_pri;
                        $tot_fint += $member->f_int_amt + $member->f_old_int + $member->f_pri_int;
                        $tot_fos += $member->f_os;
                        $tot_td += $member->thrift_amt + $member->old_thrift; ?>
                    <?php endforeach; ?>

                    <table id="navbar" class='followMeBar mt-5'>
                        <tbody style="color:white;">
                            <tr>
                                <th class=""></th>
                                <th class=""></th>
                                <th class=""></th>
                                <th></th>
                                <th class="">Loan OS</th>
                                <th class="">Principal</th>
                                <th class="">%</th>
                                <th class="">Interest</th>
                                <th class="">FL OS</th>
                                <th class="">FL Pri.</th>
                                <th class="">FL Int.</th>
                                <th class="">TD</th>
                                <th class="" width="90px">Int</th>
                                <th class="" width="90px">FL Int</th>
                                <th class="" width="90px">Others</th>
                                <th>Total</th>
                            </tr>
                            <tr>
                                <td width="80px">

                                </td>
                                <td class="text-center" width="140px">

                                </td>
                                <td width="100px">

                                </td>
                                <td width="120px">

                                </td>
                                <td>
                                    <?php echo $tot_os; ?>
                                </td>
                                <td>
                                    <?php echo $tot_pri; ?>
                                </td>
                                <td>

                                </td>
                                <td>
                                    <?php echo $tot_int; ?>
                                </td>
                                <td>
                                    <?php echo $tot_fos; ?>
                                </td>
                                <td>
                                    <?php echo $tot_fpri; ?>
                                </td>
                                <td>
                                    <?php echo $tot_fint; ?>
                                </td>
                                <td>
                                    <?php echo $tot_td; ?>
                                </td>
                                <td>
                                    <input type="input" class="form-control" value="<?php echo $tot_int; ?>" id="f_int_tot" data-id="<?php echo $sno; ?>" width="100%" height="auto" readonly>
                                </td>
                                <td>
                                    <input type="input" class="form-control" value="<?php echo $tot_fint; ?>" id="ff_int_tot" data-id="<?php echo $sno; ?>" width="100%" height="auto" readonly>
                                </td>
                                <td>
                                    <input type="input" class="form-control" id="d_others_total" data-id="<?php echo $sno; ?>" width="100%" height="auto" readonly>
                                </td>
                                <td>
                                    <input type="input" class="form-control" value="<?php echo $member_ft; ?>" id="final_tot" data-id="<?php echo $sno; ?>" width="100%" height="auto" readonly>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <table id="table_id" class="table table-striped table-bordered " style="width:100%">
                        <thead>
                            <tr>
                                <th class="text-center">S.No.</th>
                                <th class="text-center">M. No.</th>
                                <th class="text-center">Name</th>
                                <th class="text-center">Desig</th>
                                <th class="text-center">Loan No.</th>
                                <th class="text-center">Loan Amount</th>
                                <th class="text-center">Loan OS</th>
                                <th class="text-center">Principal</th>
                                <th class="text-center">Int</th>
                                <th class="text-center">Total Dues</th>
                                <th class="text-center">FL OS</th>
                                <th class="text-center">FL Pri.</th>
                                <th class="text-center">FL Int.</th>
                                <th class="text-center">TD</th>
                                <!--   <th class="text-center" width="90px">Extra Int</th>
         <th class="text-center" >Int</th>
         <th class="text-center" width="90px">F_Ex Int</th>
         <th class="text-center" >FL Int</th> -->
                                <th class="text-center">Insurance</th>
                                <th class="text-center">Others</th>
                                <th class="text-center">Total</th>
                                <th class="text-center">Recovered</th>
                            </tr>
                        </thead>

                        <tbody>

                            <form method="post" action="<?php echo base_url(); ?>index.php/Demand/demand_generate" id="member_add_" enctype='multipart/form-data'>
                                <?php
                                $pre_section = "";
                                foreach ($members as $key => $member) :
                                    $member = (object) $member;
                                    if ($pre_section != $member->section) {
                                ?>
                                        <tr>
                                            <td></td>
                                            <td style="color:blue;" colspan="2"><b><strong><?php echo $member->section; ?></strong</b> </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>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                    <?php
                                    }
                                    $pre_section = $member->section;
                                    $sno = $sno + 1; ?>

                                    <tr>
                                        <td>
                                            <?= $sno; ?>
                                        </td>
                                        <td class="text-center">
                                            <?= $member->me_no ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][me_no]" ?>" value="<?php echo $member->me_no ?>">
                                        </td>
                                        <td>
                                            <?= $member->mem_name ?>
                                        </td>
                                        <td>
                                            <?= $member->mem_desig ?>
                                        </td>
                                        <td>
                                            <?php if ($member->loan_amount > 0) { ?>
                                                <?= $member->loan_amount ?>
                                            <?php } ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_loan_amount]" ?>" value="<?php echo $member->loan_amount ?>">
                                        </td>
                                        <td>
                                            <?php if ($member->loan_os_amt > 0) { ?>
                                                <?= $member->loan_os_amt ?>
                                            <?php } ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_loan_os]" ?>" value="<?php echo $member->loan_os_amt ?>">
                                        </td>
                                        <td>
                                            <?php if ($member->loan_principle_amt > 0) { ?>
                                                <?php echo $member->loan_principle_amt; ?>
                                            <?php } ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_principal]" ?>" value="<?php echo $member->loan_principle_amt ?>">
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_last_principal]" ?>" value="<?php echo $member->old_due_pri ?>">
                                        </td>
                                        <td>
                                            <?php if ($member->loan_int_rate > 0) { ?>
                                                <?= $member->loan_int_rate ?>
                                            <?php } ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_int_rate]" ?>" value="<?php echo $member->loan_int_rate ?>">
                                        </td>
                                        <td>
                                            <?php if ($member->loan_int_amt > 0) { ?>
                                                <?php echo $member->loan_int_amt; ?>
                                            <?php } ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][p_int]" ?>" value="<?php echo $member->old_pri_int ?>">
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_last_int]" ?>" value="<?php echo $member->old_due_int ?>">
                                        </td>
                                        <td>
                                            <?php echo $member->curr_instalment . "/" . $member->loan_instalment; ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_curr_instalment]" ?>" value="<?php echo $member->curr_instalment ?>">
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_instalment]" ?>" value="<?php echo $member->loan_instalment ?>">
                                        </td>
                                        <td>
                                            <?php if ($member->f_os > 0) { ?>
                                                <?= $member->f_os ?>
                                            <?php } ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][f_os]" ?>" value="<?php echo $member->f_os ?>">
                                        </td>
                                        <td>
                                            <?php if ($member->f_pri > 0) { ?>
                                                <?php echo $member->f_pri; ?>
                                            <?php } ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][f_pri]" ?>" value="<?php echo $member->f_pri ?>">
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][f_old_pri]" ?>" value="<?php echo $member->f_old_pri ?>">
                                        </td>
                                        <td>
                                            <?php if ($member->f_int_amt > 0) { ?>
                                                <?php echo $member->f_int_amt; ?>
                                            <?php } ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][f_old_int]" ?>" value="<?php echo $member->f_old_int ?>">
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][f_p_int]" ?>" value="<?php echo $member->f_pri_int ?>">
                                        </td>
                                        <td>
                                            <?php if ($member->thrift_amt > 0) { ?>
                                                <?php echo $member->thrift_amt; ?>
                                            <?php } ?>
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_thrift]" ?>" value="<?php echo $member->thrift_amt ?>">
                                            <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][old_thrift]" ?>" value="<?php echo $member->old_thrift ?>">
                                        </td>
                                        <td width="50px" s>
                                            <input type="text" name="<?php echo "postvalue1[" . $member->me_no . "][dothers]" ?>" id="others_<?php echo $sno; ?>" data-id="<?php echo $sno; ?>" class="others_button form-control">
                                        </td>
                                        <td width="50px" s>
                                            <p data-initial-int="<?= $member->loan_int_amt ?>" id="f_int_<?php echo $sno; ?>" data-id="<?php echo $sno; ?>"><?= $member->loan_int_amt ?> </p>
                                            <input data-initial-total="<?= $member->loan_int_amt ?>" type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_int]" ?>" id="int_<?php echo $sno; ?>" value="<?= $member->loan_int_amt ?>" data-id="<?php echo $sno; ?>">
                                        </td>
                                        <td width="50px" s>
                                            <input type="text" name="<?php echo "postvalue1[" . $member->me_no . "][dfothers]" ?>" id="f_others_<?php echo $sno; ?>" data-id="<?php echo $sno; ?>" class="others_button form-control">
                                        </td>
                                        <td width="50px" s>
                                            <p data-initial-int="<?= $member->f_int_amt ?>" id="ff_int_<?php echo $sno; ?>" data-id="<?php echo $sno; ?>"><?= $member->f_int_amt ?> </p>
                                            <input data-initial-total="<?= $member->f_int_amt ?>" type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][f_int]" ?>" id="intf_<?php echo $sno; ?>" value="<?= $member->f_int_amt ?>" data-id="<?php echo $sno; ?>">
                                        </td>
                                        <td width="50px" s>
                                            <input type="text" name="<?php echo "postvalue[" . $member->me_no . "][d_others]" ?>" id="d_others_<?php echo $sno; ?>" data-id="<?php echo $sno; ?>" class="d_others form-control">
                                        </td>
                                        <td>
                                            <?php if ($member->total > 0) { ?>
                                                <p data-initial-total="<?= $member->total ?>" id="total_<?php echo $sno; ?>" data-id="<?php echo $sno; ?>"><?= $member->total ?> </p>
                                            <?php } ?>
                                            <input data-initial-total="<?= $member->total ?>" type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_total]" ?>" id="tot_<?php echo $sno; ?>" value="<?= $member->total ?>" data-id="<?php echo $sno; ?>">

                                        </td>
                                        <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_month]" ?>" value="<?php echo $month; ?>">
                                        <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][d_year]" ?>" value="<?php echo $year; ?>">
                                        <input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][added_on]" ?>" value="<?php echo date("Y-m-d"); ?>">
                                        <!--<input type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][due_by]" ?>" value="<?php echo $member->due_by; ?>">
                                         <input  type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][due_os]" ?>" value="<?php echo $member->due_os; ?>">
            <input  type="hidden" name="<?php echo "postvalue[" . $member->me_no . "][due_f_os]" ?>" value="<?php echo $member->due_f_os; ?>">-->
                                    </tr>
                                    <?php
                                    if ($member->old_due_pri > 0 || $member->old_pri_int + $member->old_due_int > 0 || $member->f_old_pri > 0 || $member->f_old_int + $member->f_pri_int > 0 || $member->old_thrift > 0) {
                                    ?>
                                        <tr style="color:red;">
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td>
                                                <?php if ($member->old_due_pri > 0) { ?>
                                                    <b> <?php echo $member->old_due_pri; ?></b>
                                                <?php } ?>
                                            </td>
                                            <td>
                                                <?php if ($member->old_pri_int + $member->old_due_int > 0) { ?>
                                                    <b> 3</b>
                                                <?php } ?>
                                            </td>
                                            <td>
                                                <?php if ($member->old_pri_int + $member->old_due_int > 0) { ?>
                                                    <b> <?php echo $member->old_pri_int + $member->old_due_int; ?></b>
                                                <?php } ?>
                                            </td>
                                            <td></td>
                                            <td></td>
                                            <td>
                                                <?php if ($member->f_old_pri > 0) { ?>
                                                    <b> <?php echo $member->f_old_pri; ?></b>
                                                <?php } ?>
                                            </td>
                                            <td>
                                                <?php if ($member->f_old_int + $member->f_pri_int > 0) { ?>
                                                    <b> <?php echo $member->f_old_int + $member->f_pri_int; ?></b>
                                                <?php } ?>
                                            </td>
                                            <td>
                                                <?php if ($member->old_thrift > 0) { ?>
                                                    <b> <?php echo $member->old_thrift; ?></b>
                                                <?php } ?>
                                            </td>
                                            <td>

                                            </td>
                                            <td>

                                            </td>
                                            <td>

                                            </td>
                                            <td>

                                            </td>
                                            <td>

                                            </td>
                                            <td>
                                                
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "May" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "June" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "July" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "August" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "September" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "October" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "November" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "December" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "January" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "February" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "March" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center"></td>
                                            <td class="text-center">
                                                <?= $data['amt']; ?>
                                            </td>
                                        </tr>
                                    <?php } else { ?>
                                        <tr>
                                            <td class="text-center">
                                                <?= $sno; ?>
                                            </td>
                                            <td class="text-center">
                                                <?= $data['me_no']; ?>
                                            </td>
                                            <td class="text-center">
                                                <?= $data['mem_name']; ?>
                                            </td>
                                            <td class="text-center">
                                                0
                                            </td>
                                            <td class="text-center">
                                                    <?php if ($data['payment_month'] == "April"  && $data['amt'] > 0) { ?>
                                                            <?= $data['amt']; ?>
                                                        <?php } else { ?>
                                                            0
                                                        <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "May" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "June" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "July" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "August" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "September" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "October" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "November" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "December" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "January" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "February" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($data['payment_month'] == "March" && $data['amt'] > 0) { ?>
                                                        <?= $data['amt']; ?>
                                                    <?php } else { ?>
                                                        0
                                                    <?php } ?>
                                            </td>
                                            $previous_title = $value[0]['me_no'];
            foreach ($value as $val) {
                if ($previous_title == $val->me_no) {
                    print_r($previous_title);
                    die;
                }
                $previous_title =  $val->me_no;
            }
        }
        print_r($val);
                                            if ($inps['type']="thrift") {
               $data['me_no']=$this->db->select('me_no,mem_name')->get('member')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','December')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','November')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','October')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','August')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','June')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','July')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','May')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','April')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','March')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','February')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
               $data['value']=$this->db->select('me_no,sum(thrift_amt) as thrift')->where('payment_month','January')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
            }
            if ($inps['type']="share") {
                $data['me_no']=$this->db->select('me_no,mem_name')->get('member')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','December')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','November')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','October')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','August')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','June')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','July')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','May')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','April')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','March')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','February')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(share_amt) as share')->where('payment_month','January')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
             }
             if ($inps['type']="principal") {
                $data['me_no']=$this->db->select('me_no,mem_name')->get('member')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','December')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','November')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','October')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','August')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','June')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','July')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','May')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','April')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','March')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','February')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
                $data['value']=$this->db->select('me_no,sum(loan_pri_amt) as principal')->where('payment_month','January')->where('payment_year',$inps['year'])->group_by('me_no')->get('payment')->result_array();
             }
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    <?php $member_ft += $member->total;
                                    $tot_os += $member->loan_os_amt;
                                    $tot_pri += $member->loan_principle_amt + $member->old_due_pri;
                                    $tot_int += $member->loan_int_amt + $member->old_pri_int + $member->old_due_int;
                                    $tot_od_int += $member->old_pri_int + $member->old_due_int;
                                    $tot_fpri += $member->f_pri + $member->f_old_pri;
                                    $tot_fint += $member->f_int_amt + $member->f_old_int + $member->f_pri_int;
                                    $tot_fod_int += $member->f_old_int + $member->f_pri_int;
                                    $tot_fos += $member->f_os;
                                    $tot_td += $member->thrift_amt + $member->old_thrift; ?>
                                <?php endforeach; ?>
                        </tbody>
                    </table>
                    <input type="hidden" name="sno" id="sno" data-tot_int="<?php echo $tot_od_int; ?>" data-tot_fint="<?php echo $tot_fod_int; ?>" data-id="<?php echo $sno; ?>" value="<?php echo $sno; ?>">

                    <div class="row mt-3">
                        <div class="col-sm-3">
                            <b>Society Phone No: 0431 - 2420 540</b>
                        </div>
                        <div class="col-sm-5 text-center">
                            <b></b>
                        </div>
                        <div class="col-sm-4 float-left">
                            <b></b>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-5"></div> <button type="submit" class="btn btn-primary col-sm-3">Save</button>
                    </div>

                </div>

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


</div>
</div>
<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);
            }
        });



    });


    $(document).ready(function() {
        $(".others_button,.insurance_button,.d_others").keyup(function() {
            var id = $(this).attr("data-id");
            var others = $('#others_' + id).val() == "" ? 0 : $('#others_' + id).val();
            var d_others = $('#d_others_' + id).val() == "" ? 0 : $('#d_others_' + id).val();
            var f_others = $('#f_others_' + id).val() == "" ? 0 : $('#f_others_' + id).val();
            var _total = $('#total_' + id).attr("data-initial-total");
            var _int = $('#f_int_' + id).attr("data-initial-int");
            var int = parseInt(_int);
            var _f_int = $('#ff_int_' + id).attr("data-initial-int");
            var f_int = parseInt(_f_int);
            var total_txt = _total.replace(",", "");
            var init_total = parseInt(total_txt);
            var others_val = parseInt(others);
            var d_others_val = parseInt(d_others);
            var f_others_val = parseInt(f_others);
            var interest = int + others_val;
            var f_interest = f_int + f_others_val;
            if (interest >= 0) {
                $('#f_int_' + id).text(interest);
                $('#int_' + id).val(interest);
            } else if (interest < 0) {
                alert("Interest Cannot be lessthan 0")
                $('#f_int_' + id).text(int);
                $('#others_' + id).val(0);
            }
            if (f_interest >= 0) {
                $('#ff_int_' + id).text(f_interest);
                $('#intf_' + id).val(f_interest);
            } else if (f_interest < 0) {
                alert("Interest Cannot be lessthan 0")
                $('#ff_int_' + id).text(f_int);
                $('#f_others_' + id).val(0);
            }
            var total = init_total + others_val + f_others_val + d_others_val;
            $('#total_' + id).text(total);
            $('#tot_' + id).val(total);
            var tot_m = $('#sno').attr("data-id");
            var tot_others = 0;
            for (j = 1; j <= tot_m; j++) {
                var others_ = $('#others_' + j).val() == "" ? 0 : $('#others_' + j).val();
                tot_others += parseInt(others_);
            }
            $('#tot_others').val(tot_others);
            var final_t = $('#sno').attr("data-id");
            var tot_int = $('#sno').attr("data-tot_int");
            var tot_fint = $('#sno').attr("data-tot_fint");
            var tot = 0;
            for (i = 1; i <= final_t; i++) {
                tot += parseInt($('#tot_' + i).val());
            }
            $('#final_tot').val(tot);
            var int_tot = 0;
            for (i = 1; i <= final_t; i++) {
                int_tot += parseInt($('#f_int_' + i).text());
            }
            var fi_tint = parseInt(tot_int);
            $('#f_int_tot').val(int_tot + fi_tint);
            var fint_tot = 0;

            for (i = 1; i <= final_t; i++) {
                fint_tot += parseInt($('#ff_int_' + i).text());
            }
            var fi_tfint = parseInt(tot_fint);
            $('#ff_int_tot').val(fint_tot + fi_tfint);

            var d_o_tot = 0;
            for (i = 1; i <= final_t; i++) {
                d_o_tot += parseInt($('#d_others_' + i).val() == "" ? 0 : $('#d_others_' + i).val());
            }

            var d_oth_tot = parseInt(d_o_tot);
            $('#d_others_total').val(d_oth_tot);
        });
    });
</script>