mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 02:04:30 -04:00
Merge pull request #6590 from beganovich/v5-669
Show all documents on the `Documents` page
This commit is contained in:
commit
cb9e470741
@ -14,6 +14,15 @@ namespace App\Http\Livewire;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Document;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Project;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\Task;
|
||||
use App\Utils\Traits\WithSorting;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
@ -28,23 +37,139 @@ class DocumentsTable extends Component
|
||||
|
||||
public $company;
|
||||
|
||||
public string $tab = 'documents';
|
||||
|
||||
protected $query;
|
||||
|
||||
public function mount($client)
|
||||
{
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
$this->client = $client;
|
||||
|
||||
$this->query = $this->documents();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$query = $this->client
|
||||
->documents()
|
||||
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
|
||||
->paginate($this->per_page);
|
||||
|
||||
return render('components.livewire.documents-table', [
|
||||
'documents' => $query,
|
||||
'documents' => $this->query->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')->paginate($this->per_page),
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateResources(string $resource)
|
||||
{
|
||||
$this->tab = $resource;
|
||||
|
||||
switch ($resource) {
|
||||
case 'documents':
|
||||
$this->query = $this->documents();
|
||||
break;
|
||||
|
||||
case 'credits':
|
||||
$this->query = $this->credits();
|
||||
break;
|
||||
|
||||
case 'expenses':
|
||||
$this->query = $this->expenses();
|
||||
break;
|
||||
|
||||
case 'invoices':
|
||||
$this->query = $this->invoices();
|
||||
break;
|
||||
|
||||
case 'payments':
|
||||
$this->query = $this->payments();
|
||||
break;
|
||||
|
||||
case 'projects':
|
||||
$this->query = $this->projects();
|
||||
break;
|
||||
|
||||
case 'quotes':
|
||||
$this->query = $this->quotes();
|
||||
break;
|
||||
|
||||
case 'recurringInvoices':
|
||||
$this->query = $this->recurringInvoices();
|
||||
break;
|
||||
|
||||
case 'tasks':
|
||||
$this->query = $this->tasks();
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->query = $this->documents();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function documents()
|
||||
{
|
||||
return $this->client->documents();
|
||||
}
|
||||
|
||||
protected function credits()
|
||||
{
|
||||
return Document::query()
|
||||
->whereHasMorph('documentable', [Credit::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
}
|
||||
|
||||
protected function expenses()
|
||||
{
|
||||
return Document::query()
|
||||
->whereHasMorph('documentable', [Expense::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
}
|
||||
|
||||
protected function invoices()
|
||||
{
|
||||
return Document::query()
|
||||
->whereHasMorph('documentable', [Invoice::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
}
|
||||
|
||||
protected function payments()
|
||||
{
|
||||
return Document::query()
|
||||
->whereHasMorph('documentable', [Payment::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
}
|
||||
|
||||
protected function projects()
|
||||
{
|
||||
return Document::query()
|
||||
->whereHasMorph('documentable', [Project::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
}
|
||||
|
||||
protected function quotes()
|
||||
{
|
||||
return Document::query()
|
||||
->whereHasMorph('documentable', [Quote::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
}
|
||||
|
||||
protected function recurringInvoices()
|
||||
{
|
||||
return Document::query()
|
||||
->whereHasMorph('documentable', [RecurringInvoice::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
}
|
||||
|
||||
protected function tasks()
|
||||
{
|
||||
return Document::query()
|
||||
->whereHasMorph('documentable', [Task::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
2
public/css/app.css
vendored
2
public/css/app.css
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
{
|
||||
"/js/app.js": "/js/app.js?id=696e8203d5e8e7cf5ff5",
|
||||
"/css/app.css": "/css/app.css?id=f0b3774b6c3be0a294a7",
|
||||
"/css/app.css": "/css/app.css?id=4ef1527acb43442be8d2",
|
||||
"/js/clients/invoices/action-selectors.js": "/js/clients/invoices/action-selectors.js?id=a09bb529b8e1826f13b4",
|
||||
"/js/clients/invoices/payment.js": "/js/clients/invoices/payment.js?id=8ce8955ba775ea5f47d1",
|
||||
"/js/clients/linkify-urls.js": "/js/clients/linkify-urls.js?id=0dc8c34010d09195d2f7",
|
||||
|
@ -4303,6 +4303,7 @@ $LANG = array(
|
||||
'savings' => 'Savings',
|
||||
'unable_to_verify_payment_method' => 'Unable to verify payment method.',
|
||||
'generic_gateway_error' => 'Gateway configuration error. Please check your credentials.',
|
||||
'my_documents' => 'My documents',
|
||||
);
|
||||
|
||||
return $LANG;
|
||||
|
@ -1,5 +1,61 @@
|
||||
<div>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="space-x-2 flex flex-row -mt-6 overflow-x-auto inline-block pb-4">
|
||||
<button
|
||||
class="button border border-transparent hover:border-gray-600 {{ $tab === 'documents' ? 'border-gray-600' : '' }}"
|
||||
wire:click="updateResources('documents')" />
|
||||
{{ ctrans('texts.my_documents') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="button border border-transparent hover:border-gray-600 {{ $tab === 'credits' ? 'border-gray-600' : '' }}"ž
|
||||
wire:click="updateResources('credits')" />
|
||||
{{ ctrans('texts.credits') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="button border border-transparent hover:border-gray-600 {{ $tab === 'expenses' ? 'border-gray-600' : '' }}"ž
|
||||
wire:click="updateResources('expenses')" />
|
||||
{{ ctrans('texts.expenses') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="button border border-transparent hover:border-gray-600 {{ $tab === 'invoices' ? 'border-gray-600' : '' }}"ž
|
||||
wire:click="updateResources('invoices')" />
|
||||
{{ ctrans('texts.invoices') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="button border border-transparent hover:border-gray-600 {{ $tab === 'payments' ? 'border-gray-600' : '' }}"ž
|
||||
wire:click="updateResources('payments')" />
|
||||
{{ ctrans('texts.payments') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="button border border-transparent hover:border-gray-600 {{ $tab === 'projects' ? 'border-gray-600' : '' }}"ž
|
||||
wire:click="updateResources('projects')" />
|
||||
{{ ctrans('texts.projects') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="button border border-transparent hover:border-gray-600 {{ $tab === 'quotes' ? 'border-gray-600' : '' }}"ž
|
||||
wire:click="updateResources('quotes')" />
|
||||
{{ ctrans('texts.quotes') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="button border border-transparent hover:border-gray-600 {{ $tab === 'recurringInvoices' ? 'border-gray-600' : '' }}"ž
|
||||
wire:click="updateResources('recurringInvoices')" />
|
||||
{{ ctrans('texts.recurring_invoices') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="button border border-transparent hover:border-gray-600 {{ $tab === 'tasks' ? 'border-gray-600' : '' }}"ž
|
||||
wire:click="updateResources('tasks')" />
|
||||
{{ ctrans('texts.tasks') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between mt-6">
|
||||
<div class="flex items-center">
|
||||
<span class="mr-2 text-sm hidden md:block">{{ ctrans('texts.per_page') }}</span>
|
||||
<select wire:model="per_page" class="form-select py-1 text-sm">
|
||||
|
Loading…
x
Reference in New Issue
Block a user