#! /bin/ksh
##########################################################################
##  N.E.C. America                                                      ##
##  Satellite Software Department                                       ##
##                                                                      ##
##        Shell to run the timecard program time.tk                     ##
##        This shell will calculate the appropriate timesheet to load   ##
##        if no timesheet is given as an argument to this shell.        ##
##									##
##        Created Fri Mar 24 09:59:25 CST 1995 by Monty Scroggins       ##
##									##
##########################################################################
##
## Note - TIMESHEETDIR must be defined to point to the directory where the 
##                timesheets are kept. The file time.tk also needs to be
##                placed in this directory. 
##  
##        EMPNAME must be defined to be the user name.  This environment
##                variable will be placed in the "Employee Name" field.
##                If your name is Penny then RHP!!
##
## Once a timesheet is created and saved, the values of these two variables
## are preserved in the timesheet file. 
## 
## If your date command returns a zero-relative value for week, uncomment 
## line 38 below to set the week value to a one relative number.
##
c\d $TIMESHEETDIR
case $# in
    1) WEND="mmddyy";
       export WEND;
       wish -f time.tk $1&;;
    [2-9]) echo  "Usage - timesheet.sh  [timesheet] <Return>";
       exit;;
    *) YEAR="95";
       WEEK="`date +%U`";
       DAY="`date +%w`";
       #let WEEK=$WEEK+1  #if your date command returns zero relative week - uncomment;
       typeset -i WEEK
       if [ $DAY = 6 ]
       then
           WEEK=$WEEK+1
       fi
            case $WEEK in
            00)echo "Your version of date returns a zero relative value for";
               echo "week number. Your week variable needs to be incremented";
               echo "Uncomment line number 38 in this file..";
               exit;;
       	     1)WEND="06";MONTH="01";;
       	     2)WEND="13";MONTH="01";;
       	     3)WEND="20";MONTH="01";;
       	     4)WEND="27";MONTH="01";;
       	     5)WEND="03";MONTH="02";;
       	     6)WEND="10";MONTH="02";;
       	     7)WEND="17";MONTH="02";;
       	     8)WEND="24";MONTH="02";;
       	     9)WEND="03";MONTH="03";;
       	    10)WEND="10";MONTH="03";;
       	    11)WEND="17";MONTH="03";;
       	    12)WEND="24";MONTH="03";;
       	    13)WEND="31";MONTH="03";;
       	    14)WEND="07";MONTH="04";;
       	    15)WEND="14";MONTH="04";;
       	    16)WEND="21";MONTH="04";;
       	    17)WEND="28";MONTH="04";;
       	    18)WEND="05";MONTH="05";;
       	    19)WEND="12";MONTH="05";;
       	    20)WEND="19";MONTH="05";;
       	    21)WEND="26";MONTH="05";;
       	    22)WEND="02";MONTH="06";;
       	    23)WEND="09";MONTH="06";;
       	    24)WEND="16";MONTH="06";;
       	    25)WEND="23";MONTH="06";;
       	    26)WEND="30";MONTH="06";;
       	    27)WEND="07";MONTH="07";;
       	    28)WEND="14";MONTH="07";;
       	    29)WEND="21";MONTH="07";;
       	    30)WEND="28";MONTH="07";;
       	    31)WEND="04";MONTH="08";;
       	    32)WEND="11";MONTH="08";;
       	    33)WEND="18";MONTH="08";;
       	    34)WEND="25";MONTH="08";;
       	    35)WEND="01";MONTH="09";;
       	    36)WEND="08";MONTH="09";;
       	    37)WEND="15";MONTH="09";;
       	    38)WEND="22";MONTH="09";;
       	    39)WEND="29";MONTH="09";;
       	    40)WEND="06";MONTH="10";;
       	    41)WEND="13";MONTH="10";;
       	    42)WEND="20";MONTH="10";;
       	    43)WEND="27";MONTH="10";;
       	    44)WEND="03";MONTH="11";;
       	    45)WEND="10";MONTH="11";;
       	    46)WEND="17";MONTH="11";;
       	    47)WEND="24";MONTH="11";;
       	    48)WEND="01";MONTH="12";;
       	    49)WEND="08";MONTH="12";;
       	    50)WEND="15";MONTH="12";;
       	    51)WEND="22";MONTH="12";;
       	    52)WEND="29";MONTH="12";
               echo "Timesheet script needs to be configured for the new year";
               echo "before weeks end!!";;
       	    53)WEND="05";YEAR="96";MONTH="01";
               echo "Timesheet script needs to be configured for the new year!";;
      esac
      WEND=$MONTH$WEND$YEAR;
      export WEND;
      TIMESHEET=$WEND.sheet;
      wish -f time.tk $TIMESHEET&;;
esac
