From 62bc55cf0bb556b6333eedec96895e59a243efd5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 21 Jan 2021 10:01:13 +1100 Subject: [PATCH 1/8] Fixes for client authentication to client portal --- app/Models/ClientContact.php | 11 +---------- app/Repositories/ClientContactRepository.php | 5 +++++ resources/views/email/admin/generic.blade.php | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 83907c3953..115fb1e206 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -49,10 +49,7 @@ class ClientContact extends Authenticatable implements HasLocalePreference 'hashed_id', ]; - protected $with = [ -// 'client', -// 'company' - ]; + protected $with = []; protected $casts = [ 'updated_at' => 'timestamp', @@ -87,12 +84,6 @@ class ClientContact extends Authenticatable implements HasLocalePreference 'client_id', ]; - /* Changing the username to id allows us to login() a contact that doesn't have an email address set*/ - public function username() - { - return 'id'; - } - public function getEntityType() { return self::class; diff --git a/app/Repositories/ClientContactRepository.php b/app/Repositories/ClientContactRepository.php index ea574f5206..91b3e2ff3f 100644 --- a/app/Repositories/ClientContactRepository.php +++ b/app/Repositories/ClientContactRepository.php @@ -58,6 +58,10 @@ class ClientContactRepository extends BaseRepository $update_contact->client_id = $client->id; } + /* We need to set NULL email addresses to blank strings to pass authentication*/ + if(array_key_exists('email', $contact) && is_null($contact['email'])) + $contact['email'] = ''; + $update_contact->fill($contact); if (array_key_exists('password', $contact) && strlen($contact['password']) > 1) { @@ -77,6 +81,7 @@ class ClientContactRepository extends BaseRepository $new_contact->contact_key = Str::random(40); $new_contact->is_primary = true; $new_contact->confirmed = true; + $new_contact->email = ' '; $new_contact->save(); } } diff --git a/resources/views/email/admin/generic.blade.php b/resources/views/email/admin/generic.blade.php index 579308450f..d08a145a7d 100644 --- a/resources/views/email/admin/generic.blade.php +++ b/resources/views/email/admin/generic.blade.php @@ -5,7 +5,7 @@ @include('email.components.header', ['logo' => $logo]) @endslot -

{{ $title }}

+

{{ $title }}

@slot('greeting') @lang($message) From 7d5b67921438eb65d0bbe37b692479b9f24a150f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 21 Jan 2021 10:02:39 +1100 Subject: [PATCH 2/8] Fix for failed() method returning an error instead of exception --- app/Jobs/Invoice/ZipInvoices.php | 2 +- app/Jobs/Mail/EntityFailedSendMailer.php | 2 +- app/Jobs/Mail/EntityPaidMailer.php | 2 +- app/Jobs/Mail/EntitySentMailer.php | 2 +- app/Jobs/Mail/EntityViewedMailer.php | 2 +- app/Jobs/Mail/MailRouter.php | 2 +- app/Jobs/Mail/PaymentFailureMailer.php | 2 +- app/Jobs/Payment/EmailPayment.php | 2 +- app/Jobs/User/UserEmailChanged.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php index 5e75a86d0e..01fb041a7c 100644 --- a/app/Jobs/Invoice/ZipInvoices.php +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -96,7 +96,7 @@ class ZipInvoices extends BaseMailerJob implements ShouldQueue Mail::to($this->email) ->send(new DownloadInvoices(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company)); } catch (\Exception $e) { - $this->failed($e); + // //$this->failed($e); } UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1)); diff --git a/app/Jobs/Mail/EntityFailedSendMailer.php b/app/Jobs/Mail/EntityFailedSendMailer.php index 3b8cf6be6e..0aabf91ef6 100644 --- a/app/Jobs/Mail/EntityFailedSendMailer.php +++ b/app/Jobs/Mail/EntityFailedSendMailer.php @@ -96,7 +96,7 @@ class EntityFailedSendMailer extends BaseMailerJob implements ShouldQueue ->send(new EntityNotificationMailer($mail_obj)); } catch (\Exception $e) { nlog("failing in EntityFailedSendMailer"); - $this->failed($e); + //$this->failed($e); $this->logMailError($e->getMessage(), $this->entity->client); } } diff --git a/app/Jobs/Mail/EntityPaidMailer.php b/app/Jobs/Mail/EntityPaidMailer.php index c5b483cb6c..7c8094cbda 100644 --- a/app/Jobs/Mail/EntityPaidMailer.php +++ b/app/Jobs/Mail/EntityPaidMailer.php @@ -83,7 +83,7 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue Mail::to($this->user->email) ->send(new EntityNotificationMailer($mail_obj)); } catch (\Exception $e) { - $this->failed($e); + // //$this->failed($e); $this->logMailError($e->getMessage(), $this->payment->client); } } diff --git a/app/Jobs/Mail/EntitySentMailer.php b/app/Jobs/Mail/EntitySentMailer.php index 76aa2c7cd3..e7660f5e1f 100644 --- a/app/Jobs/Mail/EntitySentMailer.php +++ b/app/Jobs/Mail/EntitySentMailer.php @@ -90,7 +90,7 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue Mail::to($this->user->email) ->send(new EntityNotificationMailer($mail_obj)); } catch (\Exception $e) { - $this->failed($e); + // //$this->failed($e); $this->logMailError($e->getMessage(), $this->entity->client); } } diff --git a/app/Jobs/Mail/EntityViewedMailer.php b/app/Jobs/Mail/EntityViewedMailer.php index d8e06ef43d..fa8fca3efd 100644 --- a/app/Jobs/Mail/EntityViewedMailer.php +++ b/app/Jobs/Mail/EntityViewedMailer.php @@ -88,7 +88,7 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue Mail::to($this->user->email) ->send(new EntityNotificationMailer($mail_obj)); } catch (\Exception $e) { - $this->failed($e); + //$this->failed($e); $this->logMailError($e->getMessage(), $this->entity->client); } } diff --git a/app/Jobs/Mail/MailRouter.php b/app/Jobs/Mail/MailRouter.php index 640c38244b..c2673d4e05 100644 --- a/app/Jobs/Mail/MailRouter.php +++ b/app/Jobs/Mail/MailRouter.php @@ -73,7 +73,7 @@ class MailRouter extends BaseMailerJob implements ShouldQueue Mail::to($this->to_user->email) ->send($this->mailable); } catch (\Exception $e) { - $this->failed($e); + //$this->failed($e); if ($this->to_user instanceof ClientContact) { $this->logMailError($e->getMessage(), $this->to_user->client); diff --git a/app/Jobs/Mail/PaymentFailureMailer.php b/app/Jobs/Mail/PaymentFailureMailer.php index e713f5bcd7..5d82c83cd7 100644 --- a/app/Jobs/Mail/PaymentFailureMailer.php +++ b/app/Jobs/Mail/PaymentFailureMailer.php @@ -98,7 +98,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue Mail::to($company_user->user->email) ->send(new EntityNotificationMailer($mail_obj)); } catch (\Exception $e) { - $this->failed($e); + //$this->failed($e); $this->logMailError($e->getMessage(), $this->client); } } diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index 4f5c3f1a13..32d9c36395 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -84,7 +84,7 @@ class EmailPayment extends BaseMailerJob implements ShouldQueue } catch (\Exception $e) { nlog("mailing failed with message " . $e->getMessage()); event(new PaymentWasEmailedAndFailed($this->payment, $this->company, Mail::failures(), Ninja::eventVars())); - $this->failed($e); + //$this->failed($e); return $this->logMailError($e->getMessage(), $this->payment->client); } diff --git a/app/Jobs/User/UserEmailChanged.php b/app/Jobs/User/UserEmailChanged.php index 98866df23e..425df5481e 100644 --- a/app/Jobs/User/UserEmailChanged.php +++ b/app/Jobs/User/UserEmailChanged.php @@ -79,7 +79,7 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue Mail::to($this->new_email) ->send(new UserNotificationMailer($mail_obj)); } catch (\Exception $e) { - $this->failed($e); + //$this->failed($e); $this->logMailError($e->getMessage(), $this->company->owner()); } } From 79723759eb8f30416d673089fa0e5f32ad086ea8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 21 Jan 2021 10:05:23 +1100 Subject: [PATCH 3/8] Reduce test data size for large account --- app/Console/Commands/CreateTestData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 1901521202..ab04224278 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -331,7 +331,7 @@ class CreateTestData extends Command $this->info('Creating '.$this->count.' clients'); - for ($x = 0; $x < $this->count * 500; $x++) { + for ($x = 0; $x < $this->count * 200; $x++) { $z = $x + 1; $this->info('Creating client # '.$z); From db9e8ff830a606d51c6a55c94e3c2fc59cbfbb0f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 21 Jan 2021 10:53:02 +1100 Subject: [PATCH 4/8] Add rules preventing overpayment on invoices --- .../Payment/ValidInvoicesRules.php | 19 +++++++++++++++++++ app/Services/Invoice/ApplyPayment.php | 5 ----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/Http/ValidationRules/Payment/ValidInvoicesRules.php b/app/Http/ValidationRules/Payment/ValidInvoicesRules.php index bcb231f94e..2880af0fa5 100644 --- a/app/Http/ValidationRules/Payment/ValidInvoicesRules.php +++ b/app/Http/ValidationRules/Payment/ValidInvoicesRules.php @@ -53,21 +53,40 @@ class ValidInvoicesRules implements Rule //todo optimize this into a single query foreach ($this->input['invoices'] as $invoice) { + $unique_array[] = $invoice['invoice_id']; $inv = Invoice::whereId($invoice['invoice_id'])->first(); if (! $inv) { + $this->error_msg = 'Invoice not found '; return false; } if ($inv->client_id != $this->input['client_id']) { + $this->error_msg = 'Selected invoices are not from a single client'; return false; } + + if($inv->status_id == Invoice::STATUS_DRAFT && $invoice['amount'] == $inv->amount){ + //catch here nothing to do - we need this to prevent the last elseif triggering + } + else if($inv->status_id == Invoice::STATUS_DRAFT && $invoice['amount'] > $inv->amount){ + + $this->error_msg = 'Amount cannot be greater than invoice balance'; + + return false; + } + else if($invoice['amount'] > $inv->balance) { + + $this->error_msg = 'Amount cannot be greater than invoice balance'; + + return false; + } } if (! (array_unique($unique_array) == $unique_array)) { diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index 952c5038f3..33d9e77b48 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -100,11 +100,6 @@ class ApplyPayment extends AbstractService } } - // $this->payment - // ->ledger() - // ->updatePaymentBalance($this->payment_amount * -1); - - $this->payment ->ledger() ->updatePaymentBalance($amount_paid); From f06fc9f720bc3e4872eb4fa07ad9546764e8b44a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 21 Jan 2021 10:58:54 +1100 Subject: [PATCH 5/8] Minor fix for payment validations' --- app/Http/ValidationRules/Payment/ValidInvoicesRules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/ValidationRules/Payment/ValidInvoicesRules.php b/app/Http/ValidationRules/Payment/ValidInvoicesRules.php index 2880af0fa5..957f4f2cb2 100644 --- a/app/Http/ValidationRules/Payment/ValidInvoicesRules.php +++ b/app/Http/ValidationRules/Payment/ValidInvoicesRules.php @@ -72,7 +72,7 @@ class ValidInvoicesRules implements Rule return false; } - if($inv->status_id == Invoice::STATUS_DRAFT && $invoice['amount'] == $inv->amount){ + if($inv->status_id == Invoice::STATUS_DRAFT && $invoice['amount'] <= $inv->amount){ //catch here nothing to do - we need this to prevent the last elseif triggering } else if($inv->status_id == Invoice::STATUS_DRAFT && $invoice['amount'] > $inv->amount){ From ff4f2f39537f67b3d3b20cc01090f329ee407d0b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 21 Jan 2021 12:33:39 +1100 Subject: [PATCH 6/8] Checks on Company Ledger sanity --- app/Console/Commands/CheckData.php | 6 +++--- app/Services/Client/PaymentMethod.php | 6 ++++-- app/Services/Invoice/HandleCancellation.php | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 6a9f400e69..ee12a25b99 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -298,7 +298,7 @@ class CheckData extends Command $invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance'); $credit_balance = $client->credits->where('is_deleted', false)->sum('balance'); - $invoice_balance -= $credit_balance; + // $invoice_balance -= $credit_balance;//doesn't make sense to remove the credit amount $ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first(); @@ -388,9 +388,9 @@ class CheckData extends Command foreach (Client::cursor()->where('is_deleted', 0) as $client) { //$invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance'); $invoice_balance = Invoice::where('client_id', $client->id)->where('is_deleted', false)->where('status_id', '>', 1)->withTrashed()->sum('balance'); - $client_balance = Credit::where('client_id', $client->id)->where('is_deleted', false)->withTrashed()->sum('balance'); + $credit_balance = Credit::where('client_id', $client->id)->where('is_deleted', false)->withTrashed()->sum('balance'); - $invoice_balance -= $client_balance; + // $invoice_balance -= $credit_balance; $ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first(); diff --git a/app/Services/Client/PaymentMethod.php b/app/Services/Client/PaymentMethod.php index a2b0c3c70c..e4ea317bac 100644 --- a/app/Services/Client/PaymentMethod.php +++ b/app/Services/Client/PaymentMethod.php @@ -136,11 +136,13 @@ class PaymentMethod foreach ($this->gateways as $gateway) { foreach ($gateway->driver($this->client)->gatewayTypes() as $type) { if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) { - if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $this->amount)) { + + if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $this->amount) && $gateway->fees_and_limits->{$type}->is_enabled) { $this->payment_methods[] = [$gateway->id => $type]; } + } else { - $this->payment_methods[] = [$gateway->id => $type]; + //$this->payment_methods[] = [$gateway->id => $type]; } } } diff --git a/app/Services/Invoice/HandleCancellation.php b/app/Services/Invoice/HandleCancellation.php index f7d5c83c74..6f7d71c488 100644 --- a/app/Services/Invoice/HandleCancellation.php +++ b/app/Services/Invoice/HandleCancellation.php @@ -57,8 +57,10 @@ class HandleCancellation extends AbstractService public function reverse() { + /* The stored cancelled object - contains the adjustment and status*/ $cancellation = $this->invoice->backup->cancellation; + /* Will turn the negative cancellation amount to a positive adjustment*/ $adjustment = $cancellation->adjustment * -1; $this->invoice->ledger()->updateInvoiceBalance($adjustment, 'Invoice cancellation REVERSAL'); From 05ea7f092a04b3af18537c15d65a9b338940dbcf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 21 Jan 2021 15:05:05 +1100 Subject: [PATCH 7/8] Fixes for ledger adjustments --- app/Http/Controllers/InvoiceController.php | 4 ++-- app/Repositories/PaymentRepository.php | 1 - app/Services/Invoice/HandleRestore.php | 5 +++-- app/Services/Invoice/MarkInvoiceDeleted.php | 25 +++++++++++++++------ app/Services/Ledger/LedgerService.php | 3 ++- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 1af1b10a01..9866f43133 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -687,8 +687,8 @@ class InvoiceController extends BaseController break; case 'delete': //need to make sure the invoice is cancelled first!! - //$invoice->service()->handleCancellation()->save(); - + //$invoice->service()->handleCancellation()s->save(); +nlog("inside delete"); $this->invoice_repo->delete($invoice); if (! $bulk) { diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 6ee7b715d6..25762ee7f5 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -64,7 +64,6 @@ class PaymentRepository extends BaseRepository */ private function applyPayment(array $data, Payment $payment): ?Payment { -nlog($data); $is_existing_payment = true; diff --git a/app/Services/Invoice/HandleRestore.php b/app/Services/Invoice/HandleRestore.php index ddee068ba1..fa346d3fb5 100644 --- a/app/Services/Invoice/HandleRestore.php +++ b/app/Services/Invoice/HandleRestore.php @@ -71,14 +71,15 @@ class HandleRestore extends AbstractService } //adjust ledger balance - $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance, 'Restored invoice {$this->invoice->number}')->save(); + $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance, "Restored invoice {$this->invoice->number}")->save(); //adjust paid to dates $this->invoice->client->service()->updatePaidToDate($this->payment_total)->save(); $this->invoice->client->service()->updateBalance($this->invoice->balance)->save(); - $this->invoice->ledger()->updatePaymentBalance($this->payment_total, 'Restored payment for invoice {$this->invoice->number}')->save(); + // you only need to touch the ledger ONCE per transaction. + // $this->invoice->ledger()->updatePaymentBalance($this->payment_total*-1, "Restored payment for invoice {$this->invoice->number}")->save(); $this->windBackInvoiceNumber(); diff --git a/app/Services/Invoice/MarkInvoiceDeleted.php b/app/Services/Invoice/MarkInvoiceDeleted.php index 34fa1d39d2..6b6e668feb 100644 --- a/app/Services/Invoice/MarkInvoiceDeleted.php +++ b/app/Services/Invoice/MarkInvoiceDeleted.php @@ -36,9 +36,6 @@ class MarkInvoiceDeleted extends AbstractService if ($this->invoice->is_deleted) { return $this->invoice; } - - // if(in_array($this->invoice->status_id, ['currencies', 'industries', 'languages', 'countries', 'banks'])) - // return $this-> $this->cleanup() ->setAdjustmentAmount() @@ -53,25 +50,26 @@ class MarkInvoiceDeleted extends AbstractService private function adjustLedger() { - $this->invoice->ledger()->updatePaymentBalance($this->adjustment_amount * -1); + $this->invoice->ledger()->updatePaymentBalance($this->adjustment_amount * -1, 'Invoice Deleted - reducing ledger balance'); //reduces the payment balance by payment totals return $this; } private function adjustPaidToDate() { - $this->invoice->client->service()->updatePaidToDate($this->adjustment_amount * -1)->save(); + $this->invoice->client->service()->updatePaidToDate($this->adjustment_amount * -1)->save(); //reduces the paid to date by the payment totals return $this; } private function adjustBalance() { - $this->invoice->client->service()->updateBalance($this->invoice->balance * -1)->save(); + $this->invoice->client->service()->updateBalance($this->invoice->balance * -1)->save(); //reduces the client balance by the invoice amount. return $this; } + /* Adjust the payment amounts */ private function adjustPayments() { //if total payments = adjustment amount - that means we need to delete the payments as well. @@ -79,6 +77,7 @@ class MarkInvoiceDeleted extends AbstractService if ($this->adjustment_amount == $this->total_payments) { $this->invoice->payments()->update(['payments.deleted_at' => now(), 'payments.is_deleted' => true]); } else { + //adjust payments down by the amount applied to the invoice payment. $this->invoice->payments->each(function ($payment) { @@ -96,6 +95,12 @@ class MarkInvoiceDeleted extends AbstractService return $this; } + /** + * Set the values of two variables + * + * $this->adjustment_amount - sum of the invoice paymentables + * $this->total_payments - sum of the invoice payments + */ private function setAdjustmentAmount() { foreach ($this->invoice->payments as $payment) { @@ -111,6 +116,12 @@ class MarkInvoiceDeleted extends AbstractService return $this; } + /* + * + * This sets the invoice number to _deleted + * and also removes the links to existing entities + * + */ private function cleanup() { $check = false; @@ -143,7 +154,7 @@ class MarkInvoiceDeleted extends AbstractService return $number; } - + /* Touches all paymentables as deleted */ private function deletePaymentables() { $this->invoice->payments->each(function ($payment) { diff --git a/app/Services/Ledger/LedgerService.php b/app/Services/Ledger/LedgerService.php index 53337b6838..4b0a096ae3 100644 --- a/app/Services/Ledger/LedgerService.php +++ b/app/Services/Ledger/LedgerService.php @@ -47,7 +47,7 @@ class LedgerService return $this; } - public function updatePaymentBalance($adjustment) + public function updatePaymentBalance($adjustment, $notes = '') { $balance = 0; @@ -63,6 +63,7 @@ class LedgerService $company_ledger->adjustment = $adjustment; $company_ledger->balance = $balance + $adjustment; $company_ledger->activity_id = Activity::UPDATE_PAYMENT; + $company_ledger->notes = $notes; $company_ledger->save(); $this->entity->company_ledger()->save($company_ledger); From c173fdcc5bcb99aacbf3a50e297fea28c8fb08bd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 21 Jan 2021 15:42:30 +1100 Subject: [PATCH 8/8] Fixes for ledger --- app/Jobs/Ninja/SendReminders.php | 2 +- app/PaymentDrivers/BaseDriver.php | 2 +- app/PaymentDrivers/BasePaymentDriver.php | 2 +- app/Repositories/BaseRepository.php | 2 +- app/Services/Invoice/AddGatewayFee.php | 8 -------- app/Services/Invoice/AutoBillInvoice.php | 6 +++--- app/Services/Invoice/HandleCancellation.php | 4 ++-- app/Services/Invoice/MarkSent.php | 2 +- app/Services/Payment/DeletePayment.php | 2 +- 9 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/Jobs/Ninja/SendReminders.php b/app/Jobs/Ninja/SendReminders.php index 278cbb9898..e2d58a1b86 100644 --- a/app/Jobs/Ninja/SendReminders.php +++ b/app/Jobs/Ninja/SendReminders.php @@ -308,7 +308,7 @@ class SendReminders implements ShouldQueue $invoice = $invoice->calc()->getInvoice(); $this->invoice->client->service()->updateBalance($this->invoice->balance - $temp_invoice_balance)->save(); - $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance - $temp_invoice_balance); + $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance - $temp_invoice_balance, "Late Fee Adjustment for invoice {$this->invoice->number}"); return $invoice; } diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 87c2f85aaa..4dfb178c79 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -264,7 +264,7 @@ class BaseDriver extends AbstractPaymentDriver if (collect($invoice->line_items)->contains('type_id', '3')) { $invoice->service()->toggleFeesPaid()->save(); $invoice->client->service()->updateBalance($fee_total)->save(); - $invoice->ledger()->updateInvoiceBalance($fee_total, $notes = 'Gateway fee adjustment'); + $invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}"); } }); } diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index bc63edfa00..8587018248 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -306,7 +306,7 @@ class BasePaymentDriver if (collect($invoice->line_items)->contains('type_id', '3')) { $invoice->service()->toggleFeesPaid()->save(); $invoice->client->service()->updateBalance($fee_total)->save(); - $invoice->ledger()->updateInvoiceBalance($fee_total, $notes = 'Gateway fee adjustment'); + $invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for Invoice {$invoice->number}"); } }); } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index b6fa2b9e66..b295419b3f 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -293,7 +293,7 @@ class BaseRepository if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) { - $model->ledger()->updateInvoiceBalance(($state['finished_amount'] - $state['starting_amount'])); + $model->ledger()->updateInvoiceBalance(($state['finished_amount'] - $state['starting_amount']), "Update adjustment for invoice {$model->number}"); $model->client->service()->updateBalance(($state['finished_amount'] - $state['starting_amount']))->save(); } diff --git a/app/Services/Invoice/AddGatewayFee.php b/app/Services/Invoice/AddGatewayFee.php index 4cadb94bd4..073375e7bd 100644 --- a/app/Services/Invoice/AddGatewayFee.php +++ b/app/Services/Invoice/AddGatewayFee.php @@ -93,10 +93,6 @@ class AddGatewayFee extends AbstractService /**Refresh Invoice values*/ $this->invoice = $this->invoice->calc()->getInvoice(); - /*Update client balance*/ // don't increment until we have process the payment! - //$this->invoice->client->service()->updateBalance($gateway_fee)->save(); - //$this->invoice->ledger()->updateInvoiceBalance($gateway_fee, $notes = 'Gateway fee adjustment'); - return $this->invoice; } @@ -122,10 +118,6 @@ class AddGatewayFee extends AbstractService $this->invoice = $this->invoice->calc()->getInvoice(); - // $this->invoice->client->service()->updateBalance($gateway_fee)->save(); - - // $this->invoice->ledger()->updateInvoiceBalance($gateway_fee, $notes = 'Discount fee adjustment'); - return $this->invoice; } } diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index e2b61215ec..b588c688c3 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -147,8 +147,8 @@ class AutoBillInvoice extends AbstractService ->save(); $this->invoice->ledger() - ->updateInvoiceBalance($amount * -1, 'Invoice payment using Credit') - ->updateCreditBalance($amount * -1, 'Credits used to pay down Invoice ' . $this->invoice->number) + ->updateInvoiceBalance($amount * -1, "Invoice {$this->invoice->number} payment using Credit {$current_credit->number}") + ->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}") ->save(); event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); @@ -325,7 +325,7 @@ class AutoBillInvoice extends AbstractService if ($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT) { $this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save(); - $this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, 'Invoice balance updated after stale gateway fee removed')->save(); + $this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, "Invoice {$this->invoice->number} balance updated after stale gateway fee removed")->save(); } return $this; diff --git a/app/Services/Invoice/HandleCancellation.php b/app/Services/Invoice/HandleCancellation.php index 6f7d71c488..d18c76e5a8 100644 --- a/app/Services/Invoice/HandleCancellation.php +++ b/app/Services/Invoice/HandleCancellation.php @@ -42,7 +42,7 @@ class HandleCancellation extends AbstractService $this->backupCancellation($adjustment); //set invoice balance to 0 - $this->invoice->ledger()->updateInvoiceBalance($adjustment, 'Invoice cancellation'); + $this->invoice->ledger()->updateInvoiceBalance($adjustment, "Invoice {$this->invoice->number} cancellation"); $this->invoice->balance = 0; $this->invoice = $this->invoice->service()->setStatus(Invoice::STATUS_CANCELLED)->save(); @@ -63,7 +63,7 @@ class HandleCancellation extends AbstractService /* Will turn the negative cancellation amount to a positive adjustment*/ $adjustment = $cancellation->adjustment * -1; - $this->invoice->ledger()->updateInvoiceBalance($adjustment, 'Invoice cancellation REVERSAL'); + $this->invoice->ledger()->updateInvoiceBalance($adjustment, "Invoice {$this->invoice->number} reversal"); /* Reverse the invoice status and balance */ $this->invoice->balance += $adjustment; diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 06830d753a..1767e61e94 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -51,7 +51,7 @@ class MarkSent extends AbstractService $this->client->service()->updateBalance($this->invoice->balance)->save(); - $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance); + $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance, "Invoice {$this->invoice->number} marked as sent."); event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars())); diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index 36bd08324b..3169c51a57 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -80,7 +80,7 @@ class DeletePayment if ($this->payment->invoices()->exists()) { $this->payment->invoices()->each(function ($paymentable_invoice) { $paymentable_invoice->service()->updateBalance($paymentable_invoice->pivot->amount)->save(); - $paymentable_invoice->ledger()->updateInvoiceBalance($paymentable_invoice->pivot->amount)->save(); + $paymentable_invoice->ledger()->updateInvoiceBalance($paymentable_invoice->pivot->amount, "Adjusting invoice {$paymentable_invoice->number} due to deletion of Payment {$this->payment->number}")->save(); $paymentable_invoice->client->service()->updateBalance($paymentable_invoice->pivot->amount)->save(); if ($paymentable_invoice->balance == $paymentable_invoice->amount) {