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);
return <<
Outstanding amount of 2010
{$this->CUR} {$this->hAccount2010}
Collected
{$this->CUR} {$this->hInTotal}
Spent
{$this->CUR} {$this->hOutTotal}
Balance
{$this->CUR} {$this->hBalance}
S;
}
/**
*/
function html_report()
{
$f = file($this->report_file);
$hFileMTime = $this->html_source_file($this->report_file);
$inTotal = 0;
$outTotal = 0;
$hLines = '';
$line_tmpl = <<Remaining amount today
{$this->CUR} {$this->hAccountLeft}
%s
%s
%s
%s
S;
$cat_tmpl = ' ';
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 = <<%s
{$hLines}
Date
Transaction description
Outgoing
Incoming
Total
{$this->CUR} {$hOutTotal}
{$this->CUR} {$hInTotal}
{$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 = <<Balance
{$this->CUR} {$hBalance}
%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 = <<
{$hLines}
Description of planned expenditure
Unit Price
Quantity
Recurrence
Total Price
Status
Total forecasted
{$CUR} {$hTotal}
{$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 = <<Total done
{$CUR} {$hDoneTotal}
{$hProgress}%
%s
{$CUR} %s
S;
foreach ($f as $l)
{
$l = str_getcsv($l, ';');
if ('' === trim($l[0])) {
$hLines .= sprintf($line_tmpl,
$l[1], number_format($l[2], 2));
$total += $l[2];
}
}
$hTotal = number_format($total, 2);
$s = <<
{$hLines}
Account
Amount
{$hFileMTime}
S;
return $s;
}
/**
*/
function html_source_file($file)
{
return sprintf('Total
{$CUR} {$hTotal}
Source: %s (last updated on %s).
', $file, $file, date('c', filemtime($file))); } }