Add sendInvoiceReminder

This commit is contained in:
David Callizaya 2021-10-28 17:21:34 -04:00
parent 4a0145a825
commit deb51733e7
2 changed files with 58 additions and 1 deletions

View File

@ -10,10 +10,11 @@ use Webkul\Sales\Traits\PaymentTerm;
use Webkul\Sales\Database\Factories\InvoiceFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Webkul\Sales\Traits\InvoiceReminder;
class Invoice extends Model implements InvoiceContract
{
use PaymentTerm, HasFactory;
use PaymentTerm, InvoiceReminder, HasFactory;
/**
* The attributes that aren't mass assignable.

View File

@ -0,0 +1,56 @@
<?php
namespace Webkul\Sales\Traits;
use Illuminate\Support\Facades\Mail;
use Webkul\Admin\Mail\InvoiceOverdueReminder;
trait InvoiceReminder
{
/**
* Wether the core config have maximum limit of reminders.
*
* @return bool
*/
private function hasOverdueRemindersLimit()
{
return $this->getOverdueRemindersLimit()
? true : false;
}
/**
* Get maximum limit of reminders from the core config.
*
* @return int
*/
private function getOverdueRemindersLimit()
{
static $remindersLimit = 0;
if ($remindersLimit) {
return $remindersLimit;
}
return $remindersLimit = (int) core()->getConfigData('sales.invoice_setttings.invoice_reminders.reminders_limit');
}
/**
* Send an Invoice reminder
*
* @return void
*/
public function sendInvoiceReminder()
{
if ($this->hasOverdueRemindersLimit()) {
$limit = $this->getOverdueRemindersLimit();
if ($this->reminders >= $limit) {
return;
}
}
/** @var Webkul\Customer\Models\Customer $customer */
$customer = $this->customer;
Mail::queue(new InvoiceOverdueReminder($customer, $this));
$this->reminders++;
$this->save();
}
}