<?php
session_start();
if($_SESSION["username"]=="")
{
 	echo "You are not Logged in Please <a href='index.html'>Sign in </a> First ";
}
else
{

date_default_timezone_set("Asia/Karachi");
$today=date("Y-m-d");
$month = date("m",strtotime($today));
		$year = date("Y",strtotime($today));
		 $month_name = date("F", mktime(0, 0, 0, $month, 10));
		 $my=$month_name . " " . $year;
$start_date = date("Y-m-01");

// Last date of current month
$end_date = date("Y-m-t");
// Set the start and end dates
//$start_date = $_POST["from_date"];
//$end_date = $_POST["to_date"];
include 'dbc.php';


$sql1 = "SELECT * FROM addclass";
$result1=$conn->query($sql1);
$row1 = $result1->fetch_assoc();
$feedisc1=$row1['feedisc1'] ;
$feedisc2=$row1['feedisc2'] ;
$feedisc3=$row1['feedisc3'] ;
$feedisc4=$row1['feedisc4'] ;
$feedisc5=$row1['feedisc5'] ;
$feedisc6=$row1['feedisc6'] ;

// Convert the dates to timestamps
$start_timestamp = strtotime($start_date);
$end_timestamp = strtotime($end_date);

// Start displaying the calendar
?>
 <h1><center><? echo "" . $_SESSION["userid"]; ?></center></h1>
 <h2><center>Monthly Fee Summary Report</center></h2> 
<?php

echo "<table border='1' cellpadding='5' cellspacing='0'>";
echo "<tr><th>Total Students</th><th>Day</th><th>Date</th><th>Fee Amount</th><th>$feedisc1</th><th>$feedisc2</th><th>$feedisc3</th><th>$feedisc4</th><th>$feedisc5</th><th>$feedisc6</th><th>Fine</th><th>Total</th></tr>";

// Loop through each day between the start and end date
for ($current_date = $start_timestamp; $current_date <= $end_timestamp; $current_date = strtotime("+1 day", $current_date))
 {
    $day = date('l', $current_date);  // Day of the week
    $date = date('Y-m-d', $current_date);  // Date in YYYY-MM-DD format
	include 'dbc.php';
$tfee=0;
$tfee1=0;
$tfee2=0;
$tfee3=0;
$tfee4=0;
$tfee5=0;
$tfee6=0;
$tfine=0;
$total=0;
$trecord=0;
$sql = "SELECT * FROM rec_fee where  date='$date'";
$result=$conn->query($sql);
while($row = $result->fetch_assoc())
 
  {
  $tfee=$tfee + $row['feerec'];
  $tfee1=$tfee1 + $row['fee1rec'];
  $tfee2=$tfee2 + $row['fee2rec'];
  $tfee3=$tfee3 + $row['fee3rec'];
  $tfee4=$tfee4 + $row['fee4rec'];
  $tfee5=$tfee5 + $row['fee5rec'];
  $tfee6=$tfee6 + $row['fee6rec'];
   $tfine=$tfine + $row['fine'];
 
$trecord=$trecord + 1;
  }
  $total=$tfee+$tfee1+$tfee2+$tfee3+$tfee4+$tfee5+$tfee6+$tfine;
    // Display the day and date in the table
    echo "<tr><td>{$trecord}</td><td>{$day}</td><td>{$date}</td><td>{$tfee}</td><td>{$tfe1}</td><td>{$tfee2}</td><td>{$tfee3}</td><td>{$tfee4}</td><td>{$tfee5}</td><td>{$tfee6}</td><td>{$tfine}</td><td>{$total}</td></tr>";
	$tfeerec=$tfeerec + $tfee;
$tfee1rec=$tfee1rec + $tfee1;
$tfee2rec=$tfee2rec + $tfee2;
$tfee3rec=$tfee3rec + $tfee3;
$tfee4rec=$tfee4rec + $tfee4;
$tfee5rec=$tfee5rec + $tfee5;
$tfee6rec=$tfee6rec + $tfee6;
$tfinerec=$tfinerec + $tfine;
$ttotal=$ttotal + $total;
}
echo "<tr><td colspan=3>Total</td><td>{$tfeerec}</td><td>{$tfee1rec}</td><td>{$tfee2rec}</td><td>{$tfee3rec}</td><td>{$tfee4rec}</td><td>{$tfee5rec}</td><td>{$tfee6rec}</td><td>{$tfinerec}</td><td>{$ttotal}</td></tr>";
echo "</table>";
}
?>
