From 8ca869e7dd804f12c2d752a5eb2bf466db6009a0 Mon Sep 17 00:00:00 2001 From: Romain d'Alverny Date: Mon, 2 Jul 2012 17:16:37 +0000 Subject: use new report format, code reorg --- en/about/reports/template.php | 278 +++++++------------------------------- en/about/reports/template_lib.php | 161 ++++++++++++++++++++++ 2 files changed, 210 insertions(+), 229 deletions(-) create mode 100644 en/about/reports/template_lib.php (limited to 'en') diff --git a/en/about/reports/template.php b/en/about/reports/template.php index d9bb5aaee..478a1b494 100644 --- a/en/about/reports/template.php +++ b/en/about/reports/template.php @@ -12,8 +12,9 @@ $_months = array( 10 => 'October', 11 => 'November', 12 => 'December' ); -$data = file($source_csv); +$data = file($source_csv); $parsed = array(); + foreach ($data as $l) { if (trim($l) == ',,,,,,') continue; @@ -52,16 +53,16 @@ foreach ($parsed as $tag => $values) { } $flow = array(); -$list = array(); -$count = array(); -foreach ($parsed['# Expenses details > ## Monthly summary'] as $line) { - $list[] = $line[2]; - $count[] = $line[1]; +$list = array_fill(1, 12, 0); +$count = array_fill(1, 12, 0); +$tmp = $parsed['# Expenses details > ## More details']; +array_shift($tmp); +foreach ($tmp as $line) { + $month = date('n', strtotime($line[0])); + $list[$month] += $line[3]; // amount + $count[$month] += 1; } -unset($list[0]); -unset($list[13]); -unset($count[0]); -unset($count[13]); +$expenses_monthly_summary = array($list, $count); $flow = array( 'expenses' => $list, @@ -84,6 +85,11 @@ unset($count[13]); $flow['revenue'] = $list; $flow['revenue_op'] = $count; +include 'template_lib.php'; + +$R = get_revenues($parsed['# Income details > ## Donations monthly summary']); +$expenses_total = array_sum($expenses_monthly_summary[0]); + ?> @@ -187,6 +193,7 @@ $flow['revenue_op'] = $count;
-
+

Cash flow


-
+

Income statement

+ TODO: full income statement. For now, check details below. - - - - - - - - - + + + + + + + + + + + ## Revenues']['Total of revenues'] - $parsed['# Income Statement > ## Expenses']['Total of expenses']; + $result = $R['data']['total'] - $expenses_total; if ($result > 0): ?> - + - + +
RevenuesExpenses
- - ## Revenues'] as $k => $v) { - if (in_array($k, array('Total of revenues', 'Net Loss'))) - continue; - - $s .= sprintf('', - $k, number_format(str_replace(',', '.', $v), 2, '.', ',')); - } - echo $s; - ?> -
%s%s
-
- - ## Expenses'] as $k => $v) { - if (in_array($k, array('Total of expenses', 'Net Income'))) - continue; - - $s .= sprintf('', - $k, number_format(str_replace(',', '.', $v), 2, '.', ',')); - } - echo $s; - ?> -
%s%s
-
Total of revenues ## Revenues']['Total of revenues']), 2, '.', ','); ?>Total of expenses ## Expenses']['Total of expenses']), 2, '.', ','); ?>
Revenues
Expenses
Net Income Net Loss

-
+

Balance sheet

@@ -314,188 +297,25 @@ $flow['revenue_op'] = $count;
Assets

-
+

Expenses

- - ## Monthly summary']; - echo ''; - $s = array_shift($v); - echo vsprintf('', - $s); - $sums = array(); - foreach ($v as $line) { - if ($line[0] == 'total') - continue; - - echo sprintf('', - $_months[$line[0]], - $line[1], - number_format(str_replace(',', '.', $line[2]), 2, '.', ','), - $line[1] > 0 ? number_format(str_replace(',', '.', $line[2] / $line[1]), 2, '.', ',') : '' - ); - - $sums['count'] += $line[1]; - $sums['total'] += $line[2]; - } - echo ''; - echo sprintf(' - - - ', - $sums['count'], - number_format(str_replace(',', '.', $sums['total']), 2, '.', ','), - $sums['count'] > 0 ? number_format(str_replace(',', '.', $sums['total'] / $sums['count']), 2, '.', ',') : '' - ); - echo '
%s%s%saverage/expense
%s%s%s%s
Total%s%s%s
'; - $total_expenses = $sums['total']; - ?> - -

