<div id="page-wrapper">
    <div class="header">
        <h1 class="page-header">

        </h1>
        <ol class="breadcrumb">
            <li><a href="#">Member</a></li>
            <li class="active">Tally</li>
        </ol>
    </div>

    <div id="page-inner">
        <?php foreach ($cmt as $data) : ?>
            <?php $cthrift += $data['thrift_amt'] ?>
        <?php endforeach; ?>

        <?php foreach ($pmt as $data) : ?>
            <?php $pthrift += $data['thrift_amt'] ?>
        <?php endforeach; ?>
        <?php foreach ($cms as $data) : ?>
            <?php $cshare += $data['share_amt'] ?>
        <?php endforeach; ?>

        <?php foreach ($pms as $data) : ?>
            <?php $pshare += $data['share_amt'] ?>
        <?php endforeach; ?>
        <?php foreach ($cmp as $data) : ?>
            <?php $cp += $data['loan_pri_amt']; ?>
        <?php endforeach; ?>
        <?php foreach ($pmp as $data) : ?>
            <?php $pp += $data['loan_pri_amt'] ?>
        <?php endforeach; ?>
        <?php foreach ($cmi as $data) : ?>

            <?php $ci += $data['loan_int_amt'] ?>
        <?php endforeach; ?>

        <?php foreach ($pmi as $data) : ?>

            <?php $pi += $data['loan_int_amt'] ?>
        <?php endforeach; ?>

        <?php foreach ($other_income1 as $data) : ?>
            <?php $ptotal += $data['pamount']; ?>
            <?php $ctotal += $data['camount']; ?>
        <?php endforeach; ?>

        <?php foreach ($other_income as $data) : ?>
            <?php $pototal += $data['pamount']; ?>
            <?php $cototal += $data['camount']; ?>
        <?php endforeach; ?>




        <div class="row">

            <div class="col-md-12">
                <!-- Advanced Tables -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Profit & Loss Details
                    </div>
                    <div class="panel-body">
                        <table border="1" style="float:left;margin-right:5px;margin-left:20px;">
                            <tr>
                                <th colspan="5" style="height:40px;">R693, TRICHY DISTRICT AGRICULTURAL DEPARTMENT OFFICERS CO-OPERATIVE THRIFT & CREDIT SOCIETY LIMITED.</th>
                            </tr>

                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b>S.No.</b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b>income</b></td>
                                <td width="128" style="padding-left:6px;"><label><b><?= $pmonth = date("F", strtotime('-1 month', strtotime(date('F')))); ?></b></label></td>
                                <td width="128" style="padding-left:6px;"><b> <?= $cmonth = date('F'); ?></b></td>
                                <td width="128">&nbsp;<b><?= $cmonth = date('F'); ?></b></td>
                            </tr>
                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b>1</b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b>Interest</b></td>
                                <td width="128" style="padding-left:6px;"><label> <?= $pi ?></label></td>
                                <td width="128" style="padding-left:6px;"> <?= $ci ?></td>
                                <td width="128"> <?= $ti = $pi + $ci ?></td>
                            </tr>
                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b>2</b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b>Thrifty savings</b></td>
                                <td width="128" style="padding-left:6px;"><label><?= $pthrift; ?></label></td>
                                <td width="128" style="padding-left:6px;"><?= $cthrift; ?></td>
                                <td width="128"><?= $tt = $pthrift + $cthrift; ?></td>
                            </tr>
                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b>3</b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b>Member's Principal</b></td>
                                <td width="128" style="padding-left:6px;"><label> <?= $pp ?></label></td>
                                <td width="128" style="padding-left:6px;"> <?= $cp ?></td>
                                <td width="128"> <?= $tp = $pp + $cp ?></td>
                            </tr>
                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b>4</b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b>Share</b></td>
                                <td width="128" style="padding-left:6px;"><label> <?= $pshare ?></label></td>
                                <td width="128" style="padding-left:6px;"> <?= $cshare ?></td>
                                <td width="128"><?= $ts = $pshare + $cshare ?></td>
                            </tr>
                            <?php $sno = 5; ?>
                            <?php foreach ($other_income1 as $data) : ?>
                                <tr>
                                    <td width="69" style="height:30px; padding-left:6px;"><b> <?= $sno; ?></b></td>
                                    <td width="208" style="height:30px; padding-left:6px;"><b><?= $data['list'] ?> <br> <?= $data['tamil'] ?></b></td>
                                    <td width="128" style="padding-left:6px;"><label><?= $data['pamount'] ?></label></td>
                                    <td width="128" style="padding-left:6px;"> <?= $data['camount'] ?></td>
                                    <td width="128"> <?= $t = $data['pamount'] + $data['camount'] ?></td>
                                    <?php $others_amount += $data['pamount'] + $data['camount'] ?>
                                </tr>
                                <?php $sno++; ?>
                            <?php endforeach; ?>
                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b> </b></td>
                                <td width="128" style="padding-left:6px;"><label></label></td>
                                <td width="128" style="padding-left:6px;"> </td>
                                <td width="128"> </td>
                            </tr>

                            <?php $previous_title = "";
                            foreach ($other_income as $data) {
                                if ($previous_title != $data['list']) {
                            ?>
                                    <tr>
                                        <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                                        <td width="208" style="height:30px; padding-left:6px;"><b><?= $data['list'] ?>  <br> <?= $data['tamil'] ?></b></td>
                                        <td width="128" style="padding-left:6px;"><label></label></td>
                                        <td width="128" style="padding-left:6px;"> </td>
                                        <td width="128"> </td>
                                    </tr>
                                <?php
                                } ?>
                                <tr>
                                    <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                                    <td width="208" style="height:30px; padding-left:6px;"><b><?= $data['stitle'] ?> <br> <?= $data['sub_tamil'] ?></b></td>
                                    <td width="128" style="padding-left:6px;"><?= $data['pamount'] ?></td>
                                    <td width="128" style="padding-left:6px;"><?= $data['camount'] ?> </td>
                                    <td width="128"><?= $total = $data['pamount'] + $data['camount'] ?></td>
                                </tr>

                            <?php
                                $previous_title = $data['list'];
                            } ?>

                            <?php
                            $extra1 = $pthrift + $pshare + $pp + $pi + $ptotal + $pototal;
                            $extra2 = $cthrift + $cshare + $cp + $ci + $ctotal + $cototal;
                            $extra3 = $ti + $tt + $ts + $tp + $others_amount + $total;


                            ?>
                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b> </b></td>
                                <td width="128" style="padding-left:6px;"><label></label></td>
                                <td width="128" style="padding-left:6px;"> </td>
                                <td width="128"> </td>
                            </tr>
                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b>Extra</b></td>
                                <td width="128" style="padding-left:6px;"><label><?= $extra1; ?></label></td>
                                <td width="128" style="padding-left:6px;"><?= $extra2; ?></td>
                                <td width="128"><?= $extra3; ?></td>
                            </tr>
                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b>Initial stock</b></td>
                                <td width="128" style="padding-left:6px;"><label>-</label></td>
                                <td width="128" style="padding-left:6px;">-</td>
                                <td width="128">-</td>
                            </tr>
                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b>Annual Extra</b></td>
                                <td width="128" style="padding-left:6px;"><label><?= $extra1; ?></label></td>
                                <td width="128" style="padding-left:6px;"><?= $extra2; ?></td>
                                <td width="128"><?= $extra3; ?></td>
                            </tr>

                        </table>


                        <table border="1" style="float:left;margin-left:45px;">
                            <tr>
                                <th colspan="5" style="height:40px;">R693, TRICHY DISTRICT AGRICULTURAL DEPARTMENT OFFICERS CO-OPERATIVE THRIFT & CREDIT SOCIETY LIMITED.</th>
                            </tr>

                            <tr>
                                <td width="69" style="height:30px; padding-left:6px;"><b>S.No.</b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b>Expense</b></td>
                                <td width="128" style="padding-left:6px;"><b><?= $pmonth = date("F", strtotime('-1 month', strtotime(date('F')))); ?></b></label></td>
                                <td width="128" style="padding-left:6px;"><b> <?= $cmonth = date('F'); ?></b></td>
                                <td width="128">&nbsp;<b><?= $cmonth = date('F'); ?></b></td>
                            </tr>
                            <?php $sno = 1; ?>
                            <?php foreach ($expense as $data) : ?>
                                <td width="69" style="height:30px; padding-left:6px;"><b><?= $sno; ?></b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b><?= $data['statement'] ?> <br><?= $data['tstatement'] ?>
                            </b></td>
                                <td width="128" style="padding-left:6px;"><?= $data['pamount'] ?></td>
                                <td width="128" style="padding-left:6px;"><?= $data['amount'] ?> </td>
                                <td width="128"><?= $total_ex = $data['pamount'] + $data['amount'] ?></td>
                                </tr>
                                <?php $sno++; ?>
                                <?php $pexpense += $data['pamount'];
                                $cexpense += $data['amount'];
                                $total_expenses += $total_ex;
                                ?>
                            <?php endforeach; ?>
                            <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                            <td width="208" style="height:30px; padding-left:6px;"><b> </b></td>
                            <td width="128" style="padding-left:6px;"><label></label></td>
                            <td width="128" style="padding-left:6px;"> </td>
                            <td width="128"> </td>
                            </tr>



                            <?php $previous_title1 = "";
                            foreach ($other_expense as $data) {
                                if ($previous_title1 != $data['list']) {
                            ?>

                                    <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                                    <td width="208" style="height:30px; padding-left:6px;"><b><?= $data['list'] ?>  <br> <?= $data['tamil'] ?></b></td>
                                    <td width="128" style="padding-left:6px;"><label></label></td>
                                    <td width="128" style="padding-left:6px;"> </td>
                                    <td width="128"> </td>
                                    </tr>
                                <?php
                                } ?>
                                <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                                <td width="208" style="height:30px; padding-left:6px;"><b><?= $data['stitle'] ?>  <br> <?= $data['sub_tamil'] ?></b></td>
                                <td width="128" style="padding-left:6px;"><?= $data['pamount'] ?></td>
                                <td width="128" style="padding-left:6px;"><?= $data['camount'] ?> </td>
                                <td width="128"><?= $e_total = $data['pamount'] + $data['camount'] ?></td>
                                <?php $pamount += $data['pamount']; ?>
                                <?php $camount += $data['camount']; ?>
                                <?php $ex_total += $e_total ?>

                                </tr>

                            <?php
                                $previous_title1 = $data['list'];
                            } ?>
                            <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                            <td width="208" style="height:30px; padding-left:6px;"><b> </b></td>
                            <td width="128" style="padding-left:6px;"><label></label></td>
                            <td width="128" style="padding-left:6px;"> </td>
                            <td width="128"> </td>
                            </tr>
                            <?php
                            print_r($expense_total);
                            $expense_extra =  $pexpense + $pamount;
                            $expense_extra1 =  $cexpense + $camount;
                            $expense_extra2 =  $ex_total + $total_expenses;

                            ?>

                            <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                            <td width="208" style="height:30px; padding-left:6px;"><b> </b></td>
                            <td width="128" style="padding-left:6px;"><label></label></td>
                            <td width="128" style="padding-left:6px;"> </td>
                            <td width="128"> </td>
                            </tr>
                            <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                            <td width="208" style="height:30px; padding-left:6px;"><b> </b></td>
                            <td width="128" style="padding-left:6px;"><label></label></td>
                            <td width="128" style="padding-left:6px;"> </td>
                            <td width="128"> </td>
                            </tr>
                            <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                            <td width="208" style="height:30px; padding-left:6px;"><b>Extra</b></td>
                            <td width="128" style="padding-left:6px;"><label><?= $expense_extra ?></label></td>
                            <td width="128" style="padding-left:6px;"><?= $expense_extra1 ?></td>
                            <td width="128"><?= $expense_extra2 ?></td>
                            </tr>
                            <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                            <td width="208" style="height:30px; padding-left:6px;"><b>End stock</b></td>
                            <td width="128" style="padding-left:6px;"><label>-</label></td>
                            <td width="128" style="padding-left:6px;">-</td>
                            <td width="128">-</td>
                            </tr>
                            <td width="69" style="height:30px; padding-left:6px;"><b></b></td>
                            <td width="208" style="height:30px; padding-left:6px;"><b>Annual Extra</b></td>
                            <td width="128" style="padding-left:6px;"><label><?= $expense_extra ?></label></td>
                            <td width="128" style="padding-left:6px;"><?= $expense_extra1 ?></td>
                            <td width="128"><?= $expense_extra2 ?></td>
                            </tr>

                        </table>
                    </div>


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