Add Payment Emailed Activity

This commit is contained in:
David Bomba 2023-03-17 17:36:49 +11:00
parent 4add5be307
commit 200bcd80b7
5 changed files with 30 additions and 7 deletions

View File

@ -11,33 +11,47 @@
namespace App\Listeners\Payment; namespace App\Listeners\Payment;
use App\Models\Activity;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Utils\Traits\Notifications\UserNotifies; use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use App\Utils\Traits\Notifications\UserNotifies;
class PaymentEmailedActivity implements ShouldQueue class PaymentEmailedActivity implements ShouldQueue
{ {
use UserNotifies; protected $activity_repo;
/** /**
* Create the event listener. * 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. * Handle the event.
* *
* @param object $event * @param object $event
* @return bool
*/ */
public function handle($event) public function handle($event)
{ {
MultiDB::setDb($event->company->db); 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);
} }
} }

View File

@ -284,6 +284,8 @@ class Activity extends StaticModel
const ACCEPT_PURCHASE_ORDER = 137; const ACCEPT_PURCHASE_ORDER = 137;
const PAYMENT_EMAILED = 138;
protected $casts = [ protected $casts = [
'is_system' => 'boolean', 'is_system' => 'boolean',
'updated_at' => 'timestamp', 'updated_at' => 'timestamp',

View File

@ -171,6 +171,7 @@ use App\Listeners\Activity\VendorUpdatedActivity;
use App\Listeners\Contact\UpdateContactLastLogin; use App\Listeners\Contact\UpdateContactLastLogin;
use App\Listeners\Invoice\InvoiceDeletedActivity; use App\Listeners\Invoice\InvoiceDeletedActivity;
use App\Listeners\Payment\PaymentBalanceActivity; use App\Listeners\Payment\PaymentBalanceActivity;
use App\Listeners\Payment\PaymentEmailedActivity;
use App\Listeners\Quote\QuoteCreatedNotification; use App\Listeners\Quote\QuoteCreatedNotification;
use App\Listeners\Quote\QuoteEmailedNotification; use App\Listeners\Quote\QuoteEmailedNotification;
use App\Events\Invoice\InvoiceWasEmailedAndFailed; use App\Events\Invoice\InvoiceWasEmailedAndFailed;
@ -454,7 +455,7 @@ class EventServiceProvider extends ServiceProvider
InvitationViewedListener::class, InvitationViewedListener::class,
], ],
PaymentWasEmailed::class => [ PaymentWasEmailed::class => [
// PaymentEmailedActivity::class, PaymentEmailedActivity::class,
], ],
PaymentWasEmailedAndFailed::class => [ PaymentWasEmailedAndFailed::class => [
// PaymentEmailFailureActivity::class, // PaymentEmailFailureActivity::class,

View File

@ -11,9 +11,11 @@
namespace App\Services\Payment; namespace App\Services\Payment;
use App\Utils\Ninja;
use App\Models\Payment; use App\Models\Payment;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Jobs\Payment\EmailPayment; use App\Jobs\Payment\EmailPayment;
use App\Events\Payment\PaymentWasEmailed;
class SendEmail class SendEmail
{ {
@ -36,6 +38,8 @@ class SendEmail
// $invoice->invitations->each(function ($invitation) { // $invoice->invitations->each(function ($invitation) {
// if (!$invitation->contact->trashed() && $invitation->contact->email) { // if (!$invitation->contact->trashed() && $invitation->contact->email) {
EmailPayment::dispatch($this->payment, $this->payment->company, $this->contact); 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)));
// } // }
// }); // });
// }); // });

View File

@ -5024,6 +5024,8 @@ $LANG = array(
'number_of_payments' => 'Number of payments', 'number_of_payments' => 'Number of payments',
'number_of_payments_helper' => 'The number of times this payment will be made', 'number_of_payments_helper' => 'The number of times this payment will be made',
'pre_payment_indefinitely' => 'Continue until cancelled', 'pre_payment_indefinitely' => 'Continue until cancelled',
'notification_payment_emailed' => 'Payment :payment was emailed to :client',
'notification_payment_emailed_subject' => 'Payment :payment was emailed',
); );