<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header printHide">
    <h1>
      <?php echo $this->lang->line('title'); ?>
      <small><?php echo $this->lang->line('module'); ?></small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i><?php echo $this->lang->line('home'); ?></a></li>
      <li><a href="#"><?php echo $this->lang->line('module'); ?></a></li>
      <li class="active"><?php echo $this->lang->line('title'); ?></li>
    </ol>
  </section>
  <section class="container-fluid printShow">   
    <?php require APPPATH.'views/gl/pnl/pnl-print-hdr.php'; ?>
  </section>

  <section class="content container-fluid printHide bottom-padding-0 no-min-height">
    <div class="row">
      <?php require APPPATH.'views/gl/pnl/pnl-header.php'; ?>
    </div>        
  </section>   

		<div class="content pnlContent">
			<div class="box box-primary">
            	<div class="box-header with-border no-print">
                <h3 class="box-title pull-right">
                  <button type="button" id="printDetail" class="btn btn-primary btn-sm printPreview printHide no-print" onclick="printPreview();">
                    <span class="glyphicon glyphicon glyphicon-print"></span> Print Preview
                  </button>
                  <button type="button" id="printDetail" class="btn btn-primary btn-sm printPreview printShow no-print" onclick="goNormal();">
                    <span class="glyphicon glyphicon-remove"></span> Cancel
                  </button>
                  <button type="button" id="printDetail" class="btn btn-primary btn-sm printPreview printShow no-print" onclick="window.print();">
                    <span class="glyphicon glyphicon glyphicon-print"></span> Print
                  </button>
                </h3>
              </div>
              <div class="block">                  
            	<div class="content np">
            	<table cellpadding="0" cellspacing="0" width="100%" id="test" class="editable  table-condensed">
                	<thead>
                    <tr>
            			<th style="display:none"></th>
                      <th align="left">&nbsp;&nbsp;<?php echo $this->lang->line('description') ?></th>
                      <th class="text-right"><?php echo $this->lang->line('thismonth'); ?>&nbsp;&nbsp;</th>
                      <th class="text-right"><?php echo $this->lang->line('thisyear'); ?>&nbsp;&nbsp;</th>
                      <th class="hidden"></th>
            		</tr>
        			</thead>
       				 <tbody>
	<?php 
	$bil = 0;
  foreach($monthly as $key => $month):
      $datatbl_total[$key] = 0;
      $totalamount[$key] = 0;
  endforeach;
  foreach($groupdetails as $v):
      foreach($monthly as $per => $month):
          $dataGraph[$v->acctGroupName][$per] = 0;
      endforeach;
  endforeach;

	
	if($accountGroup && (!empty($monthly))){
		foreach($accountGroup as $datatbl):
			$bil++?>
 			<?php if ($datatbl->title == 1) {?>
            		<tr>
                		<td colspan="<?php echo count($months)+1; ?>">&nbsp;<strong><?php echo $this->lang->line($datatbl->acctGroupName); ?></strong></td>
                	</tr>
            <?php }?>
      <?php foreach($monthly[$startPer] as $key=>$row):
				if($row->acctGroupID == $datatbl->ID){?>
      	<?php 
					if(true) { ?>
                <tr>
                    <td style="display:none" ><?php echo $row->ID; ?></td>
                    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?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 $per => $month):
                        $totalamount[$per] =  ($month[$key]->currentyeardebit+$month[$key]->openingBalanceDr) - ($month[$key]->currentyearcredit+$month[$key]->openingBalanceCr);  
                        $zeroChkr += $totalamount[$per];
                ?>
            			
                			<td class="text-right"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID;?>/<?php echo $per;?>" title="<?php echo $this->lang->line('details');?>" ><?php echo ($row->acctTypeID != $datatbl->acctTypeID )?number_format($totalamount,2):number_format($totalamount,2)?>&nbsp;&nbsp;</a></td>

                <?php 
                        $datatbl_total[$per] = $datatbl_total[$per] + $totalamount[$per];
                    endforeach; 
                    if($zeroChkr == 0): echo "<td class='hidden hideMe'>Display None</td>";
                    else:               echo "<td class='hidden'>Display Block</td>";
                    endif;
                ?>

                </tr>
         		<?php
					
				?>
			<?php   } ?>
			<?php } ?>
		<?php endforeach;?>
      	<?php if($groupdetails){ 
				foreach($groupdetails as $rowdet):
            foreach($monthly as $per => $month):
							$rowdet_credit[$per] = 0;
            endforeach;
					if($rowdet->parentID == $datatbl->ID){
						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($accountdetails as $key=>$row):

							if($row->acctGroupID == $rowdet->ID){
								?>
      						<?php
								if(true ){ ?>
            						<tr>
			           					<td style="display:none" ><?php echo $row->ID; ?></td>
                						<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?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 $per => $month):
                            $totalamount[$per] = $month[$key]->currentyeardebit - $month[$key]->currentyearcredit; 
                            $zeroChkr += $totalamount[$per];
                      ?>
                        <?php if($rowdet->status == 1){?>
        								    <td class="text-right"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID;?>/<?php echo $per;?>" title="<?php echo $this->lang->line('details');?>" ><?php echo ($totalamount[$per] <= 0  )?number_format($totalamount[$per] * -1,2):'('.number_format($totalamount[$per],2).')'?>&nbsp;&nbsp;</a></td>
        								<?php }elseif($rowdet->ID == 32){?>
        								    <td class="text-right"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID;?>/<?php echo $per;?>" title="<?php echo $this->lang->line('details');?>" ><?php echo ($totalamount[$per] > 0)?'('.number_format($totalamount[$per],2).")":number_format($totalamount[$per]*-1,2)?>&nbsp;&nbsp;</a></td>
        								<?php }else{?>
        								    <td class="text-right"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID;?>/<?php echo $per;?>" title="<?php echo $this->lang->line('details');?>" ><?php echo ($totalamount[$per] >= 0 )?number_format($totalamount[$per],2):'('.number_format($totalamount[$per] * -1,2).')'?>&nbsp;&nbsp;</a></td>
        								<?php }?>
                      <?php 

                          $rowdet_credit[$per] = $rowdet_credit[$per] + $totalamount[$per];

                          $datatbl_total[$per] = $datatbl_total[$per] + $totalamount[$per];

                      endforeach; 
                      if($zeroChkr == 0): echo "<td class='hidden hideMe'>Display None</td>";
                      else:               echo "<td class='hidden'>Display Block</td>";
                      endif;
                      ?>

                				</tr>
						<?php  } ?>
					<?php } ?>
				<?php endforeach;?>
				<?php 
            

            foreach($groupdetails as $rowdet1): 
              foreach($monthly as $per => $month):
                $rowdet1_credit[$per] = 0;
              endforeach;
					?>
				<?php	if($rowdet1->parentID == $rowdet->ID){
							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   foreach($groupdetails as $rowdet2): 
                    foreach($monthly as $per => $month):
                        $rowdet2_credit[$per] = 0;
                    endforeach;

					?>
				<?php		if($rowdet2->parentID == $rowdet1->ID){
								if ($rowdet2->title == 1) {?>
            						<tr>
                						<td colspan="<?php echo count($months)+1; ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet2->acctGroupName)?></strong></td>
                					</tr>
                	<?php 		} ?>
 				<?php   foreach($groupdetails as $rowdet3): 
                    foreach($monthly as $per => $month):
                      $rowdet3_credit[$per] = 0;
                    endforeach;
						if($rowdet3->parentID == $rowdet2->ID){
								if ($rowdet3->title == 1) { 
                      
                  ?>
            						<tr>
                						<td colspan="<?php echo count($months)+1; ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet3->acctGroupName)?></strong></td>
                					</tr>
                	<?php 		} ?>
     				<?php 	  foreach($accountdetails as $key2=>$row2):
									if($row2->acctGroupID == $rowdet3->ID){?>
      	<?php 
										if(true){ ?>
            								<tr>
           										<td style="display:none" ><?php echo $row2->ID; ?></td>
                								<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo substr($row2->acctCode,0, 4).'-'.substr($row2->acctCode,4, 3).'-'.substr($row2->acctCode,7, 2).' [ '.$row2->acctName.' ]'?></td>
                            
                            <?php
                                $zeroChkr = 0;
                                foreach($monthly as $per => $month):
                                    $totalamount[$per] =  ($month[$key2]->currentyeardebit+$month[$key2]->openingBalanceDr) - ($month[$key2]->currentyearcredit+$month[$key2]->openingBalanceCr);  
                                    $zeroChkr += $totalamount[$per];
                            ?>    
                                <?php if($rowdet3->status == 1){?>
                                    <td class="text-right"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $per;?>" title="<?php echo $this->lang->line('details');?>" ><?php echo ($totalamount[$per] <= 0)?number_format($totalamount[$per] * -1,2):'('.number_format($totalamount[$per],2).')'?>&nbsp;&nbsp;</a></td>
                								<?php }else{?>
	                								<td class="text-right"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $per;?>" title="<?php echo $this->lang->line('details');?>" ><?php echo ($totalamount[$per] >= 0)?number_format($totalamount[$per],2):'('.number_format($totalamount[$per] * -1,2).')'?>&nbsp;&nbsp;</a></td>
                								<?php }?>
              
              <?php
                      $rowdet_credit[$per] = $rowdet_credit[$per] + $totalamount[$per];
                      $rowdet1_credit[$per] = $rowdet1_credit[$per] + $totalamount[$per];
                      $rowdet2_credit[$per] = $rowdet2_credit[$per] + $totalamount[$per];
                      $rowdet3_credit[$per] = $rowdet3_credit[$per] + $totalamount[$per];

                      $datatbl_total[$per] = $datatbl_total[$per] + $totalamount[$per];
                  endforeach;
                  if($zeroChkr == 0): echo "<td class='hidden hideMe'>Display None</td>";
                  else:               echo "<td class='hidden'>Display Block</td>";
                  endif;
              ?>  						
                            </tr>
             	
						<?php  		} ?>
                	<?php   		  }	 ?>
				<?php   		  endforeach;?>
            						<tr class="subtotal">
                						<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
											<?php echo $this->lang->line($rowdet3->acctGroupName)?> <?php echo $this->lang->line('subtotal') ?></strong></td>
                      <?php
                          foreach($monthly as $per => $month):
                              
                      ?>  
                            <?php if($rowdet3->status == 1){?>
                						<td class="text-right"><strong><?php echo ($rowdet3_credit[$per] < 0 )?number_format($rowdet3_credit[$per] * -1,2):number_format($rowdet3_credit[$per],2) ?>&nbsp;&nbsp;</strong></td>
                 						<?php 
                              $dataGraph[$rowdet3->acctGroupName][$per] = $rowdet3_credit[$per]*-1;
                            }else{?>
                						<td class="text-right"><strong><?php echo ($rowdet3_credit[$per] >= 0  )?number_format($rowdet3_credit[$per],2):'('.number_format($rowdet3_credit[$per] * -1,2).')' ?>&nbsp;&nbsp;</strong></td>
                						<?php 
                              $dataGraph[$rowdet3->acctGroupName][$per] = $rowdet3_credit[$per]*-1;
                            }?>
                      <?php endforeach; ?>
                					</tr>
                	<?php 		} ?>
				<?php   		  endforeach;?>
     				<?php 	  foreach($accountdetails as $key2=>$row2):
									if($row2->acctGroupID == $rowdet2->ID){?>
      	<?php 
										if(true){ ?>
            								<tr>
           										<td style="display:none" ><?php echo $row2->ID; ?></td>
                								<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo substr($row2->acctCode,0, 4).'-'.substr($row2->acctCode,4, 3).'-'.substr($row2->acctCode,7, 2).' [ '.$row2->acctName.' ]'?></td>

                      <?php
                          $zeroChkr = 0;
                          foreach($monthly as $per => $month):
                              $totalamount[$per] =  ($month[$key2]->currentyeardebit+$month[$key2]->openingBalanceDr) - ($month[$key2]->currentyearcredit+$month[$key2]->openingBalanceCr); 
                              $zeroChkr += $totalamount[$per];
                      ?>

                								<td class="text-right"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $per;?>" title="<?php echo $this->lang->line('details');?>" >
                								<?php if($row2->acctGroupID == '36'): ?>
                									<?php  echo ($totalamount[$per]* -1 < 0 )?"(".number_format($totalamount[$per],2).")":number_format($totalamount[$per]* -1,2)?>
                								<?php elseif($row2->acctGroupID == '44'): ?>
                									<?php  echo ($totalamount[$per] < 0 )?"(".number_format($totalamount[$per]* -1,2).")":number_format($totalamount[$per],2)?>
                								<?php else: ?>
                									<?php echo ($totalamount[$per] < 0 )?number_format($totalamount[$per] * -1,2):number_format($totalamount[$per],2)?>
                								<?php endif; ?>
                								&nbsp;&nbsp;</a></td>

                      <?php 
                              $rowdet_credit[$per] = $rowdet_credit[$per] + $totalamount[$per];
                              $rowdet1_credit[$per] = $rowdet1_credit[$per] + $totalamount[$per];
                              $rowdet2_credit[$per] = $rowdet2_credit[$per] + $totalamount[$per];
                              

                              $datatbl_total[$per] = $datatbl_total[$per] + $totalamount[$per];
                          endforeach;
                          if($zeroChkr == 0): echo "<td class='hidden hideMe'>Display None</td>";
                          else:               echo "<td class='hidden'>Display Block</td>";
                          endif;
                          ?>
                							</tr>
						<?php  		} ?>
                	<?php   		  }	 ?>
				<?php   		  endforeach;?>
            						<tr class="subtotal">
                						<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
											<?php echo $this->lang->line($rowdet2->acctGroupName)?> <?php echo $this->lang->line('subtotal') ?></strong></td>
                      <?php
                          foreach($monthly as $per => $month):
                      ?>
                            <?php if($rowdet2->status == 1){?>
                						<td class="text-right"><strong><?php echo ($rowdet2_credit[$per] > 0 )?'('.number_format($rowdet2_credit[$per],2).')':number_format($rowdet2_credit[$per]  * -1,2) ?>&nbsp;&nbsp;</strong></td>
                 						<?php 
                                $dataGraph[$rowdet2->acctGroupName][$per] += $rowdet2_credit[$per]*-1;
                            }else{?>
                						<td class="text-right"><strong><?php echo ($rowdet2_credit[$per] < 0 )?number_format($rowdet2_credit[$per],2):number_format($rowdet2_credit[$per],2) ?>&nbsp;&nbsp;</strong></td>
                						<?php 
                                $dataGraph[$rowdet2->acctGroupName][$per] += $rowdet2_credit[$per]*-1;
                            }?>
                      <?php endforeach; ?>
                					</tr>
                	<?php   } ?>
				<?php   endforeach;?>
      			<?php   foreach($accountdetails as $key2=>$row2):
							if($row2->acctGroupID == $rowdet1->ID){?>
      	<?php 
								if(true){ ?>
    							<tr>
   									<td style="display:none" ><?php echo $row2->ID; ?></td>
        							<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo substr($row2->acctCode,0, 4).'-'.substr($row2->acctCode,4, 3).'-'.substr($row2->acctCode,7, 2).' [ '.$row2->acctName.' ]'?></td>
                  <?php
                      $zeroChkr = 0;
                      foreach($monthly as $per => $month):
                          $totalamount[$per] =  ($month[$key2]->currentyeardebit+$month[$key2]->openingBalanceDr) - ($month[$key2]->currentyearcredit+$month[$key2]->openingBalanceCr); 
                          $zeroChkr += $totalamount[$per];
                  ?>
                      <?php if($rowdet1->status == 1){?>
        								<td class="text-right"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $per;?>" title="<?php echo $this->lang->line('details');?>" class="btn btn-link"><?php echo ($totalamount[$per] < 0 )?number_format($totalamount[$per] * -1,2):number_format($totalamount[$per],2)?>&nbsp;&nbsp;</a></td>
         							<?php }else{?>
        								<td class="text-right"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $per;?>" title="<?php echo $this->lang->line('details');?>" class="btn btn-link"><?php echo ($totalamount[$per] > 0 )?'('.number_format($totalamount[$per],2).')':number_format($totalamount[$per] * -1,2)?>&nbsp;&nbsp;</a></td>
        							<?php }?>
                  <?php
                          $rowdet_credit[$per] = $rowdet_credit[$per] + $totalamount[$per];
                          $rowdet1_credit[$per] = $rowdet1_credit[$per] + $totalamount[$per];


                          $datatbl_total[$per] = $datatbl_total[$per] + $totalamount[$per];
                    endforeach;
                    if($zeroChkr == 0): echo "<td class='hidden hideMe'>Display None</td>";
                    else:               echo "<td class='hidden'>Display Block</td>";
                    endif;
                ?>
        						</tr>
             	
						<?php  	} ?>
                	<?php   	}	 ?>
				<?php 	endforeach;?>
            			  <tr class="subtotal">
                			<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;
								      <?php echo $this->lang->line($rowdet1->acctGroupName)?> <?php echo $this->lang->line('subtotal') ?></strong></td>
                  <?php
                      foreach($monthly as $per => $month):
                  ?>
                        <?php if($rowdet1->status == 1){?>
                					<td class="text-right"><strong><?php echo ($rowdet1_credit[$per] < 0 )?'('.number_format($rowdet1_credit[$per] * -1,2).')':number_format($rowdet1_credit[$per],2)?>&nbsp;&nbsp;</strong></td>
                 				<?php }else{?>
                					<td class="text-right"><strong><?php echo ($rowdet1_credit[$per] > 0 )?'('.number_format($rowdet1_credit[$per],2).')':number_format($rowdet1_credit[$per] * -1,2)?>&nbsp;&nbsp;</strong></td>
                				<?php }?>
                  <?php endforeach; ?>
                		  </tr>
                	<?php } ?>
				<?php endforeach;?>
            			  <?php /*<tr>
                			<td><strong>
								<?php echo $this->lang->line($rowdet->acctGroupName)?> <?php echo $this->lang->line('subtotal') ?></strong></td>
                    <?php
                        foreach($monthly as $per => $month):
                    ?>
                        <?php if($rowdet1->status == 1){?>
                					<td class="text-right"><strong><?php echo ($rowdet_credit[$per] < 0 )?'('.number_format($rowdet_credit[$per],2).')':number_format($rowdet_credit[$per] * -1,2)?>&nbsp;&nbsp;</strong></td>
                 				<?php }elseif($rowdet->ID == 12){?>
                					<td class="text-right"><strong><?php echo ($rowdet_credit[$per] >= 0 )?number_format($rowdet_credit[$per],2):"(".number_format($rowdet_credit[$per] * -1,2).")"?>&nbsp;&nbsp;</strong></td>
                 				<?php }else{?>
                					<td class="text-right"><strong><?php echo ($rowdet_credit[$per] > 0 )?'('.number_format($rowdet_credit[$per],2).')':number_format($rowdet_credit[$per] * -1,2)?>&nbsp;&nbsp;</strong></td>
                				<?php }?>
                    <?php endforeach; ?>

                		  </tr> */ ?>
