diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 0f7061f0a9ac..36f0f9d8dd63 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -703,13 +703,23 @@ class CheckData extends Command ->count(); if($count == 0){ - $this->logMessage("# {$client->id} # {$client->name} {$client->balance} is invalid should be 0"); + + //factor in over payments to the client balance + $over_payment = Payment::where('client_id', $client->id) + ->where('is_deleted', 0) + ->whereIn('status_id', [1,4]) + ->selectRaw('sum(amount - applied) as p') + ->pluck('p') + ->first(); - if($this->option('client_balance')){ + + $this->logMessage("# {$client->id} # {$client->name} {$client->balance} is invalid should be {$over_payment}"); + + if($this->option('client_balance') && (floatval($over_payment) != floatval($client->balance) )){ $this->logMessage("# {$client->id} " . $client->present()->name().' - '.$client->number." Fixing {$client->balance} to 0"); - $client->balance = 0; + $client->balance = $over_payment * -1; $client->save(); } diff --git a/app/PaymentDrivers/Stripe/SEPA.php b/app/PaymentDrivers/Stripe/SEPA.php index 0672a2f775f6..c002d08f1f9d 100644 --- a/app/PaymentDrivers/Stripe/SEPA.php +++ b/app/PaymentDrivers/Stripe/SEPA.php @@ -39,6 +39,7 @@ class SEPA $data['client'] = $this->stripe->client; $data['country'] = $this->stripe->client->country->iso_3166_2; $data['currency'] = $this->stripe->client->currency(); + $data['payment_hash'] = 'x'; return render('gateways.stripe.sepa.authorize', $data); } diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 85b296026d58..b78588963852 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -144,7 +144,7 @@ class PaymentRepository extends BaseRepository { $invoice_totals = array_sum(array_column($data['invoices'], 'amount')); - $invoices = Invoice::whereIn('id', array_column($data['invoices'], 'invoice_id'))->get(); + $invoices = Invoice::withTrashed()->whereIn('id', array_column($data['invoices'], 'invoice_id'))->get(); $payment->invoices()->saveMany($invoices); diff --git a/app/Services/Invoice/TriggeredActions.php b/app/Services/Invoice/TriggeredActions.php index dd838dba6046..99368b156ecc 100644 --- a/app/Services/Invoice/TriggeredActions.php +++ b/app/Services/Invoice/TriggeredActions.php @@ -44,6 +44,10 @@ class TriggeredActions extends AbstractService $this->invoice = $this->invoice->service()->markPaid()->save(); } + if ($this->request->has('mark_sent') && $this->request->input('mark_sent') == 'true') { + $this->invoice = $this->invoice->service()->markSent()->save(); + } + if ($this->request->has('amount_paid') && is_numeric($this->request->input('amount_paid'))) { $this->invoice = $this->invoice->service()->applyPaymentAmount($this->request->input('amount_paid'))->save(); } @@ -53,10 +57,6 @@ class TriggeredActions extends AbstractService $this->sendEmail(); } - if ($this->request->has('mark_sent') && $this->request->input('mark_sent') == 'true') { - $this->invoice = $this->invoice->service()->markSent()->save(); - } - if ($this->request->has('cancel') && $this->request->input('cancel') == 'true') { $this->invoice = $this->invoice->service()->handleCancellation()->save(); } diff --git a/app/Utils/Traits/GeneratesConvertedQuoteCounter.php b/app/Utils/Traits/GeneratesConvertedQuoteCounter.php index 3b1d3cf6a70d..39012ecfb452 100644 --- a/app/Utils/Traits/GeneratesConvertedQuoteCounter.php +++ b/app/Utils/Traits/GeneratesConvertedQuoteCounter.php @@ -33,6 +33,9 @@ use Illuminate\Support\Str; */ trait GeneratesConvertedQuoteCounter { + + private int $update_counter; + private function harvestQuoteCounter($quote, $invoice, Client $client) { $settings = $client->getMergedSettings(); diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index 2debb8ac9647..30c8a58f7b33 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -34,6 +34,9 @@ use Illuminate\Support\Str; */ trait GeneratesCounter { + + private int $update_counter; + //todo in the form validation, we need to ensure that if a prefix and pattern is set we throw a validation error, //only one type is allow else this will cause confusion to the end user @@ -418,7 +421,8 @@ trait GeneratesCounter $check_counter = 1; do { - + nlog($counter); + $number = $this->padCounter($counter, $padding); $number = $this->applyNumberPattern($entity, $number, $pattern); @@ -432,12 +436,16 @@ trait GeneratesCounter if ($check_counter > 100) { + $this->update_counter = $counter--; + return $number.'_'.Str::random(5); } } while ($check); + $this->update_counter = $counter--; + return $number; } @@ -469,7 +477,8 @@ trait GeneratesCounter $settings->{$counter_name} = 1; } - $settings->{$counter_name} = $settings->{$counter_name} + 1; + // $settings->{$counter_name} = $settings->{$counter_name} + 1; + $settings->{$counter_name} = $this->update_counter; $entity->settings = $settings; diff --git a/lang/en/texts.php b/lang/en/texts.php index f829dee616e0..eda88d5f99a6 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -4219,7 +4219,7 @@ $LANG = array( 'max_companies_desc' => 'You have reached your maximum number of companies. Delete existing companies to migrate new ones.', 'migration_already_completed' => 'Company already migrated', 'migration_already_completed_desc' => 'Looks like you already migrated :company_name to the V5 version of the Invoice Ninja. In case you want to start over, you can force migrate to wipe existing data.', - 'payment_method_cannot_be_authorized_first' => 'This payment method can be can saved for future use, once you complete your first transaction. Don\'t forget to check "Store credit card details" during payment process.', + 'payment_method_cannot_be_authorized_first' => 'This payment method can be can saved for future use, once you complete your first transaction. Don\'t forget to check "Store details" during payment process.', 'new_account' => 'New account', 'activity_100' => ':user created recurring invoice :recurring_invoice', 'activity_101' => ':user updated recurring invoice :recurring_invoice', diff --git a/resources/views/portal/ninja2020/gateways/stripe/sepa/authorize.blade.php b/resources/views/portal/ninja2020/gateways/stripe/sepa/authorize.blade.php index 1537ee4c6e01..9517c7ee3185 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/sepa/authorize.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/sepa/authorize.blade.php @@ -7,78 +7,14 @@ @else @endif + @endsection @section('gateway_content') - @if(session()->has('sepa_error')) -
{{ session('sepa_error') }}
-