<style type="text/css">
    td a{
        padding: 0 !important;
    }
</style>

<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 $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                <li><a href="<?php echo base_url()?>generalLedger/home"><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                <li class="active"><?php echo $this->lang->line('title4') ?></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\pnl\pnl-header.php'; ?>
					<div class="footer">
            			<div class="side fr">
                			<div class="btn-group">
                           <?php 
							$data = array(
									'name'=>'generatereport', 
									'class'=>'btn-form btn-warning-form');
									$js="onClick='changeList()'";
							echo form_button($data,$this->lang->line('generatereport'),$js);
							?>
                    		</div>
                		</div>
            		</div>  
            	</div>

    <div class="row-fluid">
        <div class="span12">
            <div class="block">            
                <div class="head">
                    <h2><?php //echo $this->lang->line('title') ?></h2>
                    <ul class="buttons">
                        <li><a href="#" class="block_loading bubble-chart">Bubble</span></a></li>
                        <li><a href="#" class="block_loading bar-chart">Bar</span></a></li>
                        <li><a href="#" class="block_loading area-chart">AreaChart</span></a></li>
                        <li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
                    </ul>
                </div><!-- head -->
                <div class="content">
                    <!-- <div id="curve_chart" style="width: 900px; height: 500px"></div> -->
                    <div class="row-fluid scRow">
                        <div class="scCol span12">
                            <div id="chart_div"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

		<div class="row-fluid">
			<div class="span12">
            	<div class="block">
                	<div class="head">
                    	<h2><?php //echo $this->lang->line('title') ?></h2>
                    <ul class="buttons">
                        <li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
                        <li><a href="#" class="block_remove"><span class="i-cancel-2"></span></a></li>
                    </ul>
                    <div class="side fr">
                        <button class="btn-form btn-success-form" onClick="do_print_Monthly()"><?php echo $this->lang->line('print') ?></button>
                    </div>
                  </div><!-- head -->                  
            	<div class="content np">
            	<table cellpadding="0" cellspacing="0" width="100%" id="test" class="editable">
                	<thead>
                    <tr>
            			<th style="display:none"></th>
                        <th align="left">&nbsp;&nbsp;<?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"></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;

	/* summary of looping
		//select * from _ref_acct_group where acctTypeID in (3,4) and parentID = 0 order by acctTypeID, parentID, orderNo
		foreach($accountGroup as $datatbl):
			//select sum(amount) as dr or cr from comp_acct_det 
			//select sum(amount) as dr or cr from comp_acct_det 
			foreach($accountdetails as $row):
				if($row->acctGroupID == $datatbl->ID)	
			//select * from _ref_acct_group where acctTypeID in (3,4) and parentID <> 0 order by acctTypeID, parentID, orderNo
			foreach($groupdetails as $rowdet):
				if($rowdet->parentID == $datatbl->ID){
				foreach($accountdetails as $row):
						if($row->acctGroupID == $rowdet->ID)
				foreach($groupdetails as $rowdet1): 
					if($rowdet1->parentID == $rowdet->ID){
					foreach($groupdetails as $rowdet2): 
						if($rowdet2->parentID == $rowdet1->ID){
						foreach($groupdetails as $rowdet3): 
							if($rowdet3->parentID == $rowdet2->ID){
							foreach($accountdetails as $row2):
								if($row2->acctGroupID == $rowdet3->ID){?>
						foreach($accountdetails as $row2):
							if($row2->acctGroupID == $rowdet2->ID){
				foreach($accountdetails as $row2):
					if($row2->acctGroupID == $rowdet1->ID){

	*/
	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="tar"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID;?>/<?php echo $selyear;?>/<?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='dn hideMe'>Display None</td>";
                    else:               echo "<td class='dn'>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="tar"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID;?>/<?php echo $selyear;?>/<?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="tar"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID;?>/<?php echo $selyear;?>/<?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="tar"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row->ID;?>/<?php echo $selyear;?>/<?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='dn hideMe'>Display None</td>";
                      else:               echo "<td class='dn'>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="tar"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $selyear;?>/<?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="tar"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $selyear;?>/<?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='dn hideMe'>Display None</td>";
                  else:               echo "<td class='dn'>Display Block</td>";
                  endif;
              ?>  						
                            </tr>
             	
						<?php  		} ?>
                	<?php   		  }	 ?>
				<?php   		  endforeach;?>
            						<tr>
                						<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="tar"><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="tar"><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="tar"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $selyear;?>/<?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='dn hideMe'>Display None</td>";
                          else:               echo "<td class='dn'>Display Block</td>";
                          endif;
                          ?>
                							</tr>
						<?php  		} ?>
                	<?php   		  }	 ?>
				<?php   		  endforeach;?>
            						<tr>
                						<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="tar"><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="tar"><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="tar"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $selyear;?>/<?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="tar"><a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $selyear;?>/<?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='dn hideMe'>Display None</td>";
                    else:               echo "<td class='dn'>Display Block</td>";
                    endif;
                ?>
        						</tr>
             	
						<?php  	} ?>
                	<?php   	}	 ?>
				<?php 	endforeach;?>
            			  <tr>
                			<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="tar"><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="tar"><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;?>
            			  <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="tar"><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="tar"><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="tar"><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>
                			<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="tar"><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="tar"><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>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

