<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;


class TransactionDetail extends AbstractModel
{
    protected $table = 'transaction_details';

    /**
     * @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;
    }
}
