<?php
// ===== Halaman Admin ===== //
//Count Users
$total_pengguna = mysqli_num_rows($conn->query("SELECT * FROM users"));
//Total saldo user
$total_saldoUser = $conn->query("SELECT SUM(saldo) AS total FROM users");
$data_saldoUser = $total_saldoUser->fetch_assoc();
//Count Pesanan SOSMED
$count_pesanan_sosmed = mysqli_num_rows($conn->query("SELECT * FROM pembelian_sosmed"));
//Count Pesanan PPOB
$count_pesanan_ppob = mysqli_num_rows($conn->query("SELECT * FROM pembelian_ppob"));
//Total Pemesanan SOSMED
$total_pemesanan_sosmed = $conn->query("SELECT SUM(harga) AS total FROM pembelian_sosmed");
$data_pesanan_sosmed = $total_pemesanan_sosmed->fetch_assoc();
//Total Pemesanan PPOB
$total_pemesanan_ppob = $conn->query("SELECT SUM(harga) AS total FROM pembelian_ppob");
$data_pesanan_ppob = $total_pemesanan_ppob->fetch_assoc();

//Count Deposit
$count_deposit = mysqli_num_rows($conn->query("SELECT * FROM deposit WHERE status = 'Success'"));
//Total Deposit
$total_deposit = $conn->query("SELECT SUM(jumlah_transfer) AS total FROM deposit WHERE status = 'Success'");
$data_deposit = $total_deposit->fetch_assoc();

// Total Profit Pembelian Sosmed Perbulan
$ThisProfitSosmed = $conn->query("SELECT SUM(profit) AS total FROM pembelian_sosmed WHERE MONTH(pembelian_sosmed.date) = '" . date('m') . "' AND YEAR(pembelian_sosmed.date) = '" . date('Y') . "'");
$ProfitSosmed = $ThisProfitSosmed->fetch_assoc();

$ThisTotalSosmed = $conn->query("SELECT SUM(harga) AS total FROM pembelian_sosmed WHERE MONTH(pembelian_sosmed.date) = '" . date('m') . "' AND YEAR(pembelian_sosmed.date) = '" . date('Y') . "'");
$AllSosmed = $ThisTotalSosmed->fetch_assoc();

$CountProfitSosmed = mysqli_num_rows($conn->query("SELECT * FROM pembelian_sosmed WHERE MONTH(pembelian_sosmed.date) = '" . date('m') . "' AND YEAR(pembelian_sosmed.date) = '" . date('Y') . "'"));

// TOTAL LAYANAN //
$layanan_total =  mysqli_num_rows($conn->query("SELECT * FROM layanan_sosmed"));
$layanan_total_ppob =  mysqli_num_rows($conn->query("SELECT * FROM layanan_ppob"));

// TOTAL LAYANAN AKTIF //
$layanan_aktif =  mysqli_num_rows($conn->query("SELECT * FROM layanan_sosmed WHERE status = 'Aktif'"));
$layanan_aktif_ppob =  mysqli_num_rows($conn->query("SELECT * FROM layanan_ppob WHERE status = 'Normal'"));

// TOTAL LAYANAN TIDAK AKTIF //
$layanan_Tidak_aktif =  mysqli_num_rows($conn->query("SELECT * FROM layanan_sosmed WHERE status = 'Tidak Aktif'"));
$layanan_Tidak_aktif_ppob =  mysqli_num_rows($conn->query("SELECT * FROM layanan_ppob WHERE status = 'Gangguan'"));

// DEPOSIT QRIS //
$panggil_QRIS = $conn->query("SELECT * FROM logo_qris WHERE id = '1'");
$data_QRIS = $panggil_QRIS->fetch_assoc();

// PAymEnT gatEWAY SAKURUPIAH//
$DT_Pgateway = $conn->query("SELECT * FROM sakurupiah WHERE id = '1' OR nama = 'SAKURUPIAH'");
$data_Pgateway = $DT_Pgateway->fetch_assoc();

// EMAIL HOSTING //
$E_hosting = $conn->query("SELECT * FROM email_hosting WHERE id = '1'");
$data_hosting = $E_hosting->fetch_assoc();

// ===== Data Tiket ===== //
$AllTiketUsers = $conn->query("SELECT * FROM tiket WHERE status = 'Pending'");
// ======================== //

// ===== ============ ===== //

$cek_kodeReferral = $conn->query("SELECT * FROM referral_kode WHERE username = '$sess_username'");
$data_kodeReferral = $cek_kodeReferral->fetch_assoc();

// ===== Halaman Pengguna ===== //
// Data User
$jumlah_order_sosmed = mysqli_num_rows($conn->query("SELECT * FROM pembelian_sosmed WHERE user = '$sess_username'"));
$jumlah_order_ppob = mysqli_num_rows($conn->query("SELECT * FROM pembelian_ppob WHERE user = '$sess_username'"));
$jumlah_deposit_user = mysqli_num_rows($conn->query("SELECT * FROM deposit WHERE username = '$sess_username' AND status = 'Success'"));
$total_deposit_user = $conn->query("SELECT SUM(jumlah_transfer) AS total FROM deposit WHERE username = '$sess_username' AND status = 'Success'");
$data_deposit_user = $total_deposit_user->fetch_assoc();

$cek_order_sosmed = $conn->query("SELECT SUM(harga) AS total FROM pembelian_sosmed WHERE user = '$sess_username'");
$data_order_sosmed = $cek_order_sosmed->fetch_assoc();

