Files
InvoiceShelf/app/Domains/Receivables/Models/PaymentMethod.php
T
Darko Gjorgjijoski 5ef7804e60 refactor: adopt modular domain architecture (#747)
* refactor: stabilize model identities for domain migration

* refactor: extract module platform context

* refactor: assign models to domain contexts

* refactor: extract ai platform context

* refactor: extract storage platform context

* refactor: extract mail platform context

* refactor: extract pdf platform context

* refactor: extract operations platform context

* refactor: move installation into operations platform

* refactor: extract money domain context

* refactor: extract taxation domain context

* refactor: extract catalog domain context

* refactor: extract metadata domain context

* refactor: extract reporting domain context

* refactor: extract purchases domain context

* refactor: extract receivables domain context

* refactor: extract accounts domain context

* refactor: complete reporting statement boundary

* refactor: extract contacts domain context

* refactor: extract sales domain context

* refactor: remove legacy application layers

* fix: migrate legacy bouncer role identities
2026-08-05 17:40:03 +02:00

111 lines
2.5 KiB
PHP

<?php
namespace App\Domains\Receivables\Models;
use App\Domains\Accounts\Models\Company;
use App\Domains\Purchases\Models\Expense;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class PaymentMethod extends Model
{
protected $table = 'payment_methods';
use HasFactory;
protected $guarded = [
'id',
];
public const TYPE_GENERAL = 'GENERAL';
public const TYPE_MODULE = 'MODULE';
protected function casts(): array
{
return [
'settings' => 'array',
'use_test_env' => 'boolean',
];
}
public function setSettingsAttribute($value)
{
$this->attributes['settings'] = json_encode($value);
}
public function payments(): HasMany
{
return $this->hasMany(Payment::class);
}
public function expenses(): HasMany
{
return $this->hasMany(Expense::class);
}
public function company(): BelongsTo
{
return $this->belongsTo(Company::class);
}
public function scopeWhereCompanyId($query, $id)
{
$query->where('company_id', $id);
}
public function scopeWhereCompany($query)
{
$query->where('company_id', request()->header('company'));
}
public function scopeWherePaymentMethod($query, $payment_id)
{
$query->orWhere('id', $payment_id);
}
public function scopeWhereSearch($query, $search)
{
$query->where('name', 'LIKE', '%'.$search.'%');
}
public function scopeApplyFilters($query, array $filters)
{
$filters = collect($filters);
if ($filters->get('method_id')) {
$query->wherePaymentMethod($filters->get('method_id'));
}
if ($filters->get('company_id')) {
$query->whereCompany($filters->get('company_id'));
}
if ($filters->get('search')) {
$query->whereSearch($filters->get('search'));
}
}
public function scopePaginateData($query, $limit)
{
if ($limit == 'all') {
return $query->get();
}
return $query->paginate($limit);
}
/**
* Retrieve the settings array for a payment method by its ID.
*/
public static function getSettings(int $id): mixed
{
$settings = PaymentMethod::find($id)
->settings;
return $settings;
}
}