<?php
require_once("config.php");

//require_once("config.php");


$mycon = databaseConnect();
$currentuserid = getCookie('pcc_id');
$my_pcc_area = getCookie('pccs_area');

//get all pcc
$myrec = $mycon->prepare("SELECT * FROM `pcc_report` where pcc_id = '$currentuserid'");
$myrec->execute();
$myrecdepartments = $myrec->fetchAll(PDO::FETCH_ASSOC);



//print_r($myrecdepartments);


?>

<!DOCTYPE HTML>
<!-- Website Template by freewebsitetemplates.com -->
<html>
<head>
	<meta charset="UTF-8">
	<title><?php echo pageTitle() ?></title>
	<link rel="stylesheet" href="css/style.css" type="text/css">
	<!--[if lt IE 9]>
		<link rel="stylesheet" type="text/css" href="css/ie.css">
	<![endif]-->
	<link rel="stylesheet" href="jquery/themes/base/jquery.ui.all.css">
	<script src="jquery/ui/jquery.ui.core.js"></script>
	<script src="jquery/ui/jquery.ui.widget.js"></script>
	<script src="jquery/ui/jquery.ui.datepicker.js"></script>
	<link rel="stylesheet" href="jquery/demos.css">
	<script>
	$(function() {
		$( "#from_searchdate" ).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'yy-mm-dd',
			duration: 'fast'
			//showTime: true
			//minDate: new Date(2011, 5, 10)
			//maxDate: '+1y +1m +1w +1d'
		});
	});
	</script>
	<script>
		$(function() {
			$( "#to_searchdate" ).datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'yy-mm-dd',
				duration: 'fast'
				//showTime: true
				//minDate: new Date(2011, 5, 10)
				//maxDate: '+1y +1m +1w +1d'
			});
		});
	</script>

</head>
<body>
	<?php require_once("inc_top_pcc.php") ?>
	<div id="body">
<div class="content">
			<div class="section">
				<div class="breadcrumb">
					<span>You are here:</span>
					<ul>
						<li>
							<a href="dashboard.php">home</a>
						</li>
						<li>
							<a href="#">Pastoral Care Centers (PCC)</a>
						</li>
					</ul>
				</div>
				<div class="company">
					<h2>Pastoral Care Centers Reports</h2>
                  <div style="clear:both; height:10px"></div>
					<table width="100%" border="0">
					  <tr>









					  					    <td align="right"><form id="form1" name="form1" method="post" action="">




					  Search By Date From:

					     <span class="input-group">
					                               <input name="from_searchdate" type="text" id="from_searchdate" readonly>
					                          </span>&nbsp;To: <span class="input-group">
					                               <input name="to_searchdate" type="text" id="to_searchdate" readonly>
					                          </span>

					  &nbsp;
					  &nbsp;
					  <input type="submit" name="searchdate" id="searchdate" value="GO!" />&nbsp;&nbsp; &nbsp;





					  Search By Expense Type:
				
					   				 <select name="expense_type" id="expense_type">
						                          <option value="">Please Expense Type</option>
						                          <option value="50% Offering">50% Offering</option>
						                          <option value="Bereavement">Bereavement</option>
						                          <option value="Gift">Gift</option>
						                          <option value="Refreshment">Refreshment</option>
						                          <option value="Others">Others</option>
						              </select>
					  &nbsp;
					  &nbsp;
					  <input type="submit" name="searchexpensetype" id="searchexpensetype" value="GO!" />&nbsp;&nbsp; &nbsp;
<a href="?nothing">View all</a>





					    <input name="command" type="hidden" id="command" value="searchform" />
					  				        </form></td>
				      </tr>

<tr>
					    <td><table width="100%" border="0">
					      <tr>
					       <td width="2%" height="29" bgcolor="#879D91"><strong>S/N</strong></td>
						   						  					        <td width="9%" bgcolor="#879D91"><strong>PCC Name</strong></td>
						   						  					          <td width="10%" bgcolor="#879D91"><strong>Fellowship Date</strong></td>
						   						  					          <td width="10%" bgcolor="#879D91"><strong>Fellowship Week</strong></td>					   				  					       
						   						  							<td width="10%" bgcolor="#879D91"><strong>Offering</strong></td>
						   						  							<td width="5%" bgcolor="#879D91"><strong>Tithe</strong></td>
						   						  							<td width="5%" bgcolor="#879D91"><strong>Expenses</strong></td>
						   						  							<td width="5%" bgcolor="#879D91"><strong>Expenses Type</strong></td>
						   						  							 <td width="5%" bgcolor="#879D91"><strong>Full Offering</strong></td>
                                                                             
<td width="9%" bgcolor="#879D91"><strong>Treasury Adjustment</strong></td>

						   						  							<td width="9%" bgcolor="#879D91"><strong>Treasury Balance</strong></td>
						   						  							<td width="10%" bgcolor="#879D91"><strong>Date Submitted</strong></td>
						  							<td width="15%" bgcolor="#879D91"><strong>Report Status</strong></td>

				          </tr>
<?php

$totaloffering = 0;
$totaltithe = 0;
$totalexpenses = 0;
$totalAd_treasury = 0;
$totaltreasury = 0;
$first_timers = 0;
$fulloffering = 0;

