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