From 801b9e0d157dd18afa99788271c18614f832282b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 3 Sep 2021 22:59:48 +1000 Subject: [PATCH] Allow users to define From Name in UI --- app/DataMapper/CompanySettings.php | 2 ++ app/Mail/TemplateEmail.php | 9 ++++++++- app/Services/Invoice/AutoBillInvoice.php | 15 +++++++++++---- app/Services/Invoice/InvoiceService.php | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 7342e628a0..288a0a60a8 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -267,8 +267,10 @@ class CompanySettings extends BaseSettings public $use_credits_payment = 'off'; //always, option, off //@implemented public $hide_empty_columns_on_pdf = false; + public $email_from_name = ''; public static $casts = [ + 'email_from_name' => 'string', 'show_all_tasks_client_portal' => 'string', 'entity_send_time' => 'int', 'shared_invoice_credit_counter' => 'bool', diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index c14e6dcba2..f42ae0e413 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -79,7 +79,14 @@ class TemplateEmail extends Mailable else $signature = $settings->email_signature; - $this->from(config('mail.from.address'), $this->company->present()->name()); + if(property_exists($settings, 'email_from_name') && strlen($settings->email_from_name) > 1) + $email_from_name = $settings->email_from_name; + else + $email_from_name = $this->company->present()->name(); + +nlog($email_from_name); + + $this->from(config('mail.from.address'), $email_from_name); if (strlen($settings->bcc_email) > 1) $this->bcc(explode(",",$settings->bcc_email)); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 9505bf2e93..7b0a2f83c8 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -14,6 +14,7 @@ namespace App\Services\Invoice; use App\DataMapper\InvoiceItem; use App\Events\Payment\PaymentWasCreated; use App\Factory\PaymentFactory; +use App\Libraries\MultiDB; use App\Models\Credit; use App\Models\Invoice; use App\Models\Payment; @@ -31,15 +32,22 @@ class AutoBillInvoice extends AbstractService private $used_credit = []; - public function __construct(Invoice $invoice) + protected $db; + + public function __construct(Invoice $invoice, $db) { $this->invoice = $invoice; - - $this->client = $invoice->client; + + $this->db = $db; } public function run() { + + MultiDB::setDb($this->db); + + $this->client = $this->invoice->client; + $is_partial = false; /* Is the invoice payable? */ @@ -82,7 +90,6 @@ class AutoBillInvoice extends AbstractService } /* $gateway fee */ - //$fee = $gateway_token->gateway->calcGatewayFee($amount, $gateway_token->gateway_type_id, $this->invoice->uses_inclusive_taxes); $this->invoice = $this->invoice->service()->addGatewayFee($gateway_token->gateway, $gateway_token->gateway_type_id, $amount)->save(); if($is_partial) diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 7023afd562..7535cae5d0 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -233,7 +233,7 @@ class InvoiceService public function autoBill() { - $this->invoice = (new AutoBillInvoice($this->invoice))->run(); + $this->invoice = (new AutoBillInvoice($this->invoice, $this->invoice->company->db))->run(); return $this; }