From e9e8e259e8e7ccae520626aa51282c802d273f4f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 1 Mar 2022 21:25:18 +1100 Subject: [PATCH] Fixes for deleting payments --- app/Console/Commands/CheckData.php | 6 +++--- app/Jobs/Util/Import.php | 4 +--- app/Services/Client/ClientService.php | 2 +- app/Services/Payment/DeletePayment.php | 17 +++++++++++++++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index be3c02e075f7..74f5187afab2 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -480,11 +480,11 @@ class CheckData extends Command LEFT JOIN paymentables ON payments.id = paymentables.payment_id - WHERE paymentable_type = 'App\\Models\\Credit' + WHERE paymentable_type = ? AND paymentables.deleted_at is NULL AND payments.is_deleted = 0 AND payments.client_id = ?; - "), [$client->id] ); + "), [App\Models\Credit::class, $client->id] ); return $results; } @@ -507,7 +507,7 @@ class CheckData extends Command $this->wrong_paid_to_dates++; - $this->logMessage($client->present()->name.' id = # '.$client->id." - Paid to date does not match Client Paid To Date = {$client->paid_to_date} - Invoice Payments = {$total_paid_to_date}"); + $this->logMessage($client->present()->name.' id = # '.$client->id." - Client Paid To Date = {$client->paid_to_date} != Invoice Payments = {$total_paid_to_date} - {$_client->payments_applied} + {$credits_used_for_payments[0]->credit_payment}"); $this->isValid = false; diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index c7156d443cf0..ca5b45dd00b0 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -362,6 +362,7 @@ class Import implements ShouldQueue ) { $data['settings']['invoice_design_id'] = 1; } + $data['settings']['email_sending_method'] = 'default'; $data = $this->transformCompanyData($data); @@ -374,9 +375,6 @@ class Import implements ShouldQueue $data['subdomain'] = MultiDB::randomSubdomainGenerator(); } - else { - $data['settings']['email_sending_method'] = 'default'; - } $rules = (new UpdateCompanyRequest())->rules(); diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index 1fa8ee4b7324..2f2152429f4f 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -99,6 +99,6 @@ class ClientService { $this->client->save(); - return $this->client; + return $this->client->fresh(); } } diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index 60ea86d86ed6..f9a92cecb64c 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -145,10 +145,23 @@ class DeletePayment $multiplier = -1; $paymentable_credit->service() - ->updateBalance($paymentable_credit->pivot->amount*$multiplier) - ->updatePaidToDate($paymentable_credit->pivot->amount*-1) + ->updateBalance($paymentable_credit->pivot->amount*$multiplier*-1) + ->updatePaidToDate($paymentable_credit->pivot->amount*$multiplier) ->setStatus(Credit::STATUS_SENT) ->save(); + + $this->payment + ->client + ->service() + ->updatePaidToDate(($paymentable_credit->pivot->amount)*-1) + ->save(); + + //01-03-2022 + // $paymentable_credit->service() + // ->updateBalance($paymentable_credit->pivot->amount*$multiplier) + // ->updatePaidToDate($paymentable_credit->pivot->amount*-1) + // ->setStatus(Credit::STATUS_SENT) + // ->save(); }); }