1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Fixes for upcoming query regression

This commit is contained in:
David Bomba 2024-07-29 10:10:02 +10:00
parent ace0d685d0
commit d7960422a6
5 changed files with 140 additions and 12 deletions

View File

@ -153,22 +153,22 @@ class InvoiceFilters extends QueryFilters
{
return $this->builder->where(function ($query) {
$query->whereIn('invoices.status_id', [Invoice::STATUS_PARTIAL, Invoice::STATUS_SENT])
->where('invoices.is_deleted', 0)
->where('invoices.balance', '>', 0)
->orWhere(function ($query) {
$query->whereIn('status_id', [Invoice::STATUS_PARTIAL, Invoice::STATUS_SENT])
->where('is_deleted', 0)
->where('balance', '>', 0)
->where(function ($query) {
$query->whereNull('invoices.due_date')
$query->whereNull('due_date')
->orWhere(function ($q) {
$q->where('invoices.due_date', '>=', now()->startOfDay()->subSecond())->where('invoices.partial', 0);
$q->where('due_date', '>=', now()->startOfDay()->subSecond())->where('partial', 0);
})
->orWhere(function ($q) {
$q->where('invoices.partial_due_date', '>=', now()->startOfDay()->subSecond())->where('invoices.partial', '>', 0);
$q->where('partial_due_date', '>=', now()->startOfDay()->subSecond())->where('partial', '>', 0);
});
})
->orderByRaw('ISNULL(invoices.due_date), invoices.due_date ' . 'desc')
->orderByRaw('ISNULL(invoices.partial_due_date), invoices.partial_due_date ' . 'desc');
->orderByRaw('ISNULL(due_date), due_date ' . 'desc')
->orderByRaw('ISNULL(partial_due_date), partial_due_date ' . 'desc');
});
}

View File

@ -164,6 +164,13 @@ class BillingPortalPurchasev2 extends Component
public $payment_confirmed = false;
public $is_eligible = true;
public $not_eligible_message = '';
public $check_rff = false;
public ?string $contact_first_name;
public ?string $contact_last_name;
public ?string $contact_email;
public ?string $client_city;
public ?string $client_postal_code;
public function mount()
{
@ -472,7 +479,6 @@ class BillingPortalPurchasev2 extends Component
*/
protected function getPaymentMethods(): self
{
nlog("total amount = {$this->float_amount_total}");
if ($this->float_amount_total == 0) {
$this->methods = [];
@ -481,10 +487,73 @@ class BillingPortalPurchasev2 extends Component
if ($this->contact && $this->float_amount_total >= 1) {
$this->methods = $this->contact->client->service()->getPaymentMethods($this->float_amount_total);
}
foreach($this->methods as $method) {
if($method['is_paypal'] == '1' && !$this->check_rff) {
$this->rff();
break;
}
}
return $this;
}
protected function rff()
{
$this->contact_first_name = $this->contact->first_name;
$this->contact_last_name = $this->contact->last_name;
$this->contact_email = $this->contact->email;
$this->client_city = $this->contact->client->city;
$this->client_postal_code = $this->contact->client->postal_code;
if(
strlen($this->contact_first_name ?? '') == 0 ||
strlen($this->contact_last_name ?? '') == 0 ||
strlen($this->contact_email ?? '') == 0 ||
strlen($this->client_city ?? '') == 0 ||
strlen($this->client_postal_code ?? '') == 0
)
{
$this->check_rff = true;
}
return $this;
}
public function handleRff()
{
$validated = $this->validate([
'contact_first_name' => ['required'],
'contact_last_name' => ['required'],
'client_city' => ['required'],
'client_postal_code' => ['required'],
'contact_email' => ['required', 'email'],
]);
$this->check_rff = false;
$this->contact->first_name = $validated['contact_first_name'];
$this->contact->last_name = $validated['contact_last_name'];
$this->contact->email = $validated['contact_email'];
$this->contact->client->postal_code = $validated['client_postal_code'];
$this->contact->client->city = $validated['client_city'];
$this->contact->pushQuietly();
$this->refreshComponent();
return $this;
}
protected function refreshComponent()
{
$this->dispatch('$refresh');
}
/**
* Middle method between selecting payment method &
* submitting the from to the backend.

File diff suppressed because one or more lines are too long

View File

@ -240,7 +240,7 @@
"src": "resources/js/setup/setup.js"
},
"resources/sass/app.scss": {
"file": "assets/app-ec452b34.css",
"file": "assets/app-df4b7e12.css",
"isEntry": true,
"src": "resources/sass/app.scss"
}

View File

@ -21,6 +21,11 @@
<input type="hidden" name="action" value="payment">
<input type="hidden" name="company_gateway_id" value="{{ $company_gateway_id }}"/>
<input type="hidden" name="payment_method_id" value="{{ $payment_method_id }}"/>
<input type="hidden" name="contact_first_name" value="{{ $contact ? $contact->first_name : '' }}">
<input type="hidden" name="contact_last_name" value="{{ $contact ? $contact->last_name : '' }}">
<input type="hidden" name="contact_email" value="{{ $contact ? $contact->email : '' }}">
<input type="hidden" name="client_city" value="{{ $contact ? $contact->client->city : '' }}">
<input type="hidden" name="client_postal_code" value="{{ $contact ? $contact->client->postal_code : '' }}">
</form>
</div>
@ -313,6 +318,61 @@
{{ ctrans('texts.trial_call_to_action') }}
</button>
</form>
@elseif(count($methods) > 0 && $check_rff)
@if($errors->any())
<div class="w-full mx-auto text-center bg-red-100 border border-red-400 text-red-700 px-4 py-1 rounded">
@foreach($errors->all() as $error)
<p class="w-full">{{ $error }}</p>
@endforeach
</div>
@endif
<form wire:submit="handleRff">
@csrf
@if(strlen($contact->first_name ?? '') === 0)
<div class="col-auto mt-3 flex items-center space-x-0 @if($contact->first_name) !== 0) hidden @endif">
<label for="first_name" class="w-1/4 text-sm font-medium text-white whitespace-nowrap text-left">{{ ctrans('texts.first_name') }}</label>
<input id="first_name" class="w-3/4 rounded-md border-gray-300 pl-2 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm text-gray-700" wire:model="contact_first_name" />
</div>
@endif
@if(strlen($contact->last_name ?? '') === 0)
<div class="col-auto mt-3 flex items-center space-x-0 @if($contact->last_name) !== 0) hidden @endif">
<label for="last_name" class="w-1/4 text-sm font-medium text-white whitespace-nowrap text-left">{{ ctrans('texts.last_name') }}</label>
<input id="last_name" class="w-3/4 rounded-md border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm text-gray-700" wire:model="contact_last_name" />
</div>
@endif
@if(strlen($contact->email ?? '') === 0)
<div class="col-auto mt-3 flex items-center space-x-0 @if($contact->email) !== 0) hidden @endif">
<label for="email" class="w-1/4 text-sm font-medium text-white whitespace-nowrap text-left">{{ ctrans('texts.email') }}</label>
<input id="email" class="w-3/4 rounded-md border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm text-gray-700" wire:model="contact_email" />
</div>
@endif
@if(strlen($client_postal_code ?? '') === 0)
<div class="col-auto mt-3 flex items-center space-x-0 @if($client_postal_code) !== 0) hidden @endif">
<label for="postal_code" class="w-1/4 text-sm font-medium text-white whitespace-nowrap text-left">{{ ctrans('texts.postal_code') }}</label>
<input id="postal_code" class="w-3/4 rounded-md border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm text-gray-700" wire:model="client_postal_code" />
</div>
@endif
@if(strlen($client_city ?? '') === 0)
<div class="col-auto mt-3 flex items-center space-x-0 @if($client_city) !== 0) hidden @endif">
<label for="city" class="w-1/4 text-sm font-medium text-white whitespace-nowrap text-left">{{ ctrans('texts.city') }}</label>
<input id="city" class="w-3/4 rounded-md border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm text-gray-700" wire:model="client_city" />
</div>
@endif
<button
type="submit"
class="relative -ml-px inline-flex items-center space-x-2 rounded border border-gray-300 bg-gray-50 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-100 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 mt-4">
{{ ctrans('texts.next') }}
</button>
</form>
@elseif(count($methods) > 0)
<div class="mt-4" x-show.important="!toggle" x-transition>
@foreach($methods as $method)