From 200bcd80b7a884fa948e6776bb82cb1aacdbde26 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Mar 2023 17:36:49 +1100 Subject: [PATCH] Add Payment Emailed Activity --- .../Payment/PaymentEmailedActivity.php | 26 ++++++++++++++----- app/Models/Activity.php | 2 ++ app/Providers/EventServiceProvider.php | 3 ++- app/Services/Payment/SendEmail.php | 4 +++ lang/en/texts.php | 2 ++ 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/Listeners/Payment/PaymentEmailedActivity.php b/app/Listeners/Payment/PaymentEmailedActivity.php index af6701c4d4..5fcf3e765a 100644 --- a/app/Listeners/Payment/PaymentEmailedActivity.php +++ b/app/Listeners/Payment/PaymentEmailedActivity.php @@ -11,33 +11,47 @@ namespace App\Listeners\Payment; +use App\Models\Activity; use App\Libraries\MultiDB; -use App\Utils\Traits\Notifications\UserNotifies; +use App\Repositories\ActivityRepository; use Illuminate\Contracts\Queue\ShouldQueue; +use App\Utils\Traits\Notifications\UserNotifies; class PaymentEmailedActivity implements ShouldQueue { - use UserNotifies; + protected $activity_repo; /** * Create the event listener. * - * @return void + * @param ActivityRepository $activity_repo */ - public function __construct() + public function __construct(ActivityRepository $activity_repo) { + $this->activity_repo = $activity_repo; } /** * Handle the event. * * @param object $event - * @return bool */ public function handle($event) { MultiDB::setDb($event->company->db); - $payment = $event->payment; + + $fields = new \stdClass(); + + $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->payment->user_id; + + $fields->user_id = $user_id; + $fields->client_id = $event->payment->client_id; + $fields->company_id = $event->payment->company_id; + $fields->activity_type_id = Activity::PAYMENT_EMAILED; + $fields->payment_id = $event->payment->id; + + $this->activity_repo->save($fields, $event->payment, $event->event_vars); + } } diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 3d84f724cb..d25a3333ec 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -284,6 +284,8 @@ class Activity extends StaticModel const ACCEPT_PURCHASE_ORDER = 137; + const PAYMENT_EMAILED = 138; + protected $casts = [ 'is_system' => 'boolean', 'updated_at' => 'timestamp', diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index a672bafc96..ae34c09620 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -171,6 +171,7 @@ use App\Listeners\Activity\VendorUpdatedActivity; use App\Listeners\Contact\UpdateContactLastLogin; use App\Listeners\Invoice\InvoiceDeletedActivity; use App\Listeners\Payment\PaymentBalanceActivity; +use App\Listeners\Payment\PaymentEmailedActivity; use App\Listeners\Quote\QuoteCreatedNotification; use App\Listeners\Quote\QuoteEmailedNotification; use App\Events\Invoice\InvoiceWasEmailedAndFailed; @@ -454,7 +455,7 @@ class EventServiceProvider extends ServiceProvider InvitationViewedListener::class, ], PaymentWasEmailed::class => [ - // PaymentEmailedActivity::class, + PaymentEmailedActivity::class, ], PaymentWasEmailedAndFailed::class => [ // PaymentEmailFailureActivity::class, diff --git a/app/Services/Payment/SendEmail.php b/app/Services/Payment/SendEmail.php index d967fd9ed3..a16e6ea926 100644 --- a/app/Services/Payment/SendEmail.php +++ b/app/Services/Payment/SendEmail.php @@ -11,9 +11,11 @@ namespace App\Services\Payment; +use App\Utils\Ninja; use App\Models\Payment; use App\Models\ClientContact; use App\Jobs\Payment\EmailPayment; +use App\Events\Payment\PaymentWasEmailed; class SendEmail { @@ -36,6 +38,8 @@ class SendEmail // $invoice->invitations->each(function ($invitation) { // if (!$invitation->contact->trashed() && $invitation->contact->email) { EmailPayment::dispatch($this->payment, $this->payment->company, $this->contact); + + event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); // } // }); // }); diff --git a/lang/en/texts.php b/lang/en/texts.php index a76a4df9b1..9cf72a3d8c 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5024,6 +5024,8 @@ $LANG = array( 'number_of_payments' => 'Number of payments', 'number_of_payments_helper' => 'The number of times this payment will be made', 'pre_payment_indefinitely' => 'Continue until cancelled', + 'notification_payment_emailed' => 'Payment :payment was emailed to :client', + 'notification_payment_emailed_subject' => 'Payment :payment was emailed', );