1 (edited by borisavljevic 2021-08-25 22:43:58)

Topic: [SOLVED] Trying but can't find solution.

Hi all,

Last few days I was trying (without success) to find solution for my problem. For easier understanding of problem, I created and attached example. Example is Bakery with list of products (Meat Pie, Cherry Pie, Chesse Pie...) and list of Row Materials. Every product has his own recepie, for example, Meat Pie includes 0,3 kg of flour + 0,2 kg of meat; making Cherry Pie includes 0,2 kg of Flour + 0,4 kg of Cherrys, etc...) My main problem is how to calculate current stock quantities for raw materials (It should be something like this: (every raw material total received) - [(every product total produced * quantity of raw material from recepie for every product)]. Take look at attached example, it will be more clear what I mean (key field is in table raw_materials - cf_qty_In_Stocks).
I think I need to use SQLite JOIN function but I don't know how to do that or maybe my database is not designed as it should. It would be great if someone can solve this problem in this example for me.
Any help is appreciated, thanks in advance.

Vladimir

Post's attachments

Attachment icon Bakery Example.rar 297.52 kb, 167 downloads since 2021-08-15 

2 (edited by brian.zaballa 2021-08-15 21:52:09)

Re: [SOLVED] Trying but can't find solution.

Check this one. This is from the post http://myvisualdatabase.com/forum/viewtopic.php?id=6995

Post's attachments

Attachment icon argonx_inventory.zip 500.76 kb, 180 downloads since 2021-08-15 

brian

3 (edited by borisavljevic 2021-08-16 09:46:46)

Re: [SOLVED] Trying but can't find solution.

At work right now, but after frst look, post you linked is what I was looking for.

Thank you Brian, appreciate your help.

Vladimir

Edit1: your example works fine as it is, but my problem is that I have table production_reports which should be key for ingredients stock quantity calculation. There would be a problem if I want to delete wrong entry from table production_reports , in that case calculation of ingredients stock quantity doesn't work. 

Thank you anyway for your time.

4 (edited by brian.zaballa 2021-08-16 13:37:33)

Re: [SOLVED] Trying but can't find solution.

That's just an example to give you an idea.

Here, I made some modification on your sample. Hope it can give you another idea on how you can do it.

You can just hide the negative value on the raw mat stock list, or have a field saying that it was a mats from a recipe.

I forgot to change the Grid title  (Total Received), it must be changed to Current Stock. If you want to show the total received, then you can just add additional calculated field on your raw_materials table

(SELECT total(quantity) FROM raw_mats_receive_reports WHERE raw_materials.id = raw_mats_receive_reports.id_raw_materials AND quantity > 0)
Post's attachments

Attachment icon Bakery Example_2.zip 555.15 kb, 177 downloads since 2021-08-16 

brian

5 (edited by borisavljevic 2021-08-16 14:32:17)

Re: [SOLVED] Trying but can't find solution.

Yea, I see now. Any quick tip how to hide negative valuse from the raw mat stock list?
Thanks again, this means a lot to me, I'm still learning.
Vladimir

Re: [SOLVED] Trying but can't find solution.

You can just add filter on your grid

Post's attachments

Attachment icon bakery_pix1.png 36.08 kb, 79 downloads since 2021-08-16 

brian

Re: [SOLVED] Trying but can't find solution.

That works, thank you again.

8 (edited by borisavljevic 2021-08-17 09:54:40)

Re: [SOLVED] Trying but can't find solution.

brian.zaballa wrote:

That's just an example to give you an idea.

Here, I made some modification on your sample. Hope it can give you another idea on how you can do it.

You can just hide the negative value on the raw mat stock list, or have a field saying that it was a mats from a recipe.

I forgot to change the Grid title  (Total Received), it must be changed to Current Stock. If you want to show the total received, then you can just add additional calculated field on your raw_materials table

(SELECT total(quantity) FROM raw_mats_receive_reports WHERE raw_materials.id = raw_mats_receive_reports.id_raw_materials AND quantity > 0)

Hi Brian,
One more thing, there is problem with code when I try to enter decimal number.

('+_qty+' * quantity * -1)

Saving integer is ok. Take look at screenshot if you have time.

Thank you for your time.
Vladimir

Post's attachments

Attachment icon Screenshot 2021-08-17 114507.jpg 41.92 kb, 77 downloads since 2021-08-17 

9 (edited by brian.zaballa 2021-08-17 13:26:13)

Re: [SOLVED] Trying but can't find solution.

Well. it'll not save as you expected. If you want it to accept decimal, then change production_reports.quantity to Real.

That error occur because of comma. Just change it to dot (.). You can trap it by checking the property NumbersOnly

Post's attachments

Attachment icon bakery_pix2.png 30.15 kb, 84 downloads since 2021-08-17 

brian

Re: [SOLVED] Trying but can't find solution.

Here, i got some changes

Post's attachments

Attachment icon Bakery Example_3.zip 555.44 kb, 181 downloads since 2021-08-17 

brian

Re: [SOLVED] Trying but can't find solution.

Thanks Brian,
I would never figure this out by myself and without your help.
Greetings and thank you for your time.