MESSAGE "Writing file cabinet procedures to library..."

PROC File_Cabinet_Wait(M_Tbl, D_Tbl)
  ; M_Tbl (master = files of files_x) D_Tbl (detail = ledger or ledger_x)
  PRIVATE Fld_Prompt, Answer_Menu, Cabinet, Employee, Hourly_Rate, Timing, Start_Time,
          File_No, Id, File_Type, Regarding, Opened, Closed, Status, 
          Empl_Num, Trust_Bal, Total_Charges, Amount_Owing, Transferable

  PROC Start_Ticker()
    Timing = TRUE
    Start_Time = Ticks()
    MESSAGE "Press Alt-T to stop timer"
  ENDPROC; Start_Ticker  

  PROC Stop_Ticker()
    PRIVATE Secs, Hrs, Seconds, Minutes, Hours, Button_Val
    Secs = (Ticks() - Start_Time) / 1000;
    Hrs  = Round(Secs / 3600, 2)
    Hours   = INT(Secs / 3600)
    Minutes = INT((Secs - Hours * 3600) / 60)
    Seconds = ROUND(MOD((Secs - Hours * 3600), 60), 0)
    Hours   = STRVAL(Hours)
    if (LEN(Hours) < 2) then
      Hours = "0" + Hours
    endif
    Minutes = STRVAL(Minutes)
    if (LEN(Minutes) < 2) then
      Minutes = "0" + Minutes
    endif
    Seconds = STRVAL(Seconds)
    if (LEN(Seconds) < 2) then
      Seconds = "0" + Seconds
    endif
    SHOWDIALOG "Elapsed Time"
      @10,20 HEIGHT 7 WIDTH 40
      @1, 1 ?? FORMAT("W36,AC", "Time:  " + Hours + ":" + Minutes + ":" + Seconds + " (" + FORMAT("W6.2",Hrs) +" hours)")
      PUSHBUTTON @3,13 WIDTH 12
        "~O~K"
        OK
        VALUE "OK"
        TAG "OK_Button"
      TO Button_Val
    ENDDIALOG      
    if (SYSMODE() = "CoEdit") then
      REFRESH
    endif  
    Timing = FALSE
  ENDPROC; Stop_Ticker  

  PROC Show_Rolodex_Info()
  PRIVATE Owner_Id, Form_No, Image_No, Msg_Str
    if (TABLE() = "Files_r") OR (TABLE() = "Files_rx")then
      Owner_Id = [Rolodex_Id]
      Msg_Str = "Related Party Details - Press ESC to return to file cabinet."
      else if (TABLE() = M_Tbl) AND (FIELD() = "Opposing") then
             Owner_Id = [Opposing]
             Msg_Str = "Opposing Party Details - Press ESC to return to file cabinet."
             else Owner_Id = ""
           endif
    endif
    Image_No = IMAGENO()
    MOVETO M_Tbl
    Form_No = FORM()
    if (Owner_Id = "") then
      Owner_Id = [Id]
      Msg_Str = "File Owner Details - Press ESC to return to file cabinet."
    endif
    ECHO OFF
    FORMKEY
    VIEW "ROLODEX"
    WINDOW MOVE GETWINDOW() TO -100, -100 ; move rolodex table off screen
    TAB
    LOCATE Owner_Id
    if RetVal then
      SHOWPULLDOWN
      ENDMENU     ; hide main menu
      PICKFORM "4"
      ECHO NORMAL
      MESSAGE Msg_Str
      WAIT WORKSPACE
      UNTIL "ESC"
      ECHO OFF
      Main_Table_Menu()
      else MESSAGE "No matching rolodex entry found!"
    ENDIF
    CLEARIMAGE; remove rolodex image
    MOVETO M_Tbl
    PICKFORM Form_No
    MOVETO Image_No
    ECHO NORMAL  
  ENDPROC; Show_Rolodex_Info

  PROC If_Status_Send_Or_Hold(Stat)
    PRIVATE Tmp_Tbl, Q_St, N, I
    {Ask} {Filestat} TAB CHECK TAB TAB
    if (Stat = "SEND") then
      TYPEIN "\"YES\""
      else TYPEIN "\"NO\""
    endif  
    DO_IT! 
    Tmp_Tbl = TABLE()  
    MOVETO "Filestat(Q)"
    CLEARIMAGE     ; erase query image
    MOVETO Tmp_Tbl
    N = NRECORDS(Tmp_Tbl)
    if (N = 0) then
      CLEARIMAGE
      RETURN Stat
    endif
    TAB
    Q_St = []
    FOR I FROM 1 TO N-1
      DOWN
      Q_St = Q_St + " OR " + []
    ENDFOR
    CLEARIMAGE
    RETURN Q_St
  ENDPROC;  If_Status_Send_Or_Hold

  PROC Ask_File_Cabinet(F_Num)
    PRIVATE Subset_Table, Temp_Status, Button, I, Form_List
    FORMKEY
    SHOWPULLDOWN
    ENDMENU
    CLEARSPEEDBAR
    PROMPT "Enter selection criteria.  Press Search to find matches, Cancel to quit."
    MOUSE SHOW
    SHOWDIALOG "File Cabinet Selection Criteria"
      @6, 3 HEIGHT 15 WIDTH 74
      @1, 2 ?? "File No."
        ACCEPT @1,14
        WIDTH 20 "A45" PICTURE "*!"
        TAG ""
        TO   File_No
      @2, 2 ?? "Owner ID"
        ACCEPT @2,14
        WIDTH 20 "A45" PICTURE "*!"
        TAG ""
        TO   Id
      @3, 2 ?? "Area of Law"
        ACCEPT @3,14
        WIDTH 20 "A45" PICTURE "*!"
        TAG ""
        TO   File_Type
      @4, 2 ?? "Regarding"
        ACCEPT @4,14
        WIDTH 20 "A45"
        TAG ""
        TO   Regarding
      @5, 2 ?? "Opened"
        ACCEPT @5,14
        WIDTH 20 "A45" PICTURE "*!"
        TAG ""
        TO   Opened
      @6, 2 ?? "Closed"
        ACCEPT @6,14
        WIDTH 20 "A45" PICTURE "*!"
        TAG ""
        TO   Closed
      @7, 2 ?? "Status"
        ACCEPT @7,14
        WIDTH 20 "A45" PICTURE "*!"
        TAG ""
        TO   Status
      @8, 2 ?? "Employee"
        ACCEPT @8,14
        WIDTH 20 "A45" PICTURE "*!"
        TAG ""
        TO   Empl_Num
      @1, 40 ?? "**** Account Balances ****"
      @2, 38 ?? "Trust"
        ACCEPT @2,48
        WIDTH 20 "A35" 
        TAG ""
        TO   Trust_Bal
      @3, 38 ?? "Charges"
        ACCEPT @3,48
        WIDTH 20 "A35" 
        TAG ""
        TO   Total_Charges
      @4, 38 ?? "Owing"
        ACCEPT @4,48
        WIDTH 20 "A35" 
        TAG ""
        TO   Amount_Owing
      @5, 38 ?? "Transfer"
        ACCEPT @5,48
        WIDTH 20 "A35" 
        TAG ""
        TO   Transferable
      @12, 7 ?? "STATUS: SEND = Print set to YES, HOLD = Print set to NO"
      PUSHBUTTON @10,24 WIDTH 10
        "~S~earch"
        OK
        DEFAULT
        VALUE ""
        TAG "OK"
        TO Button
      PUSHBUTTON @10,37 WIDTH 10
        "~C~ancel"
        CANCEL
        VALUE ""
        TAG "Cancel"
        TO Button
    ENDDIALOG
    PROMPT ""
    MOUSE HIDE
    if (RetVal = True) then
      MESSAGE "Searching..."
      ECHO OFF      
      if (Status = "SEND") OR (Status = "HOLD") then
        Temp_Status = If_Status_Send_Or_Hold(Status)
        else Temp_Status = Status
      endif
      {Ask} TYPEIN M_Tbl ENTER CheckPlus
      [File_No]        = File_No
      [Id]             = Id
      [File_Type]      = File_Type
      [Regarding]      = Regarding
      [Opened]         = Opened
      [Closed]         = Closed
      [Status]         = Temp_Status
      [Empl_Num]       = Empl_Num
      [Trust_Bal]      = Trust_Bal
      [Total_Charges]  = Total_Charges
      [Amount_Owing]   = Amount_Owing
      [Transferable]   = Transferable
      DO_IT!
      ; if error in query form, abort selection process
      if (TABLE() <> "Answer") then
        ; erase query image(s)
        WHILE (IMAGETYPE() = "Query")
          CLEARIMAGE
        ENDWHILE
        MESSAGE "Invalid selection criteria.  Query unsuccessful."
        PICKFORM F_Num
        RETURN
      endif
      Subset_Table = PRIVDIR() + "SUBSET"
      RENAME TABLE() Subset_Table
      MOVETO (M_Tbl + "(Q)")
      CLEARIMAGE     ; erase query image
      MOVETO Subset_Table
      if ISEMPTY(Subset_Table) then
        CLEARIMAGE
        No_Matches_Found()
        else ; copy form and display on screen
               COPYFORM    M_Tbl  F_Num Subset_Table "1"
               COPYREPORT "Files" "1" Subset_Table "1"  ; detailed file info
               COPYREPORT "Files" "2" Subset_Table "2"  ; summary file info             
               COPYREPORT "Files" "3" Subset_Table "3"  ; detailed account summary
               COPYREPORT "Files" "4" Subset_Table "4"  ; short account summary
               View_Answer_Table(Subset_Table, 1, 0)
               FORMTABLES Subset_Table "1" Form_List
               FOR I FROM 1 to ARRAYSIZE(Form_List)
                 MOVETO Form_List[I]
                 IMAGERIGHTS READONLY ; make all detail records uneditable
               ENDFOR
               MOVETO Subset_Table
               File_Cabinet_Answer_Wait()
               if ISTABLE(Subset_Table) then  ; delete subset table
                 ECHO OFF
                 DELETE(Subset_Table)
               endif
      endif
    endif
    PICKFORM F_Num
  ENDPROC;  Ask_File_Cabinet

  PROC Locate_Record()
    PRIVATE Search_St, Choice, Fld_Name
    Choice = 2
    SHOWDIALOG "Locate Record"
      @7, 14 HEIGHT 11 WIDTH 48
      @2,2 ?? "Search field:"
      RADIOBUTTONS @1,18 HEIGHT 3 WIDTH 20
        "File Number",
        "File Owner",
        "Regarding"
        TAG "Button_Tag"
        TO Choice
      @5,2 ?? "Search pattern:"
      ACCEPT @5,18
        WIDTH 25 "A35"
        TAG "Search_St"
        TO   Search_St
      PUSHBUTTON @7,13 WIDTH 10
        "~S~earch"
        OK
        DEFAULT
        VALUE ""
        TAG "OK"
        TO Button
      PUSHBUTTON @7,26 WIDTH 10
        "~C~ancel"
        CANCEL
        VALUE ""
        TAG "Cancel"
        TO Button
    ENDDIALOG    
    if (RetVal = True) And (Search_St <> "") then
      SWITCH
        CASE (Choice = 1) : Fld_Name = "File_No"
        CASE (Choice = 2) : Fld_Name = "Id"
        CASE (Choice = 3) : Fld_Name = "Regarding"
        OTHERWISE         : RETURN
      ENDSWITCH
      MESSAGE "Searching..."
      MOVETO M_Tbl
      MOVETO FIELD Fld_Name
      LOCATE INDEXORDER PATTERN Search_St
      if (RetVal = True) then
        MESSAGE ""
        WHILE (RetVal = True)
          SHOWPOPUP "Continue Search?" @17,63
            "Next" : "Search for next match" : "Next",
            "Quit" : "Terminate search"      : "Quit"
          ENDMENU  
          TO Choice
          if (Choice = "Next") then
            MESSAGE "Searching..."
            ECHO OFF
            CTRLPGDN
            LOCATE INDEXORDER NEXT PATTERN Search_St
            MESSAGE ""
            if (RetVal = False) then
              CTRLPGUP
              BEEP
              MESSAGE "No more matches found."
            endif
            ECHO NORMAL
            else QUITLOOP     
          endif
        ENDWHILE
        else BEEP
             MESSAGE "No matches found."
      endif; initial match was found  
    endif; search requested
  ENDPROC; Locate_Record

  PROC Close_Account()
    ; must be files table & in coedit mode
    PRIVATE Temp_Amount, Temp_Empl
    ECHO OFF
    [Closed]    = TODAY()
    [Status]    = "INACTIVE"
    Temp_Amount = [Amount_Owing]
    Temp_Empl   = [Empl_Num]
    if (Temp_Amount > 0) then
      MOVETO D_Tbl ; move to detail table (ledger)
      END
      if NOT RECORDSTATUS("New") then
        DOWN ; move to new blank record
      endif
      [Date]       = TODAY()
      [Item_No]    = 1
      [Empl_Num]   = Temp_Empl
      [T_Code]     = "PMT"
      [T_Type]     = "5"
      [T_Type_L]   = "C"
      [Amount]     = Temp_Amount
      [Billed]     = "Y"    
      WHILE TRUE   ;   must post record
        POSTRECORD NOPOST LEAVELOCKED
        if RetVal then
          QUITLOOP
          else [Item_No] = [Item_No] + 1
        endif
      ENDWHILE
    endif
    if (Temp_Amount > 0) then
      Tally_Ledger()
    endif  
    REFRESH
    MESSAGE "Account has been closed."
  ENDPROC;  Close_Account

  PROC Reopen_Account()
    ; must be in coedit mode
    ECHO OFF
    MOVETO M_Tbl ; move to master table (files)
    [Closed]     = BLANKDATE()
    [Status]     = "FOLLOW UP"
    REFRESH
    MESSAGE "Account has been reopened."
  ENDPROC;  Reopen_Account

  PROC Update_Billed_Status()
    PRIVATE Old_FN, F_Nos, I, Add_Tbl
    DYNARRAY F_Nos[]
    if Response_Is_Yes("Change Transaction Status", "Change all transactions to BILLED - YES status?") then
      MESSAGE "Changing transactions to BILLED - YES status.  One moment please..."
      ; make answer table match ledger table structure, change billed to yes
      ECHO OFF
      {Ask} TYPEIN Answer_Tbl ENTER
      CHECKPLUS TAB TAB CHECKPLUS TAB CHECKPLUS
      MOVETO FIELD "Billed"
      TYPEIN "N"
      DO_IT!
      Answer_Tbl = PRIVDIR() + TABLE()
      if ISEMPTY(Answer_Tbl) then
        MESSAGE ""
        CLEARIMAGE; remove answer table image
        RETURN
      endif
      I = 1
      TAB
      COEDITKEY
      SCAN 
        F_Nos[I] = [File_No]   ; get list of file numbers
        [Billed] = "Y"
        I = I + 1
      ENDSCAN
      DO_IT!
      CLEARIMAGE; remove answer table image
      ADD Answer_Tbl D_Tbl; Target = Ledger or Ledger_x table
      CLEARIMAGE; remove "changed" ledger table image
      CLEARIMAGE; erase target table image
      MESSAGE ""
      ;  update file account totals
      if (DYNARRAYSIZE(F_Nos) > 0) then  ; update accounts
        MOVETO M_Tbl
        PICKFORM "1"
        COEDITKEY
        Old_FN = ""
        FOREACH I IN F_Nos   ; array of files to be updated
          if (F_Nos[I] <> Old_FN) then
            Old_FN = F_Nos[I]
            MOVETO M_Tbl
            MOVETO FIELD "File_No"
            LOCATE F_Nos[I]
            if RetVal then     ; file number was found
              MOVETO D_Tbl     ; move to ledger table
              Tally_Ledger()   ; total accounts for this file
            endif
          endif  
        ENDFOREACH
        DO_IT! ; end edit
        FORMKEY
        Sound_Off()
        Message_Box("Updating File Account Balances", "All modified file accounts have been updated.")
      endif
      endif
  ENDPROC; Update_Billed_Status

  PROC Query_Ledger(S_Tbl, Billed, Rpt_No)
    PRIVATE All_Billed
    {Ask} TYPEIN S_Tbl ENTER 
    TAB CHECKPLUS EXAMPLE "LINK" TYPEIN "!" ; check file no field
    TAB CHECKPLUS                           ; check owner id field
    MOVETO FIELD "Footer_Code" CheckPlus
    {Ask} TYPEIN D_Tbl ENTER 
    CHECKPLUS TAB CHECKPLUS EXAMPLE "LINK"  ; check all fields except file no
    MOVETO FIELD "Billed" TYPEIN Billed
    DO_IT!
    Answer_Tbl = PRIVDIR() + TABLE()
    MOVETO FIELD "Billed"
    All_Billed = TRUE
    WHILE All_Billed
      if ([Billed] = "Y") OR ISBLANK([Billed]) then
        if ATLAST() then
          QUITLOOP
          else DOWN
        endif        
        else All_Billed = FALSE
      endif  
    ENDWHILE
    CLEARIMAGE                ; erase answer image
    MOVETO (D_Tbl + "(Q)")
    CLEARIMAGE                ; erase 1st query image
    MOVETO (S_Tbl + "(Q)")
    CLEARIMAGE                ; erase 2nd query image
    if ISEMPTY(Answer_Tbl) then
      No_Matches_Found()
      else COPYREPORT "Trnsactn" Rpt_No Answer_Tbl "1"
           Print_Report(Answer_Tbl, "1", Rpt_St["Statements"])
           if (Billed <> "Y") AND NOT All_Billed then
             Update_Billed_Status()
           endif
    endif
  ENDPROC;  Query_Ledger

  PROC Credit_History()
    {Ask} TYPEIN Subset_Table ENTER 
    TAB CHECKPLUS EXAMPLE "LINK" TYPEIN "!" ; check file no field
    TAB CHECKPLUS                           ; check owner id field
    MOVETO FIELD "Footer_Code" CHECKPLUS
    {Ask} TYPEIN D_Tbl ENTER 
    CHECKPLUS TAB CHECKPLUS EXAMPLE "LINK"  ; check all fields except file no
    MOVETO FIELD "T_Type_L" TYPEIN "C"      ; include only credit transactions
    DO_IT!
    Answer_Tbl = PRIVDIR() + TABLE()
    CLEARIMAGE                ; erase answer image
    MOVETO (Subset_Table + "(Q)")
    CLEARIMAGE                ; erase 1st query image
    MOVETO (D_Tbl + "(Q)")
    CLEARIMAGE                ; erase 2nd query image
    if ISEMPTY(Answer_Tbl) then
      No_Matches_Found()
      else COPYREPORT "Trnsactn" "7" Answer_Tbl "1"
           Print_Report(Answer_Tbl, "1", "")
    endif
  ENDPROC;  Credit_History

  PROC File_Cabinet_Answer_Menu()
    SHOWPULLDOWN
      "Modify"    : "Toggle between edit and main mode"               : "Modify"
        SUBMENU
          "Edit Mode - F9" : "Allow data to be edited, deleted, etc." : "Edit\Mode",
          "Main Mode - F2" : "Discontinue editing"                    : "Main\Mode"
        ENDSUBMENU,
      "Reports"          : "Choose report to generate"               : "Reports"
        SUBMENU
          "Envelope"     : "Create an envelope"                      : "R_Envelope",
          "Phone Book"   : "Generate list of phone numbers & addresses" : ""
            SUBMENU
              "Address & Phone #" : "List address & phone numbers"    : "R_Phone_Address",
              "Phone # Only"      : "List only names & phone numbers" : "R_Phone"
            ENDSUBMENU,
          "Rolodex Info" : "All info in rolodex"                     : "R_Rolodex",
          "File Cabinet Info" : "Show file cabinet data by file owner"  : ""
            SUBMENU
              "Detailed"     : "All data for files, with account balances" : "R_File_Detail",
              "Short Form"   : "Summarize file data and account balances"  : "R_File_Short"
            ENDSUBMENU,
          "Account Balances" : "Summarize accounts in file cabinet by employee and file status" : ""
            SUBMENU
              "Detailed"               : "Show balances by billed & unbilled amounts"        : "R_Account_Detail",
              "Short Form"             : "Summarize amount owing & amount to transfer"       : "R_Account_Short"
            ENDSUBMENU,
          "Statements"   : "Statement of billable services"          : ""
            SUBMENU
              "All Transactions"  : "Include all transactions for file"          : ""
                SUBMENU
                  "Total Hours"   : "Include only total for all hourly transactions" : "R_Statements_All",
                  "Itemize Hours" : "Itemize hours for each hourly transaction"      : "R_Statements_All_I"
                ENDSUBMENU,
              "Billed Previously" : "Select only previously billed transactions" : ""
                SUBMENU
                  "Total Hours"   : "Include only total for all hourly transactions" : "R_Statements_Billed",
                  "Itemize Hours" : "Itemize hours for each hourly transaction"      : "R_Statements_Billed_I"
                ENDSUBMENU,
              "Unbilled Only "    : "Select only unbilled transactions"          : ""
                SUBMENU
                  "Total Hours"   : "Include only total for all hourly transactions" : "R_Statements_Unbilled",
                  "Itemize Hours" : "Itemize hours for each hourly transaction"      : "R_Statements_Unbilled_I"
                ENDSUBMENU
            ENDSUBMENU,
          "Credit/Payment History" : "Report on credit/payment history for each account" : "R_Credit_History"
        ENDSUBMENU,
      "Assemble"         : "Combine data and forms into documents"   : "Assemble",
      "Quit"         : "Return to previous menu"     : ""
        SUBMENU
          "No      " : "Continue working with selected data"  : "Return\No",
          "Yes - F8" : "Return to complete data set"          : "Return\Yes"
        ENDSUBMENU
    ENDMENU    
    if (SYSMODE() = "Main") then
      MENUDISABLE  "Main\Mode"
      else MENUDISABLE "Edit\Mode"
           MENUDISABLE "Assemble"
           MENUDISABLE "Reports"
    endif
    File_Cabinet_Speedbar()
  ENDPROC;  File_Cabinet_Answer_Menu

  PROC File_Cabinet_Answer_Wait_Proc(TriggerType, EventInfo, CycleNumber)
    PRIVATE Answer_Tbl, Menu_Tag, Return_Code
    if (TriggerType = "ARRIVEFIELD") then
      PROMPT Fld_Prompt[FIELD()]
      RETURN 1
    endif
    if (EventInfo["TYPE"]    = "MESSAGE")        AND 
       (EventInfo["MESSAGE"] = "MENUSELECT")     AND
       (SUBSTR(EventInfo["MENUTAG"],1,2) = "R_") then       
       Menu_Tag = EventInfo["MENUTAG"]
       SHOWPULLDOWN
       ENDMENU
       CLEARSPEEDBAR
       MESSAGE "One moment please..."
       ECHO OFF
       SWITCH
         ; ***** envelope *****
         CASE (Menu_Tag = "R_Envelope") :
           MESSAGE ""
           Return_Code = Yes_No_Cancel("Duplicate Envelope Removal", "Print only one envelope per file owner?")
           if (Return_Code = "Yes") then
             {Ask} {Rolodex} CHECK TAB EXAMPLE "LINK"
             else if (Return_Code = "No") then
                    {Ask} {Rolodex} CHECKPLUS TAB EXAMPLE "LINK"
                    else FORMKEY
                  endif
           endif
           if (Return_Code <> "Cancel") then
             MESSAGE "One moment please..."
             {Ask} TYPEIN Subset_Table ENTER 
             MOVETO FIELD "Id" EXAMPLE "LINK"
             DO_IT!
             Answer_Tbl = PRIVDIR() + TABLE()
             SORT Answer_Tbl ON "Id"
             CLEARIMAGE                ; erase answer image
             MOVETO "Rolodex(Q)"
             CLEARIMAGE                ; erase 1st query image
             MOVETO (Subset_Table + "(Q)")
             CLEARIMAGE                ; erase 2nd query image
             if ISEMPTY(Answer_Tbl) then
               No_Matches_Found()
               else COPYREPORT "Rolodex" "1" Answer_Tbl "R"
                    Print_Report(Answer_Tbl, "R", Rpt_St["Envelope"])
             endif       
           endif  
         ; ***** rolodex address & phone information *****
         CASE (Menu_Tag = "R_Phone_Address") OR (Menu_Tag = "R_Phone") OR (Menu_Tag = "R_Rolodex") :
           {Ask} TYPEIN Subset_Table ENTER 
           TAB TAB CHECK EXAMPLE "LINK" TYPEIN "!"
           {Ask} {Phone} CHECK TAB CHECK EXAMPLE "LINK"
           DO_IT!
           Answer_Tbl = PRIVDIR() + TABLE()
           CLEARIMAGE                ; erase answer image
           MOVETO "Phone(Q)"
           CLEARIMAGE                ; erase 1st query image
           MOVETO (Subset_Table + "(Q)")
           CLEARIMAGE                ; erase 2nd query image
           if ISEMPTY(Answer_Tbl) then
             No_Matches_Found()
             else if (Menu_Tag = "R_Phone") then
                    COPYREPORT "Phone" "1" Answer_Tbl "R"
                    Print_Report(Answer_Tbl, "R", Rpt_St["Phone_Book"])
                    else if (Menu_Tag = "R_Phone_Address") then
                           COPYREPORT "Phone" "2" Answer_Tbl "R"
                           Print_Report(Answer_Tbl, "R", Rpt_St["Phone_Book"])
                           else COPYREPORT "Phone" "3" Answer_Tbl "R"
                                Print_Report(Answer_Tbl, "R", Rpt_St["Rolodex_Info"])
                         endif       
                  endif       
           endif
         ; ***** detailed file cabinet information *****
         CASE (Menu_Tag = "R_File_Detail"):
           FORMKEY
           Print_Report(Subset_Table, "1", Rpt_St["File_Cabinet"])
         ; ***** summarized file cabinet information *****
         CASE (Menu_Tag = "R_File_Short"):
           FORMKEY
           Print_Report(Subset_Table, "2", Rpt_St["File_Cabinet"])
         ; ***** detailed accounts receivable information *****
         CASE (Menu_Tag = "R_Account_Detail") :
           FORMKEY
           Print_Report(Subset_Table, "3", Rpt_St["Accounts"])
         ; ***** summarized accounts receivable information *****
         CASE (Menu_Tag = "R_Account_Short") :
           FORMKEY
           Print_Report(Subset_Table, "4", Rpt_St["Accounts"])
         ; ***** statement, unbilled transactions only *****
         CASE (Menu_Tag = "R_Statements_Unbilled")  :
           Query_Ledger(Subset_Table, "N", "1")
         ; ***** statement, unbilled transactions only, itemized *****
         CASE (Menu_Tag = "R_Statements_Unbilled_I")  :
           Query_Ledger(Subset_Table, "N", "2") 
         ; ***** statement, billed & unbilled *****
         CASE (Menu_Tag = "R_Statements_All")  :
           Query_Ledger(Subset_Table, "", "3")
         ; ***** statement, billed & unbilled, itemized *****
         CASE (Menu_Tag = "R_Statements_All_I")  :
           Query_Ledger(Subset_Table, "", "4")
         ; ***** statement, previously billed transactions only *****
         CASE (Menu_Tag = "R_Statements_Billed")  :
           Query_Ledger(Subset_Table, "Y", "5")
         ; ***** statement, previously billed transactions only *****
         CASE (Menu_Tag = "R_Statements_Billed_I")  :
           Query_Ledger(Subset_Table, "Y", "6")
         ; ***** last credit to account *****
         CASE (Menu_Tag = "R_Credit_History")  :
           Credit_History()
       ENDSWITCH
       MOVETO Subset_Table
       FORMKEY
       ECHO NORMAL
       EXECPROC "File_Cabinet_Answer_Menu"
       RETURN 1
       else Return_Code = Answer_Table_Wait_Proc(TriggerType, EventInfo, CycleNumber)
            if (SYSMODE() = "Main") then
              MENUENABLE  "Assemble"
              else MENUDISABLE "Assemble"
            endif
            RETURN Return_Code
    endif
  ENDPROC;  File_Cabinet_Answer_Wait_Proc

  PROC File_Cabinet_Answer_Wait()  
    File_Cabinet_Answer_Menu()
    Sound_Off()
    ECHO NORMAL
    Message_Box("Search Completed", "Matching File Cabinet Entries: " + STRVAL(NRECORDS(Subset_Table)))
    WAIT WORKSPACE
      PROC    "File_Cabinet_Answer_Wait_Proc"
      MESSAGE "MENUSELECT"
      TRIGGER "ARRIVEFIELD"
      KEY   -60,   -66,   -67,  -83,   -50,   -48,     43,  45
           ; DO_IT  Clear  Edit  Delete Alt-M  Alt-B    +    -
           ; F2     F8     F9    DEL    Memo   Summarize Balances
    ENDWAIT
    CLEARSPEEDBAR
    MESSAGE ""
  ENDPROC;  File_Cabinet_Answer_Wait

  PROC Summarize_Accounts(Tbl, I_No)
    ; pops up window with summary of billed, unbilled & total accounts
    PRIVATE Button_Val
    MOVETO Tbl
    SHOWDIALOG "Account Balances - File No: " + [File_No]
      @3,8 HEIGHT 18 WIDTH 63
      @1, 17 ?? "  Billed       Not Billed        Total"
      @2, 17 ?? "==========     ==========      ========="
      @3, 2 ?? "Trust Acnt. "+FORMAT("W13.2,E$C,AR", [Trust_Bal_P])    +FORMAT("W15.2,E$C,AR", [Trust_Bal]-[Trust_Bal_P])        +FORMAT("W15.2,E$C,AR", [Trust_Bal])
      @4, 2 ?? "Hours       "+FORMAT("W13.2,EC,AR",  [Hours_P])        +FORMAT("W15.2,EC,AR",  [Hours]-[Hours_P])                +FORMAT("W15.2,EC,AR",  [Hours])
      @6, 2 ?? "Hourly Fees "+FORMAT("W13.2,EC,AR",  [Hourly_Fees_P])  +FORMAT("W15.2,EC,AR",  [Hourly_Fees]-[Hourly_Fees_P])    +FORMAT("W15.2,EC,AR",  [Hourly_Fees])
      @7, 2 ?? "Flat Fees   "+FORMAT("W13.2,EC,AR",  [Flat_Fees_P])    +FORMAT("W15.2,EC,AR",  [Flat_Fees]-[Flat_Fees_P])        +FORMAT("W15.2,EC,AR",  [Flat_Fees])
      @8, 2 ?? "Disburse.   "+FORMAT("W13.2,EC,AR",  [Disbursements_P])+FORMAT("W15.2,EC,AR",  [Disbursements]-[Disbursements_P])+FORMAT("W15.2,EC,AR",  [Disbursements])
      @9, 2 ?? "Tot. Charges"+FORMAT("W13.2,EC,AR",  [Total_Charges_P])+FORMAT("W15.2,EC,AR",  [Total_Charges]-[Total_Charges_P])+FORMAT("W15.2,EC,AR",  [Total_Charges])
      @10,2 ?? "Credits     "+FORMAT("W13.2,EC,AR",  [Credit_Bal_P])   +FORMAT("W15.2,EC,AR",  [Credit_Bal]-[Credit_Bal_P])      +FORMAT("W15.2,EC,AR",  [Credit_Bal])
      @11,17 ?? "==========     ==========      ========="
      @12,2 ?? "Balance Due "+FORMAT("W13.2,E$C,AR", [Amount_Owing_P]) +FORMAT("W15.2,E$C,AR", [Amount_Owing]-[Amount_Owing_P])  +FORMAT("W15.2,E$C,AR", [Amount_Owing])
      @14,32  ?? "Transferable: "+FORMAT("W11.2,E$C,AR", [Transferable])
      PUSHBUTTON @14,10 WIDTH 12
        "~O~K"
        OK
        VALUE "OK"
        TAG "OK_Button"
      TO Button_Val
    ENDDIALOG      
    MOVETO I_No
    if (SYSMODE() = "CoEdit") then
      REFRESH
    endif  
  ENDPROC;  Summarize_Accounts

  PROC Depart_Cabinet_Row()
    PRIVATE In_Form
    if (SYSMODE() <> "CoEdit") OR FORMTYPE("Detail") then
      RETURN TRUE
    endif
    if NOT ISVALID() then
      Message_Box("Invalid Field Entry", "The data for this field is invalid.")
      RETURN FALSE
    endif  
    ; depart row if record is new & blank
    if RECORDSTATUS("New") AND NOT RECORDSTATUS("Modified") then
      RETURN TRUE
    endif
    if ISBLANK([File_No]) then
      MOVETO [File_No]
      Message_Box("Incomplete Entry", "This file requires a file number.")
      RETURN FALSE
    endif
    if ISBLANK([Id]) then
      MOVETO [Id]
      Message_Box("Incomplete Entry", "This file requires a file owner ID.")
      RETURN FALSE
    endif
    if ISBLANK([Empl_Num]) then
      MOVETO [Empl_Num]
      Message_Box("Incomplete Entry", "This file requires an employee number.")
      RETURN FALSE
    endif
    if ISBLANK([File_Type]) then
      MOVETO [File_Type]
      Message_Box("Incomplete Entry", "This file requires an law area designation.")
      RETURN FALSE
    endif
    if ISBLANK([Opened]) then
      MOVETO [Opened]
      Message_Box("Incomplete Entry", "This file requires a date of opening.")
      RETURN FALSE
    endif
    if ISBLANK([Status]) then
      MOVETO [Status]
      Message_Box("Incomplete Entry", "This file requires a status designation.")
      RETURN FALSE
    endif
    if ISBLANK([Rate_Per_Hour]) then
      MOVETO [Rate_Per_Hour]
      Message_Box("Incomplete Entry", "This file requires an hourly billing rate.")
      RETURN FALSE
    endif
    if RECORDSTATUS("New") then
      [Trust_Bal]     = 0
      [Hours]         = 0
      [Hourly_Fees]   = 0 
      [Flat_Fees]     = 0 
      [Disbursements] = 0
      [Total_Charges] = 0
      [Credit_Bal]    = 0
      [Amount_Owing]  = 0 
      [Transferable]  = 0
    endif
    RETURN TRUE
  ENDPROC; Depart_Cabinet_Row
  
  PROC File_Cabinet_Wait_Proc(TriggerType, EventInfo, CycleNumber)
    PRIVATE Key_Code, Menu_Pick, Form_Num
    if (TriggerType = "ARRIVEFIELD") then
      File_Cabinet_Speedbar()
      RETURN 0
    endif
    if (TriggerType = "DEPARTROW") then
      if Depart_Cabinet_Row() then
        RETURN 0
      endif
      RETURN 1
    endif
    if (TriggerType = "ARRIVETABLE") then
      File_Cabinet_Speedbar()
      if (SYSMODE() = "CoEdit") AND (TABLE() = D_Tbl) then
        Ledger_Table_Wait(TRUE, Employee, Hourly_Rate)
        File_Cabinet_Speedbar()
        RETURN 1
      endif  
      RETURN 0
    endif
    if (TriggerType = "DEPARTTABLE") then
      if (TABLE() = M_Tbl) then        
        Hourly_Rate = [Rate_Per_Hour]
        Employee    = [Empl_Num]
      endif  
      RETURN 0
    endif
    if (EventInfo["TYPE"] = "KEY") then  
      Key_Code = EventInfo["KEYCODE"]
      SWITCH
        ; F9 - COEDIT
        CASE (Key_Code = -67) : Main_Table_Edit()
                                if (TABLE() = D_Tbl) then
                                  Ledger_Table_Wait(FALSE, Employee, Hourly_Rate)
                                  if (IMAGENO() > 0) then
                                    File_Cabinet_Speedbar()
                                  endif  
                                endif  
                                RETURN 1
        ; F2 - DO_IT!
        CASE (Key_Code = -60) : if Depart_Cabinet_Row() then
                                  if ISEMPTY(Main_Table) then
                                    RETURN Main_Table_Clear()
                                    else RETURN Main_Table_End_Edit()
                                  endif
                                  else RETURN 1
                                endif
        ; F8 - CLEAR
        CASE (Key_Code = -66) : if Depart_Cabinet_Row() then
                                  RETURN Main_Table_Clear()
                                  else RETURN 1  
                                endif  
        ; DELETE
        CASE (Key_Code = -83) : if (SYSMODE() = "CoEdit") then
                                  if ISFIELDVIEW() then
                                    RETURN 0
                                  endif  
