<?php

namespace App\Models;

# use Illuminate\Database\Eloquent\Model;

class Invoice extends Model
{
    protected $table = 'invoice';

    public function displayName() {
        return '$' . $this->amount .
        ($this->description ? ' | ' . substr($this->description, 0, 15) : '') .
        ' | ' . friendly_date_time($this->created_at);
    }

    public function customer() {
        return $this->hasOne(Customer::class, 'id', 'customer_id');
    }

    public function invoiceTransactions() {
        return $this->hasMany(InvoiceTransaction::class, 'invoice_id', 'id')->orderBy('created_at', 'ASC');
    }
}
