Added field "Status" to 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         $worksheet->write($row, $col++, 'Status');
49         $row++;
50         
51         foreach ($members as $member) {
52                 $col = 0;
53                 $worksheet->write($row, $col++, $member['number']);    
54                 $worksheet->write($row, $col++, $member['nickname']);    
55                 $worksheet->write($row, $col++, $member['email']);     
56                 $worksheet->write($row, $col++, $member['firstname']);    
57                 $worksheet->write($row, $col++, $member['lastname']);    
58                 $worksheet->write($row, $col++, $member['street']);    
59                 $worksheet->write($row, $col++, $member['housenumber']);
60                 $worksheet->write($row, $col++, $member['postcode']);      
61                 $worksheet->write($row, $col++, $member['city']);         
62                 $worksheet->write($row, $col++, $member['country']); 
63                 $worksheet->write($row, $col++, $member['phone']);         
64                 $worksheet->write($row, $col++, $member['fax']);         
65                 $worksheet->write($row, $col++, $member['mobile']);         
66                 $worksheet->write($row, $col++, $member['jabber']);         
67                 $worksheet->write($row, $col++, $member['icq']);         
68                 $worksheet->write($row, $col++, $member['msn']);         
69                 $worksheet->write($row, $col++, $member['aim']);         
70                 $worksheet->write($row, $col++, $member['skype']);         
71                 $worksheet->write($row, $col++, $member['url']);    
72                 $worksheet->write($row, $col++, $member['twitter']);
73                 $worksheet->write($row, $col++, $member['directdebit']);
74                 $membership_info = fees_info_for_member($member['id'], time());
75                 $worksheet->write($row, $col++, $membership_info['is_member']);
76                 $col = 0;
77                 $row++;
78         }
79
80         // Let's send the file
81         $workbook->close();
82
83         $content = ob_get_contents();
84         ob_end_clean();
85         echo $content;
86         exit();
87 }
88
89 function action_export_payments() {
90         global $EARNING_TYPES, $EXPENSE_TYPES;
91
92     error_reporting(error_reporting() & ~E_DEPRECATED & ~E_STRICT);
93         require_once 'vendor/autoload.php';
94
95         // Creating a workbook
96         $workbook = new Spreadsheet_Excel_Writer();
97         $workbook->setVersion(8);
98
99         // sending HTTP headers
100         $workbook->send('Finanzen.xls');
101
102         // Creating a worksheet
103
104         $payments = db_get_finished_payments(0, 1000000000);
105
106
107         $row = 0;
108         $col = 0;
109         $current_year = '';
110
111         foreach ($payments as $payment) {
112                 $year = substr($payment['date'], 0, 4);
113                 if ($year != $current_year) {
114                         $current_year = $year;
115                         $worksheet =& $workbook->addWorksheet($year);
116                         $worksheet->setInputEncoding('UTF-8');
117                         $row = 0;
118
119                         $worksheet->write($row, $col++, 'Id');
120                         $worksheet->write($row, $col++, 'Datum');
121                         $worksheet->write($row, $col++, 'Kategorie');
122                         $worksheet->write($row, $col++, 'Betrag');
123                         $worksheet->write($row, $col++, 'Beschreibung');
124                         $worksheet->write($row, $col++, 'Mitglied');
125                         $worksheet->write($row, $col++, 'Kontostand');
126                         $worksheet->write($row, $col++, 'Kassenstand');
127                         $worksheet->write($row, $col++, 'Gesamt');
128                         $row++;
129                         $col = 0;
130                 }
131                 $worksheet->write($row, $col++, $payment['id']);
132                 $worksheet->write($row, $col++, $payment['date']);
133                 $worksheet->write($row, $col++, $payment['ptype'] == 'earning'? $EARNING_TYPES[$payment['type']] : $EXPENSE_TYPES[$payment['type']]);
134                 $worksheet->write($row, $col++, ($payment['ptype'] == 'earning' ? 1 : -1)  * $payment['value']);
135                 $worksheet->write($row, $col++, $payment['description']);
136                 $worksheet->write($row, $col++, $payment['nickname']);
137                 $worksheet->write($row, $col++, $payment['bank']);
138                 $worksheet->write($row, $col++, $payment['cash']);
139                 $worksheet->write($row, $col++, $payment['total']);
140
141                 $col = 0;
142                 $row++;
143         }
144
145         // Let's send the file
146         $workbook->close();
147
148         $content = ob_get_contents();
149         ob_end_clean();
150         echo $content;
151         exit();
152 }
153
154
155 ?>