I have done this more than once:
desktop product: - product_id (PK) - description - product_type_id (FK)
billing table:
invoice_line table: - invoice_id - Product code - product_type_id - price
table product_type - product_type_id - description
So, on your last table, set two itens: 1 - "product", 2 - "service", Products would be created like this: "1", "banana", "1" (this is a product); Services will be created in such a way as "2", "Change of oil", "2" (this is a service);
Now when creating invoices, make sure that you pass product_type_id for the selected product to the invoice_line table. This will give you more performance when querying data such as "SELECT * from invoce_line WHERE product_type_id = 2" to get all the sales data. (1 for products).
So, you save all your account data in a unique table; you can get, for example, all client services through a simple connection request, for example (client_id will be 10):
Select * from invoice_line join invoice on invoice_line.invoice_id = invoice.invoice_id and client_id = 10 where product_type_id = 2
That would do the trick for almost everything. I have 1000 people working on something like this and to this day no shortcomings.
Hope this helps.
source share