/** * currency_helpers.php * /app/Helpers/currency_helpers.php * This original/initial version is DEPRECATED */ // Critical Info: /* ************ All previous/existing fees fetching, fees structure, fees application/implementation, fees calculation, as well as all previous/existing fx rates, fx conversion, currency data, currency settings, currency formatting, calculation, etc helpers, methods, functions and classes must now delegate to the NEW currency + fees management suite, which implements records in the following db tables as source of truth for my fintech app/website platform. modular_currency_data, modular_currency_rates, modular_currency_rates_history, modular_currency_settings, modular_fee_internal_names, modular_fee_process_types, modular_fee_structures These NEW currency + fees management suite scripts include: /app/Classes/PaymentModule.php /app/Classes/fxMasterSuite.php /app/Classes/SimpleFileCache.php Fee structures are created and managed by the super_admin with the following script: /app/Legacy/admin/fees-management.php which has been adapted from /app/Legacy/admin/admin_fees_management.php ************ */ /** * ============================================================================ * CURRENCY HELPERS * ============================================================================ */ /** * Get currency symbol from database (with fallback) * * @param string $currencyCode The currency code (e.g., USD, NGN) * @param mysqli|null $db Database connection (optional) * @return string Currency symbol */ function getCurrencySymbol($currencyCode, $db = null) { // Try to use FxCalculator first (most reliable) global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { return $fxCalculator->getCurrencySymbol($currencyCode); } // Try database lookup if ($db) { try { $stmt = $db->prepare("SELECT symbol FROM currency_data WHERE currency_code = ? AND is_active = 1"); $stmt->bind_param('s', $currencyCode); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { return $row['symbol']; } } catch (Exception $e) { error_log("Error getting currency symbol: " . $e->getMessage()); } } // Fallback symbols $symbols = [ 'USD' => '$', 'EUR' => '€', 'GBP' => '£', 'NGN' => '₦', 'GHS' => 'GH₵', 'KES' => 'KSh', 'ZAR' => 'R', 'CNY' => '¥', 'JPY' => '¥', 'CAD' => 'C$', 'AUD' => 'A$', 'CHF' => 'Fr', 'INR' => '₹', 'BRL' => 'R$', 'MXN' => '$', 'SGD' => 'S$' ]; return $symbols[$currencyCode] ?? '$'; } /** * Format amount with currency symbol * * @param float|int|string $amount The amount to format * @param string $currencyCode The currency code * @param int|null $decimals Number of decimal places (optional, uses currency defaults) * @param mysqli|null $db Database connection (optional) * @return string Formatted amount with currency symbol */ function formatCurrency($amount, $currencyCode, $decimals = null, $db = null) { // Try to use FxCalculator global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { return $fxCalculator->formatAmount($amount, $currencyCode, $decimals); } // Get decimals from database if not provided if ($decimals === null && $db) { try { $stmt = $db->prepare("SELECT decimals FROM currency_data WHERE currency_code = ? AND is_active = 1"); $stmt->bind_param('s', $currencyCode); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { $decimals = (int)$row['decimals']; } } catch (Exception $e) { error_log("Error getting decimals: " . $e->getMessage()); } } $decimals = $decimals ?? 2; $symbol = getCurrencySymbol($currencyCode, $db); $formatted = number_format((float)$amount, $decimals); return $symbol . $formatted; } /** * Convert amount between currencies using MasterFxCalculator * * @param float|int|string $amount The amount to convert * @param string $fromCurrency Source currency code * @param string $toCurrency Target currency code * @param mysqli|null $db Database connection (optional) * @return float Converted amount */ function convertCurrency($amount, $fromCurrency, $toCurrency, $db = null) { // If same currency, no conversion needed if ($fromCurrency === $toCurrency) { return (float)$amount; } // Try to use FxCalculator (most reliable) global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { $rate = $fxCalculator->getRate($fromCurrency, $toCurrency); return (float)$amount * $rate; } // Fallback: query database directly if ($db) { $baseCurrency = getBaseCurrency($db); try { $stmt = $db->prepare("SELECT external_rates FROM currency_rates WHERE base_currency = ? ORDER BY last_updated DESC LIMIT 1"); $stmt->bind_param('s', $baseCurrency); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); if ($row) { $rates = json_decode($row['external_rates'], true); if (isset($rates[$fromCurrency]) && isset($rates[$toCurrency])) { $inBase = (float)$amount / $rates[$fromCurrency]; return $inBase * $rates[$toCurrency]; } } } catch (Exception $e) { error_log("Error converting currency: " . $e->getMessage()); } } // Ultimate fallback - return original amount error_log("Currency conversion failed, using original amount: $fromCurrency -> $toCurrency"); return (float)$amount; } /** * Get base currency from database * * @param mysqli|null $db Database connection (optional) * @return string Base currency code */ /** * Get base currency from database - SOURCE OF TRUTH: currency_settings table */ function getBaseCurrency($db = null) { static $baseCurrency = null; if ($baseCurrency !== null) { return $baseCurrency; } // Try to use MasterFxCalculator first (it now uses currency_settings) global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { $baseCurrency = $fxCalculator->getBaseCurrency(); return $baseCurrency; } // Direct database query if calculator not available if ($db) { try { // PRIMARY SOURCE: currency_settings $result = $db->query("SELECT base_currency FROM currency_settings WHERE id = 1"); if ($result && $row = $result->fetch_assoc()) { $baseCurrency = $row['base_currency']; return $baseCurrency; } // FALLBACK: folrun_currency_settings $result = $db->query("SELECT base_currency FROM folrun_currency_settings WHERE id = 1"); if ($result && $row = $result->fetch_assoc()) { $baseCurrency = $row['base_currency']; return $baseCurrency; } } catch (Exception $e) { error_log("Error getting base currency: " . $e->getMessage()); } } $baseCurrency = defined('DEFAULT_BASE_CURRENCY') ? DEFAULT_BASE_CURRENCY : 'USD'; return $baseCurrency; } /** * Get fee by key from database */ function getFeeByKey_XXX($feeKey, $db = null) { if ($db === null) { global $db; } try { $stmt = $db->prepare("SELECT fee_value, fee_type FROM folrun_fee_settings WHERE fee_key = ? AND is_active = 1 LIMIT 1"); if ($stmt) { $stmt->bind_param('s', $feeKey); $stmt->execute(); $result = $stmt->get_result(); return $result->fetch_assoc(); } } catch (Exception $e) { error_log("Error getting fee by key: " . $e->getMessage()); } return null; } /** * Get fee by transaction type, wallet type, and user role */ function getFeeByTransactionAndWallet($transactionType, $walletType, $userRole, $db = null) { if ($db === null) { global $db; } try { $sql = "SELECT * FROM folrun_fee_settings WHERE is_active = 1 AND (transaction_type = ? OR transaction_type = 'all') AND (wallet_type = ? OR wallet_type = 'all') AND (user_role = ? OR user_role = 'all') ORDER BY CASE WHEN transaction_type = ? THEN 1 ELSE 2 END, CASE WHEN wallet_type = ? THEN 1 ELSE 2 END, CASE WHEN user_role = ? THEN 1 ELSE 2 END LIMIT 1"; $stmt = $db->prepare($sql); $stmt->bind_param('ssssss', $transactionType, $walletType, $userRole, $transactionType, $walletType, $userRole); $stmt->execute(); $result = $stmt->get_result(); return $result->fetch_assoc(); } catch (Exception $e) { error_log("Error getting fee by transaction and wallet: " . $e->getMessage()); return null; } } /** * Get admin currency from database * * @param mysqli|null $db Database connection (optional) * @return string Admin currency code */ function getAdminCurrency($db = null) { static $adminCurrency = null; if ($adminCurrency !== null) { return $adminCurrency; } global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { $adminCurrency = $fxCalculator->getAdminCurrency(); return $adminCurrency; } if ($db) { try { $result = $db->query("SELECT default_admin_currency FROM currency_settings WHERE id = 1"); if ($result && $row = $result->fetch_assoc()) { $adminCurrency = $row['default_admin_currency']; return $adminCurrency; } $result = $db->query("SELECT default_admin_currency FROM folrun_currency_settings WHERE id = 1"); if ($result && $row = $result->fetch_assoc()) { $adminCurrency = $row['default_admin_currency']; return $adminCurrency; } } catch (Exception $e) { error_log("Error getting admin currency: " . $e->getMessage()); } } $adminCurrency = defined('DEFAULT_ADMIN_CURRENCY') ? DEFAULT_ADMIN_CURRENCY : 'GHS'; return $adminCurrency; } /** * Get all active currencies with rates * * @param mysqli $db Database connection * @return array Array of currencies with their data and rates */ function getAllCurrenciesWithRates($db) { $baseCurrency = getBaseCurrency($db); $currencies = []; try { // Get currency data $result = $db->query("SELECT currency_code, symbol, name, decimals, fallback_rate FROM currency_data WHERE is_active = 1 ORDER BY currency_code"); if ($result) { while ($row = $result->fetch_assoc()) { $currencies[$row['currency_code']] = [ 'name' => $row['name'], 'symbol' => $row['symbol'], 'decimals' => (int)$row['decimals'], 'fallback_rate' => (float)$row['fallback_rate'] ]; } } // Get current rates $stmt = $db->prepare("SELECT external_rates, internal_rates_from, internal_rates_to FROM currency_rates WHERE base_currency = ? ORDER BY last_updated DESC LIMIT 1"); $stmt->bind_param('s', $baseCurrency); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); $externalRates = $row ? json_decode($row['external_rates'], true) : []; $internalFrom = $row ? json_decode($row['internal_rates_from'], true) : []; $internalTo = $row ? json_decode($row['internal_rates_to'], true) : []; foreach ($currencies as $code => &$data) { $data['rate'] = $externalRates[$code] ?? $data['fallback_rate']; $data['rate_from'] = $internalFrom[$code] ?? $data['rate']; $data['rate_to'] = $internalTo[$code] ?? $data['rate']; $data['base_currency'] = $baseCurrency; } } catch (Exception $e) { error_log("Error getting currencies with rates: " . $e->getMessage()); } return $currencies; } /** * Get active currencies list (without rates) * * @param mysqli $db Database connection * @return array Array of active currencies */ function getActiveCurrencies($db): array { $currencies = []; try { $result = $db->query("SELECT currency_code, symbol, name, decimals FROM currency_data WHERE is_active = 1 ORDER BY currency_code"); if ($result) { while ($row = $result->fetch_assoc()) { $currencies[$row['currency_code']] = [ 'symbol' => $row['symbol'], 'name' => $row['name'], 'decimals' => (int)$row['decimals'] ]; } } } catch (Exception $e) { error_log("Error getting active currencies: " . $e->getMessage()); } return $currencies; } /** * ============================================================================ * FEE HELPERS * ============================================================================ */ /** * Get fee structure for a specific transaction * * @param mysqli $db Database connection * @param string $transaction_type Transaction type (deposit, withdrawal, etc.) * @param string $wallet_type Wallet type (funding, earnings, etc.) * @param float|int $amount Transaction amount * @param MasterFxCalculator|null $fxCalculator Optional FX calculator instance * @return array Fee breakdown */ function getTransactionFees($db, $transaction_type, $wallet_type, $amount, $fxCalculator = null) { $fees = [ 'fx_spread' => 0, 'main_fee' => 0, 'total' => 0 ]; try { // Get FX spread - try to use FxCalculator first if ($fxCalculator && $fxCalculator instanceof MasterFxCalculator) { $fees['fx_spread'] = $fxCalculator->getFee('fx_spread_nominal_perc', 0.05); } else { $sql = "SELECT fee_value FROM fee_settings WHERE fee_key = 'fx_spread' AND is_active = 1 LIMIT 1"; $result = $db->query($sql); if ($result && $row = $result->fetch_assoc()) { $fees['fx_spread'] = (float)$row['fee_value'] / 100; } else { $fees['fx_spread'] = 0.05; } } // Get transaction-specific fee $sql = "SELECT * FROM fee_settings WHERE (transaction_type = ? OR transaction_type = 'all') AND (wallet_type = ? OR wallet_type = 'all') AND is_active = 1 ORDER BY CASE WHEN transaction_type = ? THEN 1 WHEN transaction_type = 'all' THEN 3 ELSE 2 END, CASE WHEN wallet_type = ? THEN 1 WHEN wallet_type = 'all' THEN 3 ELSE 2 END LIMIT 1"; $stmt = $db->prepare($sql); $stmt->bind_param('ssss', $transaction_type, $wallet_type, $transaction_type, $wallet_type); $stmt->execute(); $feeSetting = $stmt->get_result()->fetch_assoc(); if ($feeSetting) { if ($feeSetting['fee_type'] === 'flexible') { if ($amount < $feeSetting['threshold_amount']) { $fees['main_fee'] = (float)$feeSetting['fixed_fee_value']; } else { $fees['main_fee'] = $amount * ((float)$feeSetting['percentage_fee_value'] / 100); } } elseif ($feeSetting['fee_type'] === 'percentage') { $fees['main_fee'] = $amount * ((float)$feeSetting['fee_value'] / 100); } elseif ($feeSetting['fee_type'] === 'fixed') { $fees['main_fee'] = (float)$feeSetting['fee_value']; } } else { $fees['main_fee'] = $amount * 0.10; // Default 10% } $fees['total'] = ($amount * $fees['fx_spread']) + $fees['main_fee']; } catch (Exception $e) { error_log("Error getting fees: " . $e->getMessage()); $fees['fx_spread'] = 0.05; $fees['main_fee'] = $amount * 0.10; $fees['total'] = ($amount * 0.05) + ($amount * 0.10); } return $fees; } /** * Get a specific fee by key * * @param mysqli $db Database connection * @param string $feeKey The fee key to retrieve * @param mixed $default Default value if fee not found * @return mixed Fee value or array for flexible fees */ /* function getFeeByKey($db, $feeKey, $default = 0) { try { $sql = "SELECT fee_value, fee_type, threshold_amount, fixed_fee_value, percentage_fee_value FROM fee_settings WHERE fee_key = ? AND is_active = 1 LIMIT 1"; $stmt = $db->prepare($sql); $stmt->bind_param('s', $feeKey); $stmt->execute(); $result = $stmt->get_result(); $fee = $result->fetch_assoc(); if ($fee) { if ($fee['fee_type'] === 'percentage') { return (float)$fee['fee_value'] / 100; } elseif ($fee['fee_type'] === 'fixed') { return (float)$fee['fee_value']; } elseif ($fee['fee_type'] === 'flexible') { return [ 'type' => 'flexible', 'threshold' => (float)$fee['threshold_amount'], 'fixed_fee' => (float)$fee['fixed_fee_value'], 'percentage_fee' => (float)$fee['percentage_fee_value'] ]; } } } catch (Exception $e) { error_log("Error getting fee by key: " . $e->getMessage()); } return $default; } */ /** * Get all active fees * * @param mysqli $db Database connection * @return array Array of all active fees */ function getAllFees($db): array { $fees = []; try { $result = $db->query("SELECT * FROM fee_settings WHERE is_active = 1 ORDER BY sort_order"); if ($result) { while ($row = $result->fetch_assoc()) { $fees[] = $row; } } } catch (Exception $e) { error_log("Error getting all fees: " . $e->getMessage()); } return $fees; } /** * ============================================================================ * USER CURRENCY HELPERS * ============================================================================ */ /** * Get user's effective currency * * @param int $user_id User ID * @param mysqli|null $db Database connection (optional) * @return string User's currency code */ function getUserCurrency($user_id, $db = null) { static $cache = []; if (isset($cache[$user_id])) { return $cache[$user_id]; } // Try to use UserManager if available global $userManager; if (isset($userManager) && $userManager instanceof UserManager) { $user = $userManager->getUser($user_id); if ($user && isset($user['currency_code'])) { $cache[$user_id] = $user['currency_code']; return $cache[$user_id]; } } // Query database directly if ($db) { try { $stmt = $db->prepare("SELECT currency_code FROM users WHERE id = ?"); $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { $cache[$user_id] = $row['currency_code']; return $cache[$user_id]; } } catch (Exception $e) { error_log("Error getting user currency: " . $e->getMessage()); } } // Default fallback return defined('DEFAULT_USER_CURRENCY') ? DEFAULT_USER_CURRENCY : 'NGN'; } /** * Update user's currency * * @param int $user_id User ID * @param string $newCurrency New currency code * @param mysqli $db Database connection * @return bool True on success, false on failure */ function updateUserCurrency($user_id, $newCurrency, $db) { try { $stmt = $db->prepare("UPDATE users SET currency_code = ? WHERE id = ?"); $stmt->bind_param('si', $newCurrency, $user_id); return $stmt->execute(); } catch (Exception $e) { error_log("Error updating user currency: " . $e->getMessage()); return false; } } /** * ============================================================================ * UTILITY FUNCTIONS * ============================================================================ */ /** * Calculate exchange rate impact (for display) * * @param string $fromCurrency Source currency * @param string $toCurrency Target currency * @param float|int $amount Amount to convert * @param mysqli|null $db Database connection (optional) * @return array Exchange rate impact details */ function getExchangeRateImpact($fromCurrency, $toCurrency, $amount, $db = null) { $rate = convertCurrency(1, $fromCurrency, $toCurrency, $db); $result = $amount * $rate; return [ 'rate' => $rate, 'original' => $amount, 'converted' => $result, 'formatted_original' => formatCurrency($amount, $fromCurrency, null, $db), 'formatted_converted' => formatCurrency($result, $toCurrency, null, $db) ]; } /** * Format amount in multiple currencies * * @param float|int $amount Amount to format * @param array $currencies Array of currency codes * @param mysqli|null $db Database connection (optional) * @return array Formatted amounts by currency */ function formatMultiCurrency($amount, $currencies, $db = null) { $result = []; foreach ($currencies as $currency) { $result[$currency] = formatCurrency($amount, $currency, null, $db); } return $result; } /** * Validate currency code * * @param string $currencyCode Currency code to validate * @param mysqli|null $db Database connection (optional) * @return bool True if currency is valid and active */ function isValidCurrency($currencyCode, $db = null) { if ($db) { try { $stmt = $db->prepare("SELECT id FROM currency_data WHERE currency_code = ? AND is_active = 1"); $stmt->bind_param('s', $currencyCode); $stmt->execute(); return $stmt->get_result()->num_rows > 0; } catch (Exception $e) { error_log("Error validating currency: " . $e->getMessage()); } } $validCurrencies = ['USD', 'EUR', 'GBP', 'NGN', 'GHS', 'KES', 'ZAR', 'CNY']; return in_array(strtoupper($currencyCode), $validCurrencies); } /** * Get currency data for display * * @param string $currencyCode Currency code * @param mysqli|null $db Database connection (optional) * @return array Currency display data */ function getCurrencyDisplayData($currencyCode, $db = null) { global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { $data = $fxCalculator->getCurrencyDataFromDb($currencyCode); return [ 'code' => $currencyCode, 'symbol' => $data['symbol'] ?? '$', 'name' => $data['name'] ?? $currencyCode, 'decimals' => $data['decimals'] ?? 2 ]; } if ($db) { try { $stmt = $db->prepare("SELECT symbol, name, decimals FROM currency_data WHERE currency_code = ? AND is_active = 1"); $stmt->bind_param('s', $currencyCode); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { return [ 'code' => $currencyCode, 'symbol' => $row['symbol'], 'name' => $row['name'], 'decimals' => (int)$row['decimals'] ]; } } catch (Exception $e) { error_log("Error getting currency display data: " . $e->getMessage()); } } return [ 'code' => $currencyCode, 'symbol' => getCurrencySymbol($currencyCode), 'name' => $currencyCode, 'decimals' => 2 ]; } /** * Get minimum deposit amount for a user based on their role * Returns amount in the system base currency (from database) * * @param int $user_id User ID * @param mysqli|null $db Database connection * @return float Minimum deposit amount in system base currency (0 = no limit) */ function getMinimumDepositForUser($user_id, $db = null) { if ($db === null) { global $db; } if (!$db) { return 2.00; } // Get user's role $sql = "SELECT role FROM users WHERE id = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 2.00; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); if (!$user) { return 2.00; } $role = $user['role']; // Get limits for this role (amounts are in system base currency) $sql = "SELECT min_deposit_base FROM transaction_limits WHERE role = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 2.00; } $stmt->bind_param('s', $role); $stmt->execute(); $result = $stmt->get_result(); $limit = $result->fetch_assoc(); // Return 0 if no limit found (meaning no minimum) return $limit ? (float)$limit['min_deposit_base'] : 0; } /** * Get maximum deposit amount for a user based on their role * * @param int $user_id User ID * @param mysqli|null $db Database connection * @return float Maximum deposit amount (0 = no limit) */ function getMaximumDepositForUser($user_id, $db = null) { if ($db === null) { global $db; } if (!$db) { return 0; } $sql = "SELECT role FROM users WHERE id = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); if (!$user) { return 0; } $role = $user['role']; $sql = "SELECT max_deposit_base FROM transaction_limits WHERE role = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('s', $role); $stmt->execute(); $result = $stmt->get_result(); $limit = $result->fetch_assoc(); return $limit ? (float)$limit['max_deposit_base'] : 0; } /** * Get minimum withdrawal amount for a user based on their role * * @param int $user_id User ID * @param string|null $currency Currency to return the amount in * @param mysqli|null $db Database connection * @return float Minimum withdrawal amount */ function getMinimumWithdrawalForUser($user_id, $currency = null, $db = null) { if ($db === null) { global $db; } if (!$db) { return 2.00; } $sql = "SELECT role FROM users WHERE id = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 2.00; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); if (!$user) { return 2.00; } $role = $user['role']; $sql = "SELECT min_withdrawal_base FROM transaction_limits WHERE (role = ? OR role IS NULL) ORDER BY CASE WHEN role = ? THEN 0 ELSE 1 END LIMIT 1"; $stmt = $db->prepare($sql); if (!$stmt) { return 2.00; } $stmt->bind_param('ss', $role, $role); $stmt->execute(); $result = $stmt->get_result(); $limit = $result->fetch_assoc(); $minWithdrawalBase = $limit ? (float)$limit['min_withdrawal_base'] : 2.00; if ($currency !== null) { global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { return $fxCalculator->convert($minWithdrawalBase, 'USD', $currency); } } return $minWithdrawalBase; } /** * Get daily deposit limit for a user based on their role * * @param int $user_id User ID * @param mysqli|null $db Database connection * @return float Daily deposit limit (0 = no limit) */ function getDailyDepositLimitForUser($user_id, $db = null) { if ($db === null) { global $db; } if (!$db) { return 0; } $sql = "SELECT role FROM users WHERE id = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); if (!$user) { return 0; } $role = $user['role']; $sql = "SELECT daily_deposit_limit_base FROM transaction_limits WHERE role = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('s', $role); $stmt->execute(); $result = $stmt->get_result(); $limit = $result->fetch_assoc(); return $limit ? (float)$limit['daily_deposit_limit_base'] : 0; } /** * Get daily withdrawal limit for a user based on their role * CORRECTED: Uses 'daily_withdrawal_limit_base' column * * @param int $user_id User ID * @param string|null $currency Currency to return the amount in * @param mysqli|null $db Database connection * @return float Daily withdrawal limit (0 = no limit) */ function getDailyWithdrawalLimitForUser($user_id, $currency = null, $db = null) { if ($db === null) { global $db; } if (!$db) { return 0; } $sql = "SELECT role FROM users WHERE id = ?"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); if (!$user) { return 0; } $role = $user['role']; // CORRECTED: Use 'daily_withdrawal_limit_base' column $sql = "SELECT daily_withdrawal_limit_base FROM transaction_limits WHERE (role = ? OR role IS NULL) ORDER BY CASE WHEN role = ? THEN 0 ELSE 1 END LIMIT 1"; $stmt = $db->prepare($sql); if (!$stmt) { return 0; } $stmt->bind_param('ss', $role, $role); $stmt->execute(); $result = $stmt->get_result(); $limit = $result->fetch_assoc(); $dailyLimitBase = $limit ? (float)$limit['daily_withdrawal_limit_base'] : 0; if ($currency !== null && $dailyLimitBase > 0) { global $fxCalculator; if (isset($fxCalculator) && $fxCalculator instanceof MasterFxCalculator) { return $fxCalculator->convert($dailyLimitBase, 'USD', $currency); } } return $dailyLimitBase; } /** * Get formatted minimum deposit string for display * * @param int $user_id User ID * @param string $userCurrency User's currency code * @param mysqli|null $db Database connection * @return string Formatted minimum deposit string */ function getFormattedMinimumDeposit($user_id, $userCurrency, $db = null) { if ($db === null) { global $db; } global $fxCalculator; $minInBase = getMinimumDepositForUser($user_id, null, $db); $minInUserCurrency = $fxCalculator->convert($minInBase, 'USD', $userCurrency); return $fxCalculator->formatAmount($minInUserCurrency, $userCurrency); } /** * Get remaining daily deposit allowance in system base currency * * @param int $user_id User ID * @param mysqli|null $db Database connection * @return float Remaining daily deposit amount in system base currency */ function getRemainingDailyDepositAllowance($user_id, $db = null) { if ($db === null) { global $db; } if (!$db) { return 0; } $dailyLimit = getDailyDepositLimitForUser($user_id, $db); // If no daily limit, return a large number if ($dailyLimit <= 0) { return 99999999.00; } // Get today's total deposits (in system base currency) $sql = "SELECT COALESCE(SUM(gross_amount_base_curr), 0) as today_deposits FROM all_transactions WHERE user_id = ? AND transaction_type = 'credit' AND DATE(date_created) = CURDATE() AND status IN ('pending', 'processing', 'successful')"; $stmt = $db->prepare($sql); if (!$stmt) { return $dailyLimit; } $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); $todayDeposits = (float)($row['today_deposits'] ?? 0); return max(0, $dailyLimit - $todayDeposits); }
Warning: http_response_code(): Cannot set response code - headers already sent (output started at /home/globalw1/public_html/gigz/app/Helpers/currency_helpers_DEPRECATED.php:1) in /home/globalw1/public_html/gigz/app/Core/Router.php on line 328

