These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * \file mypage.php |
||
4 | * \ingroup mymodule |
||
5 | * \brief Example PHP page. |
||
6 | * |
||
7 | * read flights |
||
8 | */ |
||
9 | |||
10 | // Load Dolibarr environment |
||
11 | if (false === (@include '../main.inc.php')) { // From htdocs directory |
||
12 | require '../../documents/custom/main.inc.php'; // From "custom" directory |
||
13 | } |
||
14 | |||
15 | global $db, $langs, $user, $conf; |
||
16 | |||
17 | dol_include_once('/core/class/dolgraph.class.php'); |
||
18 | dol_include_once("/flightlog/flightlog.inc.php"); |
||
19 | |||
20 | use flightlog\query\GetPilotsWithMissionsQuery; |
||
21 | use flightlog\query\GetPilotsWithMissionsQueryHandler; |
||
22 | |||
23 | $langs->load("mymodule@flightlog"); |
||
24 | |||
25 | // Get parameters |
||
26 | //TODO get all parameters from here |
||
27 | $id = GETPOST('id', 'int'); |
||
28 | $action = GETPOST('action', 'alpha'); |
||
29 | $myparam = GETPOST('myparam', 'alpha'); |
||
30 | |||
31 | $unitPriceMission = $conf->global->BBC_FLIGHT_LOG_UNIT_PRICE_MISSION; |
||
32 | |||
33 | //variables |
||
34 | $WIDTH = DolGraph::getDefaultGraphSizeForStats('width', 768); |
||
35 | $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height'); |
||
36 | |||
37 | $year = strftime("%Y", dol_now()); |
||
38 | $dir = $conf->expensereport->dir_temp; |
||
39 | |||
40 | $filenamenb = $dir . "/test2-" . $year . ".png"; |
||
41 | $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=flightlog&file=' . $fileurlnb; |
||
42 | |||
43 | $graphByTypeAndYear = new DolGraph(); |
||
44 | $mesg = $graphByTypeAndYear->isGraphKo(); |
||
45 | if (!$mesg) { |
||
46 | $data = getGraphByTypeAndYearData(); |
||
47 | $graphByTypeAndYear->SetData($data->export()); |
||
48 | $graphByTypeAndYear->SetPrecisionY(0); |
||
49 | |||
50 | $legend = []; |
||
51 | $graphByTypeAndYear->type = []; |
||
52 | foreach (fetchBbcFlightTypes() as $flightType) { |
||
53 | |||
54 | if (!in_array($flightType->numero, [1, 2, 3, 6])) { |
||
55 | continue; |
||
56 | } |
||
57 | |||
58 | $legend[] = $flightType->nom; |
||
59 | $graphByTypeAndYear->type[] = "lines"; |
||
60 | } |
||
61 | $graphByTypeAndYear->SetLegend($legend); |
||
62 | $graphByTypeAndYear->SetMaxValue($graphByTypeAndYear->GetCeilMaxValue()); |
||
63 | $graphByTypeAndYear->SetWidth($WIDTH + 100); |
||
64 | $graphByTypeAndYear->SetHeight($HEIGHT); |
||
65 | $graphByTypeAndYear->SetYLabel($langs->trans("YEAR")); |
||
66 | $graphByTypeAndYear->SetShading(3); |
||
67 | $graphByTypeAndYear->SetHorizTickIncrement(1); |
||
68 | $graphByTypeAndYear->SetPrecisionY(0); |
||
69 | |||
70 | $graphByTypeAndYear->SetTitle($langs->trans("Par type et par année")); |
||
71 | |||
72 | $graphByTypeAndYear->draw($filenamenb, $fileurlnb); |
||
73 | } |
||
74 | |||
75 | // Default action |
||
76 | if (empty($action) && empty($id) && empty($ref)) { |
||
77 | $action = 'create'; |
||
78 | } |
||
79 | |||
80 | // Load object if id or ref is provided as parameter |
||
81 | $object = new Bbcvols($db); |
||
82 | View Code Duplication | if (($id > 0 || !empty($ref)) && $action != 'add') { |
|
0 ignored issues
–
show
|
|||
83 | $result = $object->fetch($id, $ref); |
||
84 | if ($result < 0) { |
||
85 | dol_print_error($db); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | /* |
||
90 | * ACTIONS |
||
91 | * |
||
92 | * Put here all code to do according to value of "action" parameter |
||
93 | */ |
||
94 | |||
95 | /* |
||
96 | * VIEW |
||
97 | * |
||
98 | * Put here all code to build page |
||
99 | */ |
||
100 | |||
101 | llxHeader('', $langs->trans('Read flights'), ''); |
||
102 | |||
103 | $form = new Form($db); |
||
104 | |||
105 | // Put here content of your page |
||
106 | $data = array(); |
||
107 | $tmp = array(); |
||
108 | $legend = array(); |
||
109 | |||
110 | //tableau par pilote |
||
111 | $sqlYear = "SELECT DISTINCT(YEAR(llx_bbc_vols.date)) as annee FROM llx_bbc_vols "; |
||
112 | $resql_years = $db->query($sqlYear); |
||
113 | |||
114 | $num = $db->num_rows($resql_years); |
||
115 | $i = 0; |
||
116 | if ($num) { |
||
117 | print '<div class="tabs">'; |
||
118 | print '<a class="tabTitle"><img src="../theme/eldy/img/object_user.png" border="0" alt="" title=""> Recap / utilisateur </a>'; //title |
||
119 | |||
120 | while ($i < $num) { |
||
121 | $obj = $db->fetch_object($resql_years); //vol |
||
122 | if ($obj->annee) { |
||
123 | print '<a class="tab" id="' . (GETPOST("year") == $obj->annee || (!GETPOST("year") && $obj->annee == date("Y")) ? 'active' : '') . '" " href="readFlights.php?year=' . $obj->annee . '">' . $obj->annee . '</a>'; |
||
124 | } |
||
125 | $i++; |
||
126 | } |
||
127 | print '</div>'; |
||
128 | } |
||
129 | |||
130 | |||
131 | print '<div class="tabBar">'; |
||
132 | print '<table class="" width="100%">'; |
||
133 | |||
134 | print '<tbody>'; |
||
135 | print '<tr class="liste_titre">'; |
||
136 | print '<td colspan="2">Nom</td>'; |
||
137 | print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 1 : <br/>Sponsor") . '</td>'; |
||
138 | print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 2 : <br/>Baptême") . '</td>'; |
||
139 | print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Orga. <br/>(T1/T2)") . '</td>'; |
||
140 | print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Instructeur <br/>(orga T6)") . '</td>'; |
||
141 | print '<td class="liste_titre _alignCenter" >' . $langs->trans("Total bonus") . '</td>'; |
||
142 | print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 3 : <br/>Privé") . '</td>'; |
||
143 | print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 4: <br/>Meeting") . '</td>'; |
||
144 | print '<td class="liste_titre _alignCenter" colspan="1">' . $langs->trans("Type 5: <br/>Chambley") . '</td>'; |
||
145 | print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 6: <br/>instruction") . '</td>'; |
||
146 | print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 7: <br/>vols < 50 ") . '</td>'; |
||
147 | print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Réparations") . '</td>'; |
||
148 | print '<td class="liste_titre _alignCenter" colspan="1">' . $langs->trans("Facture") . '</td>'; |
||
149 | print '<td class="liste_titre _alignCenter" colspan="1">' . $langs->trans("A payer") . '</td>'; |
||
150 | print '<tr>'; |
||
151 | |||
152 | print '<tr class="liste_titre">'; |
||
153 | print '<td colspan="2" class="liste_titre"></td>'; |
||
154 | |||
155 | print '<td class="liste_titre"> # </td>'; |
||
156 | print '<td class="liste_titre"> Pts </td>'; |
||
157 | |||
158 | print '<td class="liste_titre"> # </td>'; |
||
159 | print '<td class="liste_titre"> Pts </td>'; |
||
160 | |||
161 | print '<td class="liste_titre"> # </td>'; |
||
162 | print '<td class="liste_titre"> Pts </td>'; |
||
163 | |||
164 | print '<td class="liste_titre"> # </td>'; |
||
165 | print '<td class="liste_titre"> Pts </td>'; |
||
166 | |||
167 | print '<td class="liste_titre"> Pts</td>'; |
||
168 | |||
169 | print '<td class="liste_titre"> # </td>'; |
||
170 | print '<td class="liste_titre"> € </td>'; |
||
171 | |||
172 | print '<td class="liste_titre"> # </td>'; |
||
173 | print '<td class="liste_titre"> € </td>'; |
||
174 | |||
175 | print '<td class="liste_titre"> # </td>'; |
||
176 | |||
177 | print '<td class="liste_titre"> # </td>'; |
||
178 | print '<td class="liste_titre"> € </td>'; |
||
179 | |||
180 | // T7 |
||
181 | print '<td class="liste_titre"> #</td>'; |
||
182 | print '<td class="liste_titre"> €</td>'; |
||
183 | |||
184 | // Damage |
||
185 | print '<td class="liste_titre"> €</td>'; |
||
186 | print '<td class="liste_titre"> fact. €</td>'; |
||
187 | |||
188 | print '<td class="liste_titre"> € </td>'; |
||
189 | print '<td class="liste_titre"> Balance (A payer) €</td>'; |
||
190 | |||
191 | print'</tr>'; |
||
192 | $tableQuery = new BillableFlightQuery(true, (GETPOST("year") ?: date("Y"))); |
||
193 | $tableQueryHandler = new BillableFlightQueryHandler($db, $conf->global); |
||
194 | |||
195 | $total = 0; |
||
196 | $totalT1 = 0; |
||
197 | $totalT2 = 0; |
||
198 | $totalT3 = 0; |
||
199 | $totalT4 = 0; |
||
200 | $totalT5 = 0; |
||
201 | $totalT6 = 0; |
||
202 | $totalT7 = 0; |
||
203 | /** |
||
204 | * @var int $key |
||
205 | * @var Pilot $pilot |
||
206 | */ |
||
207 | foreach ($tableQueryHandler->__invoke($tableQuery) as $key => $pilot) { |
||
208 | $total += $pilot->getTotalBill()->getValue(); |
||
209 | $totalT1 += $pilot->getCountForType('1')->getCount(); |
||
210 | $totalT2 += $pilot->getCountForType('2')->getCount(); |
||
211 | $totalT3 += $pilot->getCountForType('3')->getCount(); |
||
212 | $totalT4 += $pilot->getCountForType('4')->getCount(); |
||
213 | $totalT5 += $pilot->getCountForType('5')->getCount(); |
||
214 | $totalT6 += $pilot->getCountForType('6')->getCount(); |
||
215 | $totalT7 += $pilot->getCountForType('7')->getCount(); |
||
216 | |||
217 | print '<tr class="oddeven">'; |
||
218 | print '<td>' . $pilot->getId() . '</td>'; |
||
219 | print '<td>' . $pilot->getName() . '</td>'; |
||
220 | |||
221 | print '<td>' . $pilot->getCountForType('1')->getCount() . '</td>'; |
||
222 | print '<td>' . $pilot->getCountForType('1')->getCost()->getValue() . '</td>'; |
||
223 | |||
224 | print '<td>' . $pilot->getCountForType('2')->getCount() . '</td>'; |
||
225 | print '<td>' . $pilot->getCountForType('2')->getCost()->getValue() . '</td>'; |
||
226 | |||
227 | print '<td>' . $pilot->getCountForType('orga')->getCount() . '</td>'; |
||
228 | print '<td>' . $pilot->getCountForType('orga')->getCost()->getValue() . '</td>'; |
||
229 | |||
230 | print '<td>' . $pilot->getCountForType('orga_T6')->getCount() . '</td>'; |
||
231 | print '<td>' . $pilot->getCountForType('orga_T6')->getCost()->getValue() . '</td>'; |
||
232 | |||
233 | print sprintf('<td class="%s">', $pilot->getFlightBonus()->getValue() === 0?'text-muted':'text-bold'). $pilot->getFlightBonus()->getValue() . ' pts</td>'; |
||
234 | |||
235 | print '<td>' . $pilot->getCountForType('3')->getCount() . '</td>'; |
||
236 | print '<td>' . price($pilot->getCountForType('3')->getCost()->getValue()) . '€</td>'; |
||
237 | |||
238 | print '<td>' . $pilot->getCountForType('4')->getCount() . '</td>'; |
||
239 | print '<td>' . price($pilot->getCountForType('4')->getCost()->getValue()) . '€</td>'; |
||
240 | |||
241 | print '<td>' . $pilot->getCountForType('5')->getCount() . '</td>'; |
||
242 | |||
243 | print '<td>' . $pilot->getCountForType('6')->getCount() . '</td>'; |
||
244 | print '<td>' . price($pilot->getCountForType('6')->getCost()->getValue()) . '€</td>'; |
||
245 | |||
246 | print '<td>' . $pilot->getCountForType('7')->getCount() . '</td>'; |
||
247 | print '<td>' . price($pilot->getCountForType('7')->getCost()->getValue()) . '€</td>'; |
||
248 | |||
249 | print '<td>' . price($pilot->getCountForType('damage')->getCost()->getValue()) . '€</td>'; |
||
250 | print '<td>' . price($pilot->getCountForType('invoiced_damage')->getCost()->getValue()) . '€</td>'; |
||
251 | |||
252 | print sprintf('<td class="%s">', $pilot->getFlightsCost()->getValue() === 0?'text-muted':'text-bold'). price($pilot->getFlightsCost()->getValue()) . '€ </td>'; |
||
253 | print sprintf('<td class="%s">', $pilot->isBillable(FlightBonus::zero())?'text-bold':'text-muted'). price($pilot->getTotalBill()->getValue()) . '€</td>'; |
||
254 | print '</tr>'; |
||
255 | } |
||
256 | |||
257 | print '<tr class="oddeven">'; |
||
258 | print '<td></td>'; |
||
259 | print '<td></td>'; |
||
260 | |||
261 | print '<td>' . $totalT1 . '</td>'; |
||
262 | print '<td></td>'; |
||
263 | |||
264 | print '<td>' . $totalT2 . '</td>'; |
||
265 | print '<td>' . '</td>'; |
||
266 | |||
267 | print '<td>' . '</td>'; |
||
268 | print '<td>' . '</td>'; |
||
269 | |||
270 | print '<td>' . '</td>'; |
||
271 | print '<td>' . '</td>'; |
||
272 | |||
273 | print '<td><b>' . '</b></td>'; |
||
274 | |||
275 | print '<td>' . $totalT3 . '</td>'; |
||
276 | print '<td></td>'; |
||
277 | |||
278 | print '<td>' . $totalT4. '</td>'; |
||
279 | print '<td></td>'; |
||
280 | |||
281 | print '<td>' . $totalT5 . '</td>'; |
||
282 | |||
283 | print '<td>' . $totalT6 . '</td>'; |
||
284 | print '<td></td>'; |
||
285 | |||
286 | print '<td>' . $totalT7 . '</td>'; |
||
287 | print '<td></td>'; |
||
288 | |||
289 | print '<td></td>'; |
||
290 | print '<td></td>'; |
||
291 | |||
292 | print '<td>Total à reçevoir </td>'; |
||
293 | print "<td>" . price($total) . "€</td>"; |
||
294 | print '</tr>'; |
||
295 | |||
296 | |||
297 | print '</tbody>'; |
||
298 | print'</table>'; |
||
299 | |||
300 | |||
301 | print '<br/>'; |
||
302 | print '<h3>' . $langs->trans("Remboursement aux pilotes") . '</h3>'; |
||
303 | |||
304 | //table km |
||
305 | $tauxRemb = isset($conf->global->BBC_FLIGHT_LOG_TAUX_REMB_KM) ? $conf->global->BBC_FLIGHT_LOG_TAUX_REMB_KM : 0; |
||
306 | $year = GETPOST("year", 'int'); |
||
307 | if(empty($year)){ |
||
308 | $year = date('Y'); |
||
309 | } |
||
310 | |||
311 | $queryHandler = new GetPilotsWithMissionsQueryHandler($db); |
||
312 | $query = new GetPilotsWithMissionsQuery($year); |
||
313 | |||
314 | printBbcKilometersByQuartil($queryHandler->__invoke($query), $tauxRemb, $unitPriceMission); |
||
315 | |||
316 | print '</div>'; |
||
317 | |||
318 | print '<br/>'; |
||
319 | |||
320 | print '<div class="tabsAction">'; |
||
321 | |||
322 | |||
323 | if ($conf->facture->enabled && $user->rights->flightlog->vol->status && $user->rights->flightlog->vol->financialGenerateDocuments) { |
||
324 | print '<a class="butAction" href="generateBilling.php?year=' . (GETPOST("year", |
||
325 | 'int') ?: date("Y")) . '">Générer Factures</a>'; |
||
326 | } |
||
327 | |||
328 | if ($conf->expensereport->enabled && $user->rights->flightlog->vol->financialGenerateDocuments) { |
||
329 | print '<a class="butAction" href="generateExpenseNote.php?year=' . (GETPOST("year", |
||
330 | 'int') ?: date("Y")) . '">Générer notes de frais</a>'; |
||
331 | } |
||
332 | |||
333 | print '</div>'; |
||
334 | |||
335 | |||
336 | ?> |
||
337 | |||
338 | |||
339 | <div class="fichecenter"> |
||
340 | <?php print $graphByTypeAndYear->show(); ?> |
||
341 | </div> |
||
342 | |||
343 | <?php |
||
344 | llxFooter(); |
||
345 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.