Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with timecard code

Status
Not open for further replies.

gmagerr

Technical User
Aug 11, 2001
323
US
Hi all, i'm trying to create a timecard app for my intranet site. i want employees to be able to send in there time for that day and keep a tally of the time for the week as well. What is the best way to do this? are there any code examples out there (i couldn't find any) thanks.pm
 
Use a db,


make 8 tables:

eID (employee id number)
eEmail (employee email)
ePassword (employee password)
day1
day2
day3
day4
day5
--------------------------------
Then make a login.asp page

with to text boxes (form)
txtemail
txtpassword

-------------------------------
Then make verify.asp

'# put your to form values in a string
strEmail = Request.Form("txtemail")
strPass= Request.Form("txtpassword")

then do a select statement

your sql statment would be something like:

'# other db connection stuff here (which is found ont he page above

SELECT * from employees WHERE eEmail='" & strEmail & "'"

'# Excute line here

If strPass <> rs(&quot;eEmail&quot;) then
Response.redirect &quot;login.asp&quot;
else
session(&quot;loggedin&quot;) = true
Response.Redirect &quot;employee.asp&quot;
End if

-----------------------------

Then on your employee.asp page
put at top:

If session(&quot;loggedin&quot;) <> true then
Response.Redirect &quot;login.asp&quot;
Response.End
End if

And then put 5 text boxes, one for each day and then do an insert statement...

hope that helps










www.vzio.com
ASP WEB DEVELOPMENT
 
you can then make an xtra table for adding up all the time etc.. and displaying that as well..

if you have any further questions post them.
www.vzio.com
ASP WEB DEVELOPMENT



 
Thanks snowboardr I will use the database, that actually isn't a problem. the problem is how do i get the hours to calculate. for instance if someone clocks in at 9am and clocks out at 5pm or clocks in at 1pm and clocks out at 7pm how do i do those calculations? and then add all the hours up for the week? thanks.
 
Something like this?
<%

Dim strTime1, strTime2, strTotalHours

strTime1 = &quot;2:00 AM&quot;
strTime2 = &quot;9:00 PM&quot;


strTotalHours = DateDiff(&quot;h&quot;, strTime1, strTime2)

Response.Write strTotalHours


%> www.vzio.com
ASP WEB DEVELOPMENT



 
Thanks again snowboardr, I've created a form for the employees to input their time (i'm going to hardcode the times in a dropdown list ex. 6:00AM, 7:00AM etc etc so there are no mistakes with the employees inputting the time)
Please take a look at the code for the time calc page, and let me know if you can forsee any problems like for instance what if someone starts at midnight and ends at 3:00pm. stuff like that. Thanks a million for all of your input, i really appreciate it.

====================== timeCalc =====================

Dim strStart, strLunchOut, strLunchIn, strEnd, strMornHours, strAftHours, strTotalHours
Dim strTime1, strTime2, strTime3, strTime4

strStart = Request.Form(&quot;strTime1&quot;)
strLunchOut = Request.Form(&quot;strTime2&quot;)
strLunchIn = Request.Form(&quot;strTime3&quot;)
strEnd = Request.Form(&quot;strTime4&quot;)


strMornHours = DateDiff(&quot;h&quot;, strStart, strLunchOut)
strAftHours = DateDiff(&quot;h&quot;, strLunchIn, strEnd)
strTotalHours = strMornHours + strAftHours

Response.Write strMornHours & &quot;<br>&quot;
Response.Write strAftHours & &quot;<br>&quot;
Response.Write strTotalHours
 
One minor change here, I have done two timecard systems in the past. You don't need to actually store each day in a differant table. Here is a sized down version of my own system:

Employee: eId, eName, etc
Hours: eId, total, date
Clock: eId, time_in, time_out

Clocking in is simple, just create a record in Clock for that person and specify the time_in as Now(). When the employee goes to clock outyou will fill in the time_out and create the hours record with total. The reasoning being that if you fill in the totals it takes an extra connection, but it is still quick and will speed up the view when someone asks for total hours for the week for all employees.

eId is an arbitrary autonumber field. If your employees already have ids, add another field to the employee table.
Adding your hours for the week is a simple process of:
&quot;SELECT Employee.Name, Sum(Hours.total) FROM Employee, Hours WHERE Employee.eId = Hours.eId GROUP BY Employee.Name&quot;

That should be roughly correct, though my on-the-fly SQL usually overlooks something so it may need some polish.

If you need any help whatsoever, feel free to let me know.

-Tarwn
Tarwn@ec.rr.com

------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top