mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
Modernize all 16 models with missing type declarations: - Return types on ~87 methods (string, bool, void, array, mixed, etc.) - Typed parameters where missing - PHPDoc blocks on non-obvious methods explaining their purpose Models updated: Invoice, Estimate, Payment, User, Company, Customer, RecurringInvoice, Setting, CompanySetting, FileDisk, Transaction, EmailLog, ExchangeRateLog, PaymentMethod, CustomField, CustomFieldValue.
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class ExchangeRateLog extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [
|
|
'id',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'exchange_rate' => 'float',
|
|
];
|
|
}
|
|
|
|
public function currency(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Currency::class);
|
|
}
|
|
|
|
public function company(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Company::class);
|
|
}
|
|
|
|
/**
|
|
* Create an exchange rate log entry from a document model (invoice, estimate, etc.)
|
|
* using its exchange rate, currency, and the company's default currency setting.
|
|
*/
|
|
public static function addExchangeRateLog(mixed $model): self
|
|
{
|
|
$data = [
|
|
'exchange_rate' => $model->exchange_rate,
|
|
'company_id' => $model->company_id,
|
|
'base_currency_id' => $model->currency_id,
|
|
'currency_id' => CompanySetting::getSetting('currency', $model->company_id),
|
|
];
|
|
|
|
return self::create($data);
|
|
}
|
|
}
|