From adb705d7f018a4181c6f243e76fd4878461a4e54 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 20 Jul 2020 09:02:31 +1000 Subject: [PATCH] Adding Events --- app/Events/Credit/CreditWasDeleted.php | 41 +++++++++++ app/Events/Quote/QuoteWasViewed.php | 37 ++++++++++ .../Activity/CreatedQuoteActivity.php | 53 ++++++++++++++ .../Activity/DeleteCreditActivity.php | 54 ++++++++++++++ .../Activity/QuoteUpdatedActivity.php | 70 +++++++++++++++++++ app/Listeners/Quote/QuoteEmailActivity.php | 57 +++++++++++++++ app/Listeners/Quote/QuoteViewedActivity.php | 59 ++++++++++++++++ app/Models/Activity.php | 12 ++-- app/Providers/EventServiceProvider.php | 27 +++++++ 9 files changed, 404 insertions(+), 6 deletions(-) create mode 100644 app/Events/Credit/CreditWasDeleted.php create mode 100644 app/Events/Quote/QuoteWasViewed.php create mode 100644 app/Listeners/Activity/CreatedQuoteActivity.php create mode 100644 app/Listeners/Activity/DeleteCreditActivity.php create mode 100644 app/Listeners/Activity/QuoteUpdatedActivity.php create mode 100644 app/Listeners/Quote/QuoteEmailActivity.php create mode 100644 app/Listeners/Quote/QuoteViewedActivity.php diff --git a/app/Events/Credit/CreditWasDeleted.php b/app/Events/Credit/CreditWasDeleted.php new file mode 100644 index 0000000000..e081891a2c --- /dev/null +++ b/app/Events/Credit/CreditWasDeleted.php @@ -0,0 +1,41 @@ +credit = $credit; + $this->company = $company; + $this->event_vars = $event_vars; + } +} diff --git a/app/Events/Quote/QuoteWasViewed.php b/app/Events/Quote/QuoteWasViewed.php new file mode 100644 index 0000000000..10b68f7560 --- /dev/null +++ b/app/Events/Quote/QuoteWasViewed.php @@ -0,0 +1,37 @@ +invitation = $invitation; + $this->company = $company; + $this->event_vars = $event_vars; + } +} diff --git a/app/Listeners/Activity/CreatedQuoteActivity.php b/app/Listeners/Activity/CreatedQuoteActivity.php new file mode 100644 index 0000000000..5b6bd86d76 --- /dev/null +++ b/app/Listeners/Activity/CreatedQuoteActivity.php @@ -0,0 +1,53 @@ +activity_repo = $activity_repo; + } + + /** + * Handle the event. + * + * @param object $event + * @return void + */ + public function handle($event) + { + MultiDB::setDb($event->company->db); + + $fields = new \stdClass; + + $fields->quote_id = $event->quote->id; + $fields->user_id = $event->quote->user_id; + $fields->company_id = $event->quote->company_id; + $fields->activity_type_id = Activity::CREATE_QUOTE; + + $this->activity_repo->save($fields, $event->quote, $event->event_vars); + } +} diff --git a/app/Listeners/Activity/DeleteCreditActivity.php b/app/Listeners/Activity/DeleteCreditActivity.php new file mode 100644 index 0000000000..c24033921f --- /dev/null +++ b/app/Listeners/Activity/DeleteCreditActivity.php @@ -0,0 +1,54 @@ +activity_repo = $activity_repo; + } + + /** + * Handle the event. + * + * @param object $event + * @return void + */ + public function handle($event) + { + MultiDB::setDb($event->company->db); + + $fields = new \stdClass; + + $fields->client_id = $event->credit->client_id; + $fields->credit_id = $event->credit->id; + $fields->user_id = $event->credit->user_id; + $fields->company_id = $event->credit->company_id; + $fields->activity_type_id = Activity::DELETE_CREDIT; + + $this->activity_repo->save($fields, $event->credit, $event->event_vars); + } +} diff --git a/app/Listeners/Activity/QuoteUpdatedActivity.php b/app/Listeners/Activity/QuoteUpdatedActivity.php new file mode 100644 index 0000000000..9a8da15071 --- /dev/null +++ b/app/Listeners/Activity/QuoteUpdatedActivity.php @@ -0,0 +1,70 @@ +activity_repo = $activity_repo; + } + + /** + * Handle the event. + * + * @param object $event + * @return void + */ + public function handle($event) + { + MultiDB::setDb($event->company->db); + + $quote = $event->quote; + + $invoices = $payment->invoices; + + $fields = new \stdClass; + + $fields->payment_id = $quote->id; + $fields->user_id = $quote->user_id; + $fields->company_id = $quote->company_id; + $fields->activity_type_id = Activity::UPDATE_QUOTE; + + $this->activity_repo->save($fields, $quote, $event->event_vars); + + // foreach ($invoices as $invoice) { + // //todo we may need to add additional logic if in the future we apply payments to other entity Types, not just invoices + // $fields->invoice_id = $invoice->id; + + // $this->activity_repo->save($fields, $invoice, $event->event_vars); + // } + + // if (count($invoices) == 0) { + // $this->activity_repo->save($fields, $payment, $event->event_vars); + // } + } +} diff --git a/app/Listeners/Quote/QuoteEmailActivity.php b/app/Listeners/Quote/QuoteEmailActivity.php new file mode 100644 index 0000000000..dffcb72ce7 --- /dev/null +++ b/app/Listeners/Quote/QuoteEmailActivity.php @@ -0,0 +1,57 @@ +activity_repo = $activity_repo; + } + + /** + * Handle the event. + * + * @param object $event + * @return void + */ + public function handle($event) + { + MultiDB::setDb($event->company->db); + + $fields = new \stdClass; + + $fields->quote_id = $event->invitation->quote->id; + $fields->user_id = $event->invitation->quote->user_id; + $fields->company_id = $event->invitation->quote->company_id; + $fields->client_contact_id = $event->invitation->quote->client_contact_id; + $fields->activity_type_id = Activity::EMAIL_QUOTE; + + $this->activity_repo->save($fields, $event->invitation->quote, $event->event_vars); + } +} diff --git a/app/Listeners/Quote/QuoteViewedActivity.php b/app/Listeners/Quote/QuoteViewedActivity.php new file mode 100644 index 0000000000..a10c8e78fd --- /dev/null +++ b/app/Listeners/Quote/QuoteViewedActivity.php @@ -0,0 +1,59 @@ +activity_repo = $activity_repo; + } + + /** + * Handle the event. + * + * @param object $event + * @return void + */ + public function handle($event) + { + MultiDB::setDb($event->company->db); + + $fields = new \stdClass; + + $fields->user_id = $event->quote->user_id; + $fields->company_id = $event->quote->company_id; + $fields->activity_type_id = Activity::VIEW_QUOTE; + $fields->client_id = $event->invitation->client_id; + $fields->client_contact_id = $event->invitation->client_contact_id; + $fields->invitation_id = $event->invitation->id; + $fields->quote_id = $event->invitation->quote_id; + + $this->activity_repo->save($fields, $event->quote, $event->event_vars); + } +} diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 25b259d872..79432dabbc 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -30,12 +30,12 @@ class Activity extends StaticModel const DELETE_PAYMENT=13; // const CREATE_CREDIT=14; // const UPDATE_CREDIT=15; // - const ARCHIVE_CREDIT=16; - const DELETE_CREDIT=17; - const CREATE_QUOTE=18; - const UPDATE_QUOTE=19; - const EMAIL_QUOTE=20; - const VIEW_QUOTE=21; + const ARCHIVE_CREDIT=16; // + const DELETE_CREDIT=17; // + const CREATE_QUOTE=18; // + const UPDATE_QUOTE=19; // + const EMAIL_QUOTE=20; // + const VIEW_QUOTE=21; // const ARCHIVE_QUOTE=22; const DELETE_QUOTE=23; const RESTORE_QUOTE=24; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 8019d9409a..04e0be125e 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -23,6 +23,7 @@ use App\Events\Company\CompanyDocumentsDeleted; use App\Events\Contact\ContactLoggedIn; use App\Events\Credit\CreditWasArchived; use App\Events\Credit\CreditWasCreated; +use App\Events\Credit\CreditWasDeleted; use App\Events\Credit\CreditWasEmailedAndFailed; use App\Events\Credit\CreditWasMarkedSent; use App\Events\Credit\CreditWasUpdated; @@ -45,19 +46,26 @@ use App\Events\Payment\PaymentWasRefunded; use App\Events\Payment\PaymentWasUpdated; use App\Events\Payment\PaymentWasVoided; use App\Events\Quote\QuoteWasApproved; +use App\Events\Quote\QuoteWasCreated; +use App\Events\Quote\QuoteWasEmailed; +use App\Events\Quote\QuoteWasUpdated; +use App\Events\Quote\QuoteWasViewed; use App\Events\User\UserLoggedIn; use App\Events\User\UserWasCreated; use App\Events\User\UserWasDeleted; use App\Listeners\Activity\ArchivedClientActivity; use App\Listeners\Activity\CreatedClientActivity; use App\Listeners\Activity\CreatedCreditActivity; +use App\Listeners\Activity\CreatedQuoteActivity; use App\Listeners\Activity\CreditArchivedActivity; use App\Listeners\Activity\DeleteClientActivity; +use App\Listeners\Activity\DeleteCreditActivity; use App\Listeners\Activity\PaymentCreatedActivity; use App\Listeners\Activity\PaymentDeletedActivity; use App\Listeners\Activity\PaymentRefundedActivity; use App\Listeners\Activity\PaymentUpdatedActivity; use App\Listeners\Activity\PaymentVoidedActivity; +use App\Listeners\Activity\QuoteUpdatedActivity; use App\Listeners\Activity\RestoreClientActivity; use App\Listeners\Activity\UpdatedCreditActivity; use App\Listeners\Contact\UpdateContactLastLogin; @@ -72,10 +80,13 @@ use App\Listeners\Invoice\InvoiceEmailActivity; use App\Listeners\Invoice\InvoiceEmailFailedActivity; use App\Listeners\Invoice\InvoiceEmailedNotification; use App\Listeners\Invoice\InvoiceViewedActivity; +use App\Listeners\Invoice\QuoteEmailActivity; use App\Listeners\Invoice\UpdateInvoiceActivity; use App\Listeners\Invoice\UpdateInvoiceInvitations; use App\Listeners\Misc\InvitationViewedListener; use App\Listeners\Payment\PaymentNotification; +use App\Listeners\Quote\QuoteEmailActivity; +use App\Listeners\Quote\QuoteViewedActivity; use App\Listeners\Quote\ReachWorkflowSettings; use App\Listeners\SendVerificationNotification; use App\Listeners\SetDBListener; @@ -151,6 +162,9 @@ class EventServiceProvider extends ServiceProvider CreditWasCreated::class => [ CreatedCreditActivity::class, ], + CreditWasDeleted::class => [ + DeleteCreditActivity::class, + ], CreditWasUpdated::class => [ UpdatedCreditActivity::class, ], @@ -216,6 +230,19 @@ class EventServiceProvider extends ServiceProvider QuoteWasApproved::class => [ ReachWorkflowSettings::class, ], + QuoteWasCreated::class => [ + CreatedQuoteActivity::class, + ], + QuoteWasUpdated::class => [ + QuoteUpdatedActivity::class, + ], + QuoteWasEmailed::class => [ + QuoteEmailActivity::class, + ], + QuoteWasViewed::class => [ + QuoteViewedActivity::class, + ], + ]; /**