Calculate number of sales of a seller

Asked

Viewed 89 times

0

I’m doing academic work on comics, in this case I’m developing a database for a food distributor. I am in doubt as to how I can count the amount of sales that a seller has made in order to calculate the commission value. In addition, I created an entity for QUANTITY, how can I know the quantity of a product in an order occurrence?

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

2 answers

3


To help you create an entity model, think like this:

What is quantity? Does it contain attributes, data that describe it? Or is it a property of something else that contains it?

In your case, note that the quantity is actually an attribute of the Order, because when you order some product, you usually inform the desired quantity, agree? Thus, it does not make sense to create an entity for quantity, because it is only a number, it makes more sense to place it as an attribute of the Request entity, and from the request you would already know the occurrences of requests for a product.

  • But in case an order has several different products, if I put quantity as order attribute I will be limiting the quantity of all products and not only one?

  • 2

    In this case, you have an order relationship with multiple products and one product in multiple orders (Many to Many). When we have this situation, it is necessary to create a table that relates the order to the product, you can call it Pedidoproduct. There will be the product id and the order id (references to the order and product tables), which creates this relationship between these entities! You will create a record in this table for each product contained in the order. If you want, I will add this explanation in the reply.

  • Will I merge entities then? In that case the quantity of one product does not interfere with another?

  • You will create a new entity called Productopedido, maintaining the entities Product and Order, that is, it is not a merger, it is the creation of a new entity. The Quantity entity you remove, as it will exist as a property of the Request entity, just as you created the "total value" and "code". In the new entity Productopedido you will point to Product and Order, because it will have the id_product and id_request properties, each note being a relationship 1 to n.

  • Productopedido will be related to Order and Product?

  • That’s right. It allows you to have several products related to an order.

  • What are the attributes of the Produced entity?

  • Just a code identifier? I understand what you are talking about, but I am in doubt of how this entity works.

  • 1

    This entity will only have the product id and order id, so it is called Productopedido. It simply lists products with their respective orders.

Show 4 more comments

0

You could create a table for each product that counts with its history, inputs and outputs with the order number set as a foreign key.

So you can calculate the amount of each product withdrawn per order.

And by assigning the order to the seller, it would be simple to know how much of a product he(a) sold.

Anyway, quantity is not quite an entity and as it was put by @Giuliana Bezerra:

So it doesn’t make sense to create an entity for quantity, because it’s just a number, it makes more sense to put it as an attribute

Browser other questions tagged

You are not signed in. Login or sign up in order to post.