<?= $this->extend('layouts/enterprise') ?>

<?= $this->section('content') ?>

<?= view('partials/workspace_hero', [
    'workspaceCrumbPill'    => 'Reports',
    'workspaceCrumbCurrent' => 'Tax Reports',
    'workspaceTitle'        => 'Tax Reports',
    'workspaceDesc'         => 'Output and input VAT summary for the selected date range.',
]) ?>

<div class="enterprise-data-panel mb-4">
    <div class="enterprise-data-panel__head">
        <h2 class="enterprise-data-panel__title">Filters</h2>
        <p class="enterprise-data-panel__subtitle">Posted AR/AP documents in the period are included.</p>
    </div>
    <div class="enterprise-data-panel__toolbar">
        <form action="<?= base_url('accounting/tax-reports') ?>" method="get">
            <div class="enterprise-filter-grid">
                <div>
                    <label class="enterprise-field-label">From</label>
                    <input type="date" name="from" class="form-control form-control-sm" value="<?= esc($filters['from']) ?>">
                </div>
                <div>
                    <label class="enterprise-field-label">To</label>
                    <input type="date" name="to" class="form-control form-control-sm" value="<?= esc($filters['to']) ?>">
                </div>
                <div class="enterprise-filter-actions">
                    <button type="submit" class="btn btn-sm btn-primary">Apply Filters</button>
                    <?= view('Modules\Reports\Views\partials\export_buttons', [
                        'actionPath' => 'accounting/tax-reports',
                        'query'      => $filters,
                    ]) ?>
                </div>
            </div>
        </form>
    </div>
</div>

<section class="enterprise-kpi-grid mb-4">
    <article class="enterprise-kpi-card">
        <div class="enterprise-kpi-header">
            <span class="enterprise-kpi-label">Output VAT</span>
            <span class="enterprise-kpi-icon"><i class="fa-solid fa-arrow-up"></i></span>
        </div>
        <div class="enterprise-kpi-value"><?= number_format((float) $summary['output_vat'], 2) ?></div>
        <div class="enterprise-kpi-footer">
            <span class="enterprise-kpi-badge enterprise-kpi-badge--neutral">Sales tax</span>
            <span class="enterprise-kpi-dept">Invoices − credits</span>
        </div>
    </article>
    <article class="enterprise-kpi-card">
        <div class="enterprise-kpi-header">
            <span class="enterprise-kpi-label">Input VAT</span>
            <span class="enterprise-kpi-icon"><i class="fa-solid fa-arrow-down"></i></span>
        </div>
        <div class="enterprise-kpi-value"><?= number_format((float) $summary['input_vat'], 2) ?></div>
        <div class="enterprise-kpi-footer">
            <span class="enterprise-kpi-badge enterprise-kpi-badge--neutral">Purchase tax</span>
            <span class="enterprise-kpi-dept">Bills − debits</span>
        </div>
    </article>
    <article class="enterprise-kpi-card">
        <div class="enterprise-kpi-header">
            <span class="enterprise-kpi-label">Net VAT</span>
            <span class="enterprise-kpi-icon"><i class="fa-solid fa-scale-balanced"></i></span>
        </div>
        <div class="enterprise-kpi-value"><?= number_format((float) $summary['net'], 2) ?></div>
        <div class="enterprise-kpi-footer">
            <span class="enterprise-kpi-badge enterprise-kpi-badge--<?= (float) $summary['net'] >= 0 ? 'warning' : 'success' ?>">
                <?= (float) $summary['net'] >= 0 ? 'Payable' : 'Recoverable' ?>
            </span>
            <span class="enterprise-kpi-dept">Output − input</span>
        </div>
    </article>
</section>

<?= $this->include('Modules\Accounting\Views\tax_reports\_breakdown', ['summary' => $summary]) ?>

<?= $this->endSection() ?>
