Working on reminders

This commit is contained in:
David Bomba 2020-11-04 20:32:49 +11:00
parent d598aeeb03
commit 5c5102baeb
6 changed files with 69 additions and 3 deletions

View File

@ -205,6 +205,10 @@ class CompanySettings extends BaseSettings
public $late_fee_amount2 = 0; //@TODO
public $late_fee_amount3 = 0; //@TODO
public $late_fee_percent1 = 0; //@TODO
public $late_fee_percent2 = 0; //@TODO
public $late_fee_percent3 = 0; //@TODO
public $endless_reminder_frequency_id = '0'; //@implemented
public $late_fee_endless_amount = 0; //@TODO
public $late_fee_endless_percent = 0; //@TODO
@ -300,6 +304,9 @@ class CompanySettings extends BaseSettings
'late_fee_amount1' => 'float',
'late_fee_amount2' => 'float',
'late_fee_amount3' => 'float',
'late_fee_percent1' => 'float',
'late_fee_percent2' => 'float',
'late_fee_percent3' => 'float',
'endless_reminder_frequency_id' => 'integer',
'client_online_payment_notification' => 'bool',
'client_manual_payment_notification' => 'bool',

View File

@ -79,7 +79,7 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
$this->entity = $invitation->{$this->entity_string};
$this->reminder_template = $reminder_template ?: $this->findReminderTemplate();
$this->reminder_template = $reminder_template ?: $this->entity->calculateTemplate($this->entity_string);
$this->html_engine = new HtmlEngine($invitation);

View File

@ -12,6 +12,7 @@
namespace App\Jobs\Ninja;
use App\Libraries\MultiDB;
use App\Models\Invoice;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@ -44,17 +45,68 @@ class SendReminders implements ShouldQueue
if (! config('ninja.db.multi_db_enabled')) {
$this->sendReminderEmails();
} else {
//multiDB environment, need to
foreach (MultiDB::$dbs as $db) {
foreach (MultiDB::$dbs as $db)
{
MultiDB::setDB($db);
$this->sendReminderEmails();
}
}
}
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
}
}

View File

@ -23,6 +23,7 @@ use App\Utils\Ninja;
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceValues;
use App\Utils\Traits\MakesReminders;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
@ -37,7 +38,8 @@ class Credit extends BaseModel
use SoftDeletes;
use PresentableTrait;
use MakesInvoiceValues;
use MakesReminders;
protected $presenter = CreditPresenter::class;
protected $fillable = [

View File

@ -66,6 +66,8 @@ class MarkPaid extends AbstractService
'amount' => $payment->amount,
]);
$this->invoice->next_send_date = null;
$this->invoice->service()
->updateBalance($payment->amount * -1)
->setStatus(Invoice::STATUS_PAID)

View File

@ -186,6 +186,9 @@ trait MakesReminders
//if invoice is currently a draft, or being marked as sent, this will be the initial email
$client = $this->client;
if($entity_string != 'invoice')
return $entity_string;
//if the invoice
if ($client->getSetting('enable_reminder1') !== false && $this->inReminderWindow(
$client->getSetting('schedule_reminder1'),