mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on building dynamic tables for invoices
This commit is contained in:
parent
d99443806a
commit
47cdeef258
@ -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',
|
||||
];
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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 = [
|
||||
|
@ -1,154 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Utils\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class MakesInvoiceLabels
|
||||
* @package App\Utils\Traits
|
||||
*/
|
||||
trait MakesInvoiceLabels
|
||||
{
|
||||
private static $labels = [
|
||||
'invoice',
|
||||
'invoice_date',
|
||||
'due_date',
|
||||
'invoice_number',
|
||||
'po_number',
|
||||
'discount',
|
||||
'taxes',
|
||||
'tax',
|
||||
'item',
|
||||
'description',
|
||||
'unit_cost',
|
||||
'quantity',
|
||||
'line_total',
|
||||
'subtotal',
|
||||
'paid_to_date',
|
||||
'balance_due',
|
||||
'partial_due',
|
||||
'terms',
|
||||
'your_invoice',
|
||||
'quote',
|
||||
'your_quote',
|
||||
'quote_date',
|
||||
'quote_number',
|
||||
'total',
|
||||
'invoice_issued_to',
|
||||
'quote_issued_to',
|
||||
'rate',
|
||||
'hours',
|
||||
'balance',
|
||||
'from',
|
||||
'to',
|
||||
'invoice_to',
|
||||
'quote_to',
|
||||
'details',
|
||||
'invoice_no',
|
||||
'quote_no',
|
||||
'valid_until',
|
||||
'client_name',
|
||||
'address1',
|
||||
'address2',
|
||||
'id_number',
|
||||
'vat_number',
|
||||
'city_state_postal',
|
||||
'postal_city_state',
|
||||
'country',
|
||||
'email',
|
||||
'contact_name',
|
||||
'company_name',
|
||||
'website',
|
||||
'phone',
|
||||
'blank',
|
||||
'surcharge',
|
||||
'tax_invoice',
|
||||
'tax_quote',
|
||||
'statement',
|
||||
'statement_date',
|
||||
'your_statement',
|
||||
'statement_issued_to',
|
||||
'statement_to',
|
||||
'credit_note',
|
||||
'credit_date',
|
||||
'credit_number',
|
||||
'credit_issued_to',
|
||||
'credit_to',
|
||||
'your_credit',
|
||||
'work_phone',
|
||||
'invoice_total',
|
||||
'outstanding',
|
||||
'invoice_due_date',
|
||||
'quote_due_date',
|
||||
'service',
|
||||
'product_key',
|
||||
'unit_cost',
|
||||
'custom_value1',
|
||||
'custom_value2',
|
||||
'delivery_note',
|
||||
'date',
|
||||
'method',
|
||||
'payment_date',
|
||||
'reference',
|
||||
'amount',
|
||||
'amount_paid',
|
||||
];
|
||||
|
||||
public function invoice_number_label()
|
||||
{
|
||||
return ctrans('texts.invoice_number');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a single translated string which
|
||||
* has been appended with _label
|
||||
*
|
||||
* Used for design templates where we need both
|
||||
* the value and its _label
|
||||
*
|
||||
* ie: $invoice_number and $invoice_number_label
|
||||
*
|
||||
*
|
||||
* @param string $label The label to translate
|
||||
*
|
||||
* @return string The translated label
|
||||
*/
|
||||
public function makeLabel(string $label) :string
|
||||
{
|
||||
|
||||
if (in_array(str_replace("_label", "", $label), self::$labels))
|
||||
{
|
||||
return ctrans('texts.' . $label);
|
||||
}
|
||||
else
|
||||
return 'label does not exist';
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates and translates all labels
|
||||
*
|
||||
* @return array returns an array of keyed labels (appended with _label)
|
||||
*/
|
||||
public function makeLabels() : array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
foreach(self::$labels as $label)
|
||||
$data[][$label . '_label'] = ctrans('texts'.$label);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -20,12 +20,116 @@ use Illuminate\Support\Facades\Log;
|
||||
*/
|
||||
trait MakesInvoiceValues
|
||||
{
|
||||
private static $labels = [
|
||||
'invoice',
|
||||
'invoice_date',
|
||||
'due_date',
|
||||
'invoice_number',
|
||||
'po_number',
|
||||
'discount',
|
||||
'taxes',
|
||||
'tax',
|
||||
'item',
|
||||
'description',
|
||||
'unit_cost',
|
||||
'quantity',
|
||||
'line_total',
|
||||
'subtotal',
|
||||
'paid_to_date',
|
||||
'balance_due',
|
||||
'partial_due',
|
||||
'terms',
|
||||
'your_invoice',
|
||||
'quote',
|
||||
'your_quote',
|
||||
'quote_date',
|
||||
'quote_number',
|
||||
'total',
|
||||
'invoice_issued_to',
|
||||
'quote_issued_to',
|
||||
'rate',
|
||||
'hours',
|
||||
'balance',
|
||||
'from',
|
||||
'to',
|
||||
'invoice_to',
|
||||
'quote_to',
|
||||
'details',
|
||||
'invoice_no',
|
||||
'quote_no',
|
||||
'valid_until',
|
||||
'client_name',
|
||||
'address1',
|
||||
'address2',
|
||||
'id_number',
|
||||
'vat_number',
|
||||
'city_state_postal',
|
||||
'postal_city_state',
|
||||
'country',
|
||||
'email',
|
||||
'contact_name',
|
||||
'company_name',
|
||||
'website',
|
||||
'phone',
|
||||
'blank',
|
||||
'surcharge',
|
||||
'tax_invoice',
|
||||
'tax_quote',
|
||||
'statement',
|
||||
'statement_date',
|
||||
'your_statement',
|
||||
'statement_issued_to',
|
||||
'statement_to',
|
||||
'credit_note',
|
||||
'credit_date',
|
||||
'credit_number',
|
||||
'credit_issued_to',
|
||||
'credit_to',
|
||||
'your_credit',
|
||||
'work_phone',
|
||||
'invoice_total',
|
||||
'outstanding',
|
||||
'invoice_due_date',
|
||||
'quote_due_date',
|
||||
'service',
|
||||
'product_key',
|
||||
'unit_cost',
|
||||
'custom_value1',
|
||||
'custom_value2',
|
||||
'delivery_note',
|
||||
'date',
|
||||
'method',
|
||||
'payment_date',
|
||||
'reference',
|
||||
'amount',
|
||||
'amount_paid',
|
||||
];
|
||||
|
||||
public function makeValues()
|
||||
/**
|
||||
* Iterates and translates all labels
|
||||
*
|
||||
* @return array returns an array of keyed labels (appended with _label)
|
||||
*/
|
||||
public function makeLabels() :array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
foreach(self::$labels as $label)
|
||||
$data[][$label . '_label'] = ctrans('texts'.$label);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms all placeholders to invoice values
|
||||
*
|
||||
* @return array returns an array of keyed labels (appended with _label)
|
||||
*/
|
||||
public function makeValues() :array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
//$data['invoice'] = ;
|
||||
$data['invoice'] = $this;
|
||||
$data['invoice_date'] = $this->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 = '<table class="table table-hover table-striped">';
|
||||
|
||||
$data .= '<thead><tr class="heading">';
|
||||
|
||||
foreach($columns as $column)
|
||||
$data .= '<td>' . ctrans('texts.column') . '</td>';
|
||||
|
||||
$data .= '</tr></thead>';
|
||||
|
||||
foreach($this->line_items as $item)
|
||||
{
|
||||
$data .= '<tr class="item">';
|
||||
|
||||
foreach($columns as $column)
|
||||
$data .= '<td>{$item->column}</td>';
|
||||
|
||||
$data .= '</tr>';
|
||||
}
|
||||
$data .= '</table>';
|
||||
}
|
||||
|
||||
}
|
@ -161,6 +161,16 @@
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{{--
|
||||
column variables:
|
||||
item
|
||||
description
|
||||
cost
|
||||
quantity
|
||||
taxes
|
||||
subtotal
|
||||
--}}
|
||||
{{ $invoice->table(['item','description','cost','quantity', 'taxes', 'subtotal']) }}
|
||||
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user