Details

- -
- - ## More details']; - $line = array_shift($v); - $sums = array(); - - echo sprintf('', - $line[0], $line[1], - $line[2], $line[3], - $line[4], - $line[5]); - - foreach ($v as $line) { - if (count($line) < 2) - continue; - - echo sprintf('', - $line[0], $line[1], - $line[2], $line[3], - $line[4], - number_format(str_replace(',', '.', $line[5]), 2, '.', ',')); - - $cat = explode(':', $line[3]); - $sums[$cat[0]] += $line[5]; - } - ?> - -
%s%s%s%s%s%s
%s%s%s%s%s%s
- + ## More details']); echo $E['html']; ?>

-
+

Income, donations

- ## Donations monthly summary']; - echo '
'; - echo ''; - $line = array_shift($v); - echo sprintf(' - - ', - $line[0], $line[1], $line[2], - $line[3], - $line[4], - $line[5], $line[6]); - - echo ''; - - $sums = array(); - - foreach ($v as $line) { - echo sprintf(' - - - - - - ', - $_months[$line[0]], - $line[1], - number_format(str_replace(',', '.', $line[2]), 2, '.', ','), - number_format(str_replace(',', '.', $line[3]), 2, '.', ','), - number_format(str_replace(',', '.', $line[4]), 2, '.', ','), - number_format(str_replace(',', '.', $line[5]), 2, '.', ','), - number_format(str_replace(',', '.', $line[6]), 2, '.', ','), - $line[1] > 0 ? number_format(str_replace(',', '.', $line[2] / $line[1]), 2, '.', ',') : '' - ); - - $sums['count'] += $line[1]; - $sums['total'] += $line[2]; - $sums['check'] += $line[3]; - $sums['xfer'] += $line[4]; - $sums['paypal'] += $line[5]; - $sums['cash'] += $line[6]; - } - echo ''; - echo sprintf(' - - - - - - - ', - $sums['count'], - number_format(str_replace(',', '.', $sums['total']), 2, '.', ','), - number_format(str_replace(',', '.', $sums['check']), 2, '.', ','), - number_format(str_replace(',', '.', $sums['xfer']), 2, '.', ','), - number_format(str_replace(',', '.', $sums['paypal']), 2, '.', ','), - number_format(str_replace(',', '.', $sums['cash']), 2, '.', ','), - $sums['count'] > 0 ? number_format(str_replace(',', '.', $sums['total'] / $sums['count']), 2, '.', ',') : '' - ); - $total_revenues = $sums['total']; - echo '
%s%s%s%s%s%s%saverage
%s%s%s%s%s%s%s%s
Total%s%s%s%s%s%s%s
'; - echo << - google.setOnLoadCallback(drawChart); - function drawChart() { - var data = new google.visualization.DataTable(); - data.addColumn('string', 'Source'); - data.addColumn('number', 'Amount'); - data.addRows([ - ['Paypal', {$sums['paypal']}], - ['Bank transfer', {$sums['xfer']}], - ['Check', {$sums['check']}], - ['Cash', {$sums['cash']}], - ]); - - var options = {'title':'Donations by source', - 'width':400, - 'height':300}; - - var chart = new google.visualization.PieChart(document.getElementById('income-pie')); - chart.draw(data, options); - } - -S; - ?> +

Return to top

