Program Finance;

Uses CRT;

{$I PressSpace.inc}

Var
  OPT:Char;
  QTF:Boolean;
  CSH,SUB:Real;
  DFS:Text;

Procedure ProgramTitle(TTL:String);
Begin
  ClrScr;
  WriteLn(#$9b,'0;1;4mFinance! v1.00 by Zebedee ©1997 A Carnage Production (06-Jan-97)',#$9b,'0m');
  WriteLn;
  IF Length(TTL)>0 Then WriteLn(#$9b,'3m',TTL,' ',#$9b,'0m',#$0a);
  IF TTL<>TTL Then Write('$VER: Finance! v1.00 (06-Jan-97) ');
End;

Procedure InitVars;
Begin
  CSH:=0;
End;

Function AreYouSure:Char;
Begin
  Write('Are you sure (Yy/Nn) ? ');
  Repeat
    OPT:=UpCase(ReadKey);
  Until OPT In ['Y','N'];
  AreYouSure:=OPT;
End;

Procedure ClearData;
Begin
  ProgramTitle('Clear Data');
  If AreYouSure='Y' Then CSH:=0;
End;

Procedure ViewBalance;
Begin
  ProgramTitle('View Current Balance');
  WriteLn('Current balance is £',CSH:0:2);
  PressSpace;
End;

Procedure Credit;
Begin
  ProgramTitle('Credit Balance');
  Write('Credit balance by: £');
  ReadLn(SUB);
  CSH:=CSH+SUB;
End;

Procedure Debit;
Begin
  ProgramTitle('Debit Balance');
  Write('Debit balance by: £');
  ReadLn(SUB);
  CSH:=CSH-SUB;
End;

Procedure SaveData;
Begin
  ProgramTitle('Save Balance To Disk');
  If AreYouSure='Y' Then Begin
    WriteLn('Yes',#$0a,#$0a,'Saving data...');
    GotoXY(15,7);
    ReWrite(DFS,'SYS:Finance!.dat');
    If IOResult<>0 Then WriteLn('error!',#$0a,#$0a,'Unable to create data file!') Else Begin
      WriteLn(DFS,CSH:4:2);
      Close(DFS);
      WriteLn('done');
    End;
  End Else WriteLn('No',#$0a,#$0a,'Save aborted.');
  PressSpace;
End;

Procedure LoadData;
Begin
  ProgramTitle('Load Balance From Disk');
  If AreYouSure='Y' Then Begin
    WriteLn('Yes',#$0a,#$0a,'Loading data...');
    GotoXY(16,7);
    Reset(DFS,'SYS:Finance!.dat');
    If IOResult<>0 Then WriteLn('error!',#$0a,#$0a,'Unable to open data file!') Else Begin
      ReadLn(DFS,CSH);
      Close(DFS);
      WriteLn('done');
    End;
  End Else WriteLn('No',#$0a,#$0a,'Load aborted.');
  PressSpace;
End;

Procedure ViewInfo;
Begin
  ProgramTitle('View Program Information');
  WriteLn('Finance!  was  written for Wayne Sandercock because some prize dick head had');
  WriteLn('unfortunately  erased  Mini  Office.   This  wasn''t  particularly  his fault');
  WriteLn('because of the state of the disks - my machine just didn''t like them!',#$0a);
  WriteLn('Anyway,  I''ve  decided  to  write  Finance! as an alternative to Mini Office');
  WriteLn('until I am able to obtain another copy; something I hope to do soon.',#$0a);
  WriteLn('Finance!  is quite easy to use.  Be careful when using option 1 to clear the');
  WriteLn('data  because  the  only  way  to  get  the  balance back again is either by');
  WriteLn('crediting  the balance by the correct amount, or, as long as the data hasn''t');
  WriteLn('been saved, by loading it back from the disk.');
  PressSpace;
End;

Procedure ViewCredits;
Begin
  ProgramTitle('View Program Credits');
  WriteLn('Program : Finance!');
  WriteLn('Version : 1.00');
  WriteLn('Author  : Zebedee/Carnage');
  WriteLn('Date    : 6 January 1997');
  WriteLn('Language: HighSpeed Pascal v1.10 by HiSoft Software');
  WriteLn('Machine : Amiga A1200, 64Mb HD, 2Mb Chip RAM, 0Mb Fast RAM');
  WriteLn('Time    : 0 hours 41 minutes');
  WriteLn('D/File  : SYS:Finance!.dat');
  WriteLn('Extra   : I  listened to Club Mix ''97 while programming Finance! and smoking');
  WriteLn(#$09,'  Red  Band  cigarettes  and  drinking tea.  But I''m really sure you');
  WriteLn(#$09,'  wanted to know that...!?');
  PressSpace;
End;

Procedure CheckQuit;
Begin
  ProgramTitle('Quit');
  If AreYouSure='Y' Then QTF:=TRUE;
End;

Procedure MainMenu;
Begin
  QTF:=FALSE;
  Repeat
    OPT:='*';
    ProgramTitle('Main Menu');
    WriteLn('1. Clear all data');
    WriteLn('2. View current balance');
    WriteLn('3. Credit balance');
    WriteLn('4. Debit balance');
    WriteLn('5. Save balance to disk');
    WriteLn('6. Load balance from disk');
    WriteLn('7. View program information');
    WriteLn('8. View program credits');
    WriteLn('9. Quit');
    WriteLn;
    Write('Enter selection (1-9) : ');
    Repeat
      OPT:=UpCase(ReadKey);
    Until OPT In ['1','2','3','4','5','6','7','8','9'];
    If OPT='1' Then ClearData;
    If OPT='2' Then ViewBalance;
    If OPT='3' Then Credit;
    If OPT='4' Then Debit;
    If OPT='5' Then SaveData;
    If OPT='6' Then LoadData;
    If OPT='7' Then ViewInfo;
    If OPT='8' Then ViewCredits;
    If OPT='9' Then CheckQuit;
  Until QTF;
End;

Begin
  InitVars;
  MainMenu;
  ProgramTitle('End of program.');
End.