diff --git a/app/Repositories/Shop/InvoicePDF.php b/app/Repositories/Shop/InvoicePDF.php
index da6e2404..b66685a6 100644
--- a/app/Repositories/Shop/InvoicePDF.php
+++ b/app/Repositories/Shop/InvoicePDF.php
@@ -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.'
'.$address->zipcode.' '.$address->city;
+ if (! $address) {
+ return '';
+ }
+
+ $lines = array_filter([
+ $address->address ?? '',
+ $address->address2 ?? '',
+ trim(($address->zipcode ?? '').' '.($address->city ?? '')),
+ ]);
+
+ return implode('
', $lines);
}
public static function makeItems($details)