
			<!-- main -->
			<div class="content">
            
				<div class="main-content">
					<!-- DATA EXPORT -->
					<div class="widget widget-table">
						<div class="widget-header">
							<h3><i class="fa fa-user"></i> Employee</h3> <em> - Add Employee record</em>
						</div>
						<div class="widget-content">
<form id="frmmain" name="frmmain" data-parsley-validate novalidate>
<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">						
						
<div class="alert  alert-info " >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li>Kindly enter Employee Details..</ul>
</div>						
<div class="alert alert-success print-success-msg" style="display:none">
    <ul></ul>
</div>	
<div class="alert alert-danger print-error-msg" style="display:none">
    <ul></ul>
</div>
						
<div class="col-md-6">
							<!-- ADVANCED VALIDATION -->
								<div class="widget-content">  
                        <div class="form-group">
						<input type="hidden" class="form-control" id="usr_id" name="usr_id" value="<?php echo e(isset($data) ? $data[0]->usr_id : '0'); ?>">
						 <input type="hidden" id="ut_id" name="ut_id" value="<?php echo e(isset($data) ? $data[0]->ut_id : '0'); ?>">
                            <label for="multiselect1">User type*</label>
                                <select name="usertype" id="usertype" class="form-control" data-live-search="true" required>
								<option value="0">-- Select --</option>
                                </select>
                            <small class="text-danger" id="errusertype"></small>
                        </div>
                        <div class="form-group">
						 <input type="hidden" id="br_id" name="br_id" value="<?php echo e(isset($data) ? $data[0]->br_id : '0'); ?>">
                            <label for="text-input1">Select Branch*</label>
                                <select name="branch" id="branch" class="form-control" required>
                                    <option value="0">-- Select --</option>
                                </select>
								<small class="text-danger" id="errbranch"></small>
                        </div>
                        <div class="form-group">
                            <label for="text-input1">Employee name*</label>
                            <input type="text" name="empname" id="empname" class="form-control" value="<?php echo e(isset($data) ? $data[0]->usr_name : ''); ?>">
                            <small class="text-danger" id="errempname"></small>
                        </div>
                        <div class="form-group">
                            <label for="text-input1">Login ID</label>
                            <input type="text" name="loginid" id="loginid" class="form-control" value="<?php echo e(isset($data) ? $data[0]->usr_loginid : ''); ?>" onchange="validateLoginID(this.value)">
                            <small class="text-danger" id="errloginid"></small>
                        </div>
                        <div class="form-group">
                            <label for="text-input1">Password</label>
                            <input type="password" name="password" id="password" class="form-control">
                            <small class="text-danger" id="errpassword"></small>
                        </div>
                        <div class="form-group">
                         <label for="text-input1">Confirm Password</label>
                 <input type="password" name="cpassword" id="cpassword" class="form-control" >
                            <small class="text-danger" id="errcpassword"></small>
                        </div>
                   
								</div>
							<!-- END ADVANCED VALIDATION -->
</div>
							
<div class="col-md-6">
							<!-- ADVANCED VALIDATION -->
								<div class="widget-content">
                        <div class="form-group">
                            <label for="text-input1">Contact No. 1*</label>
                            <input type="text" name="contact1" id="contact1" class="form-control" value="<?php echo e(isset($data) ? $data[0]->usr_contact1 : ''); ?>">
                            <small class="text-danger" id="errcontact1"></small>
                        </div>
                        <div class="form-group">
                            <label for="text-input1">Contact No. 2</label>
                            <input type="text" name="contact2" id="contact2" class="form-control" value="<?php echo e(isset($data) ? $data[0]->usr_contact2 : ''); ?>">
                            <small class="text-danger" id="errcontact2"></small>
                        </div>
                        <div class="form-group">
                            <label for="text-input1">Email ID</label>
                            <input type="text" name="emailid" id="emailid" class="form-control" value="<?php echo e(isset($data) ? $data[0]->usr_emailid : ''); ?>">
                            <small class="text-danger" id="erremailid"></small>
                        </div>
                        <div class="form-group">
                            <label for="text-input1">Note</label>
							<textarea name="note" id="note" class="form-control" rows="5" cols="30"><?php echo e(isset($data) ? $data[0]->usr_note : ''); ?></textarea>
                            <small class="text-danger" id="errnote"></small>
                        </div>
                        <div class="form-group">
                            <label for="multiselect1">Status*</label>
                            <br/>
                                 <select name="status" id="status" class="form-control" required>
                                    <option value="Active" 
									<?php if(isset($data)): ?>
									<?php if($data[0]->usr_status == "Active"): ?>
										selected='selected' 
									<?php endif; ?>
									<?php endif; ?>
									> Active</option>
                                    <option value="Inactive"
									<?php if(isset($data)): ?>
									<?php if($data[0]->usr_status == "Inactive"): ?>
										selected='selected' 
									<?php endif; ?>
									<?php endif; ?>
									>Inactive</option>
                                </select>
                            <small class="text-danger" id="errstatus"></small>
                        </div>
								</div>
							<!-- END ADVANCED VALIDATION -->
</div>
<div class="col-md-12">
                       <div class="form-group">
                            <center><button type="submit" id="submit" name="submit" class="btn btn-primary">Add User</button></center>
                        </div>
