<div class="row-fluid" id="plr-records">
	<div class="span12">
		<div class="widget" id="">
			<div class="widget-title">
				<h4>
					<i class="icon-reorder">
					</i>
					List
				</h4>
                <h4 class="flash-inner"><span class="greenMsg flash-msg"><?php echo Session::get('message'); ?></span></h4>
            </div>
            <form method="post" onsubmit="return false;" action="<?php echo ADMIN_URL.'plr-accounting/update'; ?>" name="frmPlrSummary" id="frmPlrSummary">
                <input type="hidden" id="i_entry_year" name="i_entry_year" value="<?php echo $i_entry_year; ?>"/>
                <input type="hidden" id="i_entry_month" name="i_entry_month" value="<?php echo $i_entry_month; ?>"/>
                <input type="hidden" id="summary_id" name="summary_id" value="<?php echo $summaryFundRecord['summary_id']; ?>"/>            
            <?php
            if(isset($records['tithe_income']) && count($records['tithe_income'])>0  && $summary_status == 1) { 
                $lastCategory = '';$subTotalCategory = 0;
                ?>
            <div class="widget-body">
                
                <table width="100%">
                    <tr>
                        <td><h3 class="total-pricing">Tithe Income Total - <?php echo CURRENCY_SYMBOL . number_format($records['tithe_income_total'], 2, '.',','); ?></h3></td>
                    </tr>
                </table>
                <table class="table table-striped table-bordered table-advance plr-record-tbl" id="sample_1">
                    <thead>
                        <tr>
                            <th class="none-short">Action</th>
                            <th class="none-short">Description</th>
                            <th class="none-short">Category</th>
                            <th class="none-short">Amount</th>
                        </tr>
                    </thead>
                    <tbody id="tbody_drag">
                    <?php //pr($records['tithe_income']);exit;
                     $subTotalCategory = null;
                     foreach($records['tithe_income'] as $records_key => $records_value){ ?>
                            <?php if($lastCategory != $records_value['v_category']){
                                    
                                    if($subTotalCategory != null) {
                                    ?> 
                                    <tr>
                                        <td colspan="2">&nbsp;</td>
                                        <td><b>Sub Total</b></td>
                                        <td><?php echo CURRENCY_SYMBOL . number_format($subTotalCategory, 2, '.',','); ?></td>
                                    </tr> 
                                    <?php
                                        $subTotalCategory = 0; $lastCategory = ''; 
                                    } ?>
                                    
                                    <tr>
                                        <td colspan="2">&nbsp;</td>
                                        <td colspan="2"><b><?php echo $records_value['v_category']; ?></b></td>
                                    </tr>
                                    <?php
                                    $lastCategory = $records_value['v_category']; 
                                    } ?>
                                <tr class="odd gradeX <?php echo $lastCategory; ?>" id="ApplicantRow-<?php echo $records_value['id']; ?>">
                                    <td>
                                        <a class="btn_edit" title="Edit" href="javascript:void(0)" rel="<?php echo $records_value['id'];  ?>"><i class="icon-pencil"></i></a>                         </td>
                                    <td><?php echo $records_value['v_description']; ?></td>
                                    <td><?php echo $records_value['v_category']; ?></td>
                                    <td><?php echo CURRENCY_SYMBOL . number_format($records_value['f_amount'], 2, '.',','); ?></td>
                                </tr>
                       <?php $subTotalCategory = $subTotalCategory + $records_value['f_amount'];
                             $lastCategory = $records_value['v_category'];
                        } ?>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                            <td><b>Sub Total</b></td>
                            <td><?php echo CURRENCY_SYMBOL . number_format($subTotalCategory, 2, '.',','); ?></td>
                        </tr>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                            <td><b>Tithe Income Total</b></td>
                            <td><?php echo CURRENCY_SYMBOL . number_format($records['tithe_income_total'], 2, '.',','); ?></td>
                        </tr>  
                 </tbody>
                </table>
            </div>
            <?php } ?>
            <?php 
            if(isset($records['non_tithe_income']) && count($records['non_tithe_income'])>0 && $summary_status == 1) {
                $lastCategory = '';$subTotalCategory = 0;
                ?>
            <div class="widget-body">
                <table width="100%">
                    <tr>
                        <td>
                            <h3 class="total-pricing"> Non-Tithe Income Total - <?php echo CURRENCY_SYMBOL . number_format($records['non_tithe_income_total'], 2, '.',','); ?></h3>
                        </td>
                    </tr>
                </table>
                <table class="table table-striped table-bordered table-advance plr-record-tbl" id="sample_1">
                    <thead>
                        <tr>
                            <th class="none-short">Action</th>
                            <th class="none-short">Description</th>
                            <th class="none-short">Category</th>
                            <th class="none-short">Amount</th>
                        </tr>
                    </thead>
                    <tbody id="tbody_drag">
                    <?php foreach($records['non_tithe_income'] as $records_key => $records_value){ ?>
                            <?php if($lastCategory != $records_value['v_category']){
                                    if($subTotalCategory != null) {
                                ?> 
                                <tr>
                                    <td colspan="2">&nbsp;</td>
                                    <td><b>Sub Total</b></td>
                                    <td><?php echo CURRENCY_SYMBOL . number_format($subTotalCategory, 2, '.',','); ?></td>
                                </tr> 
                                <?php
                                    $subTotalCategory = 0; $lastCategory = ''; 
                                } ?>
                                
                                <tr>
                                    <td colspan="2">&nbsp;</td>
                                    <td colspan="2"><b><?php echo $records_value['v_category']; ?></b></td>
                                </tr>
                                <?php
                                $lastCategory = $records_value['v_category']; 
                            } ?>
                            <tr class="odd gradeX" id="ApplicantRow-<?php echo $records_value['id']; ?>">
                                <td>
                                    <a class="btn_edit" title="Edit" href="javascript:void(0)" rel="<?php echo $records_value['id'];  ?>"><i class="icon-pencil"></i></a>                        </td>
                                <td><?php echo $records_value['v_description']; ?></td>
                                <td><?php echo $records_value['v_category']; ?></td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($records_value['f_amount'], 2, '.',','); ?></td>
                            </tr>
                             <?php $subTotalCategory = $subTotalCategory + $records_value['f_amount'];
                                 $lastCategory = $records_value['v_category'];
                            } ?>
                            <tr>
                                <td colspan="2">&nbsp;</td>
                                <td><b>Sub Total</b></td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($subTotalCategory, 2, '.',','); ?></td>
                            </tr>
                            <tr>
                                <td colspan="2">&nbsp;</td>
                                <td><b>Non-Tithe Income Total</b></td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($records['non_tithe_income_total'], 2, '.',','); ?></td>
                           </tr> 
                    </tbody>
                </table>
            </div>
            <?php } ?>
            <?php 
            if($summary_status == 2) { ?>
                    <div class="widget-body">
                     <?php if(isset($records['expense']) && count($records['expense'])>0){
                            $lastCategory = '';$subTotalCategory = 0;
                        ?>
                        <table width="100%">
                            <td><h3 class="total-pricing">Expense Total - <?php echo CURRENCY_SYMBOL . number_format($records['expense_total'], 2, '.', ','); ?> </h3></td>
                        </table>
                        <table class="table table-striped table-bordered table-advance plr-record-tbl" id="sample_1">
                            <thead>
                                <tr>
                                    <th class="none-short">Action</th>
                                    <th class="none-short">Description</th>
                                    <th class="none-short">Category</th>
                                    <th class="none-short">Amount</th>
                                </tr>
                            </thead>
                            <tbody id="tbody_drag">
                            <?php 
                            $subTotalCategory != null;
                            foreach($records['expense'] as $records_key => $records_value){ ?>
                                <?php if($lastCategory != $records_value['v_category']){
                                    if($subTotalCategory != null) {
                                    ?> 
                                    <tr>
                                        <td colspan="2">&nbsp;</td>
                                        <td><b>Sub Total</b></td>
                                        <td><?php echo CURRENCY_SYMBOL . number_format($subTotalCategory, 2, '.',','); ?></td>
                                    </tr> 
                                    <?php
                                        $subTotalCategory = 0; $lastCategory = ''; 
                                    } ?>
                                    
                                    <tr>
                                        <td colspan="2">&nbsp;</td>
                                        <td colspan="2"><b><?php echo $records_value['v_category']; ?></b></td>
                                    </tr>
                                    <?php
                                    $lastCategory = $records_value['v_category']; 
                                } ?>
                                <tr class="odd gradeX" id="ApplicantRow-<?php echo $records_value['id']; ?>">
                                    <td>
                                        <a class="btn_edit" title="Edit" href="javascript:void(0)" rel="<?php echo $records_value['id'];  ?>"><i class="icon-pencil"></i></a>                         </td>
                                    <td><?php echo $records_value['v_description']; ?></td>
                                    <td><?php echo $records_value['v_category']; ?></td>
                                    <td><?php echo CURRENCY_SYMBOL . number_format($records_value['f_amount'], 2, '.',','); ?></td>
                                </tr>
                               <?php $subTotalCategory = $subTotalCategory + $records_value['f_amount'];
                                     $lastCategory = $records_value['v_category'];
                                } ?>
                                <tr>
                                    <td colspan="2">&nbsp;</td>
                                    <td><b>Sub Total</b></td>
                                    <td><?php echo CURRENCY_SYMBOL . number_format($subTotalCategory, 2, '.',','); ?></td>
                                </tr>
                                <tr>
                                    <td colspan="2">&nbsp;</td><td><b>Expense Total</b></td>
                                    <td><?php echo CURRENCY_SYMBOL . number_format($records['expense_total'], 2, '.', ','); ?></td>
                                </tr>  
                            </tbody>
                        </table>
            <?php } else {
                echo '<label class="redMsg">No record found.</label>';
            }?>
            </div>
            <?php } ?>
            <?php
            if($summary_status == 1) { ?>
                <div class="widget-body">
                    <table width="100%">
                        <td></td>
                    </table>
                    <table class="table table-striped table-bordered table-advance plr-record-tbl" id="sample_1">
                        <thead>
                            <th colspan="3">Summary</th>
                        </thead>
                        <tbody id="tbody_drag">
                            <tr class="odd gradeX">
                                <td colspan="2">Total Income</td>
                                <td> <?php echo CURRENCY_SYMBOL.number_format($records['tithe_income_total'], 2, '.', ','); ?> </td>
                            </tr>
                            <tr>
                                <td>Tithe</td>
                                <td>
                                <div class="tithepercentage"><input type="text" name="f_tithepercentage" id="f_tithepercentage" class="input-mini percentage" value="<?php echo number_format(abs($summaryFundRecord['tithePercentage'])); ?>"/>%</div>
                                </td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($summaryFundRecord['tithePercentageAmount'], 2, '.',','); ?></td>
                            </tr>
                            <tr>
                                <td colspan="2" >Gift Offering</td>
                                <td>$<input type="text" name="f_giftoffering" id="f_giftoffering" value="<?php echo $summaryFundRecord['giftOfferingAmount']; ?>" class="input-mini"/></td>
                            </tr>
                            <tr>
                                <td colspan="2" >Net Income</td>
                                <td>
                                <!----- If value is in Minus than add ()---->
                                <?php if($summaryFundRecord['netIncome'] < 0): ?>
                                     (<?php echo CURRENCY_SYMBOL.number_format(abs($summaryFundRecord['netIncome']), 2,'.',','); ?>)   
                                <?php else: ?>
                                    <?php echo CURRENCY_SYMBOL.number_format($summaryFundRecord['netIncome'], 2,'.',','); ?>

                                <?php endif; ?>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="3"><button type="submit" id="frmEditSubmit" class="btn btn-success">Update</button></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            <?php } ?>
            <?php 
            if(isset($summary_status) && $summary_status == 3) { ?>
                <div class="widget-body">
                    <table width="100%">
                        <td><h3 class="total-pricing">Summary/Security Fund Record - <?php echo date('F', mktime(0, 0, 0, $i_entry_month, 10)); ?> <?php echo $i_entry_year; ?>  </h3></td>
                    </table>
                    <table class="table table-striped table-bordered table-advance plr-record-tbl" id="sample_1">
                        <thead>
                            <tr>
                                <th class="none-short">Description</th>
                                <th class="none-short">Amount</th>
                            </tr>
                        </thead>
                        <tbody id="tbody_drag">
                            <tr>
                                <td>1.&nbsp;&nbsp;Amount of Working Fund at beginning of month:</td>
                                <td><input type="text" name="f_workingfundbm" id="f_workingfundbm" value="<?php echo $summaryFundRecord['f_workingfundbm']; ?>" /> </td>
                            </tr>
                            <tr>
                                <td>2.&nbsp;&nbsp;Amount taken from Reserve: amount Borrowed; non-tithe amounts rec'd:</td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($records['non_tithe_income_total'], 2, '.',','); ?> </td>
                            </tr>
                            <tr>
                                <td>3.&nbsp;&nbsp;Income for month:</td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($summaryFundRecord['netIncome'], 2, '.',','); ?></td>
                            </tr>
                            <tr>
                                <td>4.&nbsp;&nbsp;Totals Expense for month: </td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($records['expense_total'], 2, '.', ','); ?> </td>
                            </tr>
                            <tr>
                                <td>5.&nbsp;&nbsp;Show gain or loss for month: </td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($summaryFundRecord['gainLossMonth'], 2, '.', ','); ?> </td>
                            </tr>
                            <tr>
                                <td>6.&nbsp;&nbsp;Amount added to Reserve. Amount paid against loan: </td>
                                <td><input type="text" name="f_toreserve" id="f_toreserve" value="<?php echo $summaryFundRecord['f_toreserve']; ?>" /> </td>
                            </tr>
                            <tr>
                                <td>7.&nbsp;&nbsp;Amount toward Security Fund (must not exceed gain for the month): </td>
                                <td> 
                                    <?php if($summaryFundRecord['gainLossMonth'] >= $summaryFundRecord['f_secfundincrement']): ?>
                                        <?php echo CURRENCY_SYMBOL . number_format($summaryFundRecord['f_secfundincrement'], 2, '.', ','); ?>

                                    <?php else: ?>
                                        <span class="redMsg"><?php echo 'Exceeds the available amount!'; ?></span>
                                    <?php endif; ?>
                                </td>
                            </tr>
                            <tr>
                                <td>8.&nbsp;&nbsp;Completed Security Fund. Enter here when added to Working Fund: </td>
                                <td><input type="text" name="f_secfundtoworkfund" id="f_secfundtoworkfund" value="<?php echo $summaryFundRecord['f_secfundtoworkfund']; ?>" /> </td>
                            </tr>
                            <tr>
                                <td>9.&nbsp;&nbsp;Completed Security Fund. Enter here when added to Reserve: </td>
                                <td><input type="text" name="f_secfundtoreserve" id="f_secfundtoreserve" value="<?php echo $summaryFundRecord['f_secfundtoreserve']; ?>" /></td>
                            </tr>
                            <tr>
                                <td>10.&nbsp;&nbsp;Computed balance at end of month: </td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($summaryFundRecord['compBalanceEoM'], 2, '.', ','); ?></td>
                            </tr>
                            <tr>
                                <td>11.&nbsp;&nbsp;Overage or shortage: </td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($summaryFundRecord['overShort'], 2, '.', ','); ?> </td>
                            </tr>
                            <tr>
                                <td>12.&nbsp;&nbsp;Amount of Working Fund at end of month: </td>
                                <td><input type="text" name="f_workingfundem" id="f_workingfundem" value="<?php echo $summaryFundRecord['f_workingfundem']; ?>" /></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="widget-body">
                    <table width="100%">
                        <td><h3 class="total-pricing">Security Fund Record</h3></td>
                    </table>
                    <table class="table table-striped table-bordered table-advance plr-record-tbl" id="sample_1">
                        <thead>
                            <tr>
                                <th class="none-short">Description</th>
                                <th class="none-short">Amount</th>
                            </tr>
                        </thead>
                        <tbody id="tbody_drag">
                            <tr>
                                <td> Accumulated Security Fund from end of previous month:</td>
                                <td><input type="text" name="f_secfundpm" id="f_secfundpm" value="<?php echo $summaryFundRecord['f_secfundpm']; ?>" /> </td>
                            </tr>
                            <tr>
                                <td> Completed Security Fund Increment added to Fund this month:</td>
                                <td><input type="text" name="f_secfundincrement" id="f_secfundincrement" value="<?php echo $summaryFundRecord['f_secfundincrement']; ?>" /></td>
                            </tr>
                            <tr>
                                <td> Total Accumulated Security Fund at end of this month:</td>
                                <td><?php echo CURRENCY_SYMBOL . number_format($summaryFundRecord['totAccSecFundEoM'], 2, '.',','); ?></td>
                            </tr>
                            <tr>
                                <td colspan="2"><button type="submit" id="frmEditSubmit1" class="btn btn-success">Update</button></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            <?php } ?>
            </form> 
       	</div>
	</div>
</div>
<?php Session::remove('message'); ?>
<script>
$(document).ready(function(){
    setTimeout(function(){ $(".flash-msg").html('');$(".greenMsg").html(''); },3000);
    handlePlrSummaryForm();
});
</script>