1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Working on data feeds for templates

This commit is contained in:
David Bomba 2023-10-03 16:38:36 +11:00
parent af27f39ba1
commit 69400c8371
4 changed files with 38 additions and 13 deletions

View File

@ -202,6 +202,8 @@ class PdfMock
'$company.postal_city_state' => 'CA',
'$company.postal_city' => '90210, CA',
'$product.gross_line_total' => '100',
'$client.classification' => 'Individual',
'$company.classification' => 'Business',
'$client.postal_city_state' => '11243 Aufderharchester, North Carolina',
'$client.postal_city' => '11243 Aufderharchester, North Carolina',
'$client.shipping_address1' => '453',
@ -509,6 +511,8 @@ class PdfMock
'$client.billing_postal_code_label' => ctrans('texts.billing_postal_code'),
'$company.postal_city_state_label' => ctrans('texts.postal_city_state'),
'$company.city_state_postal_label' => ctrans('texts.city_state_postal'),
'$client.classification_label' => ctrans('texts.classification'),
'$company.classification_label' => ctrans('texts.classification'),
'$product.gross_line_total_label' => ctrans('texts.gross_line_total'),
'$client.shipping_address1_label' => ctrans('texts.shipping_address1'),
'$client.postal_city_state_label' => ctrans('texts.postal_city_state'),

File diff suppressed because one or more lines are too long

View File

@ -14,6 +14,7 @@ namespace App\Services\Template;
use App\Models\Task;
use App\Models\Quote;
use App\Utils\Number;
use App\Models\Client;
use App\Models\Credit;
use App\Models\Design;
use App\Models\Company;
@ -162,16 +163,10 @@ class TemplateService
}
$template = $template->render($this->data);
nlog($template);
$f = $this->document->createDocumentFragment();
// nlog($template);
// $f->appendChild(html_entity_decode($template));
// $template = html_entity_decode(htmlentities($template, ENT_QUOTES, 'UTF-8'));
// $f->appendXML(html_encode$template);
$f->appendXML(html_entity_decode($template));
// $f->appendChild($this->document->createTextNode($template));
$f->appendXML(html_entity_decode($template));
$replacements[] = $f;
}
@ -368,7 +363,7 @@ $f->appendXML(html_entity_decode($template));
'custom_surcharge_tax2' => (bool) $invoice->custom_surcharge_tax2,
'custom_surcharge_tax3' => (bool) $invoice->custom_surcharge_tax3,
'custom_surcharge_tax4' => (bool) $invoice->custom_surcharge_tax4,
'line_items' => $invoice->line_items ?: (array) [],
'line_items' => $invoice->line_items ? $this->padLineItems($invoice->line_items, $invoice->client): (array) [],
'reminder1_sent' => $this->translateDate($invoice->reminder1_sent, $invoice->client->date_format(), $invoice->client->locale()),
'reminder2_sent' => $this->translateDate($invoice->reminder2_sent, $invoice->client->date_format(), $invoice->client->locale()),
'reminder3_sent' => $this->translateDate($invoice->reminder3_sent, $invoice->client->date_format(), $invoice->client->locale()),
@ -386,11 +381,36 @@ $f->appendXML(html_entity_decode($template));
});
nlog($invoices->count());
return $invoices->toArray();
}
public function padLineItems(array $items, Client $client): array
{
return collect($items)->map(function ($item) use ($client){
$item->cost_raw = $item->cost;
$item->discount_raw = $item->discount;
$item->line_total_raw = $item->line_total;
$item->gross_line_total_raw = $item->gross_line_total;
$item->tax_amount_raw = $item->tax_amount;
$item->product_cost_raw = $item->product_cost;
$item->cost = Number::formatMoney($item->cost_raw, $client);
if($item->is_amount_discount)
$item->discount = Number::formatMoney($item->discount_raw, $client);
$item->line_total = Number::formatMoney($item->line_total_raw, $client);
$item->gross_line_total = Number::formatMoney($item->gross_line_total_raw, $client);
$item->tax_amount = Number::formatMoney($item->tax_amount_raw, $client);
$item->product_cost = Number::formatMoney($item->product_cost_raw, $client);
return $item;
})->toArray();
}
public function processInvoicesBak($invoices): array
{
$it = new InvoiceTransformer();

View File

@ -459,7 +459,7 @@ class HtmlEngine
$data['$client.postal_city'] = &$data['$postal_city'];
$data['$client.country'] = &$data['$country'];
$data['$client.email'] = &$data['$email'];
$data['$client.classification'] = ['value' => isset($this->client->classification) ? ctrans("texts.{$this->client->classification}") : ' ', 'label' => ctrans('texts.classification')];
$data['$client.billing_address'] = &$data['$client_address'];
$data['$client.billing_address1'] = &$data['$client.address1'];
$data['$client.billing_address2'] = &$data['$client.address2'];
@ -515,6 +515,7 @@ class HtmlEngine
$data['$company.postal_city_state'] = ['value' => $this->company->present()->cityStateZip($this->settings->city, $this->settings->state, $this->settings->postal_code, true) ?: ' ', 'label' => ctrans('texts.postal_city_state')];
$data['$company.postal_city'] = ['value' => $this->company->present()->cityStateZip($this->settings->city, null, $this->settings->postal_code, true) ?: ' ', 'label' => ctrans('texts.postal_city')];
$data['$company.name'] = ['value' => $this->settings->name ?: ctrans('texts.untitled_account'), 'label' => ctrans('texts.company_name')];
$data['$company.classification'] = ['value' => ($this->settings->classification ?? false) ? ctrans("texts.{$this->settings->classification}") : ' ', 'label' => ctrans('texts.classification')];
$data['$account'] = &$data['$company.name'];
$data['$company.address1'] = ['value' => $this->settings->address1 ?: ' ', 'label' => ctrans('texts.address1')];