I’m creating an invoicing app and the biggest concern I have all the time is that since I have an invoice page and then inside invoice line items is that to populate the RG I always have to touch the database.
I was wondering if I’m 2022 someone has achieved something like having a frontend database that on a save button in the page you can save the list of inline items.
Keep in mind that each line item needs to have each inputs such as price, quantity, taxes, …
You could do this by using a text string and putting different things in the text separated by a unique character
For instance you could store a product UUID, price, quantity and user UUID in a single text
For instance it would look like
Abcdefg;$5;10;abcdef :split by ;
From that your recieve a list of texts
Item 1 = abcdefg (product UUID)
Item 2 = price ($5 but you would probably store it as just a 5 then do a :convert to number)
Item 3 = 10 (quantity, again for a convert to number)
Item 4 = abcdef (user UUID)
Lots of people like to do this in JsON format and convert it which is another option
But each line item has different inputs such as the price, quantity, …
I know how to generate a custom state as a list but how do you put the fields in a list and after the save the button how do you create the each item in the database as a new record?
A more concise way to do this is just to write javascript functions and return variables corresponding to what you want to save. If the list of things is too large, you’ll end up with big objects though.
That looks good, but I’ve the add line item outside the RG and the line item inputs inside the RG.
I mean in the RG I need to have the line items and the user needs to modify the line item’s inputs that are inside the RG not just like in the video that it has the inputs outside the RG.
Will this work with the inputs inside the line items?
I’m just wondering why that’s a concern. What’s wrong with “touching the database”? I personally haven’t found performance to be an issue in similar scenarios.
i agree here-- a list of texts and numbers shouldn’t be causing performance issues. How is your database structured? How are you loading things into the repeating group?
JS Objects are the closest thing to “frontend database” here, but I don’t think you need them.
I don’t have an issue performance wise but with the database I need to keep for each line item two record, one as valid and another one as a draft one.
So that I’m not saving the valid ones all the time. And then you can see how difficult it is to manage loads of draft items and valid ones.
That’s the reason, so I can keep things simple.
Do you know if it would be possible to do as:
Thanks a lot for taking the time to help! Highly appreciated.
I see. I’m certainly a big fan of simplicity, but I’m a bit unclear as to why two separate records are needed for each line item. Could a single record with a Status field be used - i.e. just change that field’s value from “draft” to “final” when the invoice is saved/finalized?
Let’s think that a user creates a new invoice but then after, he wants to edit the invoice. If he modifies the values of the line items he is actually touching the status yes so even if he does not save the invoice, he is actually modifying the line items.
Because of this what I do is whenever a user edits an invoice, I duplicate the line items and set them as draft so if the user touches those line items and then leave without saving, the valid lines won’t be affected.
load the list of invoices onto the page as a custom state.
Create a form within a RG that shows the invoice, with the initial value coming from the custom state.
When the user modifies the form, they must click “save”-- no auto binding. Since every RG’s cell contains one invoice, you can just make changes to that single invoice when the user finishes editing a draft.
you can also opt to display the information as a popup as well, and send a different RG cell’s invoice into the popup.
This way, you are never making changes to any list, and there shouldn’t be a load time.