<?php
// accounts_transactions.php
?>
<link rel="stylesheet" href="assets/css/accounts.css">

<div id="transactionsPage" dir="rtl" class="container-fluid py-4">
    <!-- Header -->
    <div class="d-flex justify-content-between align-items-center mb-4 no-print">
        <div>
            <h2 class="fw-bold text-primary urdu-bold mb-1">ٹرانزیکشنز کا انتظام (Manage Transactions)</h2>
            <p class="text-muted urdu-regular fs-5">تمام آمدنی و اخراجات کی تفصیلات یہاں دیکھیں</p>
        </div>
        <div class="d-flex gap-2">
            <button class="btn btn-success px-4 py-2 rounded-3 urdu-regular fs-5" id="btnAddNew">
                <i class="bi bi-plus-lg me-2"></i> نئی ٹرانزیکشن
            </button>
            <a href="accounts_dashboard" class="btn btn-outline-dark px-4 py-2 rounded-3 urdu-regular fs-5">
                <i class="bi bi-arrow-right me-2"></i> واپس ڈیش بورڈ
            </a>
        </div>
    </div>

    <!-- Filters -->
    <div class="card border-0 shadow-sm rounded-4 mb-4 no-print">
        <div class="card-body p-4">
            <div class="row g-3 align-items-end">
                <div class="col-md-3">
                    <label class="form-label urdu-regular fs-6 font-weight-bold">تاریخ ابتداء (Start Date)</label>
                    <input type="date" class="form-control" id="filterStart" value="<?php echo date('Y-m-01'); ?>">
                </div>
                <div class="col-md-3">
                    <label class="form-label urdu-regular fs-6 font-weight-bold">تاریخ انتہاء (End Date)</label>
                    <input type="date" class="form-control" id="filterEnd" value="<?php echo date('Y-m-d'); ?>">
                </div>
                <div class="col-md-2">
                    <label class="form-label urdu-regular fs-6 font-weight-bold">قسم (Type)</label>
                    <select class="form-select" id="filterType">
                        <option value="">تمام (All)</option>
                        <option value="income">آمدنی (Income)</option>
                        <option value="expense">اخراجات (Expense)</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <label class="form-label urdu-regular fs-6 font-weight-bold">زمرہ (Category)</label>
                    <select class="form-select" id="filterCategory">
                        <option value="">لوڈ ہو رہا ہے...</option>
                    </select>
                </div>
                <div class="col-md-1">
                    <button class="btn btn-primary w-100 py-2" id="btnFilter">
                        <i class="bi bi-search"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Transactions Table -->
    <div class="card border-0 shadow-sm rounded-4 overflow-hidden">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0" id="transactionsTable">
                    <thead class="bg-light urdu-bold">
                        <tr>
                            <th class="py-3 px-4">#</th>
                            <th class="py-3">تاریخ (Date)</th>
                            <th class="py-3">قسم (Type)</th>
                            <th class="py-3">زمرہ (Category)</th>
                            <th class="py-3 text-start">رقم (Amount)</th>
                            <th class="py-3">طریقہ کار (Method)</th>
                            <th class="py-3">تفصیل (Description)</th>
                            <th class="py-3 px-4 text-center">ایکشن (Action)</th>
                        </tr>
                    </thead>
                    <tbody id="transactionsTableBody">
                        <!-- Loaded via AJAX -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!-- Add/Edit Transaction Modal -->
<div class="modal fade" id="txnModal" tabindex="-1" dir="rtl">
    <div class="modal-dialog modal-lg modal-dialog-centered">
        <div class="modal-content border-0 shadow-lg rounded-4">
            <div class="modal-header bg-primary text-white border-0 py-3 px-4">
                <h5 class="modal-title urdu-bold fs-4" id="txnModalTitle">نئی ٹرانزیکشن</h5>
                <button type="button" class="btn-close btn-close-white ms-0 me-auto" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body p-4">
                <form id="txnForm">
                    <input type="hidden" id="txnId">
                    <div class="row g-4 text-end">
                        <div class="col-md-6 text-end">
                            <label class="form-label urdu-regular fs-5 fw-bold">تاریخ (Date)</label>
                            <input type="date" class="form-control form-control-lg" id="txnDate" required
                                value="<?php echo date('Y-m-d'); ?>">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label urdu-regular fs-5 fw-bold">رقم (Amount)</label>
                            <input type="number" step="0.01" class="form-control form-control-lg" id="txnAmount"
                                required placeholder="رقم درج کریں">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label urdu-regular fs-5 fw-bold">ٹرانزیکشن کی قسم (Type)</label>
                            <select class="form-select form-select-lg" id="txnType" required>
                                <option value="income">آمدنی (Income)</option>
                                <option value="expense">اخراجات (Expense)</option>
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label urdu-regular fs-5 fw-bold">زمرہ (Category)</label>
                            <select class="form-select form-select-lg" id="txnCategory" required>
                                <!-- Loaded via AJAX -->
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label urdu-regular fs-5 fw-bold">ادائیگی کا طریقہ (Method)</label>
                            <select class="form-select form-select-lg" id="txnMethod">
                                <option value="Cash">نقد (Cash)</option>
                                <option value="Bank">بینک (Bank)</option>
                                <option value="Cheque">چیک (Cheque)</option>
                                <option value="Online">آن لائن (Online)</option>
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label urdu-regular fs-5 fw-bold">حوالہ نمبر (Ref No.)</label>
                            <input type="text" class="form-control form-control-lg" id="txnRef"
                                placeholder="Reference No (Optional)">
                        </div>
                        <div class="col-12">
                            <label class="form-label urdu-regular fs-5 fw-bold">تفصیل (Description)</label>
                            <textarea class="form-control" id="txnDesc" rows="3"
                                placeholder="ٹرانزیکشن کی مزید تفصیل لکھیں"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer border-0 p-4">
                <button type="button" class="btn btn-light px-4 py-2 urdu-regular fs-5" data-bs-dismiss="modal">بند
                    کریں</button>
                <button type="submit" form="txnForm" class="btn btn-primary px-5 py-2 urdu-regular fs-5"
                    id="btnSave">محفوظ کریں (Save)</button>
            </div>
        </div>
    </div>
</div>

<script src="assets/js/accounts.js?v=<?php echo time(); ?>"></script>