diff --git a/app/Helpers/Invoice/InvoiceCalc.php b/app/Helpers/Invoice/InvoiceCalc.php
index 7742e7460e7d..62b6bc76a4f9 100644
--- a/app/Helpers/Invoice/InvoiceCalc.php
+++ b/app/Helpers/Invoice/InvoiceCalc.php
@@ -151,10 +151,10 @@ class InvoiceCalc
{
// custom fields charged taxes
- if (isset($this->invoice->custom_value1) && $this->settings->custom_taxes1) {
+ if (isset($this->invoice->custom_value1) && isset($this->settings->custom_taxes1)) {
$this->total += $this->invoice->custom_value1;
}
- if (isset($this->invoice->custom_value2) && $this->settings->custom_taxes2) {
+ if (isset($this->invoice->custom_value2) && isset($this->settings->custom_taxes2)) {
$this->total += $this->invoice->custom_value2;
}
diff --git a/app/Listeners/Invoice/CreateInvoicePdf.php b/app/Listeners/Invoice/CreateInvoicePdf.php
index 398804e29118..53c0fdd0bc30 100644
--- a/app/Listeners/Invoice/CreateInvoicePdf.php
+++ b/app/Listeners/Invoice/CreateInvoicePdf.php
@@ -91,7 +91,9 @@ class CreateInvoicePdf
$data['invoice'] = $invoice;
- return view($design, $data)->render();
+ $template_variables = array_merge($invoice->makeLabels(), $invoice->makeValues());
+
+ return view($design, array_merge($data, $template_variables))->render();
}
}
diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php
index 7d8ca24a2bea..a1b9c5015f42 100644
--- a/app/Models/Invoice.php
+++ b/app/Models/Invoice.php
@@ -15,6 +15,8 @@ use App\Models\Currency;
use App\Models\Filterable;
use App\Utils\Number;
use App\Utils\Traits\MakesDates;
+use App\Utils\Traits\MakesInvoiceLabels;
+use App\Utils\Traits\MakesInvoiceValues;
use App\Utils\Traits\NumberFormatter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -29,7 +31,8 @@ class Invoice extends BaseModel
use NumberFormatter;
use MakesDates;
use PresentableTrait;
-
+ use MakesInvoiceValues;
+ use MakesInvoiceLabels;
protected $presenter = 'App\Models\Presenters\InvoicePresenter';
protected $hidden = [
@@ -248,92 +251,4 @@ class Invoice extends BaseModel
return $this->settings->design ?: 'pdf.design1';
}
- public function makeInvoiceValues()
- {
- $data = [];
-
- $data['invoice'] = ;
- $data['invoice_date'] = $this->invoice_date;
-// $data['due_date'] = ;
- $data['invoice_number'] = $this->invoice_number;
- $data['po_number'] = $this->po_number;
- // $data['discount'] = ;
- // $data['taxes'] = ;
- // $data['tax'] = ;
- // $data['item'] = ;
- // $data['description'] = ;
- // $data['unit_cost'] = ;
- // $data['quantity'] = ;
- // $data['line_total'] = ;
- // $data['subtotal'] = ;
- // $data['paid_to_date'] = ;
- $data['balance_due'] = Number::formatMoney($this->balance, $this->client->currency, $this->client->country, $this->client->settings);
- $data['partial_due'] = Number::formatMoney($this->partial, $this->client->currency, $this->client->country, $this->client->settings);
- // $data['terms'] = $this->terms;
- // $data['your_invoice'] = ;
- // $data['quote'] = ;
- // $data['your_quote'] = ;
- // $data['quote_date'] = ;
- // $data['quote_number'] = ;
- $data['total'] = Number::formatMoney($this->amount, $this->client->currency, $this->client->country, $this->client->settings);
- // $data['invoice_issued_to'] = ;
- // $data['quote_issued_to'] = ;
- // $data['rate'] = ;
- // $data['hours'] = ;
- // $data['balance'] = ;
- // $data['from'] = ;
- // $data['to'] = ;
- // $data['invoice_to'] = ;
- // $data['quote_to'] = ;
- // $data['details'] = ;
- $data['invoice_no'] = $this->invoice_number;
- // $data['quote_no'] = ;
- // $data['valid_until'] = ;
- $data['client_name'] = $this->present()->clientName();
- $data['address1'] = $this->client->address1;
- $data['address2'] = $this->client->address2;
- $data['id_number'] = $this->client->id_number;
- $data['vat_number'] = $this->client->vat_number;
- $data['city_state_postal'] = ;
- $data['postal_city_state'] = ;
- $data['country'] = ;
- $data['email'] = ;
- $data['contact_nae'] = ;
- $data['company_name'] = ;
- $data['website'] = ;
- $data['phone'] = ;
- $data['blank'] = ;
- $data['surcharge'] = ;
- $data['tax_invoice'] =
- $data['tax_quote'] =
- $data['statement'] = ;
- $data['statement_date'] = ;
- $data['your_statement'] = ;
- $data['statement_issued_to'] = ;
- $data['statement_to'] = ;
- $data['credit_note'] = ;
- $data['credit_date'] = ;
- $data['credit_number'] = ;
- $data['credit_issued_to'] = ;
- $data['credit_to'] = ;
- $data['your_credit'] = ;
- $data['work_phone'] = ;
- $data['invoice_total'] = ;
- $data['outstanding'] = ;
- $data['invoice_due_date'] = ;
- $data['quote_due_date'] = ;
- $data['service'] = ;
- $data['product_key'] = ;
- $data['unit_cost'] = ;
- $data['custom_value1'] = ;
- $data['custom_value2'] = ;
- $data['delivery_note'] = ;
- $data['date'] = ;
- $data['method'] = ;
- $data['payment_date'] = ;
- $data['reference'] = ;
- $data['amount'] = ;
- $data['amount_paid'] =;
- }
-
}
\ No newline at end of file
diff --git a/app/Models/Payment.php b/app/Models/Payment.php
index 977ffef60696..08953ffbea75 100644
--- a/app/Models/Payment.php
+++ b/app/Models/Payment.php
@@ -51,6 +51,10 @@ class Payment extends BaseModel
'transaction_reference'
];
+ protected $casts = [
+ 'settings' => 'object'
+ ];
+
public function client()
{
return $this->belongsTo(Client::class);
diff --git a/app/Models/Presenters/ClientPresenter.php b/app/Models/Presenters/ClientPresenter.php
index b2f301b51fe1..53359f360f8e 100644
--- a/app/Models/Presenters/ClientPresenter.php
+++ b/app/Models/Presenters/ClientPresenter.php
@@ -26,6 +26,11 @@ class ClientPresenter extends EntityPresenter
return $this->entity->name ?: $this->entity->primary_contact->first()->first_name . ' '. $this->entity->primary_contact->first()->last_name;
}
+ public function primary_contact_name()
+ {
+ return $this->entity->primary_contact->first()->first_name . ' '. $this->entity->primary_contact->first()->last_name;;
+ }
+
public function address()
{
$str = '';
diff --git a/app/Models/Presenters/InvoicePresenter.php b/app/Models/Presenters/InvoicePresenter.php
index 72ca95b8aa77..d97ed4c2aceb 100644
--- a/app/Models/Presenters/InvoicePresenter.php
+++ b/app/Models/Presenters/InvoicePresenter.php
@@ -53,7 +53,7 @@ class InvoicePresenter extends EntityPresenter
public function companyName()
{
- return $this->company->present()->name()
+ return $this->company->present()->name();
}
public function companyAddress()
diff --git a/app/Utils/Traits/MakesInvoiceLabels.php b/app/Utils/Traits/MakesInvoiceLabels.php
index 2f7014484eef..c874e9f2ca7b 100644
--- a/app/Utils/Traits/MakesInvoiceLabels.php
+++ b/app/Utils/Traits/MakesInvoiceLabels.php
@@ -150,4 +150,5 @@ trait MakesInvoiceLabels
$data[][$label . '_label'] = ctrans('texts'.$label);
return $data;
- }
\ No newline at end of file
+ }
+}
\ No newline at end of file
diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php
new file mode 100644
index 000000000000..4c7e5bbdde43
--- /dev/null
+++ b/app/Utils/Traits/MakesInvoiceValues.php
@@ -0,0 +1,116 @@
+invoice_date;
+ $data['due_date'] = $this->due_date;
+ $data['invoice_number'] = $this->invoice_number;
+ $data['po_number'] = $this->po_number;
+ // $data['discount'] = ;
+ // $data['taxes'] = ;
+ // $data['tax'] = ;
+ // $data['item'] = ;
+ // $data['description'] = ;
+ // $data['unit_cost'] = ;
+ // $data['quantity'] = ;
+ // $data['line_total'] = ;
+ // $data['subtotal'] = ;
+ // $data['paid_to_date'] = ;
+ $data['balance_due'] = Number::formatMoney($this->balance, $this->client->currency(), $this->client->country, $this->client->settings);
+ $data['partial_due'] = Number::formatMoney($this->partial, $this->client->currency(), $this->client->country, $this->client->settings);
+ $data['terms'] = $this->terms;
+ // $data['your_invoice'] = ;
+ // $data['quote'] = ;
+ // $data['your_quote'] = ;
+ // $data['quote_date'] = ;
+ // $data['quote_number'] = ;
+ $data['total'] = Number::formatMoney($this->amount, $this->client->currency(), $this->client->country, $this->client->settings);
+ // $data['invoice_issued_to'] = ;
+ // $data['quote_issued_to'] = ;
+ // $data['rate'] = ;
+ // $data['hours'] = ;
+ // $data['balance'] = ;
+ // $data['from'] = ;
+ // $data['to'] = ;
+ // $data['invoice_to'] = ;
+ // $data['quote_to'] = ;
+ // $data['details'] = ;
+ $data['invoice_no'] = $this->invoice_number;
+ // $data['quote_no'] = ;
+ // $data['valid_until'] = ;
+ $data['client_name'] = $this->present()->clientName();
+ $data['address1'] = $this->client->address1;
+ $data['address2'] = $this->client->address2;
+ $data['id_number'] = $this->client->id_number;
+ $data['vat_number'] = $this->client->vat_number;
+ $data['city_state_postal'] = $this->present()->cityStateZip($this->client->city, $this->client->state, $this->client->postal_code, FALSE);
+ $data['postal_city_state'] = $this->present()->cityStateZip($this->client->city, $this->client->state, $this->client->postal_code, TRUE);
+ $data['country'] = $this->client->country->name;
+ $data['email'] = isset($this->client->primary_contact()->first()->email) ?: 'no primary contact set';
+ $data['contact_name'] = $this->client->present()->primary_contact_name();
+ $data['company_name'] = $this->company->name;
+ $data['website'] = $this->client->website;
+ $data['phone'] = $this->client->primary_contact->first()->phone;
+ //$data['blank'] = ;
+ //$data['surcharge'] = ;
+ /*
+ $data['tax_invoice'] =
+ $data['tax_quote'] =
+ $data['statement'] = ;
+ $data['statement_date'] = ;
+ $data['your_statement'] = ;
+ $data['statement_issued_to'] = ;
+ $data['statement_to'] = ;
+ $data['credit_note'] = ;
+ $data['credit_date'] = ;
+ $data['credit_number'] = ;
+ $data['credit_issued_to'] = ;
+ $data['credit_to'] = ;
+ $data['your_credit'] = ;
+ $data['work_phone'] = ;
+ $data['invoice_total'] = ;
+ $data['outstanding'] = ;
+ $data['invoice_due_date'] = ;
+ $data['quote_due_date'] = ;
+ $data['service'] = ;
+ $data['product_key'] = ;
+ $data['unit_cost'] = ;
+ $data['custom_value1'] = ;
+ $data['custom_value2'] = ;
+ $data['delivery_note'] = ;
+ $data['date'] = ;
+ $data['method'] = ;
+ $data['payment_date'] = ;
+ $data['reference'] = ;
+ $data['amount'] = ;
+ $data['amount_paid'] =;
+ */
+
+ return $data;
+ }
+
+}
\ No newline at end of file
diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php
index 2c09eca8dc2d..523681561976 100644
--- a/database/seeds/RandomDataSeeder.php
+++ b/database/seeds/RandomDataSeeder.php
@@ -98,12 +98,15 @@ class RandomDataSeeder extends Seeder
factory(\App\Models\Product::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id]);
/** Invoice Factory */
- factory(\App\Models\Invoice::class,500)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
+ factory(\App\Models\Invoice::class,500)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]);
/** Recurring Invoice Factory */
factory(\App\Models\RecurringInvoice::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
- factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]);
+ // factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]);
+
+ factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
+
$clients = Client::all();
diff --git a/resources/views/pdf/design1.blade.php b/resources/views/pdf/design1.blade.php
index b36d65722faf..65fc37434599 100644
--- a/resources/views/pdf/design1.blade.php
+++ b/resources/views/pdf/design1.blade.php
@@ -139,6 +139,23 @@
John Doe
john@example.com
+
+