
<div id="content">                        
    <div class="wrap">
        <div class="head">
            <div class="info">
              <!--<h1><?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
                <?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]</h1>-->
                <ul class="breadcrumb">
                    <li><a href='<?php echo base_url()."home" ?>'><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                    <li><a href='<?php echo base_url()."GeneralLedger" ?>'><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                    <li class="active"><?php echo $this->lang->line('statFinPos') ?></li>
                </ul>
            </div><!-- info -->
            <div class="search">
                <form action="<?php echo base_url() ?>admin/search" method="post">
                    <input name="search_text" type="text" placeholder="search..."/>                                
                    <button type="submit"><span class="i-magnifier"></span></button>
                </form>
            </div>                        
        </div><!-- head --> 
        
        <div class="content">
            <div class="wrap">    
                <div class="row-fluid">
                    <div class="span12">
                        <div class="block">                        
                            <?php require APPPATH.'views\gl\bs\bs-header.php'; ?>
                            <div class="footer">
                                <div class="side fr">
                                    <div class="btn-group">
                                   <?php
                                    $data = array(
                                        'name' => 'mysubmit',
                                        'class' => 'btn-form btn-warning-form');
                                    $js = "onClick='changeList()'";
                                    echo form_button($data, $this->lang->line('generatereport'), $js);
                                    ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="block">
                            <div class="head">
                                <h2><?php echo $this->lang->line('statFinPos') ?></h2>
                                <div class="side fr">
                                    <button class="btn-form btn-success-form" onClick="do_print()"><?php echo $this->lang->line('print') ?></button>
                                </div>
                            </div><!-- head -->
                            <div class="content np">
                                <table class="editable" cellpadding="0" cellspacing="0" width="100%">
                                    <thead>
                                        <tr>
                                            <th><?php echo $this->lang->line('description') ?></th>
                                            <?php foreach($months as $month): ?>
                                            <th class="tar"><?php echo $this->lang->line('month'.date('n',strtotime($month->startDate)))." ".$selyear; ?>&nbsp;&nbsp;</th>
                                          <?php endforeach; ?>
                                            <th class="dn">&nbsp;</th<>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        if (isset($accountGroup) && !empty($accountdetails)) {
                                            foreach ($accountGroup as $datatbl):
                                                foreach($monthly as $key=>$month):
                                                    $total_thisyear[$key] = 0;
                                                    $thisyear_amount[$key] = 0;
                                                    $tyear_amount[$key] = 0;
                                                endforeach;
                                                ?>
                                                <?php if ($datatbl->title == 1) { ?>
                                                    <tr>
                                                        <td colspan="<?php echo count($months)+1; ?>"><h5><?php echo $this->lang->line($datatbl->acctGroupName) ?></h5></td>
                                                    </tr>
                                                <?php } ?>
                                                <?php
                                                foreach ($groupdetails as $rowdet):
                                                    foreach($monthly as $key=>$month):
                                                        $rowdet_thisyeartotal[$key] = 0;
                                                    endforeach;
                                                    if ($rowdet->parentID == $datatbl->ID) {
                                                        ?>
                                                    <?php if ($rowdet->title == 1) { ?>
                                                            <tr>
                                                                <td colspan="<?php echo count($months)+1; ?>">&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet->acctGroupName) ?></strong></td>
                                                            </tr>
                                                        <?php } ?>
                                                        <?php
                                                        foreach ($groupdetails as $rowdet1):
                                                            foreach($monthly as $key=>$month):
                                                                $rowdet1_thisyeartotal[$key] = 0;
                                                            endforeach;
                                                            if ($rowdet1->parentID == $rowdet->ID) {
                                                                ?>
                                                                <?php if ($rowdet1->title == 1) { ?>
                                                                    <tr>
                                                                        <td colspan="<?php echo count($months)+1; ?>">&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet1->acctGroupName) ?></strong></td>
                                                                    </tr>
                                                                <?php } ?>
                                                                <?php if ($monthly) { ?>
                                                                    <?php foreach ($monthly[$start] as $key=>$row):
                                                                        if ($row->acctGroupID == $rowdet1->ID) {
                                                                            ?>
                                                                            <?php if(true) { ?>
                                                                                <tr>
                                                                                    <td style="display:none" ><?php echo $row->ID; ?></td>
                                                                                    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID; ?>/<?php echo $selyear; ?>/<?php echo $selperiod; ?>" title="<?php echo $this->lang->line('details'); ?>" class="btn btn-link edit"><?php echo substr($row->acctCode, 0, 4) . '-' . substr($row->acctCode, 4, 3) . '-' . substr($row->acctCode, 7, 2) . ' [ ' . $row->acctName . ' ]' ?></td>
                                                                                    <?php foreach($monthly as $index=>$month): $zeroChkr = 0; ?>
                                                                                    <?php $tyear_amount[$index] = ($monthly[$index][$key]->lastyeardebit - $monthly[$index][$key]->lastyearcredit) + ($monthly[$index][$key]->currentyeardebit - $monthly[$index][$key]->currentyearcredit); 
                                                                                        $zeroChkr += $tyear_amount[$index];
                                                                                    ?>
                                                                                    
                                                                                    <?php if ($rowdet1->status == 1) { ?>
                                                                                            <td class="tar"><?php echo ($tyear_amount[$index] <= 0 ) ? number_format($tyear_amount[$index] * -1, 2) : '(' . number_format($tyear_amount[$index], 2) . ')' ?></td>
                                                                                    <?php } else { ?>
                                                                                            <td class="tar"><?php echo ($tyear_amount[$index] >= 0 ) ? number_format($tyear_amount[$index], 2) : '(' . number_format($tyear_amount[$index] * -1, 2) . ')' ?></td>
                                                                                    <?php } ?>

                                                                                        <?php $rowdet1_thisyeartotal[$index] = $rowdet1_thisyeartotal[$index] + ($monthly[$index][$key]->lastyeardebit - $monthly[$index][$key]->lastyearcredit) + ($monthly[$index][$key]->currentyeardebit - $monthly[$index][$key]->currentyearcredit); ?>                                        
                                                                                        <?php $rowdet_thisyeartotal[$index] = $rowdet_thisyeartotal[$index] + ($monthly[$index][$key]->lastyeardebit - $monthly[$index][$key]->lastyearcredit) + ($monthly[$index][$key]->currentyeardebit - $monthly[$index][$key]->currentyearcredit); ?>                                        
                                                                                        <?php $total_thisyear[$index] = $total_thisyear[$index] + ($monthly[$index][$key]->lastyeardebit - $monthly[$index][$key]->lastyearcredit) + ($monthly[$index][$key]->currentyeardebit - $monthly[$index][$key]->currentyearcredit); ?>

                                                                                    <?php endforeach;
                                                                                    if($zeroChkr == 0): echo "<td class='dn hideMe'>Display None</td>";
                                                                                    else:               echo "<td class='dn'>Display Block</td>";
                                                                                    endif;
                                                                                    ?>
                                                                                </tr>
                                        
                                    <?php } ?>        
                                <?php }
                            endforeach;
                            ?>
                        <?php } ?>
                                                                <tr>
                                                                    <td>&nbsp;&nbsp;&nbsp;<?php echo $this->lang->line('subtotal') ?> <?php echo $this->lang->line($rowdet1->acctGroupName) ?> </td>

                                                                    <?php foreach($monthly as $index=>$month): ?>
                                                                    <?php if ($rowdet1->status == 1) { ?>
                                                                            <td class="tar sep"><?php echo ($rowdet1_thisyeartotal[$index] <= 0 ) ? number_format($rowdet1_thisyeartotal[$index] * -1, 2) : '(' . number_format($rowdet1_thisyeartotal[$index], 2) . ')' ?></td>
                                                                    <?php } else { ?>
                                                                            <td class="tar sep"><?php echo ($rowdet1_thisyeartotal[$index] >= 0 ) ? number_format($rowdet1_thisyeartotal[$index], 2) : '(' . number_format($rowdet1_thisyeartotal[$index] * -1, 2) . ')' ?></td>
                                                                    <?php } ?>
                                                                    <?php endforeach;?>
                                                                </tr>
                                                                <tr><td colspan="<?php echo count($months)+1; ?>">&nbsp;</td></tr>
                    <?php }
                endforeach;
                ?>
                    <?php if ($accountdetails) { ?>
                    <?php
                    foreach ($monthly[$start] as $key=>$row):

                        //print_r($row);
                        if ($row->acctGroupID == $rowdet->ID) {
                            ?>
                                                                        <?php if ($row->acctCode == '130000000') { ?>
                                                                            
                                                                        <tr>
                                                                            <td style="display:none" ><?php echo $row->ID; ?></td>
                                                                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID; ?>/<?php echo $selyear; ?>/<?php echo $selperiod; ?>" title="<?php echo $this->lang->line('details'); ?>" class="btn btn-mini btn-link edit"><?php echo substr($row->acctCode, 0, 4) . '-' . substr($row->acctCode, 4, 3) . '-' . substr($row->acctCode, 7, 2) . ' [ ' . $row->acctName . ' ]' ?></a></td>
                                                                        
                                                                        <?php foreach($monthly as $index=>$month): $zeroChkr = 0?>
                                                                        
                                                                            <?php $thisyear_amount[$index] = $currentretained[$index]; ?>
                                                                            <?php $zeroChkr += $thisyear_amount[$index]; ?>

                                                                            <?php if ($rowdet->status == 1) { ?>
                                                                                    <td class="tar"><?php echo ($thisyear_amount[$index] <= 0 ) ? number_format($thisyear_amount[$index] * -1, 2) : '(' . number_format($thisyear_amount[$index], 2) . ')' ?></td>
                                                                            <?php } else { ?>
                                                                                    <td class="tar"><?php echo ($thisyear_amount[$index] >= 0 ) ? number_format($thisyear_amount[$index], 2) : '(' . number_format($thisyear_amount[$index] * -1, 2) . ')' ?></td>
                                                                            <?php } ?>
                                                                            <?php $total_thisyear[$index] = $total_thisyear[$index] + $thisyear_amount[$index]; ?>
                                                                            <?php $rowdet_thisyeartotal[$index] = $rowdet_thisyeartotal[$index] + ($monthly[$index][$key]->lastyeardebit - $monthly[$index][$key]->lastyearcredit) + $thisyear_amount[$index]; ?>

                                                                        <?php endforeach; 
                                                                        if($zeroChkr == 0): echo "<td class='dn hideMe'>Display None</td>";
                                                                        else:               echo "<td class='dn'>Display Block</td>";
                                                                        endif;
                                                                        ?>
                                                                        </tr>
                                                                            
                                                                        
                                                                        <?php } elseif ($row->acctCode == '120000000') { ?>
                                                                        
                                                                        <tr>
                                                                            <td style="display:none" ><?php echo $row->ID; ?></td>
                                                                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID; ?>/<?php echo $selyear; ?>/<?php echo $selperiod; ?>" title="<?php echo $this->lang->line('details'); ?>" class="btn btn-mini btn-link edit"><?php echo substr($row->acctCode, 0, 4) . '-' . substr($row->acctCode, 4, 3) . '-' . substr($row->acctCode, 7, 2) . ' [ ' . $row->acctName . ' ]' ?></a></td>
                                                                        
                                                                        <?php foreach($monthly as $index=>$month): $zeroChkr = 0; ?>
                                                                            <?php $lastyear_amount[$index] = $lastRetained; ?>
                                                                            <?php
                                                                                $thisyear_amount[$index] = $currRetain; //$currentretained * -1;                                        
                                                                                $zeroChkr += $thisyear_amount[$index];
                                                                            ?>    

                                                                            <?php if ($rowdet->status == 1) { ?>
                                                                                    <td class="tar"><?php echo ($thisyear_amount[$index] <= 0 ) ? number_format($thisyear_amount[$index] * -1, 2) : '(' . number_format($thisyear_amount[$index], 2) . ')' ?></td>
                                                                            <?php } else { ?>
                                                                                    <td class="tar"><?php echo ($thisyear_amount[$index] >= 0 ) ? number_format($thisyear_amount[$index], 2) : '(' . number_format($thisyear_amount[$index] * -1, 2) . ')' ?></td>
                                                                            <?php } ?>
                                                                            <?php $total_thisyear[$index] = $total_thisyear[$index] + $thisyear_amount[$index]; ?>
                                                                            <?php $rowdet_thisyeartotal[$index] = $rowdet_thisyeartotal[$index] + $thisyear_amount[$index]; //+ ($row->lastyeardebit-$row->lastyearcredit)+$thisyear_amount; ?>
                                                                        <?php endforeach; 
                                                                        if($zeroChkr == 0): echo "<td class='dn hideMe'>Display None</td>";
                                                                        else:               echo "<td class='dn'>Display Block</td>";
                                                                        endif;

                                                                        ?>
                                                                        </tr>
                                                                            
                                                                        <?php } ?>
                                                                    <?php if ($row->lastyeardebit == 0 && $row->lastyearcredit == 0 && $row->currentyeardebit == 0 && $row->currentyearcredit == 0) {
                                                                        
                                                                    } elseif ($row->acctCode != '130000000' && $row->acctCode != '120000000') {
                                                                        ?>
                                                                        
                                                                        <tr>
                                                                            <td style="display:none" ><?php echo $row->ID; ?></td>
                                                                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID; ?>/<?php echo $selyear; ?>/<?php echo $selperiod; ?>" title="<?php echo $this->lang->line('details'); ?>" class="btn btn-mini btn-link edit"><?php echo substr($row->acctCode, 0, 4) . '-' . substr($row->acctCode, 4, 3) . '-' . substr($row->acctCode, 7, 2) . ' [ ' . $row->acctName . ' ]' ?></td>
                                                                            
                                                                            <?php 
                                                                            $zeroChkr = 0;
                                                                            foreach($monthly as $index=>$month): ?>

                                                                                <?php $tyear_amount[$index] = ($monthly[$index][$key]->lastyeardebit - $monthly[$index][$key]->lastyearcredit) + ($monthly[$index][$key]->currentyeardebit - $monthly[$index][$key]->currentyearcredit); ?>
                                                                                <?php $zeroChkr += $tyear_amount[$index]; ?>

                                                                                <?php if ($rowdet->status == 1) { ?>
                                                                                    <td class="tar"><?php echo ($tyear_amount[$index] <= 0 ) ? number_format($tyear_amount[$index] * -1, 2) : '(' . number_format($tyear_amount[$index], 2) . ')' ?></td>
                                                                                <?php } else { ?>
                                                                                    <td class="tar"><?php echo ($tyear_amount[$index] >= 0 ) ? number_format($tyear_amount[$index], 2) : '(' . number_format($tyear_amount[$index] * -1, 2) . ')' ?></td>
                                                                                <?php } ?>
                                                                                
                                                                                <?php $total_thisyear[$index] = $total_thisyear[$index] + ($monthly[$index][$key]->lastyeardebit - $monthly[$index][$key]->lastyearcredit) + ($monthly[$index][$key]->currentyeardebit - $monthly[$index][$key]->currentyearcredit); ?>
                                                                                <?php $rowdet_thisyeartotal[$index] = $rowdet_thisyeartotal[$index] + ($monthly[$index][$key]->lastyeardebit - $monthly[$index][$key]->lastyearcredit) + ($monthly[$index][$key]->currentyeardebit - $monthly[$index][$key]->currentyearcredit); ?>
                                                                                <?php
                                                                                if($zeroChkr == 0): echo "<td class='dn hideMe'>Display None</td>";
                                                                                else:               echo "<td class='dn'>Display Block</td>";
                                                                                endif;
                                                                                ?>

                                                                            <?php endforeach;?>
                                                                        </tr>
                                
                                                                    <?php } ?>
                                                                <?php }
                                                            endforeach;
                                                            ?>
                                                        <?php } ?>        
                                                        <tr>
                                                        <?php if ($rowdet->ID == '39') { ?>
                                                                <td>&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet->acctGroupName) ?></strong></td>
                                                        <?php } else { ?>
                                                                <td>&nbsp;&nbsp;&nbsp;<?php echo $this->lang->line('subtotal') ?> <?php echo $this->lang->line($rowdet->acctGroupName) ?> </td>
                                                        <?php } ?>

                                                        <?php foreach($monthly as $index=>$month): ?>
                                                            <?php if ($rowdet->status == 1) { ?>
                                                                <td class="tar sep"><?php echo ($rowdet_thisyeartotal[$index] <= 0 ) ? number_format($rowdet_thisyeartotal[$index] * -1, 2) : '(' . number_format($rowdet_thisyeartotal[$index], 2) . ')' ?></td>
                                                            <?php } else { ?>
                                                                <td class="tar sep"><?php echo ($rowdet_thisyeartotal[$index] >= 0 ) ? number_format($rowdet_thisyeartotal[$index], 2) : '(' . number_format($rowdet_thisyeartotal[$index] * -1, 2) . ')' ?></td>
                                                            <?php } ?>
                                                        <?php endforeach;?>
                                                        </tr>
                                                        <tr><td colspan="<?php echo count($months)+1; ?>">&nbsp;</td></tr>
                                                        <?php }
                                                    endforeach;
                                                    ?>
                                                <?php foreach ($monthly[$start] as $key => $row):
                                                    if ($row->acctGroupID == $datatbl->ID) {
                                                        ?>
                                                            
                                                        <tr>
                                                            <td style="display:none" ><?php echo $row->ID; ?></td>
                                                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID; ?>/<?php echo $selyear; ?>/<?php echo $selperiod; ?>" title="<?php echo $this->lang->line('details'); ?>" class="btn btn-mini btn-link edit"><?php echo substr($row->acctCode, 0, 4) . '-' . substr($row->acctCode, 4, 3) . '-' . substr($row->acctCode, 7, 2) . ' [ ' . $row->acctName . ' ]' ?></td>
                                                            <?php foreach($monthly as $index=>$month): 

                                                                $zeroChkr = 0;
                                                            ?>

                                                                <?php if ($row->acctCode == '130000000') { ?>
                                                                    <?php $thisyear_amount[$index] = $currentretained[$index] * -1; ?>
                                                                <?php } else { ?>
                                                                    <?php $thisyear_amount[$index] = ($monthly[$index][$key]->lastyeardebit - $monthly[$index][$key]->lastyearcredit) + ($monthly[$index][$key]->currentyeardebit - $monthly[$index][$key]->currentyearcredit) ?>
                                                                <?php
                                                                }
                                                                $zeroChkr += $thisyear_amount[$index];
                                                                ?>


                                                                <?php if ($datatbl->status == 1) { ?>
                                                                    <td class="tar"><?php echo ($thisyear_amount[$index] <= 0 ) ? number_format($thisyear_amount[$index] * -1, 2) : '(' . number_format($thisyear_amount[$index], 2) . ')' ?></td>
                                                                <?php } else { ?>
                                                                    <td class="tar"><?php echo ($thisyear_amount[$index] >= 0 ) ? number_format($thisyear_amount[$index], 2) : '(' . number_format($thisyear_amount[$index] * -1, 2) . ')' ?></td>
                                                                <?php } ?>
                                                                                                        </tr>
                                                                <?php $total_thisyear[$index] = $total_thisyear[$index] + $thisyear_amount[$index]; ?>
                                                            <?php endforeach;
                                                            if($zeroChkr == 0): echo "<td class='dn hideMe'>Display None</td>";
                                                            else:               echo "<td class='dn'>Display Block</td>";
                                                            endif;

                                                            ?>
                                                        <?php }
                                                    endforeach;
                                                    ?>
                                                <tr>
                                                    <td><h4><?php echo $this->lang->line('total') ?> <?php echo $this->lang->line($datatbl->acctGroupName) ?> </h4></td>
                                                <?php foreach($monthly as $index=>$month): ?>
                                                    <?php if ($datatbl->status == 1) { ?>
                                                            <td class="tar tots"><?php echo ($total_thisyear[$index] <= 0 ) ? number_format($total_thisyear[$index] * -1, 2) : '(' . number_format($total_thisyear[$index], 2) . ')' ?></td>
                                                    <?php } else { ?>
                                                            <td class="tar tots"><?php echo ($total_thisyear[$index] >= 0 ) ? number_format($total_thisyear[$index], 2) : '(' . number_format($total_thisyear[$index] * -1, 2) . ')' ?></td>
                                                    <?php } ?>
                                                <?php endforeach;?>                                                
                                                </tr>
                                                <tr><td colspan="<?php echo count($months)+1; ?>">&nbsp;</td></tr>
    <?php endforeach;
} ?>
                                    </tbody>
                                </table>
                            </div><!-- content -->
                        </div><!-- block -->
                    </div><!-- span12 -->
                </div><!-- row-fluid -->  
            </div><!-- wrap -->
        </div><!-- content -->
        <div class="dialog" id="row_edit" style="display: none;" title="<?php echo $this->lang->line('edit'); ?> ?">
            <p><?php echo $this->lang->line('message1'); ?></p>
        </div>
    </div>
</div>  

<script type="text/javascript">
    $(document).ready(function(){
        $('.hideMe').parents('tr').css('display','none');
    });
</script>