My documents & credits

This commit is contained in:
Benjamin Beganović 2021-09-06 17:26:42 +02:00
parent 28356d2921
commit a93fcdc588
3 changed files with 57 additions and 8 deletions

View File

@ -14,6 +14,8 @@ namespace App\Http\Livewire;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Models\Client; use App\Models\Client;
use App\Models\Credit;
use App\Models\Document;
use App\Utils\Traits\WithSorting; use App\Utils\Traits\WithSorting;
use Livewire\Component; use Livewire\Component;
use Livewire\WithPagination; use Livewire\WithPagination;
@ -28,23 +30,55 @@ class DocumentsTable extends Component
public $company; public $company;
public string $tab = 'documents';
protected $query;
public function mount($client) public function mount($client)
{ {
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
$this->client = $client; $this->client = $client;
$this->query = $this->documents();
} }
public function render() 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', [ 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);
});
}
} }

View File

@ -4303,6 +4303,7 @@ $LANG = array(
'savings' => 'Savings', 'savings' => 'Savings',
'unable_to_verify_payment_method' => 'Unable to verify payment method.', 'unable_to_verify_payment_method' => 'Unable to verify payment method.',
'generic_gateway_error' => 'Gateway configuration error. Please check your credentials.', 'generic_gateway_error' => 'Gateway configuration error. Please check your credentials.',
'my_documents' => 'My documents',
); );
return $LANG; return $LANG;

View File

@ -1,5 +1,19 @@
<div> <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>
</div>
<div class="flex items-center justify-between mt-6">
<div class="flex items-center"> <div class="flex items-center">
<span class="mr-2 text-sm hidden md:block">{{ ctrans('texts.per_page') }}</span> <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"> <select wire:model="per_page" class="form-select py-1 text-sm">