59b49642cf8582a0e57024fd545bdcc598cb2e7a
[memberdb.git] / include / export.php
1 <?php
2
3 function action_export() {
4         global $EARNING_TYPES, $EXPENSE_TYPES;
5
6         ini_set('include_path', ini_get('include_path') . ':pear/');
7
8         require_once 'Spreadsheet/Excel/Writer.php';
9
10         // Creating a workbook
11         $workbook = new Spreadsheet_Excel_Writer();
12         $workbook->setVersion(8);
13
14         // sending HTTP headers
15         $workbook->send('Finanzen.xls');
16
17         // Creating a worksheet
18
19         $payments = db_get_finished_payments(0, 1000000000);
20
21
22         $row = 0;
23         $col = 0;
24         $current_year = '';
25
26         foreach ($payments as $payment) {
27                 $year = substr($payment['date'], 0, 4);
28                 if ($year != $current_year) {
29                         $current_year = $year;
30                         $worksheet =& $workbook->addWorksheet($year);
31                         $worksheet->setInputEncoding('UTF-8');
32                         $row = 0;
33
34                         $worksheet->write($row, $col++, 'Id');
35                         $worksheet->write($row, $col++, 'Datum');
36                         $worksheet->write($row, $col++, 'Kategorie');
37                         $worksheet->write($row, $col++, 'Betrag');
38                         $worksheet->write($row, $col++, 'Beschreibung');
39                         $worksheet->write($row, $col++, 'Mitglied');
40                         $worksheet->write($row, $col++, 'Kontostand');
41                         $worksheet->write($row, $col++, 'Kassenstand');
42                         $worksheet->write($row, $col++, 'Gesamt');
43                         $row++;
44                         $col = 0;
45                 }
46                 $worksheet->write($row, $col++, $payment['id']);
47                 $worksheet->write($row, $col++, $payment['date']);
48                 $worksheet->write($row, $col++, $payment['ptype'] == 'earning'? $EARNING_TYPES[$payment['type']] : $EXPENSE_TYPES[$payment['type']]);
49                 $worksheet->write($row, $col++, ($payment['ptype'] == 'earning' ? 1 : -1)  * $payment['value']);
50                 $worksheet->write($row, $col++, $payment['description']);
51                 $worksheet->write($row, $col++, $payment['nickname']);
52                 $worksheet->write($row, $col++, $payment['bank']);
53                 $worksheet->write($row, $col++, $payment['cash']);
54                 $worksheet->write($row, $col++, $payment['total']);
55
56                 $col = 0;
57                 $row++;
58         }
59
60         // Let's send the file
61         $workbook->close();
62
63         $content = ob_get_contents();
64         ob_end_clean();
65         echo $content;
66         die();
67 }
68
69
70