Jump to content

Script to calculate workers time and charge


DougR
 Share

Recommended Posts

Hey guys, I am totally new to AutoIT but I know its is amazingly powerful. If such a script like this exists, I would love to find it!

Basically, technicians arrive on site and write down the time. They fix the customers problem and write the time they leave down.

We charge $99 for the first hour, then $25 for every 15 minutes. If we are on site for only 10 minutes, the customer is still charged $99 as a minimum fee.

My problem is, workers are mis charging and not making the right calculations.

I would like a simple script where the worker could input the time he arrived, and the time he left. It would then tell him the number of hours and minutes worked (rounded up to the nearest 15 minute mark), and tell him what to charge the customer.

Can anyone be of assistance with this? Thanks!

Edited by DougR
Link to comment
Share on other sites

VB? Java? C#?

There are lots more alternatives that can give you better GUIs than AutoIt.

Are you out of your mind? How do they have much better GUIs? (Search for a program called neoSearch and yes it's made in Autoit)

They all have IDE but Autoit still have the Koda thing which is pretty much the same.

And you expect him to pick up Java C#? even they are high level but there are still lots of things going on.

VB? You mean VB.NET :D (You can't compare VB to C# nor Java. You know why!)

Wait... Wait. WTF does a language get to do with this?? It's about WinForms or WPF or what every the linux side use.

Edited by WolfWorld
Link to comment
Share on other sites

Well, I'm just saying that using another language may be beneficial since they support date/time objects and you have more control over a GUI layout. If you can find the rights objects to use, it would save you time checking for valid inputs, and processing data as well.

Link to comment
Share on other sites

Well, I'm just saying that using another language may be beneficial since they support date/time objects and you have more control over a GUI layout. If you can find the rights objects to use, it would save you time checking for valid inputs, and processing data as well.

Well, what he ask for is just a basic function. There is no need to use DateTime and TimeSpan at all.

:D And he is asking us to program for him so he can use it for his job for $99 at minimum per job :D

Link to comment
Share on other sites

@Omikron

A simple insight here, my friend.. This guy has come here, on the autoit forum to ask for help.. He's already chosen his tool.. As my very good friend M23 said once, there is more that 1 way to skin a goat, and this guy has already chosen his way. So what's the point in telling him to change his tool.. Lets just help him, shall we?

@OP..

What you need is pretty straightforward.. Start off by looking into how to capture user input using inputbox()..

Then conver it into mins and subtract the two. If you don't want to rely on user input, and take the time off the system clock, check into @min and @hour macros. Rest is simple maths.

Also to design a GUI for this will be the next step, once your time calculation function is ready. Check KODA form designer for this!

Post your code here and we all will gladly help you solve ur problems

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

Yes. He has chosen his tool. I'm just trying to present the idea that there may be other better tools to use. Although AutoIt is very handy, it is not the solution for everything. You can't keep hitting everything with a hammer.

Same reason you use libraries, so you don't have to code everything from scratch...

Here's some help with the calculation. Note that it's untested because I'm lazy. Hopefully my math is good.

Opt("MustDeclareVars", 1)

;Accepts military time format, e.g. 0000, 0600, 1030
;Charges 99 for the first hour, 25 per succeeding 15 minutes
Func _GetCharge($start, $end)
    If _IsValidTime($start) And _IsValidTime($end) Then
        Local $startH = Int(StringLeft($start, 2)), $startM = Int(StringRight($start, 2))
        Local $endH = Int(StringLeft($end, 2)), $endM = Int(StringRight($end, 2))
        Local $minutes = _GetTimeDiffUtil($startH, $startM, $endH, $endM)
        ;Charges 99 for the first hour, 25 per succeeding 15 minutes
        If $minutes < 60 Then
            Return 99
        Else
            Return 99 + 25 * Ceiling(Mod($minutes - 60, 15))
        EndIf
    EndIf
    SetError(1, 0, -1)
EndFunc

;Returns time difference in minutes. Only supports maximum of 23 hrs 59 mins time span.
Func _GetTimeDiffUtil($sHour, $sMin, $eHour, $eMin)
    ;Start time and end time occurs within the same hour
    If $sHour == $eMin Then
        If $eMin > $sMin Then
            ;Time span is within the same hour
            Return $eMin - $sMin
        Else
            ;Time span is near 24 hours
            Return 3600 - $sMin + $eMin
        EndIf
    EndIf
    ;Start time and end time occur within the same day
    If $sHour < $eHour Then
        Return (60 * ($eHour - $sHour - 1)) + (60 - $sMin + $eMin)
    EndIf
    ;Start time is before midnight and end time is after midnight
    Return _GetTimeDiffUtil($sHour, $sMin, 24, 0) + _GetTimeDiffUtil(0, 0, $eHour, $eMin)
EndFunc

;Returns true if time is between 0000 and 2359, inclusive
Func _IsValidTime($time)
    Local $timeH = Int(StringLeft($time, 2)), $timeM = Int(StringRight($time, 2))
    Return $timeH >= 0 And $timeH <= 23 And $timeM >= 0 And $timeM <= 59
EndFunc
Edited by omikron48
Link to comment
Share on other sites

Hi, I hope this helps. : )

_CalculateCost(10) ; should return 99 ( below 60 test )
_CalculateCost(60) ; should return 99 ( on 60 test )
_CalculateCost(65) ; should return 99 ( over 60 test )

_CalculateCost(70) ; rounded to 75, should return 125
_CalculateCost(75) ; should return 124
_CalculateCost(80) ; should return 124

_CalculateCost(85) ; should return 149
_CalculateCost(90) ; should return 149

_CalculateCost(105) ; should return 174

Func _CalculateCost($t) ; $t is the time in minutes spent.
    Dim $Cost = 99 ; there is a base cost of 99
    
    ; this gets the amount of quarters of time spent, after the first 60 minutes
    $q = $t - 60;
    if ($q < 0) Then $q = 0
    $q = Round($q / 15) 
    
    ; each quarter costs 25 dollar
    $Cost += $q * 25

    ; write the cost for debugging
    ConsoleWrite("t = " & $t & @CRLF & "q = " & $q & @CRLF & "Cost = " & $cost & @CRLF)
    
    ; return the cost
    Return $Cost
EndFunc
Link to comment
Share on other sites

Thanks for the replies!

Both of these don't seem to work? When I compile them, they just open then immediately close without asking for the times or anything.

Manadars code works, but you see he's used the ConsoleWrite function. Look at the MsgBox function and it will popup with a nice little message.
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...