<?php $__template->layout('Layout.main'); ?>

<?php $__template->section('title'); ?>كشف حساب عضو<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<!-- Search -->
<div class="card" style="margin-bottom:15px;">
    <div style="padding:15px 20px;">
        <form method="GET" action="/accounting/reports/member-statement" style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;">
            <div>
                <label class="form-label" style="font-size:12px;">رقم العضو</label>
                <input type="number" name="member_id" class="form-input" value="<?= $member_id ?>" placeholder="ID العضو">
            </div>
            <div>
                <label class="form-label" style="font-size:12px;">من تاريخ</label>
                <input type="date" name="date_from" class="form-input" value="<?= e($date_from) ?>">
            </div>
            <div>
                <label class="form-label" style="font-size:12px;">إلى تاريخ</label>
                <input type="date" name="date_to" class="form-input" value="<?= e($date_to) ?>">
            </div>
            <button type="submit" class="btn btn-primary">عرض</button>
        </form>
    </div>
</div>

<?php if ($member): ?>
    <div class="card" style="margin-bottom:15px;padding:15px 20px;">
        <h3 style="margin:0;">كشف حساب: <?= e($member['full_name_ar']) ?> (استمارة: <?= e($member['form_number'] ?? '—') ?>)</h3>
        <p style="color:#6B7280;margin:5px 0 0;font-size:13px;">من <?= e($date_from) ?> إلى <?= e($date_to) ?></p>
    </div>

    <div class="card">
        <div class="table-responsive">
            <table class="data-table" style="width:100%;">
                <thead>
                    <tr>
                        <th>التاريخ</th>
                        <th>رقم القيد</th>
                        <th>البيان</th>
                        <th>الحساب</th>
                        <th>مدين</th>
                        <th>دائن</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($entries as $e_row): ?>
                        <tr>
                            <td><?= e($e_row['entry_date']) ?></td>
                            <td style="direction:ltr;text-align:right;font-size:12px;">
                                <a href="/accounting/journal-entries/<?= (int)$e_row['journal_entry_id'] ?>"><?= e($e_row['entry_number']) ?></a>
                            </td>
                            <td style="font-size:13px;"><?= e($e_row['entry_description'] ?? $e_row['description_ar'] ?? '') ?></td>
                            <td style="font-size:12px;"><?= e($e_row['account_code']) ?> — <?= e($e_row['account_name'] ?? '') ?></td>
                            <td style="direction:ltr;text-align:right;"><?= bccomp((string)$e_row['debit'], '0.00', 2) > 0 ? money($e_row['debit']) : '' ?></td>
                            <td style="direction:ltr;text-align:right;"><?= bccomp((string)$e_row['credit'], '0.00', 2) > 0 ? money($e_row['credit']) : '' ?></td>
                        </tr>
                    <?php endforeach; ?>
                    <?php if (empty($entries)): ?>
                        <tr><td colspan="6" style="text-align:center;color:#6B7280;padding:30px;">لا توجد حركات لهذا العضو في الفترة المحددة</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
<?php elseif ($member_id > 0): ?>
    <div class="card" style="padding:40px;text-align:center;color:#DC2626;">العضو غير موجود</div>
<?php endif; ?>
<?php $__template->endSection(); ?>
