1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 22:22:32 +01:00

Fixes for reminders

This commit is contained in:
David Bomba 2022-05-16 18:53:01 +10:00
parent 02ac1029c2
commit 2dfe001152
5 changed files with 56 additions and 16 deletions

View File

@ -60,7 +60,7 @@ class LedgerBalanceUpdate implements ShouldQueue
nlog("Checking ledgers....");
CompanyLedger::where('balance', 0)->cursor()->each(function ($company_ledger){
CompanyLedger::where('balance', 0)->where('adjustment', '!=', 0)->cursor()->each(function ($company_ledger){
if($company_ledger->balance > 0)
return;

View File

@ -117,6 +117,9 @@ class AutoBillInvoice extends AbstractService
$payment = false;
//TODO check retries is not past threshold > 3. //return
// if threshold exceeded. set invoices.auto_bill_enabled = false.
try{
$payment = $gateway_token->gateway
->driver($this->client)
@ -125,7 +128,9 @@ class AutoBillInvoice extends AbstractService
}
catch(\Exception $e){
nlog("payment NOT captured for ". $this->invoice->number . " with error " . $e->getMessage());
// $this->invoice->service()->removeUnpaidGatewayFees();
// $this->invoice->service()->removeUnpaidGatewayFees();
//@TODO increment auto_bill_tries here
}
if($payment){

View File

@ -35,7 +35,7 @@ class UpdateReminder extends AbstractService
$this->settings = $this->invoice->client->getMergedSettings();
}
if (! $this->invoice->isPayable()) {
if (! $this->invoice->isPayable() || $this->invoice->status_id == Invoice::STATUS_DRAFT) {
$this->invoice->next_send_date = null;
$this->invoice->saveQuietly();
@ -51,7 +51,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder1_sent) &&
$this->settings->schedule_reminder1 == 'after_invoice_date' &&
$this->settings->enable_reminder1) {
$this->settings->enable_reminder1 &&
$this->settings->num_days_reminder1 != 0) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -60,7 +61,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder1_sent) &&
$this->settings->schedule_reminder1 == 'before_due_date' &&
$this->settings->enable_reminder1) {
$this->settings->enable_reminder1 &&
$this->settings->num_days_reminder1 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -69,7 +71,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder1_sent) &&
$this->settings->schedule_reminder1 == 'after_due_date' &&
$this->settings->enable_reminder1) {
$this->settings->enable_reminder1 &&
$this->settings->num_days_reminder1 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -78,7 +81,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder2_sent) &&
$this->settings->schedule_reminder2 == 'after_invoice_date' &&
$this->settings->enable_reminder2) {
$this->settings->enable_reminder2 &&
$this->settings->num_days_reminder2 != 0) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -87,7 +91,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder2_sent) &&
$this->settings->schedule_reminder2 == 'before_due_date' &&
$this->settings->enable_reminder2) {
$this->settings->enable_reminder2 &&
$this->settings->num_days_reminder2 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -96,7 +101,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder2_sent) &&
$this->settings->schedule_reminder2 == 'after_due_date' &&
$this->settings->enable_reminder2) {
$this->settings->enable_reminder2 &&
$this->settings->num_days_reminder2 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -105,7 +111,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder3_sent) &&
$this->settings->schedule_reminder3 == 'after_invoice_date' &&
$this->settings->enable_reminder3) {
$this->settings->enable_reminder3 &&
$this->settings->num_days_reminder3 != 0) {
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -114,7 +121,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder3_sent) &&
$this->settings->schedule_reminder3 == 'before_due_date' &&
$this->settings->enable_reminder3) {
$this->settings->enable_reminder3 &&
$this->settings->num_days_reminder3 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
@ -123,7 +131,8 @@ class UpdateReminder extends AbstractService
if (is_null($this->invoice->reminder3_sent) &&
$this->settings->schedule_reminder3 == 'after_due_date' &&
$this->settings->enable_reminder3) {
$this->settings->enable_reminder3 &&
$this->settings->num_days_reminder3 != 0) {
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))

View File

@ -391,10 +391,10 @@ class Design extends BaseDesign
$element = ['element' => 'tr', 'elements' => []];
$element['elements'][] = ['element' => 'td', 'content' => $invoice->number];
$element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($invoice->date, $this->client->date_format(), $this->client->locale()) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($invoice->due_date, $this->client->date_format(), $this->client->locale()) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => Number::formatMoney($invoice->amount, $this->client) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => Number::formatMoney($invoice->balance, $this->client) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($invoice->date, $this->client->date_format(), $this->client->locale()) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($invoice->due_date, $this->client->date_format(), $this->client->locale()) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => Number::formatMoney($invoice->amount, $this->client) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => Number::formatMoney($invoice->balance, $this->client) ?: ' '];
$tbody[] = $element;
}

View File

@ -169,4 +169,30 @@ class ReminderTest extends TestCase
}
public function testReminderIsSet()
{
$this->invoice->next_send_date = null;
$this->invoice->date = now()->format('Y-m-d');
$this->invoice->due_date = Carbon::now()->addDays(30)->format('Y-m-d');
$this->invoice->save();
$settings = $this->company->settings;
$settings->enable_reminder1 = true;
$settings->schedule_reminder1 = 'after_invoice_date';
$settings->num_days_reminder1 = 7;
$settings->enable_reminder2 = true;
$settings->schedule_reminder2 = 'before_due_date';
$settings->num_days_reminder2 = 1;
$settings->enable_reminder3 = true;
$settings->schedule_reminder3 = 'after_due_date';
$settings->num_days_reminder3 = 1;
$this->company->settings = $settings;
$this->invoice = $this->invoice->service()->markSent()->save();
$this->invoice->service()->setReminder($settings)->save();
$this->assertNotNull($this->invoice->next_send_date);
}
}