 <?php 
 if($_POST)
 {
	$consignee_name 			        =		set_value('consignee_name',$_POST['consignee_name']);
	$consignee_addr1 			        =		set_value('consignee_addr1',$_POST['consignee_addr1']);
	$consignee_addr2 			        =		set_value('consignee_addr2',$_POST['consignee_addr2']);
	$consignee_addr3 			        =		set_value('consignee_addr3',$_POST['consignee_addr3']);
	$consignee_addr4 			        =		set_value('consignee_addr4',$_POST['consignee_addr4']);
	// $consignee_country_id 			    =		set_value('consignee_country_id',$_POST['consignee_country_id']);
	// $consignee_state_id 			    =		set_value('consignee_state_id',$_POST['consignee_state_id']);
	// $consignee_pin 			            =		set_value('consignee_pin',$_POST['consignee_pin']);
	$consignee_con_person 			    =		set_value('consignee_con_person',$_POST['consignee_con_person']);
	$consignee_con_no 			        =		set_value('consignee_con_no',$_POST['consignee_con_no']);
	$consignee_alt_no 			        =		set_value('consignee_alt_no',$_POST['consignee_alt_no']);
	$consignee_fax 			            =		set_value('consignee_fax',$_POST['consignee_fax']);


}
else
{
	$consignee_name 			        =		'';
	$consignee_addr1			        =		'';
	$consignee_addr2 			        =		'';
	$consignee_addr3			        =		'';
	$consignee_addr4 			        =		'';
	// $consignee_country_id			    =		'';
	// $consignee_state_id 			    =		'';
	// $consignee_pin			            =		'';
	$consignee_con_person 			    =		'';
	$consignee_con_no			        =		'';
	$consignee_alt_no 			        =		'';
	$consignee_fax			            =		'';
	
	
}
 ?>
 <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="add_consignee" name="add_consignee" action="<?php echo base_url();?>General_masters/add_consignee" method="post">
    	<div class="col-md-4">
            <!-- <div class="form-group">
                <label>Parent Ledger Group Name</label><?php echo form_error('parent_id');?>
                <select class="form-control select2" id="parent_id" name="parent_id">
                	<option value="">Select Parent Ledger Group Name</option>
                  	<?php foreach($ledger_drpdwn as $row)
                  	{?>
                  		<option value="<?php echo $row['ledger_group_id'];?>" <?php if($parent_id==$row['ledger_group_id'])echo "selected";?>><?php echo $row['ledger_group_name'];?></option>
                  	<?php }?>                	
                </select>             
            </div> -->
	        <div class="form-group">
	            <label>Consignee Name</label><?php //echo form_error('consignee_name');?>
	            <input type="text" class="form-control" pattern="^[-_a-zA-Z0-9]+(\s+[-_a-zA-Z0-9]+)*$" placeholder="Enter Consignee Name..." id="consignee_name" name="consignee_name" value="<?php echo $consignee_name;?>">
	        </div>
	        <div class="form-group">
	            <label>Address Line 1</label><?php //echo form_error('consignee_addr1');?>
	            <textarea class="form-control" rows="5" placeholder="Enter Address Line 1..." id="consignee_addr1" name="consignee_addr1"><?php echo $consignee_addr1;?></textarea>
	        </div>
	        <div class="form-group">
	            <label>Address Line 2</label><?php //echo form_error('consignee_addr2');?>
	            <textarea class="form-control" rows="5" placeholder="Enter Address Line 2..." id="consignee_addr2" name="consignee_addr2"><?php echo $consignee_addr2;?></textarea>
	        </div>
	         <div class="form-group">
	            <label>Address Line 3</label><?php //echo form_error('consignee_addr2');?>
	            <textarea class="form-control" rows="5" placeholder="Enter Address Line 3..." id="consignee_addr3" name="consignee_addr3"><?php echo $consignee_addr3;?></textarea>
	        </div>
	         <div class="form-group">
	            <label>Address Line 4</label><?php //echo form_error('consignee_addr2');?>
	            <textarea class="form-control" rows="5" placeholder="Enter Address Line 4..." id="consignee_addr4" name="consignee_addr4"><?php echo $consignee_addr4;?></textarea>
	        </div>
	       <!--  <div class="form-group">
                <label>Country</label><?php //echo form_error('consignee_country_id');?>
                <select class="form-control select2" id="consignee_country_id" name="consignee_country_id">
                    <option value="">Select Country</option>
                    <?php foreach($country_drpdwn as $row)
                    {?>
                        <option value="<?php echo $row['country_id'];?>" <?php if($consignee_country_id==$row['country_id'])echo "selected";?>><?php echo $row['name'];?></option>
                    <?php }?>                   
                </select>                
            </div> -->
            <!-- <div class="form-group">
                <label>State</label><?php //echo form_error('consignee_state_id');?>
                <select class="form-control select2" id="consignee_state_id" name="consignee_state_id">
                    <option value="">Select State</option>
                    <?php foreach($state_drpdwn as $row)
                    {?>
                        <option value="<?php echo $row['state_id'];?>" <?php if($consignee_state_id==$row['state_id'])echo "selected";?>><?php echo $row['state'];?></option>
                    <?php }?>
                </select>
            </div> --> 
           <!--  <div class="form-group">
	            <label>Pincode</label><?php //echo form_error('consignee_pin');?>
	            <input type="text" class="form-control" placeholder="Enter consignee PIN..." id="consignee_pin" name="consignee_pin" value="<?php echo $consignee_pin;?>">
	        </div>
	         -->
	       
	        
	    </div>
    	<div class="col-md-4">
	        <div class="form-group">
	            <label>Contact Person</label><?php //echo form_error('consignee_con_person');?>
	            <input type="text" class="form-control" placeholder="Enter Contact Person..." id="consignee_con_person" name="consignee_con_person" value="<?php echo $consignee_con_person;?>">
	        </div>
	        <div class="form-group">
	            <label>Contact Number</label><?php //echo form_error('consignee_con_no');?>
	            <input type="text" class="form-control" placeholder="Enter Contact Number..." id="consignee_con_no" name="consignee_con_no" value="<?php echo $consignee_con_no;?>">
	        </div>
	        <div class="form-group">
	            <label>Alternate Number</label><?php //echo form_error('consignee_alt_no');?>
	            <input type="text" class="form-control" placeholder="Enter Alternate Number..." id="consignee_alt_no" name="consignee_alt_no" value="<?php echo $consignee_alt_no;?>">
	        </div>
	        <div class="form-group">
	            <label>Fax</label><?php //echo form_error('consignee_fax');?>
	            <input type="text" class="form-control" placeholder="Enter Fax..." id="consignee_fax" name="consignee_fax" value="<?php echo $consignee_fax;?>">
	        </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/consignee"><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 consignee</label></h4>
    		<div class="box box-warning">
			    <table class="table table-bordered table-hover">
			        <thead>
			            <tr>
			                <th>Name</th>
			                <th>Contact Person</th>
			                <th>Contact Number</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_consignee/<?php echo $row['consignee_id'];?>"><strong><?php echo $row['consignee_name'];?></strong></a></td>
		    						<td><?php echo $row['consignee_con_person'];?></td>
		    						<td><?php echo $row['consignee_con_no'];?></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/consignee"><strong>View Consignee Lists</strong></a>
		    </div>
	    </div>
	</form>
    <!-- /.box-body -->
</div>

<script type="text/javascript">
	$(function()
	{
		setTimeout(country_select);
        setTimeout(state_select);
	});

	function country_select()
	{
		$("#consignee_country_id").select2({
			ajax: { 
				dataType: 'json', 
				url: '<?php echo base_url();?>General_masters/get_countries',
				cache: true,
				data: function (params) 
					{
						return {
							q: params.term
						}
					}
			}
		});
	}
	function state_select()
	{
		$("#consignee_state_id").select2({
			ajax: { 
				dataType: 'json', 
				url: '<?php echo base_url();?>General_masters/get_state_by_country',
				cache: true,
				data: function (params) 
					{
						return {
							q: params.term,
							country_id:$('#consignee_country_id').val()
						}
					}
			}
		});
	}

	
</script>