belongsTo(Customer::class, 'customer_id'); } public function user() { return $this->belongsTo(User::class, 'user_id'); } /** * Whether this transaction added ('credit'), removed ('debit') or left * ('neutral') the customer's balance untouched. `amount` is always stored * positive, so the direction has to be derived from `type` (and, for * 'invoice', from the note) to mirror the actual balance mutation logic * in InvoicePaymentService / CustomerController / AdminTransactionController. */ public function getDirectionAttribute(): string { return match ($this->type) { 'admin_add_total', 'admin_add_credit', 'manual', 'refund' => 'credit', 'admin_deduct_credit' => 'debit', 'balance' => 'debit', 'transfer' => 'neutral', 'invoice' => str_starts_with((string) $this->note, 'Admin xác nhận') ? 'neutral' : 'debit', default => 'credit', }; } public function getProofImageUrlsAttribute(): array { if (! $this->proof_image) { return []; } $paths = json_decode($this->proof_image, true); if (! is_array($paths)) { $paths = [$this->proof_image]; } $paths = array_values(array_filter($paths, fn ($path) => is_string($path) && $path !== '')); return array_map( fn (int $index) => URL::temporarySignedRoute( 'admin.transactions.proof-image', now()->addDay(), ['transaction' => $this->uuid, 'index' => $index], ), array_keys($paths), ); } }