<!-- row det -->
                <?php } ?>
		<?php  endforeach; ?>
            			  <tr class="finalSubtotal">
                			<td><h4><?php echo $this->lang->line($datatbl->acctGroupName)?> <?php echo $this->lang->line('subtotal') ?></h4></td>
                      <?php
                          foreach($monthly as $per => $month):
                      ?>
                        <?php if($datatbl->status == 1){?>
                					<td class="text-right"><strong><?php echo ($datatbl_total[$per] < 0 )?'('.number_format($datatbl_total[$per],2).')':number_format($datatbl_total[$per] * -1,2)?>&nbsp;&nbsp;</strong></td>
                 				<?php }else{?>
                					<td class="text-right"><strong><?php echo ($datatbl_total[$per] > 0 )?'('.number_format($datatbl_total[$per],2).')':number_format($datatbl_total[$per] * -1,2)?>&nbsp;&nbsp;</strong></td>
                				<?php }?>
                      <?php endforeach; ?>
                		  </tr>
        <?php } ?>
<?php  endforeach; ?>
	<?php } ?>

                     </tbody> 
                     </table>
				</div><!-- content -->
				</div><!-- block -->
			</div><!-- span12 -->
		</div><!-- row-fluid -->	
</div><!-- content --><?php //print_r($months);?>
</div>
<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>  
<script type="text/javascript">
    $(document).ready(function(){
        $('.hideMe').parents('tr').css('display','none');
    });
</script>
