diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index c63386a26e4f..299dbcb3cd90 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -398,7 +398,6 @@ class CompanySettings extends BaseSettings 'email_template_reminder2' => 'string', 'email_template_reminder3' => 'string', 'email_template_reminder_endless' => 'string', - 'enable_client_portal_password' => 'bool', 'inclusive_taxes' => 'bool', 'invoice_number_pattern' => 'string', 'invoice_number_counter' => 'integer', diff --git a/app/Helpers/Mail/GmailTransport.php b/app/Helpers/Mail/GmailTransport.php index e380a6c1f7ca..bd3622cf3b1a 100644 --- a/app/Helpers/Mail/GmailTransport.php +++ b/app/Helpers/Mail/GmailTransport.php @@ -46,8 +46,6 @@ class GmailTransport extends Transport $this->gmail = null; $this->gmail = new Mail; - nlog(array_keys($message->getBcc())); - /*We should nest the token in the message and then discard it as needed*/ $token = $message->getHeaders()->get('GmailToken')->getValue(); @@ -67,8 +65,6 @@ class GmailTransport extends Transport foreach ($message->getChildren() as $child) { - nlog("trying to attach"); - if($child->getContentType() != 'text/plain') { diff --git a/app/Http/Controllers/TwoFactorController.php b/app/Http/Controllers/TwoFactorController.php index 75bc02b6455f..2bd4bb7c7db2 100644 --- a/app/Http/Controllers/TwoFactorController.php +++ b/app/Http/Controllers/TwoFactorController.php @@ -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(); diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index d4d42289c119..2daf4bc074fa 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -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; } diff --git a/app/Services/Invoice/UpdateReminder.php b/app/Services/Invoice/UpdateReminder.php index 62484e0874a4..8037b9308e71 100644 --- a/app/Services/Invoice/UpdateReminder.php +++ b/app/Services/Invoice/UpdateReminder.php @@ -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; + } + } } \ No newline at end of file