I have a report to build in PHP where I need time difference times hourly rate for an employee pay.
For example:
Employee Clock-In Clock-Out Total-Hours Rate Salary
Mike 2015-01-01 22:57:09 2015-01-02 11:48:14 12:51:05 10 128.51
Mike 2015-01-03 11:48:51 2015-01-06 22:19:27 82:30:36 10 825.10
Mike 2015-01-06 21:19:40 2015-01-06 22:00:00 00:40:20 10 6.72
My query is below
SELECT tt.id,ts.fname,tt.punch_in,tt.punch_out,
SEC_TO_TIME(TIMESTAMPDIFF(SECOND,tt.punch_in,tt.punch_out)) as working_hours_new,ter.hourlyrate,
((SUBSTRING(SEC_TO_TIME(TIMESTAMPDIFF(SECOND,tt.punch_in,tt.punch_out)),1,2) + SUBSTRING(SEC_TO_TIME(TIMESTAMPDIFF(SECOND,tt.punch_in,tt.punch_out)),4,2)/60 + SUBSTRING(SEC_TO_TIME(TIMESTAMPDIFF(SECOND,tt.punch_in,tt.punch_out)),7,2)/3600) * ter.hourlyrate) as pay
from tbl_times as tt left join tbl_server as ts on ts.serverid = tt.user_id left join tbl_employee_rates as ter on ter.userid=tt.user_id
where ts.locationid = ? and ts.active = 1 and ter.stauts = 1 and date(punch_in) >= ? and date(punch_out) <= ?
If this is not an easy way to do, should I do it in PHP... any suggestions?