 <?php 
 if($_POST)
 {
	$ledger_master_id 			   =		set_value('ledger_master_id',$_POST['ledger_master_id']);
	$ledger_name 			       =		set_value('ledger_name',$_POST['ledger_name']);
	$parent_ledger_group_id 	   =		set_value('parent_ledger_group_id',$_POST['parent_ledger_group_id']);
	$ledger_type 			       =		set_value('ledger_type',$_POST['ledger_type']);
	$opening_balance 			   =		set_value('opening_balance',$_POST['opening_balance']);
	$account_type 			       =		set_value('account_type',$_POST['account_type']);
    $reconciliation 			   =		set_value('reconciliation',$_POST['reconciliation']);
	$ledgre_notes 			       =		set_value('ledgre_notes',$_POST['ledgre_notes']);
	$ledger_company_id 			   =		set_value('ledger_company_id',$_POST['ledger_company_id']);
	$ledger_branch_id 			   =		set_value('ledger_branch_id',$_POST['ledger_branch_id']);
	 
}
else
{
	$ledger_master_id 			  =		$edit_ledger->ledger_master_id;
	$ledger_name			      =		$edit_ledger->ledger_name;
	$parent_ledger_group_id		  =		$edit_ledger->parent_ledger_group_id;
	$ledger_type 			      =	    $edit_ledger->ledger_type;
	$opening_balance			  =		$edit_ledger->opening_balance;
	$account_type 			      =		$edit_ledger->account_type;
	$reconciliation			      =		$edit_ledger->reconciliation;
	$ledgre_notes 			      =		$edit_ledger->ledgre_notes;
	$ledger_company_id			  =		$edit_ledger->ledger_company_id;
	$ledger_branch_id 			  =		$edit_ledger->ledger_branch_id;
 
}
 ?>
 <div class="box-body">
 	<div style="color:red;" class="error"><strong><?php if($this->session->flashdata('error')){ echo $this->session->flashdata('error');} ?></strong></div>
