Combining MySQL tables

Hey there! I'm developing a comprehensive stock management app, with production, purchase, sales, adjustments etc. Since GSheets can't hold a lot of data, I'm using MySQL (hosted on Digital Ocean). Everything's fine, but I'm stuck at this:

 

My schema looks something like this: 

A Products table that lists all products

A Parts table that lists all parts (which are used in the production of products)

The Products table has a child table BOM which contains which parts are used for each product along with the quantity of each part (The child is a part of the parent)

A Production table that lists the date of production (date is the key, since I want only 1 entry per day), with child Table Production_Deets that lists the Product ID and the quantity produced. (The child is a part of the parent)

Since Products are sold, and parts (which are like raw materials) purchased:

A Sales table that lists the Sales reference number, date & party name, with child Sales_Deets that has the details of the products sold along with quantity. (The child is a part of the parent)

A Purchases table that has the party name, date, with child Purchases_Deets that has the details of the parts purchased along with quantity (The child is a part of the parent)

There's also a Stock Adjustment table for Products (wherein stock of products can either be increased or decreased manually), and another for Parts (wherein stock of parts can either be increased or decreased manually).

 

Now the challenge is to combine all product-related tables into 1 table, and all parts-related tables into a second table.

I'm looking for a solution to prepare a stock ledger for products, that shows Production and stock-in, while Sales as Stock-out, along with adjustment entries (which can be either stock-in or stock-out depending on nature of adustment). This would then help me also calculate the total stock-in quantity, total stock-out quantity & current stock balance.

Similarly, I want a separate stock ledger for parts, that shows Purchases as stock-in, while Production as Stock-Out, with adjustment entries (which can be either stock-in or stock-out depending on nature of adustment). This would then help me also calculate the total stock-in quantity, total stock-out quantity & current stock balance.

 

 

I though of mainatining 2 separate stock ledger tables (with automated behaviour actions that add entries to it when a Production/Sales/Purchase/Adjustment entry is made), but the issue is, what happens when an update is made to one of those entries.... i.e:

Let's say I entered a production entry wherein I produced 5 units of Product 'A' (which requires say 3 parts: 

1 unit of Part X, 2 units of  Part Y & 3 units of Part Z)... so my ledgers look like this now:

Product Stock Ledger:

Stock Line IDTypeParent IDProduct IDQuantity
jhijsd3Productiona2xcdsA5

Parts Stock Ledger:

Stock Line IDTypeParent IDProduct IDPart IDQuantity
asdj23Productiona2xcdsAX-(5X1)= -5
asdj25Productiona2xcdsAY-(5X2)= -10
asdj26Productiona2xcdsAZ-(5X3)= -15

 

Now, I can't figure out how would I update these entries if a change is made in the Production table itself, i.e say I delete the production entry of A, or change the quantity to say 10 units...what happens then???

 

Thanks for your time & attention!

Solved Solved
0 2 117
1 ACCEPTED SOLUTION

@TeeSee1 's suggestion is a good one to evaluate.

Maybe I have properly understood your requirement and so below suggestion may or may not work. I mostly tried to read the part after " I thought of maintaining 2 separate stock tables  ......"

Have you evaluated reference actions? That is a more standard way in AppSheet of changing records in one table when there are changes in the other table. You may also wish to evaluate Appsheet Webhook API approach invoked through automation BOTs to edit records in tables.

The link to a sample app of reference actions is below. Please do read the description associated with the app.

https://www.appsheet.com/templates/This-app-shows-how-to-use-reference-actions?appGuidString=e76d2e7...

View solution in original post

2 REPLIES 2

 

I can suggest a general approach.

In an ERP system such as SAP, what you often do is NOT change the values of transactions already completed, especially when lots of related data needs to be modified also.

You enter a "reverse" transaction with a reason code, say production cancelled.

Something you may want to implement.

Just for your consideration.

@TeeSee1 's suggestion is a good one to evaluate.

Maybe I have properly understood your requirement and so below suggestion may or may not work. I mostly tried to read the part after " I thought of maintaining 2 separate stock tables  ......"

Have you evaluated reference actions? That is a more standard way in AppSheet of changing records in one table when there are changes in the other table. You may also wish to evaluate Appsheet Webhook API approach invoked through automation BOTs to edit records in tables.

The link to a sample app of reference actions is below. Please do read the description associated with the app.

https://www.appsheet.com/templates/This-app-shows-how-to-use-reference-actions?appGuidString=e76d2e7...

Top Labels in this Space