<?php require 'ust.php'; ?>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<main id="main">
  <section class="breadcrumbs">
    <div class="container">
      <div class="d-flex justify-content-between align-items-center">
        <h2>Yorumcu Paneli</h2>
        <ol>
          <li><a href="index.php">Ana Sayfa</a></li>
          <li>Yorumcu Paneli</li>
        </ol>
      </div>
    </div>
  </section>
  <section class="inner-page">
    <div class="container">
      <div class="col-lg-12">
      <div class="row">
        <div class="col-lg-3">
          <?php require 'ypm.php'; ?>
        </div><br>
      <div class="col-lg-9">
            <div class="col-lg-12" data-aos="fade-up" data-aos-delay="100">
              <div class="card">
                  <div class="card-header" style="background: rgba(1, 4, 136, 0.9); text-align: center;">
                    <span style="text-align: center; color: #fff"> Ödeme Talebinde Bulunun </span>
                  </div>
                  <div class="card-body">
                    <?php
                    $yid = $_SESSION["yorumcuid"];
                    $yorumcudetay = mysqli_fetch_array(mysqli_query($db, "SELECT * FROM yorumcular WHERE id = '$yid'"));
                    $ykredi = $yorumcudetay["kredi"];
                    $ytlc = $ykredi / 10;
                     ?>
                    <form method="post">
                      <div class="form-group my-4">
                        <label for="exampleInputEmail1">Çekmek İstediğiniz Kredi Miktarı</label><br>
                        <label style="color: red;">Toplam Krediniz <?php echo $ykredi; ?> Kredi</label><br>
                        <label style="color: red;">Kredi TL Karşılığı : <?php echo $ytlc; ?> ₺</label><br>
                        <label style="color: red;">Minimum Para Çekme Limiti : 10 ₺ ( 100 Kredi )</label>
                        <input min="100" name="istekkredi" max="<?php echo $ykredi; ?>" value="<?php echo $ykredi; ?>" type="number" class="form-control" required>
                        <small id="emailHelp" class="form-text text-muted">Kredi Bozdurma İşlemlerinde %<?php echo $komisyon; ?> Komisyon Uygulanmaktadır.</small><br>
                        <small id="emailHelp" class="form-text text-muted">10 Kredi 1 ₺'dir.</small>
                      </div>
                      <center><button style="background: rgba(1, 4, 136, 0.9);" type="submit" name="kredibislm" class="btn btn-primary"> Talepde Bulunun </button></center>
                    </form>
                  </div>
              </div>
            </div>
            <div class="col-lg-12" data-aos="fade-up" data-aos-delay="200">
              <div class="card">
                <div class="card-body">
                  <h3 class="card-title" style="text-align: center;">Ödeme Taleplerim</h3>
                  <div class="responsive-table">
                  <table class="table">
                      <thead>
                        <tr>
                          <th scope="col">#</th>
                          <th scope="col">Ödemede Bulunulan Kredi</th>
                          <th scope="col">Ödemede Bulunulan ₺</th>
                          <th scope="col">Tarih</th>
                          <th scope="col">Durum</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
                        $sayi = 0;
                        $yorumcusessioniddsi = $_SESSION["yorumcuid"];
                        $odemetalepleri = mysqli_query($db, "SELECT * FROM kredibozmaislemleri WHERE yorumcu_id = '$yorumcusessioniddsi'");
                        while ($listele = mysqli_fetch_array($odemetalepleri)) { $sayi++?>
                        <tr>
                          <td><?php echo $sayi; ?> </td>
                          <td><?php echo $listele["istek_kredi"]; ?> </td>
                          <td><?php echo $listele["istek_kredi"] / 10; ?> ₺</td>
                          <td><?php echo $listele["tarih"]; ?> </td>
                          <td><?php if($listele["durum"] == "İşleme Alındı"){ echo '<p style="background-color:yellow;">'.$listele["durum"].'</p>';}if($listele["durum"] == "Beklemede"){ echo '<p style="color:black;">'.$listele["durum"].'</p>';}if($listele["durum"] == "Banka Hesabına Aktarıldı"){ echo '<p style="background-color:green;">'.$listele["durum"].'</p>';} ?> </td>
                        </tr>
                      <?php } ?>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
      </div>
      </div>
      </div>
    </div>
  </section>
</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<?php require 'footer.php'; ?>
<?php

if(isset($_POST["kredibislm"])){
  $istekkredi = $_POST["istekkredi"];
  $kredikomisyon = $istekkredi * $komisyon;
  $kredisonuc = $kredikomisyon / 100;
  $komislukredi = $istekkredi - $kredisonuc;
  $tarih = date("d.m.Y");
  if ($istekkredi <= $yorumcudetay["kredi"]) {
  $krediiekle = mysqli_query($db, "INSERT INTO kredibozmaislemleri(yorumcu_id,istek_kredi,tarih)VALUES('$yid','$komislukredi','$tarih')");
  if($krediiekle){
    $kds = mysqli_query($db, "UPDATE yorumcular SET kredi = kredi - '$istekkredi' WHERE id = '$yid'");
  echo '<script> swal("Başarılı", "Kredi Bozdurma Talebiniz İletildi", "success"); </script>';
}
}else {
  echo '<script> swal("Hatalı İstek", "Bozdurmak İstediğiniz Tutar Kredinizden Büyük Olamaz", "warning"); </script>';
}
}
 ?>
