; MNG_EXP.FS
;
; Employee Expense Report Model (Manager)

#AUTO MACRO GO

MENU MainMenu
{
; Main menu displayed when the expense manager form is being used
;
Popup "&File"
  Begin
    MENUITEM "&Ground Travel", LoadGround
    MENUITEM "&Air Travel", LoadAir
    MENUITEM "&Meals", LoadMeals
    MENUITEM "&Lodging", LoadLodging
    MENUITEM "&Business", LoadBusiness
    MENUITEM "&Entertain", LoadEntertain
    MENUITEM "&Other", LoadOther
    MENUITEM Separator
    MENUITEM "&Save...", DataUpdateRecord
    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 "&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
}

MENU FormsMenu
{
; Menu displayed when any of the sub-forms are displayed
;
Popup "&File"
  Begin
    MENUITEM "&Main Screen", ShowCover
    MENUITEM Separator
    MENUITEM "Form &Info...", FileFormInfo
    MENUITEM Separator
    MENUITEM "E&xit", CheckExit
    MENUITEM "&Restore Filler", CleanUp
  End
Popup "&View"
  Begin
    MENUITEM "Show &Graphics", ViewShowGraphics
    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
}


RIBBON CoverRibbon
{
; Ribbon displayed when the expense manager form is being used
;
Bitmap "WIN_CAL", LoadCalndr
Bitmap "WIN_CALC", LoadCalc
Button "Task", LoadTaskMngr
Button "Dos", LoadDosSession
Space
Button "Prev.", LocateRecordPrevious
Button "Next", LocateRecordNext
Button "Search", RecordSearch
Space
BitmapText "FILEQUIT,Exit", CheckExit
Bitmap "HELPINDE", formsysinfo
}

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



MACRO Go
{
; Set the screen components up
;
WindowSetTitle "Travel Expense Model (Mngr.)"
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
LoadExpenseManager
}



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



MACRO LoadExpenseManager
{
; Load the main expense manager form
;
BeginExec FileOpenForm
  File "Mng_ttls.frp"
  Title "Expense (Manager)"
EndExec
WindowFormMaximize
}



MACRO ShowCover
{
; Re-load the expense manager form after another form has been active
;
ModeEdit
If FileCloseForm
  MainMenu
  CoverRibbon
  ViewFitInWindow
  LoadExpenseManager
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 LoadGround
{
If GRND_TTL
  EditReplaceField IDX_FIELD,"Ground"
  PrepareForTransfer
  BeginExec FileOpenForm
    File        "Ground.frp"
    Title       "Ground Travel"
    MultiCopies "No"
  EndExec
  ViewFitInWindow
  ModeView
End
}

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

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

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

MACRO LoadBusiness
{
If BUS_TTL
  EditReplaceField IDX_FIELD,"Business"
  PrepareForTransfer
  BeginExec FileOpenForm
    File        "Business.frp"
    Title       "Business"
    MultiCopies "No"
  EndExec
  GetRecord
  ViewFitInWindow
  ModeView
End
}

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

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

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()="Expense Totals (Mngr.)"
  ;
  ; 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 SetStatus
{
; Macro used by a fill field on a form in the form system
;
TimeWait 60
If SIGNATURE <1
  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
      LocateFieldNext
      If STATUS >=1
        EditReplaceField STATUS,""
      End
    End
  End
End
}

