separate (Tracker)

procedure Report_Generator is
    --------------------------------------------------------------------------------
    --|
    --|  NAME:  REPORT_GENERATOR
    --|
    --|  OVERVIEW:
    --|    This procedure controls the report menu and resolves the selections the
    --|    user makes, allowing the user to print any combination of reports.
    --|
    --|  EXCEPTIONS HANDLED:
    --|    end_error invalid user menu response
    --|    data_error    invalid user menu response
    --|
    --|  HISTORY:
    --|    written by   May Lee            February 1985
    --|    written by   Bonnie Burkhardt   March 1985
    --------------------------------------------------------------------------------

    use Vt100;

    Comments_File : File_Type;
    Comments_Filename : String (1 .. 80) := (others => ' ');

    type Orig_Or_Cur_Type is (Original, Current);
    type Ss_Ac_Array is array
                           (1 .. Num_Of_Subsystems, 1 .. Num_Of_Activities) of
                           Float range 0.0 .. 100.0;
    type Ss_Array is array (1 .. Num_Of_Subsystems) of Float range 0.0 .. 100.0;
    type Ac_Array is array (1 .. Num_Of_Activities) of Float range 0.0 .. 100.0;
    type Ms_Array is array (Ms_Num_Type) of Float range 0.0 .. 100.0;

    type Pct_Done_Type is
        record
            By_Ss_And_Ac : Ss_Ac_Array :=
               (1 .. Num_Of_Subsystems => (1 .. Num_Of_Activities => 0.0));
            By_Ss : Ss_Array := (others => 0.0);
            By_Ac : Ac_Array := (others => 0.0);
            By_Ms : Ms_Array := (others => 0.0);
            Start_By_Ss : Ss_Array := (others => 0.0);
            Start_By_Ac : Ac_Array := (others => 0.0);
            Entire_By_Ss : Ss_Array := (others => 0.0);
            Entire_By_Ac : Ac_Array := (others => 0.0);
            Contract : Float range 0.0 .. 100.0 := 0.0;
            Start : Float range 0.0 .. 100.0 := 0.0;
            Entire : Float range 0.0 .. 100.0 := 0.0;
        end record;

    Max_Data_Lines : constant Integer := 43;

    Exit_Report_Menu : Boolean := False;
    Current_Pct_Done : Pct_Done_Type;
    Original_Pct_Done : Pct_Done_Type;
    Menu_Selection : Integer := 0;
    A_Report_Printed : Boolean := False;

    procedure Calc_Pct_Done (Orig_Or_Cur : in Orig_Or_Cur_Type;
                             Pct_Done : in out Pct_Done_Type) is separate;
    procedure Start_Page (Title, Subtitle, Header1, Header2, Header_Lines : in
                             String := "") is separate;
    procedure Parameter_Data_List is separate;
    procedure Print_Comments is separate;
    procedure All_Elmnt_Status_Rep is separate;
    procedure List_By_Subsystem is separate;
    procedure List_By_Milestone is separate;
    procedure List_By_Person is separate;
    procedure Subsystem_Summary is separate;
    procedure Milestone_Summary is separate;
    procedure Work_Units_Per_Ss is separate;
    procedure Percent_Completion (Orig_Or_Cur : in Orig_Or_Cur_Type;
                                  Pct_Done : in Pct_Done_Type) is separate;
    procedure Distribution_Of_Work
                 (Orig_Or_Cur : in Orig_Or_Cur_Type) is separate;
    procedure Completion_Date_For_Ms is separate;
    procedure Reports_Printed_List is separate;

begin
    -- get report file name (input file with ".rpt" extension)

    -- start at end of filename look right to left for '.' indicating extension
    while Tracker_Filename (Filename_Lngth) /= '.' loop
        Filename_Lngth := Filename_Lngth - 1;
    end loop;

    -- filename up to extension including the '.'
    Report_Filename (1 .. Filename_Lngth) :=
       Tracker_Filename (1 .. Filename_Lngth);

    -- filename with ".rpt" extension
    Report_Filename (Filename_Lngth + 1 .. Filename_Lngth + 3) := "rpt";
    Filename_Lngth := Filename_Lngth + 3;

    Create (Report_File, Out_File, Report_Filename, "");
    Calc_Pct_Done (Original, Original_Pct_Done);
    Calc_Pct_Done (Current, Current_Pct_Done);

    while not Exit_Report_Menu loop
        Report_Case:
            begin
                Menu_Selection := Print_Report_Menu;

                case Menu_Selection is
                    when 1 =>
                        Vt100.Print_Report (1) := True;
                        Parameter_Data_List;
                    when 2 =>
                        Print_Comments;
                        Vt100.Print_Report (2) := True;
                    when 3 =>
                        Vt100.Print_Report (3) := True;
                        All_Elmnt_Status_Rep;
                    when 4 =>
                        Vt100.Print_Report (4) := True;
                        List_By_Subsystem;
                    when 5 =>
                        Vt100.Print_Report (5) := True;
                        List_By_Milestone;
                    when 6 =>
                        Vt100.Print_Report (6) := True;
                        List_By_Person;
                    when 7 =>
                        Vt100.Print_Report (7) := True;
                        Subsystem_Summary;
                    when 8 =>
                        Vt100.Print_Report (8) := True;
                        Milestone_Summary;
                    when 9 =>
                        Vt100.Print_Report (9) := True;
                        Work_Units_Per_Ss;
                    when 10 =>
                        Vt100.Print_Report (10) := True;
                        Percent_Completion (Original, Original_Pct_Done);
                        Percent_Completion (Current, Current_Pct_Done);
                    when 11 =>
                        Vt100.Print_Report (11) := True;
                        Distribution_Of_Work (Original);
                        Distribution_Of_Work (Current);
                    when 12 =>
                        Vt100.Print_Report (12) := True;
                        Completion_Date_For_Ms;
                    when 13 =>
                        -- print all reports and exit
                        Vt100.Print_Report := (others => True);
                        Parameter_Data_List;
                        Print_Comments;
                        Vt100.Clear_Screen;
                        New_Line (10);
                        Put_Line ("     Writing reports ... ");
                        All_Elmnt_Status_Rep;
                        List_By_Subsystem;
                        List_By_Milestone;
                        List_By_Person;
                        Subsystem_Summary;
                        Milestone_Summary;
                        Work_Units_Per_Ss;
                        Percent_Completion (Original, Original_Pct_Done);
                        Percent_Completion (Current, Current_Pct_Done);
                        Distribution_Of_Work (Original);
                        Distribution_Of_Work (Current);
                        Completion_Date_For_Ms;
                        Exit_Report_Menu := True;
                    when 14 =>
                        Exit_Report_Menu := True;
                        Clear_Screen;
                        Goodbye_Message;
                    when others =>
                        Put_Line ("Enter a number between 1 and 14. ");
                        delay (0.8);
                end case;

            exception
                when End_Error =>
                    New_Line;
                    New_Line;
                    Put_Line ("Enter a number between 1 and 14.");
                    delay (0.8);
                when Data_Error =>
                    New_Line;
                    New_Line;
                    Put_Line ("Enter a number between 1 and 14.");
                    delay (0.8);
                when Name_Error =>
                    null;
            end Report_Case;
    end loop;

    -- determine if any reports were written
    for I in 1 .. 12 loop
        A_Report_Printed := A_Report_Printed or Vt100.Print_Report (I);
    end loop;

    if A_Report_Printed then
        -- last report printed will always be a list of the reports generated
        Reports_Printed_List;
        Close (Report_File);
    else
        Delete (Report_File);
    end if;


end Report_Generator;