<!doctype html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>NWP ENGINEERING DEPARTMENT - SRI LANKA</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Favicon -->
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<!-- Google Fonts -->
<link href="css/fonts.css" rel="stylesheet">
<!-- Bootstrap
<link rel="stylesheet" href="css/assets/bootstrap.min.css">
<!-- Fontawesome Icon -->
<link rel="stylesheet" href="css/assets/font-awesome.min.css">
<!-- Animate CSS -->
<link rel="stylesheet" href="css/assets/animate.css">
<!-- Mean Menu -->
<link rel="stylesheet" href="css/assets/meanmenu.min.css">
<!-- Owl Carousel -->
<link rel="stylesheet" href="css/assets/owl.carousel.min.css">
<!-- Magnific Popup -->
<link rel="stylesheet" href="css/assets/magnific-popup.css">
<!-- Custom Style -->
<link rel="stylesheet" href="css/assets/normalize.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/assets/responsive.css">
<link rel="stylesheet" href="backend/bootstrap/css/bootstrap.min.css">
<!-- DataTables -->
<link rel="stylesheet" href="backend/plugins/datatables/dataTables.bootstrap.css">
<!-- Theme style -->
<link rel="stylesheet" href="backend/dist/css/AdminLTE.min.css">
<!-- daterange picker -->
<link rel="stylesheet" href="backend/plugins/daterangepicker/daterangepicker-bs3.css">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-69018766-3"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-69018766-3');
</script>
<style>
@media screen and (max-width: 767px) {
.table-responsive {
	margin-bottom: 0;
	border: none;
}
.tbl {
	padding: 12px !important;
}
}
.tbl {
	padding: 25px;
	border: 1px solid #d9d9d9;
}
.reg_list {
	padding: 0px 0 20px;
}
</style>
</head>
<body>
<!-- Pre-Loader -->
<div id="page-preloader"><span class="spinner"></span></div>
<!-- End Pre-Loader --> 

<!-- Top Bar -->
<?php 
include 'common/top-bar.php';
include 'common/mobile-menu.php';
?>
<!-- End Top Bar --> 

<!-- Page Heading -->
<section class="p-heading text-center">
  <div class="container">
    <div class="page-bg">
      <div class="row">
        <div class="col-md-12">
          <div class="p-content">
            <h4>
              <?php if($lang == 1) { ?>
                PREVIOUS PROGRESS REPORT
              <?php } if($lang == 2) { ?>
            පසුගිය  ප්‍රගති වාර්තාව
              <?php } if($lang == 3) { ?>
               முந்தைய முன்னேற்றம் அறிக்கை
              <?php } ?>
            </h4>
            <ul class="list-unstyled list-inline">
              <li class="list-inline-item"><a href="home">
                <?php if($lang == 1) { ?>
                Home
                <?php } if($lang == 2) { ?>
                මුල් පිටුව
                <?php } if($lang == 3) { ?>
                முகப்பு
                <?php } ?>
                </a>
              </li>
              <li class="list-inline-item"><i class="fa fa-long-arrow-right" aria-hidden="true"></i>
                <?php if($lang == 1) { ?>
                Previous Progress Report
                <?php } if($lang == 2) { ?>
              පසුගිය  ප්‍රගති වාර්තාව
                <?php } if($lang == 3) { ?>
              முந்தைய முன்னேற்றம் அறிக்கை
                <?php } ?>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
<!-- End Page Heading -->

<?php
$text = '';
if (!empty($_GET['type'])) {
  $type = htmlspecialchars(trim($_GET['type']), ENT_QUOTES, 'UTF-8');
  $text = " AND projects_reg.type =  '".$type."'";
} else {
	$text = '';
	$type = '';
}

if (isset($_GET['dt'])) {
	$daterange = htmlspecialchars(trim($_GET['dt']), ENT_QUOTES, 'UTF-8');
	$date1 = substr($daterange, 0, 10);
	$date2 = substr($daterange, 13, 23);
	$text2 = " AND (projects_reg.start_date BETWEEN '$date1' AND '$date2')";

} else {
	$daterange = '';
	$text2 = '';
}

$year = date('Y');
$sql="SELECT
Sum(project_invoice.tot_pay) AS amount,
division.division,
projects_reg.id,
projects_reg.pro_name,
division.division,
projects_reg.esti_amount,
projects_reg.total_cost_esti,
project_invoice.project
FROM
project_invoice
Inner Join projects_reg ON project_invoice.project = projects_reg.id
Inner Join division ON projects_reg.division = division.id
WHERE projects_reg.year<'$year' AND project_invoice.flag=1 $text $text2
GROUP BY
project_invoice.project
ORDER BY id DESC";
?>

