; EXPENSE.FS
;
; Employee Expense Report Model
;

#AUTO MACRO GO

MENU MainMenu
{
; Menu displayed only when the main expense form is loaded and displayed
;
Popup "&File"
  Begin
    MENUITEM "&Ground Travel", Ground
    MENUITEM "&Air Travel", Air
    MENUITEM "&Meals", Meals
    MENUITEM "&Lodging", Lodging
    MENUITEM "&Business", Business
    MENUITEM "&Entertain", Entertain
    MENUITEM "&Other", Other
    MENUITEM Separator
    MENUITEM "Form &Info...", FileFormInfo
    MENUITEM "&Print Record", HardCopy
    MENUITEM "Printer Set&up...", FilePrinterSetup
    MENUITEM Separator
    MENUITEM "E&xit", CheckExit
    MENUITEM "&Restore Filler", CleanUp
  End
Popup "&Help"
  Begin
    MENUITEM "&About PerForm PRO...", HelpAboutPerFormPro
    MENUITEM "&This Form System...", formsysinfo
  End
}


MENU FormsMenu
{
; Menu displayed when the any of the sub-forms are loaded and displayed
;
Popup "&File"
  Begin
    MENUITEM "&Main Screen", ShowCover
    MENUITEM Separator
    MENUITEM "Form &Info...", FileFormInfo
    MENUITEM Separator
    MENUITEM "E&xit", CheckExit
    MENUITEM "&Restore", SystemRestoreSystem
  End
Popup "&Data"
  Begin
    MENUITEM "&Save...", DataUpdateRecord
  End
Popup "&Edit"
  Begin
    MENUITEM "C&ut", EditCut
    MENUITEM "&Copy", EditCopy
    MENUITEM "&Paste", EditPaste
  End
Popup "&View"
  Begin
    MENUITEM "&Auto Recalc", ViewAutoRecalc
    MENUITEM "Show &Graphics", ViewShowGraphics
    MENUITEM "Re&calculate", ViewRecalculate
    MENUITEM Separator
    MENUITEM "Fit In &Window", ViewFitInWindow
    MENUITEM "Fit &Sides", ViewFitSides
    MENUITEM "&Real Size", ViewRealSize
    MENUITEM "&Enlarge", ViewEnlarge
  End
Popup "&Help"
  Begin
    MENUITEM "&About PerForm PRO...", HelpAboutPerFormPro
    MENUITEM "&This Form System...", formsysinfo
  End
}



MENU TotalsMenu
{
; Menu displayed only when the totals form is loaded and displayed
;
Popup "&File"
  Begin
    MENUITEM "&Main Screen", ShowCover
    MENUITEM Separator
    MENUITEM "Form &Info...", FileFormInfo
    MENUITEM Separator
    MENUITEM "E&xit", CheckExit
    MENUITEM "&Restore", SystemRestoreSystem
  End
Popup "&Data"
  Begin
    MENUITEM "&Save...", DataUpdateRecord
  End
Popup "&Security"
  Begin
    MENUITEM "Verify &Signature...", SecurityVerifySignature
    MENUITEM Separator
    MENUITEM "&Log In...", SecurityLogIn
    MENUITEM "Log &Out", SecurityLogOut
    MENUITEM "Change &Password...", SecurityChangePassword
  End
Popup "&Help"
  Begin
    MENUITEM "&About PerForm PRO...", HelpAboutPerFormPro
    MENUITEM "&This Form System...", formsysinfo
  End
}


RIBBON CoverRibbon
{
; Ribbon displayed only when the main expense form is loaded and displayed
;
Bitmap "WIN_CAL", LoadCalndr
Bitmap "WIN_CALC", LoadCalc
Button "Task", LoadTaskMngr
Button "Dos", LoadDosSession
Space
Button "New", DataNewRecord
Button "Save", DataUpdateRecord
Button "Search", RecordSearch
Space
BitmapText "FILEQUIT,Exit", CheckExit
Bitmap "HELPINDE", formsysinfo
}


RIBBON ExpRibbon
{
; Ribbon displayed when the any of the sub-forms are loaded and displayed
;
Bitmap "WIN_CAL", LoadCalndr
Bitmap "WIN_CALC", LoadCalc
Button "Task", LoadTaskMngr
Button "Dos", LoadDosSession
Space
BitmapText "FILESAVE,Save Changes", DataUpdateRecord
Space
BitmapText "FILEQUIT,Exit", CheckExit
Bitmap "HELPINDE", formsysinfo
}


