<?php

namespace Modules\PurchaseRequisition\Entities;

use Illuminate\Database\Eloquent\Model;

class PrPurchasePayment extends Model
{
    protected $table = 'pr_purchase_payments';

    protected $fillable = [
        'pr_purchase_share_id',
        'paid_amount',
        'paid_currency_id',
        'rate_to_egp',
        'egp_amount',
        'order_currency_id',
        'rate_to_order_currency',
        'order_currency_amount',
        'notes',
        'document',
        'received',
        'received_note',
        'received_at',
        'created_by',
    ];

    protected $casts = [
        'received' => 'boolean',
    ];

    public function share()
    {
        return $this->belongsTo(PrPurchaseShare::class, 'pr_purchase_share_id');
    }

    public function paidCurrency()
    {
        return $this->belongsTo(PrCurrency::class, 'paid_currency_id');
    }

    public function orderCurrency()
    {
        return $this->belongsTo(PrCurrency::class, 'order_currency_id');
    }

    public function createdBy()
    {
        return $this->belongsTo(\App\User::class, 'created_by');
    }
}
