<script type="text/javascript">
$(document).ready(function() {
    /* Build the DataTable with third column using our custom sort functions */
   $('select').select2();
    /*$("table.editable").on("click",".edit",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
		var selyear = <?php echo $selyear;?>;
        $("#row_edit").dialog("open");
    });
    $("#row_edit").dialog({
        autoOpen: false,
        resizable: false,        
        modal: true,
        buttons: {
            "Continue...": function() {
				window.location.href = "<?php echo base_url(); ?>glreports/accountDetailsfc/" + ID + "/<?php echo $selyear;?>";		
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });*/    
}); 
function do_print(){
	var addyear = $('#add_year option:selected').val();
	var addper = $('#add_period option:selected').val();
	window.open("<?php echo base_url() ?>glreports/profitNloss_print/"+addyear+"/"+addper);
}
 
function changeList(){
	var addyear = $('#add_year option:selected').val();
	var addper = $('#add_period option:selected').val();
	var urls = "<?php echo base_url();?>glreports/profitNloss/"+addyear+"/"+addper;
		window.location = urls;
}

function selectYearPeriod(obj){
		var year = obj.value;
//		alert(year);
			
			$.ajax({
  				type: "POST",
	  			dataType: "json",
				url: "<?php echo base_url()?>glreports/get_TrialBalance_year/"+year,
				data: year,
	  			async: false,
  				success: function(content){
					if(content.status == "success") {
					var items = [];
					//items.push('<option>-Please Select-</option>');
					for ( var i = 0; i < content.message.length; i++) {
					items.push('<option value="'+content.message[i].period+'">'
						+ content.message[i].financialPeriodAsat + '</option>');
					}  //end for
					jQuery("#add_period").empty();
					//jQuery("#from_period").empty();
					jQuery("#add_period").append(items.join('</br>'));
					//jQuery("#from_period").append(items.join('</br>'));
					//$("#add_period").select2('val',null);
					//$("#from_period").select2('val',null);
					$("#add_period").select2();
				} else {
					jQuery("#add_period").empty();
					//jQuery("#from_period").empty();
					$("#add_period").select2('val',null);
					//$("#from_period").select2('val',null);
					$("#error").html('<p>'+content.message+'</p>');
				} //end if
			} //end success
				
			}); //end ajax
//	window.location.reload(true); 
}

