<?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')");
    $today = date("Y-m-d");
?>

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

	<style>

        body {
            color : #fff;
            }    

		img {
            width: 100%;
            max-width: 500px;
            height: auto;
        }
        h1 {
            color:#B61A1A;
            text-align: center;
            font-family: "Times New Roman";
            font-size:33px;
            text-shadow:1px 1px 0px #CCC;
        }
        
        h2 {
            color:#819CA9;
            text-align: right;
            font-family: "Times New Roman";
            font-size:21px;
            text-shadow:1px 1px 0px #CCC;
        }
        table, th, td {
    	border-collapse:collapse;
    	border:1px solid #999;
    	font-family:Tahoma, Geneva, sans-serif;
    	font-size:12px;
        }
        .header {
        background-color: #f1f1f1;
        padding: 20px;
        text-align: center;
        margin: 0;
        }
        .head th {
    	padding:10px;
    	color:#333;
    	text-shadow:1px 1px 0px #CCC;
    	font-size:14px;
        }
	    
    </style>	
</head>
<body>
    <table width="100%" cellpadding="5">
		<tr class="dua">
		    <td><a href="../administrasi.php" title="Navigasi"><button style="padding : 10px; width:100%; background-color:#A6B7C1;"> PUSAT NAVIGASI </button></a></td>
		    <td><a href="../index.php" title="Halaman Awal"><button style="padding : 10px; width:100%; background-color:#A6B7C1;"> HOME </button></a></td>
		</tr>
	</table>
	
	<br>
    <h1>STOCK MEDIS</h1>
    <br>
<?php
    
    $jarum = 0;
    $procain = 0;
    $colagen = 0;
    $tation = 0;
    $moksa = 0;
    
    $sql = "SELECT * FROM novia_abc_cash_shopping ORDER BY id ASC";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            
            $Yur = new DateTime($row['date_']);
            $yur = $Yur->format('Y');
            if ($yur >= '2025'){
                if($row['subcategory_id']=='15'){
                    $jarum += $row['jumlah'];
                }
                if($row['subcategory_id']=='30'){
                    $procain += $row['jumlah'];
                }
                if($row['subcategory_id']=='31'){
                    $colagen += $row['jumlah'];
                }
                if($row['subcategory_id']=='32'){
                    $tation += $row['jumlah'];
                }
                if($row['subcategory_id']=='20'){
                    $moksa += $row['jumlah'];
                }
                
            }
        }
    }

    $jarum1 = 0;
    $procain1 = 0;
    $colagen1 = 0;
    $tation1 = 0;
    //$moksa1 = 2;
    
    $jarum_today = 0;
    $procain_today = 0;
    $colagen_today = 0;
    $tation_today = 0;
    
    $sql1 = "SELECT * FROM novia_abc_visit ORDER BY id ASC";
    $result1 = $conn->query($sql1);
    if ($result1->num_rows > 0) {
        while($row1 = $result1->fetch_assoc()) {
            
            $yur1 = new DateTime($row1['date_']);
            if ($yur1 >= '2025'){
                $jarum1 += $row1['pin'];
                $procain1 += $row1['procain'];
                $colagen1 += $row1['colagen'];
                $tation1 += $row1['tation'];
            }
    		$s = $row1["date_"];
            $dt = new DateTime($s);
            $currdate = $dt->format('Y-m-d');
    		
    		$dt1 = new DateTime($today);
            $currdate1 = $dt1->format('Y-m-d');
    		
    		if ( $currdate == $currdate1){
    		    $jarum_today += $row1['pin'];
                $procain_today += $row1['procain'];
                $colagen_today += $row1['colagen'];
                $tation_today += $row1['tation'];
    		}
        }
    }
    
    $jarum2 = $jarum-$jarum1;
    $procain2 = $procain-$procain1;
    $colagen2 = $colagen-$colagen1;
    $tation2 = $tation-$tation1;
    //$moksa2 = $moksa-$moksa1;
?>    
    
    <table width="100%" cellpadding="5">
        <tr class="head">
            <th></th>
            <th>Sisa Stock</th>
            <th>Pemakaian Hari ini</th>
            <th>Total Beli</th>
            <th>Total Pakai</th>
        </tr>
        <tr>
            <td><h2>Jarum</h2></td>
            <td align="right"><h2><?php echo $jarum2; ?></h2></td>
            <td align="right"><h2><?php echo $jarum_today; ?></h2></td>
            <td align="right"><h2><?php echo $jarum; ?></h2></td>
            <td align="right"><h2><?php echo $jarum1; ?></h2></td>
            
        </tr>
        <tr>
            <td><h2>Prolene</h2></td>
            <td align="right"><h2><?php echo $procain2; ?></h2></td>
            <td align="right"><h2><?php echo $procain_today; ?></h2></td>
            <td align="right"><h2><?php echo $procain; ?></h2></td>
            <td align="right"><h2><?php echo $procain1; ?></h2></td>
            
        </tr>
        <tr>
            <td><h2>Colagen</h2></td>
            <td align="right"><h2><?php echo $colagen2; ?></h2></td>
            <td align="right"><h2><?php echo $colagen_today; ?></h2></td>
            <td align="right"><h2><?php echo $colagen; ?></h2></td>
            <td align="right"><h2><?php echo $colagen1; ?></h2></td>
            
        </tr>
        <tr>
            <td><h2>Tation</h2></td>
            <td align="right"><h2><?php echo $tation2; ?></h2></td>
            <td align="right"><h2><?php echo $tation_today; ?></h2></td>
            <td align="right"><h2><?php echo $tation; ?></h2></td>
            <td align="right"><h2><?php echo $tation1; ?></h2></td>
        </tr>
        <tr>
            <td><h2>Moksa</h2></td>
            <td align="right"><h2><?php echo $moksa; ?></h2></td>
            <td><h2>-</h2></td>
            <td><h2>-</h2></td>
            <td><h2>-</h2></td>
        </tr>
    </table>
    
    
</body>