Difference Between Sales Order and Purchase Order in the Transactions Table - adventureworks

So, I imagine this is a pretty elementary question I'm asking here.
But in relation to the Production.TransactionHistory table in the AdventureWorks 2017 dbo, whether the transcation type is a Sales Order or a Purchase Order, the Product Cost is the cost that Adventure Works incurred, correct?

Related

Choose correct PRODUCT COST from ROW based on amount sold

I am making a sheet to CALCULATE REAL REVENUE from each sale I make on my online store.
The problem is that the COST of my products is not always constant. It varies depending on many factors so each time I make a purchase I add the NEW PRODUCTS COST (LATEST COST).
Each time I make a new purchase I will add the QUANTITY and the new COST. (PURCHASE 1, PURCHASE 2, PURCHASE 3,etc).
Screenshoot of my sheet with example on ROW 41
In Column B I want to know which is the CURRENT COST based on the amount of TOTAL SALES of each product.
For example:
If I have sold less than 100 ( Pruchase 1 QUANTITY) then I need the formula to choose value of E41 (PURCHASE 1 COST).
If I have sold MORE than 100 and LESS than 300 (which is the SUM of PURCHASE 1 & PURCHASE 2) I need the formula to choose value of G41 (PURCHASE 2 COST) AND SO ON...
The formula I have come up with so far is this:
=INDEX(41:41,,IF(C41<=D41,COLUMN(E41),IF(C41<=D41+F41,COLUMN(E41)+2,IF(C41<=D41+F41+H41,COLUMN(E41)+4,COLUMN(E41)+6))))
This formula WORKS but only for the first 3 PURCHASES.
I need a formula that has no limit but I don't know how to make a VARIABLE formula.
Please take my words literally when I say that I wouldn't waste one minute on trying to solve your problem with your current sheet design. You would need VBA, and then extract quantities and prices from each purchase without the ability to filter on columns. (Minute is up.)
What you need is a Purchase database: ItemID, Date, Quantity, Price, maybe Ref#. From that you can pull out the transactions for any item by filtering on the item and the cost by using functions like SUMIF. However, this just brings the real problem within reach without solving it.
The problem is that when you buy 100 pcs #42 your price is 42. Then you buy another 100 pieces #46 your average price is 44. But if you sold 50 pieces with a cost of 42 then the average cost of the remaining 150 is 45. Therefore you can't determine the average cost of any remainder without knowing the quantity sold and the average cost applied to that sale. To solve that problem you will still need VBA but the suggested db format of purchase record would at least support such a solution.
Not so long ago I programmed a solution where there were additional columns in the db and each sale was recorded in 3 columns (much like your present purchase record): date, Qty, Ref. In this way I could trace the sale of each individual purchase (this was for shares trading). The sale of the newer quantity wouldn't start until the earlier quantity was sold out.
Perhaps you don't need to trace where the purchased quantity went to and just need one column to count down the balance to zero. That would be much simpler but has the drawback that you can't roll back errors. In the end the rollback was the reason why I abandoned the design. The key to the ability to abandon it is a similar db for sales: date, qty, price, Ref#.
With such a setup you might design a system to either extract the average or FiFo price from the purchase side and associate it with a sale. If the condition is that it should be done with worksheet functions you could add a column for "current cost" in the purchase db, changing with each purchase, which you look up by date from the sales side using VLOOKUP or SUMPRODUCT, having set a cost price applicable from the day of purchase until the next. If that appeals to you, a method must be found to deal with days on which there are both purchases and sales.

Recommendation for Domain Driven Design modelling

I'm trying to model two type of invoice in ddd.
Purchase invoice and sales invoice.
Simply behaviour is purchase invoice increases stock quantities and sales invoice decreases.
Which one is rigt for ddd?
1- Defining PurchaseInvoice and SalesInvoice separately that implement business logic in two different aggregate?
2- Defining one Invoice aggregate and implement business logic help with dicriminator field?
Sounds to me like Purchase and Sales are two completely different Bounded Context. Which means that an Invoice Entity could exist in both. A discriminator is a smell that you're dealing with two different things. So neither 1 or 2 seems to be the best option. I'd rather go with an Invoice in the Purchase Bounded Context and an Invoice in the Purchase Bounded Context.