</div>                        
                    </form>
                    
						</div>
					</div>
					<!-- END DATA EXPORT -->

				</div>
			</div>
			<!-- /main -->
			
			<script type="application/javascript">
	i = 0;
	$(document).ready(function()
	  {
	   $(document).on('submit', '#frmmain', function()
	   {
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-spin fa-1x fa-fw"></li>Inserting record...');
			   
				var _token = $("input[name='_token']").val();
				var usr_id = $("#usr_id").val();
				var usertype = $("#usertype").val();
				var branch =  $('#branch').val();
				var empname =  $('#empname').val();
				var loginid =  $('#loginid').val();
				var password =  $('#password').val();
				var cpassword =  $('#cpassword').val();
				var contact1 =  $('#contact1').val();
				var contact2 =  $('#contact2').val();
				var emailid =  $('#emailid').val();
				
				var description = $('#note').val();
				var status = $('#status').val();
				
				
				document.getElementById("errusertype").innerHTML = "";
				document.getElementById("errbranch").innerHTML = "";
				document.getElementById("errempname").innerHTML = "";
				document.getElementById("errcontact1").innerHTML = "";
				document.getElementById("errcpassword").innerHTML = "";
		   
		   if(usertype == "0")
		   {
				document.getElementById("errusertype").innerHTML = "Usertype should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
		   }
		   else if(branch == "0")
		   {
				document.getElementById("errbranch").innerHTML = "Branch should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
		   }
		   else if(empname == "")
		   {
				document.getElementById("errempname").innerHTML = "Employee Name should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
		   }
		   else if(contact1 == "")
		   {
				document.getElementById("errcontact1").innerHTML = "Contact Number should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
		   }
		   else if(password != "" && cpassword != "" && password != cpassword)
		   {
			   document.getElementById("errcpassword").innerHTML = "Password Missmatch..";
			  $(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
		   }
		   else
		   {						   
				if(i == 0)
				{
					i++;
					$.ajax({
					url: "/user",
					type:'POST',
					data: {_token:_token, 
					'usr_id':usr_id,
					'usertype':usertype, 
					'branch':branch, 
					'empname':empname, 
					'loginid':loginid,
					'password':password, 
					'contact1':contact1, 
					'contact2':contact2, 
					'emailid':emailid, 
					'description':description,
					'status':status
					},
					success: function(data) {
						
						if(data.status == 1)
						{
							
							printSuccessMsg(data.message);
							$('#sideMenu').load('viewuser');
						}
						else
						{
							printErrorMsg(data.message)
						}
						
					}
				});	
				}
								   
		   }
		return false;
	   });

});

function printErrorMsg (msg) {				
		$(".alert-info").css('display','none');
		$(".print-success-msg").css('display','none');
		$(".print-error-msg").find("ul").html('');
		$(".print-error-msg").css('display','block');
		$(".print-error-msg").find("ul").append('<li class="fa fa-times-circle fa-1x fa-fw"></li>'+msg);
	}
			
	function printSuccessMsg (msg) {
		$(".alert-info").css('display','none');
		$(".print-error-msg").css('display','none');
		$(".print-success-msg").find("ul").html('');
		$(".print-success-msg").css('display','block');
		$(".print-success-msg").find("ul").append('<li class="fa fa-check  fa-1x fa-fw"></li>'+msg);
	}	
		
	
			//load branch
			$(document).ready(function(){
				var br_id = $('#br_id').val();
		$.ajax({
            type: "GET",
            url:"/loadbranch",
            dataType: "json",
            success: function (data) {
                $.each(data,function(i,obj)
                {
					if(br_id ==0)
					{
						var div_data="<option value="+obj.br_id+">"+obj.br_name+"</option>";	
					}
					else 
					{
						if(br_id == obj.br_id)
						{
							var div_data="<option value="+obj.br_id+" selected>"+obj.br_name+"</option>";	
						}
						else{
							var div_data="<option value="+obj.br_id+">"+obj.br_name+"</option>";		
						}
					}
				 $(div_data).appendTo('#branch'); 
                });  
                }
          });
        });
		
		//load usertype
		$(document).ready(function(){
			var ut_id = $('#ut_id').val();
		$.ajax({
            type: "GET",
            url:"/loadusertype",
            dataType: "json",
            success: function (data) {
                $.each(data,function(i,obj)
                {
					if(ut_id ==0)
					{
						var div_data="<option value="+obj.ut_id+">"+obj.ut_type+"</option>";	
					}
					else 
					{
						if(ut_id == obj.ut_id)
						{
							var div_data="<option value="+obj.ut_id+" selected>"+obj.ut_type+"</option>";	
						}
						else{
							var div_data="<option value="+obj.ut_id+">"+obj.ut_type+"</option>";		
						}
					}
					
                $(div_data).appendTo('#usertype'); 
                });  
                }
          });
        });
		
		function validateLoginID(loginid)
		{
			var _token = $("input[name='_token']").val();
			$.ajax({
            type: "GET",
            url:"/validateloginid",
            dataType: "json",
			data:{
			_token:_token, 
			'loginid':loginid	
			},
            success: function (data) {
					if(data.length > 0)
					{
						$('#loginid').val('');
					  document.getElementById("errloginid").innerHTML = "Login ID Already Exists..";
					  $(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
					}
					else{
						document.getElementById("errloginid").innerHTML = "";
					}
                }
          });
		}
			</script>