$currentYear = date("Y");
$date_of_current_year = ($currentYear-1)."-12-31";
	
					  	//$sql = "SELECT * FROM `pcc_report` WHERE `pcc_id` =  '$currentuserid'  AND `fellowship_date`>'2015-12-31'";
$sql = "SELECT * FROM `pcc_report` WHERE `pcc_id` =  '$currentuserid'  AND `fellowship_date`>'".$date_of_current_year."'";
					  	$param = array();

					  	if(isset($_POST['searchdate']))
					  	{
					  		$searchtext = $_POST['from_searchdate'];
					  		//$department = $_POST['department'];
					  		$start =$_POST['from_searchdate'];
					  		$end = $_POST['to_searchdate'];

					  		if(strlen(trim($start)) > 0)
					  		{
					  			//$sql .= " AND (`fellowship_date` >= :start and fellowship_date <= :end)";
					  			$sql = "SELECT * FROM `pcc_report` WHERE `pcc_id` =  '$currentuserid' AND  (`fellowship_date` >= :start and fellowship_date <= :end)";
					  			$param[":start"] = $start;
					  			$param[":end"] = $end;
					  		}
					  	}
	 
				  	if(isset($_POST['searchexpensetype']))
					  	{
					  		$searchtext = $_POST['expense_type'];
					  		//$department = $_POST['department'];
					  		$expense_type = $_POST['expense_type'];


					  		if(strlen(trim($expense_type)) > 0)
					  		{
					  			$sql .= " AND (`expense_type` = '$expense_type')";
					  			//$sql .= " AND (`expense_type` = :expense_type)";
								$param[":expense_type"] = $expense_type;

					  		}
					  	}

	$myrec = $mycon->prepare($sql);
	$myrec->execute($param);

	$pos = 0;
	while($row = $myrec->fetch(PDO::FETCH_ASSOC))
	{

            $fd = $row['fellowship_date'];
			$ds = date("Y-m-d", $row['date_submitted']);
			$date1 = date_create(date("d-m-Y", strtotime($fd)));
		    $date2 = date_create(date("d-m-Y", strtotime($ds)));
			$interval=date_diff($date1,$date2);
			
            $diff = $interval->format('%R%a');
					$time_submitted = date('H', $row['date_submitted']);
					//echo $time_submitted."<br>";

					if($diff <= 1)
					{

					$flag = "On time"; //green flag

					}
					else
					{
						$flag = "Late"; // red flag
		            }




?>
					      <tr bgcolor="<?php echo changeRowColor(++$pos) ?>" class="tableRowHover">
					       <td height="29"><?php echo $pos ?></td>
						   						  					       <td><?php echo $row['pccs_area'] ?></td>
						   						  					           <td><?php echo $row['fellowship_date'] ?></td>
						   						                                  <td><?php echo $row['fellowship_week'] ?></td>



						   						  					            <td>N<?php echo  number_format($row['offering'],2);?></td>

						   						  					              <td>N<?php echo  number_format($row['tithe'],2);?></td>
						   						  					              <td>N<?php echo  number_format($row['expenses'],2);?></td>
						   						  					                  <td><?php echo $row['expense_type'] ?></td>
						   						  					                <td>N<?php echo  number_format($row['fulloffering'],2);?></td>
                                                                                    
						<td>N<?php echo  number_format($row['Ad_treasury'],2);?></td> 
                          						  					           		<td>N<?php echo  number_format($row['treasury'],2);?></td>


						   						  					                    <td><?php echo date('m/d/Y H:i:s',$row['date_submitted']);?></td>
						   						  					                     <td><?php echo $flag ?></td>
						  				          </tr>
<?php

$first_timers =  $first_timers + $row['first_timers'];
$totaloffering = $totaloffering + $row['offering'];
$totaltithe =    $totaltithe + $row['tithe'];
$totalexpenses = $totalexpenses + $row['expenses'];
$totalAd_treasury = $totalAd_treasury + $row['Ad_treasury'];
$totaltreasury = $totaltreasury + $row['treasury'];
$fulloffering = $fulloffering + $row['fulloffering'];

	}
?>
<tr>
					       <td height="40"></td>

                            <td></td>
					        <td></td>
					        <td></td>
					       				
                         
					        <td style="background-color:#3B4F36; color:#fff; font-weight:bold;">N<?php echo  number_format($totaloffering,2);?></td>
					        <td style="background-color:#3B4F36; color:#fff; font-weight:bold;">N<?php echo  number_format($totaltithe,2);?></td>
					        <td style="background-color:#3B4F36; color:#fff; font-weight:bold;">N<?php echo  number_format($totalexpenses,2);?></td>
					        <td style="background-color:#3B4F36; color:#fff; font-weight:bold;"></td>
					        <td style="background-color:#3B4F36; color:#fff; font-weight:bold;">N<?php echo  number_format($fulloffering,2);?></td>
                            <td style="background-color:#3B4F36; color:#fff; font-weight:bold;">N<?php echo  number_format($totalAd_treasury,2);?></td>
					        <td style="background-color:#3B4F36; color:#fff; font-weight:bold;">N<?php echo  number_format($totaltreasury,2);?></td>
 							<td></td>

					        <td></td>
				          </tr>
				        </table></td>
				      </tr>
					
					  <td></tr>
			      </table>
					<p>&nbsp;</p>
				</div>
			</div>
		</div>
        </div>
	<?php require_once("inc_footer.php") ?>
</body>
</html>
