445 lines
12 KiB
Go
445 lines
12 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: payroll.sql
|
|
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const countTourengeldAmountInPeriod = `-- name: CountTourengeldAmountInPeriod :one
|
|
WITH ToursInPeriod AS (
|
|
SELECT
|
|
(("startDate" AT TIME ZONE 'UTC') AT TIME ZONE 'Europe/Berlin')::DATE as day,
|
|
"operationId",
|
|
"occupiedKm",
|
|
CASE
|
|
WHEN "occupiedKm" <= 30 THEN 1.0
|
|
ELSE ROUND("occupiedKm" / 30.0)
|
|
END AS tour_value
|
|
FROM
|
|
"Tour"
|
|
WHERE
|
|
"check" <> 3
|
|
AND "deletedAt" IS NULL
|
|
AND (
|
|
"patientId" IS NULL
|
|
OR "patientId" NOT IN (
|
|
'b7424477-a4b2-42f7-b7e7-a4bef24f6979',
|
|
'3554e1a9-9c07-45e5-b53c-692a77e4fa9a'
|
|
)
|
|
)
|
|
-- ID's for Pause and Feierabend respectively
|
|
AND (
|
|
"carName" IS NULL
|
|
OR "carName" NOT IN (
|
|
'Storno',
|
|
'Abgabe',
|
|
'Löschen'
|
|
)
|
|
AND "carName" LIKE '%KTW%'
|
|
)
|
|
AND "startDate" >= $1
|
|
AND "startDate" <= $2
|
|
AND ("driverId" ILIKE $3 OR "codriverId" ILIKE $3)
|
|
ORDER BY
|
|
"day"
|
|
),
|
|
DailyCounts AS (
|
|
SELECT
|
|
day,
|
|
SUM(tour_value) AS tour_amount
|
|
FROM
|
|
ToursInPeriod
|
|
GROUP BY
|
|
day
|
|
),
|
|
HighActivityDays AS (
|
|
SELECT
|
|
day,
|
|
GREATEST(0, tour_amount - 6) AS tourengeld
|
|
FROM
|
|
DailyCounts
|
|
),
|
|
TourenGeld AS (
|
|
SELECT
|
|
SUM(tourengeld)::float as tourengeld
|
|
FROM
|
|
HighActivityDays
|
|
)
|
|
SELECT
|
|
COALESCE(tourengeld, 0.0)
|
|
FROM TourenGeld
|
|
`
|
|
|
|
type CountTourengeldAmountInPeriodParams struct {
|
|
StartDate time.Time `json:"start_date"`
|
|
EndDate time.Time `json:"end_date"`
|
|
EmployeeID pgtype.Text `json:"employee_id"`
|
|
}
|
|
|
|
func (q *Queries) CountTourengeldAmountInPeriod(ctx context.Context, arg CountTourengeldAmountInPeriodParams) (float64, error) {
|
|
row := q.db.QueryRow(ctx, countTourengeldAmountInPeriod, arg.StartDate, arg.EndDate, arg.EmployeeID)
|
|
var tourengeld float64
|
|
err := row.Scan(&tourengeld)
|
|
return tourengeld, err
|
|
}
|
|
|
|
const countVerpflegungspauschale = `-- name: CountVerpflegungspauschale :one
|
|
SELECT
|
|
count(*)
|
|
FROM "WorkTime"
|
|
WHERE
|
|
duration > 480
|
|
AND "startDate" BETWEEN $1 AND $2
|
|
AND "userId"::int = $3::bigint
|
|
`
|
|
|
|
type CountVerpflegungspauschaleParams struct {
|
|
StartDate *time.Time `json:"start_date"`
|
|
EndDate *time.Time `json:"end_date"`
|
|
EmployeeID int64 `json:"employee_id"`
|
|
}
|
|
|
|
func (q *Queries) CountVerpflegungspauschale(ctx context.Context, arg CountVerpflegungspauschaleParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countVerpflegungspauschale, arg.StartDate, arg.EndDate, arg.EmployeeID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const evaluatePunctualityForEmployee = `-- name: EvaluatePunctualityForEmployee :one
|
|
WITH
|
|
planned_start_times AS (
|
|
SELECT
|
|
DISTINCT ON ("startDate"::DATE)
|
|
"startDate"::DATE AS plan_day,
|
|
"startDate" AS planned_start_time
|
|
FROM "PlannedTime" as p
|
|
WHERE
|
|
p."userId"::int = $1::bigint
|
|
AND p."startDate" BETWEEN $2 AND $3
|
|
AND p."startDate" IS NOT NULL
|
|
AND p.department <> 'Fortbildung'
|
|
AND p.note IS NULL
|
|
ORDER BY
|
|
"startDate"::DATE, "startDate" ASC
|
|
),
|
|
actual_start_times AS (
|
|
SELECT
|
|
DISTINCT ON ("startDate"::DATE)
|
|
"startDate"::DATE AS work_day,
|
|
"startDate" AS actual_start_time
|
|
FROM "WorkTime"
|
|
WHERE
|
|
"userId"::int = $1::bigint
|
|
AND "startDate" BETWEEN $2 AND $3
|
|
AND "startDate" IS NOT NULL
|
|
ORDER BY
|
|
"startDate"::DATE, "startDate" ASC
|
|
),
|
|
daily_comparison AS (
|
|
SELECT
|
|
p.plan_day,
|
|
p.planned_start_time,
|
|
a.actual_start_time,
|
|
(a.actual_start_time IS NOT NULL AND a.actual_start_time <= p.planned_start_time) AS was_punctual
|
|
FROM planned_start_times p
|
|
LEFT JOIN actual_start_times a ON p.plan_day = a.work_day
|
|
)
|
|
SELECT
|
|
COUNT(CASE WHEN was_punctual THEN 1 END) AS punctual_days
|
|
FROM daily_comparison
|
|
`
|
|
|
|
type EvaluatePunctualityForEmployeeParams struct {
|
|
EmployeeID int64 `json:"employee_id"`
|
|
StartDate *time.Time `json:"start_date"`
|
|
EndDate *time.Time `json:"end_date"`
|
|
}
|
|
|
|
func (q *Queries) EvaluatePunctualityForEmployee(ctx context.Context, arg EvaluatePunctualityForEmployeeParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, evaluatePunctualityForEmployee, arg.EmployeeID, arg.StartDate, arg.EndDate)
|
|
var punctual_days int64
|
|
err := row.Scan(&punctual_days)
|
|
return punctual_days, err
|
|
}
|
|
|
|
const getWeeklyTimeSummaryForEmployee = `-- name: GetWeeklyTimeSummaryForEmployee :many
|
|
WITH all_time_entries AS (
|
|
SELECT
|
|
DATE_TRUNC('week', "startDate") AS week_start,
|
|
SUM("duration" / 60.0) as worked_hours,
|
|
count(DISTINCT DATE_TRUNC('day', "startDate"))::float as worked_days,
|
|
0::float AS sick_hours,
|
|
0::float AS holiday_days
|
|
FROM "WorkTime"
|
|
WHERE
|
|
"startDate" BETWEEN $1 AND $2
|
|
AND "userId"::int = $3
|
|
AND "startDate" IS NOT NULL
|
|
GROUP BY
|
|
DATE_TRUNC('week', "startDate")
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
DATE_TRUNC('week', "start") AS week_start,
|
|
0::float as worked_hours,
|
|
0::float as worked_days,
|
|
SUM("hours") AS sick_hours,
|
|
0::float AS holiday_days
|
|
FROM "Sickdays"
|
|
WHERE
|
|
"start" BETWEEN $1 AND $2
|
|
AND "employeeId" = $3
|
|
AND "start" IS NOT NULL
|
|
GROUP BY
|
|
DATE_TRUNC('week', "start")
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
DATE_TRUNC('week', "date") AS week_start,
|
|
0::float as worked_hours,
|
|
0::float as worked_days,
|
|
0::float AS sick_hours,
|
|
count(*)::float AS holiday_days
|
|
FROM "Holiday"
|
|
WHERE
|
|
"date" BETWEEN $1 AND $2
|
|
AND "employeeId" = $3
|
|
AND "date" IS NOT NULL
|
|
GROUP BY
|
|
DATE_TRUNC('week', "date")
|
|
)
|
|
SELECT
|
|
week_start::timestamp,
|
|
SUM(worked_hours)::float AS total_worked_hours,
|
|
SUM(worked_days)::float AS total_worked_days,
|
|
SUM(sick_hours)::float AS total_sick_hours,
|
|
SUM(holiday_days)::float AS total_holiday_days
|
|
FROM all_time_entries
|
|
GROUP BY
|
|
week_start
|
|
ORDER BY
|
|
week_start
|
|
`
|
|
|
|
type GetWeeklyTimeSummaryForEmployeeParams struct {
|
|
StartDate *time.Time `json:"start_date"`
|
|
EndDate *time.Time `json:"end_date"`
|
|
EmployeeID string `json:"employee_id"`
|
|
}
|
|
|
|
type GetWeeklyTimeSummaryForEmployeeRow struct {
|
|
WeekStart time.Time `json:"week_start"`
|
|
TotalWorkedHours float64 `json:"total_worked_hours"`
|
|
TotalWorkedDays float64 `json:"total_worked_days"`
|
|
TotalSickHours float64 `json:"total_sick_hours"`
|
|
TotalHolidayDays float64 `json:"total_holiday_days"`
|
|
}
|
|
|
|
func (q *Queries) GetWeeklyTimeSummaryForEmployee(ctx context.Context, arg GetWeeklyTimeSummaryForEmployeeParams) ([]GetWeeklyTimeSummaryForEmployeeRow, error) {
|
|
rows, err := q.db.Query(ctx, getWeeklyTimeSummaryForEmployee, arg.StartDate, arg.EndDate, arg.EmployeeID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetWeeklyTimeSummaryForEmployeeRow
|
|
for rows.Next() {
|
|
var i GetWeeklyTimeSummaryForEmployeeRow
|
|
if err := rows.Scan(
|
|
&i.WeekStart,
|
|
&i.TotalWorkedHours,
|
|
&i.TotalWorkedDays,
|
|
&i.TotalSickHours,
|
|
&i.TotalHolidayDays,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const isEmployeesDepartmentKTW = `-- name: IsEmployeesDepartmentKTW :one
|
|
SELECT COALESCE(
|
|
(
|
|
bool_or(department LIKE '%KTW%')
|
|
AND
|
|
bool_and(department <> 'Leitstelle')
|
|
),
|
|
false
|
|
)::bool as meets_requirements
|
|
FROM "PlannedTime"
|
|
WHERE
|
|
"userId"::int = $1::bigint
|
|
AND "startDate" BETWEEN $2 AND $3
|
|
AND department IS NOT NULL
|
|
`
|
|
|
|
type IsEmployeesDepartmentKTWParams struct {
|
|
EmployeeID int64 `json:"employee_id"`
|
|
StartDate *time.Time `json:"start_date"`
|
|
EndDate *time.Time `json:"end_date"`
|
|
}
|
|
|
|
func (q *Queries) IsEmployeesDepartmentKTW(ctx context.Context, arg IsEmployeesDepartmentKTWParams) (bool, error) {
|
|
row := q.db.QueryRow(ctx, isEmployeesDepartmentKTW, arg.EmployeeID, arg.StartDate, arg.EndDate)
|
|
var meets_requirements bool
|
|
err := row.Scan(&meets_requirements)
|
|
return meets_requirements, err
|
|
}
|
|
|
|
const isEmployeesDepartmentNotLeitstelle = `-- name: IsEmployeesDepartmentNotLeitstelle :one
|
|
SELECT COALESCE(
|
|
(
|
|
(
|
|
bool_or(department LIKE '%KTW%')
|
|
OR bool_or(department LIKE '%BTW%')
|
|
OR bool_or(department LIKE '%TSW%')
|
|
)
|
|
AND
|
|
bool_and(department <> 'Leitstelle')
|
|
),
|
|
false
|
|
)::bool as meets_requirements
|
|
FROM "PlannedTime"
|
|
WHERE
|
|
"userId"::int = $1::bigint
|
|
AND "startDate" BETWEEN $2 AND $3
|
|
AND department IS NOT NULL
|
|
`
|
|
|
|
type IsEmployeesDepartmentNotLeitstelleParams struct {
|
|
EmployeeID int64 `json:"employee_id"`
|
|
StartDate *time.Time `json:"start_date"`
|
|
EndDate *time.Time `json:"end_date"`
|
|
}
|
|
|
|
func (q *Queries) IsEmployeesDepartmentNotLeitstelle(ctx context.Context, arg IsEmployeesDepartmentNotLeitstelleParams) (bool, error) {
|
|
row := q.db.QueryRow(ctx, isEmployeesDepartmentNotLeitstelle, arg.EmployeeID, arg.StartDate, arg.EndDate)
|
|
var meets_requirements bool
|
|
err := row.Scan(&meets_requirements)
|
|
return meets_requirements, err
|
|
}
|
|
|
|
const listActiveEmployees = `-- name: ListActiveEmployees :many
|
|
SELECT
|
|
de.id,
|
|
de.firstname,
|
|
de.surname,
|
|
de."contractStart",
|
|
de."contractEnd",
|
|
de."contractDaysWeek",
|
|
de."contractHoursWeek",
|
|
de."contractSalaryHour",
|
|
de."contractTypeName",
|
|
e.id as "dlId",
|
|
e."personTransportCertificate"
|
|
FROM "DyflexisEmployee" as de
|
|
INNER JOIN "Employee" as e ON de.id::text = e."personnelNumber"
|
|
WHERE de."contractStart" < CURRENT_DATE AND de."contractEnd" > (CURRENT_DATE - INTERVAL '2 months')
|
|
AND de.surname <> 'Shahrasebi'
|
|
ORDER BY de.firstname ASC
|
|
`
|
|
|
|
type ListActiveEmployeesRow struct {
|
|
ID int32 `json:"id"`
|
|
Firstname string `json:"firstname"`
|
|
Surname string `json:"surname"`
|
|
ContractStart time.Time `json:"contractStart"`
|
|
ContractEnd *time.Time `json:"contractEnd"`
|
|
ContractDaysWeek int32 `json:"contractDaysWeek"`
|
|
ContractHoursWeek float64 `json:"contractHoursWeek"`
|
|
ContractSalaryHour float64 `json:"contractSalaryHour"`
|
|
ContractTypeName pgtype.Text `json:"contractTypeName"`
|
|
DlId string `json:"dlId"`
|
|
PersonTransportCertificate *time.Time `json:"personTransportCertificate"`
|
|
}
|
|
|
|
func (q *Queries) ListActiveEmployees(ctx context.Context) ([]ListActiveEmployeesRow, error) {
|
|
rows, err := q.db.Query(ctx, listActiveEmployees)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListActiveEmployeesRow
|
|
for rows.Next() {
|
|
var i ListActiveEmployeesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Firstname,
|
|
&i.Surname,
|
|
&i.ContractStart,
|
|
&i.ContractEnd,
|
|
&i.ContractDaysWeek,
|
|
&i.ContractHoursWeek,
|
|
&i.ContractSalaryHour,
|
|
&i.ContractTypeName,
|
|
&i.DlId,
|
|
&i.PersonTransportCertificate,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listSickdaysForEmployee = `-- name: ListSickdaysForEmployee :many
|
|
SELECT
|
|
"start",
|
|
"end",
|
|
"days",
|
|
locked
|
|
FROM "Sickdays"
|
|
WHERE
|
|
"employeeId" = $1
|
|
ORDER BY start asc
|
|
`
|
|
|
|
type ListSickdaysForEmployeeRow struct {
|
|
Start time.Time `json:"start"`
|
|
End time.Time `json:"end"`
|
|
Days int32 `json:"days"`
|
|
Locked bool `json:"locked"`
|
|
}
|
|
|
|
func (q *Queries) ListSickdaysForEmployee(ctx context.Context, employeeID int32) ([]ListSickdaysForEmployeeRow, error) {
|
|
rows, err := q.db.Query(ctx, listSickdaysForEmployee, employeeID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListSickdaysForEmployeeRow
|
|
for rows.Next() {
|
|
var i ListSickdaysForEmployeeRow
|
|
if err := rows.Scan(
|
|
&i.Start,
|
|
&i.End,
|
|
&i.Days,
|
|
&i.Locked,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|