<?php

namespace App\Modules\Invoices;

use App\Models\ValidationModel;
use App\Models\User;
use App\Modules\Clients\Client;
use App\Modules\Clients\Customer;
use App\Modules\Invoices\InvoiceItem;
use App\Modules\Invoices\Payment;

class Invoice extends AbstractInvoice
{
    /**
     *	Register events.
     */
    public static function boot()
    {
        parent::boot();

        // When a sale is created we want to
        // update the created_by field
        static::creating(function ($invoice) {
            $invoice->type = 'invoice';
        });
    }

    public function items()
    {
        return $this->hasMany(InvoiceItem::class);
    }

    public function payments()
    {
        return $this->hasMany(Payment::class);
    }


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

    public function modifier()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }
}
