Files
exchange-2.0/app/Models/TransactionDetail.php
glovetleong 897f0c7207 fix bug
2021-03-29 17:19:36 +08:00

38 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class TransactionDetail extends AbstractModel
{
protected $table = 'transaction_detail';
/**
* @return BelongsTo
*/
public function transaction(): BelongsTo
{
return $this->BelongsTo( Transaction::class, 'transaction_id', 'id');
}
public function convert_original_price()
{
if($this->transaction()->first()->booking()->first()->fix_currency_id !== 1) {
$currency_rate = $this->transaction()->first()->currency()->first()->rates()->where('payment_method_type', $this->transaction()->first()->payment_method)->first();
return number_format($this->price / $currency_rate->selling, 2);
}
return $this->price;
}
public function convert_original_amount()
{
if($this->transaction()->first()->booking()->first()->fix_currency_id !== 1) {
$currency_rate = $this->transaction()->first()->currency()->first()->rates()->where('payment_method_type', $this->transaction()->first()->payment_method)->first();
return number_format($this->amount / $currency_rate->selling, 2);
}
return $this->amount;
}
}