Invoices
For this guide, we assume you already have already successfully followed in the steps in the CLI Quick Start.
Creating an invoice is one of the most useful features of GOBL as it demonstrates the full power of the library. For the sake of the examples on this page, we’re using Spain as the base region, but everything here should be supported with minor modifications in any other supported country.
Prepare Source
To get started we’re going to need some base data. Take the following yaml, modify as you see fit, and output to a file like invoice.yaml
:
Take note of some of the key details there:
$schema
is set to the GOBL Draft-0 invoice definition.supplier
identifies the issuer of the invoice, and thetax_id
specifically sets the origin country for this invoice.customer
includes the minimum amount of data possible for a customer.lines
defines a simple list of items, including the tax codes, in this case the category is “VAT” at the “standard” rate.- A single discount of “10%” has been defined for the line.
- There are no totals or other calculations, just the basic raw data.
Building
Take the invoice details and send them to the gobl build
command:
You should get back something like:
Congratulations! You’ve just created a complete GOBL invoice.
Take a look at some of the data that has been generated, a few observations:
- Everything has been embedded inside a GOBL Envelope, with a head and signature.
- Each invoice line has been updated with a
sum
andtotal
, where the total is the sum with discounts applied. - Tax rates valid for the
issue_date
have been added automatically. - A
totals
property has been added to the invoice, and details all the taxes that were applied to the calculations made from the lines.
Test PDF
Invopop, the creators of GOBL, offer a free stateless service to be able to test what your invoices look like as a PDFs. We do not recommend this for production use as it does not come with the same service guarantees, but is great for testing.
Create a new invoice.json
file:
Now use curl to send it to the testing service and dump the output:
And open it either from the command line if supported by your system, or directly in your favorite PDF reader:
You’ll notice that the resulting PDF has a big “DRAFT” message in the middle. If you want to remove this, you’ll have to sign the document with: