Added XLS export of members.
[memberdb.git] / include / xlsexport.php
1 <?php
2
3 function action_export_members() {
4         global $EARNING_TYPES, $EXPENSE_TYPES;
5
6     error_reporting(error_reporting() & ~E_DEPRECATED & ~E_STRICT);
7         require_once 'vendor/autoload.php';
8
9         // Creating a workbook
10         $workbook = new Spreadsheet_Excel_Writer();
11         $workbook->setVersion(8);
12
13         // sending HTTP headers
14         $workbook->send('Mitglieder.xls');
15
16         // Creating a worksheet
17
18         $members = db_get_members();
19
20
21         $row = 0;
22         $col = 0;
23
24         $worksheet =& $workbook->addWorksheet('Mitglieder');
25         $worksheet->setInputEncoding('UTF-8');
26         $row = 0;
27         $worksheet->write($row, $col++, 'Mitgliedsnummer');
28         $worksheet->write($row, $col++, 'Nickname');
29         $worksheet->write($row, $col++, 'E-Mail');
30         $worksheet->write($row, $col++, 'Vorname');
31         $worksheet->write($row, $col++, 'Nachname');
32         $worksheet->write($row, $col++, 'Stra├če');
33         $worksheet->write($row, $col++, 'Hausnummer');
34         $worksheet->write($row, $col++, 'PLZ');
35         $worksheet->write($row, $col++, 'Ort');
36         $worksheet->write($row, $col++, 'Land');
37         $worksheet->write($row, $col++, 'Telefon');
38         $worksheet->write($row, $col++, 'Fax');
39         $worksheet->write($row, $col++, 'Handy');
40         $worksheet->write($row, $col++, 'Jabber');
41         $worksheet->write($row, $col++, 'ICQ');
42         $worksheet->write($row, $col++, 'MSN');
43         $worksheet->write($row, $col++, 'AIM');
44         $worksheet->write($row, $col++, 'Skype');
45         $worksheet->write($row, $col++, 'Website');
46         $worksheet->write($row, $col++, 'Twitter');
47         $worksheet->write($row, $col++, 'Lastschrifteinzug');
48         $row++;
49         
50         foreach ($members as $member) {
51                 $col = 0;
52                 $worksheet->write($row, $col++, $member['number']);    
53                 $worksheet->write($row, $col++, $member['nickname']);    
54                 $worksheet->write($row, $col++, $member['email']);     
55                 $worksheet->write($row, $col++, $member['firstname']);    
56                 $worksheet->write($row, $col++, $member['lastname']);    
57                 $worksheet->write($row, $col++, $member['street']);    
58                 $worksheet->write($row, $col++, $member['housenumber']);
59                 $worksheet->write($row, $col++, $member['postcode']);      
60                 $worksheet->write($row, $col++, $member['city']);         
61                 $worksheet->write($row, $col++, $member['country']); 
62                 $worksheet->write($row, $col++, $member['phone']);         
63                 $worksheet->write($row, $col++, $member['fax']);         
64                 $worksheet->write($row, $col++, $member['mobile']);         
65                 $worksheet->write($row, $col++, $member['jabber']);         
66                 $worksheet->write($row, $col++, $member['icq']);         
67                 $worksheet->write($row, $col++, $member['msn']);         
68                 $worksheet->write($row, $col++, $member['aim']);         
69                 $worksheet->write($row, $col++, $member['skype']);         
70                 $worksheet->write($row, $col++, $member['url']);    
71                 $worksheet->write($row, $col++, $member['twitter']);
72                 $worksheet->write($row, $col++, $member['directdebit']);
73                 $col = 0;
74                 $row++;
75         }
76
77         // Let's send the file
78         $workbook->close();
79
80         $content = ob_get_contents();
81         ob_end_clean();
82         echo $content;
83         exit();
84 }
85
86 function action_export_payments() {
87         global $EARNING_TYPES, $EXPENSE_TYPES;
88
89     error_reporting(error_reporting() & ~E_DEPRECATED & ~E_STRICT);
90         require_once 'vendor/autoload.php';
91
92         // Creating a workbook
93         $workbook = new Spreadsheet_Excel_Writer();
94         $workbook->setVersion(8);
95
96         // sending HTTP headers
97         $workbook->send('Finanzen.xls');
98
99         // Creating a worksheet
100
101         $payments = db_get_finished_payments(0, 1000000000);
102
103
104         $row = 0;
105         $col = 0;
106         $current_year = '';
107
108         foreach ($payments as $payment) {
109                 $year = substr($payment['date'], 0, 4);
110                 if ($year != $current_year) {
111                         $current_year = $year;
112                         $worksheet =& $workbook->addWorksheet($year);
113                         $worksheet->setInputEncoding('UTF-8');
114                         $row = 0;
115
116                         $worksheet->write($row, $col++, 'Id');
117                         $worksheet->write($row, $col++, 'Datum');
118                         $worksheet->write($row, $col++, 'Kategorie');
119                         $worksheet->write($row, $col++, 'Betrag');
120                         $worksheet->write($row, $col++, 'Beschreibung');
121                         $worksheet->write($row, $col++, 'Mitglied');
122                         $worksheet->write($row, $col++, 'Kontostand');
123                         $worksheet->write($row, $col++, 'Kassenstand');
124                         $worksheet->write($row, $col++, 'Gesamt');
125                         $row++;
126                         $col = 0;
127                 }
128                 $worksheet->write($row, $col++, $payment['id']);
129                 $worksheet->write($row, $col++, $payment['date']);
130                 $worksheet->write($row, $col++, $payment['ptype'] == 'earning'? $EARNING_TYPES[$payment['type']] : $EXPENSE_TYPES[$payment['type']]);
131                 $worksheet->write($row, $col++, ($payment['ptype'] == 'earning' ? 1 : -1)  * $payment['value']);
132                 $worksheet->write($row, $col++, $payment['description']);
133                 $worksheet->write($row, $col++, $payment['nickname']);
134                 $worksheet->write($row, $col++, $payment['bank']);
135                 $worksheet->write($row, $col++, $payment['cash']);
136                 $worksheet->write($row, $col++, $payment['total']);
137
138                 $col = 0;
139                 $row++;
140         }
141
142         // Let's send the file
143         $workbook->close();
144
145         $content = ob_get_contents();
146         ob_end_clean();
147         echo $content;
148         exit();
149 }
150
151
152 ?>