52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Shop;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Venturecraft\Revisionable\RevisionableTrait;
|
|
use Znck\Eloquent\Traits\BelongsToThrough;
|
|
|
|
class Invoice extends Model
|
|
{
|
|
use BelongsToThrough, RevisionableTrait, SoftDeletes;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $table = 'shop_invoices';
|
|
|
|
protected $revisionCreationsEnabled = false;
|
|
|
|
protected $keepRevisionOf = ['status', 'total_taxed', 'shipping', 'total_shipped'];
|
|
|
|
public function payments()
|
|
{
|
|
return $this->hasMany(InvoicePayment::class);
|
|
}
|
|
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(Order::class);
|
|
}
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customer::class, 'customer_id');
|
|
}
|
|
|
|
public function address()
|
|
{
|
|
return $this->belongsTo(CustomerAddress::class, 'invoice_address_id');
|
|
}
|
|
|
|
public function scopeByUUID($query, $uuid)
|
|
{
|
|
return $query->where('uuid', $uuid);
|
|
}
|
|
|
|
public function scopeByPeriod($query, $start, $end)
|
|
{
|
|
return $query->whereBetween('created_at', [$start, $end]);
|
|
}
|
|
}
|