diff --git a/app/Helpers/Invoice/InvoiceItemCalc.php b/app/Helpers/Invoice/InvoiceItemCalc.php index 09e6edaa35..879de4c5a6 100644 --- a/app/Helpers/Invoice/InvoiceItemCalc.php +++ b/app/Helpers/Invoice/InvoiceItemCalc.php @@ -45,7 +45,7 @@ class InvoiceItemCalc public function process() { - $this->line_total = $this->formatValue($this->item->cost, $this->settings->precision) * $this->formatValue($this->item->qty, $this->settings->precision); + $this->line_total = $this->formatValue($this->item->cost, $this->settings->precision) * $this->formatValue($this->item->quantity, $this->settings->precision); $this->setDiscount() ->calcTaxes(); diff --git a/app/Models/Presenters/ClientPresenter.php b/app/Models/Presenters/ClientPresenter.php index 53359f360f..5f35521b97 100644 --- a/app/Models/Presenters/ClientPresenter.php +++ b/app/Models/Presenters/ClientPresenter.php @@ -28,7 +28,7 @@ class ClientPresenter extends EntityPresenter public function primary_contact_name() { - return $this->entity->primary_contact->first()->first_name . ' '. $this->entity->primary_contact->first()->last_name;; + return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->first_name . ' '. $this->entity->primary_contact->first()->last_name : 'No primary contact set'; } public function address() @@ -73,6 +73,13 @@ class ClientPresenter extends EntityPresenter return $str; } + public function phone() + { + return $this->entity->phone ?: ''; + } - + public function website() + { + return $this->entity->website ?: ''; + } } diff --git a/app/Transformers/InvoiceItemTransformer.php b/app/Transformers/InvoiceItemTransformer.php index 29e43f5859..f4642f2185 100644 --- a/app/Transformers/InvoiceItemTransformer.php +++ b/app/Transformers/InvoiceItemTransformer.php @@ -23,7 +23,7 @@ class InvoiceItemTransformer extends EntityTransformer 'archived_at' => $item->deleted_at, 'notes' => $item->notes, 'cost' => (float) $item->cost, - 'qty' => (float) ($item->qty ?: 0.0), + 'quantity' => (float) ($item->quantity ?: 0.0), 'tax_name1' => $item->tax_name1 ? $item->tax_name1 : '', 'tax_rate1' => (float) ($item->tax_rate1 ?: 0.0), 'tax_name2' => $item->tax_name2 ? $item->tax_name2 : '', diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index c5cd80214a..8af7bf5283 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -20,6 +20,24 @@ use Illuminate\Support\Facades\Log; */ trait MakesInvoiceValues { + + + private static $master_columns = [ + 'date', + 'discount', + 'product_key', + 'notes', + 'cost', + 'quantity', + 'tax_name1', + 'tax_name2', + 'line_total', + 'custom_label1', + 'custom_label2', + 'custom_label3', + 'custom_label4', + ]; + private static $labels = [ 'invoice', 'invoice_date', @@ -115,7 +133,7 @@ trait MakesInvoiceValues $data = []; foreach(self::$labels as $label) - $data[][$label . '_label'] = ctrans('texts'.$label); + $data[$label . '_label'] = ctrans('texts.'.$label); return $data; } @@ -177,8 +195,8 @@ trait MakesInvoiceValues $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['website'] = $this->client->present()->website(); + $data['phone'] = $this->client->present()->phone(); //$data['blank'] = ; //$data['surcharge'] = ; /* @@ -224,45 +242,82 @@ trait MakesInvoiceValues * * @return string[HTML string */ - public function table(array $columns) :string + public function table(array $columns) :?string { $data = ''; $data .= ''; - foreach($columns as $column) - $data .= ''; + $column_headers = $this->transformColumnsForHeader($columns); + + foreach($column_headers as $column) + $data .= ''; $data .= ''; - $columns = $this->transformColumns($columns); + $columns = $this->transformColumnsForLineItems($columns); $items = $this->transformLineItems($this->line_items); foreach($items as $item) { - - $data .= ''; - foreach($columns as $column) - $data .= ''; + $data .= ''; - $data .= ''; + foreach($columns as $column) + { + + $data .= ''; + + } + $data .= ''; } $data .= '
' . ctrans('texts.column') . '' . ctrans('texts.'.$column.'') . '
'. $item->{$column} . '
'. $item->{$column} . '
'; + + return $data; } + /** + * + * Transform the column headers into translated header values + * + * @param array $columns The column header values + * @return array The new column header variables + */ + private function transformColumnsForHeader(array $columns) :array + { + + $columns = array_intersect(self::$master_columns, $columns); + + return str_replace([ + 'tax_name1', + 'tax_name2' + ], + [ + 'tax', + 'tax', + ], + $columns); + + } + + + /** + * * Transform the column headers into invoice variables + * * @param array $columns The column header values * @return array The invoice variables */ - private function transformColumns(array $columns) :array + private function transformColumnsForLineItems(array $columns) :array { - + /* Removes any invalid columns the user has entered. */ + $columns = array_intersect(self::$master_columns, $columns); + return str_replace([ 'custom_invoice_label1', 'custom_invoice_label2', @@ -294,18 +349,18 @@ trait MakesInvoiceValues foreach($items as $item) { - $item->cost = Number::formatMoney($item->cost, $this->client->currency(), $this->client->country, $this->client->getMergedSettings); - $item->line_total = Number::formatMoney($item->line_total, $this->client->currency(), $this->client->country, $this->client->getMergedSettings); + $item->cost = Number::formatMoney($item->cost, $this->client->currency(), $this->client->country, $this->client->getMergedSettings()); + $item->line_total = Number::formatMoney($item->line_total, $this->client->currency(), $this->client->country, $this->client->getMergedSettings()); if(isset($item->discount) && $item->discount > 0) { if($item->is_amount_discount) - $item->discount = Number::formatMoney($item->discount, $this->client->currency(), $this->client->country, $this->client->getMergedSettings); + $item->discount = Number::formatMoney($item->discount, $this->client->currency(), $this->client->country, $this->client->getMergedSettings()); else $item->discount = $item->discount . '%'; } - + } diff --git a/resources/views/pdf/design1.blade.php b/resources/views/pdf/design1.blade.php index 24adadbad9..09f2dd4d88 100644 --- a/resources/views/pdf/design1.blade.php +++ b/resources/views/pdf/design1.blade.php @@ -115,9 +115,9 @@ - Invoice #: {{ $invoice->invoice_number }}
- Created: {{ $invoice->invoice_date }}
- Due: {{ $invoice->due_date }} + {{$invoice_number_label}}: {{ $invoice->invoice_number }}
+ {{$invoice_date_label}}: {{ $invoice->invoice_date }}
+ {{$invoice_due_date_label}}: {{ $invoice->due_date }} @@ -129,33 +129,21 @@ -
- Sparksuite, Inc.
- 12345 Sunny Road
- Sunnyville, CA 12345 + {{$client_name}}
+ {{$address1}}
+ {{$address2}}
+ {{$city_state_postal}}
+ {{$country}}
+ {{$vat_number}}
+
- Acme Corp.
- John Doe
- john@example.com + {{$company_name}}
+ {{$phone}}
+ {{$email}}
- {{$client_name}}
- {{$address1}}
- {{$address2}}
- {{$id_number}}
- {{$vat_number}}
- {{$city_state_postal}}
- {{$postal_city_state}}
- {{$country}}
- {{$email}}
- {{$contact_name}}
- {{$company_name}}
- {{$website}}
- {{$phone}}
- {{$terms}}
-
@@ -167,7 +155,6 @@ date discount product_key - item notes cost quantity @@ -179,301 +166,10 @@ custom_label3 ( will show as the following parameter as its value -> custom_invoice_value3 ) custom_label4 ( will show as the following parameter as its value -> custom_invoice_value4 ) --}} - {{ $invoice->table(['item','description','cost','quantity', 'tax_name1', 'line_total']) }} + {!! $invoice->table(['product_key', 'notes', 'cost','quantity', 'line_total']) !!} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
- Item - - Price -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Website design - - $300.00 -
- Hosting (3 months) - - $75.00 -
- Domain name (1 year) - - $10.00 -
diff --git a/tests/Feature/InvoiceTest.php b/tests/Feature/InvoiceTest.php index 112a7ac31a..a28ba37b82 100644 --- a/tests/Feature/InvoiceTest.php +++ b/tests/Feature/InvoiceTest.php @@ -46,8 +46,8 @@ class InvoiceTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'name' => $this->faker->company, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1,