<?php
	/*
<div class="col-lg-12">
	<ul class="breadcrumb">
		<li><i class="fa fa-home"></i><a href="/home">Home</a></li>
		<!--<li><a href="#">Forms</a></li>-->
		<li class="active">Designation</li>
	</ul>
</div>
*/
?>
<div class="content">
	<div class="main-content">
		<div class="row">
			
			<div class="col-md-4">
				<!-- ADVANCED VALIDATION -->
				<div class="widget">
					<div class="widget-header">
					<h3><i class="fa fa-check-circle"></i>Tariff Chart</h3></div>
					<div class="widget-content">
						<form id="frmmain" name="frmmain" data-parsley-validate novalidate>
							<input type="hidden" name="_token" value="{{ csrf_token() }}">
						    <?php
							/*
							<div class="alert  alert-info " >
								<ul><li class="fa fa-cog  fa-1x fa-fw"></li>Kindly enter Unit..</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="form-group">
								<label for="text-input1">Unit(From)*</label>
								<input type="text" name="ufrm" id="ufrm" class="form-control" >
								<input type="hidden" name="pk" id="pk" class="form-control" >
								
								<small class="text-danger" id="errusertype"></small>
							</div>
									<div class="form-group">
								<label for="text-input1">Unit(To)*</label>
								<input type="text" name="uto" id="uto" class="form-control" >
								
								<small class="text-danger" id="errusertype"></small>
							</div>
									<div class="form-group">
								<label for="text-input1">Tariff Charge*</label>
								<input type="text" name="tch" id="tch" class="form-control" >
								
								<small class="text-danger" id="errusertype"></small>
							</div>
							
								<div class="form-group">
								<label for="text-input1">Tariff Charge(Range)*</label>
								<input type="text" name="tchrg" id="tchrg" class="form-control" >
								
								<small class="text-danger" id="errusertype"></small>
							</div>
							<div class="form-group">
								<label for="multiselect1">Status*</label>
								<br/>
                                <select name="status" id="status" class="form-control" required>
                                    <option value="Active">Active</option>
                                    <option value="Inactive">Inactive</option>
								</select>
								<small class="text-danger" id="errstatus"></small>
							</div>
							<br/>
							<button type="submit" id="submit" name="submit" class="btn btn-primary userType">Submit</button>
						</form>
					</div>
				</div>
				<!-- END ADVANCED VALIDATION -->
			</div>
			
			<div class="col-md-8">
				
				
					
				<!-- BASIC VALIDATION -->
				<div class="widget widget-table">
					<div class="widget-header">
						<h3><i class="fa fa-table"></i> View Tariff Chart</h3> 
					</div>
					<div class="widget-content">
					
					
<div class="form-group col-md-8">
		<label for="multiselect1">Tariff type*</label>
		<select name="tarifftype" id="tarifftype" class="form-control" required>
			<option value="">Select</option>
			
		</select>
</div>
<div class="form-group col-md-4">
		<br>
		<button type="submit" id="btnloadrec" name="btnloadrec" class="btn btn-primary userType">Load Record</button>
</div>
		
					
						<table id="datatable-data-export" class="table table-sorting table-striped table-hover table-bordered datatable">
							<thead>
								<tr>
									<th>Unit(From)</th>
									<th>Unit(To)</th>
									<th>Charge Range</th>
									<th>Status</th>
									<th>Action</th>
								</tr>
							</thead>
							<tbody>
								@foreach($data as $value)
									<tr>
										<td>{{ $value-> tarc_unitfrom }}</td>
										<td>{{ $value-> tarc_unitto }}</td>
										<td>{{ $value-> tarc_tariffrange }}</td>
										<td>{{ $value-> tarc_status }}</td>
										<td><button class ="btn btn-default" onclick="editname({{ $value-> tarc_id }})" > Edit </button>&nbsp;<button class ="btn btn-default" onclick="delrec({{ $value-> tarc_id }})" >Delete </button></td>		
									</tr>
								@endforeach								
							</tbody>
						</table>
						
					</div>
				</div>
				<!-- END BASIC VALIDATION -->
			</div>
			
		</div>
	</div>
</div>
<script> 

</script>

<script type="application/javascript">
	
	$('.userType').click(function(e)
	{
	   e.preventDefault();
		$.ajax({
			url: 'tcinsert',
			type: 'POST',
			data:$('#frmmain').serialize(),
			success: function(data) 
			{
			   $('#sideMenu').load('/viewtariffchart');
				alert("Success");
				$("input[name='tch']").val('');	
			$("input[name='tchrg']").val('');	
			$("input[name='ufrm']").val('');	
			$("input[name='uto']").val('');	
				$("[name='status']").val('Active');
			}
			
		});
	});
	/*i=0;
	
	$(document).on('submit', '#frmmain', function()
	{
		$(".alert-info").find("ul").html('<li class="fa fa-cog fa-spin fa-1x fa-fw"></li>Processing...');
		
		var _token = $("input[name='_token']").val();
		var usertype = $("input[name='usertype']").val();
		var description = $("#description").val();
		var status = $("#status").val();
		
		document.getElementById("errusertype").innerHTML = "";
		
		if(usertype == "")
		{
			document.getElementById("errusertype").innerHTML = "User type 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(i==0)
			{ 
				i++;
				//alert(i);
				$.ajax({
					url: "/utype",
					type:'POST',
					data: {_token:_token, usertype:usertype, description:description, status:status},
					success: function(data) {											
						if(data.status == 1)
						{
							printSuccessMsg(data.message);
							$('#sideMenu').load('usertype');
						}
						else
						{
							printErrorMsg(data.message)
						}
					}
				});					   
			}							
		}							
		
		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);
			//Code to redirect page
			//var url = "/dashboard";
			//$(location).attr('href',url);
		}
		return false;
	});*/
	function editname(id)
	{
	 $.ajax({
			type: "GET",
			url:"/editUserType",
			dataType: "json",
			data: {
				'_token': $('input[name=_token]').val(),
				'id': id
			},
			success: function (data) {
		
				$.each(data,function(i,obj)
				{
					
					$('#pk').val(obj.tarc_id);
					$('#ufrm').val(obj.tarc_unitfrom);
		 	        $('#uto').val(obj.tarc_unitto);
					$('#tch').val(obj.tarc_tariffcharge);
					$('#tchrg').val(obj.tarc_tariffrange); 
					$('#status').val(obj.tarc_status); 
					// $('#btnadd').val("UPDATE"); 
				});  
			}
		}); 
		
	}
	function delrec(id)
	{
		k = 0;
		if(confirm("Are u Sure U Want To Delete?")==1)
		{
			k++;
			$.ajax({
				type: "GET",
				url:"/deltchart",
				data:'&id='+id,
				success: function (sdata)
				{
				 alert("Success");
				 $('#sideMenu').load('/viewtariffchart');
				}
			});
		}		
	}
	
	$(document).ready(function(){
	 $.ajax({
            type: "GET",
            url:"/listtarifftype",
            dataType: "json",
            success: function (data) {
                $.each(data,function(i,obj)
                {
				var div_data="<option value="+obj.cmp_id+">"+obj.cmp_name+ "  (" +obj.cmp_type+")</option>";	
                $(div_data).appendTo('#compname'); 
                });  
                }
          });
        });		
</script>					  