• Resolved pwatson92

    (@pwatson92)


    I am trying to build a simple overtime payment calculator, but I can’t get my equations to work.

    Basically I’m trying to set it so IF Hours Worked (fieldname2) > 40, the Hours Worked – 40 are overtime hours, and are multiplied by Hourly Pay (fieldname1)*1.5. But I can’t get the function to subtract 40 from fieldname2, then take those hours and multiply it by fieldname1*1.5.

    Here are the formulas I’m currently using, which I’m sure are formatted improperly (I don’t have much experience with Javascript):

    OVERTIME HOURS WORKED
    (function(){
    (fieldname2)-40
    })();

    OVERTIME PAY OWED
    (function(){
    IF(fieldname3 > 0) return (fieldname1*fieldname2*1.5)
    })();

    With fieldname3 being Overtime Hours Worked.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @pwatson92

    Javascript is a case-sensitive language, the uppercase, and lowercase matter. The IF operation is not the if conditional statement.

    The payment can be calculated with only one field. For example, assuming the fieldname1 is the currency field with the cost per hour, and fieldname2 is the number field for working hours.

    The payment can be implemented as follows:

    MIN(fieldname2,40)*fieldname1+MAX(0,fieldname1-40)*fieldname1*1.5

    But if you want to implement the process with multiple fields as you did, the equations would be:

    For overtime hours: fieldname2-40

    For overtime payment: IF(0<fieldname3, fieldname1*fieldname3*1.5, 0)

    You don’t need the function structure in any of these cases.

    I prefer my first alternative because it reduces the number of fields.

    Best regards.

    Thread Starter pwatson92

    (@pwatson92)

    Your equation wasn’t quite working right, so I simplified it to

    (fieldname2-40)*fieldname1*1.5 and I got the right result.

    • This reply was modified 4 years, 4 months ago by pwatson92.
    • This reply was modified 4 years, 4 months ago by pwatson92.
    Plugin Author codepeople

    (@codepeople)

    Hello @pwatson92

    Yes, I’m sorry. I’ve a typo in my equation, the correct is:

    MIN(fieldname2,40)*fieldname1+MAX(0,fieldname2-40)*fieldname1*1.5

    The first component in the sum MIN(fieldname2,40)*fieldname1 calculates the salary of the first 40 hours at the common hour-cost.

    The second component in the sum determines the remaining hours MAX(0,fieldname2-40) (if the person worked less than 40 hours, the previous code returns zero) and multiply them by hour-cost increased 1.5 times: MAX(0,fieldname2-40)*fieldname1*1.5

    So, the equation MIN(fieldname2,40)*fieldname1+MAX(0,fieldname2-40)*fieldname1*1.5 calculates the final salary.

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Overtime payment calculator’ is closed to new replies.