Excel-Export
authorPascal Hofmann <mail@pascalhofmann.de>
Thu, 23 Feb 2012 21:21:41 +0000 (22:21 +0100)
committerPascal Hofmann <mail@pascalhofmann.de>
Thu, 23 Feb 2012 21:21:41 +0000 (22:21 +0100)
README [new file with mode: 0644]
include/export.php [new file with mode: 0644]
include/finances.php
index.php

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..6a2d8a9
--- /dev/null
+++ b/README
@@ -0,0 +1,20 @@
+Needs PEAR OLE and PEAR Spreadsheet_Excel_Writer in Subdirectory pear/ like:
+
+pear/
+pear/OLE
+pear/OLE/ChainedBlockStream.php
+pear/OLE/PPS
+pear/OLE/PPS/File.php
+pear/OLE/PPS/Root.php
+pear/OLE/PPS.php
+pear/OLE.php
+pear/Spreadsheet
+pear/Spreadsheet/Excel
+pear/Spreadsheet/Excel/Writer
+pear/Spreadsheet/Excel/Writer/BIFFwriter.php
+pear/Spreadsheet/Excel/Writer/Format.php
+pear/Spreadsheet/Excel/Writer/Parser.php
+pear/Spreadsheet/Excel/Writer/Validator.php
+pear/Spreadsheet/Excel/Writer/Workbook.php
+pear/Spreadsheet/Excel/Writer/Worksheet.php
+pear/Spreadsheet/Excel/Writer.php
diff --git a/include/export.php b/include/export.php
new file mode 100644 (file)
index 0000000..59b4964
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+function action_export() {
+       global $EARNING_TYPES, $EXPENSE_TYPES;
+
+       ini_set('include_path', ini_get('include_path') . ':pear/');
+
+       require_once 'Spreadsheet/Excel/Writer.php';
+
+       // Creating a workbook
+       $workbook = new Spreadsheet_Excel_Writer();
+       $workbook->setVersion(8);
+
+       // sending HTTP headers
+       $workbook->send('Finanzen.xls');
+
+       // Creating a worksheet
+
+       $payments = db_get_finished_payments(0, 1000000000);
+
+
+       $row = 0;
+       $col = 0;
+       $current_year = '';
+
+       foreach ($payments as $payment) {
+               $year = substr($payment['date'], 0, 4);
+               if ($year != $current_year) {
+                       $current_year = $year;
+                       $worksheet =& $workbook->addWorksheet($year);
+                       $worksheet->setInputEncoding('UTF-8');
+                       $row = 0;
+
+                       $worksheet->write($row, $col++, 'Id');
+                       $worksheet->write($row, $col++, 'Datum');
+                       $worksheet->write($row, $col++, 'Kategorie');
+                       $worksheet->write($row, $col++, 'Betrag');
+                       $worksheet->write($row, $col++, 'Beschreibung');
+                       $worksheet->write($row, $col++, 'Mitglied');
+                       $worksheet->write($row, $col++, 'Kontostand');
+                       $worksheet->write($row, $col++, 'Kassenstand');
+                       $worksheet->write($row, $col++, 'Gesamt');
+                       $row++;
+                       $col = 0;
+               }
+               $worksheet->write($row, $col++, $payment['id']);
+               $worksheet->write($row, $col++, $payment['date']);
+               $worksheet->write($row, $col++, $payment['ptype'] == 'earning'? $EARNING_TYPES[$payment['type']] : $EXPENSE_TYPES[$payment['type']]);
+               $worksheet->write($row, $col++, ($payment['ptype'] == 'earning' ? 1 : -1)  * $payment['value']);
+               $worksheet->write($row, $col++, $payment['description']);
+               $worksheet->write($row, $col++, $payment['nickname']);
+               $worksheet->write($row, $col++, $payment['bank']);
+               $worksheet->write($row, $col++, $payment['cash']);
+               $worksheet->write($row, $col++, $payment['total']);
+
+               $col = 0;
+               $row++;
+       }
+
+       // Let's send the file
+       $workbook->close();
+
+       $content = ob_get_contents();
+       ob_end_clean();
+       echo $content;
+       die();
+}
+
+
+
index 4d5e4a9..5731292 100644 (file)
@@ -59,5 +59,6 @@ function action_finances() {/*{{{*/
     echo '<br style="clear: left;"/>';
     render_open_payments();
     render_finished_payments();
+    echo '<a href="' . link_to('export') . '">.xls runterladen</a>';
 }/*}}}*/
 
index 4b4d5c2..e6d51f0 100644 (file)
--- a/index.php
+++ b/index.php
@@ -19,6 +19,7 @@ require_once('include/expenses.php');
 require_once('include/members.php');
 require_once('include/payments.php');
 require_once('include/dtaus.php');
+require_once('include/export.php');
 
 db_connect();
 
@@ -49,6 +50,7 @@ switch ($action) {
     case 'fees'           : action_fees();            break;
     case 'dtaus'          : action_dtaus();           break;
     case 'finances'       : action_finances();        break;
+    case 'export'         : action_export();          break;
     default: action_404();
 }