Skip to content

Commit fb29977

Browse files
committed
new template and classes
1 parent d0bea5d commit fb29977

32 files changed

+1068
-425
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ phpstan.neon
99
testbench.yaml
1010
vendor
1111
node_modules
12-
.phpunit.cache
12+
.phpunit.cache
13+
workbench/storage

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ php artisan vendor:publish --tag="invoices-config"
7070
This is the contents of the published config file:
7171

7272
```php
73-
use Finller\Invoice\Invoice;
73+
use Finller\Invoice\Models\Invoice;
7474
use Finller\Invoice\InvoiceDiscount;
75-
use Finller\Invoice\InvoiceItem;
76-
use Finller\Invoice\InvoiceType;
75+
use Finller\Invoice\Models\InvoiceItem;
76+
use Finller\Invoice\Enums\InvoiceType;
7777

7878
return [
7979

@@ -193,7 +193,7 @@ return [
193193

194194
### Storing an Invoice in Your Database
195195

196-
You can store an Invoice in your database using the Eloquent Model: `Finller\Invoice\Invoice`.
196+
You can store an Invoice in your database using the Eloquent Model: `Finller\Invoice\Models\Invoice`.
197197

198198
> [!NOTE]
199199
> Don't forget to publish and run the migrations
@@ -202,9 +202,9 @@ Here is a full example:
202202

203203
```php
204204
use Brick\Money\Money;
205-
use Finller\Invoice\Invoice;
206-
use Finller\Invoice\InvoiceState;
207-
use Finller\Invoice\InvoiceType;
205+
use Finller\Invoice\Models\Invoice;
206+
use Finller\Invoice\Enums\InvoiceState;
207+
use Finller\Invoice\Enums\InvoiceType;
208208

209209
// Let's say your app edit invoices for your users
210210
$customer = User::find(1);
@@ -256,7 +256,7 @@ You can configure the format of your serial numbers in the configuration file. T
256256

257257
When `invoices.serial_number.auto_generate` is set to `true`, a unique serial number is assigned to each new invoice automatically.
258258

259-
Serial numbers are generated sequentially, with each new serial number based on the latest available one. To define what qualifies as the `previous` serial number, you can extend the `Finller\Invoice\Invoice` class and override the `getPreviousInvoice` method.
259+
Serial numbers are generated sequentially, with each new serial number based on the latest available one. To define what qualifies as the `previous` serial number, you can extend the `Finller\Invoice\Models\Invoice` class and override the `getPreviousInvoice` method.
260260

261261
By default, the previous invoice is determined based on criteria such as prefix, series, year, and month for accurate, scoped numbering.
262262

@@ -273,7 +273,7 @@ For instance, you might want to define a unique series for each user, creating s
273273
When creating an invoice, you can dynamically specify the prefix and series as follows:
274274

