diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index f8e007bbcb82..53c72ccc02fc 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -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', diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index 2edf49716043..f2c27e6857ce 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -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); diff --git a/app/Jobs/Ninja/SendReminders.php b/app/Jobs/Ninja/SendReminders.php index fd26d397ba78..a10e45075cb4 100644 --- a/app/Jobs/Ninja/SendReminders.php +++ b/app/Jobs/Ninja/SendReminders.php @@ -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 + } + } \ No newline at end of file diff --git a/app/Models/Credit.php b/app/Models/Credit.php index cd11e9ea578c..9ad51f51605b 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -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 = [ diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 0e6ea9a54a0a..1fe1d0deed01 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -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) diff --git a/app/Utils/Traits/MakesReminders.php b/app/Utils/Traits/MakesReminders.php index 7efe062e157b..9754573b401a 100644 --- a/app/Utils/Traits/MakesReminders.php +++ b/app/Utils/Traits/MakesReminders.php @@ -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'),