Skip to content

Commit 5f16ec8

Browse files
committed
allow address customization
1 parent 2ea6b0f commit 5f16ec8

File tree

6 files changed

+112
-138
lines changed

6 files changed

+112
-138
lines changed

config/invoices.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
'date_format' => 'Y-m-d',
5858

5959
'default_seller' => [
60+
'company' => null,
6061
'name' => null,
6162
'address' => [
6263
'street' => null,
@@ -68,7 +69,9 @@
6869
'email' => null,
6970
'phone' => null,
7071
'tax_number' => null,
71-
'company_number' => null,
72+
'fields' => [
73+
//
74+
],
7275
],
7376

7477
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@if ($address->company)
2+
<p class="pb-1 text-xs"><strong>{{ $address->company }}</strong></p>
3+
@endif
4+
5+
@if ($address->name)
6+
<p class="pb-1 text-xs">{{ $address->name }}</p>
7+
@endif
8+
9+
@if ($address->street)
10+
<p class="pb-1 text-xs">{{ $address->street }}</p>
11+
@endif
12+
13+
@if ($address->city)
14+
<p class="pb-1 text-xs">
15+
{{ $address->city }}, {{ $address->state }} {{ $address->postal_code }}
16+
</p>
17+
@endif
18+
19+
@if ($address->country)
20+
<p class="pb-1 text-xs">{{ $address->country }}</p>
21+
@endif
22+
23+
@if ($address->fields)
24+
@foreach ($address->fields as $key => $value)
25+
<p class="pb-1 text-xs">
26+
@if (is_string($key))
27+
{{ $key }}
28+
@endif
29+
{{ $value }}
30+
</p>
31+
@endforeach
32+
@endif

resources/views/default/invoice.blade.php

Lines changed: 58 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -76,173 +76,94 @@
7676
<tbody>
7777
<tr>
7878
<td class="p-0 align-top" width="33%">
79-
@php
80-
$name = $invoice->seller->name;
81-
$street = $invoice->seller->address->street;
82-
$postal_code = $invoice->seller->address->postal_code;
83-
$city = $invoice->seller->address->city;
84-
$state = $invoice->seller->address->state;
85-
$country = $invoice->seller->address->country;
86-
$address_fields = $invoice->seller->address?->fields ?? [];
87-
$email = $invoice->seller->email;
88-
$phone = $invoice->seller->phone;
89-
$tax_number = $invoice->seller->tax_number;
90-
$fields = $invoice->seller->fields;
91-
@endphp
92-
9379
<p class="mb-1 pb-1 text-xs text-gray-500">{{ __('invoices::invoice.from') }}</p>
9480

95-
@if ($name)
96-
<p class="pb-1 text-xs"><strong>{{ $name }}</strong></p>
97-
@endif
98-
@if ($street)
99-
<p class="pb-1 text-xs">{{ $street }}</p>
100-
@endif
101-
@if ($postal_code || $city)
102-
<p class="whitespace-nowrap pb-1 text-xs">
103-
{{ $postal_code }}
104-
{{ $city }}
105-
</p>
81+
@if ($invoice->seller->company)
82+
<p class="pb-1 text-xs"><strong>{{ $invoice->seller->company }}</strong></p>
10683
@endif
107-
@if ($state)
108-
<p class="pb-1 text-xs">{{ $state }}</p>
109-
@endif
110-
@if ($country)
111-
<p class="pb-1 text-xs">{{ $country }}</p>
84+
85+
@if ($invoice->seller->name)
86+
<p class="pb-1 text-xs"><strong>{{ $invoice->seller->name }}</strong></p>
11287
@endif
11388

114-
@foreach ($address_fields as $key => $value)
115-
<p class="pb-1 text-xs">
116-
@if (is_string($key))
117-
{{ $key }}
118-
@endif
119-
{{ $value }}
120-
</p>
121-
@endforeach
89+
@if ($invoice->seller->address)
90+
@include('invoices::default.includes.address', [
91+
'address' => $invoice->seller->address,
92+
])
93+
@endif
12294

123-
@if ($email)
124-
<p class="pb-1 text-xs">{{ $email }}</p>
95+
@if ($invoice->seller->email)
96+
<p class="pb-1 text-xs">{{ $invoice->seller->email }}</p>
12597
@endif
126-
@if ($phone)
127-
<p class="pb-1 text-xs">{{ $phone }}</p>
98+
@if ($invoice->seller->phone)
99+
<p class="pb-1 text-xs">{{ $invoice->seller->phone }}</p>
128100
@endif
129-
@if ($tax_number)
130-
<p class="pb-1 text-xs">{{ $tax_number }}</p>
101+
@if ($invoice->seller->tax_number)
102+
<p class="pb-1 text-xs">{{ $invoice->seller->tax_number }}</p>
103+
@endif
104+
105+
@if ($invoice->seller->fields)
106+
@foreach ($invoice->seller->fields as $key => $value)
107+
<p class="pb-1 text-xs">
108+
@if (is_string($key))
109+
{{ $key }}
110+
@endif
111+
{{ $value }}
112+
</p>
113+
@endforeach
131114
@endif
132-
@foreach ($fields as $key => $value)
133-
<p class="pb-1 text-xs">
134-
@if (is_string($key))
135-
{{ $key }}
136-
@endif
137-
{{ $value }}
138-
</p>
139-
@endforeach
140115
</td>
141116
<td class="p-0 align-top" width="33%">
142-
@php
143-
$name = $invoice->buyer->name;
144-
$street = $invoice->buyer->address?->street;
145-
$postal_code = $invoice->buyer->address?->postal_code;
146-
$city = $invoice->buyer->address?->city;
147-
$state = $invoice->buyer->address?->state;
148-
$country = $invoice->buyer->address?->country;
149-
$address_fields = $invoice->buyer->address?->fields ?? [];
150-
$email = $invoice->buyer->email;
151-
$phone = $invoice->buyer->phone;
152-
$tax_number = $invoice->buyer->tax_number;
153-
$fields = $invoice->buyer->fields;
154-
@endphp
155117
<p class="mb-1 pb-1 text-xs text-gray-500">{{ __('invoices::invoice.to') }}</p>
156118

157-
@if ($name)
158-
<p class="pb-1 text-xs"><strong>{{ $name }}</strong></p>
119+
@if ($invoice->buyer->company)
120+
<p class="pb-1 text-xs"><strong>{{ $invoice->buyer->company }}</strong></p>
159121
@endif
160-
@if ($street)
161-
<p class="pb-1 text-xs">{{ $street }}</p>
162-
@endif
163-
@if ($postal_code || $city)
164-
<p class="whitespace-nowrap pb-1 text-xs">
165-
{{ $postal_code }}
166-
{{ $city }}
167-
</p>
168-
@endif
169-
@if ($state)
170-
<p class="pb-1 text-xs">{{ $state }}</p>
171-
@endif
172-
@if ($country)
173-
<p class="pb-1 text-xs">{{ $country }}</p>
122+
123+
@if ($invoice->buyer->name)
124+
<p class="pb-1 text-xs"><strong>{{ $invoice->buyer->name }}</strong></p>
174125
@endif
175126

176-
@foreach ($address_fields as $key => $value)
177-
<p class="pb-1 text-xs">
178-
@if (is_string($key))
179-
{{ $key }}
180-
@endif
181-
{{ $value }}
182-
</p>
183-
@endforeach
127+
@if ($invoice->buyer->address)
128+
@include('invoices::default.includes.address', [
129+
'address' => $invoice->buyer->address,
130+
])
131+
@endif
184132

185-
@if ($email)
186-
<p class="pb-1 text-xs">{{ $email }}</p>
133+
@if ($invoice->buyer->email)
134+
<p class="pb-1 text-xs">{{ $invoice->buyer->email }}</p>
187135
@endif
188-
@if ($phone)
189-
<p class="pb-1 text-xs">{{ $phone }}</p>
136+
@if ($invoice->buyer->phone)
137+
<p class="pb-1 text-xs">{{ $invoice->buyer->phone }}</p>
190138
@endif
191-
@if ($tax_number)
192-
<p class="pb-1 text-xs">{{ $tax_number }}</p>
139+
@if ($invoice->buyer->tax_number)
140+
<p class="pb-1 text-xs">{{ $invoice->buyer->tax_number }}</p>
193141
@endif
194142

195-
@foreach ($fields as $key => $value)
196-
<p class="pb-1 text-xs">
197-
@if (is_string($key))
198-
{{ $key }}
199-
@endif
200-
{{ $value }}
201-
</p>
202-
@endforeach
143+
@if ($invoice->buyer->fields)
144+
@foreach ($invoice->buyer->fields as $key => $value)
145+
<p class="pb-1 text-xs">
146+
@if (is_string($key))
147+
{{ $key }}
148+
@endif
149+
{{ $value }}
150+
</p>
151+
@endforeach
152+
@endif
203153
</td>
204154

205155
@if ($invoice->buyer->shipping_address)
206156
<td class="p-0 align-top" width="33%">
207-
@php
208-
$name = $invoice->buyer->shipping_address->name;
209-
$street = $invoice->buyer->shipping_address->street;
210-
$postal_code = $invoice->buyer->shipping_address->postal_code;
211-
$city = $invoice->buyer->shipping_address->city;
212-
$state = $invoice->buyer->shipping_address->state;
213-
$country = $invoice->buyer->shipping_address->country;
214-
$fields = $invoice->buyer->shipping_address->fields;
215-
@endphp
157+
216158
<p class="mb-1 whitespace-nowrap pb-1 text-xs text-gray-500">
217159
{{ __('invoices::invoice.shipping_to') }}
218160
</p>
219161

220-
@if ($name)
221-
<p class="pb-1 text-xs"><strong>{{ $name }}</strong></p>
162+
@if ($invoice->buyer->shipping_address)
163+
@include('invoices::default.includes.address', [
164+
'address' => $invoice->buyer->shipping_address,
165+
])
222166
@endif
223-
@if ($street)
224-
<p class="pb-1 text-xs">{{ $street }}</p>
225-
@endif
226-
@if ($postal_code || $city)
227-
<p class="whitespace-nowrap pb-1 text-xs">
228-
{{ $postal_code }}
229-
{{ $city }}
230-
</p>
231-
@endif
232-
@if ($state)
233-
<p class="pb-1 text-xs">{{ $state }}</p>
234-
@endif
235-
@if ($country)
236-
<p class="pb-1 text-xs">{{ $country }}</p>
237-
@endif
238-
@foreach ($fields as $key => $value)
239-
<p class="pb-1 text-xs">
240-
@if (is_string($key))
241-
{{ $key }}
242-
@endif
243-
{{ $value }}
244-
</p>
245-
@endforeach
246167
</td>
247168
@endif
248169

src/Support/Address.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Address implements Arrayable
1515
* @param array<array-key, null|int|float|string> $fields
1616
*/
1717
public function __construct(
18+
public ?string $company = null,
1819
public ?string $name = null,
1920
public ?string $street = null,
2021
public ?string $state = null,
@@ -32,6 +33,8 @@ public function __construct(
3233
public static function fromArray(array $values): self
3334
{
3435
return new self(
36+
// @phpstan-ignore-next-line
37+
company: data_get($values, 'company'),
3538
// @phpstan-ignore-next-line
3639
name: data_get($values, 'name'),
3740
// @phpstan-ignore-next-line
@@ -51,6 +54,7 @@ public static function fromArray(array $values): self
5154

5255
/**
5356
* @return array{
57+
* company: ?string,
5458
* name: ?string,
5559
* street: ?string,
5660
* state: ?string,
@@ -63,6 +67,7 @@ public static function fromArray(array $values): self
6367
public function toArray(): array
6468
{
6569
return [
70+
'company' => $this->company,
6671
'name' => $this->name,
6772
'street' => $this->street,
6873
'state' => $this->state,

src/Support/Buyer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Buyer implements Arrayable
1515
* @param array<array-key, null|int|float|string> $fields
1616
*/
1717
public function __construct(
18+
public ?string $company = null,
1819
public ?string $name = null,
1920
public ?Address $address = null,
2021
public ?Address $shipping_address = null,
@@ -32,6 +33,8 @@ public function __construct(
3233
public static function fromArray(array $values): self
3334
{
3435
return new self(
36+
// @phpstan-ignore-next-line
37+
company: data_get($values, 'company'),
3538
// @phpstan-ignore-next-line
3639
name: data_get($values, 'name'),
3740
// @phpstan-ignore-next-line
@@ -51,8 +54,10 @@ public static function fromArray(array $values): self
5154

5255
/**
5356
* @return array{
57+
* company: ?string,
5458
* name: ?string,
5559
* address: null|array{
60+
* company: ?string,
5661
* name: ?string,
5762
* street: ?string,
5863
* state: ?string,
@@ -62,6 +67,7 @@ public static function fromArray(array $values): self
6267
* fields: null|array<array-key, null|int|float|string>,
6368
* },
6469
* shipping_address: null|array{
70+
* company: ?string,
6571
* name: ?string,
6672
* street: ?string,
6773
* state: ?string,
@@ -79,6 +85,7 @@ public static function fromArray(array $values): self
7985
public function toArray(): array
8086
{
8187
return [
88+
'company' => $this->company,
8289
'name' => $this->name,
8390
'address' => $this->address?->toArray(),
8491
'shipping_address' => $this->shipping_address?->toArray(),

src/Support/Seller.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Seller implements Arrayable
1515
* @param array<array-key, null|int|float|string> $fields
1616
*/
1717
public function __construct(
18+
public ?string $company = null,
1819
public ?string $name = null,
1920
public ?Address $address = null,
2021
public ?string $tax_number = null,
@@ -31,6 +32,8 @@ public function __construct(
3132
public static function fromArray(array $values): self
3233
{
3334
return new self(
35+
// @phpstan-ignore-next-line
36+
company: data_get($values, 'company'),
3437
// @phpstan-ignore-next-line
3538
name: data_get($values, 'name'),
3639
// @phpstan-ignore-next-line
@@ -48,8 +51,10 @@ public static function fromArray(array $values): self
4851

4952
/**
5053
* @return array{
54+
* company: ?string,
5155
* name: ?string,
5256
* address: null|array{
57+
* company: ?string,
5358
* name: ?string,
5459
* street: ?string,
5560
* state: ?string,
@@ -67,6 +72,7 @@ public static function fromArray(array $values): self
6772
public function toArray(): array
6873
{
6974
return [
75+
'company' => $this->company,
7076
'name' => $this->name,
7177
'address' => $this->address?->toArray(),
7278
'tax_number' => $this->tax_number,

0 commit comments

Comments
 (0)