1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Wire up Reminder activities

This commit is contained in:
David Bomba 2023-03-17 17:23:48 +11:00
parent 58491eaf06
commit 4add5be307
2 changed files with 30 additions and 28 deletions

View File

@ -11,27 +11,33 @@
namespace App\Jobs\Util;
use App\DataMapper\InvoiceItem;
use App\Events\Invoice\InvoiceWasEmailed;
use App\Jobs\Entity\EmailEntity;
use App\Jobs\Ninja\TransactionLog;
use App\Libraries\MultiDB;
use App\Models\Invoice;
use App\Models\TransactionEvent;
use App\Utils\Ninja;
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesReminders;
use App\Models\Invoice;
use App\Libraries\MultiDB;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Carbon;
use App\DataMapper\InvoiceItem;
use App\Jobs\Entity\EmailEntity;
use App\Models\TransactionEvent;
use App\Utils\Traits\MakesDates;
use App\Jobs\Ninja\TransactionLog;
use Illuminate\Support\Facades\App;
use App\Utils\Traits\MakesReminders;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use App\Events\Invoice\InvoiceWasEmailed;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
use App\Events\Invoice\InvoiceReminderWasEmailed;
class ReminderJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, MakesReminders, MakesDates;
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
use MakesReminders;
use MakesDates;
public $tries = 1;
@ -44,7 +50,7 @@ class ReminderJob implements ShouldQueue
*
* @return void
*/
public function handle() :void
public function handle(): void
{
set_time_limit(0);
@ -73,7 +79,7 @@ class ReminderJob implements ShouldQueue
});
} else {
//multiDB environment, need to
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
@ -94,7 +100,7 @@ class ReminderJob implements ShouldQueue
})
->with('invitations')->chunk(50, function ($invoices) {
// if ($invoice->refresh() && $invoice->isPayable()) {
foreach ($invoices as $invoice) {
$this->sendReminderForInvoice($invoice);
}
@ -125,22 +131,17 @@ class ReminderJob implements ShouldQueue
$enabled_reminder = 'enable_reminder_endless';
}
//check if this reminder needs to be emailed
//15-01-2022 - insert addition if block if send_reminders is definitely set
if (in_array($reminder_template, ['reminder1', 'reminder2', 'reminder3', 'reminder_endless', 'endless_reminder']) &&
$invoice->client->getSetting($enabled_reminder) &&
$invoice->client->getSetting('send_reminders') &&
(Ninja::isSelfHost() || $invoice->company->account->isPaidHostedClient())) {
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
if ($invitation->contact && !$invitation->contact->trashed() && $invitation->contact->email) {
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template)->delay(now()->addSeconds(3));
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
nlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}");
$invoice->entityEmailEvent($invitation, $reminder_template);
}
});
if ($invoice->invitations->count() > 0) {
event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars(), $reminder_template));
}
}
$invoice->service()->setReminder()->save();
} else {
@ -156,7 +157,7 @@ class ReminderJob implements ShouldQueue
* @param string $template
* @return Invoice
*/
private function calcLateFee($invoice, $template) :Invoice
private function calcLateFee($invoice, $template): Invoice
{
$late_fee_amount = 0;
$late_fee_percent = 0;
@ -196,7 +197,7 @@ class ReminderJob implements ShouldQueue
*
* @return Invoice
*/
private function setLateFee($invoice, $amount, $percent) :Invoice
private function setLateFee($invoice, $amount, $percent): Invoice
{
App::forgetInstance('translator');
$t = app('translator');
@ -217,7 +218,7 @@ class ReminderJob implements ShouldQueue
$fee += round($invoice->balance * $percent / 100, 2);
}
$invoice_item = new InvoiceItem;
$invoice_item = new InvoiceItem();
$invoice_item->type_id = '5';
$invoice_item->product_key = trans('texts.fee');
$invoice_item->notes = ctrans('texts.late_fee_added', ['date' => $this->translateDate(now()->startOfDay(), $invoice->client->date_format(), $invoice->client->locale())]);

View File

@ -721,7 +721,7 @@ class Invoice extends BaseModel
return 0;
}
public function entityEmailEvent($invitation, $reminder_template, $template)
public function entityEmailEvent($invitation, $reminder_template, $template = '')
{
switch ($reminder_template) {
case 'invoice':
@ -737,6 +737,7 @@ class Invoice extends BaseModel
event(new InvoiceReminderWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), Activity::INVOICE_REMINDER3_SENT));
break;
case 'reminder_endless':
case 'endless_reminder':
event(new InvoiceReminderWasEmailed($invitation, $invitation->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null), Activity::INVOICE_REMINDER_ENDLESS_SENT));
break;
default: