Now next step is to create a dtr table (for Daily Time record) as we are about to create a simple payroll program, the name of the table will be dtr. the query generated by the Work Bench should look like the ff:
CREATE TABLE `dtr` ( `dtrID` int(11) NOT NULL AUTO_INCREMENT, `TimeIn` datetime DEFAULT NULL, `TimeOut` datetime DEFAULT NULL, `idpersons` int(11) DEFAULT NULL, PRIMARY KEY (`dtrID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
The idpersons here will now become a Foreign Key (Primary Key in persons table). Foreign key plays an important role in relational database system, thus it eliminates repetition and normalized your database design to achieve high performance and high speed access through data retrieval. The Next table we are about to create is the rate table in this table we stored the current rate for each employee, the rate field in dtr table is current rate for the current payroll, the rate in the rate table serves as the rate template for the employee in every creation of new payroll, in this technique any new rate applied the previous rate that was already been paid will not be affected by the new changes in rate. The Rate table will look similar below:
CREATE TABLE `rate` ( `idrate` int(11) NOT NULL AUTO_INCREMENT, `idpersons` int(11) NOT NULL, `rate` decimal(10,2) DEFAULT NULL, PRIMARY KEY (`idrate`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
If you have noticed, the rate field is in decimal datatype and with two (2) decimal places. The reasons why we used a two decimal places is that, this would avoid differences in sum as the data grows bigger in amount, because a difference of 0.001 centavos would no affect with the total summary if the total summary will only covered small quantity but in the case of one month or one year summary these will not be the same. The Tables are now look as shown below:
The Persons table holds the names and basic information of an employee, The dtr table holds the Daily time record of each employee for each date. The rate table holds the current implemented rate for each employee. Now we’ll gonna need one more table this is payroll table. This table will holds the payroll data derived from the dtr table. as shown below:
CREATE TABLE `payroll` ( `idpayroll` int(11) NOT NULL AUTO_INCREMENT, `StartDate` date DEFAULT NULL, `EndDate` date DEFAULT NULL, `idpersons` int(11) DEFAULT NULL, `rate` decimal(10,2) DEFAULT NULL, `NumberDays` decimal(2,2) DEFAULT NULL, PRIMARY KEY (`idpayroll`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1$$</span>
The Start Date is the Start of payroll date and EndDate is the End of a payroll date, this denotes payroll range. The rate is copied from the rate table rate field. The NumberDays is the summary of DTR days present converted into number of days. If you have seven (7) days in a payroll and you have six(6) and a half day present only so it would be 6.5 days as the number of days. The idpersons is a Foreign Key in payroll table yet the primary Key in persons table. This will relate to persons table.