diff --git a/app/Designs/Custom.php b/app/Designs/Custom.php
index 47ec98972539..5d88133f2f14 100644
--- a/app/Designs/Custom.php
+++ b/app/Designs/Custom.php
@@ -24,18 +24,18 @@ class Custom extends AbstractDesign
private $table_styles;
- public function __construct(array $data)
+ public function __construct($design)
{
- $this->header = $data['header'];
+ $this->header = $design->header;
- $this->body = $data['body'];
+ $this->body = $design->body;
- $this->table = $data['table'];
+ $this->table = $design->table;
- $this->footer = $data['footer'];
+ $this->footer = $design->footer;
- $this->table_styles = $data['table_styles'];
+ $this->table_styles = $design->table_styles;
}
diff --git a/app/Designs/Plain.php b/app/Designs/Plain.php
index e2546c27d5ed..826d738aacbb 100644
--- a/app/Designs/Plain.php
+++ b/app/Designs/Plain.php
@@ -41,7 +41,7 @@ class Plain extends AbstractDesign
$invoice_label
- $company_address
+ $company_details
$company_logo
diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php
index fad05bdf5e57..1f57dd6414d6 100644
--- a/app/Jobs/Invoice/CreateInvoicePdf.php
+++ b/app/Jobs/Invoice/CreateInvoicePdf.php
@@ -11,13 +11,14 @@
namespace App\Jobs\Invoice;
+use App\Designs\Custom;
use App\Designs\Designer;
use App\Designs\Modern;
use App\Libraries\MultiDB;
use App\Models\ClientContact;
use App\Models\Company;
+use App\Models\Design;
use App\Models\Invoice;
-
use App\Utils\Traits\MakesInvoiceHtml;
use App\Utils\Traits\NumberFormatter;
use Illuminate\Bus\Queueable;
@@ -25,9 +26,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
-
use Illuminate\Support\Facades\App;
-
use Illuminate\Support\Facades\Storage;
use Spatie\Browsershot\Browsershot;
@@ -77,8 +76,17 @@ class CreateInvoicePdf implements ShouldQueue {
//$file_path = $path . $this->invoice->number . '-' . $this->contact->contact_key .'.pdf';
$file_path = $path . $this->invoice->number . '.pdf';
- $modern = new Modern();
- $designer = new Designer($modern, $this->invoice->client->getSetting('invoice_variables'));
+ $design = Design::find($this->invoice->client->getSetting('invoice_design_id'));
+
+ if($design->is_custom){
+ $invoice_design = new Custom($design->design);
+ }
+ else{
+ $class = 'App\Designs\\'.$design->name;
+ $invoice_design = new $class();
+ }
+
+ $designer = new Designer($invoice_design, $this->invoice->client->getSetting('invoice_variables'));
//get invoice design
$html = $this->generateInvoiceHtml($designer->build($this->invoice)->getHtml(), $this->invoice, $this->contact);
diff --git a/app/Models/Design.php b/app/Models/Design.php
index 1e9248f57178..2c163f2810d5 100644
--- a/app/Models/Design.php
+++ b/app/Models/Design.php
@@ -17,6 +17,12 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class Design extends BaseModel
{
+ protected $casts = [
+ 'design' => 'object',
+ 'updated_at' => 'timestamp',
+ 'created_at' => 'timestamp',
+ ];
+
public function company()
{
return $this->belongsTo(Company::class);
diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php
index a8fdaa1f2ce2..fba5d66133ca 100644
--- a/tests/MockAccountData.php
+++ b/tests/MockAccountData.php
@@ -95,6 +95,25 @@ trait MockAccountData
'account_id' => $this->account->id,
]);
+ $settings = CompanySettings::defaults();
+
+ $settings->name = 'The Best Company Name';
+ $settings->company_logo = 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png';
+ $settings->website = 'www.invoiceninja.com';
+ $settings->address1 = 'Address 1';
+ $settings->address2 = 'Address 2';
+ $settings->city = 'City';
+ $settings->state = 'State';
+ $settings->postal_code = 'Postal Code';
+ $settings->phone = '555-343-2323';
+ $settings->email = 'user@example.com';
+ $settings->country_id = '840';
+ $settings->vat_number = 'vat number';
+ $settings->id_number = 'id number';
+
+ $this->company->settings = $settings;
+ $this->company->save();
+
$this->account->default_company_id = $this->company->id;
$this->account->save();
@@ -131,8 +150,14 @@ trait MockAccountData
// 'settings' => json_encode(DefaultSettings::userSettings()),
// ]);
- $this->client = ClientFactory::create($this->company->id, $this->user->id);
- $this->client->save();
+ // $this->client = ClientFactory::create($this->company->id, $this->user->id);
+ // $this->client->save();
+
+ $this->client = factory(\App\Models\Client::class)->create([
+ 'user_id' => $this->user->id,
+ 'company_id' => $this->company->id,
+ ]);
+
factory(\App\Models\ClientContact::class,1)->create([
'user_id' => $this->user->id,
@@ -148,7 +173,6 @@ trait MockAccountData
'company_id' => $this->company->id,
'send_email' => true
]);
-
$gs = new GroupSetting;
$gs->name = 'Test';