2020-04-23 00:49:23 +02:00
|
|
|
<?php
|
|
|
|
|
2020-12-05 14:24:21 +01:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-12-05 14:24:21 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-12-05 14:24:21 +01:00
|
|
|
*/
|
|
|
|
|
2023-12-13 17:52:49 +01:00
|
|
|
namespace App\Livewire;
|
2020-04-23 00:49:23 +02:00
|
|
|
|
2021-06-07 03:06:31 +02:00
|
|
|
use App\Libraries\MultiDB;
|
2022-12-23 01:51:29 +01:00
|
|
|
use App\Models\Company;
|
2020-04-23 00:49:23 +02:00
|
|
|
use App\Models\Payment;
|
2020-05-04 23:22:31 +02:00
|
|
|
use App\Utils\Traits\WithSorting;
|
2020-04-23 00:49:23 +02:00
|
|
|
use Livewire\Component;
|
|
|
|
use Livewire\WithPagination;
|
|
|
|
|
|
|
|
class PaymentsTable extends Component
|
|
|
|
{
|
|
|
|
use WithSorting;
|
|
|
|
use WithPagination;
|
|
|
|
|
2022-12-23 01:51:29 +01:00
|
|
|
public int $per_page = 10;
|
2021-06-07 03:06:31 +02:00
|
|
|
|
2022-12-23 01:51:29 +01:00
|
|
|
public Company $company;
|
2020-04-23 00:49:23 +02:00
|
|
|
|
2022-12-23 01:51:29 +01:00
|
|
|
public int $company_id;
|
|
|
|
|
|
|
|
public string $db;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2020-04-23 00:49:23 +02:00
|
|
|
public function mount()
|
|
|
|
{
|
2022-12-23 01:51:29 +01:00
|
|
|
MultiDB::setDb($this->db);
|
2021-06-07 03:06:31 +02:00
|
|
|
|
2022-12-23 01:51:29 +01:00
|
|
|
$this->company = Company::find($this->company_id);
|
2020-04-23 00:49:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
$query = Payment::query()
|
2023-01-19 04:45:34 +01:00
|
|
|
->with('type', 'client', 'invoices')
|
2021-07-03 23:46:25 +02:00
|
|
|
->where('company_id', $this->company->id)
|
2022-09-16 06:20:46 +02:00
|
|
|
->where('client_id', auth()->guard('contact')->user()->client_id)
|
|
|
|
->whereIn('status_id', [Payment::STATUS_FAILED, Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_REFUNDED, Payment::STATUS_PARTIALLY_REFUNDED])
|
2022-12-16 23:26:31 +01:00
|
|
|
->orderBy($this->sort_field, $this->sort_asc ? 'desc' : 'asc')
|
2021-09-06 18:14:00 +02:00
|
|
|
->withTrashed()
|
2020-04-23 00:49:23 +02:00
|
|
|
->paginate($this->per_page);
|
|
|
|
|
|
|
|
return render('components.livewire.payments-table', [
|
2020-09-06 11:38:10 +02:00
|
|
|
'payments' => $query,
|
2020-04-23 00:49:23 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|