9 // Not used but referred to from account.cpp
17 * A Loan is list of transactions. each transaction is a date and a balance.
18 * The balance states the amount added to de loan (Debit) or payed back (Credit).
21 //----------------------------transaction---------------------
30 friend std::istream & operator>>(std::istream &, transaction &);
31 friend std::ostream & operator<<(std::ostream &, transaction );
34 std::istream &operator>>(std::istream &s, transaction &t)
40 t.mutation = balance(debit, credit);
45 std::ostream & operator<<(std::ostream &s, transaction t)
47 s << t.booked << " " << t.mutation;
52 //----------------------------loan----------------------------
56 std::list<transaction> records;
60 void read(char *filename);
64 void loan::read(char *filename)
66 std::ifstream in(filename);
75 records.push_back(tr);
82 std::list<transaction>::const_iterator ri;
83 transaction tr, prev_tr;
84 balance saldo, prev_saldo;
86 for (ri = records.begin(); ri != records.end(); ri++)
93 std::cout << " " << saldo;
95 if (ri != records.begin())
97 int days_of_interest = tr.booked - prev_tr.booked;
98 amount loaned_low, loaned_high;
99 amount interest_low, interest_high;
101 loaned_low = prev_saldo.debit();
102 if (loaned_low > 2500000)
104 loaned_high = loaned_low - 2500000;
105 loaned_low = 2500000;
107 interest_low = (loaned_low * days_of_interest * 9 / 365 + 50) / 100;
108 interest_high = (loaned_high * days_of_interest * 12 / 365 + 50) / 100;
110 std::cout << std::setw(6) << std::right << days_of_interest;
111 std::cout << " " << interest_low << " " << interest_high << " " << interest_low + interest_high;
119 //----------------------------main----------------------------
121 static char helptext[] =
122 "Usage: loan [options] loanfile\n"
126 " --from <start> : Calculate the report from <start> date\n"
128 " --to <end> : Calculate the report until <end> date\n"
129 " --help : Print this helpful message\n"
131 " --version : Print the version number\n";
133 static struct option long_options[] =
135 { "help", no_argument, 0, 'h' },
136 { "from", required_argument, 0, 'f' },
137 { "to", required_argument, 0, 't' },
138 { "version", no_argument, 0, 'V' },
142 int main(int argc, char * argv[])
146 int option_index = 0;
148 String from_option, to_option;
150 while ((c = getopt_long(argc, argv, "hf:t:V", long_options, &option_index)) != -1)
155 std::cout << helptext;
160 std::cout << "account version 1.4\n";
165 from_option = String(optarg);
169 to_option = String(optarg);
176 std::cerr << "Usage: loan [options] loan_file\n";
182 loan_account.read(argv[optind]);
183 loan_account.report();