1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Change the way we display shipping addresses

This commit is contained in:
David Bomba 2023-05-09 19:53:09 +10:00
parent ec5a8eb100
commit 879d3181cb
2 changed files with 91 additions and 67 deletions

View File

@ -254,24 +254,41 @@ class Design extends BaseDesign
return $elements;
}
$elements = [
['element' => 'p', 'content' => ctrans('texts.shipping_address'), 'properties' => ['data-ref' => 'shipping_address-label', 'style' => 'font-weight: bold; text-transform: uppercase']],
['element' => 'p', 'content' => $this->client->name, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.name']],
['element' => 'p', 'content' => $this->client->shipping_address1, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.shipping_address1']],
['element' => 'p', 'content' => $this->client->shipping_address2, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.shipping_address2']],
['element' => 'p', 'show_empty' => false, 'elements' => [
['element' => 'span', 'content' => "{$this->client->shipping_city} ", 'properties' => ['ref' => 'shipping_address-client.shipping_city']],
['element' => 'span', 'content' => "{$this->client->shipping_state} ", 'properties' => ['ref' => 'shipping_address-client.shipping_state']],
['element' => 'span', 'content' => "{$this->client->shipping_postal_code} ", 'properties' => ['ref' => 'shipping_address-client.shipping_postal_code']],
]],
['element' => 'p', 'content' => optional($this->client->shipping_country)->name, 'show_empty' => false],
// $elements = [
// ['element' => 'p', 'content' => ctrans('texts.shipping_address'), 'properties' => ['data-ref' => 'shipping_address-label', 'style' => 'font-weight: bold; text-transform: uppercase']],
// ['element' => 'p', 'content' => $this->client->name, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.name']],
// ['element' => 'p', 'content' => $this->client->shipping_address1, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.shipping_address1']],
// ['element' => 'p', 'content' => $this->client->shipping_address2, 'show_empty' => false, 'properties' => ['data-ref' => 'shipping_address-client.shipping_address2']],
// ['element' => 'p', 'show_empty' => false, 'elements' => [
// ['element' => 'span', 'content' => "{$this->client->shipping_city} ", 'properties' => ['ref' => 'shipping_address-client.shipping_city']],
// ['element' => 'span', 'content' => "{$this->client->shipping_state} ", 'properties' => ['ref' => 'shipping_address-client.shipping_state']],
// ['element' => 'span', 'content' => "{$this->client->shipping_postal_code} ", 'properties' => ['ref' => 'shipping_address-client.shipping_postal_code']],
// ]],
// ['element' => 'p', 'content' => optional($this->client->shipping_country)->name, 'show_empty' => false],
// ];
$address_variables = [
'$client.address1',
'$client.address2',
'$client.city_state_postal',
'$client.country',
'$client.postal_city_state',
'$client.postal_city',
];
// if (!is_null($this->context['contact'])) {
// $elements[] = ['element' => 'p', 'content' => $this->context['contact']->email, 'show_empty' => false, 'properties' => ['data-ref' => 'delivery_note-contact.email']];
// }
$variables = $this->context['pdf_variables']['client_details'];
$elements = collect($variables)->filter(function ($variable) use ($address_variables){
return in_array($variable, $address_variables);
})->map(function ($variable){
$variable = str_replace('$client.', '$client.shipping_', $variable);
return ['element' => 'p', 'content' => $variable, 'show_empty' => false, 'properties' => ['data-ref' => "client_details-shipping-" . substr($variable, 1)]];
})->toArray();
return $elements;
}
public function clientDetails(): array
@ -312,71 +329,72 @@ class Design extends BaseDesign
return $elements;
}
public function entityDetailsx(): array
{
if ($this->type === 'statement') {
$s_date = $this->translateDate($this->options['start_date'], $this->client->date_format(), $this->client->locale()) . " - " . $this->translateDate($this->options['end_date'], $this->client->date_format(), $this->client->locale());
//@deprecated
// public function entityDetailsx(): array
// {
// if ($this->type === 'statement') {
// $s_date = $this->translateDate($this->options['start_date'], $this->client->date_format(), $this->client->locale()) . " - " . $this->translateDate($this->options['end_date'], $this->client->date_format(), $this->client->locale());
return [
['element' => 'p', 'content' => "<h2>".ctrans('texts.statement')."</h2>", 'properties' => ['data-ref' => 'statement-label']],
['element' => 'p', 'content' => ctrans('texts.statement_date'), 'properties' => ['data-ref' => 'statement-label'],'elements' =>
['element' => 'span', 'content' => "{$s_date} "]
],
['element' => 'p', 'content' => '$balance_due_label', 'properties' => ['data-ref' => 'statement-label'],'elements' =>
['element' => 'span', 'content' => Number::formatMoney($this->invoices->sum('balance'), $this->client)]
],
];
}
// return [
// ['element' => 'p', 'content' => "<h2>".ctrans('texts.statement')."</h2>", 'properties' => ['data-ref' => 'statement-label']],
// ['element' => 'p', 'content' => ctrans('texts.statement_date'), 'properties' => ['data-ref' => 'statement-label'],'elements' =>
// ['element' => 'span', 'content' => "{$s_date} "]
// ],
// ['element' => 'p', 'content' => '$balance_due_label', 'properties' => ['data-ref' => 'statement-label'],'elements' =>
// ['element' => 'span', 'content' => Number::formatMoney($this->invoices->sum('balance'), $this->client)]
// ],
// ];
// }
$variables = $this->context['pdf_variables']['invoice_details'];
// $variables = $this->context['pdf_variables']['invoice_details'];
if ($this->entity instanceof Quote) {
$variables = $this->context['pdf_variables']['quote_details'];
// if ($this->entity instanceof Quote) {
// $variables = $this->context['pdf_variables']['quote_details'];
if ($this->entity->partial > 0) {
$variables[] = '$quote.balance_due';
}
}
// if ($this->entity->partial > 0) {
// $variables[] = '$quote.balance_due';
// }
// }
if ($this->entity instanceof Credit) {
$variables = $this->context['pdf_variables']['credit_details'];
}
// if ($this->entity instanceof Credit) {
// $variables = $this->context['pdf_variables']['credit_details'];
// }
if ($this->vendor) {
$variables = $this->context['pdf_variables']['purchase_order_details'];
}
// if ($this->vendor) {
// $variables = $this->context['pdf_variables']['purchase_order_details'];
// }
$elements = [];
// $elements = [];
// We don't want to show account balance or invoice total on PDF.. or any amount with currency.
if ($this->type == self::DELIVERY_NOTE) {
$variables = array_filter($variables, function ($m) {
return !in_array($m, ['$invoice.balance_due', '$invoice.total']);
});
}
// // We don't want to show account balance or invoice total on PDF.. or any amount with currency.
// if ($this->type == self::DELIVERY_NOTE) {
// $variables = array_filter($variables, function ($m) {
// return !in_array($m, ['$invoice.balance_due', '$invoice.total']);
// });
// }
foreach ($variables as $variable) {
$_variable = explode('.', $variable)[1];
$_customs = ['custom1', 'custom2', 'custom3', 'custom4'];
// foreach ($variables as $variable) {
// $_variable = explode('.', $variable)[1];
// $_customs = ['custom1', 'custom2', 'custom3', 'custom4'];
/* 2/7/2022 don't show custom values if they are empty */
$var = str_replace("custom", "custom_value", $_variable);
// /* 2/7/2022 don't show custom values if they are empty */
// $var = str_replace("custom", "custom_value", $_variable);
if (in_array($_variable, $_customs) && !empty($this->entity->{$var})) {
$elements[] = ['element' => 'div', 'properties' => ['style' => "display: table-row; visibility: {$this->entityVariableCheck($_variable)};"],'elements' => [
['element' => 'div', 'content' => $variable . '_label', 'properties' => ['class' => 'entity-details-cell', 'data-ref' => 'entity_details-' . substr($variable, 1) . '_label']],
['element' => 'div', 'content' => $variable, 'properties' => ['class' => 'entity-details-cell', 'data-ref' => 'entity_details-' . substr($variable, 1)]],
]];
} else {
$elements[] = ['element' => 'div', 'properties' => ['style' => "display: table-row; visibility: {$this->entityVariableCheck($variable)};"], 'elements' => [
['element' => 'div', 'content' => $variable . '_label', 'properties' => ['class' => 'entity-details-cell','data-ref' => 'entity_details-' . substr($variable, 1) . '_label']],
['element' => 'div', 'content' => $variable, 'properties' => ['class' => 'entity-details-cell','data-ref' => 'entity_details-' . substr($variable, 1)]],
]];
}
}
// if (in_array($_variable, $_customs) && !empty($this->entity->{$var})) {
// $elements[] = ['element' => 'div', 'properties' => ['style' => "display: table-row; visibility: {$this->entityVariableCheck($_variable)};"],'elements' => [
// ['element' => 'div', 'content' => $variable . '_label', 'properties' => ['class' => 'entity-details-cell', 'data-ref' => 'entity_details-' . substr($variable, 1) . '_label']],
// ['element' => 'div', 'content' => $variable, 'properties' => ['class' => 'entity-details-cell', 'data-ref' => 'entity_details-' . substr($variable, 1)]],
// ]];
// } else {
// $elements[] = ['element' => 'div', 'properties' => ['style' => "display: table-row; visibility: {$this->entityVariableCheck($variable)};"], 'elements' => [
// ['element' => 'div', 'content' => $variable . '_label', 'properties' => ['class' => 'entity-details-cell','data-ref' => 'entity_details-' . substr($variable, 1) . '_label']],
// ['element' => 'div', 'content' => $variable, 'properties' => ['class' => 'entity-details-cell','data-ref' => 'entity_details-' . substr($variable, 1)]],
// ]];
// }
// }
return $elements;
}
// return $elements;
// }
public function entityDetails(): array
{

View File

@ -460,6 +460,12 @@ class HtmlEngine
$data['$client.shipping_state'] = ['value' => $this->client->shipping_state ?: ' ', 'label' => ctrans('texts.shipping_state')];
$data['$client.shipping_postal_code'] = ['value' => $this->client->shipping_postal_code ?: ' ', 'label' => ctrans('texts.shipping_postal_code')];
$data['$client.shipping_country'] = ['value' => isset($this->client->shipping_country->name) ? ctrans('texts.country_' . $this->client->shipping_country->name) : '', 'label' => ctrans('texts.shipping_country')];
$data['$shipping_postal_city_state'] = ['value' => $this->entity->present()->cityStateZip($this->client->shipping_city, $this->client->shipping_state, $this->client->shipping_postal_code, true) ?: ' ', 'label' => ctrans('texts.postal_city_state')];
$data['$client.shipping_postal_city_state'] = &$data['$shipping_postal_city_state'];
$data['$shipping_postal_city'] = ['value' => $this->entity->present()->cityStateZip($this->client->shipping_city, null, $this->client->shipping_postal_code, true) ?: ' ', 'label' => ctrans('texts.postal_city')];
$data['$client.shipping_postal_city'] = &$data['$shipping_postal_city'];
$data['$shipping_city_state_postal'] = ['value' => $this->entity->present()->cityStateZip($this->client->shipping_city, $this->client->shipping_state, $this->client->shipping_postal_code, false) ?: ' ', 'label' => ctrans('texts.city_state_postal')];
$data['$client.shipping_city_state_postal'] = &$data['$shipping_city_state_postal'];
$data['$client.currency'] = ['value' => $this->client->currency()->code, 'label' => ''];