From 4777586dbe21eb53cfe8383479721338d972c48b Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 26 Dec 2017 16:35:31 +0200 Subject: [PATCH] Add more subscription types --- app/Constants.php | 11 ++ app/Events/ClientWasCreated.php | 1 + app/Listeners/SubscriptionListener.php | 160 +++++++++++++++--- app/Providers/EventServiceProvider.php | 22 +++ resources/lang/en/texts.php | 11 ++ .../views/accounts/subscription.blade.php | 20 ++- 6 files changed, 197 insertions(+), 28 deletions(-) diff --git a/app/Constants.php b/app/Constants.php index 509fed2cd59a..da5228033fff 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -307,6 +307,17 @@ if (! defined('APP_NAME')) { define('EVENT_DELETE_QUOTE', 7); define('EVENT_UPDATE_INVOICE', 8); define('EVENT_DELETE_INVOICE', 9); + define('EVENT_UPDATE_CLIENT', 10); + define('EVENT_DELETE_CLIENT', 11); + define('EVENT_DELETE_PAYMENT', 12); + define('EVENT_UPDATE_VENDOR', 13); + define('EVENT_DELETE_VENDOR', 14); + define('EVENT_CREATE_EXPENSE', 15); + define('EVENT_UPDATE_EXPENSE', 16); + define('EVENT_DELETE_EXPENSE', 17); + define('EVENT_CREATE_TASK', 18); + define('EVENT_UPDATE_TASK', 19); + define('EVENT_DELETE_TASK', 20); define('REQUESTED_PRO_PLAN', 'REQUESTED_PRO_PLAN'); define('NINJA_ACCOUNT_KEY', env('NINJA_ACCOUNT_KEY', 'zg4ylmzDkdkPOT8yoKQw9LTWaoZJx79h')); diff --git a/app/Events/ClientWasCreated.php b/app/Events/ClientWasCreated.php index 1fa399469daa..8a4c9fc1a66a 100644 --- a/app/Events/ClientWasCreated.php +++ b/app/Events/ClientWasCreated.php @@ -1,3 +1,4 @@ + checkSubscriptions(EVENT_CREATE_CLIENT, $event->client, $transformer); } + /** + * @param ClientWasUpdated $event + */ + public function updatedClient(ClientWasUpdated $event) + { + $transformer = new ClientTransformer($event->client->account); + $this->checkSubscriptions(EVENT_UPDATE_CLIENT, $event->client, $transformer); + } + + /** + * @param ClientWasDeleted $event + */ + public function deletedClient(ClientWasDeleted $event) + { + $transformer = new ClientTransformer($event->client->account); + $this->checkSubscriptions(EVENT_DELETE_CLIENT, $event->client, $transformer); + } + + /** * @param PaymentWasCreated $event */ @@ -46,25 +77,14 @@ class SubscriptionListener } /** - * @param CreditWasCreated $event + * @param PaymentWasDeleted $event */ - public function createdCredit(CreditWasCreated $event) + public function deletedPayment(PaymentWasDeleted $event) { + $transformer = new PaymentTransformer($event->payment->account); + $this->checkSubscriptions(EVENT_DELETE_PAYMENT, $event->payment, $transformer, [ENTITY_CLIENT, ENTITY_INVOICE]); } - /** - * @param VendorWasCreated $event - */ - public function createdVendor(VendorWasCreated $event) - { - } - - /** - * @param ExpenseWasCreated $event - */ - public function createdExpense(ExpenseWasCreated $event) - { - } /** * @param InvoiceWasCreated $event @@ -84,6 +104,16 @@ class SubscriptionListener $this->checkSubscriptions(EVENT_UPDATE_INVOICE, $event->invoice, $transformer, ENTITY_CLIENT); } + /** + * @param InvoiceWasDeleted $event + */ + public function deletedInvoice(InvoiceWasDeleted $event) + { + $transformer = new InvoiceTransformer($event->invoice->account); + $this->checkSubscriptions(EVENT_DELETE_INVOICE, $event->invoice, $transformer, ENTITY_CLIENT); + } + + /** * @param QuoteWasCreated $event */ @@ -102,15 +132,6 @@ class SubscriptionListener $this->checkSubscriptions(EVENT_UPDATE_QUOTE, $event->quote, $transformer, ENTITY_CLIENT); } - /** - * @param InvoiceWasDeleted $event - */ - public function deletedInvoice(InvoiceWasDeleted $event) - { - $transformer = new InvoiceTransformer($event->invoice->account); - $this->checkSubscriptions(EVENT_DELETE_INVOICE, $event->invoice, $transformer, ENTITY_CLIENT); - } - /** * @param InvoiceWasDeleted $event */ @@ -120,6 +141,91 @@ class SubscriptionListener $this->checkSubscriptions(EVENT_DELETE_QUOTE, $event->quote, $transformer, ENTITY_CLIENT); } + + /** + * @param VendorWasCreated $event + */ + public function createdVendor(VendorWasCreated $event) + { + $transformer = new VendorTransformer($event->vendor->account); + $this->checkSubscriptions(EVENT_CREATE_VENDOR, $event->vendor, $transformer); + } + + /** + * @param VendorWasUpdated $event + */ + public function updatedVendor(VendorWasUpdated $event) + { + $transformer = new VendorTransformer($event->vendor->account); + $this->checkSubscriptions(EVENT_UPDATE_VENDOR, $event->vendor, $transformer); + } + + /** + * @param VendorWasDeleted $event + */ + public function deletedVendor(VendorWasDeleted $event) + { + $transformer = new VendorTransformer($event->vendor->account); + $this->checkSubscriptions(EVENT_DELETE_VENDOR, $event->vendor, $transformer); + } + + + /** + * @param ExpenseWasCreated $event + */ + public function createdExpense(ExpenseWasCreated $event) + { + $transformer = new ExpenseTransformer($event->expense->account); + $this->checkSubscriptions(EVENT_CREATE_EXPENSE, $event->expense, $transformer); + } + + /** + * @param ExpenseWasUpdated $event + */ + public function updatedExpense(ExpenseWasUpdated $event) + { + $transformer = new ExpenseTransformer($event->expense->account); + $this->checkSubscriptions(EVENT_UPDATE_EXPENSE, $event->expense, $transformer); + } + + /** + * @param ExpenseWasDeleted $event + */ + public function deletedExpense(ExpenseWasDeleted $event) + { + $transformer = new ExpenseTransformer($event->expense->account); + $this->checkSubscriptions(EVENT_DELETE_EXPENSE, $event->expense, $transformer); + } + + + /** + * @param TaskWasCreated $event + */ + public function createdTask(TaskWasCreated $event) + { + $transformer = new TaskTransformer($event->task->account); + $this->checkSubscriptions(EVENT_CREATE_TASK, $event->task, $transformer); + } + + /** + * @param TaskWasUpdated $event + */ + public function updatedTask(TaskWasUpdated $event) + { + $transformer = new TaskTransformer($event->task->account); + $this->checkSubscriptions(EVENT_UPDATE_TAK, $event->task, $transformer); + } + + /** + * @param TaskWasDeleted $event + */ + public function deletedTask(TaskWasDeleted $event) + { + $transformer = new TaskTransformer($event->task->account); + $this->checkSubscriptions(EVENT_DELETE_TASK, $event->task, $transformer); + } + + /** * @param $eventId * @param $entity diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 87d520bcea6b..2dd0210492f0 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -21,8 +21,12 @@ class EventServiceProvider extends ServiceProvider 'App\Events\ClientWasArchived' => [ 'App\Listeners\ActivityListener@archivedClient', ], + 'App\Events\ClientWasUpdated' => [ + 'App\Listeners\SubscriptionListener@updatedClient', + ], 'App\Events\ClientWasDeleted' => [ 'App\Listeners\ActivityListener@deletedClient', + 'App\Listeners\SubscriptionListener@deletedClient', ], 'App\Events\ClientWasRestored' => [ 'App\Listeners\ActivityListener@restoredClient', @@ -121,6 +125,7 @@ class EventServiceProvider extends ServiceProvider 'App\Listeners\ActivityListener@deletedPayment', 'App\Listeners\InvoiceListener@deletedPayment', 'App\Listeners\CreditListener@deletedPayment', + 'App\Listeners\SubscriptionListener@deletedPayment', ], 'App\Events\PaymentWasRefunded' => [ 'App\Listeners\ActivityListener@refundedPayment', @@ -168,9 +173,11 @@ class EventServiceProvider extends ServiceProvider // Task events 'App\Events\TaskWasCreated' => [ 'App\Listeners\ActivityListener@createdTask', + 'App\Listeners\SubscriptionListener@createdTask', ], 'App\Events\TaskWasUpdated' => [ 'App\Listeners\ActivityListener@updatedTask', + 'App\Listeners\SubscriptionListener@updatedTask', ], 'App\Events\TaskWasRestored' => [ 'App\Listeners\ActivityListener@restoredTask', @@ -180,14 +187,28 @@ class EventServiceProvider extends ServiceProvider ], 'App\Events\TaskWasDeleted' => [ 'App\Listeners\ActivityListener@deletedTask', + 'App\Listeners\SubscriptionListener@deletedTask', + ], + + // Vendor events + 'App\Events\VendorWasCreated' => [ + 'App\Listeners\SubscriptionListener@createdVendor', + ], + 'App\Events\VendorWasUpdated' => [ + 'App\Listeners\SubscriptionListener@updatedVendor', + ], + 'App\Events\VendorWasDeleted' => [ + 'App\Listeners\SubscriptionListener@deletedVendor', ], // Expense events 'App\Events\ExpenseWasCreated' => [ 'App\Listeners\ActivityListener@createdExpense', + 'App\Listeners\SubscriptionListener@createdExpense', ], 'App\Events\ExpenseWasUpdated' => [ 'App\Listeners\ActivityListener@updatedExpense', + 'App\Listeners\SubscriptionListener@updatedExpense', ], 'App\Events\ExpenseWasRestored' => [ 'App\Listeners\ActivityListener@restoredExpense', @@ -197,6 +218,7 @@ class EventServiceProvider extends ServiceProvider ], 'App\Events\ExpenseWasDeleted' => [ 'App\Listeners\ActivityListener@deletedExpense', + 'App\Listeners\SubscriptionListener@deletedExpense', ], 'Illuminate\Queue\Events\JobExceptionOccurred' => [ diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index f034faf799fd..6c2bb5054216 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2581,6 +2581,17 @@ $LANG = array( 'subscription_event_7' => 'Deleted Quote', 'subscription_event_8' => 'Updated Invoice', 'subscription_event_9' => 'Deleted Invoice', + 'subscription_event_10' => 'Updated Client', + 'subscription_event_11' => 'Deleted Client', + 'subscription_event_12' => 'Deleted Payment', + 'subscription_event_13' => 'Updated Vendor', + 'subscription_event_14' => 'Deleted Vendor', + 'subscription_event_15' => 'Created Expense', + 'subscription_event_16' => 'Updated Expense', + 'subscription_event_17' => 'Deleted Expense', + 'subscription_event_18' => 'Created Task', + 'subscription_event_19' => 'Updated Task', + 'subscription_event_20' => 'Deleted Task', 'subscriptions' => 'Subscriptions', 'updated_subscription' => 'Successfully updated subscription', 'created_subscription' => 'Successfully created subscription', diff --git a/resources/views/accounts/subscription.blade.php b/resources/views/accounts/subscription.blade.php index 856f14c665cb..1d9586958ff5 100644 --- a/resources/views/accounts/subscription.blade.php +++ b/resources/views/accounts/subscription.blade.php @@ -23,6 +23,8 @@ ->options([ trans('texts.clients') => [ EVENT_CREATE_CLIENT => trans('texts.subscription_event_' . EVENT_CREATE_CLIENT), + EVENT_UPDATE_CLIENT => trans('texts.subscription_event_' . EVENT_UPDATE_CLIENT), + EVENT_DELETE_CLIENT => trans('texts.subscription_event_' . EVENT_DELETE_CLIENT), ], trans('texts.invoices') => [ EVENT_CREATE_INVOICE => trans('texts.subscription_event_' . EVENT_CREATE_INVOICE), @@ -31,12 +33,28 @@ ], trans('texts.payments') => [ EVENT_CREATE_PAYMENT => trans('texts.subscription_event_' . EVENT_CREATE_PAYMENT), + EVENT_DELETE_PAYMENT => trans('texts.subscription_event_' . EVENT_DELETE_PAYMENT), ], trans('texts.quotes') => [ EVENT_CREATE_QUOTE => trans('texts.subscription_event_' . EVENT_CREATE_QUOTE), EVENT_UPDATE_QUOTE => trans('texts.subscription_event_' . EVENT_UPDATE_QUOTE), EVENT_DELETE_QUOTE => trans('texts.subscription_event_' . EVENT_DELETE_QUOTE), - ] + ], + trans('texts.tasks') => [ + EVENT_CREATE_TASK => trans('texts.subscription_event_' . EVENT_CREATE_TASK), + EVENT_UPDATE_TASK => trans('texts.subscription_event_' . EVENT_UPDATE_TASK), + EVENT_DELETE_TASK => trans('texts.subscription_event_' . EVENT_DELETE_TASK), + ], + trans('texts.vendors') => [ + EVENT_CREATE_VENDOR => trans('texts.subscription_event_' . EVENT_CREATE_VENDOR), + EVENT_UPDATE_VENDOR => trans('texts.subscription_event_' . EVENT_UPDATE_VENDOR), + EVENT_DELETE_VENDOR => trans('texts.subscription_event_' . EVENT_DELETE_VENDOR), + ], + trans('texts.expenses') => [ + EVENT_CREATE_EXPENSE => trans('texts.subscription_event_' . EVENT_CREATE_EXPENSE), + EVENT_UPDATE_EXPENSE => trans('texts.subscription_event_' . EVENT_UPDATE_EXPENSE), + EVENT_DELETE_EXPENSE => trans('texts.subscription_event_' . EVENT_DELETE_EXPENSE), + ], ]) ->label('event') !!}