diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index c22a55717198..f608881e3ff7 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -549,8 +549,6 @@ class CreateTestData extends Command $credit->service()->markSent()->save(); $credit->service()->createInvitations(); - event(new CreateCreditInvitation($credit)); - } private function createQuote($client) @@ -561,9 +559,11 @@ class CreateTestData extends Command // } $faker = \Faker\Factory::create(); + //$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id $quote =factory(\App\Models\Quote::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]); $quote->date = $faker->date(); - + $quote->client_id = $client->id; + $quote->setRelation('client', $client); $quote->line_items = $this->buildLineItems(rand(1,10)); @@ -596,7 +596,6 @@ class CreateTestData extends Command $quote->service()->markSent()->save(); $quote->service()->createInvitations(); - CreateQuoteInvitations::dispatch($quote, $quote->company); } private function buildLineItems($count = 1) diff --git a/app/Listeners/Misc/InvitationViewedListener.php b/app/Listeners/Misc/InvitationViewedListener.php index aed6d113ce9d..749cb7cffc9c 100644 --- a/app/Listeners/Misc/InvitationViewedListener.php +++ b/app/Listeners/Misc/InvitationViewedListener.php @@ -40,16 +40,58 @@ class InvitationViewedListener implements ShouldQueue foreach($invitation->company->company_users as $company_user) { + $notifiable_methods = []; + + $notifications = $company_user->notifications; + + $entity_viewed = "{$entity_name}_viewed"; + + /*** Check for Mail notifications***/ + $all_user_notifications = ''; + + if($event->entity->user_id == $company_user->user_id || $event->entity->assigned_user_id == $company_user->user_id) + $all_user_notifications = "all_user_notifications"; + + $possible_permissions = [$entity_viewed, "all_notifications", $all_user_notifications]; + + $permission_count = array_intersect($possible_permissions, $notifications->email); + + if(count($permission_count) >=1) + array_push($notifiable_methods, 'mail'); + /*** Check for Mail notifications***/ + + + /*** Check for Slack notifications***/ + //@TODO when hillel implements this we can uncomment this. + // $permission_count = array_intersect($possible_permissions, $notifications->slack); + // if(count($permission_count) >=1) + // array_push($notifiable_methods, 'slack'); + + /*** Check for Slack notifications***/ + + $notification->method = $notifiable_methods; + $company_user->user->notify($notification); } if(isset($invitation->company->slack_webhook_url)){ - $notification->is_system = true; + $notification->method = ['slack']; Notification::route('slack', $invitation->company->slack_webhook_url) ->notify($notification); } } + + + + private function userNotificationArray($notifications) + { + $via_array = []; + + if(stripos($this->company_user->permissions, ) !== false); + + } + } diff --git a/app/Models/CompanyUser.php b/app/Models/CompanyUser.php index 532238d952b3..79e2466c2a12 100644 --- a/app/Models/CompanyUser.php +++ b/app/Models/CompanyUser.php @@ -35,7 +35,7 @@ class CompanyUser extends Pivot 'deleted_at' => 'timestamp', 'settings' => 'object', 'notifications' => 'object', - 'permissions' => 'object', + 'permissions' => 'string', ]; protected $fillable = [ diff --git a/app/Models/User.php b/app/Models/User.php index 94c43c2fc79c..3f33928b6429 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -301,8 +301,8 @@ class User extends Authenticatable implements MustVerifyEmail public function routeNotificationForSlack($notification) { - if($this->company()) - return $this->company()->slack_webhook_url; + if($this->company_user->slack_webhook_url) + return $this->company_user->slack_webhook_url; } diff --git a/app/Notifications/Admin/EntityViewedNotification.php b/app/Notifications/Admin/EntityViewedNotification.php index b1db215fe9bd..2387b31b7969 100644 --- a/app/Notifications/Admin/EntityViewedNotification.php +++ b/app/Notifications/Admin/EntityViewedNotification.php @@ -30,7 +30,7 @@ class EntityViewedNotification extends Notification implements ShouldQueue protected $settings; - public $is_system; + public $method; protected $contact; @@ -55,7 +55,8 @@ class EntityViewedNotification extends Notification implements ShouldQueue public function via($notifiable) { - return $this->is_system ? ['slack'] : ['mail']; + return $this->method; + } /** diff --git a/app/Services/Notification/NotificationService.php b/app/Services/Notification/NotificationService.php index fb3a3ced7d95..b7c080ac0e86 100644 --- a/app/Services/Notification/NotificationService.php +++ b/app/Services/Notification/NotificationService.php @@ -19,6 +19,28 @@ use Illuminate\Support\Facades\Notification; class NotificationService extends AbstractService { + const ALL = 'all_notifications'; + + const ALL_USER = 'all_user_notifications'; + + const PAYMENT_SUCCESS = 'payment_success'; + + const PAYMENT_FAILURE = 'payment_failure'; + + const INVOICE_SENT = 'invoice_sent'; + + const QUOTE_SENT = 'quote_sent'; + + const CREDIT_SENT = 'credit_sent'; + + const QUOTE_VIEWED = 'quote_viewed'; + + const INVOICE_VIEWED = 'invoice_viewed'; + + const CREDIT_VIEWED = 'credit_viewed'; + + const QUOTE_APPROVED = 'quote_approved'; + public $company; public $notification; diff --git a/app/Services/Quote/MarkSent.php b/app/Services/Quote/MarkSent.php index de21e3e3c252..7a3e4efa7093 100644 --- a/app/Services/Quote/MarkSent.php +++ b/app/Services/Quote/MarkSent.php @@ -9,26 +9,29 @@ class MarkSent { private $client; - public function __construct($client) + private $quote; + + public function __construct($client, $quote) { $this->client = $client; + $this->quote = $quote; } - public function run($quote) + public function run() { /* Return immediately if status is not draft */ - if ($quote->status_id != Quote::STATUS_DRAFT) { + if ($this->quote->status_id != Quote::STATUS_DRAFT) { return $quote; } - $quote->markInvitationsSent(); + $this->quote->markInvitationsSent(); - event(new QuoteWasMarkedSent($quote, $quote->company)); + event(new QuoteWasMarkedSent($this->quote, $this->quote->company)); - $quote->service()->setStatus(Quote::STATUS_SENT)->applyNumber()->save(); + $this->quote->service()->setStatus(Quote::STATUS_SENT)->applyNumber()->save(); - return $quote; + return $this->quote; } } diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 6aae906b7122..c9939726f5ad 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -69,9 +69,9 @@ class QuoteService public function markSent() :QuoteService { - $mark_sent = new MarkSent($this->quote->client); + $mark_sent = new MarkSent($this->quote->client, $this->quote); - $this->quote = $mark_sent->run($this->quote); + $this->quote = $mark_sent->run(); return $this; }