From 8e06644fac56590ca95fedf380eb149545d087f6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 25 Jan 2021 07:55:04 +1100 Subject: [PATCH] Track payment ID with Activity 54 --- app/Events/Invoice/InvoiceWasPaid.php | 6 +++++- app/Listeners/Invoice/InvoicePaidActivity.php | 3 ++- app/PaymentDrivers/BaseDriver.php | 2 +- app/Services/Credit/ApplyPayment.php | 2 +- app/Services/Invoice/MarkPaid.php | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Events/Invoice/InvoiceWasPaid.php b/app/Events/Invoice/InvoiceWasPaid.php index 4aa412813160..95a6d23556b2 100644 --- a/app/Events/Invoice/InvoiceWasPaid.php +++ b/app/Events/Invoice/InvoiceWasPaid.php @@ -13,6 +13,7 @@ namespace App\Events\Invoice; use App\Models\Company; use App\Models\Invoice; +use App\Models\Payment; use Illuminate\Queue\SerializesModels; /** @@ -27,6 +28,8 @@ class InvoiceWasPaid */ public $invoice; + public $payment; + public $company; public $event_vars; @@ -38,9 +41,10 @@ class InvoiceWasPaid * @param Company $company * @param array $event_vars */ - public function __construct(Invoice $invoice, Company $company, array $event_vars) + public function __construct(Invoice $invoice, Payment $payment, Company $company, array $event_vars) { $this->invoice = $invoice; + $this->payment = $payment; $this->company = $company; $this->event_vars = $event_vars; } diff --git a/app/Listeners/Invoice/InvoicePaidActivity.php b/app/Listeners/Invoice/InvoicePaidActivity.php index 5a6e5cc7e1d5..98dcf939c19f 100644 --- a/app/Listeners/Invoice/InvoicePaidActivity.php +++ b/app/Listeners/Invoice/InvoicePaidActivity.php @@ -47,7 +47,8 @@ class InvoicePaidActivity implements ShouldQueue $fields->user_id = $event->invoice->user_id; $fields->company_id = $event->invoice->company_id; $fields->activity_type_id = Activity::PAID_INVOICE; - + $fields->payment_id = $event->payment->id; + $this->activity_repo->save($fields, $event->invoice, $event->event_vars); try { diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 4dfb178c798d..a8e5b6e6f343 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -187,7 +187,7 @@ class BaseDriver extends AbstractPaymentDriver $payment->invoices()->sync($invoices); $invoices->each(function ($invoice) use ($payment) { - event(new InvoiceWasPaid($invoice, $payment->company, Ninja::eventVars())); + event(new InvoiceWasPaid($invoice, $payment, $payment->company, Ninja::eventVars())); }); return $payment->service()->applyNumber()->save(); diff --git a/app/Services/Credit/ApplyPayment.php b/app/Services/Credit/ApplyPayment.php index c69dcf1b8589..e97e38c3854b 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -148,7 +148,7 @@ class ApplyPayment if ((int)$this->invoice->balance == 0) { $this->invoice->service()->deletePdf(); - event(new InvoiceWasPaid($this->invoice, $this->payment->company, Ninja::eventVars())); + event(new InvoiceWasPaid($this->invoice, $payment, $this->payment->company, Ninja::eventVars())); } } } diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 285287b67ea5..55c7e18016b8 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -80,7 +80,7 @@ class MarkPaid extends AbstractService /* Update Invoice balance */ event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); - event(new InvoiceWasPaid($this->invoice, $payment->company, Ninja::eventVars())); + event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars())); $payment->ledger() ->updatePaymentBalance($payment->amount * -1);