Creating Business Rules
You will now learn about business rules and how to define them for the Order Entry sample application.
From the database application standpoint, business rules are the underlying data-processing "laws" of an application. Typical rules would include:
- Data deletion constraints (such as not allowing the deletion of a customer who has outstanding invoices).
- Data validation (such as ensuring that a new order can't be created for customers who are already over their credit limits or making sure an entered payment type is permitted).
Although business rules will often have common elements from one application to the next (like the deletion-constraint example), these rules are more typically application-specific and, therefore, may encompass a tremendously diverse range of functionality. DataFlex is outstanding in its ability to handle any data rule, no matter how complex or unique; you will be able to implement what is needed to deliver your application.
Business Rules for the Order Entry Application
For the Order Entry application, we need the following business rules:
- If a customer appears on any order, users cannot remove that customer from the
customertable. - If a vendor supplies an item that appears in the
inventorytable, you cannot delete the vendor from thevendorstable. - Users cannot sell more parts than are already in the inventory stock. If they do, an error message informing them of that fact should be generated.
- If an item appears on an order (or is associated with several orders), you cannot delete the item from the
inventorypartstable. - When an item is ordered, you must decrement the quantity ordered from the quantity on hand. This will give you the current amount of inventory for each item.
- The
OrderHeader.Totalcolumn is the sum of all the extended detail prices. - Only one customer per order is allowed.
- Automatically incrementing numbers must be created for new orders, customers, and vendors.
- The extension for each item is the quantity ordered multiplied by the unit price.
- If a salesperson is responsible for any existing orders, you cannot remove that salesperson from the
salespersonstable. - Each line item in the invoice's table (or grid) must be numbered.
Business rules may be implemented at the database level, at the Data Dictionary level (or several levels of Data Dictionary classes), at the interface level, or a combination thereof. Where you decide to enforce the rules will depend on how you need the application to interact with its users, and how strictly the rule may need to be enforced across multiple programs or applications. It is better to implement as many of the rules as possible in the Data Dictionaries. They will be enforced whenever the referenced tables are used, and maintenance is centralized in one area.