Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Time Sheet in PDF
  FAQ FAQ  Forum Search   Register Register  Login Login

Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Time Sheet in PDF

 Post Reply Post Reply Page  12>
Author
sammer View Drop Down
New Member
New Member


Joined: 04 Jun 2012
Points: 3
Post Options Post Options   Quote sammer Quote  Post ReplyReply Direct Link To This Post Topic: Time Sheet in PDF
    Posted: 04 Jun 2012 at 7:04pm
I tried looked at some of the similar posts related to this topic and made my own but it's not working. I don't see what I did incorrectly. Please help!



Edited by sammer - 04 Jun 2012 at 7:05pm
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4109
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 04 Jun 2012 at 11:52pm
There should be a document level function called "TimeDiff" that computes the difference in the time fields. There is also a docuemnt level function, "Time2Num" that converts the character string of "HH:MM" to the number of minutes.
 
Document level funcitons are used to avoid repeating the exact code in multiple times. One has one funciton that performs a task and if that task is needs to be updated there is only one place to update the code.
 
function Time2Num(cTime){
// convert time string h:MM tt or HH:MM to minutes
var min = 0
if ( /(\d{0,2})[:](\d{2})[ ]?([ap])/i.test(cTime) ) {
   // civilian time
   if(RegExp.$1 != 12)
      min = 60 * RegExp.$1; // hour not 12
   min += Number(RegExp.$2);
   if (RegExp.$3 == "p")
      min += 12 * 60;  // adjust for time after 11:59.999 am
   }
else if (/(\d{0,2})[:](\d{2})/.test(cTime)) {
        // military time
        min = 60 * Number(RegExp.$1);
        min += Number(RegExp.$2);
        }
return min;
} // end funciton Time2Num

event.value = '';
var fDiff = 0;
// compute the difference for first pair of fields
// get the start time
var sStart = this.getField('Field5').value;
// get the end time
var sEnd = this.getField('Field6').value;
// complete script only if we have data
if(sStart != '' && sEnd != '') {
// convert sStart string to seconds
var fStart = Time2Num(sStart);
// convert sEnd string to seconds
var fEnd = Time2Num(sEnd);
// compute difference in seconds
fDiff += fEnd - fStart;
console.println("In: " + sStart + " minutes: " + fStart);
console.println("Out: " + sEnd + " minutes; " + fEnd);
console.println("Difference: " + (fEnd - fStart));
}
// compute and add the difference for the second pair of fields
// get the start time
var sStart = this.getField('Field8').value;
// get the end time
var sEnd = this.getField('Field9').value;
// complete script only if we have data
if(sStart != '' && sEnd != '') {
// convert sStart string to seconds
var fStart = Time2Num(sStart);
// convert sEnd string to seconds
var fEnd = Time2Num(sEnd);
// compute difference in seconds
fDiff += fEnd - fStart;
console.println("In: " + sStart + " minutes: " + fStart);
console.println("Out: " + sEnd + " minutes; " + fEnd);
console.println("Difference: " + (fEnd - fStart));
}
// convert to rounded minutes if not zero
if (fDiff != 0) {
fDiff = Math.round(fDiff / 60);
// report decimal hours
event.value = fDiff / 60;
}
 
Back to Top
sammer View Drop Down
New Member
New Member


Joined: 04 Jun 2012
Points: 3
Post Options Post Options   Quote sammer Quote  Post ReplyReply Direct Link To This Post Posted: 05 Jun 2012 at 3:30pm
Hey thanks a lot for your help. I inputted TimeIn - 8:30, TimeOut 12:00 and the 2nd TimeIn 13:00, TimeOut 16:30 but the TotalHrsWorked shows me 0.111167 or simply just 0.12. It should should show 7.
Back to Top
sammer View Drop Down
New Member
New Member


Joined: 04 Jun 2012
Points: 3
Post Options Post Options   Quote sammer Quote  Post ReplyReply Direct Link To This Post Posted: 05 Jun 2012 at 7:16pm
It works now! Thank youuuuu!
Back to Top
gq1969 View Drop Down
New Member
New Member
Avatar

Joined: 13 Jun 2012
Location: louisiana
Points: 7
Post Options Post Options   Quote gq1969 Quote  Post ReplyReply Direct Link To This Post Posted: 13 Jun 2012 at 2:33pm
does one have to use calculation script in each pdf box
and if so what would they be?

clock in        lunch out      lunch in         clock out            total



Edited by gq1969 - 13 Jun 2012 at 2:37pm
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4109
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 13 Jun 2012 at 3:52pm
The "Time2Num" function above should let you convert individual time entry fields to minutes, you then only need to add and subtract the minutes as needed to get and sum the difference.
Back to Top
gq1969 View Drop Down
New Member
New Member
Avatar

Joined: 13 Jun 2012
Location: louisiana
Points: 7
Post Options Post Options   Quote gq1969 Quote  Post ReplyReply Direct Link To This Post Posted: 14 Jun 2012 at 5:30am
but im using clock in 8:00 am  clock out 5:00pm
script  not working for this time pattern i guess
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4109
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 14 Jun 2012 at 6:50pm
They are functions and you need to call them with the necessary parameters.
 
 
Back to Top
gq1969 View Drop Down
New Member
New Member
Avatar

