fix: make invoices creation resistant to missing address if this still happens

This commit is contained in:
Valentin Lab
2025-10-04 12:55:11 +02:00
parent 7c796802be
commit 11edccad02

View File

@@ -17,12 +17,15 @@ class InvoicePDF
public static function get($id)
{
$invoice = Invoices::getFull($id);
$customFields = [];
if ($orderRef = optional($invoice->order)->ref) {
$customFields['order number'] = $orderRef;
}
$customer = new Party([
'name' => $invoice->customer->name,
'name' => optional($invoice->customer)->name ?? __('Client inconnu'),
'address' => self::makeAddress($invoice->address),
'custom_fields' => [
'order number' => $invoice->order->ref,
],
'custom_fields' => $customFields,
]);
$items = self::makeItems($invoice->order->detail);
@@ -48,7 +51,17 @@ class InvoicePDF
public static function makeAddress($address)
{
return $address->address.'<br>'.$address->zipcode.' '.$address->city;
if (! $address) {
return '';
}
$lines = array_filter([
$address->address ?? '',
$address->address2 ?? '',
trim(($address->zipcode ?? '').' '.($address->city ?? '')),
]);
return implode('<br>', $lines);
}
public static function makeItems($details)