From a93fcdc588da784bf48fcb08fe4feed7e02bf3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 6 Sep 2021 17:26:42 +0200 Subject: [PATCH 1/9] My documents & credits --- app/Http/Livewire/DocumentsTable.php | 48 ++++++++++++++++--- resources/lang/en/texts.php | 1 + .../livewire/documents-table.blade.php | 16 ++++++- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/app/Http/Livewire/DocumentsTable.php b/app/Http/Livewire/DocumentsTable.php index 4e9954fa7b9c..ffa3e49ac8c3 100644 --- a/app/Http/Livewire/DocumentsTable.php +++ b/app/Http/Livewire/DocumentsTable.php @@ -14,6 +14,8 @@ namespace App\Http\Livewire; use App\Libraries\MultiDB; use App\Models\Client; +use App\Models\Credit; +use App\Models\Document; use App\Utils\Traits\WithSorting; use Livewire\Component; use Livewire\WithPagination; @@ -28,23 +30,55 @@ 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; + + 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); + }); + } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index ba8a3e755cda..b08dd95999fb 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -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; diff --git a/resources/views/portal/ninja2020/components/livewire/documents-table.blade.php b/resources/views/portal/ninja2020/components/livewire/documents-table.blade.php index 1cbb071de65c..03d430f74b25 100644 --- a/resources/views/portal/ninja2020/components/livewire/documents-table.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/documents-table.blade.php @@ -1,5 +1,19 @@
-
+
+ + + +
+ +