<script type="text/javascript">
    $(document).ready(function(){
        <!-- page script -->
        $('.datatables').DataTable();
        $('.datetimepicker').datetimepicker({
            viewMode: 'months',
            format: 'DD/MM/YYYY'
        });
    });
	
	function back(){
		  //window.history.back(); //(Sayem-27-11-2015)Problem with history.back is, It keep the previous state of the page. not updated state.
      window.location.replace(document.referrer); //Refresh and reload the previous page.
	}

	function printJournalDetail(){
		var dateFrom = $('#dateFrom').val();
		var dateTo = $('#dateTo').val();
		var urls = "<?php echo base_url();?>report/journalDetailsPrint/<?php echo $ID; ?>";
			window.location = urls;
	}
	
//Create By Fadhirul(28-4-2016)	
	
	function viewRptSales(me)
	{
		var urls = "<?php echo base_url();?>sales/print_sale/657";
			window.location = urls;
	}
	
	function viewRptOtherPayment(me,code)
	{
		//alert(code);
		if(code == 0)
		{
			var urls = "<?php echo base_url();?>expenses/printDetail/" + me + "/cogs";
			window.location = urls;
		}
		else{
			var urls = "<?php echo base_url();?>expenses/printDetail/" + me + "/operational";
			window.location = urls;
		}
		
	}
//*******************************	

</script>

			<div class="content-wrapper">
        		<!-- Content Header (Page header) -->
        		<section class="content-header">
          			<h1>
            			<?php echo $this->lang->line('title') ?>
            			<!--<small>advanced tables</small>-->
          			</h1>
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="#">Tables</a></li>
                        <li class="active">Data tables</li>
                    </ol>
        		</section>

                <!-- Main content -->
                <section class="content">
                  <div class="row">
                    <div class="col-xs-12">
        
        			  <div class="box box-primary">
                        <div class="box-header with-border">
                          <h3 class="box-title"><?php //echo $this->lang->line('selectDate'); ?></h3>
                        </div><!-- /.box-header -->
                        <form class="form-horizontal">
                          <div class="box-body">
                            <div class="form-group col-sm-6">
                              <label class="col-sm-4 control-label"><?php echo $this->lang->line('jlnumber');?></label>
                              <div class="col-sm-8">
                                <?php 								
								$data = array(
									'name'=>'journal_number', 
									'id'=>'journal_number', 
									'disabled'=>'disabled', 
									'class'=>'form-control',); 
									echo form_input($data, $journalHead->journalID); ?>
                              </div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-6">
                              <label class="col-sm-4 control-label"><?php echo $this->lang->line('description');?></label>
                              <div class="col-sm-8"><b>
                                <?php
								
//Edit by Fadhirul(28-4-2016)								
									$checkSales = explode('[', $journalHead->formNo);
									
									if($checkSales[0] == "OR"){
										$data = array(
											'name'=>'description', 
											'id'=>'description', 
											'readonly'=>'readonly',
											'onclick'=>'viewRptSales('.$journalHead->recPaymentID.')',
											'title'=>'Click here', 
											'class'=>'form-control',); 
										echo form_input($data, $journalHead->description);
									}
									else{
										$otherPay = $checkSales[1];
										
										if($otherPay == "OP-C"){
											$num = 0;
										}
										else{
											$num = 1;
										}
										
										$data = array(
											'name'=>'description', 
											'id'=>'description', 
											'readonly'=>'readonly',
											'onclick'=>'viewRptOtherPayment('.$journalHead->othersPaymentID.','.$num.')',
											'title'=>'Click here', 
											'class'=>'form-control',); 
										echo form_input($data, $journalHead->description);
									}
