ifnex/04_Laravel/resources/views/filament/widgets/unsettled-credits.blade.php
Kazem Alghasi 93ebbb1fc8 feat(finance): implement multi-currency credit tracking and dashboard widgets
Integrate multi-currency debt visibility across the platform by adding
support for foreign currency credits in the user profile shortcode,
improving the admin dashboard with unsettled credits widgets, and
enhancing the Filament admin panel with navigation badges and relation
managers.

- Add multi-currency debt table to WordPress user profile shortcode
- Implement `UnsettledCreditsWidget` for Filament dashboard
- Add navigation badge to `CustomerCreditResource` for open credits
- Add `CreditsRelationManager` to `UserResource`
- Update `CustomerOrderController` API to include `foreign_credits`
- Add concurrency check in `CustomerCreditService` during settlement
2026-10-04 01:01:20 +03:30

109 lines
6.5 KiB
PHP

{{--
IFNEX — Unsettled foreign currency credits dashboard widget.
Shows: currency summary badges + top 5 debtors table.
--}}
<x-filament-widgets::widget>
<div class="ifnex-card-shadow ifnex-card bg-white dark:bg-gray-800 rounded-2xl border border-gray-200 dark:border-gray-700 overflow-hidden">
{{-- ──────── Header ──────── --}}
<div class="px-5 py-4 border-b border-gray-100 dark:border-gray-700 flex items-center justify-between">
<div class="flex items-center gap-2.5">
<span class="inline-flex items-center justify-center w-9 h-9 rounded-xl bg-amber-100 dark:bg-amber-900/40 text-amber-600 dark:text-amber-400">
<x-heroicon-o-globe-alt class="w-5 h-5" />
</span>
<div>
<h3 class="text-base font-bold text-gray-900 dark:text-white">بدهی‌های ارزی تسویه‌نشده</h3>
<span class="text-xs text-gray-500 dark:text-gray-400">
{{ ifnex_persian_digits(number_format($totalDebtors)) }} مشتری بدهکار،
{{ ifnex_persian_digits(number_format($totalOpenCredits)) }} اعتبار باز
</span>
</div>
</div>
<a href="{{ route('filament.admin.resources.customer-credits.index') }}?tableFilters[status][value]=open"
class="ifnex-link-inline text-xs font-semibold text-amber-600 hover:text-amber-700 dark:text-amber-400 transition-colors">
مشاهده همه ←
</a>
</div>
@if(!$hasDebts)
{{-- Empty state --}}
<div class="p-8 text-center">
<div class="inline-flex items-center justify-center w-14 h-14 rounded-2xl bg-green-100 dark:bg-green-900/30 text-green-500 mb-3">
<x-heroicon-o-check-circle class="w-7 h-7" />
</div>
<p class="text-sm font-medium text-gray-500 dark:text-gray-400">
✅ هیچ بدهی ارزی تسویه‌نشده‌ای وجود ندارد
</p>
</div>
@else
{{-- ──────── Currency Summary ──────── --}}
<div class="px-5 py-3 border-b border-gray-100 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/40">
<div class="flex flex-wrap gap-2">
@foreach($currencySummary as $cs)
<span class="ifnex-badge ifnex-badge-warning" style="font-size: 13px; padding: 4px 10px;">
{{ $cs['currency_code'] }}:
{{ number_format($cs['total_balance'], 2) }}
<span style="opacity:0.7; font-weight:400;">
({{ ifnex_persian_digits(number_format($cs['credit_count'])) }} رکورد)
</span>
</span>
@endforeach
</div>
</div>
{{-- ──────── Top Debtors Table ──────── --}}
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="bg-gray-50 dark:bg-gray-900/40 text-gray-500 dark:text-gray-400 border-b border-gray-100 dark:border-gray-700">
<th class="ifnex-th text-right">مشتری</th>
<th class="ifnex-th text-right">موبایل</th>
<th class="ifnex-th text-right">ارزها</th>
<th class="ifnex-th text-right">تعداد اعتبار</th>
<th class="ifnex-th text-right">آخرین اعطا</th>
<th class="ifnex-th text-right">اقدام</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-50 dark:divide-gray-700/60">
@foreach($topDebtors as $debtor)
<tr class="ifnex-table-row-hover transition-colors duration-150">
<td class="ifnex-td">
<a href="{{ route('filament.admin.resources.users.edit', $debtor->user_id) }}"
class="font-bold text-gray-900 dark:text-white hover:text-amber-600 transition-colors">
{{ $debtor->user_name }}
</a>
</td>
<td class="ifnex-td text-xs text-gray-700 dark:text-gray-300 ltr">
{{ $debtor->user_phone ?: '—' }}
</td>
<td class="ifnex-td">
@php $currencies = explode(',', $debtor->currencies); @endphp
@foreach($currencies as $cur)
<span class="ifnex-badge ifnex-badge-info" style="margin-inline-end:4px;">
{{ $cur }}
</span>
@endforeach
</td>
<td class="ifnex-td text-center">
<span class="ifnex-badge ifnex-badge-warning">
{{ ifnex_persian_digits(number_format($debtor->credit_count)) }}
</span>
</td>
<td class="ifnex-td text-xs text-gray-500">
{{ $debtor->latest_grant ? \Morilog\Jalali\Jalalian::fromCarbon(\Carbon\Carbon::parse($debtor->latest_grant))->format('Y/m/d') : '—' }}
</td>
<td class="ifnex-td">
<a href="{{ route('filament.admin.pages.customer-financial') }}?data.customer_id={{ $debtor->user_id }}"
class="ifnex-btn ifnex-btn-sm ifnex-btn-info"
style="font-size:11px; padding:3px 8px;">
وضعیت مالی
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</div>
</x-filament-widgets::widget>