I am trying to save an invoice into a database. The invoice gets created within bubble via input fields and need to be shown afterwords whenever you like as 1 saved invoice.
While I started to save the different “products” within that invoice as “list of products” as one column in the database “invoice” I recognized that I dont know how to store the respective quantity (QTY) attached to the specific product.
a) the quantity will of course change from invoice to invoice (so putting the QTY fixed next to the product in a separate database would not make sense)
b) the invoice needs to be saved and displayed afterwards whenever you like (temporary calculations on the page would not help as the QTY needs also somehow to be recorded).
You’ll want to create a new datatype to represent each ‘item’ on the invoice.
This invoice_item (or line_item, or invoice_product) datatype will contain all the information you need to store about that particular item on the invoice.
The exact data you need to store will depend on your app, but you’ll most likely want fields for:
Invoice - of type 'Invoice
Product - of type ‘Product’
Quantity - of type ‘Number’
Customer - of type ‘User’ or ‘Customer’
Price - of type ‘Number’
Along with whatever other data you need to have.
You’ll probably also want to add a field (a list) of invoice_items to the Invoice datatype so the items are linked both ways.
You will have to create a database called INVOICES with 4 columns:
Order → To store the order that generated this invoice
Produtc → To store the product
Quantity → To store the quantity of the product
Value → To store que value of the product
Note that none of they will be LIST type. If you have 2 products in this Order, you will need to generate the following entries in your database:
Order | Product | Quantity | Value
Order 1 | Coffee | 2 | 1.99
Order 1 | Water | 1 | 0.99
So when you want to recreate the invoice of the Order 1, you just need to make a search in your “Invoices” database.
Have another type for InvoiceLine. Store the product, the quantity, price etc on the InvoiceLine and have a field on it for Invoice which links the InvoiceLine s to the Invoice “header”.