//*******************************************								 								
								 ?>
                              </b></div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-6">
                              <label class="col-sm-4 control-label"><?php echo $this->lang->line('effective_date');?></label>
                              <div class="col-sm-8">
                                <?php 								
									$data = array(
										'type'=>'text',
										'name'=>'effdate', 
										'id'=>'effdate', 
										'disabled'=>'disabled', 
										'class'=>'form-control',); 
										echo form_input($data, date("d-m-Y", strtotime($journalHead->effective_date))); ?>
                              </div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-6">
                              <label class="col-sm-4 control-label"><?php echo $this->lang->line('amount_dr_ttl');?></label>
                              <div class="col-sm-8">
                                <?php                 
								$data = array(
									'name'=>'amountdebit', 
									'id'=>'amountdebit', 
									'disabled'=>'disabled',
									'class'=>'form-control',); 
									echo form_input($data, number_format($journalHead->total_amount_dr,2)); ?>
                              </div>
                            </div>
                            <div class="form-group col-sm-6">
                              <label class="col-sm-4 control-label"><?php echo $this->lang->line('amount_cr_ttl');?></label>
                              <div class="col-sm-8">
                                <?php 								
								$data = array(
									'name'=>'amountcredit', 
									'id'=>'amountcredit', 
									'disabled'=>'disabled',
									'class'=>'form-control',); 
									echo form_input($data, number_format($journalHead->total_amount_cr,2)); ?>
                              </div>
                            </div>
                          </div>
                          
                        </form>
                      </div>
        
                      <div class="box box-primary">
                      	<div class="box-header with-border">
                            <!--<h3 class="pull-left"><?php //echo $this->lang->line($title.'SubHdr'); ?></h3>-->
                            <div class="box-title pull-right">
                            	<!--<button class="btn btn-primary btn-sm"><span class="glyphicon glyphicon glyphicon-plus"></span></button>
                                <button class="btn btn-primary btn-sm"><span class="glyphicon glyphicon glyphicon-minus"></span></button>-->
                                <button class="btn btn-primary btn-sm" onclick="printJournalDetail()"><span class="glyphicon glyphicon glyphicon-print"></span></button>
                            </div>
                        </div><!-- /.box-header -->
                        <div class="box-body table-scroll-xs">
                          <table id="example1" class="table table-bordered table-striped datatables">
                             <thead>
            					<tr>
                                	<th style="display:none"></th>
									<th width="5">#</th>
									<th><?php echo $this->lang->line('acctCode')?></th>
									<th><?php echo $this->lang->line('description')?></th>
									<th class="text-right"><?php echo $this->lang->line('amount_dr')?></th>
									<th class="text-right"><?php echo $this->lang->line('amount_cr')?></th>
            					</tr>
            				</thead>
                            
                            <tbody>
							<?php $bil = 0; 
                                if($datatbls){
                                    foreach($datatbls as $datatbl):
                                        $bil++?>
                                        <tr>
                                            <td style="display:none" ><?php echo $datatbl->ID; ?></td>
											<td class="tac"><?php echo $datatbl->sequence; ?></td>
											<td><?php echo substr($datatbl->acctcode,0, 4).'-'.substr($datatbl->acctcode,4, 3).'-'.substr($datatbl->acctcode,7, 2) . "  [" . $datatbl->acctname. "]"?></td>
											<td><?php echo $datatbl->description?></td>
											<td class="text-right"><?php echo number_format($datatbl->amount_dr,2); ?></td>
											<td class="text-right"><?php echo number_format($datatbl->amount_cr,2); ?></td>
                                        </tr>
                            <?php endforeach; }?>
                            </tbody>
                            
                          </table>
                          
                        </div><!-- /.box-body -->
                        
                        <div class="box">
                        	<div class="box-header with-border">
                            	<div class="box-title pull-right">
                            		<button class="btn btn-primary btn-sm" onclick="back()"><?php echo $this->lang->line('goback')?></button>
                        		</div>
                            </div>
                        </div><!-- /.box-header -->
                        
                      </div><!-- /.box -->
                      
                      
                      
                    </div><!-- /.col -->
                  </div><!-- /.row -->
                </section><!-- /.content -->
              </div><!-- /.content-wrapper -->