This Scala project implements a Discount Rules Engine, designed to calculate discounts for orders based on various rules. The rules include considerations such as expiry date, product type, order date, quantity, channel, and payment method.
Discount Rules Engine is a Scala application that reads order data from a CSV file, applies discount rules to each order, calculates the discounts, and stores the processed data in an Oracle database. The project uses Apache Log4j for logging and JDBC for database connectivity.
To set up the project, follow these steps:
- Clone the repository to your local machine.
- Ensure you have Scala and SBT installed.
- Add the Oracle JDBC driver (ojdbc6.jar) to the
lib
directory of the project. - Configure the
log.xml
file for logging preferences. - Ensure an Oracle database is available to connect to.
To use the Discount Rules Engine:
- Place your order data in a CSV file (e.g.,
TRX1000.csv
) inside thesrc/main/resources
directory. - Run the
DiscountRulesEngine
object. - Check the logs for information about the application's execution.
- Verify the database for processed order data.
The Discount Rules Engine applies the following rules to calculate discounts:
- Expiry Qualification: If the order's expiry date is less than 30 days from the order date, apply a discount based on the remaining days until expiry.
- Wine or Cheese Discount: Apply a discount if the product is either wine or cheese.
- March 23rd Discount: Apply a discount if the order date is March 23rd.
- Quantity Discount: Apply a discount based on the quantity bought.
- App Discount: Apply a discount if the channel is through the app.
- Visa Discount: Apply a discount if the payment method is Visa.
The project creates a table named discountOrders
in the Oracle database to store processed order data. The table schema includes fields for order details, price before discount, discount amount, and price after discount.
The project uses Log4j for logging. Logs are configured in the log.xml
file and stored in the logs
directory.
The project has the following dependencies:
- Scala 2.13.13
- Apache Log4j 2.14.1