<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>دفعة مورد جديدة<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/procurement/payments" class="btn btn-outline"><i data-lucide="arrow-right" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> العودة للقائمة</a>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<form method="POST" action="/procurement/payments">
    <?= csrf_field() ?>

    <div class="card" style="margin-bottom:20px;">
        <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
            <i data-lucide="banknote" style="width:18px;height:18px;color:#1e3a5f;"></i>
            <h3 style="margin:0;color:#1e3a5f;font-size:15px;">بيانات الدفعة</h3>
        </div>
        <div style="padding:20px;">
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
                <div>
                    <label class="form-label">المورد <span style="color:#DC2626;">*</span></label>
                    <select name="supplier_id" class="form-select" required>
                        <option value="">-- اختر المورد --</option>
                        <?php foreach ($suppliers as $sup): ?>
                        <option value="<?= (int) $sup['id'] ?>"><?= e($sup['name_ar']) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div>
                    <label class="form-label">الفاتورة</label>
                    <select name="invoice_id" class="form-select">
                        <option value="">— بدون فاتورة —</option>
                        <?php foreach ($approvedInvoices as $inv): ?>
                        <option value="<?= (int) $inv['id'] ?>" data-supplier="<?= (int) $inv['supplier_id'] ?>" data-amount="<?= e($inv['total_amount']) ?>">
                            <?= e($inv['internal_number']) ?> — <?= e($inv['supplier_name']) ?> (<?= money($inv['total_amount']) ?>)
                        </option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div>
                    <label class="form-label">المبلغ <span style="color:#DC2626;">*</span></label>
                    <input type="number" name="amount" class="form-input" step="0.01" min="0.01" required placeholder="0.00">
                </div>
                <div>
                    <label class="form-label">طريقة الدفع <span style="color:#DC2626;">*</span></label>
                    <select name="payment_method" class="form-select" required>
                        <?php foreach ($paymentMethods as $val => $label): ?>
                        <option value="<?= e($val) ?>"><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div>
                    <label class="form-label">الحساب البنكي</label>
                    <select name="bank_account_id" class="form-select">
                        <option value="">— اختياري —</option>
                        <?php foreach ($bankAccounts as $ba): ?>
                        <option value="<?= (int) $ba['id'] ?>"><?= e($ba['name_ar'] ?? $ba['account_number'] ?? '') ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div>
                    <label class="form-label">تاريخ الدفع</label>
                    <input type="date" name="payment_date" class="form-input" value="<?= date('Y-m-d') ?>">
                </div>
                <div>
                    <label class="form-label">رقم الشيك</label>
                    <input type="text" name="check_number" class="form-input" placeholder="اختياري">
                </div>
                <div>
                    <label class="form-label">الرقم المرجعي</label>
                    <input type="text" name="reference_number" class="form-input" placeholder="اختياري">
                </div>
            </div>
            <div style="margin-top:15px;">
                <label class="form-label">ملاحظات</label>
                <textarea name="notes" class="form-input" rows="2" placeholder="ملاحظات إضافية..."></textarea>
            </div>
        </div>
    </div>

    <div style="text-align:left;">
        <button type="submit" class="btn btn-primary" style="padding:10px 30px;">
            <i data-lucide="save" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> حفظ الدفعة
        </button>
    </div>
</form>

<script>document.addEventListener('DOMContentLoaded', function() { if (typeof lucide !== 'undefined') lucide.createIcons(); });</script>
<?php $__template->endSection(); ?>
