Draft
Calculating FIFO (First-In, First-Out) Gross Margin
Loading description...
SQL
Databases
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Notes says:
It is not possible for more units of a certain product to be sold than purchased at any given moment in time because the FIFO Gross Margin calculation assumes that sales are matched to prior purchases.
but in example tests I see
it looks like a contradiction to me. So from the description the result for this sku is unclear (could be 20, 30 or even 40)
don't have much time today :/. Putting kata into draft and will carefully work with all issues when have time (and re-check my solution because looks that it has issues)...Very interesting problem
Very interesting, you could easily make an entire series of kata's on this subject, each with different expected behavior for sales when nothing is in stock ;)
I've also thought there could be at least 2 kata:
P.S. as this is quite a practical task (but not in SQL) I know there exists several approaches to calculating a gross margin; not only different ways of dealing with sales of skus that are not in stock but also a different algos, not only FIFO.
I hope author goes for (2) here, which was the intended way (looking at author comments in a previous discussion). This would be a challenging task in SQL.
I'm thinking about the following task: one table with current stock and maximum stock capacity for each product, and then the purchases and sales tables. User should make a sql report with current stock after each purchase/sale, and actions taken for each purchase/sale -> approved or rejected. A purchase is rejected when stock is full and a sale is rejected when stock is empty. Do you think such kata is too close to the current kata you are drafting? If not, I'll have a go at authoring such kata.
purchase / sales - naming is inconsistent: singular/plural
I'd suggest 'purchases'
I believe my solution is correct. Could you verify with ref sol?
The example in description shows
purchase:
as header, but notsales:
for the next set of datafixed :)
Does this mean we only take into account products with records in both tables? In addition, can more units of a certain product be sold than purchased (or still in stock) at any given moment in time?
updated the Notes section of description as answers to your questions
In such cases, will there always be future purchases or can there be more total sales than total purchases? And if possible, can the margin still be calculated? I mean, you'll have revenue on an item, without any cost, since you don't have the item, not even in the future
Also, if more units can be sold than purchased, then Note 1 should not be OK, as you may very well sell X units, having purchased 0. In such case Note 1 should only take into account products with at least 1 sale, regardless of number of units purchased.
yes, you are absolutely right :/ I just updated initially without thinking deeply. It should not be possible to be sold more than purchased
ok, then it does not matter if at any certain moment in time, there are more sales than purchases, as future purchases will make up for such eager sales ;) I know enough to start working on this beauty of a kata now
EDIT: I notice you edited the description that such cases will not occur, which makes it even more clear for the user to solve :)
Oh I misinterpreted the notes. I thought you would make sure no more than "purchased" amount of units could be "sold" at any given time. Instead, you want us to discard the sales at such moments when no more purchased is currently in stock. That really seems odd tbh. Such sales should not have occured if you ask me.
If you want to keep the current behavior, I suggest: