<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); 
 
 
		   
        });
		  $(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/generalledger" class="btn btn-info"> Back </a>

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


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

	
			
	
		
	
					
					
				
						<table id="register" class="table table-bordered " width="100%" >
						<thead>
							<tr>
								
								<th>Account:</th>
								<th>Debit:</th>
								<th>Credit:</th>
								<th>Description:</th>

																<th>Verified:</th>
																
																<th>Date:</th>
																<th>Code:</th>
																	<th>Refno:</th>
<th>Type:</th>
							
						<th>Customer</th>
		<th>Save</th>
									<th></th>	
								
							</tr>
								<tr>
								
										<?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/updateJE' , 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="myid" value="<?php echo set_value('id',$finalsalesid); ?>" class="form-control" required placeholder="Enter invoice">
								<input type="hidden" name="code" value="<?php echo set_value('code',$allsalesdetails[0]['code']); ?>" class="form-control" required placeholder="Enter invoice">

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

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

								
								
								
								
								
									<th>
								

	<select class="chzn-select" name="bankname" required style="width:150px">
	
	<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'];
	 
	 	$number=$allsalesdetails[0]['account'];
			 $child = $this->usermodel->populateall('glaccounts','number',$number);

					 


							


if(is_array($child)) {

   foreach($child as $childrow){
	
   //echo $courserow->coursename;
    ?>
					<option  selected="selected" value="<?=  $childrow->number;   ?>"><?=  $childrow->accountname." (".$childrow->number.")";  ?></option>



	<?php

}} else {
	

	
}
	 
	 
	 
	 
	 
					 
															 $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="debit"  id="debit" value="<?php echo set_value('debit',$allsalesdetails[0]['debit']); ?>" class="form-control"  placeholder="Enter debit" >
								
								</th>	
								
									<th>
								

								
		  		<input type="text" name="credit"   id="credit" value="<?php echo set_value('credit',$allsalesdetails[0]['credit']); ?>" class="form-control"  placeholder="Enter credit" >
								
								</th>
								
						<th>
								

								
		  		<input type="text" name="description" id="description" value="<?php echo set_value('description',$allsalesdetails[0]['description']); ?>" class="form-control"  placeholder="Enter description" >
								
								</th>
								
					
										
							
								<th>
								
<select class="form-control"name="confirm"  >
	
	<option value="">-Select-</option>

 
					<option  selected="selected" value="<?=  $allsalesdetails[0]['confirm'];   ?>"><?php   echo $allsalesdetails[0]['confirm']; ?></option>

   <option value="Yes"  >Yes</option>
   <option value="No"  >No</option>

   

</select>	
								
								
								</th>
										<th>
		<input type="text" name="journaldate" id="journaldate"   style="width:150px" value="<?php echo set_value('balance',$allsalesdetails[0]['crateddate']); ?>" class="form-control"  placeholder="Enter date eg, 2019-07-05 05:03:47 " >
								</th>




							<th>
		  		<input type="text" name="transactioncode" id="transactioncode"  value="<?php echo set_value('transactioncode',$allsalesdetails[0]['transactioncode']); ?>" class="form-control"  placeholder="Enter transaction code" >
								</th>
								
															<th>
		  		<input type="text" name="invoice"  style="width:150px" id="invoice" readonly value="<?php echo set_value('code',$allsalesdetails[0]['code']); ?>" class="form-control"  placeholder="Enter Refno" >
								</th>
		
							
		
								<td>
								

								
								<input type="text" name="type" value="<?php echo set_value('type',$allsalesdetails[0]['type']); ?>" class="form-control"  placeholder="Transaction type">
								
								</td>
								
								
								
								<td>


	<select  name="supplier" id="supplier"  class="chzn-select"  style="width:150px">
	
	<option value=""  >Select Customer/supplier</option>
	
	
	
	
	
	
		<?php 
		$supplierid=$allsalesdetails[0]['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>
				  					
								
								<th colspan="2">

								
								<button type="submit"  value="je" name="btn_journalentry" class="btn btn-primary"> Update </button>
<select class="form-control" name="branch"  required>
	
	<option value="no"  >--select branch</option>

	
	<?php 
	
	
	
			 
					 		$maincategory = $this->usermodel->populateall('branch','id',$allsalesdetails[0]['branch']);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No Branch/Counter.';
}
				 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No Branch/Counter.';
}
	
?>
</select>
 
  					<?php  echo form_close();?>
								
								</th>
								
							</tr>
								
						</thead>
							</table>
						
			
					
					
					
					
					
					
										   
				
									
							
								
			<div class="modal-footer">

    

				</div>

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

 
</div>


















