Add projects to invoice list

This commit is contained in:
David Bomba 2025-10-18 10:09:55 +11:00
parent 435bb8e999
commit db73210904
8 changed files with 40 additions and 11 deletions

View File

@ -150,7 +150,8 @@ class CreditFilters extends QueryFilters
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
if ($sort_col[0] == 'client_id') {
return $this->builder->orderBy(\App\Models\Client::select('name')
return $this->builder->orderByRaw('ISNULL(client_id), client_id '. $dir)
->orderBy(\App\Models\Client::select('name')
->whereColumn('clients.id', 'credits.client_id'), $dir);
}

View File

@ -287,11 +287,20 @@ class InvoiceFilters extends QueryFilters
if ($sort_col[0] == 'client_id') {
return $this->builder->orderBy(\App\Models\Client::select('name')
return $this->builder->orderByRaw('ISNULL(client_id), client_id '. $dir)
->orderBy(\App\Models\Client::select('name')
->whereColumn('clients.id', 'invoices.client_id'), $dir);
}
if ($sort_col[0] == 'project_id') {
return $this->builder->orderByRaw('ISNULL(project_id), project_id '. $dir)
->orderBy(\App\Models\Project::select('name')
->whereColumn('projects.id', 'invoices.project_id'), $dir);
}
if ($sort_col[0] == 'number') {
return $this->builder->orderByRaw("REGEXP_REPLACE(invoices.number,'[^0-9]+','')+0 " . $dir);
}

View File

@ -172,7 +172,8 @@ class PaymentFilters extends QueryFilters
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
if ($sort_col[0] == 'client_id') {
return $this->builder->orderBy(\App\Models\Client::select('name')
return $this->builder->orderByRaw('ISNULL(client_id), client_id '. $dir)
->orderBy(\App\Models\Client::select('name')
->whereColumn('clients.id', 'payments.client_id'), $dir);
}

View File

@ -68,7 +68,8 @@ class ProjectFilters extends QueryFilters
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
if ($sort_col[0] == 'client_id') {
return $this->builder->orderBy(\App\Models\Client::select('name')
return $this->builder->orderByRaw('ISNULL(client_id), client_id '. $dir)
->orderBy(\App\Models\Client::select('name')
->whereColumn('clients.id', 'projects.client_id'), $dir);
}

View File

@ -173,7 +173,8 @@ class QuoteFilters extends QueryFilters
}
if ($sort_col[0] == 'client_id') {
return $this->builder->orderBy(\App\Models\Client::select('name')
return $this->builder->orderByRaw('ISNULL(client_id), client_id '. $dir)
->orderBy(\App\Models\Client::select('name')
->whereColumn('clients.id', 'quotes.client_id'), $dir);
}

View File

@ -141,7 +141,8 @@ class RecurringInvoiceFilters extends QueryFilters
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
if ($sort_col[0] == 'client_id') {
return $this->builder->orderBy(\App\Models\Client::select('name')
return $this->builder->orderByRaw('ISNULL(client_id), client_id '. $dir)
->orderBy(\App\Models\Client::select('name')
->whereColumn('clients.id', 'recurring_invoices.client_id'), $dir);
}

View File

@ -138,12 +138,14 @@ class TaskFilters extends QueryFilters
$dir = ($sort_col[1] == 'asc') ? 'asc' : 'desc';
if ($sort_col[0] == 'client_id') {
return $this->builder->orderBy(\App\Models\Client::select('name')
return $this->builder->orderByRaw('ISNULL(client_id), client_id '. $dir)
->orderBy(\App\Models\Client::select('name')
->whereColumn('clients.id', 'tasks.client_id'), $dir);
}
if ($sort_col[0] == 'user_id') {
return $this->builder->orderBy(\App\Models\User::select('first_name')
return $this->builder->orderByRaw('ISNULL(user_id), user_id '. $dir)
->orderBy(\App\Models\User::select('first_name')
->whereColumn('users.id', 'tasks.user_id'), $dir);
}

View File

@ -12,15 +12,16 @@
namespace App\Transformers;
use App\Models\Activity;
use App\Models\Backup;
use App\Models\Client;
use App\Models\Credit;
use App\Models\Document;
use App\Models\Invoice;
use App\Models\InvoiceInvitation;
use App\Models\Payment;
use App\Models\Project;
use App\Models\Activity;
use App\Models\Document;
use App\Utils\Traits\MakesHash;
use App\Models\InvoiceInvitation;
class InvoiceTransformer extends EntityTransformer
{
@ -36,6 +37,7 @@ class InvoiceTransformer extends EntityTransformer
'client',
'activities',
'location',
'project',
];
public function includeLocation(Invoice $invoice)
@ -70,6 +72,17 @@ class InvoiceTransformer extends EntityTransformer
return $this->includeItem($invoice->client, $transformer, Client::class);
}
public function includeProject(Invoice $invoice)
{
$transformer = new ProjectTransformer($this->serializer);
if (!$invoice->project) {
return null;
}
return $this->includeItem($invoice->project, $transformer, Project::class);
}
public function includePayments(Invoice $invoice)
{
$transformer = new PaymentTransformer($this->serializer);