Skip to content

Commit 88c4726

Browse files
committed
Invoice Status, fixes PR #113
1 parent 16cdd39 commit 88c4726

File tree

8 files changed

+181
-171
lines changed

8 files changed

+181
-171
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ use LaravelDaily\Invoices\Classes\InvoiceItem;
143143
]);
144144

145145
$items = [
146-
(new InvoiceItem())->title('Service 1')->description('additional text')->pricePerUnit(47.79)->quantity(2)->discount(10),
146+
(new InvoiceItem())
147+
->title('Service 1')
148+
->description('Your product or service description')
149+
->pricePerUnit(47.79)
150+
->quantity(2)
151+
->discount(10),
147152
(new InvoiceItem())->title('Service 2')->pricePerUnit(71.96)->quantity(2),
148153
(new InvoiceItem())->title('Service 3')->pricePerUnit(4.56),
149154
(new InvoiceItem())->title('Service 4')->pricePerUnit(87.51)->quantity(7)->discount(4)->units('kg'),
@@ -173,6 +178,9 @@ use LaravelDaily\Invoices\Classes\InvoiceItem;
173178

174179
$invoice = Invoice::make('receipt')
175180
->series('BIG')
181+
// ability to include translated invoice status
182+
// in case it was paid
183+
->status(__('invoices::invoice.paid'))
176184
->sequence(667)
177185
->serialNumberFormat('{SEQUENCE}/{SERIES}')
178186
->seller($client)
@@ -341,6 +349,7 @@ Almost every configuration value can be overrided dynamically by methods.
341349
- addItem(InvoiceItem $item)
342350
- addItems(Iterable)
343351
- name(string)
352+
- status(string) - invoice status [paid/due] if needed
344353
- seller(PartyContract)
345354
- buyer(PartyContract)
346355
- setCustomData(mixed) - allows user to attach additional data to invoice
@@ -388,6 +397,7 @@ Almost every configuration value can be overrided dynamically by methods.
388397
- download() - offers to download invoice
389398
- save($disk) - saves invoice to storage, use ->filename() for filename
390399
- url() - return url of saved invoice
400+
- toHtml() - render html view instead of pdf
391401

392402
## InvoiceItem
393403
- title(string) - product or service name

config/invoices.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,59 @@
22

33
return [
44
'date' => [
5-
/**
5+
/*
66
* Carbon date format
77
*/
8-
'format' => 'Y-m-d',
9-
/**
8+
'format' => 'Y-m-d',
9+
/*
1010
* Due date for payment since invoice's date.
1111
*/
1212
'pay_until_days' => 7,
1313
],
1414

1515
'serial_number' => [
16-
'series' => 'AA',
17-
'sequence' => 1,
18-
/**
16+
'series' => 'AA',
17+
'sequence' => 1,
18+
/*
1919
* Sequence will be padded accordingly, for ex. 00001
2020
*/
2121
'sequence_padding' => 5,
2222
'delimiter' => '.',
23-
/**
23+
/*
2424
* Supported tags {SERIES}, {DELIMITER}, {SEQUENCE}
2525
* Example: AA.00001
2626
*/
27-
'format' => '{SERIES}{DELIMITER}{SEQUENCE}',
27+
'format' => '{SERIES}{DELIMITER}{SEQUENCE}',
2828
],
2929

3030
'currency' => [
31-
'code' => 'eur',
32-
/**
31+
'code' => 'eur',
32+
/*
3333
* Usually cents
3434
* Used when spelling out the amount and if your currency has decimals.
3535
*
3636
* Example: Amount in words: Eight hundred fifty thousand sixty-eight EUR and fifteen ct.
3737
*/
38-
'fraction' => 'ct.',
39-
'symbol' => '',
40-
/**
38+
'fraction' => 'ct.',
39+
'symbol' => '',
40+
/*
4141
* Example: 19.00
4242
*/
43-
'decimals' => 2,
44-
/**
43+
'decimals' => 2,
44+
/*
4545
* Example: 1.99
4646
*/
47-
'decimal_point' => '.',
48-
/**
47+
'decimal_point' => '.',
48+
/*
4949
* By default empty.
5050
* Example: 1,999.00
5151
*/
5252
'thousands_separator' => '',
53-
/**
53+
/*
5454
* Supported tags {VALUE}, {SYMBOL}, {CODE}
5555
* Example: 1.99 €
5656
*/
57-
'format' => '{VALUE} {SYMBOL}',
57+
'format' => '{VALUE} {SYMBOL}',
5858
],
5959

6060
'paper' => [
@@ -65,18 +65,16 @@
6565

6666
'disk' => 'local',
6767

68-
'status' => 'Due',
69-
7068
'seller' => [
71-
/**
69+
/*
7270
* Class used in templates via $invoice->seller
7371
*
7472
* Must implement LaravelDaily\Invoices\Contracts\PartyContract
7573
* or extend LaravelDaily\Invoices\Classes\Party
7674
*/
7775
'class' => \LaravelDaily\Invoices\Classes\Seller::class,
7876

79-
/**
77+
/*
8078
* Default attributes for Seller::class
8179
*/
8280
'attributes' => [
@@ -86,7 +84,7 @@
8684
'vat' => '123456789',
8785
'phone' => '760-355-3930',
8886
'custom_fields' => [
89-
/**
87+
/*
9088
* Custom attributes for Seller::class
9189
*
9290
* Used to display additional info on Seller section in invoice
42 Bytes
Binary file not shown.

resources/lang/en/invoice.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

33
return [
4-
54
/*
65
|--------------------------------------------------------------------------
76
| Invoice Language Lines
87
|--------------------------------------------------------------------------
98
*/
109

10+
'invoice' => 'Invoice',
1111
'serial' => 'Serial No.',
1212
'date' => 'Invoice date',
1313
'seller' => 'Seller',
@@ -33,5 +33,6 @@
3333
'amount_in_words_format' => '%s %s and %s %s',
3434
'notes' => 'Notes',
3535
'shipping' => 'Shipping',
36-
36+
'paid' => 'Paid',
37+
'due' => 'Due',
3738
];

resources/lang/nl/invoice.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

33
return [
4-
54
/*
65
|--------------------------------------------------------------------------
76
| Factuur Taal Lijnen
87
|--------------------------------------------------------------------------
98
*/
109

10+
'invoice' => 'Factuur',
1111
'serial' => 'Factuurnummer',
1212
'date' => 'Factuurdatum',
1313
'seller' => 'Leverancier',
@@ -33,5 +33,6 @@
3333
'amount_in_words_format' => '%s %s en %s %s',
3434
'notes' => 'Opmerkingen',
3535
'shipping' => 'Verzending',
36-
36+
'paid' => 'Betaald',
37+
'due' => 'Openstaand',
3738
];

resources/views/templates/default.blade.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
.table td {
7070
padding: 0.75rem;
7171
vertical-align: top;
72+
}
73+
74+
.table.table-items td {
7275
border-top: 1px solid #dee2e6;
7376
}
7477
@@ -77,10 +80,6 @@
7780
border-bottom: 2px solid #dee2e6;
7881
}
7982
80-
.table tbody + tbody {
81-
border-top: 2px solid #dee2e6;
82-
}
83-
8483
.mt-5 {
8584
margin-top: 3rem !important;
8685
}
@@ -123,18 +122,8 @@
123122
.border-0 {
124123
border: none !important;
125124
}
126-
127-
.description {
128-
margin-top: 0.25rem;
129-
margin-bottom: 0;
130-
color: #999;
131-
}
132-
133-
.status {
134-
color: #999;
135-
font-size: 2rem;
136-
font-weight: bold;
137-
text-transform: uppercase;
125+
.cool-gray {
126+
color: #6B7280;
138127
}
139128
</style>
140129
</head>
@@ -144,6 +133,7 @@
144133
@if($invoice->logo)
145134
<img src="{{ $invoice->getLogo() }}" alt="logo" height="100">
146135
@endif
136+
147137
<table class="table mt-5">
148138
<tbody>
149139
<tr>
@@ -153,7 +143,11 @@
153143
</h4>
154144
</td>
155145
<td class="border-0 pl-0">
156-
<p class="status">{{ $invoice->status }}</p>
146+
@if($invoice->status)
147+
<h4 class="text-uppercase cool-gray">
148+
<strong>{{ $invoice->status }}</strong>
149+
</h4>
150+
@endif
157151
<p>{{ __('invoices::invoice.serial') }} <strong>{{ $invoice->getSerialNumber() }}</strong></p>
158152
<p>{{ __('invoices::invoice.date') }}: <strong>{{ $invoice->getDate() }}</strong></p>
159153
</td>
@@ -256,7 +250,7 @@
256250
</table>
257251

258252
{{-- Table --}}
259-
<table class="table">
253+
<table class="table table-items">
260254
<thead>
261255
<tr>
262256
<th scope="col" class="border-0 pl-0">{{ __('invoices::invoice.description') }}</th>
@@ -280,8 +274,9 @@
280274
<tr>
281275
<td class="pl-0">
282276
{{ $item->title }}
277+
283278
@if($item->description)
284-
<p class="description">{{ $item->description }}</p>
279+
<p class="cool-gray">{{ $item->description }}</p>
285280
@endif
286281
</td>
287282
@if($invoice->hasItemUnits)

src/Invoice.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,14 @@ class Invoice
152152
*
153153
* @throws \Illuminate\Contracts\Container\BindingResolutionException
154154
*/
155-
public function __construct($name = 'Invoice')
155+
public function __construct($name = '')
156156
{
157157
// Invoice
158-
$this->name = $name;
158+
$this->name = $name ?: __('invoices::invoice.invoice');
159159
$this->seller = app()->make(config('invoices.seller.class'));
160160
$this->items = Collection::make([]);
161161
$this->template = 'default';
162162

163-
$this->status = config('invoices.status');
164-
165163
// Date
166164
$this->date = Carbon::now();
167165
$this->date_format = config('invoices.date.format');
@@ -197,7 +195,7 @@ public function __construct($name = 'Invoice')
197195
*
198196
* @return Invoice
199197
*/
200-
public static function make($name = 'Invoice')
198+
public static function make($name = '')
201199
{
202200
return new static($name);
203201
}
@@ -249,20 +247,31 @@ public function addItems($items)
249247
*/
250248
public function render()
251249
{
252-
if (!$this->pdf) {
253-
$this->beforeRender();
250+
if ($this->pdf) {
251+
return $this;
252+
}
254253

255-
$template = sprintf('invoices::templates.%s', $this->template);
256-
$view = View::make($template, ['invoice' => $this]);
257-
$html = mb_convert_encoding($view, 'HTML-ENTITIES', 'UTF-8');
254+
$this->beforeRender();
258255

259-
$this->pdf = PDF::setOptions(['enable_php' => true])->loadHtml($html);
260-
$this->output = $this->pdf->output();
261-
}
256+
$template = sprintf('invoices::templates.%s', $this->template);
257+
$view = View::make($template, ['invoice' => $this]);
258+
$html = mb_convert_encoding($view, 'HTML-ENTITIES', 'UTF-8');
259+
260+
$this->pdf = PDF::setOptions(['enable_php' => true])->loadHtml($html);
261+
$this->output = $this->pdf->output();
262262

263263
return $this;
264264
}
265265

266+
public function toHtml()
267+
{
268+
$this->beforeRender();
269+
270+
$template = sprintf('invoices::templates.%s', $this->template);
271+
272+
return View::make($template, ['invoice' => $this]);
273+
}
274+
266275
/**
267276
* @throws Exception
268277
*

0 commit comments

Comments
 (0)