+ + diff --git a/en/about/reports/template_lib.php b/en/about/reports/template_lib.php new file mode 100644 index 000000000..72bf48bd6 --- /dev/null +++ b/en/about/reports/template_lib.php @@ -0,0 +1,161 @@ +'; + $html .= ''; + + $line = array_shift($v); + $sums = array(); + + $html .= sprintf('', + $line[0], $line[1], + $line[2], $line[3], + $line[4], + $line[5]); + + foreach ($v as $line) { + if (count($line) < 2) + continue; + + $html .= sprintf('', + date('Y-M-d', strtotime($line[0])), $line[1], + $line[2], + number_format(str_replace(',', '.', $line[3]), 2, '.', ',')); + + $cat = explode(':', $line[1]); + $sums[$cat[0]] += $line[3]; + $sums['total'] += $line[3]; + } + + $html .= ' + + + + +
%s%s%s%s
%s%s%s%s
Total:' . number_format(str_replace(',', '.', $sums['total']), 2, '.', ',') . '
'; + + unset($sums['total']); + arsort($sums); + foreach ($sums as $k => $v) + $sums[$k] = "['{$k}', $v]"; + + $values = implode(', ', $sums); + $html .= << + google.setOnLoadCallback(drawChartExpenses); + function drawChartExpenses() { + var data = new google.visualization.DataTable(); + data.addColumn('string', 'Source'); + data.addColumn('number', 'Amount'); + data.addRows([{$values}]); + var options = {'title':'Expenses by category', + 'width':400, + 'height':300}; + + var chart = new google.visualization.PieChart(document.getElementById('expenses-cats-pie')); + chart.draw(data, options); + } + +H; + + return array('html' => $html); +} + +/** + * @param string $v + * + * @return array('html' => string, 'data' => mixed) +*/ +function get_revenues($v) +{ + global $_months; + + $html = '
'; + $html .= ''; + + $line = array_shift($v); + $html .= sprintf(' + + ', + $line[0], $line[1], $line[2], + $line[3], + $line[4], + $line[5], $line[6]); + + $html .= ''; + + $sums = array(); + + foreach ($v as $line) { + $html .= sprintf(' + + + + + + ', + $_months[$line[0]], + $line[1], + number_format(str_replace(',', '.', $line[2]), 2, '.', ','), + number_format(str_replace(',', '.', $line[3]), 2, '.', ','), + number_format(str_replace(',', '.', $line[4]), 2, '.', ','), + number_format(str_replace(',', '.', $line[5]), 2, '.', ','), + number_format(str_replace(',', '.', $line[6]), 2, '.', ','), + $line[1] > 0 ? number_format(str_replace(',', '.', $line[2] / $line[1]), 2, '.', ',') : '' + ); + + $sums['count'] += $line[1]; + $sums['total'] += $line[2]; + $sums['check'] += $line[3]; + $sums['xfer'] += $line[4]; + $sums['paypal'] += $line[5]; + $sums['cash'] += $line[6]; + } + $html .= ''; + $html .= sprintf(' + + + + + + + ', + $sums['count'], + number_format(str_replace(',', '.', $sums['total']), 2, '.', ','), + number_format(str_replace(',', '.', $sums['check']), 2, '.', ','), + number_format(str_replace(',', '.', $sums['xfer']), 2, '.', ','), + number_format(str_replace(',', '.', $sums['paypal']), 2, '.', ','), + number_format(str_replace(',', '.', $sums['cash']), 2, '.', ','), + $sums['count'] > 0 ? number_format(str_replace(',', '.', $sums['total'] / $sums['count']), 2, '.', ',') : '' + ); + $total_revenues = $sums['total']; + $html .= '
%s%s%s%s%s%s%saverage
%s%s%s%s%s%s%s%s
Total%s%s%s%s%s%s%s
'; + + $html .= << + google.setOnLoadCallback(drawChart); + function drawChart() { + var data = new google.visualization.DataTable(); + data.addColumn('string', 'Source'); + data.addColumn('number', 'Amount'); + data.addRows([ + ['Paypal', {$sums['paypal']}], + ['Bank transfer', {$sums['xfer']}], + ['Check', {$sums['check']}], + ['Cash', {$sums['cash']}], + ]); + + var options = {'title':'Donations by source', + 'width':400, + 'height':300}; + + var chart = new google.visualization.PieChart(document.getElementById('income-pie')); + chart.draw(data, options); + } + +S; + + return array('html' => $html, 'data' => array('total' => $total_revenues)); +} \ No newline at end of file -- cgit v1.2.1