Skip to content

Commit ddcf2bf

Browse files
committed
readme
1 parent 6e06a77 commit ddcf2bf

File tree

1 file changed

+63
-36
lines changed

1 file changed

+63
-36
lines changed

README.md

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
# Manage invoices in your Laravel App
1+
# Everything You Need to Manage Invoices in Laravel
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/finller/laravel-invoices.svg?style=flat-square)](https://packagist.org/packages/finller/laravel-invoices)
44
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/finller/laravel-invoices/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/finller/laravel-invoices/actions?query=workflow%3Arun-tests+branch%3Amain)
55
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/finller/laravel-invoices/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/finller/laravel-invoices/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/finller/laravel-invoices.svg?style=flat-square)](https://packagist.org/packages/finller/laravel-invoices)
77

8-
Creating invoices is not a basic operation as you must ensure that it's done safely.
9-
This package provid all the basics to store invoices in your app and display them in a PDF.
10-
11-
## Migrating to v3
12-
13-
The v3 introduce a more robust way to configure serial numbers.
14-
15-
- `configureSerialNumber` replaces 'setSerialNumberPrefix`, 'setSerialNumberSerie`, ...
8+
This package provides a robust, easy-to-use system for managing invoices within a Laravel application, with options for database storage, serial numbering, and PDF generation.
169

1710
## Demo
1811

19-
[Interactive demo here](https://elegantengineering.tech/laravel-invoices)
12+
Try out [the interactive demo](https://elegantengineering.tech/laravel-invoices) to explore package capabilities.
2013

2114
## Installation
2215

@@ -143,38 +136,47 @@ return [
143136
];
144137
```
145138

146-
## Usage
147-
148139
## Store an invoice in your database
149140

150-
An invoice is just a model with InvoiceItem relationships, so you can create an invoice just like that:
141+
You can store an Invoice in your database using the Eloquent Model: `Finller\Invoice\Invoice`.
142+
143+
> [!NOTE]
144+
> Don't forget to publish and run the migrations
145+
146+
Here is a full example:
151147

152148
```php
153149
use Finller\Invoice\Invoice;
154150
use Finller\Invoice\InvoiceState;
155151
use Finller\Invoice\InvoiceType;
156152

157-
// Define general invoice data
153+
// Let's say your app edit invoices for your users
154+
$customer = User::find(1);
155+
// Let's imagine that your users have purchased something in your app
156+
$order = Order::find(2);
157+
158158
$invoice = new Invoice([
159159
'type' => InvoiceType::Invoice,
160160
'state' => InvoiceState::Draft,
161161
'description' => 'A description for my invoice',
162162
'seller_information' => config('invoices.default_seller'),
163163
'buyer_information' => [
164-
'name' => 'Client name',
165-
'address' => [],
166-
'tax_number' => "XYZ",
164+
'name' => 'John Doe',
165+
'address' => [
166+
'street' => '8405 Old James St.Rochester',
167+
'city' => 'New York',
168+
'postal_code' => '14609',
169+
'state' => 'New York (NY)',
170+
'country' => 'United States',
171+
],
172+
'email' => '[email protected]',
173+
'tax_number' => "FR123456789",
167174
],
168175
// ...
169176
]);
170177

171-
$invoice->configureSerialNumber(
172-
prefix: "CLI",
173-
serie: 42,
174-
);
175-
176-
$invoice->buyer()->associate($customer);
177-
$invoice->invoiceable()->associate($order); // optionnally associate the invoice to a model
178+
$invoice->buyer()->associate($customer); // optionnally associate the invoice to any model
179+
$invoice->invoiceable()->associate($order); // optionnally associate the invoice to any model
178180

179181
$invoice->save();
180182

@@ -190,27 +192,29 @@ $invoice->items()->saveMany([
190192
]);
191193
```
192194

193-
## Generate unique serial numbers automatically
195+
## Automatic Generation of Unique Serial Numbers
196+
197+
This package provides a simple and reliable way to generate serial numbers automatically, such as "INV240001."
194198

195-
This package provid an easy way to generate explicite serial number like "INV-0001" in a safe and automatic way.
199+
You can configure the format of your serial numbers in the configuration file. The default format is `PPYYCCCC`, where each letter has a specific meaning (see the config file for details).
196200

197-
You can configure the format of your serial numbers in the config file. The default format is `PPYYCCCC` (see config to understand the meaning of each letters).
201+
When `invoices.serial_number.auto_generate` is set to `true`, a unique serial number is assigned to each new invoice automatically.
198202

199-
Each time you create a new invoice, and if `invoices.serial_number.auto_generate` is set to `true`, the invoice will be given a unique serial number.
203+
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.
200204

201-
Serial number are generated one after the other, the new generated serial number is based on the `previous` one available.
202-
To determine which is the `previous` serial number you can extends `Finller\Invoice\Invoice`
203-
and override the `getPreviousInvoice` method.
205+
By default, the previous invoice is determined based on criteria such as prefix, series, year, and month for accurate, scoped numbering.
204206

205-
By default the previous invoice is scoped by prefix, serie, year and month as you would expect.
207+
## Managing Multiple Prefixes and Series
206208

207-
## Managing multiple prefix and multiple series
209+
In more complex applications, you may need to use different prefixes and/or series for your invoices.
208210

209-
In more complex app, you might need to have different prefix and/or series for your invoices.
211+
For instance, you might want to define a unique series for each user, creating serial numbers that look like: `INV0001-2400X`, where `0001` represents the user’s ID, `24` the year and `X` the index of the invoice.
210212

211-
For example, you might want to define a serie for each of your user and having serial numbers looking like: INV0001-00X where 1 is the id of the user.
213+
> [!NOTE]
214+
> When using IDs for series, it's recommended to plan for future growth to avoid overflow.
215+
> Even if you have a limited number of users now, ensure that the ID can accommodate the maximum number of digits allowed by the serial number format.
212216
213-
When creating an invoice, you can define the prefix and the serie on the fly like that;
217+
When creating an invoice, you can dynamically specify the prefix and series as follows:
214218

215219
```php
216220
use Finller\Invoice\Invoice;
@@ -220,8 +224,31 @@ $invoice->configureSerialNumber(
220224
prefix: "ORG",
221225
serie: $buyer_id,
222226
);
227+
```
228+
229+
## Customizing the Serial Number Format
230+
231+
In most cases, the format of your serial numbers should remain consistent, so it's recommended to set it in the configuration file.
232+
233+
The format you choose will determine the types of information you need to provide to `configureSerialNumber`.
234+
235+
Below is an example of the most complex serial number format you can create with this package:
236+
237+
```php
238+
239+
$invoice = new Invoice();
240+
241+
$invoice->configureSerialNumber(
242+
format: "PP-SSSSSS-YYMMCCCC",
243+
prefix: "IN",
244+
serie: 100,
245+
year: now()->format('Y'),
246+
month: now()->format('m')
247+
);
223248

224249
$invoice->save();
250+
251+
$invoice->serial_number; // IN-000100-2410-0001
225252
```
226253

227254
## Display your invoice as a PDF

0 commit comments

Comments
 (0)