<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <!-- <h1 class="m-0">Old Demand</h1> -->
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="#">Demand</a></li>
                    <li class="breadcrumb-item active">Old Demand</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 no-print">
                            Old Demand 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/demand_old" id="member_add_" enctype='multipart/form-data'>
                            <div class="row no-print">
                                <div class="col-sm-2">
                                    <div>Division</div>
                                    <select name="division" id="division_id" class="form-control">
                                        <option value="">All</option>
                                        <?php foreach ($divisions as $div) { ?>
                                            <option <?php if ($division == $div['division']) {
                                                        echo "selected";
                                                    } ?> value="<?php echo $div['division']; ?>"><?php echo $div['division']; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <div>Section</div>
                                    <select name="section" id="section_id" onchange="displaydemand_type_method();" class="form-control">
                                        <option value="">All</option>
                                        <?php foreach ($sections as $sec) { ?>
                                            <option <?php if ($section == $sec['section']) {
                                                        echo "selected";
                                                    } ?> value="<?php echo $sec['section']; ?>"><?php echo $sec['section']; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <div>Members</div>
                                    <select name="mem_no" id="mem_no" class="form-control">
                                        <option value="">All</option>
                                        <?php foreach ($membersf as $mem) { ?>
                                            <option value="<?php echo $mem['me_no']; ?>"><?php echo $mem['me_no'] . "-" . $mem['mem_name']; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <div>Month</div>
                                    <?php $m = $month; ?>
                                    <select name="month" class="form-control">
                                        <option value="">Select Month</option>
                                        <option <?php if ($m == "January") {
                                                    echo "selected";
                                                } ?> value="January">January</option>
                                        <option <?php if ($m == "February") {
                                                    echo "selected";
                                                } ?> value="February">February</option>
                                        <option <?php if ($m == "March") {
                                                    echo "selected";
                                                } ?> value="March">March</option>
                                        <option <?php if ($m == "April") {
                                                    echo "selected";
                                                } ?> value="April">April</option>
                                        <option <?php if ($m == "May") {
                                                    echo "selected";
                                                } ?> value="May">May</option>
                                        <option <?php if ($m == "June") {
                                                    echo "selected";
                                                } ?> value="June">June</option>
                                        <option <?php if ($m == "July") {
                                                    echo "selected";
                                                } ?> value="July">July</option>
                                        <option <?php if ($m == "August") {
                                                    echo "selected";
                                                } ?> value="August">August</option>
                                        <option <?php if ($m == "September") {
                                                    echo "selected";
                                                } ?> value="September">September</option>
                                        <option <?php if ($m == "October") {
                                                    echo "selected";
                                                } ?> value="October">October</option>
                                        <option <?php if ($m == "November") {
                                                    echo "selected";
                                                } ?> value="November">November</option>
                                        <option <?php if ($m == "December") {
                                                    echo "selected";
                                                } ?> value="December">December</option>
                                    </select>
                                </div>
                                <div class="col-sm-2">Year
                                    <?php $y = $year; ?>
                                    <select name="year" class="form-control">
                                        <option value="">Year</option>
                                        <?php for ($j = date("Y"); $j >= 2023; $j--) { ?>
                                            <option <?php if ($j == $y) {
                                                        echo "selected";
                                                    } ?> value="<?php echo $j; ?>"><?php echo $j; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                                <div class="col-sm-1 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_p_int = 0;
                    $tot_f_p_int = 0;
                    $tot_fpri = 0;
                    $tot_fint = 0;
                    $tot_fos = 0;
                    $tot_td = 0;
                    $tot_others = 0;
                    $tot_ins = 0;
                    $tot_recover = 0;
                    // echo "<pre>";print_r($members);die();
                    ?>
                    <?php if (isset($members) && count($members) > 0) { ?><br><br>
                        <div class="row mt-3 " id="printableArea">
                            <div class="col-sm-12 ">
                                <div class="tile">
                                    <div class="tile-body print-container">
                                        <div class="row mb-2">
                                            <div class="col-sm-12 text-center">
                                                <h5><b>
                                                        <h5><b><?php echo $common[0]['society_title']; ?></b></h5>
                                                    </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", strtotime($members[0]->added_on)); ?></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>

                                        <form>

                                            <div class="row no-print">
                                                <div class="col-sm-1">
                                                    <input type="submit" name="export" id="export" class="btn btn-success" value="Export" />

                                                </div>
                                                <div class="col-sm-1">
                                                    <input type="button" onclick="printDiv('printableArea')" class="btn btn-primary" value="Print" />

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

                                        <br><br>
                                        <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="excel_id" class="table table-striped table-bordered " style="width:100%;display:inline-table">
                                            <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">Thrift Bal</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">P.Int</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">FP.Int</th> -->
                                                    <th class="text-center">Thrift</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>
                                                <?php
                                                $pre_section = "";
                                                if ($division != "") {

                                                    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></td>
                                                            </tr>
                                                        <?php
                                                        }
                                                        $pre_section = $member->section;
                                                        $sno = $sno + 1; ?>

                                                        <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->me_no ?>

                                                            </td>
                                                            <td style="padding:5px; margin:0px;">
                                                                <?= $member->mem_name ?>
                                                            </td>
                                                            <td style="padding:5px; margin:0px;">
                                                                <?= $member->mem_desig ?>
                                                            </td>
                                                            <!-- <td style="padding:5px; margin:0px;text-align:right;" id="loan_os_amt">
                                                                <?php if ($member->tot_thrift != "") { ?>
                                                                    <?= $member->tot_thrift ?>
                                                                <?php } ?>
                                                            </td> -->
                                                            <td style="padding:5px; margin:0px;text-align:right;" id="loan_os_amt">
                                                                <?php if ($member->loan_no != "") { ?>
                                                                    <?= $member->loan_no ?>
                                                                <?php } ?>
                                                            </td>
                                                            <?php if ($display_demand_type != "wothrift") { ?>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_loan_os > 0) { ?>
                                                                        <?= $member->d_loan_os ?>
                                                                    <?php } ?>

                                                                </td>
                                                                <!-- <td class="text-right" style="padding:5px; margin:0px;">
                                                                    <?= $member->curr_instalment . '/' . $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) { ?>
                                                                        <?php echo $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 } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->p_int > 0) { ?>
                                                                        <?php echo $member->p_int; ?>
                                                                    <?php } ?>

                                                                </td>
                                                                <!-- <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_os > 0) { ?>
                                                                        <?= $member->f_os ?>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_pri > 0) { ?>
                                                                        <?php echo $member->f_pri; ?>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_int > 0) { ?>
                                                                        <?php echo $member->f_int; ?>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_p_int > 0) { ?>
                                                                        <?php echo $member->f_p_int; ?>
                                                                    <?php } ?>
                                                                </td> -->
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_thrift != "") { ?>
                                                                        <?= $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;">
                                                                    <?php if ($member->d_others > 0) { ?>
                                                                        <?php echo $member->d_others; ?>
                                                                    <?php } ?>
                                                                </td>
                                                            <?php } ?>
                                                            <?php if ($display_demand_type == "all") { ?>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_total > 0) { ?>
                                                                        <?php echo $member->d_total; ?>
                                                                    <?php } ?>
                                                                </td>
                                                            <?php } else if ($display_demand_type == "thrift") { ?>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_thrift > 0) { ?>
                                                                        <?php echo $member->d_thrift; ?>
                                                                    <?php } ?>
                                                                </td>
                                                            <?php } else { ?>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_total  > 0) { ?>
                                                                        <?php echo $member->d_total; ?>
                                                                    <?php } ?>
                                                                </td>
                                                            <?php } ?>
                                                            <td></td>
                                                        </tr>
                                                        <?php
                                                        if ($member->old_p_int > 0 || $member->d_last_thrift > 0 || $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 style="padding:5px; margin:0px;text-align:right;"></td>
                                                                <td></td>
                                                                <!-- <td></td> -->
                                                                <td></td>
                                                                <td></td>
                                                                <!-- <td></td> -->
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_last_principal > 0) { ?>
                                                                        <b> <?php echo $member->d_last_principal; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">

                                                                    <b> 3%</b>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_last_int > 0) { ?>
                                                                        <b> <?php echo $member->d_last_int; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->old_p_int > 0) { ?>
                                                                        <b> <?php echo $member->old_p_int; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <!-- <td style="padding:5px; margin:0px;text-align:right;">
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_old_pri > 0) { ?>
                                                                        <b> <?php echo $member->f_old_pri; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_old_int > 0) { ?>
                                                                        <b> <?php echo $member->f_old_int; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_old_p_int > 0) { ?>
                                                                        <b> <?php echo  $member->f_old_p_int; ?></b>
                                                                    <?php } ?>
                                                                </td> -->
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_last_thrift > 0) { ?>
                                                                        <b> <?php echo $member->d_last_thrift; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->old_ins > 0) { ?>
                                                                        <b><?php echo $member->old_ins; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td>
                                                                    <?php if ($member->old_others > 0) { ?>
                                                                        <b> <?php echo $member->old_others; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td>

                                                                </td>
                                                                <td></td>
                                                            </tr>
                                                        <?php } ?>
                                                        <?php $member_ft += $member->d_total;
                                                        $tot_thrift += $member->tot_thrift;
                                                        $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->d_last_int;
                                                        $tot_p_int += $member->p_int + $member->old_p_int;
                                                        $tot_fpri += $member->f_pri + $member->f_old_pri;
                                                        $tot_fint += $member->f_int + $member->f_old_int;
                                                        $tot_fos += $member->f_os;
                                                        $tot_f_p_int += $member->f_p_int + $member->f_old_p_int;
                                                        $tot_td += $member->d_thrift + $member->d_last_thrift;
                                                        $tot_ins += $member->d_insurance + $member->old_ins;
                                                        $tot_others += $member->d_others + $member->old_others; ?>
                                                    <?php } ?>
                                                <?php } else { ?>


                                                    <?php foreach ($members as $key => $member) {
                                                        $member = (object) $member;
                                                    ?>

                                                        <?php
                                                        $pre_section = $member->section;
                                                        $sno = $sno + 1; ?>

                                                        <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->me_no ?>

                                                            </td>
                                                            <td style="padding:5px; margin:0px;">
                                                                <?= $member->mem_name ?>
                                                            </td>
                                                            <td style="padding:5px; margin:0px;">
                                                                <?= $member->mem_desig ?>
                                                            </td>
                                                            <!-- <td style="padding:5px; margin:0px;text-align:right;" id="loan_os_amt">
                                                                <?php if ($member->tot_thrift != "") { ?>
                                                                    <?= $member->tot_thrift ?>
                                                                <?php } ?>
                                                            </td> -->
                                                            <td style="padding:5px; margin:0px;text-align:right;" id="loan_os_amt">
                                                                <?php if ($member->loan_no != "") { ?>
                                                                    <?= $member->loan_no ?>
                                                                <?php } ?>
                                                            </td>
                                                            <?php if ($display_demand_type != "wothrift") { ?>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_loan_os > 0) { ?>
                                                                        <?= $member->d_loan_os ?>
                                                                    <?php } ?>

                                                                </td>
                                                                <!-- <td class="text-right" style="padding:5px; margin:0px;">
                                                                    <?= $member->curr_instalment . '/' . $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) { ?>
                                                                        <?php echo $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 } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->p_int > 0) { ?>
                                                                        <?php echo $member->p_int; ?>
                                                                    <?php } ?>

                                                                </td>
                                                                <!-- <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_os > 0) { ?>
                                                                        <?= $member->f_os ?>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_pri > 0) { ?>
                                                                        <?php echo $member->f_pri; ?>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_int > 0) { ?>
                                                                        <?php echo $member->f_int; ?>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                </td> -->
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_thrift != "") { ?>
                                                                        <?= $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;">
                                                                    <?php if ($member->d_others > 0) { ?>
                                                                        <?php echo $member->d_others; ?>
                                                                    <?php } ?>
                                                                </td>
                                                            <?php } ?>
                                                            <?php if ($display_demand_type == "all") { ?>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_total > 0) { ?>
                                                                        <?php echo $member->d_total; ?>
                                                                    <?php } ?>
                                                                </td>
                                                            <?php } else if ($display_demand_type == "thrift") { ?>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_thrift > 0) { ?>
                                                                        <?php echo $member->d_thrift; ?>
                                                                    <?php } ?>
                                                                </td>
                                                            <?php } else { ?>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_total  > 0) { ?>
                                                                        <?php echo $member->d_total; ?>
                                                                    <?php } ?>
                                                                </td>
                                                            <?php } ?>
                                                            <td></td>
                                                        </tr>
                                                        <?php
                                                        if ($member->d_last_thrift > 0 || $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 style="padding:5px; margin:0px;text-align:right;"></td>
                                                                <td></td>
                                                                <!-- <td></td> -->
                                                                <td></td>
                                                                <td></td>
                                                                <!-- <td></td> -->
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_last_principal > 0) { ?>
                                                                        <b> <?php echo $member->d_last_principal; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">

                                                                    <b> 3%</b>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_last_int > 0) { ?>
                                                                        <b> <?php echo $member->d_last_int; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->old_p_int > 0) { ?>
                                                                        <b> <?php echo $member->old_p_int; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <!-- <td style="padding:5px; margin:0px;text-align:right;">
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_old_pri > 0) { ?>
                                                                        <b> <?php echo $member->f_old_pri; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_old_int > 0) { ?>
                                                                        <b> <?php echo $member->f_old_int; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->f_old_p_int > 0) { ?>
                                                                        <b> <?php echo  $member->f_old_p_int; ?></b>
                                                                    <?php } ?>
                                                                </td> -->
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->d_last_thrift > 0) { ?>
                                                                        <b> <?php echo $member->d_last_thrift; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td style="padding:5px; margin:0px;text-align:right;">
                                                                    <?php if ($member->old_ins > 0) { ?>
                                                                        <b><?php echo $member->old_ins; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td>
                                                                    <?php if ($member->old_others > 0) { ?>
                                                                        <b> <?php echo $member->old_others; ?></b>
                                                                    <?php } ?>
                                                                </td>
                                                                <td>

                                                                </td>
                                                                <td></td>
                                                            </tr>
                                                        <?php } ?>
                                                        <?php $member_ft += $member->d_total;
                                                        $tot_thrift += $member->tot_thrift;
                                                        $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->d_last_int;
                                                        $tot_p_int += $member->p_int + $member->old_p_int;
                                                        $tot_fpri += $member->f_pri + $member->f_old_pri;
                                                        $tot_fint += $member->f_int + $member->f_old_int;
                                                        $tot_fos += $member->f_os;
                                                        $tot_f_p_int += $member->f_p_int + $member->f_old_p_int;
                                                        $tot_td += $member->d_thrift + $member->d_last_thrift;
                                                        $tot_ins += $member->d_insurance + $member->old_ins;
                                                        $tot_others += $member->d_others + $member->old_others; ?>


                                                    <?php } ?>
                                                <?php } ?>
                                                <tr style="height:30px;">
                                                    <td>

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

                                                    </td>
                                                    <td></td>
                                                    <td>

                                                    </td>
                                                    <!-- <td style="padding:5px; margin:0px;text-align:right;">
                                                        <b> <?php echo $tot_thrift; ?></b>
                                                    </td> -->
                                                    <td>

                                                    </td>
                                                    <?php if ($display_demand_type != "wothrift") { ?>
                                                    <?php } ?>
                                                    <?php if ($display_demand_type != "thrift") { ?>
                                                        <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_p_int; ?></b>
                                                        </td>
                                                        <!-- <td style="padding:5px; margin:0px;text-align:right;">
                                                            <b> <?php echo $tot_fos; ?></b>
                                                        </td>
                                                        <td style="padding:5px; margin:0px;text-align:right;">
                                                            <b> <?php echo $tot_fpri; ?></b>
                                                        </td>
                                                        <td style="padding:5px; margin:0px;text-align:right;">
                                                            <b> <?php echo $tot_fint; ?></b>
                                                        </td>
                                                        <td style="padding:5px; margin:0px;text-align:right;">
                                                            <b> <?php echo $tot_f_p_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>
                                                    <?php } ?>
                                                    <?php if ($display_demand_type == "all") { ?>
                                                        <td style="padding:5px; margin:0px;text-align:right;">
                                                            <b> <?php echo $member_ft; ?></b>
                                                        </td>
                                                    <?php } else if ($display_demand_type == "thrift") { ?>
                                                        <td style="padding:5px; margin:0px;text-align:right;">
                                                            <b> <?php echo $tot_td; ?></b>
                                                        </td>
                                                    <?php } else { ?>
                                                        <td style="padding:5px; margin:0px;text-align:right;">
                                                            <b> <?php echo $member_ft; ?></b>
                                                        </td>
                                                    <?php } ?>
                                                    <td></td>
                                                </tr>
                                            </tbody>
                                        </table>

                                        <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>

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

                    <?php } ?>






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


<script src="//cdn.rawgit.com/rainabba/jquery-table2excel/1.1.0/dist/jquery.table2excel.min.js"> </script>
<script>
    $(document).ready(function() {
        $("#export").click(function() {
            $("#excel_id").table2excel({
                filename: "Demand_Details",
            });
            return false;
        });
    })
</script>
<script>
    function displaydemand_type_method() {
        var section = $("#section_id").val();
        if (section != "" && section != "MANAGER") {
            $("#display_demand_type").show();
        } else {
            $("#display_demand_type").hide();
        }
    }


    $('#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/getsection",
            data: {
                division: division
            },
            dataType: 'html',
            success: function(data) {

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

    });
</script>