<?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')");
//-------------
?>

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

	<style>
		body {
            margin: auto;
            background-color: #bbb;
            color : #fff;
            background-image : url('../images/bg_brown_01.jpg');
            max-width: 900px;
            }
		a { text-decoration: none; color:inherit;}
		a:hover {color:#FF00FF;}   /* Mouse over link */
		table, th, td {
    	border-collapse:collapse;
    	border:1px solid #999;
    	font-family:Tahoma, Geneva, sans-serif;
    	font-size:12px;
        }
        .head {
        	background: rgb(206,220,231); /* Old browsers */
        	background: -moz-linear-gradient(top,  rgba(206,220,231,1) 0%, rgba(89,106,114,1) 100%); /* FF3.6+ */
        	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(206,220,231,1)), color-stop(100%,rgba(89,106,114,1))); /* Chrome,Safari4+ */
        	background: -webkit-linear-gradient(top,  rgba(206,220,231,1) 0%,rgba(89,106,114,1) 100%); /* Chrome10+,Safari5.1+ */
        	background: -o-linear-gradient(top,  rgba(206,220,231,1) 0%,rgba(89,106,114,1) 100%); /* Opera 11.10+ */
        	background: -ms-linear-gradient(top,  rgba(206,220,231,1) 0%,rgba(89,106,114,1) 100%); /* IE10+ */
        	background: linear-gradient(to bottom,  rgba(206,220,231,1) 0%,rgba(89,106,114,1) 100%); /* W3C */
        	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cedce7', endColorstr='#596a72',GradientType=0 ); /* IE6-9 */
        	text-shadow:1px 1px 0px #CCC;
        	font-size:18px;
        	padding:10px;
        	color:#333;
            }
        img {
            width: 100%;
            max-width: 500px;
            height: auto;
        }
        .btn-pastel-green {
          background-color: #29434E; /* Hijau Pastel */
          border: none;
          color: #ccc;
          padding: 10px 3px;
          text-align: center;
          text-decoration: none;
          display: inline-block;
          font-size: 21px;
          font-family: "Times New Roman";
          margin: 4px 2px;
          cursor: pointer;
          border-radius: 8px;
          transition-duration: 0.4s;
          width:31%;
        }

        .btn-pastel-green:hover {
          background-color: #9ab87a; /* Hijau Pastel yang lebih gelap */
          color: white;
        }
        h2 {
            color:#B61A1A;
            text-align: center;
            font-family: "Times New Roman";
            font-size:33px;
            text-shadow:1px 1px 0px #CCC;
        }
        .satu {
        	background-color:#CECECE;
            }
         
        .dua {
        	background-color:#E0E0E0;
            }

	
    </style>	
</head>
<body>
    <div><img src="../images/Piutang.png" alt="Pinjaman" width="100%" height="auto"></div>
    <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>
        <?php
        //----------------------
        $sql = "SELECT * FROM novia_abc_users ORDER BY id ASC";
        $result = $conn->query($sql);
        if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
                $id = $row['id'];
                if ($id != 3){
        		//--------
                    $TotalPinjaman = 0;
                    $sql1 = "SELECT * FROM novia_abc_cash_loan WHERE userid = $id ORDER BY id ASC";
                    $result1 = $conn->query($sql1);
                    if ($result1->num_rows > 0) {
                        while($row1 = $result1->fetch_assoc()) {
                            $TotalPinjaman += $row1['nilai'];
                        }
                    }
        		//--------
    	?>
    	    
    	    <button class="btn-pastel-green"><a href="cash-piutang.php?userid=<?php echo $row['id'] ?>" style="font-size:16px;" title="Total Piutang"><?php echo $row['name']."<br>Total = ".$TotalPinjaman ?></a></button>
	        	    
        <?php
                }
            }
        }
        ?>    

<br>
<?php 
    $userid = $_GET['userid'];
    $query = mysqli_query($conn, "SELECT id,name FROM novia_abc_users where id='$userid'");
    $userData = mysqli_fetch_array($query);
    $user_name1   = $userData['name'];    
    $name = $NAME[$userid];
    
?>
    



    	<table width="100%" max-width="600px" cellpadding="5" align="center">
        <tr class="head">
            <td>No</td>
            <td>Tanggal</td>
            <td>Jumlah</td>
            <td>Keterangan Pinjaman</td>
            <td>Hapus</td>
        </tr>

    
    
    <?php
     //--------
        $Count = 0;
        $Jumlah = 0;
        $sql = "SELECT * FROM novia_abc_cash_loan WHERE userid = $userid ORDER BY id DESC";
        $result = $conn->query($sql);
        if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
                $Count ++;
                $si = $row['tanggal'];
                $dti = new DateTime($si);
                $Tanggal = $dti->format('Y-m-d');
                $Jumlah += $row['nilai'];
                $id = $row['id'];
                ?>
                <tr>
                    <td><?php echo $Count ?></td>
                    <td><a href="cash-piutang-edit.php?id=<?php echo $row['id'] ?>"><?php echo $Tanggal ?></a></td>
                    <td align="right"><a href="cash-piutang-edit.php?id=<?php echo $row['id'] ?>"><?php echo $row['nilai'] ?></a></td>
                    <td><a href="cash-piutang-edit.php?id=<?php echo $row['id'] ?>"><?php echo $row['keterangan'] ?></a></td>
                    <form method="post" action="cash-piutang-hapus.php?id=<?php echo $id."-".$userid ?>">
                    <td><input type="submit" name="submit" value="Hapus"></td>
                    </form>
                </tr>
                <?php

                
            }
        }
	//--------   
    

    ?>
    <h2><?php echo $name." = ".$Jumlah; ?></h2>
    </table> 	
    <br>
    <form  method="post"  action="cash-piutang-insert.php?userid=<?php echo $userid; ?>">
    	<table width="100%" max-width="600px" cellpadding="5" align="center">

            <tr class="dua">
                <td><input type="text" name="keterangan" placeholder="Keterangan" size="18" maxlength="500" autocomplete="off" autofocus value=""/></td>
                <td><input type="text" name="nilai" placeholder="nilai" size="5" maxlength="10" autocomplete="off" autofocus value=""/></td>
                <td><button type="submit" name="simpan" style="padding: 10px; width: 100%; background-color:#29434E; color:#ccc;">TAMBAH</button</td> 
            </tr>        
        </table>
    </form>
    <br>
</body>
</html>

