Tweak values for show/hide shipping

This commit is contained in:
David Bomba 2025-01-29 14:26:15 +11:00
parent 09dffc6920
commit b607493b94
3 changed files with 56 additions and 48 deletions

View File

@ -20,15 +20,12 @@ use App\Models\Credit;
use App\Models\Design;
use App\Models\Invoice;
use App\Models\Payment;
use App\Services\PdfMaker\Design as PdfMakerDesign;
use App\Services\PdfMaker\PdfMaker;
use App\Utils\HostedPDF\NinjaPdf;
use App\Utils\HtmlEngine;
use App\Utils\Number;
use App\Utils\PhantomJS\Phantom;
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\Pdf\PdfMaker as PdfMakerTrait;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;

View File

@ -67,60 +67,66 @@ class GenerateDeliveryNote
// return (new \App\Services\Pdf\PdfService($invitation, 'delivery_note'))->boot()->getPdf();
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
return (new Phantom())->generate($this->invoice->invitations->first());
}
// if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
// return (new Phantom())->generate($this->invoice->invitations->first());
// }
$design = Design::withTrashed()->find($design_id);
$html = new HtmlEngine($invitation);
if ($design->is_custom) {
$options = ['custom_partials' => json_decode(json_encode($design->design), true)];
$template = new PdfMakerDesign(PdfMakerDesign::CUSTOM, $options);
} else {
$template = new PdfMakerDesign(strtolower($design->name));
}
$variables = $html->generateLabelsAndValues();
$variables['labels']['$entity_label'] = ctrans('texts.delivery_note');
$variables['labels']['$invoice.date_label'] = ctrans('texts.date');
$variables['labels']['$invoice.number_label'] = ctrans('texts.number');
$ps = new \App\Services\Pdf\PdfService($invitation, 'delivery_note');
return $ps->boot()->getPdf();
$state = [
'template' => $template->elements([
'client' => $this->invoice->client,
'entity' => $this->invoice,
'pdf_variables' => (array) $this->invoice->company->settings->pdf_variables,
'contact' => $this->contact,
], 'delivery_note'),
'variables' => $variables,
'options' => [
'client' => $this->invoice->client,
'entity' => $this->invoice,
'contact' => $this->contact,
],
'process_markdown' => $this->invoice->client->company->markdown_enabled,
];
$maker = new PdfMakerService($state);
$maker
->design($template)
->build();
// $html = new HtmlEngine($invitation);
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
} else {
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML());
}
// if ($design->is_custom) {
// $options = ['custom_partials' => json_decode(json_encode($design->design), true)];
// $template = new PdfMakerDesign(PdfMakerDesign::CUSTOM, $options);
// } else {
// $template = new PdfMakerDesign(strtolower($design->name));
// }
if (config('ninja.log_pdf_html')) {
info($maker->getCompiledHTML());
}
// $variables = $html->generateLabelsAndValues();
// $variables['labels']['$entity_label'] = ctrans('texts.delivery_note');
// $variables['labels']['$invoice.date_label'] = ctrans('texts.date');
// $variables['labels']['$invoice.number_label'] = ctrans('texts.number');
$maker = null;
$state = null;
// $state = [
// 'template' => $template->elements([
// 'client' => $this->invoice->client,
// 'entity' => $this->invoice,
// 'pdf_variables' => (array) $this->invoice->company->settings->pdf_variables,
// 'contact' => $this->contact,
// ], 'delivery_note'),
// 'variables' => $variables,
// 'options' => [
// 'client' => $this->invoice->client,
// 'entity' => $this->invoice,
// 'contact' => $this->contact,
// ],
// 'process_markdown' => $this->invoice->client->company->markdown_enabled,
// ];
return $pdf;
// $maker = new PdfMakerService($state);
// $maker
// ->design($template)
// ->build();
// if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
// $pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
// } else {
// $pdf = $this->makePdf(null, null, $maker->getCompiledHTML());
// }
// if (config('ninja.log_pdf_html')) {
// info($maker->getCompiledHTML());
// }
// $maker = null;
// $state = null;
// return $pdf;
}
}

View File

@ -1770,6 +1770,11 @@ class PdfBuilder
return $elements;
}
$this->service->html_variables['values']['$show_shipping_address_block'] = 'none';
$this->service->html_variables['values']['$show_shipping_address'] = 'none';
$this->service->html_variables['values']['$show_shipping_address_visibility'] = 'hidden';
$elements = [
['element' => 'div', 'content' => ctrans('texts.delivery_note'), 'properties' => ['data-ref' => 'delivery_note-label', 'style' => 'font-weight: bold; text-transform: uppercase']],
['element' => 'div', 'content' => $this->service->config->client->name, 'show_empty' => false, 'properties' => ['data-ref' => 'delivery_note-client.name']],
@ -1816,7 +1821,7 @@ class PdfBuilder
{
$elements = [];
if (!$this->service->config->client) {
if (!$this->service->config->client || $this->service->document_type == PdfService::DELIVERY_NOTE) {
return $elements;
}