From e13d867c7f4bcde84c6f6217bd0bd95874208f7d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 31 Jul 2023 11:17:36 +1000 Subject: [PATCH] Additional query filters for invoices --- app/Filters/InvoiceFilters.php | 42 +++++++++++++++++++ app/Http/Livewire/BillingPortalPurchasev2.php | 3 ++ 2 files changed, 45 insertions(+) diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index 1e07412eda..a1f522168e 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -183,6 +183,48 @@ class InvoiceFilters extends QueryFilters ->where('client_id', $this->decodePrimaryKey($client_id)); } + + /** + * @param string $date + * @return Builder + * @throws InvalidArgumentException + */ + public function date(string $date = ''): Builder + { + if (strlen($date) == 0) { + return $this->builder; + } + + if (is_numeric($date)) { + $created_at = Carbon::createFromTimestamp((int)$date); + } else { + $created_at = Carbon::parse($date); + } + + return $this->builder->where('date', '>=', $date); + } + + /** + * @param string $date + * @return Builder + * @throws InvalidArgumentException + */ + public function due_date(string $date = ''): Builder + { + if (strlen($date) == 0) { + return $this->builder; + } + + if (is_numeric($date)) { + $created_at = Carbon::createFromTimestamp((int)$date); + } else { + $created_at = Carbon::parse($date); + } + + return $this->builder->where('due_date', '>=', $date); + } + + /** * Sorts the list based on $sort. * diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index aaf9bf65cb..2e1272e5e8 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -25,6 +25,7 @@ use App\Models\Subscription; use App\Repositories\ClientContactRepository; use App\Repositories\ClientRepository; use App\Utils\Number; +use App\Utils\Traits\MakesHash; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; @@ -34,6 +35,7 @@ use Livewire\Component; class BillingPortalPurchasev2 extends Component { + use MakesHash; /** * Random hash generated by backend to handle the tracking of state. * @@ -422,6 +424,7 @@ class BillingPortalPurchasev2 extends Component $client_repo = new ClientRepository(new ClientContactRepository()); $data = [ 'name' => '', + 'group_id' => $this->encodePrimaryKey($this->subscription->group_id), 'contacts' => [ ['email' => $this->email], ],