
		<!-- MAIN CONTENT WRAPPER -->
		
<script src="assets/js/king-table.js"></script>
			<!-- main -->
			<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">Fiscal year</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> Fiscal year</h3></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()); ?>">
<?php echo csrf_field(); ?>           
<div class="alert  alert-info " >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li>Enter Fiscal Year 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="form-group">
                            <label for="text-input1">Fiscal Year title*</label>
							<input type="hidden" class="form-control" id="fyr_id" name="fyr_id" >
                            <input type="text" name="fyear" id="fyear" class="form-control" >
                            <small class="text-danger" id="errfyear"></small>
                        </div>

                        <div class="form-group">
                            <label for="text-input1">Starts from*</label>
                            <input type="date" name="fstartyear" id="fstartyear" class="form-control" >
                            <small class="text-danger" id="errfstartyear"></small>
                        </div>
                        
                        <div class="form-group">
                            <label for="text-input1">Ends At*</label>
                            <input type="date" name="fendyear" id="fendyear" class="form-control" >
                            <small class="text-danger" id="errfendyear"></small>
                        </div>
                             
                        <br/>
                        <button type="submit" id="submit" name="submit" class="btn btn-primary">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 All Fiscal year records</h3> 
                        </div>
						<div class="widget-content">
							<table id="datatable-data-export" class="table table-sorting table-striped table-hover table-bordered datatable">
								<thead>
									<tr>
										<th>Title</th>
										<th>Starts from</th>
										<th>Ends at</th>
										<th>Action</th>
									</tr>
								</thead>
								<tbody>
								<?php $__currentLoopData = $data['Fiscalyear']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $Fiscalyear): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
									<tr>
										<td><?php echo e($Fiscalyear->fyr_yearname); ?></td>
										<td><?php echo e($Fiscalyear->fyr_startdate); ?></td>
										<td><?php echo e($Fiscalyear->fyr_enddate); ?></td>
										
									<td> <span class="btn btn-default btn-xs editlink" onclick="Edit(<?php echo e($Fiscalyear->fyr_id); ?>)">Edit</span>
												 <span class="btn btn-default btn-xs" onclick="Delete(<?php echo e($Fiscalyear->fyr_id); ?>)">Delete </span></td>
									</tr>
								<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
								</tbody>
							</table>
							
						</div>
					</div>
							<!-- END BASIC VALIDATION -->
						</div>

					</div>
				</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 fyr_id = $('#fyr_id').val();
				var fyear = $('#fyear').val();
				var fstartyear = $('#fstartyear').val();
				var fendyear = $('#fendyear').val();
				
				
				document.getElementById("errfyear").innerHTML = "";
				document.getElementById("errfstartyear").innerHTML = "";
				document.getElementById("errfendyear").innerHTML = "";
		   
		   if(fyear == "")
		   {
				document.getElementById("errfyear").innerHTML = "Title 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(fstartyear == "")
		   {
				document.getElementById("errfstartyear").innerHTML = "Fiscal Year Starts From 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(fendyear == "")
		   {
				document.getElementById("errfendyear").innerHTML = "Fiscal Year Ends At 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++;
				$.ajax({
				url: "/fiscalyear",
				type:'POST',
				data: {_token:_token, fyr_id:fyr_id, fyear:fyear, fstartyear:fstartyear, fendyear:fendyear},
				success: function(data) {
					//alert(data);
					if(data.status == 1)
					{
						printSuccessMsg(data.message);
						$('#sideMenu').load('fiscalyear');
					}
					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);
	}
	
	function Edit(id)
{
$.ajax({
		type: "GET",
		url:"/editfiscalyear",
		dataType: "json",
		data: {
			'_token': $('input[name=_token]').val(),
			'id': id
		},
		success: function (data) {
		 $.each(data,function(i,obj)
			{
				 $('#fyr_id').val(obj.fyr_id);
				 $('#fyear').val(obj.fyr_yearname);
				 $('#fstartyear').val(obj.fyr_startdate);
				 $('#fendyear').val(obj.fyr_enddate);
				// $('#btnadd').val("UPDATE"); 
			 });  
			}
	  });
}
function Delete(id)
{
	//alert(id);
	k = 0;
	if(k == 0)
	{
		k++;
			$.ajax({
            type: "GET",
            url:"/delfiscalyear",
            dataType: "json",
			data: {
                '_token': $('input[name=_token]').val(),
                'id': id
            },
            success: function (sdata) {
			if(sdata.status == 1)
			{
				printSuccessMsg(sdata.message);
				$('#sideMenu').load('fiscalyear');
			}
			else
			{
				printErrorMsg(sdata.message)
			}
           }
          });
	}

}
	</script>