Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shadrix's avatar
Level 12

Why do we need an InvoiceLines table? (Databasedesign)

This could be super trivial, but I'm trying to design a database schema for the invoice.

I have looked up many example like here 1, 2 or 3

Why does everyone use an invoice_lines table?

I don't see the point (especially in my use case). I can easily create the invoice using the information from the order_items table. And the created invoice pdf itself is secured in the cloud + with a backup.

Is it just to back up the information given in an invoice?

0 likes
6 replies
jlrdw's avatar

Is it just to back up the information given in an invoice?

Usually legal reasons, but if you have them stored as pdf you are okay.

Edit:

I can easily create the invoice using the information from the order_items table.

Prices change, so don't depend on related data to "re-create" a 6 month old invoice.

1 like
sr57's avatar
sr57
Best Answer
Level 39

especially in my use case

You are the only one who knows your needs.

That said, why ... ?

  • not really a backup but a picture taken at the order instant (order items can later change but you are still able to get the search from data from your invoices in the db)

  • yes the .pdf invoices have also the rigth data, but you can't "query" these data

  • invoices items can be different from order items (you can add some lines like transportation, insurance, rebate, ... or change words for clients requirements ....)

1 like
Snapey's avatar

sometimes invoice lines need to reflect what was actually fulfilled (which could be different to what was ordered)

One example is holding the specific serial number of a picked item

Another example might be where a 'kit' is involved . Invoice is what the customer is charged for (ie, complete unit, order is 1 x pack A, 2 x Pack B, 4 x Pack C

Having said that, I have multiple sites where orderline and invoice line are the same thing

1 like
martinbean's avatar

@shadrix Simple: because a single invoice has many line items. So you’d have an invoice_line_items table or similar that has a row per line item, and each row with a foreign key pointing to the invoice that line item belongs to.

1 like
shadrix's avatar
Level 12

Oh wow! Thanks for your detailed answers, I didn't expect that at all. Cool, because each of you added something unique about it. I can't even decide who gets the Best Answer 😂

sr57's avatar

@shadrix

If you got what you want, just play dice to choose the best answer and in order to close the subject.

Please or to participate in this conversation.