-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance Invoice Reminder System with Upcoming and Overdue
- Loading branch information
1 parent
e640d10
commit b3e5cfa
Showing
5 changed files
with
169 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
|
||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use App\Services\BillingService; | ||
|
||
class ProcessInvoiceReminders extends Command | ||
{ | ||
protected $signature = 'invoices:process-reminders'; | ||
protected $description = 'Process invoice reminders for upcoming and overdue invoices'; | ||
|
||
protected $billingService; | ||
|
||
public function __construct(BillingService $billingService) | ||
{ | ||
parent::__construct(); | ||
$this->billingService = $billingService; | ||
} | ||
|
||
public function handle() | ||
{ | ||
$this->info('Processing invoice reminders...'); | ||
|
||
// Process upcoming invoice reminders | ||
$upcomingCount = $this->billingService->sendUpcomingInvoiceReminders(); | ||
$this->info("Sent {$upcomingCount} upcoming invoice reminders"); | ||
|
||
// Process overdue invoice reminders | ||
$overdueCount = $this->billingService->sendOverdueReminders(); | ||
$this->info("Sent {$overdueCount} overdue invoice reminders"); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
|
||
<?php | ||
|
||
namespace App\Mail; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class UpcomingInvoiceReminder extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
public $data; | ||
public $template; | ||
|
||
public function __construct($data, $template) | ||
{ | ||
$this->data = $data; | ||
$this->template = $template; | ||
} | ||
|
||
public function build() | ||
{ | ||
return $this->subject($this->parseTemplate($this->template->subject)) | ||
->view('emails.upcoming-invoice-reminder') | ||
->with([ | ||
'content' => $this->parseTemplate($this->template->body), | ||
'data' => $this->data | ||
]); | ||
} | ||
|
||
private function parseTemplate($text) | ||
{ | ||
foreach ($this->data as $key => $value) { | ||
$text = str_replace('{{'.$key.'}}', $value, $text); | ||
} | ||
return $text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
database/migrations/2024_01_20_000000_add_upcoming_reminder_sent_to_invoices.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
|
||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class AddUpcomingReminderSentToInvoices extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::table('invoices', function (Blueprint $table) { | ||
$table->boolean('upcoming_reminder_sent')->nullable(); | ||
}); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::table('invoices', function (Blueprint $table) { | ||
$table->dropColumn('upcoming_reminder_sent'); | ||
}); | ||
} | ||
} |