Designing a domain model (class diagram) for a financial software [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
During my preparation for an exam in software engineering, I came across the following task in an old exam:
For a client, you create a new financial software whose task is, among other things, to perform tax calculations. The following requirements have been communicated to you by the Client:
The system must be able to:
calculate and display VAT for different countries and tax rates (Germany 19%, Austria 20%, Switzerland 8%).
calculate and display the income tax according to country-specific tax tables (separate table for Germany, Austria, Switzerland).
The system must allow the user to:
enter the tax relevant data (gross amount for VAT, annual income for income tax)
print the result of the tax calculation on a network printer.
send the result of the tax calculation to the appropriate tax office.
Task 1: Capture the requirements communicated by the client in a domain model (class diagram) with the following information: classes, attributes, methods, relationships, multiplicities, relationship name.
Solution:
I am not sure how to define the right classes, relationships and multiplicities. But I tried it and came to the following incomplete solution:
First Update:
Second Update:
Could someone help me with this? Thanks :)
Review of your diagram
I propose you to read your first diagram, and leave it as an exercise to cross-check if it really meets the requirements:
"A tax rate is composed of a country" (top composition). So countries do not exist independently of tax codes. Is this really what you meant? And does anything in the requirements tell that there is only one tax rate per country?
"A tax rate is composed of an (optional) income tax rate, and an (optional) VAT rate" (double composition in the middle). Ouh!?
"Every income tax rate has its own tax category(ies)" (bottom composition). Isn't the idea of categories to group similar income tax rates?
"A tax rate aggregates tax administrations, and a tax administration may appear in several aggregates" (aggregation). Why should an administration be aggregated in tax codes?
First recommentation: read in your course the difference between association, aggregation and composition. THe use of aggreegation and composition are in principle exceptional and there must be strong reasons to use use it.
Some more questions:
Where are the names of the relations?
What requirement justifies the tax administration? If it is justified, should'nt it be related to a country?
Is printing some elements really part of the domain model or does it already belong to some user-interface?
Second recommendation: only show elements taht you can reasonably derive from the requirements, and avoid any user-interface related behaviors.
Edit: your final diagram following our exchanges in the comment section represents much better what you wanted to represent initially. You could add the multiplicity 1..* rate for 1 category. You could also add a separator, in order to show classes consistently with a property and operation sections, even if one of the two is empty. The design is still basic, since all properties/attributes are public which is not recommended (but for I suppose you did this to avoid a lot of extra getters/setters in your design).
Alternate approach:
Your narrative describes one single use-case, which is perform tax calculation and consists of entering the calculation data, printing it and sending it. The actors are probably some clerc of your customer and perhaps tax offices.
I find the following candidates for classes chronologically, when reading the narrative: VAT, country, tax rate, income tax, "country-specific tax tables", gross amount, annual income, tax calculation, tax office. Let's have a closer look:
Tax office is very unclear: is there a network printer per tax office? how is the relevant tax office determined? are there one office per country, or can the organisation be more complex?
VAT and income tax are very different:
for VAT there are different rates per country. The applicable rate is always known, and the calculation is based on the applicable rate and the gross value.
For income tax the narrative speaks of country-specific tax tables: this means that the rate might not be known in advance, but depend on the taxable income level. (e.g. in Austria there is a minimum, and beyond it's flat rate; but in France, there is a normal rate, and a reduced rate for the first 500K€). In reality, income tax is much more complicated, since it may also depend on the legal form of the enterprise, or what is done with the income (re-invested vs. distributed), but let's keep it simple for the exercise. The wording leaves an ambiguity whether there is one table per country or several.
You could nevertheless generalize the concept of tax, if you'd want, considering in this exercise, that its amount is calculated for a base amount (gross amount or annual income).
The tax calculation is not fully clear: is it just the user interface, or is the calculation actually some domain object. This would give us:
This would lead to a diagram like:

Statistics for people's shoppings

I am building some project (website) on people's shopping (stuff stored in refrigerator) . I need to generate an automatic shopping cart based on people's shopping .
For example if some person buys every week one bottle of milk , than the website will offer the person to buy milk once a week (if there is no milk in refrigerator) .
I am storing shopping history of each family.
But for calculating the shopping cart i need to generate some statistics formula . But i have no clue how to do it. because there might be scenarios (for example birthday) , when the family will buy more products than needed, and it will make me false data for statistics. I want to ignore such scenarios.
Anyone has idea how and what statistics should i use?
pseudocode
assuming the customer had an account and your database is MySQL
every purchase must save customerid, product id/name ,date of purchase,comment(optional) to a table (e.g. purchased table)
customer has their own table that includes at least their personal info(e.g. customer table)
lets say customer browses the product (viewing the website)
• customer clicks the product
• system/server counts the number of purchase in purchase table
• if the number of purchase is more than one then
- get the last date of purchased product - the current date purchased product = frequency of product needed by date
- total number of product purchased / total number of times the product purchased = frequency of product needed by item count
UPDATE
I would suggest that the purchase table has a field that specifies if the current order/purchase is an occasional field instead, so it would be excluded.
example
• system/server counts the number of purchase in purchase table if the purchase is not occasional

MS Access 2003 - Calculating an average based on qty sold/per site with supply %

Here is another question I have about being able to calculate this scenario in Access, or even at all for that matter:
I have a query that find the TOP 5 items sold in a given timeframe, and it groups by site. I use this to create a comparative chart between the site for ppt presentations. I do a lot of these but I have a problem with the presentation that I foresee they will have a problem with and it makes for bad metrics:
Some stores are bigger than others, and get much more supply. So a straight aggregate total of just qty of toping selling items, and comparing the locations is stacking the deck a little.
So if Site A gets 80% of the supply, and sells 500, Site B gets 15% supply and sell 75, and site C get 5% supply and sells 50 items, then Site C actually has the best sales for their size. I have exactly what I need in terms in the first chart (from my queries and such) to show the aggregate total, but what do I need to represent the idea mentioned above.
The factors that I have that go into this are:
ItemID - group by
Item - group by
qty sold - sum/descending (which is the variable that determines the Top 5)
Store/Location - Group By
and then I run a seperate query to get the total deliveries (supply) to each site
I realize that this may just be a lack of mathmatical understanding on my part, but can anyone help with this?
thanks
The first issue that I see isn't about SQL savvy; it's how to serve your data customer. What does he or she want to see? Metrics is a term with a holy ring, and for good reason: it's supposed to be what is used for the big business decisions, and it's scary easy to measure the wrong thing.
So I'd make sure I know what my customer wants. If you can't model it on a spreadsheet, you won't be able to develop your reporting effectively.
Every deck of cards is loaded. You have to know how they want it loaded.

Resources