<section class="reg_list">
  <div class="container">
    <div class="row">
      <div class="col-lg-12 col-md-12">
        <div class="tbl">
          <div class="row">
            <div class="col-md-12">
              <h4>PREVIOUS PROGRESS REPORT <?php 
			  if(isset($_GET['type'])) {
				$sql_ty = mysqli_fetch_assoc(mysqli_query($conn, "SELECT type FROM project_type WHERE id='$type'"));
				echo ' - '.$sql_ty['type'];
			  } else { } ?></h4>
            </div>
            <div class="col-md-12"><hr>
              <form class="form-horizontal" name="form" id="form">
				<div class="form-group col-sm-6">
					<label class="col-sm-12 col-md-5 control-label">Select Date-range:</label>            
					<div class="col-sm-12 col-md-7">
						<div class="input-group"> 
						  <div class="input-group-addon"> <i class="fa fa-calendar"></i> </div>
						  <input type="text" class="form-control" value="<?php echo $daterange; ?>" onChange="formHandler2($(this).val())" id="date" name="date" autocomplete="off">
						</div>
					</div>
				</div>                
				<div class="form-group col-sm-6">
                  <label class="col-sm-12 col-md-4 control-label">Project Type:</label>
                  <div class="col-sm-12 col-md-8">
                    <select class="form-control" name="type" id="type" onChange="formHandler($(this).val())">
                      <option value="">Select Project Type...</option>
                      <?php 
                        $sql1="SELECT * FROM project_type ORDER BY id DESC";
                        $result=mysqli_query($conn, $sql1);
                        while ($row = mysqli_fetch_array($result)){
                      ?>
                        <option value="<?php echo $row['id']; ?>" <?php if($type == $row['id']) { echo 'selected'; } ?>><?php echo $row['type']; ?></option>
                      <?php } ?>
                    </select>
                  </div>
                </div>
              </form>
            </div>	
          </div>  
          <hr>
          <div class="table-responsive">
            <table id="tabl_reg" class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th rowspan="2">Serial Number</th>
                  <th rowspan="2">Project</th>
                  <th rowspan="2">Prostate Provision</th>
                  <th rowspan="2">Divisional Secretariat</th>
                  <th rowspan="2">Annual Allocation</th>
                  <th rowspan="2">Expenses in the month of reporting</th>
                  <th rowspan="2">Accumulated Expenses</th>
                  <th rowspan="2">Financial Progress</th>
                  <th rowspan="2">Number of units</th>
                  <th rowspan="2">Beneficiaries</th>
                  <th colspan="6">Physical Progress</th>
                  <th rowspan="2">Other</th>
                  <th rowspan="2">Implementation Agency</th>
                </tr>
                <tr>
                  <th>A</th>
                  <th>B</th>
                  <th>C</th>
                  <th>D</th>
                  <th>E</th>
                  <th>F</th>
                </tr>
              </thead>
              <tbody>
                <?php
                  $result=mysqli_query($conn, $sql);
                  $x = 0;
                  while ($row = mysqli_fetch_array($result)){ $x++;
					$pr = $row['id'];
                ?>
                <tr>
                  <td><?php echo $x; ?>.</td>
                  <td><?php echo $row['pro_name']; ?></td>
                  <td><?php echo $est_val = $row['esti_amount']; ?></td>
                  <td><?php echo $row['division']; ?></td>
                  <td><?php echo $row['total_cost_esti']; ?></td>
                  <td><?php $month = date('m'); $sql_d = mysqli_fetch_assoc(mysqli_query($conn, "SELECT Sum(tot_pay) AS amount FROM project_invoice WHERE project='$pr' AND EXTRACT(MONTH FROM DATE)='$month'")); echo $sql_d['amount']; ?></td>
                  <td><?php echo $ac_exp = $row['amount']; ?></td>
                  <td><?php $prog = ($ac_exp/$est_val) * 100; echo number_format($prog,2).'%'; ?></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                </tr>
                <?php  } ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

<!-- Footer -->
<?php include 'common/footer.php'; ?>
<!-- End Footer --> 

<!-- =========================================
JavaScript Files
========================================== --> 

<!-- jQuery JS --> 
<script src="js/assets/vendor/jquery-1.12.4.min.js"></script> 
<!-- Poppers Js --> 
<script src="js/assets/popper.js"></script> 
<!-- Bootstrap 
<script src="js/assets/bootstrap.min.js"></script> 
<!-- Sticky Js --> 
<script src="js/assets/jquery.sticky.js"></script> 
<!-- WOW JS --> 
<script src="js/assets/wow.min.js"></script> 
<!-- Smooth Scroll --> 
<script src="js/assets/smooth-scroll.js"></script> 
<!-- Mean Menu --> 
<script src="js/assets/jquery.meanmenu.min.js"></script> 
<!-- News Ticker --> 
<script src="js/assets/jquery.newsticker.min.js"></script> 
<!-- Owl Carousel --> 
<script src="js/assets/owl.carousel.min.js"></script> 
<!-- Magnific Popup --> 
<script src="js/assets/jquery.magnific-popup.min.js"></script> 
<!-- Syotimer --> 
<script src="js/assets/jquery.syotimer.min.js"></script> 
<!-- Custom JS --> 
<script src="js/plugins.js"></script> 
<script src="js/custom.js"></script> 

<!-- Bootstrap 3.3.5 --> 
<script src="backend/bootstrap/js/bootstrap.min.js"></script> 
<!-- DataTables --> 
<script src="backend/plugins/datatables/jquery.dataTables.min.js"></script> 
<script src="backend/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- date-range-picker -->
<script src="backend/plugins/daterangepicker_n/moment.min.js"></script>
<script src="backend/plugins/daterangepicker_n/daterangepicker.js"></script>
<script src='js/pdf_export/dataTables.buttons.min.js'></script> 
<script src='js/pdf_export/buttons.html5.min.js'></script> 
<script src='js/pdf_export/buttons.bootstrap.min.js'></script> 
<script src='js/pdf_export/jszip.min.js'></script> 
<script src='js/pdf_export/pdfmake.min.js'></script> 
<script src='js/pdf_export/vfs_fonts.js'></script> 
<script src="js/pdf_export/pdf_export_prv.js"></script> 

<script>
$('#date').daterangepicker();

$(function () {
  $("#tabl_reg").DataTable();
});
  
function formHandler(id){
  window.location.href = 'previous-progress-report?type='+id;
}

function formHandler2(date){
  var type = $('#type').val();
  window.location.href = 'previous-progress-report?type='+type+'&dt='+date;
}
</script>

</body>
</html>