;                                  if (TABLE() = M_Tbl) then                           
;                                    GETRECORD "Timecard" [File_No] TO DYNARRAY A
;                                    if RetVal then
;                                      Message_Box("Timecard Entries Are Outstanding", "Cannot delete if timecard contains related entries!")
;                                      RETURN 1
;                                    endif
;                                  endif
                                  RETURN Display_Delete_Box()
                                endif  
                                RETURN 1
        ; Alt-M - Memo
        CASE (Key_Code = -50) : Display_Memo(Main_Table)
                                Main_Table_Menu()
                                File_Cabinet_Speedbar()
                                RETURN 1
        ; Alt-C  Close Account
        CASE (Key_Code = -46) : if (FORM() = "1") OR (FORM() = "2") then
                                  if (SYSMODE() = "Main") then
                                    COEDITKEY
                                  endif  
                                  Close_Account()
                                endif
                                RETURN 1
        ; Alt-R  Reopen Account
        CASE (Key_Code = -19) : Main_Table_Edit()
                                if (SYSMODE() = "CoEdit") then
                                  Reopen_Account()
                                endif
                                RETURN 1
        ; ALT-B - Summarize account balances
        CASE (Key_Code = -48) :  Summarize_Accounts(M_Tbl, IMAGENO())
                                 RETURN 1
        ; ALT-L - Locate Record
        CASE (Key_Code = -38) :  Locate_Record()
                                 RETURN 1
        ; ALT-I - Inquire about Rolodex
        CASE (Key_Code = -23) :  if (SYSMODE() = "Main")then
                                   Show_Rolodex_Info()
                                 endif  
                                 RETURN 1
        ; ALT-T - Start or stop time keeper
        CASE (Key_Code = -20) : if Timing then
                                  Stop_Ticker()
                                  else Start_Ticker()
                                endif  
                                RETURN 1
        ; ALT-F - Switch form
        CASE (Key_Code = -33) :  if (SYSMODE() = "Main") then
                                   ECHO OFF
                                   MOVETO M_Tbl
                                   Form_Num = NUMVAL(FORM()) + 1
                                   if (Form_Num > 2) then
                                     Form_Num = 1
                                   endif  
                                   PICKFORM Form_Num
                                   ECHO NORMAL
                                 endif  
                                 RETURN 1
        ; + or - to change current date
        CASE (Key_Code = 43) OR (Key_Code = 45) : 
          RETURN Change_Date(Key_Code)
        OTHERWISE            : SOUND 400 100 RETURN 1             
      ENDSWITCH
    endif
    if (EventInfo["MESSAGE"] = "MENUSELECT") then 
      Menu_Pick = EventInfo["MENUTAG"]
      SWITCH
        CASE (Menu_Pick = "Edit\Mode")  : Main_Table_Edit()
                                          if (TABLE() = D_Tbl) then
                                            Ledger_Table_Wait(FALSE, Employee, Hourly_Rate)
                                            if (IMAGENO() > 0) then
                                              File_Cabinet_Speedbar()
                                            endif
                                          endif  
                                          RETURN 1
        CASE (Menu_Pick = "Main\Mode")  : if Depart_Cabinet_Row() then
                                            if ISEMPTY(M_Tbl) then
                                              RETURN Main_Table_Clear()
                                              else RETURN Main_Table_End_Edit()
                                            endif
                                            else RETURN 1
                                          endif
        CASE (Menu_Pick = "Ask")        : MOVETO M_Tbl
                                          if ISBLANK([File_No]) then
                                            File_No = ""
                                            else File_No = [File_No]
                                          endif  
                                          if (M_Tbl = "Files") then
                                            Status = "SEND"  
                                            else Status = "HOLD"  
                                          endif
                                          Ask_File_Cabinet(NUMVAL(FORM()))
                                          Main_Table_Menu()
                                          File_Cabinet_Speedbar()
                                          RETURN 1
        CASE (Menu_Pick = "Close\Yes")  : if Depart_Cabinet_Row() then
                                            RETURN Main_Table_Clear()
                                            else RETURN 1  
                                          endif
        CASE (Menu_Pick = "Close\No")   : RETURN 1
        OTHERWISE                       : SOUND 400 100 RETURN 1
      ENDSWITCH
    endif
    SOUND 400 100 RETURN 1  ; safety valve, ignore all events not recognized
  ENDPROC; File_Cabinet_Wait_Proc

  PROC File_Cabinet_Speedbar()
    CLEARSPEEDBAR
    SPEEDBAR "~F10~ Menu":-68, "~Alt-M~ Memo":-50, "~Alt-B~ Balances":-48
    if ISASSIGNED(Fld_Prompt[FIELD()]) then
      PROMPT Fld_Prompt[FIELD()]
      else PROMPT ""
    endif  
  ENDPROC;  File_Cabinet_Speedbar

  ; MAIN PROCEDURE BEGINS HERE!
  ; initialize "ASK" dialog box variables not initialized with each ask
  Id         = ""  
  File_Type  = ""
  Regarding  = ""
  Opened     = ""
  Closed     = ""
  Empl_Num    = ""
  Trust_Bal  = ""
  Total_Charges = ""
  Amount_Owing  = ""
  Transferable  = ""

  Answer_Menu = "File_Cabinet_Answer_Menu"
  DYNARRAY Fld_Prompt[]
  Fld_Prompt["File_No"]       = "Unique file number"
  Fld_Prompt["Id"]            = "F1 to select file owner from rolodex"   
  Fld_Prompt["Regarding"]     = "Description of pertinent matter"
  Fld_Prompt["Empl_Num"]      = "F1 to assign atty. and default rate"
  Fld_Prompt["File_Type"]     = "F1 to select area of law"
  Fld_Prompt["Opened"]        = "Date this file was opened (##/##/##)"
  Fld_Prompt["Closed"]        = "Date this file closes (##/##/##)"
  Fld_Prompt["Status"]        = "F1 to select file status"
  Fld_Prompt["Footer_Code"]   = "F1 to select statement footer"
  Fld_Prompt["Opposing"]      = "F1 to select opposing atty from rolodex"   
  Fld_Prompt["Memo"]          = "Add or edit notes for this file"
  Fld_Prompt["Rate_Per_Hour"] = "Hourly billing rate"

  Fld_Prompt["Memo_Date"]     = "Enter Date of this memo entry"
  Fld_Prompt["Memo_Note"]     = "Enter Memo (up to 90 characters)"

  Fld_Prompt["Date"]          = "Date for this transaction, (##/##/##)"
  Fld_Prompt["T_Code"]        = "F1 to select trans. code & description"
  Fld_Prompt["Quantity"]      = "Number of billable units"
  Fld_Prompt["Rate"]          = "Dollar value per unit"
  Fld_Prompt["Amount"]        = "Dollar amount of ledger entry"
  Fld_Prompt["Billed"]        = "Has transaction been billed (Y/N)?"
  Fld_Prompt["Note"]          = "Note to append to trans. description"
  Fld_Prompt["A1"]            = "First line of address, or firm name"
  Fld_Prompt["Location"]      = "Location for this phone number"
  Fld_Prompt["Phone"]         = "Phone No.: ###-####, 1-###-###-####"
  Fld_Prompt["Relationship"]  = "Code for type of relationship"
  Fld_Prompt["Rolodex_Id"]    = "Select Id from Rolodex"
  Fld_Prompt["Identifier"]    = "Name of variable"
  Fld_Prompt["Response"]      = "Text to replace variable"
  if (M_Tbl = "Files") then
    Cabinet = "Open"
    else Cabinet = "Archived"
  endif  
  Main_Table_View(M_Tbl, 1, 0)
  END
  Timing = False
  File_Cabinet_Speedbar()
  ECHO NORMAL
  WAIT WORKSPACE
    PROC    "File_Cabinet_Wait_Proc"
    TRIGGER "ARRIVEFIELD", "ARRIVETABLE", "DEPARTROW", "DEPARTTABLE"
    MESSAGE "MENUSELECT"              
    KEY   -60,   -66,   -67,  -83, -50,   -46,   -19,   -48,    -38,   -23,    -33,   -20,   43, 45
         ; DO_IT  Clear  Edit  Del  Alt-M  Alt-C  Alt-R  Alt-B   Alt-L  Alt-I   Alt-F Alt-T
         ; F2     F8     F9    DEL  Memo   Close  Reopen Balnces Locate Inquire Form  Timer   +   -
  ENDWAIT
  CLEARSPEEDBAR
  PROMPT ""
  MESSAGE ""
ENDPROC
WRITELIB Off_Lib File_Cabinet_Wait

RELEASE PROCS ALL