Lesson 5 Test your knowledge
So far we created a way to track the inventory changes produced by purchase invoices. To test what you’ve learned, we advise you to create another type of invoice called sale_invoice. This invoice is similar with purchase_invoice with some differences.
To help you out, here are some tips:
- instead of supplier entity, create and use another entity called client (this one will have same properties like supplier entity);
- instead of purchase_invoice_item, create and use an entity called sale_invoice_item (similar with purchase_invoice_item);
- in the InventoryService add another method called createOut, which creates an inventory entity that contributes to the overall of the product quantity, in a way that decreases its quantity;
- create another Event listener, but this time for the sale_invoice entity;
- modify the methods of the generated workflow (called SaleInvoiceOperations) in order to keep track of inventory changes produced by this new document (sale_invoice)
The complete ER diagram shoud look like this:
erDiagram
product {
string name
decimal price
string bar_code
int key PK "id_product"
}
supplier {
string name
string address
int key PK "id_supplier"
}
purchase_invoice {
datetime date
string number
string terms
int key PK "id_purchase_invoice"
int id_supplier FK "id_supplier"
int id_document FK "id_document"
}
purchase_invoice_item {
decimal quantity
decimal unit_price
decimal amount
int key PK "id_purchase_invoice_item"
int id_purchase_invoice FK "id_purchase_invoice"
int id_product FK "id_product"
}
document {
int key PK "id_document"
}
inventory {
decimal quantity
string description
int key PK "id_inventory"
int id_product FK "id_product"
int id_document FK "id_document"
}
client {
string name
string address
int key PK "id_client"
}
sale_invoice {
datetime date
string number
string terms
int key PK "id_sale_invoice"
int id_customer FK "id_customer"
int id_document FK "id_document"
}
sale_invoice_item {
decimal quantity
decimal unit_price
decimal amount
int key PK "id_sale_invoice_item"
int id_sale_invoice FK "id_sale_invoice"
int id_product FK "id_product"
}
purchase_invoice many--one supplier : issues
purchase_invoice one--many purchase_invoice_item : contains
purchase_invoice many--one document : references
purchase_invoice_item many--one product : references
sale_invoice one--many sale_invoice_item : contains
sale_invoice many--one client : receives
sale_invoice many--one document : references
sale_invoice_item many--one product : references
inventory many--one product : has
inventory many--one document : generates