You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConnectedBankAccount.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Models\Banking;
  3. use App\Enums\BankAccountType;
  4. use App\Models\Accounting\Account;
  5. use App\Traits\Blamable;
  6. use App\Traits\CompanyOwned;
  7. use Illuminate\Database\Eloquent\Casts\Attribute;
  8. use Illuminate\Database\Eloquent\Model;
  9. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  10. use Illuminate\Database\Eloquent\Relations\HasOneThrough;
  11. use Wallo\FilamentCompanies\FilamentCompanies;
  12. class ConnectedBankAccount extends Model
  13. {
  14. use Blamable;
  15. use CompanyOwned;
  16. protected $table = 'connected_bank_accounts';
  17. protected $fillable = [
  18. 'company_id',
  19. 'institution_id',
  20. 'bank_account_id',
  21. 'external_account_id',
  22. 'access_token',
  23. 'identifier',
  24. 'item_id',
  25. 'currency_code',
  26. 'current_balance',
  27. 'name',
  28. 'mask',
  29. 'type',
  30. 'subtype',
  31. 'import_transactions',
  32. 'created_by',
  33. 'updated_by',
  34. ];
  35. protected $casts = [
  36. 'import_transactions' => 'boolean',
  37. 'type' => BankAccountType::class,
  38. 'access_token' => 'encrypted',
  39. ];
  40. protected $appends = [
  41. 'masked_number',
  42. ];
  43. public function company(): BelongsTo
  44. {
  45. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  46. }
  47. public function institution(): BelongsTo
  48. {
  49. return $this->belongsTo(Institution::class, 'institution_id');
  50. }
  51. public function bankAccount(): BelongsTo
  52. {
  53. return $this->belongsTo(BankAccount::class, 'bank_account_id');
  54. }
  55. public function account(): HasOneThrough
  56. {
  57. return $this->hasOneThrough(
  58. Account::class,
  59. BankAccount::class,
  60. 'id',
  61. 'accountable_id',
  62. 'bank_account_id',
  63. 'id'
  64. );
  65. }
  66. protected function maskedNumber(): Attribute
  67. {
  68. return Attribute::get(static function (mixed $value, array $attributes): ?string {
  69. return $attributes['mask'] ? '•••• ' . substr($attributes['mask'], -4) : null;
  70. });
  71. }
  72. public function createdBy(): BelongsTo
  73. {
  74. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  75. }
  76. public function updatedBy(): BelongsTo
  77. {
  78. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  79. }
  80. }