put "SEND THE FEE, AND YOU'LL BE ALLOWED MORE MONTHS"
end extend
function getStartDate
-- end of stack this month, whichever is newer
put (field "Month") && "1," && (field "Year") into it
if length(it) < 11 then put the date into it
else
convert it to seconds
if field 16 is not empty then add 60*60*24*32 to it
--add 32 days for next month if this month has dates
end if
put startOfMonth(it) into it --so we can compare
put the date into thisMonth
put startOfMonth(thisMonth) into thisMonth --both at week starts in seconds
if thisMonth < 2587766400 then
answer "Set the Control Panel to today's date" with "OK"
return "Cancel"
end if
if it >= thisMonth then return it --calendar already beyond today
convert it to short date
convert thisMonth to short date
answer "Start from which date?" with it or thisMonth or "Cancel"
if it is "Cancel" then return it
convert it to seconds
return it
end getStartDate
function startOfMonth aDate -- the seconds of Monday before the 1st
put 60*60*24 into OneDay --seconds in a day
put aDate into it
convert it to long date
put 1 into word 2 of item 2 of it --first of month
convert it to seconds
convert it to long date
repeat while item 1 of it <> "Sunday"
convert it to seconds
subtract OneDay from it --look for previous Sunday
convert it to long date
end repeat
convert it to seconds
return it
end startOfMonth
on openBackground
show menubar
hide message
push recent card
put (field 1 & line 1 of field year) into it
set the name of this card to it
if length of line 2 of field year < 2 then
put "4 4" into line 2 of field Year -- default values for shifts in a row
-- and number of shifts per day to schedule
end if
if (word 1 of line 3 of field year < 1) then put 1 into line 3 of field year
-- personal menu set up
global menu1,menu2
put NewMenu("Schedule","Requests On","Requests Off" ,"(-","Erase Schedule","Go To Next Month", "Go To Prior Month", "Extend Calendar","(-", "HELP") into menu1
if menu1 is 0 then answer ("Unable to make menu "Beep") with "Drat"
put NewMenu("SetUp","Set Requests On","Set Requests Off","(-", "Set Max # Days in a Row", "Set # Shifts per Day","Set Salvos","(-", "Talley", "Go to Current Month", "Delete this Card") into menu2
if menu2 is 0 then answer ("Unable to make menu Visual") with "Drat"
end OpenBackground
on closebackground
global menu1,menu2
put deleteMenu(menu1) into menu1 -- clearing global for safety
put deleteMenu(menu2) into menu2
end closebackground
on idle
global menu1, menu2, lastTick
if (the ticks-lastTick)>120 then
put the ticks into lastTick
ShowMenu(menu1)
ShowMenu(menu2)
end if
pass idle
end idle
on doMenu which -- get menu items from doMenu before Hypercard does
global menu1,menu2
if which is "Requests Off" then
send "mouseUp" to bkgnd button "Schedule Off"
else if which is "Requests On" then
send "mouseUp" to bkgnd button "Schedule On"
else if which is "Set Requests Off" then
send "mouseUp" to bkgnd button "Requests Off"
else if which is "Set Requests On" then
send "mouseUp" to bkgnd button "Requests On"
else if which is "Talley" then
send "mouseUp" to bkgnd button "Talley"
else if which is "Go to Current Month" then
send "mouseUp" to bkgnd button "Show Current Month"
else if which is "Erase Schedule" then
send "mouseUp" to bkgnd button "Erase Sched"
else if which is "Set Max # Days in a Row" then
setDaysinaRow
else if which is "Set # Shifts per Day" then
setShiftsPerDay
else if which is "Set Salvos" then
ask "How days per Salvo... (1-5)" with "1"
put it into line 3 of field "year"
else if which is "Extend Calendar" then
extend
else if which is "Go To Next Month" then
visual Effect Dissolve Fast
doMenu Next
else if which is "Go To Prior Month" then
visual Effect Dissolve Fast
doMenu Prev
else if which is "Help" then
visual Effect Dissolve Fast
send "mouseUp" to bkgnd button "Help"
else if which is "Delete this Card" then
Answer "Are you Sure..." with "Yes" or "No"
if it is "No" then exit doMenu
doMenu Delete Card
else pass doMenu -- pass on menu commands I don't trap
end doMenu
on SetDaysInaRow
Ask "Limit Days in a Row to..." with "5"
put it into word 1 of line 2 of field Year -- hide it here
end SetDaysInaRow
on setShiftsPerDay
put 0 into it
repeat until (it > 0 and it <= 4)
Ask "How Many Shifts Per Day (1 - 4)" with "4"
end repeat
put " " & it into word 2 of line 2 of field year -- hide it here
end setShiftsPerDay
on LabelDays
global firstofmonth, lastofmonth
-- ***** now put which day of the week it is in each box ******
repeat with index = firstofmonth to lastofmonth
put field 1 && word 1 of field index & "," & field 37 into it
convert it to abbreviated date
put word 1 of it into it
put it into line 5 of field index
end repeat
end LabelDays
on CheckButtons
put Char 1 of word 1 of field 1 & char 1 of word 2 of field 1 into name
global storage
put "" into storage
put "A B C D" into Shifts
repeat with shift = 1 to 4
repeat with index = 1 to 31
put index+((shift-1)*31) into today -- there are 124 buttons to check
if hilite of card button today = "True" then
put word shift of Shifts & index & " " after storage
-- storage looks like this ..A1 A3 A22 B12 C14 etc...
end if
end repeat
end repeat
put name & " " before storage
end CheckButtons
-- part 5 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=196 top=44 right=67 bottom=304
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 3
-- text size: 18
-- style flags: 256
-- line height: 24
-- part name: Month
-- part 8 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=11 top=99 right=141 bottom=80
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 9 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=79 top=99 right=141 bottom=148
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 10 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=147 top=99 right=142 bottom=216
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 11 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=215 top=99 right=141 bottom=284
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 12 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=283 top=99 right=141 bottom=352
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 13 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=351 top=99 right=141 bottom=420
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 14 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=419 top=99 right=141 bottom=488
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 15 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=11 top=145 right=187 bottom=80
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 16 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=79 top=145 right=187 bottom=148
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 17 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=147 top=145 right=187 bottom=216
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 18 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=215 top=145 right=187 bottom=284
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 19 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=283 top=145 right=187 bottom=352
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 20 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=351 top=145 right=187 bottom=420
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 22 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=419 top=145 right=187 bottom=488
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 23 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=11 top=191 right=233 bottom=80
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 24 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=79 top=191 right=233 bottom=148
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 25 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=147 top=191 right=233 bottom=216
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 26 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=215 top=191 right=233 bottom=284
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 27 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=283 top=191 right=233 bottom=352
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 28 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=348 top=191 right=233 bottom=417
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 29 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=419 top=191 right=233 bottom=488
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 30 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=11 top=237 right=279 bottom=80
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 31 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=79 top=237 right=279 bottom=148
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 32 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=147 top=237 right=279 bottom=216
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 33 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=215 top=237 right=279 bottom=284
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 34 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=283 top=237 right=279 bottom=352
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 35 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=351 top=237 right=279 bottom=420
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 36 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=419 top=237 right=279 bottom=488
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 37 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=11 top=283 right=325 bottom=80
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 38 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=79 top=283 right=325 bottom=148
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 39 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=147 top=283 right=325 bottom=216
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 40 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=215 top=283 right=325 bottom=284
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 41 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=283 top=283 right=325 bottom=352
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 42 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=351 top=283 right=325 bottom=420
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 43 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=419 top=283 right=325 bottom=488
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 10
-- part name:
-- part 44 (button)
-- low flags: 00
-- high flags: 0000
-- rect: left=0 top=324 right=342 bottom=30
-- title width / last selected line: 0
-- icon id / first selected line: 20689 / 20689
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: go to home
----- HyperTalk script -----
on mouseUp
go Home
end mouseUp
-- part 49 (field)
-- low flags: 00
-- high flags: 0000
-- rect: left=10 top=43 right=62 bottom=66
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 14
-- style flags: 256
-- line height: 18
-- part name: Year
-- part 53 (field)
-- low flags: 80
-- high flags: 0000
-- rect: left=18 top=107 right=316 bottom=474
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: backfield
-- part 55 (button)
-- low flags: 00
-- high flags: 0000
-- rect: left=138 top=0 right=15 bottom=219
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Schedule Off
----- HyperTalk script -----
On mouseup
global shiftloopcount, storage, index, SalvoNum
put line 3 of field year into SalvoNum
Ask "How Many Shifts of type 'A' per Day(1-4)" with "1"
if it > 4 or it < 1 then
exitroutine
exit mouseUp
else
put it into TypeANum
put it & " " into ShiftLoopCount
end if
Ask "How Many Shifts of Type 'B' per Day (1-4)" with "1"
if it > 4 or it < 1 then
exitroutine
exit mouseUp
else
put it into TypeBNum
put it & " " after shiftLoopCount
end if
Ask "How Many Shifts of Type 'C' per Day (1-4)" with "1"
if it > 4 or it < 1 then
exitroutine
exit mouseUp
else
put it into TypeCNum
put it & " " after shiftLoopCount
end if
Ask "How Many Shifts of Type 'D' per Day (1-4)" with "1"
if it > 4 or it < 1 then
exitroutine
exit mouseUp
else
put it into TypeDNum
put it & " " after shiftLoopCount
end if
Hide Message
set cursor to 4
set lockscreen to true
-- Answer "Schedule people who WANT certain shifts? " with "Yes" or "No"
-- if it contains "Yes" then
-- put "Getting Requests On First"
-- send mouseUp to bkgnd button "Schedule On"
-- end if
if (the length of line 5 of field 15 < 1) then -- pick some field in the middle
SetUpCalendar
LabelDays -- if the days haven't been labelled, do it now
end if
-- now get requests off for this month
set cursor to 4
put "" into field 38 -- clear it out first
put " I'm getting peoples requests for days off"
put id of last card of bkgnd "Requests Off" into lastid -- for later checking
put "False" into LastCardTest -- set THE Boolean to false
put 0 into cardnum
repeat until (LastCardTest="True")
push card--push calendar card on to stack
closebackground -- take care of the menus etc...
put cardnum + 1 into cardnum -- increment this for each loop
go to card cardnum of bkgnd "requests off"
get id of card
if it = lastid then put "True" into LastCardTest--if so... Stop
GetData
closebackground
pop card
put storage into line cardnum of field backfield
end repeat
if (number of lines of field 38 = 1) then
answer "Only one person? - don't waste your time"
exit mouseUp
end if
BeginToSchedule
end mouseUp
on BeginToSchedule
global employeenum, Name, index, shift, shiftloopcount, employee
global firstofmonth, lastofmonth, shifnum, subindex, DaysInaRowLimit
global limitpointer, SalvoNum
set cursor to 4
put "A B C D" into shifts
put word 2 of line 2 of field year into shifnum
put word 1 of line 2 of field "Year" into it
put it - 1 into DaysInaRowLimit
put the number of lines of field 38 into employeenum
SetUpCalendar -- find first and last of month
set lockscreen to false -- let's watch it work
repeat with index = firstofmonth to lastofmonth -- day by day
put word 1 of line 1 of field index after line 6 of field index -- save date we'll put it back later
put "" into word 1 of line 1 of field index--strip leading blanks
put "" before word 1 of line 1 of field index
repeat with subindex = 1 to Shifnum -- sched all 4 shifts day by day
-- *********
put word subindex of shiftloopcount into shiftloop -- how people pert shift
put word subindex of shifts into shift -- how many shifts
repeat with subsubindex = 1 to shiftloop
if number of words of line subindex of field index < (shiftloop) then -- if not full up... proceed
GetAWorker
PutName
-- remember to count down the number of days they're available
if (Name contains "**") then next repeat -- but not if it's 'no name'
CountDown
if SalvoNum > 1 then
Salvo
end if
else -- if already done ... skip this part
wait 1 -- later may use this area to keep a running total
end if
end repeat
end repeat
put last word of line 6 of field index before line 1 of field index
put "" into line 6 of field index
end repeat
end BeginToschedule
On GetAWorker
Global employeenum, Name, Date, Answer, employee, index
put "False" into Cycled
put "False" into Looped
put "False" into Date -- set the Boolean
put random (employeenum) into seed -- start looking in a random spot
put seed into employee
Repeat until (Cycled = "True")
put First word of line employee of field 38 into Name
shiftLimittest-- first test of potential to work
if Answer = "Yes" then AvailabilityTest--check for day off requested
if answer = "Yes" then NightMorningTest--did they work last shift of yesterday
if answer = "Yes" then DaysInaRowTest --within our limits for days in a row?
if answer = "No" then -- if any test says, NO...they can't be put on
put "**" into Name -- is left like this if no one available
else
put "Filled" into Date
exit GetaWorker -- got a name - no need to stick around
end if
if (employee = employeenum) then
put 1 into employee
put "true" into looped
else
put (employee + 1) into employee
end if
if employee = seed AND looped = "true" then
put "True" into Cycled
end if
-- if we've gone through everyone once, then quit...(a full cycle)
end repeat
end GetAWorker
On AvailabilityTest
-- Just determines if a person is 'available'
global employee, Name, Date, Answer, index, Shift,Shifnum
if field index contains Name then -- are they already scheduled for today
put "No" into answer -- if so...
else
if line employee of field 38 contains (" " & first word of line 6 of field index & shift) -- remember we've hidden the date here
then
put "No" into answer
else
put "Yes" into answer -- yes he is available
end if
end if
end AvailabilityTest
on NightMorningTest -- Does not allow someone to work the night before
-- and the morning after (e.g. graveyard on the 3rd, AM on the 4th!!)
global shifnum, Name, index, subindex, answer
if subindex = 1 then -- we only need to do this test on the first shift
if line shifnum of field (index - 1) contains Name
then put "No" into answer -- tell the prog this person's unavailable
end if
end NightMorningTest
On DaysInaRowTest
global DaysInaRowLimit, index, subindex, Name, firstofmonth,answer
global shifnum
put "" into LimitReached -- intitialize
put index into here
if (index - daysInaRowLimit) > firstofmonth then
put (index - daysInaRowLimit - 1) into there
-- otherwise, its the first days of month, skip it
Repeat with rowindex = (here - 1) down to there
if field rowindex contains Name then
put "No" into Answer--set default to 'not available'...keep looking
else -- however, if anywhere along the 'days in a row' we're looking
put "Yes" into Answer --we don't find the person, then they're
exit repeat --available, and we don't need to look further
end if
end repeat
end if
end DaysInaRowTest
on GetData
Global Storage
put first char of first word of field "Name" & first char of second word of field "Name" && field "data" into storage