@extends('backend.header')
@section('index-content')
<style>
	select{
		height: 40px;
	}
</style>
<div class="row px-3">


	<section role="main" class="content-body">
		<header class="page-header">
			<h2>Admin Approve Survey List</h2>
		</header>
		<div class="row">
			<div class="col-xs-12">
				<div class="right-wrapper">
					<ol class="breadcrumbs">
						<li>
							<a href="{{url('index')}}">
								<i class="fa fa-home"></i>
							</a>
						</li>
						<li><span class="active">Admin Approve Survey List</span></li>
					</ol>
				</div>
			</div>
		</div>

		<!-- start: page -->
		<section class="panel mt-4">
			<header class="panel-heading">
				<h4 class="my-0">Admin Approve Survey List</h4>	
				<div class="panel-actions">
					<a href="#" class="fa fa-caret-down"></a>
					<a href="#" class="fa fa-times"></a>
				</div>

				<!--<h2 class="panel-title">सर्वेक्षण तपशील</h2>-->
			</header>
			@if(session('error'))
						<div class="alert alert-danger">{{session('error')}}</div>
						@endif
						@if(session('success'))
						<div class="alert alert-success">{{session('success')}}</div>
						@endif
			<form action="{{url('status_update_by_admin')}}" method="post">
				@csrf
				<div class="panel-body">
					<div class="row px-3">
						<div class="col-md-3 px-2">
							<h4>District Name</h4>
							<select name="jilla" id="jilla_id" class="w-100" required>
								<option value="">District Name</option>

								@foreach($jilla as $j)
								<option value="{{$j->id}}">{{$j->area_name}}</option>
								@endforeach
							</select>

						</div>
						<div class="col-md-3 px-2">
							<h4>Mandal Name</h4>
							<select name="taluka" class="w-100" id="taluka" required>
								<option value="">Mandal Name</option>   
							</select>
						</div>
						<div class="col-md-3 px-2">
							<h4>Panchayat Name</h4>
							<select name="gram" class="w-100" id="gram_id" required>
								<option value="">Panchayat Name</option>
							</select>
						</div>
						<div class="col-md-3 px-2">
							<h4>Phases</h4>
							<select name="phase_no" class="w-100" id="phase_no" required>
								<option value="">Select Phase</option>
							</select>
						</div>
						<div class="col-md-3 px-2">
							<h4>Status</h4>
							<select name="status" class="w-100" id="status" required>
								<option value="0">Pending</option>
								<option value="1">Approve</option>
								<option value="2">Reject</option>
							</select>
						</div>
					</div>
					<div class="row">
						<div class="col-12 px-3">
							<div class="text-right mt-3 pr-2">
								<input type="submit" class="btn btn-success" value="Submit" id="surveyfilter">
							</div>
						</div>
					</div>
				</div>
			</form>
		</section>

		<section class="panel mt-4">
			<header class="panel-heading">
				<h4 class="my-0">Admin Approve Invoice List</h4>	
				<div class="panel-actions">
					<a href="#" class="fa fa-caret-down"></a>
					<a href="#" class="fa fa-times"></a>
				</div>
			</header>
		
			<form action="{{url('admin_update_invoice_status')}}" method="post">
				@csrf
				<div class="panel-body">
					<div class="row px-3">
						<div class="col-md-3 px-2">
							<h4>District Name</h4>
							<select name="jilla" id="district_id" class="w-100" required>
								<option value="">District Name</option>

								@foreach($jilla as $j)
								<option value="{{$j->id}}">{{$j->area_name}}</option>
								@endforeach
							</select>

						</div>
						<div class="col-md-3 px-2">
							<h4>Type</h4>
							<select name="type" class="w-100" id="type" required>
								<option value="">Select Type</option>   
								<option value="1">Lights</option>   
								<option value="2">Arms/Clamps</option>   
								<option value="3">CCMS</option>   
							</select>
						</div>
						<div class="col-md-3 px-2">
							<h4>Invoice Number</h4>
							<select name="invoice_number" class="w-100" id="invoice_number" required>
								<option value="">Invoice Number</option>
							</select>
						</div>
						
						<div class="col-md-3 px-2">
							<h4>Status</h4>
							<select name="status" class="w-100" id="invoice_status" required>
								<option value="0">Pending</option>
								<option value="1">Approve</option>
								<option value="2">Reject</option>
							</select>
						</div>
					</div>
					<div class="row">
						<div class="col-12 px-3">
							<div class="text-right mt-3 pr-2">
								<input type="submit" class="btn btn-success" value="Submit" id="surveyfilter">
							</div>
						</div>
					</div>
				</div>
			</form>
		</section>

		
</section>

</div>

<script type="text/javascript">
	$("#gram_id").on("change",function()
				{
					var id=$(this).val();
			
			$.ajax({
				url:'{{url("/gram_survey_phase_status")}}/'+id,
				method:'get',
				dataType:"json",
				success:function(data)
				{
					var dataRow="<option value=''>Select Phase</option>";
					data.forEach(el => {
                   
                    dataRow+= `<option value="${el.phase_no}">Phase - ${el.phase_no}</option>`;
                                });
                       $("#phase_no").html(dataRow);
                  
				},	
				error:function(data)
				{
					$("#status").val("0");
				}
			});
		});
	$("#phase_no").on("change",function()
				{
					var id=$("#gram_id").val();
					var phase = $(this).val();
			
			$.ajax({
				url:'{{url("/gram_survey_status")}}/'+id+'/'+phase,
				method:'get',
				dataType:"json",
				success:function(data)
				{
					if(data != null){
					$('#status').val(data.approve_status);
					}
				},	
				error:function(data)
				{
					$("#status").val("0");
				}
			});
		});
	$("#type").on("change",function()
				{
					var id=$("#district_id").val();
					var type = $(this).val();
			
			$.ajax({
				url:'{{url("/get_invoice_list")}}?id='+id+'&type='+type,
				method:'get',
				dataType:"html",
				success:function(data)
				{
					
					$('#invoice_number').html(data);
					
				},	
				error:function(data)
				{
					//$("#status").val("0");
				}
			});
		});
	$("#invoice_number").on("change",function()
				{
					var type=$("#type").val();
					var id = $(this).val();
			
			$.ajax({
				url:'{{url("/get_invoice_status")}}?id='+id+'&type='+type,
				method:'get',
				dataType:"json",
				success:function(data)
				{
					if(data != null){
					$('#invoice_status').val(data.approve_status);
					}
				},	
				error:function(data)
				{
					$("#invoice_status").val("0");
				}
			});
		});
</script>

@stop