<?php 
    date_default_timezone_set("Asia/Jakarta");
    error_reporting(E_ALL);
    include 'config.php';
    include('loginsession.php');
    $filename = __FILE__;
    if (strlen(__FILE__) > 48) {$filename = substr(__FILE__, 48);}
    $save = mysqli_query($conn, "INSERT INTO novia_abc_user_logs (userid,filename) VALUES ('$userini_id','$filename')");
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//ID" "http://www.w3.org/TR/html4/frameset.dtd">
<html lang="id">
<head>
	<title>PASIEN TAHUN INI</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="css/style.css">
	<link href="images/balance.ico" rel="icon" type="image/icon" />
	<style>

    </style>	
</head>

<body>
<?php

if(isset($_GET['tanggal'])){
$no = 0;
$ni = 0;
$total_stok= 0;
$no1 = 0;
$total_stok1= 0;
$sty = 1;
$tgl = $_GET['tanggal'];
$medrek = substr($tgl,0,8);
$medrek1 = substr($tgl,8,2);
$today = date("Y-m-d");

$bulan = new DateTime($tgl);
$formated_dateyear = $bulan->format('Y');
$formated_date = $bulan->format('Y'); // Tuesday

$income = "SELECT date_, biaya FROM novia_abc_visit ORDER BY date_ ASC";
$resultan = $conn->query($income);
if ($resultan->num_rows > 0) {
    while($baris = $resultan->fetch_assoc()) {
		$si = $baris["date_"];
        $dti = new DateTime($si);
        $currdate_ = $dti->format('Y');
		if ( $currdate_ == $formated_dateyear){
			$no1++;
			$total_stok1 += $baris["biaya"];
		}
	}	
} else {}

$dt1 = new DateTime($tgl);
$timeU1 = $dt1->format('U');
$viaMundur = $timeU1 - 31104000;
$tgl1 = date("Y-m-d", substr($viaMundur, 0, 10));


$dt2 = new DateTime($tgl);
$timeU2 = $dt2->format('U');
$viaMaju = $timeU2 + 31104000;
$tgl2 = date("Y-m-d", substr($viaMaju, 0, 10));

?>

	<table width="100%" cellpadding="5">
		<tr class="dua">
			<td width="5%"><a href="index.php" title="Kembali ke halaman awal"><button style="padding : 10px; width:100%">HOME</button></a></td>
			<td><a href="visit-monthly.php?tanggal=<?php echo $today;?>" title="Lihat Pasien Bulan ini"><button style="padding : 10px; width:100%">PASIEN BULANAN</button></a></td>
			<td><a href="visit-daily.php?tanggal=<?php echo $today;?>" title="Lihat Pasien Bulan ini"><button style="padding : 10px; width:100%">PASIEN HARIAN</button></a></td>
		</tr>
	</table>
	
	<table width="100%" cellpadding="5">
		<tr class="dua">
			<td width="5%" style="padding-top : 10 px"; align="center";>
				<a href="visit-yearly.php?tanggal=<?php echo $tgl1;?>" title="Lihat pasien tahun sebelumnya" style = "font-family: 'Heebo' sans-serif; font-size:25px;"><<a>

			</td>
			<td width="25%" style="padding-top : 5 px;" align="center";>
				<a style = "font-family: 'Heebo' sans-serif; font-size:25px;"><?php echo "Pasien ".$formated_date; ?><a>
			</td>
			<td width="5%" style="padding-top : 10 px"; align="center";>
				<a href="visit-yearly.php?tanggal=<?php echo $tgl2;?>" title="Lihat pasien tahun berikutnya" style = "font-family: 'Heebo' sans-serif; font-size:25px;">><a>
			</td>
		</tr>
		<tr class="satu">
			<td colspan=3 style="padding-top : 5 px;" align="center";><a style = "font-family: 'Heebo' sans-serif; font-size:20px;"><?php echo "Tahunan ".$no1." : Income ".$total_stok1; ?></a></td>
		</tr>
	</table>
	
	<table width="100%" cellpadding="5" align="center">
		<tr class="satu">
			<td>
				<form method="get">
					<label>PILIH TANGGAL</label>
					<input type="date" name="tanggal">
					<input type="submit" value="GO">
				</form>
			</td>
		</tr>
	</table>
	
	
	<table width="100%" cellpadding="5">
		<tr class="head" align="left">
			<th width="5%">No</th>
			<th width="15%">Date</th>
			<th width="10%">MR</th>
			<th width="22%">Nama</th>
			<th width="25%">Tindakan</th>
			<th width="10%">Biaya</th>
			<th width="10%">Edit Satus</th>
		</tr>
	
	

<?php 
$gantitanggal = 0;
$sql = "SELECT * FROM novia_abc_visit ORDER BY date_ DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
		
		$s = $row["date_"];
        $dt = new DateTime($s);
        $currdate = $dt->format('Y');
        $jam = $dt->format('d M');
        $jamganti = $dt->format('d');
		
		if ( $currdate == $formated_dateyear){
			if ( $gantitanggal != $jamganti ){
				$gantitanggal = $jamganti;
				$no++;
			}
			$ni++;
			$y = 2;
			$result1 = fmod($no,$y);
			if ( $result1 == 0 ) $sty = "dua";
			if ( $result1 == 1 ) $sty = "satu";
			$total_stok += $row["biaya"];
			
			$imr = $row["mr"];
			$sql_1 = mysqli_fetch_array(mysqli_query($conn, "SELECT name FROM novia_abc_biodata where mr='$imr'"));
			$namo = $sql_1['name'];
			
			
				?>
				
				<tr class=<?php echo $sty; ?>>
					<td><?php echo $ni; ?>.</td>
					<td align="left"><a <a href="status-view.php?id=<?php echo $row["mr"];?>" title="Lihat Status Pasien"><?php echo $jam; ?></a></td>
					<td align="left"><a <a href="status-view.php?id=<?php echo $row["mr"];?>" title="Lihat Status Pasien"><?php echo $row["mr"]; ?></a></td>
					<td align="left"><a <a href="status-view.php?id=<?php echo $row["mr"];?>" title="Lihat Status Pasien"><?php echo $sql_1["name"]; ?></a></td>
					<td align="left"><a <a href="status-view.php?id=<?php echo $row["mr"];?>" title="Lihat Status Pasien "><?php echo $row["tindakan"]; ?></a></td>
					<td align="left"><a <a href="status-view.php?id=<?php echo $row["mr"];?>" title="Lihat Status Pasien "><?php echo $row["biaya"]; ?></a></td>
					<td align="left"><a href="status-daftar-edit.php?imr=<?php echo $row["mr"]."-".$tgl."-".$row["id"];?>" title="Edit Kunjungan Pasien "><button>Edit Status</button></a></td>
					
				</tr>
				<?php
				}
			}
		} else {
			//echo "0 results";
	}
}
?>
		<tr class="head" align="left">
			<th colspan="5">Total</th>
			<th colspan="2"><?php echo $total_stok; ?></th>
		</tr>
</table>

</body>
</html>