MACRO Go
{
; Set the screen components up
;
WindowSetTitle "Travel Expense Model"
MainMenu
ViewFitInWindow
WindowFormMaximize
ViewShowRibbon 0
CoverRibbon
;
; Establish the desired program preferences
;
ViewAutoRecalc 1
BeginExec ViewPreferences
  OnNewRecord           "RememberSelected"
  UpdateFillLogFile     "NO"
  SignatureVerification "Automatic"
  BeepOnError           "YES"
  SavePreferences       "NO"
  AutoDataLookup        "NO"
  ShowDeletedRecords    "NO"
  HighlightField        "NO"
EndExec
;
; Load the work and main forms
;
BeginExec FileOpenForm
  File  "Buffer.frp"
  Title "Buffer"
  Show  "Hidden"
EndExec
LoadCoverForm
;
; Default is help OFF -- button always shows the current value
;
EditReplaceField TOGGLEHELP,"Help Off"
}



MACRO formsysinfo
{
Message="[0][PerForm PRO Plus|Employee Expense Report Model|Version 1.0, by Michael Harris|Delrina Technology Inc.|To be used as a foundation for your own|expense reporting system.][Continue]"
}


MACRO LoadCoverForm
{
; Load the cover form
;
BeginExec FileOpenForm
  File  "Cover.frp"
  Title "Main Screen"
EndExec
WindowFormMaximize
}


MACRO ShowCover
{
; Re-load the cover form after another form has been active
;
If FileCloseForm
  MainMenu
  CoverRibbon
  LoadCoverForm
  ViewFitInWindow
End
GetRecordBack
}


MACRO PrepareForTransfer
{
; Prepare to transfer to a sub-form from the main form
;
DataUpdateRecord
Buffer->REPORT_NO=REPORT_NO
Buffer->IDX_FIELD=IDX_FIELD
FileCloseForm
FormsMenu
ExpRibbon
}




MACRO CheckForCompletion
{
; Verify the required data is on the cover page so we can get back
;
CHKEXIT=1
If ~EMPNUM
  CHKEXIT = 0
  WaitForIdle
  Message "[3][An Employee Number must be entered.][&OK]"
  LocateGoToField "EMPNUM"
End
If ~FROM_DATE
  If CHKEXIT
    CHKEXIT = 0
    WaitForIdle
    Message "[3][A begin date for the expense|report must be specified.][&OK]"
    LocateGoToField "FROM_DATE"
  End
End
If ~TO_DATE
  If CHKEXIT
    CHKEXIT = 0
    WaitForIdle
    Message "[3][An end date for the expense|report must be specified.][&OK]"
    LocateGoToField "TO_DATE"
  End
End
}



MACRO Ground
{
; Called by both the menu and the cover form button.  Checks for completed
; fill data and displays help if help is turned on.
;
CheckForCompletion
If CHKEXIT
  If TOGGLEHELP="1"
    STAYORGO=Message "[2][Use this form to enter expenses accumulated|through the use of ground transportation.][Continue|Cancel]"
    If STAYORGO="1"
      LoadGround
    End
  Else
    LoadGround
  End
End
}


MACRO LoadGround
{
EditReplaceField IDX_FIELD,"Ground"
PrepareForTransfer
BeginExec FileOpenForm
  File  "Ground.frp"
  Title "Ground Travel"
  MultiCopies "No"
EndExec
ViewFitInWindow
}


MACRO Air
{
CheckForCompletion
If CHKEXIT
  If TOGGLEHELP="1"
    STAYORGO=Message "[2][Use this form to enter expenses accumulated|through the use of air transportation.][Continue|Cancel]"
    If STAYORGO="1"
      LoadAir
    End
  Else
    LoadAir
  End
End
}


MACRO LoadAir
{
EditReplaceField IDX_FIELD,"Air"
PrepareForTransfer
BeginExec FileOpenForm
  File  "Air.frp"
  Title "Air Travel"
  MultiCopies "No"
EndExec
GetRecord
ViewFitInWindow
}


MACRO Meals
{
CheckForCompletion
If CHKEXIT
  If TOGGLEHELP="1"
    STAYORGO=Message "[2][Use this form to enter expenses accumulated|through meals consumed during the|expense period.][Continue|Cancel]"
    If STAYORGO="1"
      LoadMeals
    End
  Else
    LoadMeals
  End
End
}


MACRO LoadMeals
{
EditReplaceField IDX_FIELD,"Meals"
PrepareForTransfer
BeginExec FileOpenForm
  File  "Meals.frp"
  Title "Meals (Chow Time!)"
  MultiCopies "No"
EndExec
GetRecord
ViewFitInWindow
}


