File size: 4,782 Bytes
201773a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ChipFlow - Withdrawals</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
</head>
<body class="bg-gray-100">
    <div class="container mx-auto p-4">
        <div class="bg-white rounded-lg shadow p-6">
            <h1 class="text-2xl font-bold mb-6">Withdrawal Management</h1>
            
            <div class="mb-6">
                <button id="newWithdrawBtn" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700">
                    <i data-feather="plus" class="mr-2"></i>New Withdrawal
                </button>
            </div>

            <div class="overflow-x-auto">
                <table class="min-w-full bg-white">
                    <thead>
                        <tr class="bg-gray-100 text-left">
                            <th class="py-3 px-4">ID</th>
                            <th class="py-3 px-4">Customer</th>
                            <th class="py-3 px-4">Bank</th>
                            <th class="py-3 px-4">Chips</th>
                            <th class="py-3 px-4">Amount</th>
                            <th class="py-3 px-4">Status</th>
                            <th class="py-3 px-4">Date</th>
                            <th class="py-3 px-4">Actions</th>
                        </tr>
                    </thead>
                    <tbody id="withdrawTableBody">
                        <!-- Data will be loaded via JS -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script>
        feather.replace();
        
        // Load withdrawal data
        fetch('/api/withdrawals')
            .then(response => response.json())
            .then(data => {
                const tbody = document.getElementById('withdrawTableBody');
                tbody.innerHTML = data.map(withdrawal => `
                    <tr class="border-b">
                        <td class="py-3 px-4">${withdrawal.id}</td>
                        <td class="py-3 px-4">${withdrawal.customerName}</td>
                        <td class="py-3 px-4">${withdrawal.bankName}</td>
                        <td class="py-3 px-4">${withdrawal.chips}</td>
                        <td class="py-3 px-4">${withdrawal.amount}</td>
                        <td class="py-3 px-4">
                            <span class="px-2 py-1 rounded-full text-xs ${getStatusClass(withdrawal.status)}">
                                ${withdrawal.status}
                            </span>
                        </td>
                        <td class="py-3 px-4">${new Date(withdrawal.date).toLocaleDateString()}</td>
                        <td class="py-3 px-4">
                            <button onclick="viewWithdrawal('${withdrawal.id}')" class="text-blue-600 hover:text-blue-800 mr-2">
                                <i data-feather="eye"></i>
                            </button>
                            ${withdrawal.status === 'Pending' ? `
                            <button onclick="approveWithdrawal('${withdrawal.id}')" class="text-green-600 hover:text-green-800 mr-2">
                                <i data-feather="check"></i>
                            </button>
                            <button onclick="rejectWithdrawal('${withdrawal.id}')" class="text-red-600 hover:text-red-800">
                                <i data-feather="x"></i>
                            </button>
                            ` : ''}
                        </td>
                    </tr>
                `).join('');
                feather.replace();
            });

        function getStatusClass(status) {
            return {
                'Pending': 'bg-yellow-100 text-yellow-800',
                'Completed': 'bg-green-100 text-green-800',
                'Rejected': 'bg-red-100 text-red-800'
            }[status] || 'bg-gray-100 text-gray-800';
        }

        document.getElementById('newWithdrawBtn').addEventListener('click', () => {
            window.location.href = '/withdraw_new.html';
        });

        function viewWithdrawal(id) {
            window.location.href = `/withdraw_detail.html?id=${id}`;
        }

        function approveWithdrawal(id) {
            fetch(`/api/withdrawals/${id}/approve`, { method: 'POST' })
                .then(() => window.location.reload());
        }

        function rejectWithdrawal(id) {
            fetch(`/api/withdrawals/${id}/reject`, { method: 'POST' })
                .then(() => window.location.reload());
        }
    </script>
</body>
</html>