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