<!-- MAIN CONTENT WRAPPER -->
<script src="assets/js/king-table.js"></script>
			<div class="content">
				<div class="main-content">
					<div class="row">
                    	
                        <div class="col-md-12">
							<!-- ADVANCED VALIDATION -->
							<div class="widget">
								<div class="widget-header">
									<h3><i class="fa fa-check-circle"></i> {{ __('grade.grade_fund_entry') }}</h3></div>
								<div class="widget-content">
                    <form id="frmmain" name="frmmain" data-parsley-validate novalidate>
                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
					<input type="hidden" class="form-control" id="grfn_id" name="grfn_id" value="0" >
					<input type="hidden" class="form-control" id="fyr_id" name="fyr_id" value="{{$data['fiscalyear'][0]->fyr_id}}" >
{!! csrf_field() !!}           
<div class="alert  alert-info " >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li>{{ __('grade.enter_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="row">
	<div class="form-group col-md-4">
		<label for="text-input1">{{ __('grade.grade') }}*</label>
		<input type="hidden" id="edit_grd_id" name="edit_grd_id" value="0">
		<select name="grd_id" id="grd_id" class="form-control" required>
					<option value="">-- {{ __('grade.grade') }} --</option>
		</select>
		<small class="text-danger" id="errgrd_id"></small>
	</div>
						
	<div class="form-group col-md-4">
		<label for="text-input1">{{ __('grade.fund_type') }}*</label>
		<input type="hidden" id="edit_ftyp_id" name="edit_ftyp_id" value="0">
		<select name="ftyp_id" id="ftyp_id" class="form-control" required>
			<option value=""> -- {{ __('grade.fund_type') }} -- </option>
		</select>
		<small class="text-danger" id="errftyp_id"></small>
	</div>
				
	<div class="form-group col-md-4">
		<label for="text-input1">{{ __('grade.billing_cycle') }}*</label>
		<select name="grfn_paycycle" id="grfn_paycycle" class="form-control" required>
			<option value="">-- {{ __('grade.billing_cycle') }} --</option>
			<option value="Daily">{{ __('grade.Daily') }}</option>
			<option value="Weekly">{{ __('grade.Weekly') }}</option>
			<option value="Monthly">{{ __('grade.Monthly') }}</option>
			<option value="Quarterly">{{ __('grade.Quarterly') }}</option>
			<option value="Semiannually">{{ __('grade.Semiannually') }}</option>
			<option value="Yearly">{{ __('grade.Yearly') }}</option>
			<option value="One time">{{ __('grade.Onetime') }}</option>
		</select>
		<small class="text-danger" id="errgrfn_paycycle"></small>
	</div>
</div>

<div class="row">	
	<div class="form-group col-md-4">
		<label for="text-input1">{{ __('grade.amount') }}*</label>
		<input type="text" name="grfn_amt" id="grfn_amt" class="form-control" >
		<small class="text-danger" id="errgrfn_amt"></small>
	</div>
	
	<div class="form-group col-md-4">
		<label for="text-input1">{{ __('grade.description') }}</label>
		<input type="text" name="grfn_description" id="grfn_description" class="form-control" >
		<small class="text-danger" id="errgrfn_description"></small>
	</div>

	<div class="form-group col-md-4">
		<label for="multiselect1">{{ __('grade.status') }}*</label>
		<br/>
		<select name="grfn_status" id="grfn_status" class="form-control" required>
			<option value="Active">{{ __('grade.Active') }}</option>
			<option value="Inactive">{{ __('grade.Inactive') }}</option>
		</select>
		<small class="text-danger" id="errgrfn_status"></small>
	</div>
</div>
    
<div class="row">
	<center><button type="submit" id="submit" name="submit" class="btn btn-primary submit">Submit</button></center>
</div>

                    </form>
								</div>
							</div>
							<!-- END ADVANCED VALIDATION -->
						</div>
                    
						<div class="col-md-12">
							<!-- BASIC VALIDATION -->
								<div class="widget widget-table">
						<div class="widget-header">
							<h3><i class="fa fa-table"></i> {{ __('grade.view_grdfund_list') }} - ( {{  date("d-m-Y",strtotime($data['fiscalyear'][0]->fyr_startdate)) }} -  {{ date("d-m-Y",strtotime($data['fiscalyear'][0]->fyr_enddate)) }} )</h3> 
                        </div>
						<div class="widget-content">
<?php
/*						
<div class="form-group">
	<div class="col-md-12">
		<div class="col-md-2"><b>Select Grade</b></div>
		<div class="col-md-6">
			<select name="grd_selectgradeid" id="grd_selectgradeid" class="form-control" required>
					<option value="">Select Grade</option>
			</select>
		</div>
		<div class="col-md-4">
			<button type="button" id="submit" name="submit" class="btn btn-primary submit">Submit</button>
		</div>
	</div>	
	<div class="col-md-12">
		<hr>
	</div>	
	<small class="text-danger" id="errgrd_selectgradeid"></small>
</div>
*/
?>
												<table id="myTable" class="table table-sorting table-striped table-hover table-bordered datatable">
								<thead>
									<tr>
										<th>{{ __('grade.grade') }}</th>
										<th>{{ __('grade.fund_type') }}</th>
										<th>{{ __('grade.billing_cycle') }}</th>
										<th style="text-align: right;">{{ __('grade.amount') }}</th>
										<th>{{ __('grade.description') }}</th>
										<th>{{ __('grade.status') }}</th>
										<th>{{ __('grade.action') }}</th>
									</tr>
								</thead>
								<tbody>
								<?php $gramt = 0; ?>
								@foreach($data['gradefund'] as $gradefund)
									<tr>
										<td>{{$gradefund->grd_grade}} ({{$gradefund->grd_prefix}})</td>
										<td>{{$gradefund->ftyp_fundtype}}</td>
										<td>{{$gradefund->grfn_paycycle}}</td>
										<td style="text-align: right;">{{$gradefund->grfn_amt}}</td>
										<td>{{$gradefund->grfn_description}}</td>
										<td>{{$gradefund->grfn_status}}</td>
			<?php 
			if($data['edit']=='1' || $data['delete']=='1'){ echo'<td>';}
			?>
			<?php 
			if($data['edit']=='1'){echo'<button class="btn btn-default btn-xs print" onclick="Edit('.$gradefund->grfn_id.')"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>' . __("mylanguage.edit") . '</button>'; } if($data['delete']=='1'){echo' <button class="btn btn-default btn-xs print" onclick="Delete('.$gradefund->grfn_id.')"><i class="fa fa-trash" aria-hidden="true"></i>' . __("mylanguage.delete") . '</button>';} echo '</td>';
			?>
									</tr>
									<?php 
									$gramt = $gramt + $gradefund->grfn_amt;
									?>
								@endforeach
								</tbody>
								<tfoot>
									<tr>
										<th style="text-align: right;" colspan="4"></th>
										<th colspan="3"></th>
									</tr>
								</tfoot>
							</table>
						</div>
					</div>
							<!-- END BASIC VALIDATION -->
						</div>

					</div>
				</div>
			</div>
			<!-- /main -->

<script type="application/javascript">
i=0;
	//$(document).on('submit', '#frmmain', function()
	$('.submit').click(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 ftyp_id =  $('#ftyp_id').val();
			var grd_id =  $('#grd_id').val();
			var fyr_id =  $('#fyr_id').val();
			var grfn_amt =  $('#grfn_amt').val();
			var grfn_paycycle = $('#grfn_paycycle').val();
			var grfn_description = $("input[name='grfn_description']").val();
			var grfn_status = $("#grfn_status").val();

			document.getElementById("errftyp_id").innerHTML = "";
			document.getElementById("errgrd_id").innerHTML = "";
			document.getElementById("errgrfn_amt").innerHTML = "";
			document.getElementById("errgrfn_paycycle").innerHTML = "";
			document.getElementById("errgrfn_description").innerHTML = "";	
			document.getElementById("errgrfn_status").innerHTML = "";		   	
	
			if(grd_id == "")
			{
				document.getElementById("errgrd_id").innerHTML = "Kindly select Grade...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
			}
			else if(ftyp_id == "")
			{
				document.getElementById("errftyp_id").innerHTML = "Kindly select Fund Type...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');				
			}
			else if(grfn_paycycle == "")
			{
				document.getElementById("errgrfn_paycycle").innerHTML = "Kindly select Billing Cycle...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');				
			}
			else if(grfn_amt == "")
			{
				document.getElementById("errgrfn_amt").innerHTML = "Amount Shoud 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: "/insertgradefund",
						type:'POST',
						data: $('#frmmain').serialize(),
						success: function(data) {											
							if(data.status == 1)
							{
								printSuccessMsg(data.message);
								$('#sideMenu').load('loadgradefund');
							}
							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);
			//Code to redirect page
			//var url = "/dashboard";
			//$(location).attr('href',url);
		}
</script>	
<script>
	function Edit(id)
	{
		$.ajax({
			type: "GET",
			url:"/editgradefund",
			dataType: "json",
			data: {
				'_token': $('input[name=_token]').val(),
				'id': id
			},
			success: function (data) {
				$.each(data,function(i,obj)
				{	   				
					$('#grfn_id').val(obj.grfn_id);
					$('#ftyp_id').val(obj.ftyp_id);
					$('#grd_id').val(obj.grd_id);
					$('#fyr_id').val(obj.fyr_id);
					$('#grfn_amt').val(obj.grfn_amt);
					$('#grfn_paycycle').val(obj.grfn_paycycle);
					$('#grfn_description').val(obj.grfn_description);
					$('#grfn_status').val(obj.grfn_status);
				});  
			}
		});
	}
</script>
<script>
	function Delete(id)
	{
		if(confirm("Are you sure want to delete this record?") == true)
		{
			k = 0;
			if(k == 0)
			{
				k++;
				$.ajax({
					type: "GET",
					url:"/deletegradefund",
					dataType: "json",
					data: {
						'_token': $('input[name=_token]').val(),
						'id': id
					},
					success: function (sdata) {
						if(sdata.status == 1)
						{
							printSuccessMsg(sdata.message);
							$('#sideMenu').load('loadgradefund');
						}
						else
						{
							printErrorMsg(sdata.message)
						}
					}
				});
			}
		}
	}
</script>
<script>
	//load Full fund types 	edit_ftyp_id edit_grd_id
	$(document).ready(function(){
		var edit_ftyp_id = $('#edit_ftyp_id').val();
		$.ajax({
		type: "GET",
		url:"/loadfundtypelist",
		dataType: "json",
		success: function (data) {
		$.each(data,function(i,obj)
		{
			if(edit_ftyp_id ==0)
			{
				var div_data="<option value="+obj.ftyp_id+">"+obj.ftyp_fundtype+"</option>";	
			}
			else 
			{
				if(edit_ftyp_id == obj.ftyp_id)
				{
					var div_data="<option value="+obj.ftyp_id+" selected>"+obj.ftyp_fundtype+"</option>";	
				}
				else{
					var div_data="<option value="+obj.ftyp_id+">"+obj.ftyp_fundtype+"</option>";		
				}
			}
		 $(div_data).appendTo('#ftyp_id'); 
		});  
		}
		});
	});
</script>		  
<script>
	//load Full fund types 	edit_grd_id edit_grd_id
	$(document).ready(function(){
		var edit_grd_id = $('#edit_grd_id').val();
		$.ajax({
		type: "GET",
		url:"/loadgradelist",
		dataType: "json",
		success: function (data) {
		$.each(data,function(i,obj)
		{
			if(edit_grd_id ==0)
			{
				var div_data="<option value="+obj.grd_id+">"+obj.grd_grade+" (" + obj.grd_prefix + ")</option>";	
			}
			else 
			{
				if(edit_grd_id == obj.grd_id)
				{
					var div_data="<option value="+obj.grd_id+" selected>"+obj.grd_grade+" (" + obj.grd_prefix + ")</option>";	
				}
				else{
					var div_data="<option value="+obj.grd_id+">"+obj.grd_grade+" (" + obj.grd_prefix + ")</option>";		
				}
			}
			$(div_data).appendTo('#grd_id');
			$(div_data).appendTo('#grd_selectgradeid');
		});  
		}
		});
	});
//DataTable starts here
$(document).ready( function () {
    $('#myTable').DataTable({
        "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;
 
            // Remove the formatting to get integer data for summation
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };
 
            // Total over all pages
            total = api
                .column( 3 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
 
            // Total over this page
            pageTotal = api
                .column( 3, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
 
            // Update footer
            $( api.column( 3 ).footer() ).html(
                ''+pageTotal +' ( '+ total +' total)'
            );
        }
    });
} );
//DataTable ends here
</script>