MItarbeiteruebersicht - Zeiterfassung

This commit is contained in:
2023-07-10 12:13:52 +02:00
parent e77b22cefc
commit d98669dde2
2 changed files with 229 additions and 37 deletions

View File

@@ -1,9 +1,12 @@
Imports System.ComponentModel
Imports System.Drawing
Imports System.Net
Imports VERAG_PROG_ALLGEMEIN.cCreditSafeAPI
Public Class frmMitarbeitersuche
Dim mit_id As Integer = -1
Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
Dim requestDone As Boolean = False
Sub New()
' Dieser Aufruf ist für den Designer erforderlich.
@@ -57,6 +60,8 @@ Public Class frmMitarbeitersuche
Sub initMA()
btn.Visible = False
pnl.Visible = False
lblTimasZeiten.Visible = False
lblTimasSaldo.Visible = False
Panel1.Visible = False
btnSettings.Visible = False
Dim MA As cMitarbeiter = Nothing
@@ -152,6 +157,10 @@ Public Class frmMitarbeitersuche
End If
If VERAG_PROG_ALLGEMEIN.cAllgemein.USRID = MA.mit_id Then
btn.Visible = True
'Eintrag für Zeitübersicht
lblTimasZeiten.Visible = True
lblTimasSaldo.Visible = True
If Not requestDone Then getTime(MA.mit_timasId)
End If
If VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG_bool("MA_TeamBearbeiten", "SDL") Then
@@ -208,4 +217,164 @@ Public Class frmMitarbeitersuche
initMA()
End Sub
Private Sub getTime(maid)
Try
Dim returnText As String = ""
lblTimasZeiten.Text = ""
If maid Is Nothing Then
Exit Sub
End If
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim rest As New Chilkat.Rest
Dim API_STRING As String
API_STRING = "https://zeit.verag.ag"
Dim success As Boolean
rest.VerboseLogging = True
Dim bTls As Boolean = True
Dim port As Integer = 443
Dim bAutoReconnect As Boolean = True
success = rest.Connect(API_STRING, port, bTls, bAutoReconnect)
If (success <> True) Then
Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
Debug.WriteLine(rest.LastErrorText)
'lblTimas.Text = rest.LastErrorText
End If
success = rest.SetAuthBasic("admin", "BmWr501956")
If (success <> True) Then
Debug.WriteLine("BAFailReason: " & rest.ConnectFailReason)
Debug.WriteLine(rest.LastErrorText)
'lblTimas.Text = rest.LastErrorText
End If
Dim responseJson As String = rest.FullRequestNoBody("GET", "/rest/web-api/employees/" & maid & "/balance")
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
If (rest.ResponseStatusCode <> 200) Then
Debug.WriteLine(rest.ResponseHeader)
'lblTimas.Text = rest.ResponseStatusCode & " " & rest.ResponseStatusText
Exit Sub
End If
Debug.WriteLine(responseJson)
Dim json As New Chilkat.JsonObject
success = json.Load(responseJson)
If (success <> True) Then
Debug.WriteLine(json.LastErrorText)
End If
Debug.WriteLine(json)
'"overallBalance" 101580,
'"dailyBalance": -17340,
'"monthlyBalance": -328380,
'"actualTimeOfDay": 4260,
Dim saldo = json.StringOf("dailyBalanceYesterday") 'Tagessaldo (gestern) in Sekunden
If saldo IsNot Nothing Then
Dim saldoAsDouble = CDbl(saldo)
saldoAsDouble = Math.Round(saldoAsDouble / 3600, 2)
returnText = "Saldo Vortag: " & saldoAsDouble & "h"
End If
lblTimasSaldo.Text = returnText
Dim yesterdayMidnight As DateTime
yesterdayMidnight = Today().AddDays(-1)
rest.AddQueryParam("id", maid)
rest.AddQueryParam("from", yesterdayMidnight.ToString("yyyy-MM-ddThh:mm:ss"))
rest.AddQueryParam("to", Now().ToString("yyyy-MM-ddThh:mm:ss"))
Dim Response As String
Response = rest.FullRequestNoBody("GET", "/rest/web-api/employees/" & maid & "/bookings")
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
If (rest.ResponseStatusCode <> 200) Then
Debug.WriteLine(rest.ResponseHeader)
'rest.ResponseStatusCode & " " & rest.ResponseStatusText
Exit Sub
End If
Debug.WriteLine(Response)
Dim jsonArray As New Chilkat.JsonArray
success = jsonArray.Load(Response)
If (success <> True) Then
Debug.WriteLine(jsonArray.LastErrorText)
Exit Sub
End If
If jsonArray.Size = -1 Then
Exit Sub
End If
Dim dt As New DataTable
dt.Columns.Add("statusid", GetType(Integer))
dt.Columns.Add("stamp", GetType(DateTime))
dt.Columns.Add("type", GetType(String))
Dim j As Integer = 0
While j < jsonArray.Size
Dim timeEntry As Chilkat.JsonObject = jsonArray.ObjectAt(j)
If IsDate(timeEntry.StringOf("stamp")) Then
If CDate(timeEntry.StringOf("stamp")) >= Today() Then
Dim R As DataRow = dt.NewRow
R("statusid") = timeEntry.StringOf("statusid")
R("stamp") = timeEntry.StringOf("stamp")
R("type") = timeEntry.StringOf("type")
dt.Rows.Add(R)
lblTimasZeiten.Text &= " " & IIf(timeEntry.StringOf("type") = "in", "+", " - ") & CDate(timeEntry.StringOf("stamp")).ToString("hh:mm:ss")
If jsonArray.Size - 1 = j Then
lblTimasZeiten.Text &= " Status: " & IIf(timeEntry.StringOf("type") = "in", "Anwesend", "Abwesend")
End If
End If
End If
j = j + 1
End While
requestDone = True
rest.ClearAllQueryParams()
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
End Class