MACRO Lodging
{
CheckForCompletion
If CHKEXIT
  If TOGGLEHELP="1"
    STAYORGO=Message "[2][Use this form to enter expenses accumulated|through Hotel accommodations.|Do not include meals paid outside of grouped|hotel charges.][Continue|Cancel]"
    If STAYORGO="1"
      LoadLodging
    End
  Else
    LoadLodging
  End
End
}

MACRO LoadLodging
{
EditReplaceField IDX_FIELD,"Lodging"
PrepareForTransfer
BeginExec FileOpenForm
  File  "Lodging.frp"
  Title "Lodging"
  MultiCopies "No"
EndExec
GetRecord
ViewFitInWindow
}


MACRO Business
{
CheckForCompletion
If CHKEXIT
  If TOGGLEHELP="1"
    STAYORGO=Message "[2][Use this form to enter expenses incurred for work related|purchases required to complete company related matters.|Remember, this is the reason you get paid!][Continue|Cancel]"
    If STAYORGO="1"
      LoadBusiness
    End
  Else
    LoadBusiness
  End
End
}


MACRO LoadBusiness
{
EditReplaceField IDX_FIELD,"Business"
PrepareForTransfer
BeginExec FileOpenForm
  File  "Business.frp"
  Title "The reason you're here!"
  MultiCopies "No"
EndExec
GetRecord
ViewFitInWindow
}



MACRO Entertain
{
CheckForCompletion
If CHKEXIT
  If TOGGLEHELP="1"
    STAYORGO=Message "[2][Use this form to enter expenses accumulated|through business related entertainment.|Receipts from Bordello's or Chip'n Dales|are NOT allowable expense claim items.][Continue|Cancel]"
    If STAYORGO="1"
      LoadEntertain
    End
  Else
    LoadEntertain
  End
End
}

MACRO LoadEntertain
{
EditReplaceField IDX_FIELD,"Entertainment"
PrepareForTransfer
BeginExec FileOpenForm
  File  "Entrtain.frp"
  Title "Entertainment"
  MultiCopies "No"
EndExec
GetRecord
ViewFitInWindow
}


MACRO Other
{
CheckForCompletion
If CHKEXIT
  If TOGGLEHELP="1"
    STAYORGO=Message "[2][Use this form to enter any other expenses,|outside of normal business expenses,|incurred by employee.][Continue|Cancel]"
    If STAYORGO="1"
      LoadOther
    End
  Else
    LoadOther
  End
End
}


MACRO LoadOther
{
EditReplaceField IDX_FIELD,"Other"
PrepareForTransfer
BeginExec FileOpenForm
  File  "Other.frp"
  Title "Other"
  MultiCopies "No"
EndExec
GetRecord
ViewFitInWindow
}



MACRO Totals
{
CheckForCompletion
If CHKEXIT
  If TOGGLEHELP="1"
    STAYORGO=Message "[2][Use this form to view the total amount you|have entered as travel expenses.][Continue|Cancel]"
    If STAYORGO="1"
      LoadTotals
    End
  Else
    LoadTotals
  End
End
}


MACRO LoadTotals
{
Buffer->REPORT_NO=REPORT_NO
DataUpdateRecord
FileCloseForm
TotalsMenu
BeginExec FileOpenForm
  File  "Totals.frp"
  Title "Totals"
EndExec
ViewFitInWindow
GetRecordBack
}


MACRO GetRecord
{
; Search for a match on both report number and the index field by searching
; from the start of the data file.
;
BeginExec LocateSearchOnIndexField
  BeginIndex
    File  "IDX00000.NDX"
    IndexExpression "REPORT_NO+IDX_FIELD"
  EndIndex
  SearchData REPORT_NO = Buffer->REPORT_NO
  SearchData IDX_FIELD = Buffer->IDX_FIELD
  SearchMatch "Equal to"
  StartSearchFromFirst
EndExec
}


MACRO GetRecordBack
{
; Search for a match on report number to get the record back when switching
; between forms.
;
BeginExec LocateSearchOnIndexField
  BeginIndex
    File  "IDX00004.NDX"
    IndexExpression "REPORT_NO"
    IndexCaseSensitive
    IndexUniqueRecords
  EndIndex
  SearchData REPORT_NO = Buffer->REPORT_NO
  SearchMatch "Equal to"
  StartSearchFromFirst
EndExec
}



