From 523477ffba07f1ff14de6cba78b09dd734ccbe07 Mon Sep 17 00:00:00 2001 From: Patrik Oberschmid Date: Mon, 13 Apr 2026 12:55:51 +0200 Subject: [PATCH] Add firma flag to availability and show office/home label MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Server query gets the last stamp's BU_TERM in the same OUTER APPLY as LAST_STAMP, exposing FIRMA (1 = Zeiterfassung/Büro). Three OUTER APPLYs reduced to two by combining MAX(BU_BU) with TOP 1 ORDER BY. Client model gains a firma boolean and the people-tile indicator appends "· Büro" or "· Home" next to the timestamp, but only when the user is logged in. --- 3CX_TAPI.user.js | 6 +++++- client/src/availability-info.ts | 1 + client/src/availability.ts | 6 +++++- .../src/CPATapi.Server/Models/Availability.cs | 2 ++ .../Repository/ZeitConsensRepository.cs | 21 +++++++++++-------- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/3CX_TAPI.user.js b/3CX_TAPI.user.js index 2a2aa61..9a9ca8c 100644 --- a/3CX_TAPI.user.js +++ b/3CX_TAPI.user.js @@ -859,7 +859,11 @@ class Availability { var pad = (n) => n.toString().padStart(2, '0'); time = pad(d.getDate()) + '.' + pad(d.getMonth() + 1) + '. ' + pad(d.getHours()) + ':' + pad(d.getMinutes()); } - indicator.innerHTML = '' + time + ''; + var location = ''; + if (entry.loggedIn) { + location = entry.firma ? ' · Büro' : ' · Home'; + } + indicator.innerHTML = '' + time + location + ''; } updateSquare(square) { var extension = square.dataset.tapiExtension; diff --git a/client/src/availability-info.ts b/client/src/availability-info.ts index 93ba93e..85ba76d 100644 --- a/client/src/availability-info.ts +++ b/client/src/availability-info.ts @@ -3,4 +3,5 @@ export class AvailabilityInfo { public loggedIn: boolean; public extension: string; public lastStamp: string; + public firma: boolean; } diff --git a/client/src/availability.ts b/client/src/availability.ts index 39cfdb0..f658875 100644 --- a/client/src/availability.ts +++ b/client/src/availability.ts @@ -71,7 +71,11 @@ export class Availability { var pad = (n: number) => n.toString().padStart(2, '0') time = pad(d.getDate()) + '.' + pad(d.getMonth() + 1) + '. ' + pad(d.getHours()) + ':' + pad(d.getMinutes()) } - indicator.innerHTML = '' + time + '' + var location = '' + if (entry.loggedIn) { + location = entry.firma ? ' · Büro' : ' · Home' + } + indicator.innerHTML = '' + time + location + '' } private updateSquare(square: HTMLElement) { diff --git a/server/src/CPATapi.Server/Models/Availability.cs b/server/src/CPATapi.Server/Models/Availability.cs index b8b8beb..62be9ba 100644 --- a/server/src/CPATapi.Server/Models/Availability.cs +++ b/server/src/CPATapi.Server/Models/Availability.cs @@ -13,4 +13,6 @@ public class Availability public string? US_EXTENSION { get; set; } [JsonPropertyName("lastStamp")] public DateTime? LAST_STAMP { get; set; } + [JsonPropertyName("firma")] + public bool? FIRMA { get; set; } } diff --git a/server/src/CPATapi.Server/Repository/ZeitConsensRepository.cs b/server/src/CPATapi.Server/Repository/ZeitConsensRepository.cs index aea63f7..9390115 100644 --- a/server/src/CPATapi.Server/Repository/ZeitConsensRepository.cs +++ b/server/src/CPATapi.Server/Repository/ZeitConsensRepository.cs @@ -11,21 +11,24 @@ internal class ZeitConsensRepository(IConfiguration config) : Repository(config) ma.MA_USER_NAME ,bu.LOGGED_IN ,us.US_EXTENSION - ,buLastStamp.LAST_STAMP + ,buLast.LAST_STAMP + ,buLast.FIRMA FROM dbo.MA_DATEN ma - INNER JOIN projectmanagement.dbo.CP_USER us on us.US_LOGINNAME = ma.MA_USER_NAME + INNER JOIN projectmanagement.dbo.CP_USER us ON us.US_LOGINNAME = ma.MA_USER_NAME OUTER APPLY ( - SELECT count(*) % 2 AS LOGGED_IN - FROM dbo.BU + SELECT COUNT(*) % 2 AS LOGGED_IN + FROM dbo.BU bu WHERE bu.BU_MA_NR = ma.MA_NR - AND - BU_BU >= @from AND BU_BU < @to + AND bu.BU_BU >= @from AND bu.BU_BU < @to ) bu OUTER APPLY ( - SELECT MAX(BU_BU) AS LAST_STAMP - FROM dbo.BU + SELECT TOP 1 + bu.BU_BU AS LAST_STAMP + ,CASE WHEN bu.BU_TERM = 'Zeiterfassung' THEN 1 ELSE 0 END AS FIRMA + FROM dbo.BU bu WHERE bu.BU_MA_NR = ma.MA_NR - ) buLastStamp + ORDER BY bu.BU_BU DESC + ) buLast WHERE ma.MA_USER_AKTIV = 1 """;