1
|
|
|
<?php |
2
|
|
|
/************************************************************************ |
3
|
|
|
* OVIDENTIA http://www.ovidentia.org * |
4
|
|
|
************************************************************************ |
5
|
|
|
* Copyright (c) 2003 by CANTICO ( http://www.cantico.fr ) * |
6
|
|
|
* * |
7
|
|
|
* This file is part of Ovidentia. * |
8
|
|
|
* * |
9
|
|
|
* Ovidentia is free software; you can redistribute it and/or modify * |
10
|
|
|
* it under the terms of the GNU General Public License as published by * |
11
|
|
|
* the Free Software Foundation; either version 2, or (at your option) * |
12
|
|
|
* any later version. * |
13
|
|
|
* * |
14
|
|
|
* This program is distributed in the hope that it will be useful, but * |
15
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
17
|
|
|
* See the GNU General Public License for more details. * |
18
|
|
|
* * |
19
|
|
|
* You should have received a copy of the GNU General Public License * |
20
|
|
|
* along with this program; if not, write to the Free Software * |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,* |
22
|
|
|
* USA. * |
23
|
|
|
************************************************************************/ |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
require_once dirname(__FILE__).'/xls.class.php'; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* days by year and by right types |
31
|
|
|
* |
32
|
|
|
*/ |
33
|
|
|
class absences_StatisticsXls extends absences_Xls |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
private $type_rows = null; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* |
43
|
|
|
* @var Worksheet |
44
|
|
|
*/ |
45
|
|
|
private $type_worksheet = null; |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
private $type_years = array(); |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* |
57
|
|
|
* @var array |
58
|
|
|
*/ |
59
|
|
|
private $filter = array(); |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function __construct(Array $filter) |
64
|
|
|
{ |
65
|
|
|
parent::__construct(absences_translate('Statistics')); |
66
|
|
|
|
67
|
|
|
$this->filter = $filter; |
68
|
|
|
|
69
|
|
|
$this->year_format = $this->workbook->addFormat(); |
|
|
|
|
70
|
|
|
$this->year_format->setBold(); |
|
|
|
|
71
|
|
|
$this->year_format->setPattern(1); |
|
|
|
|
72
|
|
|
$this->year_format->setFgColor(15); |
|
|
|
|
73
|
|
|
$this->year_format->setAlign('center'); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$this->addTypesWorksheet(); |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
$this->workbook->close(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* |
84
|
|
|
*/ |
85
|
|
|
private function getRows() |
86
|
|
|
{ |
87
|
|
|
|
88
|
|
|
if (!isset($this->type_rows)) |
89
|
|
|
{ |
90
|
|
|
|
91
|
|
|
global $babDB; |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
$res = $babDB->db_query(' |
95
|
|
|
SELECT |
96
|
|
|
id, |
97
|
|
|
name |
98
|
|
|
FROM |
99
|
|
|
absences_types |
100
|
|
|
ORDER BY name |
101
|
|
|
'); |
102
|
|
|
|
103
|
|
|
$row = 2; |
104
|
|
|
while ($arr = $babDB->db_fetch_assoc($res)) |
105
|
|
|
{ |
106
|
|
|
$this->type_rows[$arr['id']] = array( |
107
|
|
|
'name' => $arr['name'], |
108
|
|
|
'row' => $row++ |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
return $this->type_rows; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Get row number by id type |
121
|
|
|
*/ |
122
|
|
|
private function getRow($id_type) |
123
|
|
|
{ |
124
|
|
|
$rows = $this->getRows(); |
125
|
|
|
return $rows[$id_type]['row']; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
|
130
|
|
|
|
131
|
|
|
private function getTypeWorksheet() |
132
|
|
|
{ |
133
|
|
|
if (!isset($this->type_worksheet)) |
134
|
|
|
{ |
135
|
|
|
$this->type_worksheet = $this->workbook->addWorksheet(absences_translate('Vacation rights')); |
|
|
|
|
136
|
|
|
|
137
|
|
|
// create first column |
138
|
|
|
$this->type_worksheet->setColumn(0, 0, 30); |
|
|
|
|
139
|
|
|
$this->type_worksheet->writeString(1, 0, absences_translate('Vacation type') , $this->header); |
|
|
|
|
140
|
|
|
|
141
|
|
|
foreach($this->getRows() as $arr) |
|
|
|
|
142
|
|
|
{ |
143
|
|
|
$this->type_worksheet->writeString($arr['row'], 0, $arr['name']); |
|
|
|
|
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return $this->type_worksheet; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
|
152
|
|
|
private function prepareTypeData() |
153
|
|
|
{ |
154
|
|
|
global $babDB; |
155
|
|
|
|
156
|
|
|
$years = array(); |
157
|
|
|
$types = array(); |
158
|
|
|
|
159
|
|
|
$organization = ''; |
160
|
|
|
if(isset($this->filter['organization']) && $this->filter['organization']){ |
161
|
|
|
$organization = 'AND p.id_organization='.$babDB->quote($this->filter['organization']); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$res = $babDB->db_query(' |
165
|
|
|
SELECT |
166
|
|
|
t.id, |
167
|
|
|
YEAR(e.date_begin) year, |
168
|
|
|
SUM(ee.quantity) total, |
169
|
|
|
quantity_unit |
170
|
|
|
FROM |
171
|
|
|
absences_types t, |
172
|
|
|
absences_rights r, |
173
|
|
|
absences_entries_elem ee, |
174
|
|
|
absences_entries e, |
175
|
|
|
absences_personnel p |
176
|
|
|
WHERE r.id_type=t.id |
177
|
|
|
AND ee.id_right=r.id |
178
|
|
|
AND ee.id_entry=e.id |
179
|
|
|
AND e.status=\'Y\' |
180
|
|
|
AND p.id_user=e.id_user |
181
|
|
|
'.$organization.' |
182
|
|
|
GROUP BY year, t.id, r.quantity_unit |
183
|
|
|
ORDER BY year |
184
|
|
|
'); |
185
|
|
|
|
186
|
|
|
while ($arr = $babDB->db_fetch_assoc($res)) |
187
|
|
|
{ |
188
|
|
|
$years[$arr['year']] = $arr['year']; |
189
|
|
|
$types[$arr['id']][$arr['year']][$arr['quantity_unit']] = $arr['total']; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
return array($years, $types); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
protected function addTypesWorksheet() |
198
|
|
|
{ |
199
|
|
|
$worksheet = $this->getTypeWorksheet(); |
200
|
|
|
list($years, $types) = $this->prepareTypeData(); |
201
|
|
|
|
202
|
|
|
$col_index = array(); |
203
|
|
|
|
204
|
|
|
// first an second row |
205
|
|
|
$col = 1; |
206
|
|
|
foreach($years as $y) |
207
|
|
|
{ |
208
|
|
|
$worksheet->mergeCells(0, $col, 0, 1+$col); |
|
|
|
|
209
|
|
|
|
210
|
|
|
$worksheet->setColumn(0, 0, 30); |
|
|
|
|
211
|
|
|
$worksheet->writeString(0, $col, $y , $this->year_format); |
|
|
|
|
212
|
|
|
$col_index[$y]['D'] = $col; |
213
|
|
|
$worksheet->writeString(1, $col++, absences_translate('days') , $this->header); |
|
|
|
|
214
|
|
|
$col_index[$y]['H'] = $col; |
215
|
|
|
$worksheet->writeString(1, $col++, absences_translate('hours') , $this->header); |
|
|
|
|
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
foreach($types as $id_type => $yearly) |
220
|
|
|
{ |
221
|
|
|
$row = $this->getRow($id_type); |
222
|
|
|
foreach($yearly as $year => $quantities) |
223
|
|
|
{ |
224
|
|
|
foreach($quantities as $quantity_unit => $total) |
225
|
|
|
{ |
226
|
|
|
$col = $col_index[$year][$quantity_unit]; |
227
|
|
|
$worksheet->writeNumber($row, $col, $total, $this->quantity); |
|
|
|
|
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: