﻿<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Scopes\OrganisationScope;

/**
 * InvoicePayment
 */
class InvoicePayment extends Model
{
    use HasFactory;

    /**
     * getDateAttribute
     *
     * @param  mixed $value
     * @return void
     */

     protected static function booted()
     {
         static::addGlobalScope(new OrganisationScope);

  // Automatically set the organisation_id before creating the model
        static::creating(function ($model) {
            if (auth()->check()) {
                $model->organisation_id = auth()->user()->organisation_id;
            }
        });
     }

    public function getDateAttribute($value)
    {
        return custom_datetime($value);
    }


    /**
     * getPaymentTypeAttribute
     *
     * @param  mixed $value
     * @return void
     */
    public function getPaymentTypeAttribute($value)
    {
        return strtoupper($value);
    }

    public function invoice()
    {
        return $this->belongsTo(Invoice::class, 'invoice_id', 'id');
    }