Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
33.33% covered (danger)
33.33%
3 / 9
60.00% covered (warning)
60.00%
3 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Account
33.33% covered (danger)
33.33%
3 / 9
60.00% covered (warning)
60.00%
3 / 5
26.96
0.00% covered (danger)
0.00%
0 / 1
 auditName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 transactions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 incomingTransfers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 branch
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 icon
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace App\Models;
4
5use App\Support\Auditable;
6use Illuminate\Database\Eloquent\Model;
7
8/**
9 * A cash / bank / mobile-wallet account. See
10 * App\Services\Accounting\AccountingService for balance + ledger math.
11 */
12class Account extends Model
13{
14    use Auditable;
15
16    protected $fillable = ['branch_id', 'name', 'type', 'opening_balance', 'is_default', 'is_active', 'created_by'];
17
18    protected $casts = [
19        'opening_balance' => 'decimal:2',
20        'is_default' => 'boolean',
21        'is_active' => 'boolean',
22    ];
23
24    protected function auditName(): string
25    {
26        return 'account';
27    }
28
29    public function transactions()
30    {
31        return $this->hasMany(Transaction::class);
32    }
33
34    public function incomingTransfers()
35    {
36        return $this->hasMany(Transaction::class, 'to_account_id');
37    }
38
39    public function branch()
40    {
41        return $this->belongsTo(Branch::class);
42    }
43
44    public function icon(): string
45    {
46        return match ($this->type) {
47            'bank' => 'fa-building-columns',
48            'mobile_wallet' => 'fa-mobile-screen',
49            default => 'fa-money-bill-wave',
50        };
51    }
52}