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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Models\Banking;
  3. use App\Casts\MoneyCast;
  4. use App\Concerns\Blamable;
  5. use App\Concerns\CompanyOwned;
  6. use App\Enums\Banking\BankAccountType;
  7. use App\Models\Accounting\Account;
  8. use Illuminate\Database\Eloquent\Casts\Attribute;
  9. use Illuminate\Database\Eloquent\Model;
  10. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  11. use Illuminate\Database\Eloquent\Relations\HasOneThrough;
  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. 'last_imported_at',
  33. 'created_by',
  34. 'updated_by',
  35. ];
  36. protected $casts = [
  37. 'current_balance' => MoneyCast::class,
  38. 'import_transactions' => 'boolean',
  39. 'type' => BankAccountType::class,
  40. 'access_token' => 'encrypted',
  41. 'last_imported_at' => 'datetime',
  42. ];
  43. protected $appends = [
  44. 'masked_number',
  45. ];
  46. public function institution(): BelongsTo
  47. {
  48. return $this->belongsTo(Institution::class, 'institution_id');
  49. }
  50. public function bankAccount(): BelongsTo
  51. {
  52. return $this->belongsTo(BankAccount::class, 'bank_account_id');
  53. }
  54. public function account(): HasOneThrough
  55. {
  56. return $this->hasOneThrough(
  57. Account::class,
  58. BankAccount::class,
  59. 'id',
  60. 'accountable_id',
  61. 'bank_account_id',
  62. 'id'
  63. );
  64. }
  65. protected function maskedNumber(): Attribute
  66. {
  67. return Attribute::get(static function (mixed $value, array $attributes): ?string {
  68. return $attributes['mask'] ? '•••• ' . substr($attributes['mask'], -4) : null;
  69. });
  70. }
  71. }