<script>
$(document).ready(function(){
	$('select').select2();
//	$('#acctCodel').select2();savedetails
	jQuery('.datepicker2').datepicker({
			dateFormat : 'dd-mm-yy',
			changeMonth : true,
			changeYear : true
			});
   var oTable = $("#test").dataTable( {
        "iDisplayLength": 10,
		 "aLengthMenu": [5,10,25,50,100],
		 "sPaginationType": "full_numbers", 
		 "aoColumns": [ 
		 	{"bSortable": false }, 
			null, 
			null, 
			null, 
			null, 
			null,
			null,
			null,
			null ]});
//     oTable.fnSort( [ [1,'asc'] ] );
});

function do_print(){
	window.open("<?php echo base_url() ?>glreports/accountDetailsfc_print/<?php echo $ID;?>/<?php echo $year;?>/<?php echo $period;?>");
}

function do_print2(){
	window.open("<?php echo base_url() ?>glreports/accountDetailsfc_print2/<?php echo $ID;?>/<?php echo $year;?>");
}
</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 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('title') ?></li>
				</ul>
			</div>
			<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="row-fluid scRow">  
				<div class="span12">
				
					<div class="block">
						<div class="head">
							<h2><strong><?php echo $this->lang->line('title') ?></strong></h2>
							<ul class="buttons">
								<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
                            </ul>
						</div><!-- head -->
						<div class="content np">
							<div class="controls-row"><!-- Row 1-->
								<div class="span2"><?php echo $this->lang->line('acctCode');?></div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'acctCode', 
									'id'=>'acctCode', 
									'disabled'=>'disabled', 
									'class'=>'input-medium',); 
									echo form_input($data,  substr($accountHead->acctCode,0,4).'-'.substr($accountHead->acctCode,4,3).'-'.substr($accountHead->acctCode,7)); ?>
								</div>
							</div><!-- End Row 1-->
							<div class="controls-row"><!-- Row 2-->
								<div class="span2"><?php echo $this->lang->line('acctName');?></div>
								<div class="span8">
                            	<?php 								
								$data = array(
									'name'=>'acctName', 
									'id'=>'acctName', 
									'disabled'=>'disabled', 
									'class'=>'span12',); 
									echo form_input($data, $accountHead->acctName); ?>
								</div>
							</div><!-- End Row 2-->
						</div><!-- content np-->
					</div>  <!-- block -->  
				</div>  <!-- span12 -->  
			</div> <!-- row-fluid scRow-->   
			
			<div class="row-fluid scRow">   
				<div class="span12">
					<div class="block">
						<div class="head">
							<h2><?php echo $this->lang->line('titlelist') ?></h2>
							<ul class="buttons">
								<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
                            </ul> 
							<div class="side fr">
							<?php
								if($period=='' || $period==0){
									echo "<button class='btn-form btn-success-form' onClick='do_print2()'>Print</button>";
								}
								else{
									echo "<button class='btn-form btn-success-form' onClick='do_print()'>Print</button>";
								}
								?>
							</div>
						</div>
						<div class="content np table-sorting">
							<table cellpadding="0" cellspacing="0" width="100%" id="oTable" class="editable">
								<thead>
									<tr>
										<th style="display:none"></th>
										<th width="5">#</th>
										<th class="tac"><?php echo $this->lang->line('date')?></th>
										<th><?php echo $this->lang->line('journalNo')?></th>
										<th><?php echo $this->lang->line('referenceNo')?></th>
										<th><?php echo $this->lang->line('description')?></th>
										<th class="tar"><?php echo $this->lang->line('amount_dr')?></th>
										<th class="tar"><?php echo $this->lang->line('amount_cr')?></th>
										<th class="tar"><?php echo $this->lang->line('balance')?></th>
									</tr>
								</thead>
								<tbody>
									<tr>
										<td style="display:none" ></td>
										<td class="tac">1</td>
										<td class="tac">&nbsp;</td>
										<td colspan="5"><?php echo $this->lang->line('openbalance')?></td>
										<td class="tar"><?php echo ($accountHead->acctTypeID != '3' && $accountHead->acctTypeID != '3' )?number_format($openingBalance,2):number_format(0,2); ?></td>
									</tr>
									<?php $bil = 1; 
									//$balanceAmount = $accountdetails->total;
									$balanceAmount = $openingBalance;
									$totalDebit=0;
									$totalCredit=0;
									if($datatbls){
										foreach($datatbls as $datatbl):
									if($bil == 1){
										$balanceAmount = $balanceAmount + $datatbl->amount_dr - $datatbl->amount_cr;
										$totalDebit = $datatbl->amount_dr + $totalDebit;
										$totalCredit = $datatbl->amount_cr + $totalCredit;
										$bil++?>
									<tr>
										<td style="display:none" ><?php echo $datatbl->ID; ?></td>
										<td class="tac"><?php echo $bil; ?></td>
										<td class="tac"><?php echo date("d-m-Y",strtotime($datatbl->effective_date)); ?></td>
										<td><a href="<?php echo base_url()?>glreports/journalDetails1/<?php echo $datatbl->journalID ?>" title="<?php echo $this->lang->line('details');?>" class="btn btn-mini btn-link edit"><?php echo $datatbl->journalID?></a></td>
										<td><?php echo $datatbl->refNo; ?></td>
										<td><?php echo $datatbl->description; ?></td>
										<td class="tar"><?php echo number_format($datatbl->amount_dr,2); ?></td>
										<td class="tar"><?php echo number_format($datatbl->amount_cr,2); ?></td>
										<td class="tar"><?php echo number_format($balanceAmount,2); ?></td>
									</tr>
									<?php 
										}
									else{
										$balanceAmount = $balanceAmount + $datatbl->amount_dr - $datatbl->amount_cr;
										$totalDebit = $datatbl->amount_dr + $totalDebit;
										$totalCredit = $datatbl->amount_cr + $totalCredit;
										$bil++?>
									<tr>
										<td style="display:none" ><?php echo $datatbl->ID; ?></td>
										<td class="tac"><?php echo $bil; ?></td>
										<td class="tac"><?php echo date("d-m-Y",strtotime($datatbl->effective_date)); ?></td>
										<td><a href="<?php echo base_url()?>glreports/journalDetails1/<?php echo $datatbl->journalID ?>" title="<?php echo $this->lang->line('details');?>" class="btn btn-mini btn-link edit"><?php echo $datatbl->journalID?></a></td>
										<td><?php echo $datatbl->refNo; ?></td>
										<td><?php echo $datatbl->description?></td>
										<td class="tar"><?php echo number_format($datatbl->amount_dr,2); ?></td>
										<td class="tar"><?php echo number_format($datatbl->amount_cr,2); ?></td>
										<td class="tar"><?php echo number_format($balanceAmount,2); ?></td>
									</tr>
									<?php 
										}
									endforeach; 
									}?>
									<tr>
										<td style="display:none" ></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td> <!--Farid-->
										<td class="tar"><?php echo "Total"; ?></td>
										<td class="tar"><?php echo number_format($totalDebit,2); ?></td>
										<td class="tar"><?php echo number_format($totalCredit,2); ?></td>
										<td></td>
									</tr>
								</tbody>
							</table>                                         
						</div>
					</div><!-- block grid-->
				</div> <!--span 12 -->
			</div> <!--row fluid -->
			
		</div>  <!--content class -->
	</div>  <!--wrap -->
</div> <!--content id -->                      