404 - Page Not Found

Debug Information:

Message: No route matched for: /sitemap.xml
Request Method: GET
Request URI: /sitemap.xml
Script Name: /gigz/public/index.php
Base Path: /gigz/public

Loaded Routes:
  GET: /test-route
  GET: /
  GET: /home
  GET: /login
  GET: /register
  GET: /logout
  GET: /forgot-password
  GET: /reset-password
  GET: /verify
  GET: /faq
  GET: /contact
  GET: /about
  GET: /terms
  GET: /privacy
  GET: /dashboard/wallets
  GET: /dashboard
  GET: /dashboard/profile
  GET: /dashboard/transactions
  GET: /dashboard/deposit
  GET: /dashboard/withdraw
  GET: /dashboard/referrals
  GET: /dashboard/analytics
  GET: /dashboard/security
  GET: /dashboard/settings
  GET: /dashboard/kyc
  GET: /dashboard/bank-accounts
  GET: /dashboard/notifications
  GET: /dashboard/support
  GET: /dashboard/rewards
  GET: /dashboard/api-keys
  GET: /dashboard/available-content
  GET: /dashboard/content
  GET: /dashboard/earnings
  GET: /dashboard/transfer
  GET: /dashboard/currency-change
  GET: /dashboard/deposit-complete
  GET: /dashboard/pending-deposits
  GET: /dashboard/publisher
  GET: /dashboard/sharer
  GET: /dashboard/buyer
  GET: /dashboard/seller
  GET: /dashboard/generic
  GET: /dashboard/ajax/get_notifications
  GET: /dashboard/ajax/get_transaction
  GET: /dashboard/ajax/get_payment_proof
  GET: /admin/login
  GET: /admin/logout
  GET: /admin/profile
  GET: /admin
  GET: /admin/dashboard
  GET: /admin/users
  GET: /admin/user-detail
  GET: /admin/user-edit
  GET: /admin/user-wallets
  GET: /admin/transactions
  GET: /admin/transactions-detail
  GET: /admin/deposits
  GET: /admin/deposit-confirm
  GET: /admin/withdrawals
  GET: /admin/withdrawal-approve
  GET: /admin/kyc
  GET: /admin/kyc-review
  GET: /admin/referrals
  GET: /admin/reports
  GET: /admin/settings
  GET: /admin/fees-management
  GET: /admin/audit-log
  GET: /admin/system-health
  GET: /admin/system-alerts
  GET: /admin/partners
  GET: /admin/partner-payouts
  GET: /admin/admins
  GET: /admin/create-admin
  GET: /admin/edit-admin
  GET: /admin/edit-partner
  GET: /admin/content
  GET: /admin/content-edit
  GET: /admin/content-preview
  GET: /admin/fx-profits
  GET: /admin/debug
  GET: /admin/export/transactions
  GET: /admin/export/fx-profits
  GET: /admin/export/users
  GET: /admin/export/referrals
  GET: /admin/export/content
  GET: /admin/export/deposits
  GET: /admin/export/withdrawals
  GET: /admin/export/audit-log
  GET: /admin/export/partner-payouts
  GET: /admin/ajax/get_transaction_admin
  GET: /admin/ajax/get_audit_detail
  GET: /admin/ajax/get_kyc_document
  GET: /admin/ajax/get_content
  GET: /admin/ajax/get_user
  GET: /admin/ajax/get_stats
  GET: /admin/ajax/check_currency_integrity
  GET: /admin/cron/backup
  GET: /admin/cron/cleanup
  GET: /admin/cron/expire
  GET: /admin/cron/notify
  GET: /admin/cron/process_queue
  GET: /admin/cron/process_referrals
  GET: /admin/cron/queue
  GET: /admin/cron/reports
  GET: /admin/cron/update_rates
  GET: /dashboard/products
  GET: /dashboard/upgrade
  GET: /dashboard/store
  GET: /dashboard/orders
  GET: /dashboard/wishlist
  GET: /dashboard/add-product
  GET: /dashboard/orders-seller
  GET: /dashboard/sales
  GET: /dashboard/my-shares
  GET: /dashboard/deposit-confirm
  GET: /admin/currency-management
  GET: /dashboard/deposit-bank-transfer
  GET: /dashboard/ajax/get_bank_details
  GET: /admin/payment-methods
  GET: /admin/bank-details
  GET: /admin/payment-proofs
  GET: /admin/admin_currency_management
  GET: /admin/admin_fees_management
  GET: /admin/ajax/get_payment_proof
  GET: /admin/dynamic-user-wallets
  GET: /ajax/get_dynamic_variables
  GET: /admin/ajax/get_dynamic_variables
  GET: /dashboard/ajax/get_dynamic_variables
  GET: /dashboard/ajax/calculate_withdrawal
  GET: /debug-fees
  GET: /receipt
  GET: /admin/test-currency
  POST: /login
  POST: /register
  POST: /forgot-password
  POST: /reset-password
  POST: /contact
  POST: /dashboard/profile
  POST: /dashboard/currency-change
  POST: /dashboard/kyc
  POST: /dashboard/bank-accounts
  POST: /dashboard/ajax/add_bank_account
  POST: /dashboard/ajax/set_primary_bank
  POST: /dashboard/ajax/delete_bank_account
  POST: /dashboard/ajax/calculate_deposit
  POST: /dashboard/ajax/calculate_withdrawal
  POST: /dashboard/ajax/confirm_payment
  POST: /dashboard/ajax/process_withdrawal
  POST: /dashboard/ajax/upload_kyc
  POST: /dashboard/ajax/currency_change
  POST: /dashboard/ajax/delete_account
  POST: /dashboard/ajax/generate_2fa_secret
  POST: /dashboard/ajax/regenerate_backup_codes
  POST: /dashboard/ajax/get_transaction.php
  POST: /dashboard/ajax/get_transaction
  POST: /dashboard/ajax/get_payment_proof
  POST: /admin/login
  POST: /admin/profile
  POST: /admin/dashboard
  POST: /admin/users
  POST: /admin/user-edit
  POST: /admin/user-wallets
  POST: /admin/transactions
  POST: /admin/deposits
  POST: /admin/deposit-confirm
  POST: /admin/withdrawals
  POST: /admin/withdrawal-approve
  POST: /admin/kyc
  POST: /admin/kyc-review
  POST: /admin/referrals
  POST: /admin/reports
  POST: /admin/settings
  POST: /admin/fees-management
  POST: /admin/audit-log
  POST: /admin/system-health
  POST: /admin/system-alerts
  POST: /admin/partners
  POST: /admin/partner-payouts
  POST: /admin/admins
  POST: /admin/create-admin
  POST: /admin/edit-admin
  POST: /admin/edit-partner
  POST: /admin/content
  POST: /admin/content-edit
  POST: /admin/fx-profits
  POST: /admin/debug
  POST: /admin/ajax/adjust_wallet
  POST: /admin/ajax/approve_withdrawal
  POST: /admin/ajax/confirm_deposit
  POST: /admin/ajax/verify_kyc
  POST: /admin/ajax/delete_user
  POST: /admin/ajax/delete_admin
  POST: /admin/ajax/toggle_user_status
  POST: /admin/ajax/reset_user_password
  POST: /admin/ajax/clear_cache
  POST: /admin/ajax/run_cron
  POST: /admin/ajax/process_partner_payout
  POST: /admin/ajax/calculate_partner_payout
  POST: /admin/ajax/reverse_transaction
  POST: /admin/ajax/sync_currency_data
  POST: /admin/currency-management
  POST: /dashboard/deposit-confirm
  POST: /dashboard/deposit-bank-transfer
  POST: /dashboard/deposit-complete
  POST: /admin/payment-methods
  POST: /admin/bank-details
  POST: /admin/payment-proofs
  POST: /admin/admin_currency_management
  POST: /admin/admin_fees_management
  POST: /admin/ajax/confirm_payment_proof
  POST: /admin/ajax/reject_payment_proof
  POST: /admin/ajax/reject_deposit
  POST: /admin/ajax/adjust_wallet_dynamic
  POST: /admin/dynamic-user-wallets
  POST: /ajax/get_dynamic_variables
  POST: /admin/ajax/get_dynamic_variables
  POST: /dashboard/ajax/get_dynamic_variables
  POST: /ajax/save-browser-timezone