feat: add withdraw request functionality and UI components

This commit is contained in:
2026-08-27 02:39:57 +03:30
parent aeef95339d
commit 4ce663c669
115 changed files with 4064 additions and 315 deletions
@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources\Admin;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class WithdrawRequestResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'amount' => $this->amount,
'status' => $this->status,
'admin_note' => $this->admin_note,
'user' => $this->relationLoaded('user') ? $this->user->only(['id', 'fullname', 'level', 'phone']) : null,
'bank_card' => $this->relationLoaded('bankCard') && $this->bankCard
? $this->bankCard->only(['id', 'card_number', 'holder_name'])
: null,
'reviewed_by' => $this->relationLoaded('reviewedBy') && $this->reviewedBy ? $this->reviewedBy->only(['id', 'fullname']) : null,
'created_at' => verta($this->created_at)->format('%Y/%m/%d - H:i'),
'reviewed_at' => $this->reviewed_at ? verta($this->reviewed_at)->format('%Y/%m/%d - H:i') : null,
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Resources\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class BankCardResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'card_number' => $this->card_number,
'holder_name' => $this->holder_name,
];
}
}
@@ -0,0 +1,76 @@
<?php
namespace App\Http\Resources\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CaseDetailResource extends JsonResource
{
public function toArray(Request $request): array
{
$report = $this->reports->sortByDesc('submitted_at')->first();
return [
'id' => $this->id,
'code' => $this->code,
'status' => $this->status,
'modality' => $this->modality,
'priority' => $this->priority,
'note' => $this->note,
'rejection_reason' => $this->rejection_reason,
'submitted_at' => $this->submitted_at ? verta($this->submitted_at)->format('%Y/%m/%d - H:i') : null,
'processing_deadline' => $this->processing_deadline?->toIso8601String(),
'pet' => $this->whenLoaded('pet', fn () => [
'name' => $this->pet->name,
'type' => $this->pet->type,
'gender' => $this->pet->gender,
'breed' => $this->pet->breed,
'age' => $this->pet->birthday ? (int) $this->pet->birthday->diffInYears(now()) : null,
'weight' => $this->pet->weight,
'sterilized' => $this->pet->sterilized,
]),
'requester' => $this->whenLoaded('requester', fn () => [
'level' => $this->requester->level,
'fullname' => $this->requester->fullname,
'phone' => $this->requester->phone,
'specialty' => $this->requester->specialty,
'clinic_name' => $this->requester->clinic_name,
'clinic_phone' => $this->requester->clinic_phone,
'province' => $this->requester->province,
'city' => $this->requester->city,
]),
'primary_files' => $this->mediaFiles('primary'),
'history_files' => $this->mediaFiles('history'),
'report' => $report ? [
'id' => $report->id,
'status' => $report->status,
'technique' => $report->technique,
'finding' => $report->finding,
'diagnose' => $report->diagnose,
'recommendation' => $report->recommendation,
'submitted_at' => $report->submitted_at ? verta($report->submitted_at)->format('%Y/%m/%d - H:i') : null,
'attachments' => $report->attachments->map(fn ($medium) => $this->mediumPayload($medium))->values(),
] : null,
];
}
protected function mediaFiles(string $collection): array
{
return $this->media
->filter(fn ($medium) => $medium->pivot->collection === $collection)
->map(fn ($medium) => $this->mediumPayload($medium))
->values()
->all();
}
protected function mediumPayload($medium): array
{
return [
'id' => $medium->id,
'filename' => $medium->filename,
'url' => $medium->url,
'mime_type' => $medium->mime_type,
];
}
}
@@ -2,7 +2,6 @@
namespace App\Http\Resources\Client;
use App\Enums\DocumentModalityEnum;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
@@ -17,10 +16,7 @@ class FastRequestResource extends JsonResource
'status' => $this->status,
'priority' => $this->priority,
'pet' => new PetArchiveResource($this->whenLoaded('pet')),
'invoice' => [
'number' => str_pad((string) $this->id, 5, '0', STR_PAD_LEFT),
'amount' => DocumentModalityEnum::from($this->modality)->price(),
],
'invoice' => new InvoiceResource($this->whenLoaded('invoice')),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class InvoiceResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'number' => $this->number,
'amount' => $this->amount,
'status' => $this->status,
'payment_method' => $this->payment_method,
'paid_at' => $this->paid_at,
'created_at' => $this->created_at,
'document' => $this->whenLoaded('document', fn () => [
'id' => $this->document->id,
'code' => $this->document->code,
'modality' => $this->document->modality,
]),
];
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Resources\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PaymentResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'track_id' => $this->track_id,
'amount' => $this->amount,
'status' => $this->status,
'ref_number' => $this->ref_number,
];
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ReportResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'status' => $this->status,
'submitted_at' => $this->submitted_at ? verta($this->submitted_at)->format('%Y/%m/%d - H:i') : null,
'document' => $this->whenLoaded('document', fn () => [
'id' => $this->document->id,
'code' => $this->document->code,
'modality' => $this->document->modality,
'status' => $this->document->status,
]),
'doctor' => $this->whenLoaded('doctor', fn () => optional($this->doctor)->fullname),
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Resources\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class WalletTransactionResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'type' => $this->type,
'reason' => $this->reason,
'amount' => $this->amount,
'balance_after' => $this->balance_after,
'description' => $this->description,
'via_gateway' => $this->payment_id !== null,
'invoice_number' => $this->whenLoaded('invoice', fn () => $this->invoice?->number),
'created_at' => verta($this->created_at)->format('%Y/%m/%d - H:i'),
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Resources\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class WithdrawRequestResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'amount' => $this->amount,
'status' => $this->status,
'admin_note' => $this->admin_note,
'bank_card' => $this->relationLoaded('bankCard') && $this->bankCard
? $this->bankCard->only(['id', 'card_number', 'holder_name'])
: null,
'created_at' => verta($this->created_at)->format('%Y/%m/%d - H:i'),
'reviewed_at' => $this->reviewed_at ? verta($this->reviewed_at)->format('%Y/%m/%d - H:i') : null,
];
}
}