Polish the manual invoice feature with 4 improvements: 1. Admin invoice form: numeric fields (unit_price, discount_amount) now display values with thousand-separators (e.g. 1,000,000 instead of 1000000) via formatStateUsing/dehydrateStateUsing for easier reading of large Rial amounts. The placeholder/subtotal/total calculations also strip commas before arithmetic. 2. Fix 'total amount payable = 0' bug in the form. The placeholder had a typo: 'foreach ( as )' overwrote the loop variable and made the inner calculation use the array instead of each item, so the sum was always 0. Now correctly iterates with . 3. Customer dashboard widget: add an 'Invoices pending payment' card showing the count, with a link to /my-account/?tab=invoices if > 0. Relabel the existing 'Pending payment' card to 'Pending payment (orders)' to clarify it's for orders, not invoices. 4. Customer profile financial status: include manual invoices in the accounting_balance and pending_payments_total. Show a breakdown list (orders vs invoices) under the balance card, plus two new stat cards (pending invoices count/total, paid invoices count/total) with a link to the invoices tab.
34 lines
1.0 KiB
PHP
34 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ManualInvoiceResource\Pages;
|
|
|
|
use App\Filament\Resources\ManualInvoiceResource;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
|
|
class EditManualInvoice extends EditRecord
|
|
{
|
|
protected static string $resource = ManualInvoiceResource::class;
|
|
|
|
protected static ?string $title = 'ویرایش فاکتور';
|
|
|
|
protected function mutateFormDataBeforeSave(array $data): array
|
|
{
|
|
// فقط اگه فاکتور pending_payment باشه قابل ویرایشه
|
|
// محاسبه مجدد subtotal و total
|
|
$totals = \App\Models\ManualInvoice::calculateTotal(
|
|
$data['items'] ?? [],
|
|
(float) ($data['discount_amount'] ?? 0)
|
|
);
|
|
$data['subtotal'] = $totals['subtotal'];
|
|
$data['discount_amount'] = $totals['discount_amount'];
|
|
$data['total_amount'] = $totals['total_amount'];
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function getRedirectUrl(): string
|
|
{
|
|
return $this->getResource()::getUrl('index');
|
|
}
|
|
}
|