diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index ae280aedd2..2e5aedba90 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -717,6 +717,10 @@ class InvoiceController extends BaseController else $this->reminder_template = $invoice->calculateTemplate(); + //touch reminder1,2,3_sent + last_sent here if the email is a reminder. + + $invoice->service()->touchReminder($this->reminder_template)->save(); + $invoice->invitations->load('contact.client.country','invoice.client.country','invoice.company')->each(function ($invitation) use ($invoice) { $email_builder = (new InvoiceEmail())->build($invitation, $this->reminder_template); diff --git a/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php b/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php index 6d138eba25..050bcd6a9d 100644 --- a/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php +++ b/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php @@ -43,12 +43,12 @@ class StoreCompanyGatewayRequest extends Request protected function prepareForValidation() { $input = $this->all(); - $gateway = Gateway::where('key', $input['gateway_key'])->first(); + $default_gateway_fields = json_decode($gateway->fields); /*Force gateway properties */ - if(isset($input['config'])) + if(isset($input['config']) && is_object(json_decode($input['config']))) { foreach(json_decode($input['config']) as $key => $value) { diff --git a/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php b/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php index 15c3e5e5a1..4c99746583 100644 --- a/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php +++ b/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php @@ -46,7 +46,7 @@ class UpdateCompanyGatewayRequest extends Request $input = $this->all(); /*Force gateway properties */ - if(isset($input['config']) && $input['gateway_key']) + if(isset($input['config']) && is_object(json_decode($input['config'])) && array_key_exists('gateway_key', $input)) { $gateway = Gateway::where('key', $input['gateway_key'])->first(); $default_gateway_fields = json_decode($gateway->fields); diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 2bb79b2d4c..40471e2e26 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -215,6 +215,7 @@ class InvoiceService return $this; } + /*Set partial value and due date to null*/ public function clearPartial() { $this->invoice->partial = null; @@ -223,6 +224,7 @@ class InvoiceService return $this; } + /*Update the partial amount of a invoice*/ public function updatePartial($amount) { $this->invoice->partial += $amount; @@ -230,6 +232,31 @@ class InvoiceService return $this; } + /*When a reminder is sent we want to touch the dates they were sent*/ + public function touchReminder(string $reminder_template) + { + switch ($reminder_template) { + case 'reminder1': + $this->invoice->reminder1_sent = now()->format('Y-m-d'); + $this->invoice->reminder_last_sent = now()->format('Y-m-d'); + break; + case 'reminder2': + $this->invoice->reminder2_sent = now()->format('Y-m-d'); + $this->invoice->reminder_last_sent = now()->format('Y-m-d'); + break; + case 'reminder3': + $this->invoice->reminder3_sent = now()->format('Y-m-d'); + $this->invoice->reminder_last_sent = now()->format('Y-m-d'); + break; + + default: + # code... + break; + } + + return $this; + } + /**