devise / index.html
nadiraouf's picture
I want the application to consist of two interfaces: an admin interface and a client interface. - Follow Up Deployment
bcb5f4a verified
Raw History Blame Contribute Delete
46.9 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Currency Exchange Platform</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
body { font-family: 'Inter', sans-serif; }
.gradient-bg { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.glass-effect {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.hover-scale { transition: transform 0.3s ease; }
.hover-scale:hover { transform: translateY(-2px); }
.pulse-animation {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.7; }
100% { opacity: 1; }
}
.slide-in {
animation: slideIn 0.5s ease-out;
}
@keyframes slideIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: #888;
border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: #555;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<!-- Navigation -->
<nav class="gradient-bg text-white shadow-lg">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between items-center h-16">
<div class="flex items-center">
<i class="fas fa-exchange-alt text-2xl mr-2"></i>
<span class="text-xl font-bold">DZD Exchange</span>
</div>
<div id="navButtons" class="flex space-x-4">
<button onclick="showLogin()" class="glass-effect px-4 py-2 rounded-lg hover:bg-white/20 transition">
<i class="fas fa-sign-in-alt mr-2"></i>Client Login
</button>
<button onclick="showAdminLogin()" class="bg-white text-purple-600 px-4 py-2 rounded-lg font-semibold hover:bg-gray-100 transition">
<i class="fas fa-user-cog mr-2"></i>Admin Login
</button>
</div>
</div>
</div>
</nav>
<!-- Auth Pages Container -->
<div id="authContainer" class="min-h-screen flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
<div class="max-w-md w-full space-y-8">
<!-- Login Form -->
<div id="loginForm" class="bg-white shadow-2xl rounded-xl p-8 slide-in">
<div class="text-center">
<i class="fas fa-exchange-alt text-4xl text-purple-600 mb-4"></i>
<h2 class="text-3xl font-bold text-gray-900">Client Login</h2>
<p class="mt-2 text-gray-600">Sign in to your account</p>
</div>
<form class="mt-8 space-y-6" onsubmit="handleLogin(event)">
<div>
<label class="block text-sm font-medium text-gray-700">Phone Number</label>
<input type="tel" id="loginPhone" required
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-purple-500">
</div>
<button type="submit" class="w-full bg-gradient-to-r from-purple-600 to-indigo-600 text-white py-3 px-4 rounded-lg font-semibold hover:from-purple-700 hover:to-indigo-700 transition">
<i class="fas fa-sign-in-alt mr-2"></i>Sign In
</button>
<p class="text-center text-sm text-gray-600">
Don't have an account?
<button type="button" onclick="showRegister()" class="text-purple-600 hover:text-purple-500 font-semibold">Register here</button>
</p>
</form>
</div>
<!-- Register Form -->
<div id="registerForm" class="bg-white shadow-2xl rounded-xl p-8 slide-in" style="display: none;">
<div class="text-center">
<i class="fas fa-user-plus text-4xl text-purple-600 mb-4"></i>
<h2 class="text-3xl font-bold text-gray-900">Create Account</h2>
<p class="mt-2 text-gray-600">Join our exchange platform</p>
</div>
<form class="mt-8 space-y-6" onsubmit="handleRegister(event)">
<div>
<label class="block text-sm font-medium text-gray-700">Full Name</label>
<input type="text" id="regName" required
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-purple-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Phone Number</label>
<input type="tel" id="regPhone" required
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-purple-500">
</div>
<button type="submit" class="w-full bg-gradient-to-r from-purple-600 to-indigo-600 text-white py-3 px-4 rounded-lg font-semibold hover:from-purple-700 hover:to-indigo-700 transition">
<i class="fas fa-user-plus mr-2"></i>Create Account
</button>
<p class="text-center text-sm text-gray-600">
Already have an account?
<button type="button" onclick="showLogin()" class="text-purple-600 hover:text-purple-500 font-semibold">Sign in here</button>
</p>
</form>
</div>
</div>
</div>
<!-- Customer Dashboard -->
<div id="customerDashboard" class="hidden min-h-screen bg-gray-50">
<!-- Customer Header -->
<header class="bg-white shadow-sm">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between items-center py-4">
<div>
<h1 class="text-2xl font-bold text-gray-900">Welcome, <span id="customerName">Customer</span></h1>
<p class="text-gray-600">Phone: <span id="customerPhone">+213</span></p>
</div>
<button onclick="logout()" class="bg-red-500 text-white px-4 py-2 rounded-lg hover:bg-red-600 transition">
<i class="fas fa-sign-out-alt mr-2"></i>Logout
</button>
</div>
</div>
</header>
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<!-- Wallet Balance Card -->
<div class="bg-gradient-to-r from-purple-600 to-indigo-600 rounded-xl p-6 text-white mb-6 hover-scale">
<div class="flex items-center justify-between">
<div>
<h3 class="text-lg font-semibold opacity-90">Wallet Balance</h3>
<p class="text-3xl font-bold mt-2" id="walletBalance">0 DZD</p>
<p class="text-sm opacity-75 mt-1">Debt: <span id="debtAmount">0 DZD</span></p>
</div>
<div class="text-4xl">
<i class="fas fa-wallet"></i>
</div>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Current Prices -->
<div class="bg-white rounded-xl shadow-lg p-6">
<h3 class="text-xl font-bold text-gray-900 mb-4">
<i class="fas fa-chart-line text-purple-600 mr-2"></i>Current Prices
</h3>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead>
<tr>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Range (USD)</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Rate (DZD/USD)</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200" id="pricesTable">
<!-- Dynamic content -->
</tbody>
</table>
</div>
</div>
<!-- Request Credit Form -->
<div class="bg-white rounded-xl shadow-lg p-6">
<h3 class="text-xl font-bold text-gray-900 mb-4">
<i class="fas fa-credit-card text-purple-600 mr-2"></i>Request Credit
</h3>
<form class="space-y-4" onsubmit="handleCreditRequest(event)">
<div>
<label class="block text-sm font-medium text-gray-700">Platform</label>
<select id="platform" required onchange="updateDZDAmount()"
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
<option value="">Select Platform</option>
<option value="Binance">Binance</option>
<option value="RedotPay">RedotPay</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">USD Amount</label>
<input type="number" id="usdAmount" required min="1" step="0.01" oninput="updateDZDAmount()"
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
</div>
<div class="bg-gray-50 p-3 rounded-lg">
<p class="text-sm text-gray-600">Equivalent DZD: <span id="dzdAmount" class="font-bold text-purple-600">0</span></p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">ID Number</label>
<input type="text" id="idNumber" required
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Payment Proof</label>
<input type="file" id="paymentProof" accept="image/*" required
class="mt-1 block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-semibold file:bg-purple-50 file:text-purple-700 hover:file:bg-purple-100">
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Comments (Optional)</label>
<textarea id="comments" rows="2"
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500"></textarea>
</div>
<button type="submit" class="w-full bg-gradient-to-r from-purple-600 to-indigo-600 text-white py-2 px-4 rounded-lg font-semibold hover:from-purple-700 hover:to-indigo-700 transition">
Submit Request
</button>
</form>
</div>
</div>
<!-- My Orders -->
<div class="mt-8 bg-white rounded-xl shadow-lg p-6">
<h3 class="text-xl font-bold text-gray-900 mb-4">
<i class="fas fa-list text-purple-600 mr-2"></i>My Orders
</h3>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead>
<tr>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Date</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Platform</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">USD Amount</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">DZD Amount</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Notes</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200" id="ordersTable">
<!-- Dynamic content -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Admin Dashboard -->
<div id="adminDashboard" class="hidden min-h-screen bg-gray-50">
<!-- Admin Header -->
<header class="bg-gray-900 text-white">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between items-center py-4">
<div>
<h1 class="text-2xl font-bold">Admin Panel</h1>
<p class="text-gray-300">Total USD Stock: <span id="totalUSDStock" class="text-green-400 font-bold">$100,000</span></p>
</div>
<div class="flex space-x-2">
<button onclick="showReports()" class="bg-blue-600 px-4 py-2 rounded-lg hover:bg-blue-700 transition">
<i class="fas fa-chart-bar mr-2"></i>Reports
</button>
<button onclick="showPrices()" class="bg-green-600 px-4 py-2 rounded-lg hover:bg-green-700 transition">
<i class="fas fa-dollar-sign mr-2"></i>Prices
</button>
<button onclick="logout()" class="bg-red-600 px-4 py-2 rounded-lg hover:bg-red-700 transition">
<i class="fas fa-sign-out-alt mr-2"></i>Logout
</button>
</div>
</div>
</div>
</header>
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<!-- Stats Cards -->
<div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
<div class="bg-white rounded-xl shadow-lg p-6 text-center hover-scale">
<i class="fas fa-users text-3xl text-blue-600 mb-2"></i>
<h3 class="text-2xl font-bold" id="totalCustomers">0</h3>
<p class="text-gray-600">Total Customers</p>
</div>
<div class="bg-white rounded-xl shadow-lg p-6 text-center hover-scale">
<i class="fas fa-shopping-cart text-3xl text-green-600 mb-2"></i>
<h3 class="text-2xl font-bold" id="totalOrders">0</h3>
<p class="text-gray-600">Total Orders</p>
</div>
<div class="bg-white rounded-xl shadow-lg p-6 text-center hover-scale">
<i class="fas fa-clock text-3xl text-yellow-600 mb-2"></i>
<h3 class="text-2xl font-bold" id="pendingOrders">0</h3>
<p class="text-gray-600">Pending Orders</p>
</div>
<div class="bg-white rounded-xl shadow-lg p-6 text-center hover-scale">
<i class="fas fa-chart-line text-3xl text-purple-600 mb-2"></i>
<h3 class="text-2xl font-bold" id="dailyVolume">0 DZD</h3>
<p class="text-gray-600">Today's Volume</p>
</div>
</div>
<!-- Orders Management -->
<div class="bg-white rounded-xl shadow-lg p-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-bold text-gray-900">
<i class="fas fa-list text-purple-600 mr-2"></i>All Orders
</h3>
<div class="flex space-x-2">
<select id="statusFilter" onchange="filterOrders()"
class="px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
<option value="">All Status</option>
<option value="Pending">Pending</option>
<option value="In Progress">In Progress</option>
<option value="Paid">Paid</option>
<option value="Rejected">Rejected</option>
</select>
<input type="date" id="dateFilter" onchange="filterOrders()"
class="px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
</div>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead>
<tr>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Customer</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Date</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Platform</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">USD</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">DZD</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200" id="adminOrdersTable">
<!-- Dynamic content -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Reports Page -->
<div id="reportsPage" class="hidden min-h-screen bg-gray-50">
<header class="bg-gray-900 text-white">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between items-center py-4">
<h1 class="text-2xl font-bold">Reports</h1>
<button onclick="showAdminDashboard()" class="bg-gray-600 px-4 py-2 rounded-lg hover:bg-gray-700 transition">
<i class="fas fa-arrow-left mr-2"></i>Back to Dashboard
</button>
</div>
</div>
</header>
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<!-- Filters -->
<div class="bg-white rounded-xl shadow-lg p-6 mb-6">
<h3 class="text-xl font-bold text-gray-900 mb-4">Filters</h3>
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<select id="reportPlatform" class="px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
<option value="">All Platforms</option>
<option value="Binance">Binance</option>
<option value="RedotPay">RedotPay</option>
</select>
<select id="reportUser" class="px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
<option value="">All Users</option>
</select>
<input type="date" id="reportStartDate" class="px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
<input type="date" id="reportEndDate" class="px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
</div>
<button onclick="generateReport()" class="mt-4 bg-purple-600 text-white px-4 py-2 rounded-lg hover:bg-purple-700 transition">
Generate Report
</button>
</div>
<!-- Report Content -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="bg-white rounded-xl shadow-lg p-6">
<h3 class="text-xl font-bold text-gray-900 mb-4">Volume Overview</h3>
<canvas id="volumeChart" width="400" height="200"></canvas>
</div>
<div class="bg-white rounded-xl shadow-lg p-6">
<h3 class="text-xl font-bold text-gray-900 mb-4">Top Customers</h3>
<div id="topCustomers" class="space-y-3">
<!-- Dynamic content -->
</div>
</div>
</div>
</div>
</div>
<!-- Prices Management -->
<div id="pricesPage" class="hidden min-h-screen bg-gray-50">
<header class="bg-gray-900 text-white">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between items-center py-4">
<h1 class="text-2xl font-bold">Manage Prices & Quantities</h1>
<button onclick="showAdminDashboard()" class="bg-gray-600 px-4 py-2 rounded-lg hover:bg-gray-700 transition">
<i class="fas fa-arrow-left mr-2"></i>Back to Dashboard
</button>
</div>
</div>
</header>
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Prices Management -->
<div class="bg-white rounded-xl shadow-lg p-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-bold text-gray-900">Price Ranges</h3>
<button onclick="addPriceRange()" class="bg-green-600 text-white px-3 py-1 rounded-lg hover:bg-green-700 transition">
<i class="fas fa-plus mr-1"></i>Add
</button>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead>
<tr>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Min USD</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Max USD</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Rate</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200" id="pricesManagementTable">
<!-- Dynamic content -->
</tbody>
</table>
</div>
</div>
<!-- Quantity Management -->
<div class="bg-white rounded-xl shadow-lg p-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-bold text-gray-900">Quantity Ranges</h3>
<button onclick="addQuantityRange()" class="bg-green-600 text-white px-3 py-1 rounded-lg hover:bg-green-700 transition">
<i class="fas fa-plus mr-1"></i>Add
</button>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead>
<tr>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Min Qty</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Max Qty</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Available</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200" id="quantityManagementTable">
<!-- Dynamic content -->
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- Action Modal -->
<div id="actionModal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50">
<div class="bg-white rounded-xl p-6 max-w-md w-full mx-4">
<h3 class="text-lg font-bold text-gray-900 mb-4">Order Action</h3>
<form onsubmit="handleOrderAction(event)">
<input type="hidden" id="actionOrderId">
<input type="hidden" id="actionType">
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700">Status</label>
<select id="actionStatus" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
<option value="Pending">Pending</option>
<option value="In Progress">In Progress</option>
<option value="Paid">Paid</option>
<option value="Rejected">Rejected</option>
</select>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700">Admin Notes</label>
<textarea id="actionNotes" rows="3"
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500"></textarea>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700">Add Balance (DZD)</label>
<input type="number" id="actionBalance" value="0"
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
</div>
<div class="flex space-x-2">
<button type="submit" class="flex-1 bg-purple-600 text-white py-2 px-4 rounded-lg hover:bg-purple-700 transition">
Apply
</button>
<button type="button" onclick="closeActionModal()" class="flex-1 bg-gray-300 text-gray-700 py-2 px-4 rounded-lg hover:bg-gray-400 transition">
Cancel
</button>
</div>
</form>
</div>
</div>
<script>
// Database simulation
let users = [
{ id: 1, name: 'John Doe', phone: '+213555123456', wallet_balance_dzd: 50000, type: 'customer' },
{ id: 2, name: 'Admin User', phone: '+213555000000', wallet_balance_dzd: 0, type: 'admin' }
];
let orders = [
{ id: 1, user_id: 1, platform: 'Binance', usd_amount: 100, dzd_amount: 15000, id_number: 'BIN123', status: 'Pending', date: '2024-01-15', admin_notes: '' },
{ id: 2, user_id: 1, platform: 'RedotPay', usd_amount: 50, dzd_amount: 7500, id_number: 'RED456', status: 'Paid', date: '2024-01-14', admin_notes: 'Payment confirmed' }
];
let prices = [
{ min_usd: 0, max_usd: 100, price_per_usd_dzd: 150 },
{ min_usd: 101, max_usd: 500, price_per_usd_dzd: 148 },
{ min_usd: 501, max_usd: 1000, price_per_usd_dzd: 145 }
];
let quantityRanges = [
{ min_quantity: 0, max_quantity: 1000, available_quantity: 5000 },
{ min_quantity: 1001, max_quantity: 5000, available_quantity: 15000 }
];
let currentUser = null;
// Navigation functions
function showLogin() {
document.getElementById('loginForm').style.display = 'block';
document.getElementById('registerForm').style.display = 'none';
}
function showRegister() {
document.getElementById('loginForm').style.display = 'none';
document.getElementById('registerForm').style.display = 'block';
}
function showCustomerDashboard() {
document.getElementById('authContainer').style.display = 'none';
document.getElementById('customerDashboard').classList.remove('hidden');
document.getElementById('adminDashboard').classList.add('hidden');
document.getElementById('reportsPage').classList.add('hidden');
document.getElementById('pricesPage').classList.add('hidden');
loadCustomerData();
}
function showAdminDashboard() {
document.getElementById('authContainer').style.display = 'none';
document.getElementById('customerDashboard').classList.add('hidden');
document.getElementById('adminDashboard').classList.remove('hidden');
document.getElementById('reportsPage').classList.add('hidden');
document.getElementById('pricesPage').classList.add('hidden');
loadAdminData();
}
function showReports() {
document.getElementById('adminDashboard').classList.add('hidden');
document.getElementById('reportsPage').classList.remove('hidden');
loadReports();
}
function showPrices() {
document.getElementById('adminDashboard').classList.add('hidden');
document.getElementById('pricesPage').classList.remove('hidden');
loadPricesManagement();
}
function logout() {
currentUser = null;
document.getElementById('authContainer').style.display = 'flex';
document.getElementById('customerDashboard').classList.add('hidden');
document.getElementById('adminDashboard').classList.add('hidden');
document.getElementById('navButtons').style.display = 'flex';
}
// Auth handlers
function handleLogin(e) {
e.preventDefault();
const phone = document.getElementById('loginPhone').value;
const user = users.find(u => u.phone === phone && u.type !== 'admin');
if (user) {
currentUser = user;
showCustomerDashboard();
} else {
alert('User not found');
}
}
function showAdminLogin() {
// Hard-coded admin login
const admin = users.find(u => u.phone === '+213555000000');
if (admin) {
currentUser = admin;
showAdminDashboard();
} else {
alert('Admin account not found');
}
}
function handleRegister(e) {
e.preventDefault();
const name = document.getElementById('regName').value;
const phone = document.getElementById('regPhone').value;
const newUser = {
id: users.length + 1,
name: name,
phone: phone,
wallet_balance_dzd: 0,
type: 'customer'
};
users.push(newUser);
currentUser = newUser;
showCustomerDashboard();
}
// Customer functions
function loadCustomerData() {
if (!currentUser) return;
document.getElementById('customerName').textContent = currentUser.name;
document.getElementById('customerPhone').textContent = currentUser.phone;
document.getElementById('walletBalance').textContent = `${currentUser.wallet_balance_dzd.toLocaleString()} DZD`;
document.getElementById('debtAmount').textContent = currentUser.wallet_balance_dzd < 0 ?
`${Math.abs(currentUser.wallet_balance_dzd).toLocaleString()} DZD` : '0 DZD';
loadPrices();
loadCustomerOrders();
}
function loadPrices() {
const pricesTable = document.getElementById('pricesTable');
pricesTable.innerHTML = prices.map(price => `
<tr>
<td class="px-4 py-2 text-sm text-gray-900">${price.min_usd} - ${price.max_usd}</td>
<td class="px-4 py-2 text-sm text-gray-900">${price.price_per_usd_dzd}</td>
</tr>
`).join('');
}
function loadCustomerOrders() {
const ordersTable = document.getElementById('ordersTable');
const customerOrders = orders.filter(o => o.user_id === currentUser.id);
ordersTable.innerHTML = customerOrders.map(order => `
<tr>
<td class="px-4 py-2 text-sm text-gray-900">${order.date}</td>
<td class="px-4 py-2 text-sm text-gray-900">${order.platform}</td>
<td class="px-4 py-2 text-sm text-gray-900">${order.usd_amount}</td>
<td class="px-4 py-2 text-sm text-gray-900">${order.dzd_amount.toLocaleString()}</td>
<td class="px-4 py-2 text-sm">
<span class="px-2 py-1 rounded-full text-xs font-semibold
${order.status === 'Paid' ? 'bg-green-100 text-green-800' :
order.status === 'Rejected' ? 'bg-red-100 text-red-800' :
order.status === 'In Progress' ? 'bg-yellow-100 text-yellow-800' :
'bg-gray-100 text-gray-800'}">
${order.status}
</span>
</td>
<td class="px-4 py-2 text-sm text-gray-900">${order.admin_notes || '-'}</td>
</tr>
`).join('');
}
function updateDZDAmount() {
const usdAmount = parseFloat(document.getElementById('usdAmount').value || 0);
const applicablePrice = prices.find(p => usdAmount >= p.min_usd && usdAmount <= p.max_usd) || prices[prices.length - 1];
const dzdAmount = usdAmount * applicablePrice.price_per_usd_dzd;
document.getElementById('dzdAmount').textContent = dzdAmount.toLocaleString();
}
function handleCreditRequest(e) {
e.preventDefault();
const formData = new FormData(e.target);
const newOrder = {
id: orders.length + 1,
user_id: currentUser.id,
platform: document.getElementById('platform').value,
usd_amount: parseFloat(document.getElementById('usdAmount').value),
dzd_amount: parseFloat(document.getElementById('dzdAmount').textContent.replace(/,/g, '')),
id_number: document.getElementById('idNumber').value,
status: 'Pending',
date: new Date().toISOString().split('T')[0],
admin_notes: ''
};
orders.push(newOrder);
e.target.reset();
document.getElementById('dzdAmount').textContent = '0';
loadCustomerOrders();
alert('Credit request submitted successfully!');
}
// Admin functions
function loadAdminData() {
// Update stats
document.getElementById('totalCustomers').textContent = users.filter(u => u.type === 'customer').length;
document.getElementById('totalOrders').textContent = orders.length;
document.getElementById('pendingOrders').textContent = orders.filter(o => o.status === 'Pending').length;
const dailyVolume = orders
.filter(o => o.date === new Date().toISOString().split('T')[0] && o.status === 'Paid')
.reduce((sum, o) => sum + o.dzd_amount, 0);
document.getElementById('dailyVolume').textContent = `${dailyVolume.toLocaleString()} DZD`;
loadAdminOrders();
}
function loadAdminOrders() {
const adminOrdersTable = document.getElementById('adminOrdersTable');
adminOrdersTable.innerHTML = orders.map(order => {
const user = users.find(u => u.id === order.user_id);
return `
<tr>
<td class="px-4 py-2 text-sm text-gray-900">${user ? user.name : 'Unknown'}</td>
<td class="px-4 py-2 text-sm text-gray-900">${order.date}</td>
<td class="px-4 py-2 text-sm text-gray-900">${order.platform}</td>
<td class="px-4 py-2 text-sm text-gray-900">${order.usd_amount}</td>
<td class="px-4 py-2 text-sm text-gray-900">${order.dzd_amount.toLocaleString()}</td>
<td class="px-4 py-2 text-sm">
<span class="px-2 py-1 rounded-full text-xs font-semibold
${order.status === 'Paid' ? 'bg-green-100 text-green-800' :
order.status === 'Rejected' ? 'bg-red-100 text-red-800' :
order.status === 'In Progress' ? 'bg-yellow-100 text-yellow-800' :
'bg-gray-100 text-gray-800'}">
${order.status}
</span>
</td>
<td class="px-4 py-2 text-sm">
<button onclick="openActionModal(${order.id})"
class="text-purple-600 hover:text-purple-900 font-semibold">
Manage
</button>
</td>
</tr>
`;
}).join('');
}
function filterOrders() {
// Placeholder for filtering logic
loadAdminOrders();
}
function openActionModal(orderId) {
document.getElementById('actionModal').classList.remove('hidden');
document.getElementById('actionOrderId').value = orderId;
}
function closeActionModal() {
document.getElementById('actionModal').classList.add('hidden');
}
function handleOrderAction(e) {
e.preventDefault();
const orderId = parseInt(document.getElementById('actionOrderId').value);
const status = document.getElementById('actionStatus').value;
const notes = document.getElementById('actionNotes').value;
const balance = parseFloat(document.getElementById('actionBalance').value);
const order = orders.find(o => o.id === orderId);
if (order) {
order.status = status;
order.admin_notes = notes;
if (balance > 0) {
const user = users.find(u => u.id === order.user_id);
if (user) {
user.wallet_balance_dzd += balance;
}
}
loadAdminData();
closeActionModal();
}
}
function loadPricesManagement() {
const pricesTable = document.getElementById('pricesManagementTable');
const quantityTable = document.getElementById('quantityManagementTable');
pricesTable.innerHTML = prices.map((price, index) => `
<tr>
<td class="px-4 py-2 text-sm">
<input type="number" value="${price.min_usd}"
onchange="updatePrice(${index}, 'min_usd', this.value)"
class="w-20 px-2 py-1 border rounded">
</td>
<td class="px-4 py-2 text-sm">
<input type="number" value="${price.max_usd}"
onchange="updatePrice(${index}, 'max_usd', this.value)"
class="w-20 px-2 py-1 border rounded">
</td>
<td class="px-4 py-2 text-sm">
<input type="number" value="${price.price_per_usd_dzd}"
onchange="updatePrice(${index}, 'price_per_usd_dzd', this.value)"
class="w-20 px-2 py-1 border rounded">
</td>
<td class="px-4 py-2 text-sm">
<button onclick="deletePrice(${index})" class="text-red-600 hover:text-red-900">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
`).join('');
quantityTable.innerHTML = quantityRanges.map((range, index) => `
<tr>
<td class="px-4 py-2 text-sm">
<input type="number" value="${range.min_quantity}"
onchange="updateQuantity(${index}, 'min_quantity', this.value)"
class="w-20 px-2 py-1 border rounded">
</td>
<td class="px-4 py-2 text-sm">
<input type="number" value="${range.max_quantity}"
onchange="updateQuantity(${index}, 'max_quantity', this.value)"
class="w-20 px-2 py-1 border rounded">
</td>
<td class="px-4 py-2 text-sm">
<input type="number" value="${range.available_quantity}"
onchange="updateQuantity(${index}, 'available_quantity', this.value)"
class="w-20 px-2 py-1 border rounded">
</td>
<td class="px-4 py-2 text-sm">
<button onclick="deleteQuantity(${index})" class="text-red-600 hover:text-red-900">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
`).join('');
}
function updatePrice(index, field, value) {
prices[index][field] = parseFloat(value);
}
function updateQuantity(index, field, value) {
quantityRanges[index][field] = parseFloat(value);
}
function deletePrice(index) {
prices.splice(index, 1);
loadPricesManagement();
}
function deleteQuantity(index) {
quantityRanges.splice(index, 1);
loadPricesManagement();
}
function addPriceRange() {
prices.push({ min_usd: 0, max_usd: 0, price_per_usd_dzd: 0 });
loadPricesManagement();
}
function addQuantityRange() {
quantityRanges.push({ min_quantity: 0, max_quantity: 0, available_quantity: 0 });
loadPricesManagement();
}
function loadReports() {
// Placeholder for report generation
const ctx = document.getElementById('volumeChart').getContext('2d');
// Simple chart drawing
ctx.fillStyle = '#667eea';
ctx.fillRect(10, 50, 50, 100);
ctx.fillRect(70, 30, 50, 120);
ctx.fillRect(130, 60, 50, 90);
}
function generateReport() {
// Placeholder for report generation
alert('Report generated successfully!');
}
// Initialize
showLogin();
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=nadiraouf/devise" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>