<form role="form" id="edit_ledger" name="edit_ledger" action="<?php echo base_url();?>General_masters/edit_ledger/<?php echo $ledger_master_id;?>" method="post">
    	<input type="hidden" id="ledger_master_id" name="ledger_master_id" value="<?php echo $ledger_master_id;?>">

    	<div class="col-md-4">
		<div class="form-group">
                <label>Company</label><?php echo form_error('ledger_company_id');?> 
                <select class="form-control select2" id="ledger_company_id" name="ledger_company_id">
                	<option value="">Select Company</option>
                  	<?php 
					foreach($company_drpdwn as $row)
                  	{?>
                  		<option value="<?php echo $row['cmp_id'];?>" <?php if($ledger_company_id==$row['cmp_id'])echo "selected";?>><?php echo $row['cmp_name'];?></option>
                  	<?php }?>                	
                </select>             
            </div>
	        <div class="form-group">
                <label>Branch</label><?php echo form_error('ledger_branch_id');?>
                <select class="form-control select2" id="ledger_branch_id" name="ledger_branch_id">
                	<option value="">Select Branch</option>
                  	<?php foreach($branch_drpdwn  as $row)
                  	{?>
                  		<option value="<?php echo $row['branch_id'];?>" <?php if($ledger_branch_id==$row['branch_id'])echo "selected";?>><?php echo $row['branch_name'];?></option>
                  	<?php }?>                	
                </select>             
            </div>
            <div class="form-group">
                <label>Parent Ledger Group Name</label><?php echo form_error('parent_ledger_group_id');?>
                <select class="form-control select2" id="parent_ledger_group_id" name="parent_ledger_group_id">
                	<option value="">Select Ledger Group Name</option>
                  	<?php foreach($ledger_drpdwn as $row)
                  	{?>
                  		<option value="<?php echo $row['ledger_group_id'];?>" <?php if($parent_ledger_group_id==$row['ledger_group_id'])echo "selected";?>><?php echo $row['ledger_group_name'];?></option>
                  	<?php }?>                	
                </select>             
            </div>
	        <div class="form-group">
	            <label>Ledger Name</label><?php echo form_error('ledger_name');?>
	            <input type="text" class="form-control" placeholder="Enter Ledger Group Name..." id="ledger_name" name="ledger_name" value="<?php echo $ledger_name;?>">
	        </div>
	        <div class="form-group">  
	            <label>Ledger Type</label> <select class="form-control select2" id="ledger_type" name="ledger_type">
 					<option value="">Select Ledger Type</option>
                  	<?php foreach($ladeger_type_data as $key=>$value)
                  	{?>
                  		<option value="<?php echo $key;?>" <?php if($ledger_type==$key)echo "selected";?>><?php echo $value;?></option>
                  	<?php }?> 
 				</select>
	        </div>
			
	    </div>
    	<div class="col-md-4">
	        <div class="form-group">
	            <label>Opening Balance</label><?php echo form_error('opening_balance');?>
	            <input type="text" class="form-control" placeholder="Enter Opening Balance..." id="opening_balance" name="opening_balance" value="<?php echo $opening_balance;?>">
	        </div>
	        
	       <div class="form-group">
	            <label>Account Type</label><?php echo form_error('account_type');?>
	            <select class="form-control select2" id="account_type" name="account_type">
                	<option value="">Select Account Type</option>
                  	<?php foreach($account_type_data as $key=>$value)
                  	{?>
                  		 <option value="<?php echo $key;?>" <?php if($account_type==$key)echo "selected";?>><?php echo $value;?></option>
                  	<?php }?>                	
                </select>       
	        </div> 
	        
	        <div class="form-group">
                <label>Reconciliation </label> 
             &nbsp;<input name="reconciliation" type="checkbox" value="<?php echo $reconciliation ; ?>" <?php if($reconciliation == '1') {?> checked="checked" <?php } ?> />
            </div><div class="form-group">
                <label>Notes</label><?php echo form_error('parent_id');?>
              <textarea class="form-control" rows="5" placeholder="Enter Notes..." id="ledgre_notes" name="ledgre_notes"><?php  echo $ledgre_notes;?></textarea>       
            </div>
	        
            <div class="form-group">
            <div class="col-md-6"></div>
            	<div class="col-md-6"><input type="submit" id="submit" name="submit" class="btn btn-info" value="Save">
            	<a href="<?php echo base_url()?>General_masters/Ledger"><button type="button" class="btn btn-warning">Cancel</button></a></div>
            </div>
	    </div>
    	<div class="col-md-4 form-group has-warning">
    		<h4><label>Recently Listed Ledger </label></h4>
    		<div class="box box-warning">
			    <table class="table table-bordered table-hover">
			        <thead>
			            <tr>
			                <th>Ledger Name</th>
			                <th>Ledger Group Name</th>
							 <th>Company</th>
							  <th>Branch</th>
			                
			            </tr>
			        </thead>
			        <tbody>
	        			<?php if(count($recent_list)!=0)
	        			{
	        				foreach($recent_list as $row)
	        				{?>
		    					<tr>
		    						<td><a href="<?php echo base_url();?>General_masters/edit_ledger/<?php echo $row['ledger_master_id'];?>"><strong><?php echo $row['ledger_name'];?></strong></a></td>
		    						<td><?php echo $row['parent'];?></td>
										<td><?php echo $row['companyname'];?></td>
											<td><?php echo $row['branch_name'];?></td>
		    					 
		    					</tr>
	        				<?php }
	        			}
	        			else
	        			{?>
	        				<tr><td colspan="3">Data Not Found</td></tr>
	        			<?php }?>
			        </tbody>
			    </table>
			    <a class="text-red" href="<?php echo base_url();?>General_masters/ledger"><strong>View All Ledger Lists</strong></a>
		    </div>
	    </div>
	</form>
    <!-- /.box-body -->
</div>

<script type="text/javascript">
	$(function()
	{
		setTimeout(company_select);
	});
	function company_select()
	{
		$("#branch_cmp_id").select2({
			ajax: { 
				dataType: 'json', 
				url: '<?php echo base_url();?>General_masters/get_company',
				cache: true,
				data: function (params) 
					{
						return {
							q: params.term
						}
					}
			}
		});
	}
</script>
<script language="javascript">
$(document).ready(function() {
    $("#opening_balance").keydown(function (e) {
        // Allow: backspace, delete, tab, escape, enter and .
        if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
             // Allow: Ctrl+A
            (e.keyCode == 65 && e.ctrlKey === true) ||
             // Allow: Ctrl+C
            (e.keyCode == 67 && e.ctrlKey === true) ||
             // Allow: Ctrl+X
            (e.keyCode == 88 && e.ctrlKey === true) ||
             // Allow: home, end, left, right
            (e.keyCode >= 35 && e.keyCode <= 39)) {
                 // let it happen, don't do anything
                 return;
        }
        // Ensure that it is a number and stop the keypress
        if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
            e.preventDefault();
        }
    });
});
</script>