Fixes for Two Factor

This commit is contained in:
David Bomba 2021-06-23 14:55:12 +10:00
parent 4eea13334e
commit b56b5c1ec9
3 changed files with 66 additions and 10 deletions

View File

@ -11,11 +11,16 @@
namespace App\Http\Controllers;
use PragmaRX\Google2FA\Google2FA;
use App\Models\User;
use Crypt;
use PragmaRX\Google2FA\Google2FA;
class TwoFactorController extends BaseController
{
protected $entity_type = User::class;
protected $entity_transformer = UserTransformer::class;
public function setupTwoFactor()
{
$user = auth()->user();

View File

@ -377,23 +377,28 @@ class InvoiceService
{
switch ($reminder_template) {
case 'reminder1':
$this->invoice->reminder1_sent = now()->format('Y-m-d');
$this->invoice->reminder_last_sent = now()->format('Y-m-d');
$this->invoice->reminder1_sent = now();
$this->invoice->reminder_last_sent = now();
$this->invoice->last_sent_date = now();
break;
case 'reminder2':
$this->invoice->reminder2_sent = now()->format('Y-m-d');
$this->invoice->reminder_last_sent = now()->format('Y-m-d');
$this->invoice->reminder2_sent = now();
$this->invoice->reminder_last_sent = now();
$this->invoice->last_sent_date = now();
break;
case 'reminder3':
$this->invoice->reminder3_sent = now()->format('Y-m-d');
$this->invoice->reminder_last_sent = now()->format('Y-m-d');
$this->invoice->reminder3_sent = now();
$this->invoice->reminder_last_sent = now();
$this->invoice->last_sent_date = now();
break;
case 'endless_reminder':
$this->invoice->reminder_last_sent = now()->format('Y-m-d');
$this->invoice->reminder_last_sent = now();
$this->invoice->last_sent_date = now();
break;
default:
$this->invoice->reminder1_sent = now()->format('Y-m-d');
$this->invoice->reminder_last_sent = now()->format('Y-m-d');
$this->invoice->reminder1_sent = now();
$this->invoice->reminder_last_sent = now();
$this->invoice->last_sent_date = now();
break;
}

View File

@ -12,6 +12,7 @@
namespace App\Services\Invoice;
use App\Models\Invoice;
use App\Models\RecurringInvoice;
use App\Services\AbstractService;
use Carbon\Carbon;
@ -126,6 +127,14 @@ class UpdateReminder extends AbstractService
$date_collection->push($reminder_date);
}
if ($this->invoice->last_sent_date &&
(int)$this->settings->endless_reminder_frequency_id > 0) {
$reminder_date = $this->addTimeInterval($this->invoice->last_sent_date, (int)$this->settings->num_days_reminder3)->addSeconds($offset);
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)));
$date_collection->push($reminder_date);
}
if($date_collection->count() >=1 && $date_collection->sort()->first()->gte(now()))
$this->invoice->next_send_date = $date_collection->sort()->first();
else
@ -133,4 +142,41 @@ class UpdateReminder extends AbstractService
return $this->invoice;
}
private function addTimeInterval($date, $endless_reminder_frequency_id) :?Carbon
{
if (!$date)
return null;
switch ($endless_reminder_frequency_id) {
case RecurringInvoice::FREQUENCY_DAILY:
return Carbon::parse($date)->addDay()->startOfDay();
case RecurringInvoice::FREQUENCY_WEEKLY:
return Carbon::parse($date)->addWeek()->startOfDay();
case RecurringInvoice::FREQUENCY_TWO_WEEKS:
return Carbon::parse($date)->addWeeks(2)->startOfDay();
case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
return Carbon::parse($date)->addWeeks(4)->startOfDay();
case RecurringInvoice::FREQUENCY_MONTHLY:
return Carbon::parse($date)->addMonthNoOverflow()->startOfDay();
case RecurringInvoice::FREQUENCY_TWO_MONTHS:
return Carbon::parse($date)->addMonthsNoOverflow(2)->startOfDay();
case RecurringInvoice::FREQUENCY_THREE_MONTHS:
return Carbon::parse($date)->addMonthsNoOverflow(3)->startOfDay();
case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
return Carbon::parse($date)->addMonthsNoOverflow(4)->startOfDay();
case RecurringInvoice::FREQUENCY_SIX_MONTHS:
return Carbon::parse($date)->addMonthsNoOverflow(6)->startOfDay();
case RecurringInvoice::FREQUENCY_ANNUALLY:
return Carbon::parse($date)->addYear()->startOfDay();
case RecurringInvoice::FREQUENCY_TWO_YEARS:
return Carbon::parse($date)->addYears(2)->startOfDay();
case RecurringInvoice::FREQUENCY_THREE_YEARS:
return Carbon::parse($date)->addYears(3)->startOfDay();
default:
return null;
}
}
}