Could someone help me with a rough database schema for a timesheet application where the i would be able to
Store hours per day for a time period ( 2 weeks ) for different projects. Ex person A can put 3 hours for projectA and 4 hours for projectB on the same day
Make it so that its is easy to get a reports on total hours put for a project, or to get total hours on all projects by a certain person
EDIT: Another requirement would be that each timesheet for a particular time period for every person needs to have a field indicating that the person has submitted the timesheet and another saying that it has been approved
The following code is taken from the ]project-open[ open-source system in PostgreSQL syntax and edited.
Please note the "conf_objects" table with approval/confirmation information. When the user "submits" a time sheet, all submitted hours are assigned to a new conf_object. It's the job of the supervisor to set the status of the conf_object to "approved". Both the supervisor or the user may delete the conf_object at any time, which will will mark the hours as "not submitted" (hour.conf_object_id = NULL) again, so that these hours will end up on the "Hours Not Submitted" report.
The original ]po[ SQL statements are included in the ~/packages/intranet-*/sql/postgresql/intranet-*-create.sql creation scripts.
Borrowing from Eric Petroelje & mdma:
The first index of WorkSegment is ProjectID, Date. The second index of WorkSegment is EmployeeID, Date. These indexes are not unique. This is so a person can work on a project more than once in one day. The indexes allow for reporting on hours worked by project or by person.
Each WorkSegment row is for one segment of time, one day, one project. Each employee has as many WorkSegment rows as is needed to describe his payroll cycle.
There is a unique index on ProjectID, EmployeeID, and PayrollCycleID. There is one TimeSheetSegment row for each project that an employee works for during a payroll cycle.
The TimeSheet row brings the TimeSheetSegment and WorkSegment rows together. The EmployeeID, PayrollCycleID index is unique.
The Approval row is created when the time sheet is submitted. These fields could be part of the TimeSheet table. I broke them out with a fourth-order normalization because the Approval table is likely to have different database access permissions than the TimeSheet table.
The PayrollCycle table normalizes some of the date fields, and provides an integer key that makes it easier to pull together the WorkSegment and TimeSheetSegment rows to make a coherent time sheet.
A table for people(1)
A table for projects(2)
A table for bookings(3) - who did the work (FK into 1), what project did they work on (FK into 2), when did they do the work, how much work did they do.
Select sum(time_booked) from (3) where person equals (some id from 1) and project = (some ID from 2)
or
Select sum(time_booked) from (3) where person equals (some id from 1)
etc...
Sounds a bit like homework, but I'd probably start with something like this:
Here is a rough sketch that will give you a good start:
EDIT: As an alternative to the approved flag in each ProjectTimesheet row, you could instead separate out the approved status to a separate table. For example, to allow approval for an employee's timesheet over a given period, a manager would add an approval entry to the Approval table: