1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Jobs/Ninja/SendReminders.php

112 lines
2.4 KiB
PHP
Raw Normal View History

2020-11-04 09:43:20 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Jobs\Ninja;
use App\Libraries\MultiDB;
2020-11-04 10:32:49 +01:00
use App\Models\Invoice;
2020-11-04 09:43:20 +01:00
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SendReminders implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
info("Sending reminders ".Carbon::now()->format('Y-m-d h:i:s'));
if (! config('ninja.db.multi_db_enabled')) {
2020-11-04 10:32:49 +01:00
$this->sendReminderEmails();
2020-11-04 09:43:20 +01:00
} else {
//multiDB environment, need to
2020-11-04 10:32:49 +01:00
foreach (MultiDB::$dbs as $db)
{
2020-11-04 09:43:20 +01:00
MultiDB::setDB($db);
2020-11-04 10:32:49 +01:00
$this->sendReminderEmails();
2020-11-04 09:43:20 +01:00
}
}
}
2020-11-04 10:32:49 +01:00
private function chargeLateFee()
{
}
private function sendReminderEmails()
{
$invoices = Invoice::where('is_deleted', 0)
->where('balance', '>', 0)
->whereDate('next_send_date', '<=', now()->startOfDay())
->cursor();
//we only need invoices that are payable
$invoices->filter(function ($invoice){
return $invoice->isPayable();
})->each(function ($invoice){
$reminder_template = $invoice->calculateTemplate('invoice');
if($reminder_template == 'reminder1'){
}
elseif($reminder_template == 'reminder2'){
}
elseif($reminder_template == 'reminder3'){
}
elseif($reminder_template == 'endless_reminder'){
}
//@todo
});
//iterate through all the reminder emails due today
//
//determine which reminder
//
//determine late fees
//
//send
}
2020-11-04 09:43:20 +01:00
}