<link href="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/ui.theme.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/autocomplete.css" rel="stylesheet">
	
 <link href="<?php echo base_url(); ?>assets/select/chosen.min.css" rel="stylesheet" media="screen">
	
		   
		   		   <script src="<?php echo base_url(); ?>assets/select/chosen.jquery.min.js"></script>


 
            
        <script type="text/javascript">  
        $(this).ready( function() {  
            $("#id").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>/Systemusers/lookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		
		
			
		 $(document).on("click", "#managebtndelete", function()
        {
          var transactionid = $(this).data('id');
		  $("#transactionid").val(transactionid); 
   var myid = $(this).data('myid');
		  $("#myid").val(myid); 
		   
		   
        });
		  $(function() {
<!--             $(".datepicker").datepicker(); -->
<!--             $(".uniform_on").uniform() -->;
            $(".chzn-select").chosen();
   <!--          $('.textarea').wysihtml5(); -->

        });
        </script>
	   	
 
 <div class="row">
  
   	

   	<div class="col-md-12">

  <?php
 
				echo $this->session->flashdata('msg'); 
   $session_data = $this->session->userdata('logged_in');

      $mydate=date("Y-m-d H:i:s");
 $date = Date('Y-m-d') ;
		 	 $year = Date('Y') ;
		  $month = Date('m') ;
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
    $deletebank=$this->usermodel->populatuserpermissionsdataarray('accounting','deletebank',$userid);

  
  ?>
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
				 <span class="pull-center"> Update/Create Journal Entry  </span>
	  
				 	  				 <a href="<?php echo base_url();?>user/viewjournalentry" class="btn btn-info"> Back </a>

				 
            	</div>
            </div>
			<div class="panel-body">


	<div class="col-md-12">

				<?PHP
//$session_data = $this->session->userdata('logged_in');


		
                 echo form_open('user/addjojurnal' , array('class' => 'form-inline form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):
				 $salesid=$main[0]['invoice']

				 ?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

 </div>
	<div class="col-md-12">
										<input type="hidden" name="myview" value="user/viewmyjournalentry?randomitemidentifier=<?php echo $main[0]['invoice']; ?>" class="form-control" required placeholder="Enter invoiceno">

									<input type="hidden" name="view" value="user/viewmyjournalentry?randomitemidentifier=" class="form-control" required placeholder="Enter invoiceno">
								<input type="hidden" name="action" value="update" class="form-control" required placeholder="Enter invoiceno">

								<input type="hidden" name="itemid" value="<?php echo set_value('id',$main[0]['id']); ?>" class="form-control" required placeholder="Enter invoiceno">

 	
	      <div class="form-group">
    <label for="inputcurrency" class="col-sm-2 control-label">Currency Name?</label>
    <div class="col-sm-4">
	<select class="form-control" name="currency" required>
	
	
   <?php
 $currencyid= $main[0]['currency'];
 		$currency= $this->usermodel->populateall('currency','id',$currencyid);



if(is_array($currency)) {

   foreach($currency as $currencyrow){

    ?>
					<option selected="selected" value="<?=  $currencyrow->id;   ?>"><?=  $currencyrow->name; ?></option>

   
    <?php

}} else {
 ?>
<option value=""  >---Select Currency---</option>

		<?php 
}
 
	$session_data = $this->session->userdata('logged_in');

  
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
					 
					 					 $banking= $this->usermodel->populateall('currency','companyid',$companyid);


	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $bankingrow->id;   ?>"><?=  $bankingrow->name ;?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('bankname'); ?>

	</div>
  </div>
  
		
		
	
  	
		<div class="form-group">
    <label for="inputorderedby" class="col-sm-2 control-label">	Journal no: </label>
    <div class="col-sm-4">
	
		  		<input type="text" name="id" readonly value="<?php echo set_value('id',$main[0]['id']); ?>" class="form-control" required placeholder="Enter  id ">
		 
				
		<span class="text-danger"> <?php echo form_error('id'); ?>
		
		</span>
	</div>
  </div>
	 
	   </div>
		<div class="col-md-12">

		
		
				
			  <div class="form-group">
    <label for="inputorderdate" class="col-sm-2 control-label">Date captured </label>
    <div class="col-sm-4">

	<input type="text" readonly  name="entrydate" value="<?php echo set_value('entrydate',$main[0]['entrydate']); ?>"id="entrydate" class="form-control" required placeholder="Enter specific order date  (dd-mm-YYY) ">
			<span class="text-danger"> <?php echo form_error('entrydate'); ?>
		
		</span>
	</div>
  </div>		
			
		
					  <div class="form-group">
    <label for="inputjournaldate" class="col-sm-2 control-label">Journal Date </label>
    <div class="col-sm-4">

	<input type="text" name="journaldate" value="<?php echo set_value('journaldate',$main[0]['journaldate']); ?>"id="journaldate" class="form-control" required placeholder="Enter journal date  (dd-mm-YYY) ">
			<span class="text-danger"> <?php echo form_error('journaldate'); ?>
		
		</span>
	</div>
  </div>		
		
		   </div>
	
		
		<div class="col-md-12">

				  <div class="form-group">
    <label for="inputinvoice" class="col-sm-2 control-label">Ref NO </label>
    <div class="col-sm-4">
<input type="text" readonly name="invoice" value="<?php echo set_value('invoice',$main[0]['invoice']); ?>" class="form-control" required placeholder="Enter invoiceno">
			<span class="text-danger"> <?php echo form_error('invoice'); ?>
		
		</span>
	</div>
  </div>
 
  	  

				
  
  
  
  
<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">Description</label>
    <div class="col-sm-4">

	<textarea name="description" class="form-control" placeholder="Bussines/comments/note"><?php echo set_value('description',$main[0]['description']); ?></textarea> 
			
	</div>
  </div>
  
</div>
	
  	<div class="col-md-12">					
				
			 <div class="form-group">
    <label for="inputterms" class="col-sm-2 control-label"> </label>

    <div class="col-sm-4">
     
	         <button type="submit"  name="btn_journalEntry"  value="journal"  class="btn btn-primary"> Update Journal Entry</button>
<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printmyjournal?invoice=<?php   if(isset($main[0]['invoice'])) {echo $main[0]['invoice']; } ?>"> Print Journal Entry  </a>

    </div>
  </div>
  
						
			
			 
  	
		
  
  

	
  					<?php echo form_close();?>
					
		 </div>			
			  </div>		
			
				<div class="widget-content nopadding table_holder table-responsive"  >		
	
		
	
					
					
				
					<div class="table-responsive">
						<table id="register" class="table table-bordered " width="100%" >
						<thead>
							<tr style="background:gray">
								<th>Debit Account:</th>
								<th>Credit Account:</th>
								<th>Account:</th>
								<th>Description:</th>
									<th>Ref No:</th>
									
										<th> Code:</th>
										<th> Type:</th>
									
																		<th>Date:</th>

									
									
									
									
									
								<th>Customer:</th>

								
							
						<th>Save</th>

									<th></th>	
								
							</tr>
		<tr style="background:gray">								
										<?php
										function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
						}
						return $number;
					}
	 $session_data = $this->session->userdata('logged_in');
 echo $this->session->flashdata('deletemsg'); 

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	    $addproductaction=$this->usermodel->populatuserpermissionsdataarray('purchases','add',$userid);

	 $updateaction=$this->usermodel->populatuserpermissionsdataarray('purchases','update',$userid);
  $updatebuyingpriceaction=$this->usermodel->populatuserpermissionsdataarray('purchases','updatebuyingprice',$userid);
  $deleteaction=$this->usermodel->populatuserpermissionsdataarray('purchases','delete',$userid);
  $updatesellingpriceaction=$this->usermodel->populatuserpermissionsdataarray('purchases','updatesellingprice',$userid);
    $updateclosedinvoiceaction=$this->usermodel->populatuserpermissionsdataarray('purchases','updateclosedinvoice',$userid);

      $invoicestatus=$this->usermodel->populateallarray('purchaseorder','invoice',$finalsalesid);
$myinvoice=$invoicestatus[0]["status"];
  
   echo $this->session->flashdata('productmsg'); 
                 echo form_open('user/savedoublejournal' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

									<input type="hidden" name="view" value="user/viewmyjournalentry?randomitemidentifier=<?php echo $main[0]['invoice']; ?>" class="form-control" required placeholder="Enter invoiceno">
		  		<input type="hidden" name="itemid" id="itemid" value="" class="form-control"  placeholder="Enter itemid" >
	<input type="hidden" name="action" value="insert" class="form-control" required placeholder="Enter insert">

		 							
								
								
									<th>
								

	<select class="chzn-select" name="bankname" required style="width:180px">
	
	<option value=""  >Select Account</option>
	
	<?php 
	$session_data = $this->session->userdata('logged_in');

  
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
					 
															 $banking= $this->usermodel->populateall('glaccounts','companyid',$companyid);


										//$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype>','1');

	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname." (".$bankingrow->number.")";  ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>

	
								
								
								</th>
								
								
									<th>
								
<select class="chzn-select" name="banknamecredit" required style="width:180px">
	
	<option value=""  >Select Account</option>
	
	<?php 
	$session_data = $this->session->userdata('logged_in');

  
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
					 
															 $banking= $this->usermodel->populateall('glaccounts','companyid',$companyid);


										//$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype>','1');

	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname." (".$bankingrow->number.")";  ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>
								
								
								</th>	
								
									<th>
								

								
		  		<input type="text" name="amount" id="amount" value="0" required class="form-control"  placeholder="Enter amount" >
								
								</th>
								
						<th>
								

								
		  		<input type="text" name="description" id="description" value="<?php echo set_value('description'); ?>" class="form-control" required placeholder="Enter description" >
								
								</th>
								
					
								<th>
								

								
								<input type="TEXT" style="width:180px" name="invoice" value="<?php echo set_value('invoice',$finalsalesid); ?>" class="form-control" required placeholder="Enter invoice">
								
								</th>
								
								<th>
								

								
								<input type="TEXT" name="transactioncode" value="<?php echo set_value('transactioncode'); ?>" class="form-control"  placeholder="Code">
								
								</th>
												
							
									
										<th>
								

								
								<input type="TEXT" name="type" value="<?php echo set_value('type'); ?>" class="form-control"  placeholder="Type">
								
								</th>
										<th>
								

									<input type="text" style="width:150px" name="journaldate" value="<?php echo set_value('journaldate',$main[0]['journaldate']); ?>"id="journaldate" class="form-control" required placeholder="Enter journal date  (dd-mm-YYY) ">

								
								</th>	
								
								
							<th>
						
		<select  name="supplier" id="supplier"  class="chzn-select"  style="width:150px">
	
	<option value=""  >Select Customer/supplier</option>

		<?php 



	
					 
			$mycustomer= $this->usermodel->populateviewcustomers('people','firstname','ASC','companyid', $companyid);
	     // $mycustomer=$this->usermodel->populatealldatawhere('products','bulk',$userid);


if(is_array($mycustomer)) {

   foreach($mycustomer as $mycustomerrow){

   //echo $courserow->coursename;
   ?>
					<option value="<?=  $mycustomerrow->id;   ?>"><?=  $mycustomerrow->firstname ." ".$mycustomerrow->company.""; ?></option>




	<?php

}} else {
    echo 'No supplier available.';
}
	
?>
</select>		
		  		
	
								
								</th>
								
								<th colspan="2">

								
								<button type="submit"  value="statement" name="btn_statment" class="btn btn-primary"> Save  </button>

 
  					<?php echo form_close();?>
								
								</th>
								
							</tr>
								
						</thead>
						<?php
					
 if(!is_array($submain)) {
	  echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='5'>";
    echo"There is no data found..";
    echo "</td>";
   echo "</tr>";

			 }else{
 
 $finaltotaldebits=0;
   $finaltotalcredits=0;
  	foreach ($submain as $c){
		
$itemid=$c->id;

$finaltotaldebits=$finaltotaldebits+$c->debit;
$finaltotalcredits=$finaltotalcredits+$c->credit;

             ?>
				                    <tbody >
									
										 
										<?php
					
		
                 echo form_open('user/savejournal' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>								
											<tr>
		

									<input type="hidden" name="view" value="user/viewmyjournalentry?randomitemidentifier=<?php echo $main[0]['invoice']; ?>" class="form-control" required placeholder="Enter invoiceno">

	<input type="hidden" name="action" value="update" class="form-control" required placeholder="Enter insert">

								
								

		
												
											<input type="hidden" name="itemid" id="itemid" value="<?php echo set_value('itemid',$c->id); ?>" class="form-control" required placeholder="itemid" >


											
			
											
											
											
			<td>
			
	
			
			
			
			
			
			<select class="chzn-select" name="bankname" required style="width:180px">
	
	<option value=""  >Select Account</option>
	
	
	<?php 
	$accountid= $c->account ;
		 $mybanking= $this->usermodel->populateall('glaccounts','number',$accountid);



	
if(is_array($mybanking)) {

   foreach($mybanking as $mybankingrow){

   //echo $courserow->coursename;
    ?>
					<option selected="selected" value="<?=  $mybankingrow->number;   ?>"><?=  $mybankingrow->accountname." (".$mybankingrow->number.")";  ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	

	
															 $banking= $this->usermodel->populateall('glaccounts','companyid',$companyid);


										//$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype>','1');

	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname." (".$bankingrow->number.")";  ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>
			
			
			
			
			
			
			
			
			</td>
				<td>
				
																						<input type="TEXT" name="debit" value="<?php echo set_value('debit',$c->debit); ?>" class="form-control" required placeholder="Enter debit">

				
				</td>
								<td>
								
								
								
																		<input type="TEXT" name="credit" value="<?php echo set_value('credit',$c->credit); ?>" class="form-control" required placeholder="Enter credit">
	
								
								</td>

			<td>
			
			
			
											<input type="TEXT" name="description" value="<?php echo set_value('description',$c->description); ?>" class="form-control" required placeholder="Enter description">

			
			
			</td>


						<td>
								

								
								<input type="TEXT" name="invoice" value="<?php echo set_value('invoice',$c->code); ?>" class="form-control"  placeholder="Enter invoice">
								
								</td>
								
								<td>
								

								
								<input type="TEXT" name="transactioncode" value="<?php echo set_value('transactioncode',$c->transactioncode); ?>" class="form-control"  placeholder="Transaction code">
								
								</td>
												
							
										<td>
								

								
								<input type="TEXT" name="type" value="<?php echo set_value('type',$c->type); ?>" class="form-control" required placeholder="Transaction type">
								
								</td>						
											
											
								
										<td>
								

								
								<input type="TEXT" name="journaldate" value="<?php echo set_value('crateddate',$c->crateddate); ?>" class="form-control" required placeholder="Transaction journaldate">
								
								</td>						
												
											

										
											 
		<td>


	<select  name="supplier" id="supplier"  class="chzn-select"  style="width:150px">
	
	<option value=""  >Select Customer/supplier</option>
	
	
	
	
	
	
		<?php 
		$supplierid=$c->supplier;
	     $mycurrentcustomer=$this->usermodel->populateall('people','id',$supplierid);



	
					 


if(is_array($mycurrentcustomer)) {

   foreach($mycurrentcustomer as $mycurrentcustomerrow){

   //echo $courserow->coursename;
   ?>
					<option  selected="selected"  value="<?=  $mycurrentcustomerrow->id;   ?>"><?=  $mycurrentcustomerrow->firstname ." ".$mycurrentcustomerrow->company.""; ?></option>




	<?php

}} else {
   // echo 'No supplier available.';
}






	
					 
			$mycustomer= $this->usermodel->populateviewcustomers('people','firstname','ASC','companyid', $companyid);


if(is_array($mycustomer)) {

   foreach($mycustomer as $mycustomerrow){

   //echo $courserow->coursename;
   ?>
					<option value="<?=  $mycustomerrow->id;   ?>"><?=  $mycustomerrow->firstname ." ".$mycustomerrow->company.""; ?></option>




	<?php

}} else {
    echo 'No supplier available.';
}
	
?>
</select>


</td>
				  									 
											 
											 
											 
											 
											 
											 
												  
											  
											  
											  
											  
											  <td>
								<button type="submit"  value="statement" name="btn_statment" class="btn btn-primary"> Update  </button>

											  </td>
											  
											  
												 	<td  style='color:green'> 
				<?php

	
 if( $deleteaction==true){
	 ?>
		                              <a  id="more" class="btn btn-danger" href="<?php echo base_url();?>user/deletepurchasedproducts?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&itemid=<?php   {echo  $itemid;}  ?>&view=user/viewmyjournalentry?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&deltetable=debitcredit&maintable=journal"> <span class="glyphicon glyphicon-trash"></span> </a>

	 
	 	<?php	

 }else{
	
 }
  ?>
		                              </td> 
							
 </tr>
 <?php 
	 }?>
				<?php }?>							
	

            <tr>
			<td><h3 style="padding:0; margin:0;">
			TOTAL :
			</h3>
				</td>
			
			<td><h3 style="padding:0; margin:0;">Debit:<?php if(isset($finaltotaldebits)) {echo formatMoney($finaltotaldebits, true); }?></h3></td>
			<td><h3 style="padding:0; margin:0;">Credit:<?php if(isset($finaltotalcredits)) {echo formatMoney($finaltotalcredits, true); }?></h3></td>

			
			</tr>

								
				
									</tbody>
									
									
					</table>
				</div>	
			</div>			
					
					
					
					
					
					
					
					
					
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    
			
			
		</div>
	    </div>
		
  

 
</div>


