MACRO RecordSearch
{
; Display the Search On Index dialog with most of the fields filled in with
; default values.  The user can fill in the report number value and start
; the search with a minimum of fuss and bother.
;
BeginDialog LocateSearchOnIndexField
  BeginIndex
    File  "IDX00004.NDX"
    IndexExpression "REPORT_NO"
    IndexCaseSensitive
    IndexUniqueRecords
  EndIndex
  SearchData REPORT_NO=""
  SearchMatch "Equal to"
  StartSearchFromFirst
EndDialog
}



MACRO HardCopy
{
; Close the cover form, and load up the print form and print it.
;
Buffer->REPORT_NO=REPORT_NO
FileCloseForm
BeginExec FileOpenForm
  File "Printfrp.frp"
  Title "Hard Copy"
  Show "Hidden"
EndExec
;
; Plant the report number in the field and the entire form will lookup the
; data automatically.  Auto recalc is turned on at the start and cannot be
; turned off by the user except through the keyboard quick keys.  To be
; perfectly safe you could add a "ViewAutoRecalc 1" command here.
;
REPORT_NO = Buffer->REPORT_NO
;
; Enter amount paid per mile. eg. AMNT_MILE=".25" is 25 cents per mile
;
EditReplaceField CENTS_MILE,".25"
ViewFitInWindow
WaitForIdle
BeginExec FilePrint
  PAGEFROM    "All"
  COPIES      1
  PRINTSPEED  "FAST"
  PRINTCOLORS "AS_COLOR"
  PRINTFORM   "YES"
  PRINTDATA   "YES"
  DATA        "CURRENT"
EndExec
;
; Go back and show the cover page again.
;
ShowCover
}



MACRO LoadCalc
{
; Run the Windows calculator accessory
;
SystemRunProgram "Calc.exe"
}

MACRO LoadCalndr
{
; Run the Windows calendar accessory
;
SystemRunProgram "Calendar.exe"
}

MACRO LoadTaskMngr
{
; Run the Windows task manager Switch To dialog
;
SystemRunProgram "Taskman.exe"
}

MACRO LoadDosSession
{
; Run a DOS session
;
SystemRunProgram "Dos.pif"
}



MACRO CheckExit
{
; Verify the user really wants to get out of here
;
If FORMTITLE()="Main Form"
  ;
  ; The main expense form
  ;
  CHKEXIT=Message "[2][Exiting the Form System.|What action do you wish to take?][&Exit Filler|Close Form &System|&Cancel]"
  If CHKEXIT=1
    ; Restore Filler back to a somewhat normal status and exit Filler
    ;
    ViewShowRibbon 1
    FileExit
  Else
    If CHKEXIT=2
      ; Shut down the form system, but keep Filler running
      ;
      CleanUp
    End
  End
Else
  ;
  ; Currently using any of the sub-forms
  ;
  CHKEXIT=Message "[2][Exiting the Form System.|What action do you wish to take?][&Exit Filler|&Main Screen|&Cancel]"
  If CHKEXIT=1
    ; Restore Filler back to a somewhat normal status and exit Filler
    ;
    ViewShowRibbon 1
    FileExit
  Else
    If CHKEXIT=2
      ; Go back and show the main expense management form again
      ;
      ShowCover
    End
  End
End
}



MACRO CleanUp
{
; Restore Filler back to a somewhat normal status
;
WindowCloseAll
SystemRestoreSystem
ViewShowRibbon 1
}


MACRO DateMessage
{
; User just entered a date that failed CheckDate.  Alert and take them back.
;
WaitForIdle
Message "[3][The date entered is not between the From|and To dates specified for this expense|period.  Please change the date to comply|with the expense period.][OK]"
LocateFieldPrevious
}


MACRO CheckDate
{
; Verify the date entered is between the FROM and TO dates
;
If DIFFDATE([FROM_DATE],[DATE])<0
  DateMessage
End
If DIFFDATE([TO_DATE],[DATE])>0
  DateMessage
End
}


MACRO SetStatus
{
WaitForIdle
If ~SIGNATURE
  SETSTAT=Message "[0][You must set a status for your report|before locking your report.][&Submitted|&In Progress|&Cancel]"
  If SETSTAT = 1
    EditReplaceField STATUS,"Submitted"
  Else
    If SETSTAT = 2
      EditReplaceField STATUS,"In Progress"
    Else
      ; by default SETSTAT=3
      ;
      LocateFieldNext
      If STATUS >=1
        EditReplaceField STATUS,""
      End
    End
  End
End
}