$cek_order_ppob = $conn->query("SELECT SUM(harga) AS total FROM pembelian_ppob WHERE user = '$sess_username'");
$data_order_ppob = $cek_order_ppob->fetch_assoc();

// ===== ============== ===== //

// ===== Data Halaman Kontak ===== //
$CallDbHalaman = $conn->query("SELECT * FROM halaman WHERE id = '1'");
$PageContact = $CallDbHalaman->fetch_assoc();
// ======================== //

// ===== Data Tiket ===== //
$CallDBTiket = $conn->query("SELECT * FROM tiket WHERE status = 'Responded' AND user = '$sess_username'");
// ======================== //

// ===== Data Website ===== //
$panggil = $conn->query("SELECT * FROM setting_web WHERE id = '1'");
$data = $panggil->fetch_assoc();

// ===== Banner Slider ===== //
$banner_slider = $conn->query("SELECT * FROM banner_slider WHERE id = '1'");
$data_banner_slider = $banner_slider->fetch_assoc();


// ======================== //
$total_depo_succes = mysqli_num_rows($conn->query("SELECT * FROM deposit WHERE status = 'Success'"));
$total_depo_error = mysqli_num_rows($conn->query("SELECT * FROM deposit WHERE status = 'Error'"));
$total_depo_pending = mysqli_num_rows($conn->query("SELECT * FROM deposit WHERE status = 'Pending'"));

$total_sosmed_succes = mysqli_num_rows($conn->query("SELECT * FROM pembelian_sosmed WHERE status = 'Success'"));
$total_ppob_succes = mysqli_num_rows($conn->query("SELECT * FROM pembelian_ppob WHERE status = 'Success'"));
$total_pemesanan_sosmed_success = $conn->query("SELECT SUM(harga) AS total FROM pembelian_sosmed WHERE status = 'Success'");
$data_pesanan_sosmed_success = $total_pemesanan_sosmed_success->fetch_assoc();
$total_pemesanan_ppob_success = $conn->query("SELECT SUM(harga) AS total FROM pembelian_ppob WHERE status = 'Success'");
$data_pesanan_ppob_success = $total_pemesanan_ppob_success->fetch_assoc();

$total_sosmed_error = mysqli_num_rows($conn->query("SELECT * FROM pembelian_sosmed WHERE status = 'Error'"));
$total_ppob_error = mysqli_num_rows($conn->query("SELECT * FROM pembelian_ppob WHERE status = 'Error'"));
$total_pemesanan_sosmed_error = $conn->query("SELECT SUM(harga) AS total FROM pembelian_sosmed WHERE status = 'Error'");
$data_pesanan_sosmed_error = $total_pemesanan_sosmed_error->fetch_assoc();
$total_pemesanan_ppob_error = $conn->query("SELECT SUM(harga) AS total FROM pembelian_ppob WHERE status = 'Error'");
$data_pesanan_ppob_error = $total_pemesanan_ppob_error->fetch_assoc();

$total_sosmed_pending = mysqli_num_rows($conn->query("SELECT * FROM pembelian_sosmed WHERE status = 'Pending'"));
$total_ppob_pending = mysqli_num_rows($conn->query("SELECT * FROM pembelian_ppob WHERE status = 'Pending'"));
$total_pemesanan_sosmed_pending = $conn->query("SELECT SUM(harga) AS total FROM pembelian_sosmed WHERE status = 'Pending'");
$data_pesanan_sosmed_pending = $total_pemesanan_sosmed_pending->fetch_assoc();
$total_pemesanan_ppob_pending = $conn->query("SELECT SUM(harga) AS total FROM pembelian_ppob WHERE status = 'Pending'");
$data_pesanan_ppob_pending = $total_pemesanan_ppob_pending->fetch_assoc();

$total_sosmed_partial = mysqli_num_rows($conn->query("SELECT * FROM pembelian_sosmed WHERE status = 'Partial'"));
$total_pemesanan_sosmed_partial = $conn->query("SELECT SUM(harga) AS total FROM pembelian_sosmed WHERE status = 'Partial'");
$data_pesanan_sosmed_partial = $total_pemesanan_sosmed_partial->fetch_assoc();

$total_sosmed_processing = mysqli_num_rows($conn->query("SELECT * FROM pembelian_sosmed WHERE status = 'Processing'"));
$total_ppob_processing = mysqli_num_rows($conn->query("SELECT * FROM pembelian_ppob WHERE status = 'Processing'"));
$total_pemesanan_sosmed_processing = $conn->query("SELECT SUM(harga) AS total FROM pembelian_sosmed WHERE status = 'Processing'");
$data_pesanan_sosmed_processing = $total_pemesanan_sosmed_processing->fetch_assoc();
$total_pemesanan_ppob_processing = $conn->query("SELECT SUM(harga) AS total FROM pembelian_ppob WHERE status = 'Processing'");
$data_pesanan_ppob_processing = $total_pemesanan_ppob_processing->fetch_assoc();

$total_sosmed_progress = mysqli_num_rows($conn->query("SELECT * FROM pembelian_sosmed WHERE status = 'In Progress'"));
$total_pemesanan_sosmed_progress = $conn->query("SELECT SUM(harga) AS total FROM pembelian_sosmed WHERE status = 'In Progress'");
$data_pesanan_sosmed_progress = $total_pemesanan_sosmed_progress->fetch_assoc();

$aktif =  mysqli_num_rows($conn->query("SELECT * FROM users WHERE status = 'Aktif'"));
$nonaktif =  mysqli_num_rows($conn->query("SELECT * FROM users WHERE status = 'Tidak Aktif'"));