<script type="text/javascript">
    $(document).ready(function(){
        
        var data = google.visualization.arrayToDataTable([
            ["Month",
          <?php foreach($dataGraph as $key=>$v): ?>
           '<?php echo $key ?>',
          <?php endforeach; ?>
              "Total Earning"
            ],
          <?php $i = 0; foreach($months as $key=>$month): ?>
            [
            "<?php echo $this->lang->line('monthSrt'.date('n',strtotime($month->startDate)))." ".$selyear; ?>",  
            <?php foreach($dataGraph as $v): ?>
              <?php echo $v[$month->period]; ?>,
            <?php endforeach; 
              echo $datatbl_total[$month->period]*-1;
            ?>
            ],
          <?php endforeach; ?>
        ]);
        $('.bubble-chart').on('click',function(){

            data = google.visualization.arrayToDataTable([
                ["ID","Income","Expenses","Month","Total Earning"],
              <?php $i = 0; foreach($months as $key=>$month): ?>
                [
                  "<?php echo $this->lang->line('monthSrt'.date('n',strtotime($month->startDate)))." ".$selyear; ?>",  
                  <?php echo $dataGraph['revenue'][$month->period]+$dataGraph['operatingincome'][$month->period]+$dataGraph['financeincome'][$month->period]+$dataGraph['othercomprehensiveincome'][$month->period]; ?>,
                  <?php echo $dataGraph['COGS'][$month->period]+$dataGraph['operatingexpenses'][$month->period]+$dataGraph['financeCost'][$month->period]+$dataGraph['taxation'][$month->period]; ?>,
                  "<?php echo $this->lang->line('monthSrt'.date('n',strtotime($month->startDate)))." ".$selyear; ?>",  
                <?php  echo $datatbl_total[$month->period]*-1;
                ?>
                ],
              <?php endforeach; ?>
            ]);

            var options = {
                title : '<?php echo $this->lang->line("title4") ?>',
                vAxis: {title: 'Expenses'},
                hAxis: {title: 'Income'},
                //colorAxis: {colors: ['yellow', 'red']},
                height: 500
            };
            var chart = new google.visualization.BubbleChart(document.getElementById('chart_div'));
            chart.draw(data, options);
        });
        $('.bar-chart').on('click',function(){
            drawVisualization();
        });
        $('.area-chart').on('click',function(){

            data = google.visualization.arrayToDataTable([
                ["Month","Income","Expenses","Total Earning"],
              <?php $i = 0; foreach($months as $key=>$month): ?>
                [
                "<?php echo $this->lang->line('monthSrt'.date('n',strtotime($month->startDate)))." ".$selyear; ?>",  
                  <?php echo $dataGraph['revenue'][$month->period]+$dataGraph['operatingincome'][$month->period]+$dataGraph['financeincome'][$month->period]+$dataGraph['othercomprehensiveincome'][$month->period]; ?>,
                  <?php echo $dataGraph['COGS'][$month->period]+$dataGraph['operatingexpenses'][$month->period]+$dataGraph['financeCost'][$month->period]+$dataGraph['taxation'][$month->period]; ?>,
                <?php  echo $datatbl_total[$month->period]*-1;
                ?>
                ],
              <?php endforeach; ?>
            ]);

            var options = {
                title : '<?php echo $this->lang->line("title4") ?>',
                vAxis: {title: 'RM'},
                hAxis: {title: 'Monthly'},
                height: 500
            };
            var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
            chart.draw(data, options);
        });
    });

    //google.load("visualization", "1", {packages:["corechart"]});
      google.load('visualization', '1.1', {packages: ["corechart"]});
      google.setOnLoadCallback(drawVisualization);

      function drawVisualization() {
          // Some raw data (not necessarily accurate)
          data = google.visualization.arrayToDataTable([
                ["Month","Income","Expenses","Total Earning"],
              <?php $i = 0; foreach($months as $key=>$month): ?>
                [
                "<?php echo $this->lang->line('monthSrt'.date('n',strtotime($month->startDate)))." ".$selyear; ?>",  
                  <?php echo $dataGraph['revenue'][$month->period]+$dataGraph['operatingincome'][$month->period]+$dataGraph['financeincome'][$month->period]+$dataGraph['othercomprehensiveincome'][$month->period]; ?>,
                  <?php echo $dataGraph['COGS'][$month->period]+$dataGraph['operatingexpenses'][$month->period]+$dataGraph['financeCost'][$month->period]+$dataGraph['taxation'][$month->period]; ?>,
                <?php  echo $datatbl_total[$month->period]*-1;
                ?>
                ],
              <?php endforeach; ?>
            ]);

        var options = {
          title : '<?php echo $this->lang->line("title4") ?>',
          vAxis: {title: 'RM'},
          hAxis: {title: 'Monthly'},
          seriesType: 'bars',
          series: {2: {type: 'line'}},
          height: 500
        };

        var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }

     
    $(window).resize(function(){
      drawVisualization();
    });

</script>