mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 22:47:32 -05:00 
			
		
		
		
	My documents & credits
This commit is contained in:
		
							parent
							
								
									28356d2921
								
							
						
					
					
						commit
						a93fcdc588
					
				@ -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);
 | 
			
		||||
            });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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,19 @@
 | 
			
		||||
<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">
 | 
			
		||||
            <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