<?php
    include('../loginsession.php');
    error_reporting(E_ALL);
    $filename = __FILE__;  //---Nama file saat ini
    if (strlen(__FILE__) > 48) {$filename = substr(__FILE__, 48);}
    $save = mysqli_query($conn, "INSERT INTO novia_abc_user_logs (userid,filename) VALUES ('$userini_id','$filename')");
    
    //---
    
    if(isset($_GET['tanggal'])){
    $tgl = $_GET['tanggal'];
    }
    $bulan = new DateTime($tgl);
    $formated_dateyear = $bulan->format('Y-m');
    $formated_date = $bulan->format('M Y'); // Tuesday
    
    $dt1 = new DateTime($tgl);
    $timeU1 = $dt1->format('U');
    $viaMundur = $timeU1 - 2592000;
    $tgl1 = date("Y-m-d", substr($viaMundur, 0, 10));
    
    $dt2 = new DateTime($tgl);
    $timeU2 = $dt2->format('U');
    $viaMaju = $timeU2 + 2592000;
    $tgl2 = date("Y-m-d", substr($viaMaju, 0, 10));    
        
    
    //---
    /*
    $dt1 = new DateTime($tgl);
    $timeU1 = $dt1->format('U');
    $viaMundur = $timeU1 - 86400;
    $tgl1 = date("Y-m-d", substr($viaMundur, 0, 10));
    
    
    $dt2 = new DateTime($tgl);
    $timeU2 = $dt2->format('U');
    $viaMaju = $timeU2 + 86400;
    $tgl2 = date("Y-m-d", substr($viaMaju, 0, 10));
    
    $bulan = new DateTime($tgl);
    $formated_date = $bulan->format('d M Y'); // Tuesday
    $Hari = $bulan->format('l');
    $hari = $HARI[$Hari];
    */
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//ID" "http://www.w3.org/TR/html4/frameset.dtd">
<html lang="id">
<head>
	<title>STATISTIK KEUANGAN</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>

		input[type=text],input[type=password]
		{
		width:60%;
		padding:8px;
		margin-top:8px;
		margin-bottom:8px;
		border:1px solid #ccc;
		padding-left:5px;
		font-size:18px;
		}

		input[type=submit]
		{
		width:35%;
		background-color:#8baca4;
		color:#FFFFFF;
		border:2px solid #8baca4;
		padding:6px;
		font-size:18px;
		cursor:pointer;
		border-radius:5px;
		}
		img {
            width: 100%;
            max-width: 500px;
            height: auto;
        }
    </style>	
</head>

<body>

    <div><img src="../images/page/keuangan_statistik.png" alt="Keuangan Harian"></div>

    <table width="100%" cellpadding="5">

		<tr class="dua">
		    <td><a href="../index.php" title="HOME"><button style="padding : 10px; width:100%; background-color:#A6B7C1;"> HOME </button></a></td>    		
		    <td width="33%"><a href="../administrasi.php" title="NAVIGASI"><button style="padding : 10px; width:100%; background-color:#A6B7C1;">NAVIGASI</button></a></td>
		</tr>
	</table>
	<table width="100%" cellpadding="5">
		<tr class="dua">
		<td><a href="cash-view-monthly.php?tanggal=<?php echo date("Y-m-d");?>" title="Lihat Pengeluaran Bulan ini"><button style="padding : 10px; width:100%; background-color:#8baca4;">BELANJA BULANAN</button></a></td>
		<td><a href="cash-view-daily.php?tanggal=<?php echo date("Y-m-d");?>" title="Lihat Pengeluaran Hari ini"><button style="padding : 10px; width:100%; background-color:#8baca4;"> BELANJA 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="cash-stat.php?tanggal=<?php echo $tgl1;?>" title="Lihat bulan 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 "Pengeluaran ".$formated_date; ?><a>
			</td>
			<td width="5%" style="padding-top : 10 px"; align="center";>
				<a href="cash-stat.php?tanggal=<?php echo $tgl2;?>" title="Lihat bulan berikutnya" style = "font-family: 'Heebo' sans-serif; font-size:25px;">><a>
			</td>
			
		</tr>

		<tr class="satu">
			<td colspan=3  align="center";>
				<form method="get">
					<label>PILIH BULAN</label>
					<input type="date" name="tanggal">
					<input type="submit" value="GO">
				</form>
			</td>
		</tr>
	</table>
    
    


<table width="100%" cellpadding="5">
	<tr class="head">
		<th width="15">No</th>
		<th width="150">Sub Kategori</th>
		<th align="left">Bulanan</th>
		<th align="left">Semua</th>
		<td></td>
	</tr>

<?php 


$sty = 1;
$sql = "SELECT * FROM novia_abc_cash_category_sub";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
	while($row = $result->fetch_assoc()) {
		
		$si = $row['maincategory'] + 1;
		$y = 2;
		$result1 = fmod($si,$y);
		if ( $result1 == 0 ) $sty = "dua";
		if ( $result1 == 1 ) $sty = "satu";
		//---
		$idr = $row['id'];
		$total = 0;
		$all = 0;
		$sql_2 = "SELECT * FROM novia_abc_cash_shopping WHERE subcategory_id=$idr";
		$result_2 = $conn->query($sql_2);
        if ($result_2->num_rows > 0) {
        	while($row_2 = $result_2->fetch_assoc()) {
                
        	    $all += $row_2['harga'];
        	    
        	    $si_2 = $row_2["date_"];
                $dti_2 = new DateTime($si_2);
                $currdate_2 = $dti_2->format('Y-m');
        		if ( $currdate_2 == $formated_dateyear){
        			$total += $row_2['harga'];
        		}
        	}
        }
        //---

		
?>
	<tr class=<?php echo $sty; ?>>
		<td width="15" align="center"><?php echo $row["id"]; ?></td>
		<td width="150" align="left"><a href="cash-stat-item.php?item=<?php echo $idr;?>" title=""><?php echo $row["subcategory_item"]; ?></a></td>			
		<td align="right"><?php echo $total; ?></td>
		<td align="right"><?php echo $all; ?></td>
		<td></td>
	</tr>
<?php
	}
} else {
    echo "0 results";
}
?>
</body>
</html>
