From 47cdeef25816598857d443c1995e8813d546f768 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 3 Sep 2019 09:00:52 +1000 Subject: [PATCH] Working on building dynamic tables for invoices --- .../Requests/Invoice/UpdateInvoiceRequest.php | 2 +- app/Listeners/Invoice/CreateInvoicePdf.php | 8 +- app/Models/Invoice.php | 2 - app/Utils/Traits/MakesInvoiceLabels.php | 154 ------------------ app/Utils/Traits/MakesInvoiceValues.php | 138 +++++++++++++++- resources/views/pdf/design1.blade.php | 10 ++ 6 files changed, 149 insertions(+), 165 deletions(-) delete mode 100644 app/Utils/Traits/MakesInvoiceLabels.php diff --git a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php index 596a86dba952..f6e79f5cde3d 100644 --- a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php +++ b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php @@ -35,7 +35,7 @@ class UpdateInvoiceRequest extends Request { return [ 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', - 'client_id' => 'required|integer', + //'client_id' => 'required|integer', //'invoice_type_id' => 'integer', ]; } diff --git a/app/Listeners/Invoice/CreateInvoicePdf.php b/app/Listeners/Invoice/CreateInvoicePdf.php index 53c0fdd0bc30..a93491551def 100644 --- a/app/Listeners/Invoice/CreateInvoicePdf.php +++ b/app/Listeners/Invoice/CreateInvoicePdf.php @@ -18,7 +18,7 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Spatie\Browsershot\Browsershot; -class CreateInvoicePdf +class CreateInvoicePdf implements ShouldQueue { protected $activity_repo; /** @@ -89,11 +89,7 @@ class CreateInvoicePdf private function generateInvoiceHtml($design, $invoice) :string { - $data['invoice'] = $invoice; - - $template_variables = array_merge($invoice->makeLabels(), $invoice->makeValues()); - - return view($design, array_merge($data, $template_variables))->render(); + return view($design, array_merge($invoice->makeLabels(), $invoice->makeValues()))->render(); } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index a1b9c5015f42..e962cd363c08 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -15,7 +15,6 @@ 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; @@ -32,7 +31,6 @@ class Invoice extends BaseModel use MakesDates; use PresentableTrait; use MakesInvoiceValues; - use MakesInvoiceLabels; protected $presenter = 'App\Models\Presenters\InvoicePresenter'; protected $hidden = [ diff --git a/app/Utils/Traits/MakesInvoiceLabels.php b/app/Utils/Traits/MakesInvoiceLabels.php deleted file mode 100644 index c874e9f2ca7b..000000000000 --- a/app/Utils/Traits/MakesInvoiceLabels.php +++ /dev/null @@ -1,154 +0,0 @@ -invoice_date; $data['due_date'] = $this->due_date; $data['invoice_number'] = $this->invoice_number; @@ -113,4 +217,34 @@ trait MakesInvoiceValues return $data; } + /** + * Returns a formatted HTML table of invoice line items + * + * @param array $columns The columns to be displayed + * + * @return string[HTML string + */ + public function table(array $columns) :string + { + $data = ''; + + $data .= ''; + + foreach($columns as $column) + $data .= ''; + + $data .= ''; + + foreach($this->line_items as $item) + { + $data .= ''; + + foreach($columns as $column) + $data .= ''; + + $data .= ''; + } + $data .= '
' . ctrans('texts.column') . '
{$item->column}
'; + } + } \ No newline at end of file diff --git a/resources/views/pdf/design1.blade.php b/resources/views/pdf/design1.blade.php index 65fc37434599..cfa3b5a410b7 100644 --- a/resources/views/pdf/design1.blade.php +++ b/resources/views/pdf/design1.blade.php @@ -161,6 +161,16 @@ + {{-- + column variables: + item + description + cost + quantity + taxes + subtotal + --}} + {{ $invoice->table(['item','description','cost','quantity', 'taxes', 'subtotal']) }}