Joined: 13 Jun 2012
Location: louisiana
Points: 7
Post Options Post Options   Quote gq1969 Quote  Post ReplyReply Direct Link To This Post Posted: 15 Jun 2012 at 4:44pm
That is nice, works like a charm the one you posted but why does it have to be in 15min increments  is there way to set it in 5min increments my time is per 5mins


Edited by gq1969 - 15 Jun 2012 at 5:07pm
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4109
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 15 Jun 2012 at 6:14pm
It has 15 minutes because that was a requirement of the reporting entity.
Back to Top
gq1969 View Drop Down
New Member
New Member
Avatar

Joined: 13 Jun 2012
Location: louisiana
Points: 7
Post Options Post Options   Quote gq1969 Quote  Post ReplyReply Direct Link To This Post Posted: 16 Jun 2012 at 1:22am
function GetLastLevel() {
var sField = event.targetName; // get field's name
var aField = sField.split("."); // make into an array split on "." value
return aField[aField.length -1] // get last item in array
} //end GetLastLevel

function SetDefaultFieldNames(aFieldNames) {
// use the current value for the default value
for (i in aFieldNames) {
this.getField(aFieldNames).defaultValue = this.getField(aFieldNames).value;
}
return;
} // end SetDefalutFieldNames

function FormatMinutes(TotalMinWorked) {
// compute time worked as hours and decimal of an hour
return TotalMinWorked == 0? "" :  util.printf("%,03.2f", TotalMinWorked/60);

/*
// compute time worked as hours:minutes
var MinWorked = TotalMinWorked % 60; // Minutes worked less than 1 hour (Modulos 60)
var HrsWorked = Math.floor((TotalMinWorked - MinWorked) / 60); // Hours worked integer of minutes / 60
return TotalMinWorked == 0? '' : HrsWorked + util.printf(":%,302.0f", MinWorked); // format output
*/
} // end FormatMinutes

function SetDays(sFieldName) {
var oDate = util.scand("mm/dd/yyyy", event.value);
var sYear = oDate.getFullYear();
var sMonth = oDate.getMonth();
var sDate = oDate.getDate();
var sValue;
var aField = this.getField(sFieldName).getArray();
for(i = 0; i < aField.length; i++) {
sValue = new Date(sYear, sMonth, (sDate - aField.length) + i +1);
aField.value = util.printd('mm/dd/yyyy', sValue);
}
return;
} // end SetDays

function DayMinutes(iDay) {
/* compute minutes worked in a day from passed day index value */
var oIn;  // in period date time object for computing time difference
var oOut; // out period date time object for computing time difference
var minWorked = 0 // minutes worked for given day
var day = "01/01/2000"; // force date string for computation
// get day and in & out values for day
var In = this.getField("In."+iDay).value;
var Out = this.getField("Out."+iDay).value;
if (In != "" & Out !="") { // do we have an "in" and "out" pair
    oIn  = util.scand("mm/dd/yy h:MM tt", day + " " + In);
    oOut = util.scand("mm/dd/yy h:MM tt", day + " " + Out);
    minWorked += TimeDiff(oIn, oOut); // add worked time
}
// get day and in & out values for lunch
var In = this.getField("LOut."+iDay).value;
var Out = this.getField("LRtn."+iDay).value;
if (In != "" & Out !="" & this.getField("Out."+iDay).value != "") {
    oIn  = util.scand("mm/dd/yy h:MM tt", day + " " + In);
    oOut = util.scand("mm/dd/yy h:MM tt", day + " " + Out);
    minWorked -= TimeDiff(oIn, oOut); // subtract lunch
}
return minWorked; // for day
} // end DayMinutes

function TimeDiff(oStart, oEnd) {
    var Stop  = oEnd.valueOf(); // value of end date time object in minutes
    var Begin = oStart.valueOf(); // value of start date time object in minutes
     if (Begin > Stop) { // check for end time before start time
         app.alert("End time before start time of "+ util.printd("mm/dd/yy h:MM tt", oStart), 0, 0);
         return 0; // do not count this time
    }
    var Diff = Math.floor((Stop - Begin)/1000/60); // difference in milliseconds
    return Diff;
} // end TimeDiff

function GrandTotal() {

// compute total hours worked for reporting period ("Total1")
var aDayWorked = this.getField("sDate").getArray(); // day worked field group and make array
var DayMinWroked = 0; // minutes worked for day i
var TotalMinWorked = 0; // total minutes worked

// compute total minutes worked from minutes worked each day of days in aDayWorked  array
for (i = 0; i < aDayWorked.length; i++) {
    // clear Regular Comp and Over Minutes for day
    dRegMinutes = 0;
    DayMinWorked = DayMinutes(i); // compute minutes for day i
    dRegMinutes =  DayMinWorked;
    // update accumulated totals for day i
    TotalMinWorked = TotalMinWorked + DayMinWorked; // total period minutes worked
    // total hours for day i
    this.getField("hDay." + i).value = FormatMinutes(DayMinWorked);
    
} // end for DayWorked

// fill in total hours worked
event.value = FormatMinutes(TotalMinWorked);
// fill fields for period regular hours, comp hours and over time hours

return FormatMinutes(TotalMinWorked);
} // end GrandTotal function

what can i edit to get times to fall out as
8:00am to 10:40am = 2.40 total


Edited by gq1969 - 16 Jun 2012 at 1:22am
Back to Top
 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.047 seconds.