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 = '
' . ctrans('texts.column') . ' | '; + $column_headers = $this->transformColumnsForHeader($columns); + + foreach($column_headers as $column) + $data .= '' . ctrans('texts.'.$column.'') . ' | '; $data .= '
'. $item->{$column} . ' | '; + $data .= '|
'. $item->{$column} . ' | '; + + } + $data .= ''; } $data .= '
- 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}} - |
- 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, |