home *** CD-ROM | disk | FTP | other *** search
-
- procedure Print_Amortization;
- const PRINT_PAGE = 58; { Number of print lines per page. }
- VIDEO_PAGE = 20; { Number of print lines on video screen. }
- TOF = #12; { Printer top of form control code. }
- ADDR_SIZE = 4; { Number of bytes required to store an Address }
- { CP/M-80 systems replace 4 with 2. }
-
- type Address = array[1..2] of Integer;
- Totals = (Payments,Principle,Interest);
-
- var hold_out_ptr : Address;
- total_ptr : Totals;
- month_offset,
- offset_factor,
- calc_pmt,
- periodic_rate,
- loan_balance : Real;
- final_total : array[Payments..Interest] of Real;
- year_total : array[Payments..Interest] of Real;
- line_cnt : Integer;
- pmt_no,
- max_line : Byte;
-
- function Ready_To_Print: Boolean;
- begin
- if (loan.out_dev = PRINTER) then
- begin
- Clear_Prompts;
- Display_Prompt(CMD_LINE,'CMD', QUIT_KEY + ' Cancel Printing ');
- Display_Prompt(MSG_LINE,'INP','Press ' + ENTER_KEY +
- 'when PRINTER is READY. ==> ');
- Ready_To_Print := (Valid_Key([CR,QUIT]) = CR);
- Display_Prompt(MSG_LINE,'MSG','Printing amortization table...');
- end
- else
- Ready_To_Print := TRUE;
- end; { Ready_To_Print }
-
- procedure Init_Variables;
- var i : Byte;
-
- begin
- month_offset := 0.0;
- offset_factor := 12 / loan.pmts_per_yr;
- calc_pmt := loan.payment;
- periodic_rate := loan.rate / loan.pmts_per_yr / 100.0;
- loan_balance := loan.principle;
- for total_ptr := Payments to Interest do
- begin
- year_total[total_ptr] := 0.0;
- final_total[total_ptr] := 0.0;
- end;
- pmt_no := ZERO;
- end; { Init_Variables }
-
- procedure Init_Output_Device;
- begin
- Move (ConOutPtr,hold_out_ptr,ADDR_SIZE); { Save console device addr. }
- if loan.out_dev = PRINTER then
- begin
- Move (LstOutPtr,ConOutPtr,ADDR_SIZE);
- max_line := PRINT_PAGE;
- end
- else
- max_line := VIDEO_PAGE;
- end; { Init_Output_Device }
-
- procedure Print_Table;
- type Month_Str = string[3];
-
- const month_id : array[1..12] of Month_Str =
- ('Jan','Feb','Mar','Apr',
- 'May','Jun','Jul','Aug',
- 'Sep','Oct','Nov','Dec');
-
- var interest_amt,
- principle_amt : Real;
- current_year : Integer;
- current_month : Byte;
- user_quit : Boolean;
-
-
- procedure New_Page(device: Char);
-
- procedure Print_Header;
- begin
- {$I-}
- WriteLn(' Payment Remaining Total of Principle Interest');
- io_status := IOresult;
- {$I+}
- if (io_status = ZERO) then
- WriteLn(' No./Date Principle Payments Payment Payment')
- else
- Disp_IO_Error('Printer');
- if (not err_flag) then
- begin
- Repeat_Char('-',62); WriteLn;
- line_cnt := 3;
- end;
- end { Print_Header };
-
- begin { New_Page }
- if (device = VIDEO) then
- ClrScr
- else
- if (pmt_no > ZERO) then
- Write(TOF);
- if (not user_quit) then
- Print_Header;
- end; { New_Page }
-
- procedure Continue_Prompt;
- begin
- Display_Prompt(CMD_LINE,'CMD', QUIT_KEY + ' Cancel Printing ');
- Display_Prompt(PROMPT_LINE,'INP',
- 'Press ANY KEY to continue. ==> ');
- Read(Kbd,inchr);
- GoToXY(1,PROMPT_LINE); ClrEol;
- if (inchr = QUIT) then
- user_quit := TRUE;
- end; { Continue_Prompt }
-
- function Calc_Month: Integer;
- begin
- Calc_Month := Round(loan.first_mo +
- month_offset - 1.49) mod 12 + 1;
- end; { Calc_Month }
-
- function Calc_Year: Integer;
- begin
- Calc_year := loan.first_yr +
- ((Round(month_offset) + loan.first_mo - 1) div 12);
- end; { Calc_Year }
-
- procedure Calc_Detail_Line;
- var cents : Real;
-
- begin
- current_month := Calc_Month;
- current_year := Calc_Year;
- interest_amt := (loan_balance * periodic_rate);
- cents := Frac(interest_amt);
- interest_amt := interest_amt - cents +
- (Round(cents * 100.0) * 0.01);
- if ((loan_balance + interest_amt) < calc_pmt) then
- calc_pmt := (loan_balance + interest_amt);
- principle_amt := calc_pmt - interest_amt;
- loan_balance := loan_balance - principle_amt;
- final_total[Payments] := final_total[Payments] + calc_pmt;
- final_total[Principle] := final_total[Principle] + principle_amt;
- final_total[Interest] := final_total[Interest] + interest_amt;
- if (loan.select_yr = ZERO) or (loan.select_yr = current_year) then
- begin
- year_total[Payments] := year_total[Payments] + calc_pmt;
- year_total[Principle] := year_total[Principle] + principle_amt;
- year_total[Interest] := year_total[Interest] + interest_amt;
- end;
- end; { Calc_Detail_Line }
-
- procedure Print_Detail_Line;
- begin
- with loan do
- if (select_yr = 0) or (select_yr = current_year) then
- begin
- {$I-}
- WriteLn((pmt_no + 1):3,month_id[current_month]:5,
- current_year:5,loan_balance:11:2,final_total[Payments]:12:2,
- principle_amt:12:2,interest_amt:12:2);
- io_status := IOresult;
- line_cnt := Succ(line_cnt);
- end;
- {$I+}
- if (io_status <> ZERO) then
- Disp_IO_Error('Printer')
- end; { Print_Detail_Line }
-
- procedure Check_EndOfPage;
- begin
- if line_cnt > max_line then
- begin
- if (loan.out_dev = VIDEO) then
- Continue_Prompt;
- New_Page(loan.out_dev);
- end;
- end; { Check_EndOfPage }
-
- procedure Check_EndOfYear;
- var next_year,
- next_month,
- current_month : Integer;
-
- function End_Loan_Year: Boolean;
- begin
- End_Loan_Year :=
- ((Round(month_offset) mod 12) = ZERO) and
- (next_month <> current_month);
- end; { End_Loan_Year }
-
- function End_Select_Year: Boolean;
- begin
- with loan do
- if (select_yr > ZERO) and (next_year = (select_yr + 1)) then
- begin
- End_Select_Year := TRUE;
- pmt_no := Trunc(no_of_pmts + 0.99);
- end
- else
- End_Select_Year := False;
- end; { End_Select_Year }
-
- function End_Loan: Boolean;
- begin
- End_Loan :=
- ((pmt_no + 1) = Trunc(loan.no_of_pmts + 0.99));
- end; { End_Pmts }
-
- procedure Print_Annual_Totals;
- begin
- if (loan.out_dev = PRINTER) then
- WriteLn;
- Write('Total for Yr.',SPACE:11);
- for total_ptr := Payments to Interest do
- begin
- Write(year_total[total_ptr]:12:2);
- year_total[total_ptr] := 0.0;
- end;
- WriteLn; line_cnt := Succ(line_cnt);
- if (loan.out_dev = PRINTER) then
- begin
- WriteLn; line_cnt := line_cnt + 2;
- end;
- end; { Print_Annual_Totals }
-
- begin { Check_EndOfYear }
- current_month := Calc_Month;
- month_offset := month_offset + offset_factor;
- next_month := Calc_Month;
- next_year := Calc_Year;
- if (loan.pmts_per_yr > 1) then
- if (End_Loan_Year or End_Select_Year) or End_Loan then
- Print_Annual_Totals;
- end; { Check_EndOfYear }
-
- procedure Check_UsrQuit;
- begin
- if KeyPressed then
- begin
- Read(Kbd,inchr);
- if (inchr = QUIT) then
- user_quit := TRUE;
- end;
- end; { Check_Usr_Quit }
-
- function End_Table: Boolean;
- begin
- if (user_quit or (pmt_no >= Trunc(loan.no_of_pmts + 0.99))) then
- begin
- End_Table := TRUE;
- if (loan.out_dev = VIDEO) and (line_cnt > (max_line - 3)) then
- begin
- Continue_Prompt;
- New_Page(VIDEO);
- end;
- end
- else
- End_Table := FALSE;
- end; { End_Table }
-
- procedure Print_Final_Totals;
- begin
- if (loan.select_yr = ZERO) then
- begin
- WriteLn;
- WriteLn('Loan Totals ',SPACE:12,final_total[Payments]:12:2,
- final_total[Principle]:12:2,final_total[Interest]:12:2);
- end;
- if (loan.out_dev = PRINTER) then
- Write(TOF)
- else
- Continue_Prompt;
- end; { Print_Final_Totals }
-
- begin { Print_Table }
- user_quit := FALSE;
- err_flag := FALSE;
- New_Page(loan.out_dev);
- repeat
- Calc_Detail_Line;
- Print_Detail_Line;
- if (not err_flag) then
- begin
- Check_EndOfPage;
- Check_EndOfYear;
- Check_UsrQuit;
- pmt_no := Succ(pmt_no);
- end;
- until (End_Table or err_flag);
- if (not (err_flag or user_quit)) then
- Print_Final_Totals;
- Move(hold_out_ptr,ConOutPtr,ADDR_SIZE); { Restore console device addr. }
- end; { Print_Table }
-
- begin { Print_Amortization }
- if Ready_To_Print then
- begin
- Init_Variables;
- Init_Output_Device;
- Print_Table;
- end;
- end; { Print_Amortization }
-