mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor context['product-table-columns'] to generic pdf_variables:
- Pass 'pdf_variables' to CreateQuotePdf & CreateInvoicPdf - Update Playful & Plain to support new variable engine - Update DesignHelpers trait to support new variable engine - Make tests pass for ExampleIntegrationTest
This commit is contained in:
parent
ba41e22b3b
commit
23577a5f0f
@ -90,13 +90,11 @@ class CreateInvoicePdf implements ShouldQueue
|
||||
|
||||
$design_class = new $design_namespace();
|
||||
|
||||
$pdf_variables = json_decode(json_encode($this->invoice->company->settings->pdf_variables), 1);
|
||||
|
||||
$state = [
|
||||
'template' => $design_class->elements([
|
||||
'client' => $this->invoice->client,
|
||||
'entity' => $this->invoice,
|
||||
'product-table-columns' => $pdf_variables['product_columns'],
|
||||
'pdf_variables' => (array)$this->invoice->company->settings->pdf_variables,
|
||||
]),
|
||||
'variables' => $html->generateLabelsAndValues(),
|
||||
];
|
||||
|
@ -94,7 +94,7 @@ class CreateQuotePdf implements ShouldQueue
|
||||
'template' => $design_class->elements([
|
||||
'client' => $this->quote->client,
|
||||
'entity' => $this->quote,
|
||||
'product-table-columns' => $pdf_variables['product_columns'],
|
||||
'pdf_variables' => (array)$this->quote->company->settings->pdf_variables,
|
||||
]),
|
||||
'variables' => $html->generateLabelsAndValues(),
|
||||
];
|
||||
|
@ -78,7 +78,7 @@ class Plain extends BaseDesign
|
||||
|
||||
public function companyAddress(): array
|
||||
{
|
||||
$variables = $this->entity->company->settings->pdf_variables->company_address;
|
||||
$variables = $this->context['pdf_variables']['company_address'];
|
||||
|
||||
$elements = [];
|
||||
|
||||
@ -91,10 +91,10 @@ class Plain extends BaseDesign
|
||||
|
||||
public function entityDetails(): array
|
||||
{
|
||||
$variables = $this->entity->company->settings->pdf_variables->invoice_details;
|
||||
$variables = $this->context['pdf_variables']['invoice_details'];
|
||||
|
||||
if ($this->entity instanceof \App\Models\Quote) {
|
||||
$variables = $this->entity->company->settings->pdf_variables->quote_details;
|
||||
$variables = $this->context['pdf_variables']['quote_details'];
|
||||
}
|
||||
|
||||
$elements = [];
|
||||
@ -113,7 +113,7 @@ class Plain extends BaseDesign
|
||||
|
||||
public function clientDetails(): array
|
||||
{
|
||||
$variables = $this->entity->company->settings->pdf_variables->client_details;
|
||||
$variables = $this->context['pdf_variables']['client_details'];
|
||||
|
||||
$elements = [];
|
||||
|
||||
@ -166,7 +166,7 @@ class Plain extends BaseDesign
|
||||
|
||||
$elements = [];
|
||||
|
||||
foreach ($this->context['product-table-columns'] as $column) {
|
||||
foreach ($this->context['pdf_variables']['product_columns'] as $column) {
|
||||
$elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'px-4 py-2']];
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ class Plain extends BaseDesign
|
||||
foreach ($items as $row) {
|
||||
$element = ['element' => 'tr', 'content' => '', 'elements' => []];
|
||||
|
||||
foreach ($this->context['product-table-columns'] as $key => $cell) {
|
||||
foreach ($this->context['pdf_variables']['product_columns'] as $key => $cell) {
|
||||
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'border-t-2 border-b border-gray-200 px-4 py-4']];
|
||||
}
|
||||
|
||||
|
@ -82,10 +82,10 @@ class Playful extends BaseDesign
|
||||
|
||||
public function entityDetails(): array
|
||||
{
|
||||
$variables = $this->entity->company->settings->pdf_variables->invoice_details;
|
||||
$variables = $this->context['pdf_variables']['invoice_details'];
|
||||
|
||||
if ($this->entity instanceof \App\Models\Quote) {
|
||||
$variables = $this->entity->company->settings->pdf_variables->quote_details;
|
||||
$variables = $this->context['pdf_variables']['quote_details'];
|
||||
}
|
||||
|
||||
$elements = [];
|
||||
@ -102,7 +102,7 @@ class Playful extends BaseDesign
|
||||
|
||||
public function companyDetails()
|
||||
{
|
||||
$variables = $this->entity->company->settings->pdf_variables->company_details;
|
||||
$variables = $this->context['pdf_variables']['company_details'];
|
||||
|
||||
$elements = [];
|
||||
|
||||
@ -115,7 +115,7 @@ class Playful extends BaseDesign
|
||||
|
||||
public function companyAddress(): array
|
||||
{
|
||||
$variables = $this->entity->company->settings->pdf_variables->company_address;
|
||||
$variables = $this->context['pdf_variables']['company_address'];
|
||||
|
||||
$elements = [];
|
||||
|
||||
@ -128,7 +128,7 @@ class Playful extends BaseDesign
|
||||
|
||||
public function clientDetails(): array
|
||||
{
|
||||
$variables = $this->entity->company->settings->pdf_variables->client_details;
|
||||
$variables = $this->context['pdf_variables']['client_details'];
|
||||
|
||||
$elements = [];
|
||||
|
||||
@ -154,7 +154,7 @@ class Playful extends BaseDesign
|
||||
|
||||
$elements = [];
|
||||
|
||||
foreach ($this->context['product-table-columns'] as $column) {
|
||||
foreach ($this->context['pdf_variables']['product_columns'] as $column) {
|
||||
$elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'font-semibold text-white px-4 py-3']];
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ class Playful extends BaseDesign
|
||||
foreach ($items as $row) {
|
||||
$element = ['element' => 'tr', 'properties' => ['class' => 'border-b-2 border-teal-600'], 'content' => '', 'elements' => []];
|
||||
|
||||
foreach ($this->context['product-table-columns'] as $key => $cell) {
|
||||
foreach ($this->context['pdf_variables']['product_columns'] as $key => $cell) {
|
||||
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'px-4 py-4']];
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ trait DesignHelpers
|
||||
*/
|
||||
public function processTaxColumns(): void
|
||||
{
|
||||
if (in_array('$product.tax', $this->context['product-table-columns'])) {
|
||||
if (in_array('$product.tax', (array)$this->context['pdf_variables']['product_columns'])) {
|
||||
$line_items = collect($this->entity->line_items);
|
||||
|
||||
$tax1 = $line_items->where('tax_name1', '<>', '')->where('type_id', 1)->count();
|
||||
@ -116,10 +116,10 @@ trait DesignHelpers
|
||||
array_push($taxes, '$product.tax_rate3');
|
||||
}
|
||||
|
||||
$key = array_search('$product.tax', $this->context['product-table-columns'], true);
|
||||
$key = array_search('$product.tax', $this->context['pdf_variables']['product_columns'], true);
|
||||
|
||||
if ($key) {
|
||||
array_splice($this->context['product-table-columns'], $key, 1, $taxes);
|
||||
array_splice($this->context['pdf_variables']['product_columns'], $key, 1, $taxes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,7 +132,7 @@ trait DesignHelpers
|
||||
*/
|
||||
public function calculateColspan(int $taken): int
|
||||
{
|
||||
$total = (int) count($this->context['product-table-columns']);
|
||||
$total = (int) count($this->context['pdf_variables']['product_columns']);
|
||||
|
||||
return (int)$total - $taken;
|
||||
}
|
||||
@ -177,16 +177,16 @@ trait DesignHelpers
|
||||
}
|
||||
|
||||
if (is_null($this->entity->{$_variable})) {
|
||||
// info("{$this->entity->id} $_variable is null!");
|
||||
// info("{$this->entity->id} $_variable is null!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (empty($this->entity->{$_variable})) {
|
||||
// info("{$this->entity->id} $_variable is empty!");
|
||||
// info("{$this->entity->id} $_variable is empty!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// info("{$this->entity->id} $_variable ALL GOOD!!");
|
||||
// info("{$this->entity->id} $_variable ALL GOOD!!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,11 @@ class ExampleIntegrationTest extends TestCase
|
||||
$engine = new HtmlEngine(null, $invitation, 'invoice');
|
||||
$design = new Playful();
|
||||
|
||||
$product_table_columns = json_decode(
|
||||
json_encode($invoice->company->settings->pdf_variables),
|
||||
1
|
||||
)['product_columns'];
|
||||
|
||||
$state = [
|
||||
'template' => $design->elements([
|
||||
'client' => $invoice->client,
|
||||
'entity' => $invoice,
|
||||
'product-table-columns' => $product_table_columns,
|
||||
'pdf_variables' => (array)$invoice->company->settings->pdf_variables,
|
||||
]),
|
||||
'variables' => $engine->generateLabelsAndValues(),
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user