Commit 85874f1c authored by Mahmoud Aglan's avatar Mahmoud Aglan

Add super_admin payment method edit with audit logging

Super admins can now edit the payment method on any existing payment
directly from the invoice detail page. The change is automatically
captured in the audit log via the Auditable trait on the Payment model.
Co-Authored-By: 's avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent 97d3b159
......@@ -25,6 +25,10 @@ class InvoiceShow extends Component
public string $paymentDate = '';
public string $paymentNotes = '';
// Edit payment method (super_admin only)
public ?string $editingPaymentId = null;
public string $editingPaymentMethod = '';
public function mount(Invoice $invoice): void
{
$this->authorize('invoices.view');
......@@ -83,6 +87,56 @@ public function recordPayment(PaymentService $service): void
}
}
public function startEditPaymentMethod(string $paymentUuid): void
{
abort_unless(auth()->user()->is_super_admin, 403);
$payment = $this->invoice->payments->firstWhere('uuid', $paymentUuid);
if (! $payment) {
return;
}
$this->editingPaymentId = $paymentUuid;
$this->editingPaymentMethod = $payment->method->value ?? $payment->method;
}
public function savePaymentMethod(): void
{
abort_unless(auth()->user()->is_super_admin, 403);
$this->validate([
'editingPaymentMethod' => 'required|in:cash,card,bank_transfer,wallet,online,cheque,other',
], [
'editingPaymentMethod.required' => 'طريقة الدفع مطلوبة',
'editingPaymentMethod.in' => 'طريقة الدفع غير صالحة',
]);
$payment = $this->invoice->payments->firstWhere('uuid', $this->editingPaymentId);
if (! $payment) {
$this->editingPaymentId = null;
return;
}
$oldMethod = $payment->method->value ?? $payment->method;
$newMethod = $this->editingPaymentMethod;
if ($oldMethod !== $newMethod) {
$payment->method = $newMethod;
$payment->save();
}
$this->invoice->refresh()->load(['items', 'payments', 'billable', 'creator']);
$this->editingPaymentId = null;
$this->editingPaymentMethod = '';
session()->flash('success', __('تم تعديل طريقة الدفع'));
}
public function cancelEditPaymentMethod(): void
{
$this->editingPaymentId = null;
$this->editingPaymentMethod = '';
}
public function cancelInvoice(InvoiceService $service): void
{
try {
......
......@@ -176,25 +176,45 @@ class="text-gray-600 hover:text-gray-800 text-sm font-medium">
</thead>
<tbody class="divide-y divide-gray-100">
@foreach($invoice->payments as $payment)
<tr>
@php
$methodColors = [
'cash' => 'green',
'card' => 'blue',
'bank_transfer' => 'indigo',
'wallet' => 'purple',
'online' => 'cyan',
'cheque' => 'amber',
'other' => 'gray',
];
$methodValue = $payment->method->value ?? $payment->method;
$mColor = $methodColors[$methodValue] ?? 'gray';
$pStatusColors = [
'confirmed' => 'green',
'pending' => 'yellow',
'failed' => 'red',
'cancelled' => 'gray',
'refunded' => 'purple',
];
$pStatusValue = $payment->status->value ?? $payment->status;
$pColor = $pStatusColors[$pStatusValue] ?? 'gray';
$isEditing = $editingPaymentId === $payment->uuid;
@endphp
<tr class="{{ $isEditing ? 'bg-amber-50' : '' }}">
<td class="px-4 py-3 font-mono text-gray-600 text-xs" dir="ltr">{{ $payment->reference }}</td>
<td class="px-4 py-3 text-center">
@php
$methodColors = [
'cash' => 'green',
'card' => 'blue',
'bank_transfer' => 'indigo',
'wallet' => 'purple',
'online' => 'cyan',
'cheque' => 'amber',
'other' => 'gray',
];
$methodValue = $payment->method->value ?? $payment->method;
$mColor = $methodColors[$methodValue] ?? 'gray';
@endphp
<span class="px-2 py-0.5 text-xs bg-{{ $mColor }}-100 text-{{ $mColor }}-700 rounded-full">
{{ $payment->method->label() }}
</span>
@if($isEditing)
<select wire:model="editingPaymentMethod"
class="text-xs border border-amber-300 rounded-md px-2 py-1 focus:ring-2 focus:ring-amber-400 focus:border-amber-400 bg-white">
@foreach($paymentMethods as $val => $lbl)
<option value="{{ $val }}">{{ $lbl }}</option>
@endforeach
</select>
@error('editingPaymentMethod') <p class="mt-1 text-xs text-red-600">{{ $message }}</p> @enderror
@else
<span class="px-2 py-0.5 text-xs bg-{{ $mColor }}-100 text-{{ $mColor }}-700 rounded-full">
{{ $payment->method->label() }}
</span>
@endif
</td>
<td class="px-4 py-3 text-center font-medium" dir="ltr">
{{ number_format($payment->amount / 100, 2) }} {{ __('ج.م') }}
......@@ -203,23 +223,36 @@ class="text-gray-600 hover:text-gray-800 text-sm font-medium">
{{ $payment->payment_date?->format('Y-m-d') ?? $payment->created_at?->format('Y-m-d') }}
</td>
<td class="px-4 py-3 text-center">
@php
$pStatusColors = [
'confirmed' => 'green',
'pending' => 'yellow',
'failed' => 'red',
'cancelled' => 'gray',
'refunded' => 'purple',
];
$pStatusValue = $payment->status->value ?? $payment->status;
$pColor = $pStatusColors[$pStatusValue] ?? 'gray';
@endphp
<span class="px-2 py-0.5 text-xs bg-{{ $pColor }}-100 text-{{ $pColor }}-700 rounded-full">
{{ $payment->status->label() }}
</span>
</td>
<td class="px-4 py-3 text-center">
<x-ui.print-receipt-button :route="route('receipts.payment.print', $payment->uuid)" size="sm" />
<div class="flex items-center justify-center gap-2">
<x-ui.print-receipt-button :route="route('receipts.payment.print', $payment->uuid)" size="sm" />
@if(auth()->user()?->is_super_admin)
@if($isEditing)
<button type="button" wire:click="savePaymentMethod"
wire:loading.attr="disabled" wire:target="savePaymentMethod"
class="text-xs px-2 py-1 bg-green-600 text-white rounded hover:bg-green-700 disabled:opacity-50 transition-colors">
<span wire:loading.remove wire:target="savePaymentMethod">{{ __('حفظ') }}</span>
<span wire:loading wire:target="savePaymentMethod">...</span>
</button>
<button type="button" wire:click="cancelEditPaymentMethod"
class="text-xs px-2 py-1 bg-gray-200 text-gray-700 rounded hover:bg-gray-300 transition-colors">
{{ __('إلغاء') }}
</button>
@else
<button type="button" wire:click="startEditPaymentMethod('{{ $payment->uuid }}')"
title="{{ __('تعديل طريقة الدفع') }}"
class="text-xs text-amber-600 hover:text-amber-800 transition-colors">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
</svg>
</button>
@endif
@endif
</div>
</td>
</tr>
@endforeach
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment