Skip to content

Commit 9ee380a

Browse files
committed
Added call, meeting & lunch reminders 15 mins before they occur
1 parent b31d29e commit 9ee380a

File tree

6 files changed

+544
-5
lines changed

6 files changed

+544
-5
lines changed

database/migrations/add_client_to_laravel_crm_deals_table.php.stub

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,54 @@ class AddClientToLaravelCrmDealsTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::table(config('laravel-crm.db_table_prefix').'deals', function (Blueprint $table) {
17-
$table->foreignIdFor(\VentureDrake\LaravelCrm\Models\Client::class)->after('organisation_id')->nullable();
16+
Schema::table(config('laravel-crm.db_table_prefix').'leads', function (Blueprint $table) {
17+
$table->string('url')->nullable();
1818
});
19+
20+
Schema::table(config('laravel-crm.db_table_prefix').'deals', function (Blueprint $table) {
21+
$table->string('url')->nullable();
22+
});
23+
24+
Schema::table(config('laravel-crm.db_table_prefix').'quotes', function (Blueprint $table) {
25+
$table->string('url')->nullable();
26+
});
27+
28+
Schema::table(config('laravel-crm.db_table_prefix').'orders', function (Blueprint $table) {
29+
$table->string('url')->nullable();
30+
});
31+
32+
Schema::table(config('laravel-crm.db_table_prefix').'invoices', function (Blueprint $table) {
33+
$table->string('url')->nullable();
34+
});
35+
36+
Schema::table(config('laravel-crm.db_table_prefix').'deliveries', function (Blueprint $table) {
37+
$table->string('url')->nullable();
38+
});
39+
40+
Schema::table(config('laravel-crm.db_table_prefix').'clients', function (Blueprint $table) {
41+
$table->string('url')->nullable();
42+
});
43+
44+
Schema::table(config('laravel-crm.db_table_prefix').'organisations', function (Blueprint $table) {
45+
$table->string('url')->nullable();
46+
});
47+
48+
Schema::table(config('laravel-crm.db_table_prefix').'people', function (Blueprint $table) {
49+
$table->string('url')->nullable();
50+
});
51+
52+
53+
Schema::table(config('laravel-crm.db_table_prefix').'users', function (Blueprint $table) {
54+
$table->string('url')->nullable();
55+
});
56+
57+
Schema::table('crm_teams', function (Blueprint $table) {
58+
$table->string('url')->nullable();
59+
});
60+
61+
Schema::table(config('laravel-crm.db_table_prefix').'products', function (Blueprint $table) {
62+
$table->string('url')->nullable();
63+
});
1964
}
2065

2166
/**
@@ -25,8 +70,52 @@ class AddClientToLaravelCrmDealsTable extends Migration
2570
*/
2671
public function down()
2772
{
73+
Schema::table(config('laravel-crm.db_table_prefix').'leads', function (Blueprint $table) {
74+
$table->dropColumn('url');
75+
});
76+
2877
Schema::table(config('laravel-crm.db_table_prefix').'deals', function (Blueprint $table) {
29-
$table->dropColumn('client_id');
78+
$table->dropColumn('url');
79+
});
80+
81+
Schema::table(config('laravel-crm.db_table_prefix').'quotes', function (Blueprint $table) {
82+
$table->dropColumn('url');
83+
});
84+
85+
Schema::table(config('laravel-crm.db_table_prefix').'orders', function (Blueprint $table) {
86+
$table->dropColumn('url');
87+
});
88+
89+
Schema::table(config('laravel-crm.db_table_prefix').'invoices', function (Blueprint $table) {
90+
$table->dropColumn('url');
91+
});
92+
93+
Schema::table(config('laravel-crm.db_table_prefix').'deliveries', function (Blueprint $table) {
94+
$table->dropColumn('url');
95+
});
96+
97+
Schema::table(config('laravel-crm.db_table_prefix').'clients', function (Blueprint $table) {
98+
$table->dropColumn('url');
99+
});
100+
101+
Schema::table(config('laravel-crm.db_table_prefix').'organisations', function (Blueprint $table) {
102+
$table->dropColumn('url');
103+
});
104+
105+
Schema::table(config('laravel-crm.db_table_prefix').'people', function (Blueprint $table) {
106+
$table->dropColumn('url');
107+
});
108+
109+
Schema::table(config('laravel-crm.db_table_prefix').'users', function (Blueprint $table) {
110+
$table->dropColumn('url');
111+
});
112+
113+
Schema::table('crm_teams', function (Blueprint $table) {
114+
$table->dropColumn('url');
115+
});
116+
117+
Schema::table(config('laravel-crm.db_table_prefix').'products', function (Blueprint $table) {
118+
$table->dropColumn('url');
30119
});
31120
}
32121
}

src/Console/LaravelCrmReminders.php

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
use Carbon\Carbon;
66
use Illuminate\Console\Command;
77
use Illuminate\Support\Composer;
8+
use VentureDrake\LaravelCrm\Models\Call;
9+
use VentureDrake\LaravelCrm\Models\Lunch;
10+
use VentureDrake\LaravelCrm\Models\Meeting;
811
use VentureDrake\LaravelCrm\Models\Task;
12+
use VentureDrake\LaravelCrm\Notifications\CallReminderNotification;
13+
use VentureDrake\LaravelCrm\Notifications\LunchReminderNotification;
14+
use VentureDrake\LaravelCrm\Notifications\MeetingReminderNotification;
915
use VentureDrake\LaravelCrm\Notifications\TaskReminderNotification;
1016
use VentureDrake\LaravelCrm\Services\SettingService;
1117

@@ -61,7 +67,7 @@ public function handle()
6167
foreach(Task::whereNull('completed_at')
6268
->where('reminder_email', 0)
6369
->where('due_at', '>=', Carbon::now()->timezone($this->settingService->get('timezone')->value ?? 'UTC')->subMinutes(5)->format('Y-m-d H:i:\\00'))
64-
->where('due_at', '<=', Carbon::now()->timezone($this->settingService->get('timezone')->value ?? 'UTC')->addMinutes(5)->format('Y-m-d H:i:\\00'))
70+
->where('due_at', '<=', Carbon::now()->timezone($this->settingService->get('timezone')->value ?? 'UTC')->addMinutes(15)->format('Y-m-d H:i:\\00'))
6571
->orderBy('due_at', 'asc')
6672
->get() as $task) {
6773
if ($task->user_assigned_id) {
@@ -78,6 +84,63 @@ public function handle()
7884
}
7985
}
8086

87+
foreach(Call::where('reminder_email', 0)
88+
->where('start_at', '>=', Carbon::now()->timezone($this->settingService->get('timezone')->value ?? 'UTC')->subMinutes(5)->format('Y-m-d H:i:\\00'))
89+
->where('start_at', '<=', Carbon::now()->timezone($this->settingService->get('timezone')->value ?? 'UTC')->addMinutes(15)->format('Y-m-d H:i:\\00'))
90+
->orderBy('start_at', 'asc')
91+
->get() as $call) {
92+
if ($call->user_assigned_id) {
93+
$user = \App\User::find($call->user_assigned_id);
94+
$this->info('Sending call #'.$call->id.' reminder to '.$user->name);
95+
96+
$user->notify(
97+
new CallReminderNotification($call, $user)
98+
);
99+
100+
$call->update([
101+
'reminder_email' => 1,
102+
]);
103+
}
104+
}
105+
106+
foreach(Meeting::where('reminder_email', 0)
107+
->where('start_at', '>=', Carbon::now()->timezone($this->settingService->get('timezone')->value ?? 'UTC')->subMinutes(5)->format('Y-m-d H:i:\\00'))
108+
->where('start_at', '<=', Carbon::now()->timezone($this->settingService->get('timezone')->value ?? 'UTC')->addMinutes(15)->format('Y-m-d H:i:\\00'))
109+
->orderBy('start_at', 'asc')
110+
->get() as $meeting) {
111+
if ($meeting->user_assigned_id) {
112+
$user = \App\User::find($meeting->user_assigned_id);
113+
$this->info('Sending meeting #'.$meeting->id.' reminder to '.$user->name);
114+
115+
$user->notify(
116+
new MeetingReminderNotification($meeting, $user)
117+
);
118+
119+
$meeting->update([
120+
'reminder_email' => 1,
121+
]);
122+
}
123+
}
124+
125+
foreach(Lunch::where('reminder_email', 0)
126+
->where('start_at', '>=', Carbon::now()->timezone($this->settingService->get('timezone')->value ?? 'UTC')->subMinutes(5)->format('Y-m-d H:i:\\00'))
127+
->where('start_at', '<=', Carbon::now()->timezone($this->settingService->get('timezone')->value ?? 'UTC')->addMinutes(15)->format('Y-m-d H:i:\\00'))
128+
->orderBy('start_at', 'asc')
129+
->get() as $lunch) {
130+
if ($lunch->user_assigned_id) {
131+
$user = \App\User::find($lunch->user_assigned_id);
132+
$this->info('Sending lunch #'.$lunch->id.' reminder to '.$user->name);
133+
134+
$user->notify(
135+
new LunchReminderNotification($lunch, $user)
136+
);
137+
138+
$lunch->update([
139+
'reminder_email' => 1,
140+
]);
141+
}
142+
}
143+
81144
$this->info('Laravel CRM reminders sent.');
82145
}
83146
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
3+
namespace VentureDrake\LaravelCrm\Notifications;
4+
5+
use App\User;
6+
use Carbon\Carbon;
7+
use Illuminate\Support\HtmlString;
8+
use VentureDrake\LaravelCrm\Models\Call;
9+
use Illuminate\Bus\Queueable;
10+
use Illuminate\Notifications\Messages\MailMessage;
11+
use Illuminate\Notifications\Notification;
12+
13+
class CallReminderNotification extends Notification
14+
{
15+
use Queueable;
16+
17+
protected $call;
18+
19+
protected $user;
20+
21+
protected $notify;
22+
23+
/**
24+
* Create a new notification instance.
25+
*
26+
* @return void
27+
*/
28+
public function __construct(Call $call, User $user, $notify = 'user')
29+
{
30+
$this->call = $call;
31+
$this->user = $user;
32+
$this->notify = $notify;
33+
}
34+
35+
/**
36+
* Get the notification's delivery channels.
37+
*
38+
* @param mixed $notifiable
39+
* @return array
40+
*/
41+
public function via($notifiable)
42+
{
43+
return ['mail'];
44+
}
45+
46+
/**
47+
* Get the mail representation of the notification.
48+
*
49+
* @param mixed $notifiable
50+
* @return \Illuminate\Notifications\Messages\MailMessage
51+
*/
52+
public function toMail($notifiable)
53+
{
54+
$mailMessage = new MailMessage();
55+
$subject = 'CALL REMINDER: '.$this->call->name.' ('.Carbon::parse($this->call->start_at)->format('M d, Y \\@ h:i A').')';
56+
$greeting = 'Hi '.$this->user->name.',';
57+
58+
$mailMessage
59+
->subject($subject)
60+
->greeting($greeting);
61+
62+
$mailMessage->line(new HtmlString('<strong>THIS CALL IS COMING UP:</strong>'));
63+
$mailMessage->line(new HtmlString('<strong>'.$this->call->name.'</strong>'));
64+
$mailMessage->line(new HtmlString('Starting: '.Carbon::parse($this->call->start_at)->format('M d, Y \\@ h:i A').'<br />Ending: '.Carbon::parse($this->call->finish_at)->format('M d, Y \\@ h:i A'). '<br />Location: '.$this->call->location));
65+
$mailMessage->line(new HtmlString($this->call->description));
66+
67+
if($this->call->callable) {
68+
switch(class_basename($this->call->callable->getMorphClass())) {
69+
case "Lead":
70+
$mailMessage->line(new HtmlString('Lead: <a href="'.config('app.url').'/leads/'.$this->call->callable->id.'">'.$this->call->callable->title.'</a></small>'));
71+
break;
72+
73+
case "Deal":
74+
$mailMessage->line(new HtmlString('Lead: <a href="'.config('app.url').'/deals/'.$this->call->callable->id.'">'.$this->call->callable->title.'</a></small>'));
75+
break;
76+
77+
case "Quote":
78+
$mailMessage->line(new HtmlString('Quote: <a href="'.config('app.url').'/quotes/'.$this->call->callable->id.'">'.$this->call->callable->title.'</a></small>'));
79+
break;
80+
81+
case "Order":
82+
$mailMessage->line(new HtmlString('Quote: <a href="'.config('app.url').'/orders/'.$this->call->callable->id.'">'.$this->call->callable->order_id.'</a></small>'));
83+
break;
84+
85+
case "Invoice":
86+
$mailMessage->line(new HtmlString('Invoice: <a href="'.config('app.url').'/invoices/'.$this->call->callable->id.'">'.$this->call->callable->invoice_id.'</a></small>'));
87+
break;
88+
89+
case "Delivery":
90+
$mailMessage->line(new HtmlString('Delivery: <a href="'.config('app.url').'/deliveries/'.$this->call->callable->id.'">'.$this->call->callable->delivery_id.'</a></small>'));
91+
break;
92+
93+
case "Client":
94+
$mailMessage->line(new HtmlString('Client: <a href="'.config('app.url').'/clients/'.$this->call->callable->id.'">'.$this->call->callable->name.'</a></small>'));
95+
break;
96+
97+
case "Organisation":
98+
$mailMessage->line(new HtmlString('Organisation: <a href="'.config('app.url').'/organisation/'.$this->call->callable->id.'">'.$this->call->callable->name.'</a></small>'));
99+
break;
100+
101+
case "Person":
102+
$mailMessage->line(new HtmlString('Person: <a href="'.config('app.url').'/people/'.$this->call->callable->id.'">'.$this->call->callable->name.'</a></small>'));
103+
break;
104+
}
105+
}
106+
107+
$placeholders = [
108+
'call' => $this->call,
109+
'user' => $this->user,
110+
];
111+
112+
$mailMessage->markdown('laravel-crm::notifications.email', $placeholders);
113+
114+
return $mailMessage;
115+
}
116+
117+
/**
118+
* Get the array representation of the notification.
119+
*
120+
* @param mixed $notifiable
121+
* @return array
122+
*/
123+
public function toArray($notifiable)
124+
{
125+
return [
126+
//
127+
];
128+
}
129+
}

0 commit comments

Comments
 (0)