12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
-
- namespace App\Models\Banking;
-
- use App\Enums\BankAccountType;
- use App\Models\Accounting\Account;
- use App\Traits\Blamable;
- use App\Traits\CompanyOwned;
- use Illuminate\Database\Eloquent\Casts\Attribute;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasOneThrough;
- use Wallo\FilamentCompanies\FilamentCompanies;
-
- class ConnectedBankAccount extends Model
- {
- use Blamable;
- use CompanyOwned;
-
- protected $table = 'connected_bank_accounts';
-
- protected $fillable = [
- 'company_id',
- 'institution_id',
- 'bank_account_id',
- 'external_account_id',
- 'access_token',
- 'identifier',
- 'item_id',
- 'currency_code',
- 'current_balance',
- 'name',
- 'mask',
- 'type',
- 'subtype',
- 'import_transactions',
- 'created_by',
- 'updated_by',
- ];
-
- protected $casts = [
- 'import_transactions' => 'boolean',
- 'type' => BankAccountType::class,
- 'access_token' => 'encrypted',
- ];
-
- protected $appends = [
- 'masked_number',
- ];
-
- public function company(): BelongsTo
- {
- return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
- }
-
- public function institution(): BelongsTo
- {
- return $this->belongsTo(Institution::class, 'institution_id');
- }
-
- public function bankAccount(): BelongsTo
- {
- return $this->belongsTo(BankAccount::class, 'bank_account_id');
- }
-
- public function account(): HasOneThrough
- {
- return $this->hasOneThrough(
- Account::class,
- BankAccount::class,
- 'id',
- 'accountable_id',
- 'bank_account_id',
- 'id'
- );
- }
-
- protected function maskedNumber(): Attribute
- {
- return Attribute::get(static function (mixed $value, array $attributes): ?string {
- return $attributes['mask'] ? '•••• ' . substr($attributes['mask'], -4) : null;
- });
- }
-
- public function createdBy(): BelongsTo
- {
- return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
- }
-
- public function updatedBy(): BelongsTo
- {
- return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
- }
- }
|