diff options
author | T <t@tjp.lol> | 2025-08-04 15:34:23 -0600 |
---|---|---|
committer | T <t@tjp.lol> | 2025-08-04 19:49:08 -0600 |
commit | dc895cec9d8a84af89ce2501db234dff33c757e2 (patch) | |
tree | 8c961466f0769616b3a82da91f4cde4d3a881b73 /internal/database | |
parent | 56e0af3b41742876b471332aeb943a5a2ca8dfbf (diff) |
timesheet and unified reports
Diffstat (limited to 'internal/database')
-rw-r--r-- | internal/database/queries.sql | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/database/queries.sql b/internal/database/queries.sql index 32114a6..3a644b8 100644 --- a/internal/database/queries.sql +++ b/internal/database/queries.sql @@ -231,3 +231,56 @@ where year = @year and month = @month; insert into invoice (year, month, number, client_id, total_amount) values (@year, @month, @number, @client_id, @total_amount) returning *; + +-- name: GetTimesheetDataByClient :many +select + te.id as time_entry_id, + te.start_time, + te.end_time, + te.description, + te.billable_rate as entry_billable_rate, + c.id as client_id, + c.name as client_name, + c.billable_rate as client_billable_rate, + p.id as project_id, + p.name as project_name, + p.billable_rate as project_billable_rate, + cast(round((julianday(te.end_time) - julianday(te.start_time)) * 24 * 60 * 60) as integer) as duration_seconds +from time_entry te +join client c on te.client_id = c.id +left join project p on te.project_id = p.id +where c.id = @client_id + and te.start_time >= @start_time + and te.start_time <= @end_time + and te.end_time is not null +order by te.start_time; + +-- name: GetTimesheetDataByProject :many +select + te.id as time_entry_id, + te.start_time, + te.end_time, + te.description, + te.billable_rate as entry_billable_rate, + c.id as client_id, + c.name as client_name, + c.billable_rate as client_billable_rate, + p.id as project_id, + p.name as project_name, + p.billable_rate as project_billable_rate, + cast( + case + when te.end_time is null then + (julianday('now', 'utc') - julianday(te.start_time)) * 24 * 60 * 60 + else + (julianday(te.end_time) - julianday(te.start_time)) * 24 * 60 * 60 + end as integer + ) as duration_seconds +from time_entry te +join client c on te.client_id = c.id +join project p on te.project_id = p.id +where p.id = @project_id + and te.start_time >= @start_time + and te.start_time <= @end_time + and te.end_time is not null +order by te.start_time; |