<?php 
session_start();
$title = "Power Generation";
$group = "gen";
$menu = "gen";
include('header.php');
$_SESSION['isEdit']=false;
unset($_SESSION['batchid']);
?>
<script>
function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}
	 	
	return xmlhttp;
}


function loadPowerSupply(showloading) {
	if(showloading == 1)		
	document.getElementById('load').innerHTML='<img src="img/loading.gif"/>';
	var strURL="../load/loadpowersupply.php";
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('load').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}		
}

function Delete(id)
{
	if(confirm("Delete Generation Report?"))
	{
    	var datastring = {'id':id,'delete':'gen'};
    	$.ajax({
    	            type: "POST",
    	            url: "../include/delete_ajax.php",
    	            data: datastring,
    	            dataType: 'json',
    	            cache: false,
    	            success: function(data) {
    	            	if(data.success == 1)
    	            	{       	
    	            		loadPowerSupply(0);	
    	            		setTimeout(function() {
    	                        toastr.options = {
    	                            closeButton: true,
    	                            progressBar: true,
    	                            positionClass: "toast-top-full-width",
    	                            showMethod: 'slideDown',
    	                            timeOut: 4000
    	                        };
    	                        toastr.success('Report deleted successfully');
    	                        
    	                    }, 1300);
    	            	}
    	            	else
    	            	{
    	            		setTimeout(function() {
    	                        toastr.options = {
    	                            closeButton: true,
    	                            progressBar: true,
    	                            positionClass: "toast-top-full-width",
    	                            showMethod: 'slideDown',
    	                            timeOut: 4000
    	                        };
    	                        toastr.error('Error');
    
    	                    }, 1300);
    	            	}
    	            },
    	            error: function(){
    	                  alert('error handling here');
    	            }
    	        });
	}
}
$(document).ready(function(){
	loadPowerSupply(1);
});
</script>


<div class="content-body">
        	<div class="row">
                    <div id="recent-transactions" class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title">Power Generation</h4>
                            </div>
                            <div class="card-content">
							<div class="row row-pad">
                                <div class="col-md-8"><a class="btn btn-info pull-right" href="gen">Add new</a></div>
                            </div>
                            <div class="row row-pad">
                                <div class="col-lg-8">
                                    <div class="table-responsive">
                                       <table class="table table-striped table-bordered table-hover table-advanced">
                                            <thead>
                                                <tr>
                                                    <th>S/N</th>
                                                    <th>Date</th> 
                                                    <th colspan="2">Actions</th>                             
                                                </tr>
                                            </thead>
                                            <tbody id="load">
                                                </tbody>
                                       </table>
                                    </div>
                                </div>
                            </div>
                            
                            </div>
                        </div>
                    </div>
                </div>
                <!--/ Recent Transactions -->

   </div>

   
    <?php include('footer.php');?>

   
