Invoice filters for expense

This commit is contained in:
David Bomba 2023-06-27 21:31:21 +10:00
parent 1ecce29e56
commit 356834b628
3 changed files with 19 additions and 1 deletions

View File

@ -109,7 +109,7 @@ class ExpenseFilters extends QueryFilters
public function has_invoices(string $value = ''): Builder public function has_invoices(string $value = ''): Builder
{ {
if ($value == 'true') { if ($value == 'true') {
return $this->builder->whereNotNull('invoice_id')->select('expenses.invoice_id'); return $this->builder->whereNotNull('invoice_id');
} }
return $this->builder; return $this->builder;

View File

@ -225,6 +225,11 @@ class Expense extends BaseModel
return $this->belongsTo(Company::class); return $this->belongsTo(Company::class);
} }
public function invoice()
{
return $this->belongsTo(Invoice::class);
}
public function vendor() public function vendor()
{ {
return $this->belongsTo(Vendor::class); return $this->belongsTo(Vendor::class);

View File

@ -13,6 +13,7 @@ namespace App\Transformers;
use App\Models\Vendor; use App\Models\Vendor;
use App\Models\Expense; use App\Models\Expense;
use App\Models\Invoice;
use App\Models\Document; use App\Models\Document;
use App\Models\ExpenseCategory; use App\Models\ExpenseCategory;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
@ -39,6 +40,7 @@ class ExpenseTransformer extends EntityTransformer
'client', 'client',
'vendor', 'vendor',
'category', 'category',
'invoice',
]; ];
public function includeDocuments(Expense $expense) public function includeDocuments(Expense $expense)
@ -59,6 +61,17 @@ class ExpenseTransformer extends EntityTransformer
return $this->includeItem($expense->client, $transformer, Client::class); return $this->includeItem($expense->client, $transformer, Client::class);
} }
public function includeInvoice(Expense $expense): ?Item
{
$transformer = new InvoiceTransformer($this->serializer);
if (!$expense->invoice) {
return null;
}
return $this->includeItem($expense->invoice, $transformer, Invoice::class);
}
public function includeCategory(Expense $expense): ?Item public function includeCategory(Expense $expense): ?Item
{ {
$transformer = new ExpenseCategoryTransformer($this->serializer); $transformer = new ExpenseCategoryTransformer($this->serializer);