</script>
<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">
                	<div class="head">
                    	<h2><?php echo $this->lang->line('title3') ?></h2>
                            <div class="side fr">
                    
							</div>
                    </div><!-- head -->
				<div class="content np">
                	<div class="content nb"><!-- Row 4-->
                    	<div class="span2 tar"><?php echo form_label($this->lang->line('year'),'add_year');?></div>
						<div class="span4">
						<?php
							$preselyear = $selyear;
							$options = '';
							$options[] = $this->lang->line('selectyear');
							if(!empty($yrs)){
								foreach($yrs as $row){
									$options[$row['financialYear']] = $row['financialYear'];
								}
							}
							$js='onchange="selectYearPeriod(this)"class="input-medium" id="add_year"';

							echo form_dropdown('add_year', $options, $preselyear, $js);
						?>       
                        </div>
                    	<div class="span2 tar"><?php echo form_label($this->lang->line('to'),'add_period');?></div>
						<div class="span4">
						<?php
							$preselperiod = $selper;
							$options = '';
							$options[] = $this->lang->line('period');
							if($period){
								foreach($period as $row){
									$options[$row->period] = $row->financialPeriodAsat;
								}
							}
							$js='class="input-medium" id="add_period" style="width:75%"';

							echo form_dropdown('add_period', $options, $preselperiod, $js);
						?>       
                        </div>
                 	</div><!-- End Row 4-->
				</div><!-- content -->    
					<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 class="row-fluid">
			<div class="span12">
            	<div class="block">
                	<div class="head">
                    	<h2><?php //echo $this->lang->line('title') ?></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 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>
                        <th class="tar"><?php echo $this->lang->line('thisyear') ?>&nbsp;&nbsp;</th>
                        <!-- th class="tar"><?php echo $this->lang->line('budget') ?>&nbsp;&nbsp;</th>
                        <th class="tar"><?php echo $this->lang->line('variance') ?>&nbsp;&nbsp;</th-->
            		</tr>
        			</thead>
       				 <tbody>
	<?php $bil = 0; 
	$datatbl_total = 0;
	$datatbl_budgettotal = 0;
	/* 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($accountdetails)){
		foreach($accountGroup as $datatbl):
			$bil++?>
 			<?php if ($datatbl->title == 1) {?>
            		<tr>
                		<td colspan="2">&nbsp;<strong><?php echo $this->lang->line($datatbl->acctGroupName) ?></strong></td>
                	</tr>
            <?php }?>
      <?php foreach($accountdetails as $row):
				if($row->acctGroupID == $datatbl->ID){?>
      	<?php 
					if(($row->currentyeardebit != '' && $row->currentyearcredit !='') || ($row->openingBalanceDr != '' || $row->openingBalanceCr !='')) { ?>
                 <?php $totalamount =  ($row->currentyeardebit+$row->openingBalanceDr) - ($row->currentyearcredit+$row->openingBalanceCr);  
                 					if(floatval($totalamount) == 0 ) continue; ?>
                 <?php $varAmount = ($row->acctTypeID == 4)?$row->budgetAmount + $totalamount:$totalamount - $row->budgetAmount?>
            			<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 $selper;?>" 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.' ]'?></a></td>
                			<td class="tar"><?php echo ($row->acctTypeID != $datatbl->acctTypeID )?number_format($totalamount,2):number_format($totalamount,2)?>&nbsp;&nbsp;</td>
                			<!-- td class="tar"><?php echo ($row->budgetAmount == 0 )?'0':number_format($row->budgetAmount,2)?>&nbsp;&nbsp;</td>
                			<td class="tar"><?php echo number_format($varAmount,2)?>&nbsp;&nbsp;</td -->
                		</tr>
             	<?php
						$datatbl_total = $datatbl_total + $totalamount;
						$datatbl_budgettotal = $datatbl_budgettotal + $row->budgetAmount;
							?>
			<?php   } ?>
			<?php } ?>
		<?php endforeach;?>
      	<?php if($groupdetails){ 
				foreach($groupdetails as $rowdet):
							$rowdet_credit = 0;
							$rowdet_budgetcredit = 0;
					if($rowdet->parentID == $datatbl->ID){
						if ($rowdet->title == 1) {?>
            				<tr>
                				<td colspan="2">&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet->acctGroupName)?></strong></td>
                			</tr>
                	<?php } ?>
      				<?php foreach($accountdetails as $row):

							if($row->acctGroupID == $rowdet->ID){
								?>
      						<?php
      							//if($row->currentyeardebit != 0 && $row->currentyearcredit !=0){	// && will never satisfy if one of the value is available
								if($row->currentyeardebit != '' || $row->currentyearcredit != ''){ ?>
                 			<?php   $totalamount = $row->currentyeardebit - $row->currentyearcredit; 
                 					if(floatval($totalamount) == 0 ) continue;
                 			?>
                 			<?php $varAmount = ($row->acctTypeID == 4)?$totalamount + $row->budgetAmount : $totalamount - $row->budgetAmount; ?>
            						<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 $selper;?>" 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.' ]'?></a></td>
                                                <?php if($rowdet->status == 1){?>
                								<td class="tar"><?php echo ($totalamount < 0 )?number_format($totalamount * -1,2):'('.number_format($totalamount,2).')'?>&nbsp;&nbsp;</td>
                								<?php }elseif($rowdet->ID == 32){?>
                								<td class="tar"><?php echo ($totalamount > 0 )?'('.number_format($totalamount,2).")":number_format($totalamount*-1,2)?>&nbsp;&nbsp;</td>
                								<?php }else{?>
	                								<td class="tar"><?php echo ($totalamount > 0 )?number_format($totalamount,2):'('.number_format($totalamount * -1,2).')'?>&nbsp;&nbsp;</td>
                								<?php }?>
                						<!-- td class="tar"><?php echo ($row->budgetAmount == 0 )?'':number_format($row->budgetAmount,2)?>&nbsp;&nbsp;</td>
                						<td class="tar"><?php echo number_format($varAmount,2)?>&nbsp;&nbsp;</td -->
                					</tr>
             	<?php
											$rowdet_credit = $rowdet_credit + $totalamount;
											$rowdet_budgetcredit = $rowdet_budgetcredit + $row->budgetAmount;
											$datatbl_total = $datatbl_total + $totalamount;
											$datatbl_budgettotal = $datatbl_budgettotal + $row->budgetAmount;
							?>
						<?php  } ?>
					<?php } ?>
				<?php endforeach;?>
				<?php foreach($groupdetails as $rowdet1): 
					$rowdet1_credit = 0; 
					$rowdet1_budgetcredit = 0; 
					?>
				<?php	if($rowdet1->parentID == $rowdet->ID){
							if ($rowdet1->title == 1) {?>
            					<tr>
                					<td colspan="2">&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet1->acctGroupName)?></strong></td>
                				</tr>
                	<?php 	} ?>
				<?php   foreach($groupdetails as $rowdet2): 
					$rowdet2_credit = 0; 
					$rowdet2_budgetcredit = 0; 
					?>
				<?php		if($rowdet2->parentID == $rowdet1->ID){
								if ($rowdet2->title == 1) {?>
            						<tr>
                						<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet2->acctGroupName)?></strong></td>
                					</tr>
                	<?php 		} ?>
 				<?php   foreach($groupdetails as $rowdet3): 
					$rowdet3_credit = 0; 
					$rowdet3_budgetcredit = 0; ?>
				<?php		if($rowdet3->parentID == $rowdet2->ID){
								if ($rowdet3->title == 1) {?>
            						<tr>
                						<td colspan="2">&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 $row2):
									if($row2->acctGroupID == $rowdet3->ID){?>
      	<?php 
										if($row2->currentyeardebit != '' || $row2->currentyearcredit !='' || $row2->openingBalanceDr != 0 || $row2->openingBalanceCr !=0){ ?>
                 			<?php   		  $totalamount =  ($row2->currentyeardebit+$row2->openingBalanceDr) - ($row2->currentyearcredit+$row2->openingBalanceCr); 
                 					if(floatval($totalamount) == 0 ) continue;?>
                 			<?php $varAmount = ($row2->acctTypeID == 4)?$totalamount + $row2->budgetAmount :$totalamount - $row2->budgetAmount ?>
            								<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;<a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $selyear;?>/<?php echo $selper;?>" title="<?php echo $this->lang->line('details');?>" class="btn btn-mini btn-link edit"><?php echo substr($row2->acctCode,0, 4).'-'.substr($row2->acctCode,4, 3).'-'.substr($row2->acctCode,7, 2).' [ '.$row2->acctName.' ]'?></a></td>
                                                <?php if($rowdet3->status == 1){?>
                									<td class="tar"><?php echo ($totalamount < 0 )?number_format($totalamount * -1,2):'('.number_format($totalamount,2).')'?>&nbsp;&nbsp;</td>
                								<?php }else{?>
	                								<td class="tar"><?php echo ($totalamount > 0 )?number_format($totalamount,2):'('.number_format($totalamount * -1,2).')'?>&nbsp;&nbsp;</td>
                								<?php }?>
                                                <!--  td class="tar"><?php echo ($row2->budgetAmount == 0 )?'':number_format($row2->budgetAmount,2)?>&nbsp;&nbsp;</td>
                								<td class="tar"><?php echo number_format( $varAmount,2)?>&nbsp;&nbsp;</td -->
                							</tr>
             	<?php
											$rowdet_credit = $rowdet_credit + $totalamount;
											$rowdet1_credit = $rowdet1_credit + $totalamount;
											$rowdet2_credit = $rowdet2_credit + $totalamount;
											$rowdet3_credit = $rowdet3_credit + $totalamount;
											$rowdet_budgetcredit = $rowdet_budgetcredit + $row2->budgetAmount;
											$rowdet1_budgetcredit = $rowdet1_budgetcredit + $row2->budgetAmount;
											$rowdet2_budgetcredit = $rowdet2_budgetcredit + $row2->budgetAmount;
											$rowdet3_budgetcredit = $rowdet3_budgetcredit + $row2->budgetAmount;
											$datatbl_total = $datatbl_total + $totalamount;
											$datatbl_budgettotal = $datatbl_budgettotal + $row2->budgetAmount;
							?>
						<?php  		} ?>
                	<?php   		  }	 ?>
				<?php   		  endforeach;?>
                 			<?php $varAmount = ($rowdet3->acctTypeID == 4)?$rowdet3_budgetcredit + $rowdet3_credit : $rowdet3_credit - $rowdet3_budgetcredit?>
            						<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 if($rowdet3->status == 1){?>
                						<td class="tar"><?php echo ($rowdet3_credit < 0 )?number_format($rowdet3_credit * -1,2):number_format($rowdet3_credit,2) ?>&nbsp;&nbsp;</td>
                 						<?php }else{?>
                						<td class="tar"><?php echo ($rowdet3_credit > 0 )?number_format($rowdet3_credit,2):'('.number_format($rowdet3_credit * -1,2).')' ?>&nbsp;&nbsp;</td>
                						<?php }?>
               						<!--  td class="tar"><?php echo ($rowdet3_budgetcredit < 0 )?number_format($rowdet3_budgetcredit * -1,2):number_format($rowdet3_budgetcredit,2) ?>&nbsp;&nbsp;</td>
                						<td class="tar"><?php echo number_format($varAmount,2)?>&nbsp;&nbsp;</td-->
                					</tr>
                	<?php 		} ?>
				<?php   		  endforeach;?>
     				<?php 	  foreach($accountdetails as $row2):
									if($row2->acctGroupID == $rowdet2->ID){?>
      	<?php 
										if($row2->currentyeardebit != '' || $row2->currentyearcredit !='' || ($row2->openingBalanceDr != 0 || $row2->openingBalanceCr !=0)){ ?>
                 			<?php   		  $totalamount =  ($row2->currentyeardebit+$row2->openingBalanceDr) - ($row2->currentyearcredit+$row2->openingBalanceCr); 
                 					if(floatval($totalamount) == 0 ) continue; ?>
                 			<?php 			  $varAmount = ($row2->acctTypeID == 3)?$row2->budgetAmount + $totalamount : $totalamount - $row2->budgetAmount?>
            								<tr>
           										<td style="display:none" ><?php echo $row2->ID; ?></td>
                								<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $selyear;?>/<?php echo $selper;?>" title="<?php echo $this->lang->line('details');?>" class="btn btn-mini btn-link edit"><?php echo substr($row2->acctCode,0, 4).'-'.substr($row2->acctCode,4, 3).'-'.substr($row2->acctCode,7, 2).' [ '.$row2->acctName.' ]'?></a></td>
                								<td class="tar">
                								<?php if($row2->acctGroupID == '36'): ?>
                									<?php  echo ($totalamount* -1 < 0 )?"(".number_format($totalamount,2).")":number_format($totalamount* -1,2)?>
                								<?php elseif($row2->acctGroupID == '44'): ?>
                									<?php  echo ($totalamount < 0 )?"(".number_format($totalamount* -1,2).")":number_format($totalamount,2)?>
                								<?php else: ?>
                									<?php echo ($totalamount < 0 )?number_format($totalamount * -1,2):number_format($totalamount,2)?>
                								<?php endif; ?>
                								&nbsp;&nbsp;</td>
                								<!-- td class="tar"><?php echo ($row2->budgetAmount == 0 )?'':number_format($row2->budgetAmount,2)?>&nbsp;&nbsp;</td>
                								<td class="tar"><?php echo number_format( $varAmount,2)?>&nbsp;&nbsp;</td -->
                							</tr>
             	<?php
											$rowdet_credit = $rowdet_credit + $totalamount;
											$rowdet1_credit = $rowdet1_credit + $totalamount;
											$rowdet2_credit = $rowdet2_credit + $totalamount;
											$rowdet_budgetcredit = $rowdet_budgetcredit + $row2->budgetAmount;
											$rowdet1_budgetcredit = $rowdet1_budgetcredit + $row2->budgetAmount;
											$rowdet2_budgetcredit = $rowdet2_budgetcredit + $row2->budgetAmount;
											$datatbl_total = $datatbl_total + $totalamount;
											$datatbl_budgettotal = $datatbl_budgettotal + $row2->budgetAmount;
							?>
						<?php  		} ?>
                	<?php   		  }	 ?>
				<?php   		  endforeach;?>
                 			<?php $varAmount = ($rowdet2->acctTypeID == 4)?$rowdet2_budgetcredit + $rowdet2_credit :$rowdet2_credit -  $rowdet2_budgetcredit?>
            						<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 if($rowdet2->status == 1){?>
                						<td class="tar"><?php echo ($rowdet2_credit >= 0 )?'('.number_format($rowdet2_credit,2).')':number_format($rowdet2_credit  * -1,2) ?>&nbsp;&nbsp;</td>
                 						<?php }else{?>
                						<td class="tar"><?php echo ($rowdet2_credit < 0 )?number_format($rowdet2_credit,2):number_format($rowdet2_credit,2) ?>&nbsp;&nbsp;</td>
                						<?php }?>
                						<!-- td class="tar"><?php echo ($rowdet2_budgetcredit < 0 )?number_format($rowdet2_budgetcredit * -1,2):number_format($rowdet2_budgetcredit,2) ?>&nbsp;&nbsp;</td>
                						<td class="tar"><?php echo number_format($varAmount,2)?>&nbsp;&nbsp;</td -->
                					</tr>
                	<?php   } ?>
				<?php   endforeach;?>
      			<?php   foreach($accountdetails as $row2):
							if($row2->acctGroupID == $rowdet1->ID){?>
      	<?php 
								if($row2->currentyeardebit != '' || $row2->currentyearcredit !=''){ ?>
                 			<?php 	$totalamount = ($row2->currentyeardebit+$row2->openingBalanceDr) - ($row2->currentyearcredit+$row2->openingBalanceCr); 
                 					if(floatval($totalamount) == 0 ) continue; ?>
                 			<?php $varAmount = ($row2->acctTypeID == 4)?$row2->budgetAmount + $totalamount :$totalamount - $row2->budgetAmount?>
            							<tr>
           									<td style="display:none" ><?php echo $row2->ID; ?></td>
                							<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo base_url(); ?>glreports/accountDetailsfc/<?php echo $row2->ID;?>/<?php echo $selyear;?>/<?php echo $selper;?>" title="<?php echo $this->lang->line('details');?>" class="btn btn-link"><?php echo substr($row2->acctCode,0, 4).'-'.substr($row2->acctCode,4, 3).'-'.substr($row2->acctCode,7, 2).' [ '.$row2->acctName.' ]'?></a></td>
                                            <?php if($rowdet1->status == 1){?>
                								<td class="tar"><?php echo ($totalamount < 0 )?number_format($totalamount * -1,2):number_format($totalamount,2)?>&nbsp;&nbsp;</td>
                 							<?php }else{?>
                								<td class="tar"><?php echo ($totalamount > 0 )?'('.number_format($totalamount,2).')':number_format($totalamount * -1,2)?>&nbsp;&nbsp;</td>
                							<?php }?>
                							<!--  td class="tar"><?php echo ($row2->budgetAmount == 0 )?'':number_format($row2->budgetAmount,2)?>&nbsp;&nbsp;</td>
                							<td class="tar"><?php echo number_format($varAmount,2)?>&nbsp;&nbsp;</td-->
                						</tr>
             	<?php
										$rowdet_credit = $rowdet_credit + $totalamount;
										$rowdet1_credit = $rowdet1_credit + $totalamount;
										$rowdet_budgetcredit = $rowdet_budgetcredit + $row2->budgetAmount;
										$rowdet1_budgetcredit = $rowdet1_budgetcredit + $row2->budgetAmount;
										$datatbl_total = $datatbl_total + $totalamount;
										$datatbl_budgettotal = $datatbl_budgettotal + $row2->budgetAmount;
							?>
						<?php  	} ?>
                	<?php   	}	 ?>
				<?php 	endforeach;?>
                 			<?php $varAmount = $rowdet1_credit-$rowdet1_budgetcredit ?>
            			  <tr>
                			<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;
								<?php echo $this->lang->line($rowdet1->acctGroupName)?> <?php echo $this->lang->line('subtotal') ?></strong></td>
                                <?php if($rowdet1->status == 1){?>
                					<td class="tar"><?php echo ($rowdet1_credit < 0 )?'('.number_format($rowdet1_credit * -1,2).')':number_format($rowdet1_credit,2)?>&nbsp;&nbsp;</td>
                 				<?php }else{?>
                					<td class="tar"><?php echo ($rowdet1_credit > 0 )?'('.number_format($rowdet1_credit,2).')':number_format($rowdet1_credit * -1,2)?>&nbsp;&nbsp;</td>
                				<?php }?>
                			<!--  td class="tar"><?php echo number_format($rowdet1_budgetcredit,2) ?>&nbsp;&nbsp;</td>
                			<td class="tar"><?php echo number_format($varAmount,2)?>&nbsp;&nbsp;</td -->
                		  </tr>
                	<?php } ?>
				<?php endforeach;?>
                 			<?php $varAmount = $rowdet_credit - $rowdet_budgetcredit ?>
            			  <tr>
                			<td><strong>
								<?php echo $this->lang->line($rowdet->acctGroupName)?> <?php echo $this->lang->line('subtotal') ?></strong></td>
                                <?php if($rowdet1->status == 1){?>
                					<td class="tar"><?php echo ($rowdet_credit < 0 )?'('.number_format($rowdet_credit,2).')':number_format($rowdet_credit * -1,2)?>&nbsp;&nbsp;</td>
                 				<?php }elseif($rowdet->ID == 12){?>
                					<td class="tar"><?php echo ($rowdet_credit > 0 )?number_format($rowdet_credit,2):"(".number_format($rowdet_credit * -1,2).")"?>&nbsp;&nbsp;</td>
                 				<?php }else{?>
                					<td class="tar"><?php echo ($rowdet_credit > 0 )?'('.number_format($rowdet_credit,2).')':number_format($rowdet_credit * -1,2)?>&nbsp;&nbsp;</td>
                				<?php }?>
                			<!--  td class="tar"><?php echo number_format($rowdet_budgetcredit,2) ?>&nbsp;&nbsp;</td>
                			<td class="tar"><?php echo number_format($varAmount,2)?>&nbsp;&nbsp;</td -->
                		  </tr>
<!-- row det -->
                <?php } ?>
		<?php  endforeach; ?>
                 			<?php $varAmount = $datatbl_total - $datatbl_budgettotal ?>
            			  <tr>
                			<td><h4><?php echo $this->lang->line($datatbl->acctGroupName)?> <?php echo $this->lang->line('subtotal') ?></h4></td>
                                <?php if($datatbl->status == 1){?>
                					<td class="tar"><?php echo ($datatbl_total < 0 )?'('.number_format($datatbl_total,2).')':number_format($datatbl_total * -1,2)?>&nbsp;&nbsp;</td>
                 				<?php }else{?>
                					<td class="tar"><?php echo ($datatbl_total > 0 )?'('.number_format($datatbl_total,2).')':number_format($datatbl_total * -1,2)?>&nbsp;&nbsp;</td>
                				<?php }?>
                			<!--  td class="tar"><?php echo number_format($datatbl_budgettotal,2) ?>&nbsp;&nbsp;</td>
                			<td class="tar"><?php echo number_format($varAmount,2)?>&nbsp;&nbsp;</td-->
                		  </tr>
        <?php } ?>
<?php  endforeach; ?>
		<!--tr>
			<td><h4><?php echo $this->lang->line('netincome') ?></h4></td>
        	<td class="tar"><?php echo number_format($datatbl_total,2) ?>&nbsp;&nbsp;</td>
  		</tr -->
	<?php }?>
                     </tbody>
                     </table>
				</div><!-- content -->
				</div><!-- block -->
			</div><!-- span12 -->
		</div><!-- row-fluid -->	
	</div><!-- wrap -->
</div><!-- content --></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>  
