5 Replies Latest reply on Dec 23, 2014 4:34 AM by ashleyfoozi

    Time -  less than or equal to formula.

    ashleyfoozi

      I have an overtime sheet that calculates the difference between the time in and the time out on each line and puts the result in a text box called "TIMERow1_0"

      In another text box ("TRow1_0") on the same row I want to put the time to be paid. If the time is <= 4:00 then "TRow1_0" must show 4:00 and if greater than 4:00 it must show the actual time worked.

       

      In South Africa if you work on a Sunday or Public Holiday you will be paid a minimum of 4 hours at double your hourly rate. So if you are called out in an emergency repair and it takes you 2 hours then you will be paid 4 hours. If you work more than 4 hours you will be paid at the actual time worked multiplied double your hourly ate.

       

      In the screenshot below

      "TIME ACTUAL" = "TIMERow1_0"

      "TIME" = "TRow1_0"

      The button does the time diff calculation and puts the result in "TIMERow1_0"

        • 1. Re: Time -  less than or equal to formula.
          try67 MVP & Adobe Community Professional

          I'm assuming you're using a script to calculate the "actual time" field's

          value. In the same script you can also assign the value of the "time"

          field. If the hours digits is 4 or more, assign the actual value. If it's

          less (but more than zero, presumably), assign "4:00".

           

          On Thu, Dec 18, 2014 at 9:12 AM, ashleyfoozi <forums_noreply@adobe.com>

          • 2. Re: Time -  less than or equal to formula.
            gkaiseril MVP & Adobe Community Professional

            A lot would depend upon how you are calculating the time variables and how one is storing the value in the time worked. For PDF forms the formatted display can be very different from stored value of a field.

             

            One can use the Math.max method to compare 2 or more values and return the maximum value of the items.

             

            If you are forcing the value to the time string

             

            // compute the time worked as a minimum of 4 or the actual time if more than 4 hours;

            if(this.getField( "TIMERow1_0").value != "")

            event.value = Math.max(this.getField( "TIMERow1_0").value, "4:00");

             


            • 3. Re: Time -  less than or equal to formula.
              ashleyfoozi Level 1

              Thank you for the replies, they pointed me in the right direction.

              However my code is only able to calculate correctly if the time in column "Time Actual" is a whole hour.

              The grey block in each row calculates the time difference between "Time In" and "Time Out"

              "Paid Time" is what I am battling with because if a person works 4 hours or less they will get paid 4 hours and anything over 4 hours is paid at actual time.

              The problem is in the "if" statement. I know that the variation should be converting the time to minutes where I can then say <= 240 minutes.

              Where am I going wrong.

               

              Capture.JPG

               

              var hrsTime = parseInt(this.getField("TIMERow.0.0").value.split(":")[0]);

              var minTime = parseInt(this.getField("TIMERow.0.0").value.split(":")[1]);

               

              if (hrsTime + minTime <= 4) {

              var minRez = 00;

              var hrsRez = 4;

              }

              else {

              var minRez = minTime;

              var hrsRez = hrsTime;

              }

              this.getField("TRow.0.0").value = hrsRez + ":" + minRez;

              • 4. Re: Time -  less than or equal to formula.
                gkaiseril MVP & Adobe Community Professional

                A minute is 1/60 of an hour. So if you want the hours and minutes expressed as hour, you need to add the minutes times 1/60 to the hours so the total value is in hours. Because of issues with decimals in floating point notaion, I would convert the hours to minutes.

                 

                var hrsTime = parseInt(this.getField("TIMERow.0.0").value.split(":")[0]);
                var minTime = parseInt(this.getField("TIMERow.0.0").value.split(":")[1]);

                var minRez = minTime;
                var hrsRez = hrsTime;

                var TotalMin = (hrsTime * 60) + Number(minTime);

                var TotalMin = Math.max((hrsTime * 60) + Number(minTime) , 240);
                hrsRez = Math.floor(TotalMin / 60); // whole hours;

                minRez = TotalMin % 60; // remainder in minutes;

                this.field("TRow.0.0").value = hrsRez + ":" + minRez;

                 

                You are still going to have to workout your formatting.

                 

                Since you will be converting the time string form the string of hourw:minutes I would look at a function to perform this task. I would also look at setting the computed field values to the decimal hours and then create a document level function for the display format of the value. This function is then called for the custom format using the event value as a parameter.

                 

                // document level functions;

                function Time2Num(sTime) {
                // convert time string of HH:MM to minutes;
                var aTime = sTime.split(":");
                var nHours = aTime[0]; // number of hours;
                var nMinutes = Number(aTime[1]); // number of minutes;
                // return time as minutes;
                return (nHours * 60) + nMinutes;
                }

                function Num2Time(nMinutes) {
                // get whole hours from minutes
                var nHrs = Math.floor(nMinutes / 60);
                // get remainder of minutes when divided by 60;
                var nMins = nMinutes % 60;
                // return formatted time string;
                return util.printf("%,1 1.0f", nHrs) + ":" + util.printf("%,102.0f", nMins);
                }

                // end document level functions;

                 

                // custom calculation  for TRow.0.0;

                var sTime = this.getField("TIMERow.0.0").value; // input field value;

                var nTime = Math.max(Time2Num(sTime), 240); // convert to minutes;

                event.value = Num2Time(nTime); // formatted result;

                // end custom calculation script;

                • 5. Re: Time -  less than or equal to formula.
                  ashleyfoozi Level 1

                  You are a GENIUS!!!

                  Thank you.

                   

                  All I had to do was adapt it to an "if else" and now the code works for odd time differences like 03:56.

                  As I said earlier we have to pay overtime if a person works 4 hours or less on a Sunday and then actual time worked for more than 4 hours.

                  We were using photocopied excel spreadsheets and the amount of errors there were each month was horrendous. Ever see people trying to calculate time on a calculator.

                  Now with my fillable PDF the poor pay clerk will have a much easier time.

                   

                  Thank you again