I am currently working on structuring out a database in MySQL Workbench to keep track of expenses for Truck drivers that would be turned into an application using Java.
-
Objective:
Create a report of expenses in a table format View or Edit past expenses Display data Yearly report Total Company Salary Total Gas Expense Total Toll Expense Total Miscellaneous Expense
-
Input Needed:
Enter the Company Income earned weekly Enter the Gas Expense weekly Enter Toll Expense Weekly Enter Miscellaneous expense weekly Create a Miscellaneous category
-
Calculation:
Get Personal Salary = Company Income - (Gas Expense + Toll Expense + Miscellaneous Expense)
-
Result:
Display information in a table
Right now the issue is structuring out MySQL tables.
Currently I have:
The portion of the results and calculations will be done in Java but I would like to know if this table structure is correct? I also want the user to input the type of miscellaneous expense.
Best Answer
There are a couple of problems with this design.
NOTE: With points 3 & 4 above, if personal salary and company income are not annual/on-going static values but are instead values for a specific project or contract then these should still not be stored with expenses. Create a new table for Project/Contract, add a foreign key referencing a project/contract to the expense table and do it that way.
Also, consider your application design. Doing aggregations and calculations across small data sets in Java is fine, but if you're talking about producing annual reports and your data set grows large, this processing would probably be best handled by the database engine which can handle this work in a set-based method rather than row-by-row processing as happens in most applications.