<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use \DateTimeInterface;

class ExpenseReceipt extends Model
{
    use HasFactory;

    protected $fillable = [
        'expense_receipt_id',
        'user_id',
        'receipt_by',
        'receipt_notes',
        'status',
    ];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('d-m-Y H:i:s');
    }

    public function userData()
    {
        return $this->belongsTo(User::class,'user_id');
    }
   
    public function expenseCategoryData()
    {
        return $this->belongsTo(ExpenseCategory::class,'expense_category_id');
    }
    
    public function expenseData()
    {
        return $this->belongsTo(Expense::class,'expense_id');
    }

    //To fetch pending ExpenseReceipt data...
    public static function getPendingExpenseReceiptData($userId)
    {
        $data = ExpenseReceipt::where('status', false)->where('user_id', $userId)->pluck('id')->toArray();
        return $data;
    }
}
