summaryrefslogtreecommitdiff
path: root/internal/queries/queries.sql.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/queries/queries.sql.go')
-rw-r--r--internal/queries/queries.sql.go169
1 files changed, 169 insertions, 0 deletions
diff --git a/internal/queries/queries.sql.go b/internal/queries/queries.sql.go
index e70de22..dff9659 100644
--- a/internal/queries/queries.sql.go
+++ b/internal/queries/queries.sql.go
@@ -654,6 +654,175 @@ func (q *Queries) GetProjectByNameAndClient(ctx context.Context, arg GetProjectB
return i, err
}
+const getTimesheetDataByClient = `-- 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 = ?1
+ and te.start_time >= ?2
+ and te.start_time <= ?3
+ and te.end_time is not null
+order by te.start_time
+`
+
+type GetTimesheetDataByClientParams struct {
+ ClientID int64
+ StartTime time.Time
+ EndTime time.Time
+}
+
+type GetTimesheetDataByClientRow struct {
+ TimeEntryID int64
+ StartTime time.Time
+ EndTime sql.NullTime
+ Description sql.NullString
+ EntryBillableRate sql.NullInt64
+ ClientID int64
+ ClientName string
+ ClientBillableRate sql.NullInt64
+ ProjectID sql.NullInt64
+ ProjectName sql.NullString
+ ProjectBillableRate sql.NullInt64
+ DurationSeconds int64
+}
+
+func (q *Queries) GetTimesheetDataByClient(ctx context.Context, arg GetTimesheetDataByClientParams) ([]GetTimesheetDataByClientRow, error) {
+ rows, err := q.db.QueryContext(ctx, getTimesheetDataByClient, arg.ClientID, arg.StartTime, arg.EndTime)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []GetTimesheetDataByClientRow
+ for rows.Next() {
+ var i GetTimesheetDataByClientRow
+ if err := rows.Scan(
+ &i.TimeEntryID,
+ &i.StartTime,
+ &i.EndTime,
+ &i.Description,
+ &i.EntryBillableRate,
+ &i.ClientID,
+ &i.ClientName,
+ &i.ClientBillableRate,
+ &i.ProjectID,
+ &i.ProjectName,
+ &i.ProjectBillableRate,
+ &i.DurationSeconds,
+ ); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Close(); err != nil {
+ return nil, err
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
+const getTimesheetDataByProject = `-- 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 = ?1
+ and te.start_time >= ?2
+ and te.start_time <= ?3
+ and te.end_time is not null
+order by te.start_time
+`
+
+type GetTimesheetDataByProjectParams struct {
+ ProjectID int64
+ StartTime time.Time
+ EndTime time.Time
+}
+
+type GetTimesheetDataByProjectRow struct {
+ TimeEntryID int64
+ StartTime time.Time
+ EndTime sql.NullTime
+ Description sql.NullString
+ EntryBillableRate sql.NullInt64
+ ClientID int64
+ ClientName string
+ ClientBillableRate sql.NullInt64
+ ProjectID int64
+ ProjectName string
+ ProjectBillableRate sql.NullInt64
+ DurationSeconds int64
+}
+
+func (q *Queries) GetTimesheetDataByProject(ctx context.Context, arg GetTimesheetDataByProjectParams) ([]GetTimesheetDataByProjectRow, error) {
+ rows, err := q.db.QueryContext(ctx, getTimesheetDataByProject, arg.ProjectID, arg.StartTime, arg.EndTime)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []GetTimesheetDataByProjectRow
+ for rows.Next() {
+ var i GetTimesheetDataByProjectRow
+ if err := rows.Scan(
+ &i.TimeEntryID,
+ &i.StartTime,
+ &i.EndTime,
+ &i.Description,
+ &i.EntryBillableRate,
+ &i.ClientID,
+ &i.ClientName,
+ &i.ClientBillableRate,
+ &i.ProjectID,
+ &i.ProjectName,
+ &i.ProjectBillableRate,
+ &i.DurationSeconds,
+ ); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Close(); err != nil {
+ return nil, err
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
const getWeekSummaryByProject = `-- name: GetWeekSummaryByProject :many
select
p.id as project_id,