Jump to content

Recommended Posts

Posted

Hi,

I am trying to create a bit of hour registration tool.

The problem i am running into is that allmost every body works 40 hours (5 days) a week except for 2 people.
The work 24 hours (3 days) a week.

I made a registration of how many hours they work, wich I can read and use for calculation.
Also i have made a GUI with 2 date pickers that calculate the difference in days between them, keeping in mind that the weekend is not a work day.

The difference I multiply by 8 to calculate how many hours needs to be registered, here lies my problem when someone is working 3 days a week it should not be showing 40 hours but only 24 hours.

 

I'm hoping that there is a way to do this.

 

The hours per week a written down in a ini file:

[Uren]
PerWeek=24    //Hours per week
Vakantie=0    //Vacation hours
Extra=0       //Extra days

Gebruikers.ini:

[Mark Wingens]
Afdeling=Optics

ID.ini:

[ID]
1=

Ziekmelding.ini:

[ID]
15=15
[VAN]
15=2019/03/11
[TM]
15=2019/03/11
[AANTAL]
15=1
[UREN]
15=8
[REDEN]
15=Ziek melding
[OPMERKING]
15=test ziekmelding
[Accoderen]
15=Ja

Code:

$ZiekmeldingAanvr = GUICreate("Ziek melding", 437, 193, -1, -1, $WS_POPUPWINDOW)
    GUICtrlCreateLabel("Ziek melding", 296, 40, 133, 34)
    GUICtrlSetFont(-1, 16, 800, 0, "Segoe UI")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlCreateLabel("Van", 16, 42, 23, 17)
    $VanDatum = GUICtrlCreateDate("", 88, 40, 186, 21)
    GUICtrlCreateLabel("Tot en met", 16, 74, 55, 17)
    $TMDatum = GUICtrlCreateDate("", 88, 72, 186, 21)
    GUICtrlCreateLabel("Aantal uren", 16, 106, 67, 17)
    $AantalDagen = GUICtrlCreateInput("", 88, 104, 186, 21)
    GUICtrlCreateLabel("Opmerking", 16, 138, 55, 17)
    $Opmerking = GUICtrlCreateInput("", 88, 136, 334, 21)

    GUICtrlCreateLabel("Medewerker", 16, 10, 63, 17)
    $Gebruikers = GUICtrlCreateCombo("", 88, 8, 186, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))

    $Opslaan = GUICtrlCreateButton("Opslaan", 259, 160, 75, 25)
    $Sluiten = GUICtrlCreateButton("Annuleren", 347, 160, 75, 25)

    Local $sStyle = "yyyy/MM/dd"
    GUICtrlSendMsg($VanDatum, $DTM_SETFORMATW, 0, $sStyle)
    GUICtrlSendMsg($TMDatum, $DTM_SETFORMATW, 0, $sStyle)

    GUICtrlSetState($VanDatum, $GUI_DISABLE)
    GUICtrlSetState($TMDatum, $GUI_DISABLE)
    GUICtrlSetState($AantalDagen, $GUI_DISABLE)
    GUICtrlSetState($Opmerking, $GUI_DISABLE)
    GUICtrlSetState($Opslaan, $GUI_DISABLE)
    GUISetState(@SW_SHOW)

    ; Get the sections of the ini file
    Global $aSections = IniReadSectionNames(@ScriptDir & "\DB\gebruikers.ini")
    ; If the IniReadSectionNames succeeded, convert the array to a string with each item separated by a | (pipe) and set the default selected item to $aSections[1]
    If (Not @error) Then GUICtrlSetData($Gebruikers, _ArrayToString($aSections, "|", 1), $aSections[1])

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Sluiten
                GUIDelete($ZiekmeldingAanvr)
                Hoofdmenu()
                ExitLoop
            Case $Gebruikers
                $GO = 1
                If GUICtrlRead($Gebruikers) = "Kies een medewerker..." Then
                    MsgBox(4096, "Let op!", "Kies een medewerker.")
                    $GO = 0
                EndIf
                If $GO = 1 Then
                    GUICtrlSetState($VanDatum, $GUI_ENABLE)
                    GUICtrlSetState($TMDatum, $GUI_ENABLE)
                    GUICtrlSetState($AantalDagen, $GUI_ENABLE)
                    GUICtrlSetState($Opmerking, $GUI_ENABLE)
                    GUICtrlSetState($Opslaan, $GUI_ENABLE)
                    $Start_Date = GUICtrlRead($VanDatum)
                    $End_Date = GUICtrlRead($TMDatum)
                    Local $DT = $Start_Date, $iCount = 0, $Y, $M, $D
                    While $DT <= $End_Date
                        $Y = StringRegExpReplace($DT, "(\d+)/.*", "$1")
                        $M = StringRegExpReplace($DT, ".*/(\d+)/.*", "$1")
                        $D = StringRegExpReplace($DT, ".*/(\d+)", "$1")
                        If _DateToDayOfWeek($Y, $M, $D) <> 1 And _DateToDayOfWeek($Y, $M, $D) <> 7 Then
                            $iCount += 1
                        EndIf
                        $DT = _DateAdd("D", 1, $DT)
                    WEnd
                    $Aantalurenverlof = $iCount * 8
                    GUICtrlSetData($AantalDagen, $Aantalurenverlof)
                EndIf
            Case $VanDatum
                $Start_Date = GUICtrlRead($VanDatum)
                $End_Date = GUICtrlRead($TMDatum)
                Local $DT = $Start_Date, $iCount = 0, $Y, $M, $D
                While $DT <= $End_Date
                    $Y = StringRegExpReplace($DT, "(\d+)/.*", "$1")
                    $M = StringRegExpReplace($DT, ".*/(\d+)/.*", "$1")
                    $D = StringRegExpReplace($DT, ".*/(\d+)", "$1")
                    If _DateToDayOfWeek($Y, $M, $D) <> 1 And _DateToDayOfWeek($Y, $M, $D) <> 7 Then
                        $iCount += 1
                    EndIf
                    $DT = _DateAdd("D", 1, $DT)
                WEnd
                $Aantalurenverlof = $iCount * 8
                GUICtrlSetData($AantalDagen, $Aantalurenverlof)
            Case $TMDatum
                $Start_Date = GUICtrlRead($VanDatum)
                $End_Date = GUICtrlRead($TMDatum)
                Local $DT = $Start_Date, $iCount = 0, $Y, $M, $D
                While $DT <= $End_Date
                    $Y = StringRegExpReplace($DT, "(\d+)/.*", "$1")
                    $M = StringRegExpReplace($DT, ".*/(\d+)/.*", "$1")
                    $D = StringRegExpReplace($DT, ".*/(\d+)", "$1")
                    If _DateToDayOfWeek($Y, $M, $D) <> 1 And _DateToDayOfWeek($Y, $M, $D) <> 7 Then
                        $iCount += 1
                    EndIf
                    $DT = _DateAdd("D", 1, $DT)
                WEnd
                $Aantalurenverlof = $iCount * 8
                GUICtrlSetData($AantalDagen, $Aantalurenverlof)
            Case $Opslaan
                $GO = 1
                $VAR = _DateDiff('D', GUICtrlRead($VanDatum), GUICtrlRead($TMDatum))
                If $VAR < 0 Then
                    MsgBox(4096, "Let op!", "Controleerde ingevoerde data." & @CRLF & @CRLF & "Van datum:" & @TAB & GUICtrlRead($VanDatum) & @CRLF & "Tot en met datum:" & @TAB & GUICtrlRead($TMDatum))
                    $GO = 0
                EndIf
                If $GO = 1 Then
                    Local $AfdelingTemp = IniRead(@ScriptDir & "\DB\Gebruikers.ini", GUICtrlRead($Gebruikers), "Afdeling", "")
                    GUICtrlSetState($VanDatum, $GUI_DISABLE)
                    GUICtrlSetState($TMDatum, $GUI_DISABLE)
                    GUICtrlSetState($AantalDagen, $GUI_DISABLE)
                    GUICtrlSetState($Opmerking, $GUI_DISABLE)
                    GUICtrlSetState($Opslaan, $GUI_DISABLE)
                    GUICtrlSetState($Sluiten, $GUI_DISABLE)
                    $VAR = GUICtrlRead($VanDatum)
                    $YEAR = StringLeft($VAR, 4)
                    $aArray = IniReadSection(@ScriptDir & "\DB\Gebruikers\" & $AfdelingTemp & "\" & GUICtrlRead($Gebruikers) & "\Jaren\" & $YEAR & "\ID.ini", "ID")
                    $count = UBound($aArray, 1)
                    $VAR = $count + 1
                    $Dagen = GUICtrlRead($AantalDagen) / 8
                    $Dagen = Round($Dagen, 3)
                    $Replace = StringRegExpReplace(GUICtrlRead($AantalDagen), ",", ".")
                    IniWrite(@ScriptDir & "\DB\Gebruikers\" & $AfdelingTemp & "\" & GUICtrlRead($Gebruikers) & "\Jaren\" & $YEAR & "\ID.ini", "ID", $VAR, "")
                    IniWrite(@ScriptDir & "\DB\Gebruikers\" & $AfdelingTemp & "\" & GUICtrlRead($Gebruikers) & "\Jaren\" & $YEAR & "\ziekmelding.ini", "ID", $VAR, $VAR)
                    IniWrite(@ScriptDir & "\DB\Gebruikers\" & $AfdelingTemp & "\" & GUICtrlRead($Gebruikers) & "\Jaren\" & $YEAR & "\ziekmelding.ini", "VAN", $VAR, GUICtrlRead($VanDatum))
                    IniWrite(@ScriptDir & "\DB\Gebruikers\" & $AfdelingTemp & "\" & GUICtrlRead($Gebruikers) & "\Jaren\" & $YEAR & "\ziekmelding.ini", "TM", $VAR, GUICtrlRead($TMDatum))
                    IniWrite(@ScriptDir & "\DB\Gebruikers\" & $AfdelingTemp & "\" & GUICtrlRead($Gebruikers) & "\Jaren\" & $YEAR & "\ziekmelding.ini", "AANTAL", $VAR, $Dagen)
                    IniWrite(@ScriptDir & "\DB\Gebruikers\" & $AfdelingTemp & "\" & GUICtrlRead($Gebruikers) & "\Jaren\" & $YEAR & "\ziekmelding.ini", "UREN", $VAR, $Replace)
                    IniWrite(@ScriptDir & "\DB\Gebruikers\" & $AfdelingTemp & "\" & GUICtrlRead($Gebruikers) & "\Jaren\" & $YEAR & "\ziekmelding.ini", "REDEN", $VAR, "Ziek melding")
                    IniWrite(@ScriptDir & "\DB\Gebruikers\" & $AfdelingTemp & "\" & GUICtrlRead($Gebruikers) & "\Jaren\" & $YEAR & "\ziekmelding.ini", "OPMERKING", $VAR, GUICtrlRead($Opmerking))
                    IniWrite(@ScriptDir & "\DB\Gebruikers\" & $AfdelingTemp & "\" & GUICtrlRead($Gebruikers) & "\Jaren\" & $YEAR & "\ziekmelding.ini", "Accoderen", $VAR, "Ja")

                    Global $ZiekMedewerker = GUICtrlRead($Gebruikers)
                    Global $ZiekEmail = IniRead(@ScriptDir & "\DB\gebruikers.ini", $ZiekMedewerker, "Email", "")
                    Global $ZiekVan = GUICtrlRead($VanDatum)
                    Global $ZiekTM = GUICtrlRead($TMDatum)
                    Ziekmeldingmail()

                    Sleep(250)
                    MsgBox(4096, "Opgeslagen", "De ziek melding is opgeslagen.")
                    Sleep(100)
                    GUIDelete($ZiekmeldingAanvr)
                    ZiekmeldingAanvr()
                    ExitLoop
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>ZiekmeldingAanvr

 

Posted

Wingens,

You only excluded out the #includes from your example so I wont test to confirm.., to Try work it out based as:  $iCount * 8 - 8

Deye

Posted

Sorry forgot to put the includes in them.

It's part of a larger script, so here are all the includes from the total script:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <file.au3>
#include <array.au3>
#include <GuiListView.au3>
#include <Misc.au3>
#include <smtpauth.au3>
#include <Inet.au3>
#include <DateTimeConstants.au3>
#include <Date.au3>
#include <GuiListView.au3>
#include <ColorConstants.au3>

 

Posted (edited)

@FrancescoDiMuro

Ok i will try,

 

What i am trying to create is a way to register when people take a day of or get sick or take vacation and how much of the hours the have it would take.

I got it working for the people who are working full-time (5 days a week and 8 hours a day) but we have several people who work less then 5 days a week and now when we select a periode of 5+ days we need it to read the hours a week and calculate how many days of vacation they take.

Edited by Wingens
Posted

@Wingens
Ok, thank you :)
These tasks seems to be easily done with an SQL Table, for example, but, since you are using .ini files, you could do something like this:

[Username]
WorkHours=8
WorkDays=3
VacationHours=X
TotalMonthHours=Y

Having an .ini with this type of "structure", could help you extracting some information :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...