report_file = $files['report']; $i->forecast_file = $files['forecast']; $i->accounts_file = $files['accounts']; $i->CUR = 'EUR'; return $i; } /** */ function html_summary() { $account2010 = 7523.96; $this->hAccount2010 = number_format($account2010, 2); $this->hAccountLeft = number_format($account2010 + $this->balance, 2); $balanceSign = $this->balance >= 0 ? 'plus' : 'minus'; return << At the end of 2010 we had {$this->CUR} {$this->hAccount2010}. Since then, we received {$this->CUR} {$this->hInTotal}, and spent {$this->CUR} {$this->hOutTotal} (see detailed report). Our balance so far is of {$this->CUR} {$this->hBalance}, and we still have {$this->CUR} {$this->hAccountLeft}: {$this->CUR} {$this->accounts[0][1]} in our {$this->accounts[0][0]} {$this->CUR} {$this->accounts[1][1]} in our {$this->accounts[1][0]} {$this->CUR} {$this->accounts[2][1]} in our {$this->accounts[2][0]} S; } /** */ function html_report() { $f = file($this->report_file); $hFileMTime = $this->html_source_file($this->report_file); $inTotal = 0; $outTotal = 0; $hLines = ''; $line_tmpl = << %s %s %s %s S; $cat_tmpl = '%s'; foreach ($f as $l) { $l = str_getcsv($l, ';'); if ('cat' === trim($l[0])) { $hLines .= sprintf($cat_tmpl, $l[1]); } elseif ('' === trim($l[0])) { $hLines .= sprintf($line_tmpl, $l[1], $l[2], $l[3] != '' ? $this->CUR . ' ' . number_format($l[3], 2) : '', $l[4] != '' ? $this->CUR . ' ' . number_format($l[4], 2) : ''); $inTotal += $l[4]; $outTotal += $l[3]; } } $this->balance = $balance = $inTotal - $outTotal; $this->hInTotal = $hInTotal = number_format($inTotal, 2); $this->hOutTotal = $hOutTotal = number_format($outTotal, 2); $this->hBalance = $hBalance = number_format($balance, 2); $s = << Date Transaction description Outgoing Incoming {$hLines} Total {$this->CUR} {$hOutTotal} {$this->CUR} {$hInTotal} Balance {$this->CUR} {$hBalance} {$hFileMTime} S; return $s; } /** */ function html_forecast() { $f = file($this->forecast_file); $hFileMTime = $this->html_source_file($this->forecast_file); $total = 0; $doneTotal = 0; $hLines = ''; $CUR = 'EUR'; $line_tmpl = << %s {$CUR} %s %d %d {$CUR} %s %s S; foreach ($f as $l) { $l = str_getcsv($l, ';'); if ('' === trim($l[0])) { $subtotal = $l[2] * $l[3] * $l[4]; $hLines .= sprintf($line_tmpl, $l[1], number_format($l[2], 2), $l[3], $l[4], number_format($subtotal, 2), $l[6]); $total += $subtotal; if (strtolower($l[6]) != 'pending') { $doneTotal += $subtotal; } } } $hTotal = number_format($total, 2); $hDoneTotal = number_format($doneTotal, 2); $hProgress = round($doneTotal / $total * 100, 2); $s = << Description of planned expenditure Unit Price Quantity Recurrence Total Price Status {$hLines} Total forecasted {$CUR} {$hTotal} Total done {$CUR} {$hDoneTotal} {$hProgress}% {$hFileMTime} S; return $s; } /** */ function html_accounts() { $f = file($this->accounts_file); $hFileMTime = $this->html_source_file($this->accounts_file); $total = 0; $doneTotal = 0; $hLines = ''; $CUR = 'EUR'; $line_tmpl = << %s {$CUR} %s S; $this->accounts = array(); foreach ($f as $l) { $l = str_getcsv($l, ';'); if ('' === trim($l[0])) { $this->accounts[] = array( str_replace(array('(', ')'), array('(', ')'), $l[1]), number_format($l[2], 2) ); $hLines .= sprintf($line_tmpl, $l[1], number_format($l[2], 2)); $total += $l[2]; } } $hTotal = number_format($total, 2); $s = << Account Amount {$hLines} Total {$CUR} {$hTotal} S; $s =<<Source: %s (last updated on %s).

', $file, $file, date('c', filemtime($file))); } }