275275
```php
276-
use Finller\Invoice\Invoice;
276+
use Finller\Invoice\Models\Invoice;
277277
$invoice = new Invoice();
278278

279279
$invoice->configureSerialNumber(
@@ -380,7 +380,7 @@ class PaymentInvoice extends Mailable
380380

381381
To customize how your model is converted to a `PdfInvoice`, follow these steps:
382382

383-
1. **Create a Custom Model**: Define your own `\App\Models\Invoice` class and ensure it extends the base `\Finller\Invoice\Invoice` class.
383+
1. **Create a Custom Model**: Define your own `\App\Models\Invoice` class and ensure it extends the base `\Finller\Invoice\Models\Invoice` class.
384384

385385
2. **Override the `toPdfInvoice` Method**: Implement your specific logic within the `toPdfInvoice` method to control the customization.
386386

@@ -399,7 +399,7 @@ If you need to set the logo dynamically on the invoice, for example, when allowi
399399
To dynamically set the logo, define the `getLogo` method as shown below:
400400

401401
```php
402-
class Invoice extends \Finller\Invoice\Invoice
402+
class Invoice extends \Finller\Invoice\Models\Invoice
403403
{
404404
// ...
405405

@@ -426,7 +426,7 @@ You can even use this package exclusively for the `PdfInvoice` class if that sui
426426
Here’s an example of a fully configured `PdfInvoice` instance:
427427

428428
```php
429-
use Finller\Invoice\PdfInvoice;
429+
use Finller\Invoice\Pdf\PdfInvoice;
430430

431431
$pdfInvoice = new PdfInvoice(
432432
name: "Invoice",
@@ -480,7 +480,7 @@ $pdfInvoice = new PdfInvoice(
480480
```php
481481
namespace App\Http\Controllers;
482482

483-
use Finller\Invoice\PdfInvoice;
483+
use Finller\Invoice\Pdf\PdfInvoice;
484484

485485
class InvoiceController extends Controller
486486
{
@@ -519,7 +519,7 @@ class InvoiceController extends Controller
519519
```php
520520
namespace App\Http\Controllers;
521521

522-
use Finller\Invoice\PdfInvoice;
522+
use Finller\Invoice\Pdf\PdfInvoice;
523523

524524
class Invoice extends Component
525525
{

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"require": {
2020
"php": "^8.1",
21-
"barryvdh/laravel-dompdf": "^3.0.0",
21+
"dompdf/dompdf": "^3.1",
2222
"elegantly/laravel-money": "^2.1.0",
2323
"illuminate/contracts": "^11.0||^12.0",
2424
"spatie/laravel-package-tools": "^1.14"

config/invoices.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
declare(strict_types=1);
44

5-
use Finller\Invoice\Invoice;
5+
use Finller\Invoice\Enums\InvoiceType;
66
use Finller\Invoice\InvoiceDiscount;
7-
use Finller\Invoice\InvoiceItem;
8-
use Finller\Invoice\InvoiceType;
7+
use Finller\Invoice\Models\Invoice;
8+
use Finller\Invoice\Models\InvoiceItem;
99

1010
return [
1111

@@ -77,40 +77,49 @@
7777
'default_currency' => 'USD',
7878

7979
'pdf' => [
80+
81+
'paper' => [
82+
'paper' => 'a4',
83+
'orientation' => 'portrait',
84+
],
85+
8086
/**
8187
* Default DOM PDF options
8288
*
8389
* @see Available options https://github.com/barryvdh/laravel-dompdf#configuration
8490
*/
8591
'options' => [
86-
'isPhpEnabled' => true,
87-
'fontHeightRatio' => 0.9,
92+
'isRemoteEnabled' => true,
93+
'isPhpEnabled' => false,
94+
'fontHeightRatio' => 1,
8895
/**
8996
* Supported values are: 'DejaVu Sans', 'Helvetica', 'Courier', 'Times', 'Symbol', 'ZapfDingbats'
9097
*/
9198
'defaultFont' => 'Helvetica',
92-
],
9399

94-
'paper' => [
95-
'paper' => 'a4',
96-
'orientation' => 'portrait',
100+
'fontDir' => sys_get_temp_dir(),
101+
'fontCache' => sys_get_temp_dir(),
102+
'tempDir' => sys_get_temp_dir(),
103+
'chroot' => sys_get_temp_dir(),
97104
],
98105

99106
/**
100107
* The logo displayed in the PDF
101108
*/
102109
'logo' => null,
103110

104-
/**
105-
* The color displayed at the top of the PDF
106-
*/
107-
'color' => '#050038',
108-
109111
/**
110112
* The template used to render the PDF
111113
*/
112114
'template' => 'default.layout',
113115

116+
'template_data' => [
117+
/**
118+
* The color displayed at the top of the PDF
119+
*/
120+
'color' => '#050038',
121+
],
122+
114123
],
115124

116125
];

database/factories/InvoiceFactory.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
namespace Finller\Invoice\Database\Factories;
66

77
use Carbon\Carbon;
8-
use Finller\Invoice\Invoice;
9-
use Finller\Invoice\InvoiceState;
10-
use Finller\Invoice\InvoiceType;
8+
use Finller\Invoice\Enums\InvoiceState;
9+
use Finller\Invoice\Enums\InvoiceType;
10+
use Finller\Invoice\Models\Invoice;
11+
use Finller\Invoice\Support\Address;
12+
use Finller\Invoice\Support\Buyer;
13+
use Finller\Invoice\Support\Seller;
1114
use Illuminate\Database\Eloquent\Factories\Factory;
1215

1316
/**
@@ -31,19 +34,20 @@ public function definition()
3134
'created_at' => $created_at,
3235
'due_at' => fake()->dateTimeBetween($created_at, '+ 30 days'),
3336
'description' => fake()->sentence(),
34-
'buyer_information' => [
35-
'name' => fake()->company(),
36-
'address' => [
37-
'street' => fake()->streetName(),
38-
'city' => fake()->city(),
39-
'postal_code' => fake()->postcode(),
40-
'state' => null,
41-
'country' => fake()->country(),
42-
],
43-
'email' => fake()->email(),
44-
'phone_number' => fake()->phoneNumber(),
45-
'tax_number' => fake()->numberBetween(12345678, 99999999),
46-
],
37+
// @phpstan-ignore-next-line
38+
'seller_information' => Seller::fromArray(config('invoices.default_seller')),
39+
'buyer_information' => new Buyer(
40+
name : fake()->company(),
41+
billing_address : new Address(
42+
street: fake()->streetName(),
43+
city: fake()->city(),
44+
postal_code : fake()->postcode(),
45+
country: fake()->country(),
46+
),
47+
email : fake()->email(),
48+
phone : fake()->phoneNumber(),
49+
tax_number : (string) fake()->numberBetween(12345678, 99999999),
50+
),
4751
];
4852
}
4953

database/factories/InvoiceItemFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Finller\Invoice\Database\Factories;
66

77
use Brick\Money\Money;
8-
use Finller\Invoice\InvoiceItem;
8+
use Finller\Invoice\Models\InvoiceItem;
99
use Illuminate\Database\Eloquent\Factories\Factory;
1010

1111
/**

database/migrations/migrate_serial_number_details_columns_to_invoices_table.php.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66
use Illuminate\Database\Eloquent\Collection;
7-
use Finller\Invoice\Invoice;
7+
use Finller\Invoice\Models\Invoice;
88
use Illuminate\Database\Eloquent\Model;
99

1010
return new class extends Migration

resources/lang/en/invoice.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
'from' => 'Bill From',
2727
'to' => 'Bill To',
28+
'shipping_to' => 'Shipping To',
2829

2930
'states' => [
3031
'draft' => 'Draft',
@@ -39,4 +40,6 @@
3940
'credit' => 'Credit note',
4041
'proforma' => 'Proforma invoice',
4142
],
43+
44+
'page' => 'Page',
4245
];

resources/lang/fr/invoice.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
'from' => 'De',
2727
'to' => 'Pour',
28+
'shipping_to' => 'Livré à',
2829

2930
'states' => [
3031
'draft' => 'Brouillon',
@@ -39,4 +40,6 @@
3940
'credit' => "Facture d'avoir",
4041
'proforma' => 'Facture Proforma',
4142
],
43+
44+
'page' => 'Page',
4245
];

0 commit comments

Comments
 (0)