<?php require 'ust.php'; ?>
  <main id="main" class="main">
    <section class="section dashboard">
          <div class="row">
            <div class="col-lg-3">
              <div class="card info-card sales-card">
                <div class="card-body">
                  <h5 class="card-title">Toplam Üye</h5>
                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-person"></i>
                    </div>
                    <?php $uyesay = mysqli_num_rows(mysqli_query($db, "SELECT * FROM uyeler")); ?>
                    <div class="ps-3">
                      <h6><?php echo $uyesay; ?></h6>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-lg-3">
              <div class="card info-card revenue-card">
                <div class="card-body">
                  <h5 class="card-title"> Onay Bekleyen Falcı </h5>
                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-people"></i>
                    </div>
                    <?php $falcısay = mysqli_num_rows(mysqli_query($db, "SELECT * FROM yorumcular WHERE onay = '0'")); ?>
                    <div class="ps-3">
                      <h6><?php echo $falcısay; ?></h6>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-lg-3">
              <div class="card info-card customers-card">
                <div class="card-body">
                  <h5 class="card-title">Bekleyen Fallar</h5>
                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-stars"></i>
                    </div>
                    <?php
                    $kahvefalisayisi = mysqli_num_rows(mysqli_query($db, "SELECT * FROM kahvefali WHERE fal_durum = 'Bakılmadı'"));
                    $tarotfalisayisi = mysqli_num_rows(mysqli_query($db, "SELECT * FROM tarotfali WHERE durum = 'Bakılmadı'"));
                    $yildiznamefalisayisi = mysqli_num_rows(mysqli_query($db, "SELECT * FROM yildiznamefali WHERE fal_durum = 'Bakılmadı'"));
                    $katinafalisayisi = mysqli_num_rows(mysqli_query($db, "SELECT * FROM katinafali WHERE durum = 'Bakılmadı'"));
                    $sufalisayisi = mysqli_num_rows(mysqli_query($db, "SELECT * FROM sufali WHERE fal_durum = 'Bakılmadı'"));
                    $toplambkleyenfalsayisi = $kahvefalisayisi + $tarotfalisayisi + $yildiznamefalisayisi + $katinafalisayisi + $sufalisayisi;
                     ?>
                    <div class="ps-3">
                      <h6><?php echo $toplambkleyenfalsayisi; ?></h6>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-lg-3">
              <div class="card info-card sales-card">
                <div class="card-body">
                  <h5 class="card-title">Toplam Kazanç</h5>
                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-cash"></i>
                    </div>
                    <?php $kazancsay = mysqli_fetch_array(mysqli_query($db, "SELECT SUM(istek_kredi)  FROM kredibozmaislemleri"));
                    $kredikomisyon = $kazancsay[0] * $komisyon;
                    $kredisonuc = $kredikomisyon / 100;
                    $kredisonucc = $kredisonuc / 10;
                    ?>
                    <div class="ps-3">
                      <h6><?php echo $kredisonucc; ?> ₺</h6>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-12">
              <div class="card">
            <div class="card-body">
              <h5 class="card-title">Bekleyen Ödeme Talepleri</h5>
              <small>Burada Listelenen Ödemeler Komisyon Oranı Düşülerek Yansıtılmıştır</small>
              <div class="table-responsive">
              <table class="table table-striped datatable">
                <thead>
                  <tr>
                    <th scope="col">Yorumcu Adı</th>
                    <th scope="col">Çekmek İstediği Kredi Miktarı</th>
                    <th scope="col">Çekmek İstediği ₺ Miktarı</th>
                    <th scope="col">Tarih</th>
                    <th scope="col">Durum</th>
                    <th scope="col">Düzenle</th>
                  </tr>
                </thead>
                <tbody>
                  <?php
                  $getir = mysqli_query($db, "SELECT * FROM kredibozmaislemleri ORDER BY id DESC");
                  while ($listele = mysqli_fetch_array($getir)) {
                    $yid = $listele["yorumcu_id"];
                    $ydetay = mysqli_fetch_array(mysqli_query($db, "SELECT * FROM yorumcular WHERE id = '$yid'"));
                   ?>
                  <tr>
                    <td><?php echo $ydetay["ad_soyad"] ?></td>
                    <td><?php echo $listele["istek_kredi"] ?></td>
                    <td><?php echo $listele["istek_kredi"] / 10; ?> ₺</td>
                    <td><?php echo $listele["tarih"] ?></td>
                    <td><?php echo $listele["durum"] ?></td>
                    <td><button type="button" class="btn btn-success btn-sm" data-bs-toggle="modal" data-bs-target="#exampleModal_<?php echo $listele["id"]; ?>"><i class="bi bi-gear"></i> Düzenle</button></td>
                  </tr>
                  <div class="modal fade" id="exampleModal_<?php echo $listele["id"]; ?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                      <div class="modal-content">
                        <div class="modal-header">
                          <h5 class="modal-title" id="exampleModalLabel"><?php echo $ydetay["ad_soyad"]; ?> Yorumcunun Kredi İşlemi</h5>
                          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                          <form method="post">
                            <div class="mb-3">
                              <label for="exampleInputEmail1" class="form-label">Ad Soyad</label>
                              <input type="text" class="form-control" value="<?php echo $ydetay["ad_soyad"]; ?>" disabled>
                            </div>
                            <div class="mb-3">
                              <label for="exampleInputEmail1" class="form-label"> İban Bilgisi </label>
                              <input type="text" class="form-control" value="<?php echo $ydetay["iban"]; ?>" disabled>
                            </div>
                              <div class="mb-3">
                                <label for="exampleInputEmail1" class="form-label">Çekmek İstediği Kredi Miktarı</label>
                                <input type="text" class="form-control" value="<?php echo $listele["istek_kredi"]; ?>" disabled>
                                <input type="hidden" name="krediid" class="form-control" value="<?php echo $listele["id"]; ?>" >
                              </div>
                              <div class="mb-3">
                                <label for="exampleInputEmail1" class="form-label">Kredi ₺ İşlemi</label>
                                <input type="text" class="form-control" value="<?php echo $listele["istek_kredi"] / 10; ?> ₺" disabled>
                              </div>
                              <div class="mb-3">
                                <label for="exampleInputEmail1" class="form-label">Durum Güncelle</label>
                                <select name="durum" class="form-select">
                                  <option value="İşleme Alındı">İşleme Alındı</option>
                                  <option value="Banka Hesabına Aktarıldı">Banka Hesabına Aktarıldı</option>
                                    <option value="İptal Edildi">İptal Edildi</option>
                                </select>
                              </div>
                              <button type="submit" name="kredibozma" class="btn btn-primary">Uygula</button>
                            </form>
                        </div>
                        <div class="modal-footer">
                          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Pencereyi Kapat</button>
                        </div>
                      </div>
                    </div>
                  </div>
                <?php } ?>
                </tbody>
              </table>
            </div>
            </div>
          </div>
            </div>
      </div>
    </section>
  </main>
<?php require 'footer.php'; ?>
<?php
  if (isset($_POST["kredibozma"])) {
    $krediid = $_POST["krediid"];
    $durum = $_POST["durum"];
    $duzenle = mysqli_query($db, "UPDATE kredibozmaislemleri SET durum = '$durum' WHERE id = '$krediid'");
    if ($duzenle) {
      echo '<script>swal("Başarılı", "Kredi Düzenleme İşlemi Başarılı Bir Şekilde Uygulandı", "success");setTimeout(function(){ window.location.assign("anasayfa.php");}, 2000);</script>';
    }else {
      echo '<script>swal("Hata", "Beklenemdik Bir Hata Meydana Geldi Lütfen Tekrar Deneyin.", "error");</script>';
    }
  }
 ?>
