Completed
Push — feature/refactor_ui ( 5b72cd...525b74 )
by Laurent
01:37
created

readFlights.php (1 issue)

Upgrade to new PHP Analysis Engine

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("/flightlog/flightlog.inc.php");
18
19
use flightlog\query\GetPilotsWithMissionsQuery;
20
use flightlog\query\GetPilotsWithMissionsQueryHandler;
21
22
$langs->load("mymodule@flightlog");
23
24
// Get parameters
25
//TODO get all parameters from here
26
$id = GETPOST('id', 'int');
27
$action = GETPOST('action', 'alpha');
28
$myparam = GETPOST('myparam', 'alpha');
29
30
$unitPriceMission = $conf->global->BBC_FLIGHT_LOG_UNIT_PRICE_MISSION;
31
32
$ctrl = new \FlightLog\Http\Web\Controller\StatisticalGraphController($db);
33
34
// Default action
35
if (empty($action) && empty($id) && empty($ref)) {
36
    $action = 'create';
37
}
38
39
// Load object if id or ref is provided as parameter
40
$object = new Bbcvols($db);
41 View Code Duplication
if (($id > 0 || !empty($ref)) && $action != 'add') {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
42
    $result = $object->fetch($id, $ref);
43
    if ($result < 0) {
44
        dol_print_error($db);
45
    }
46
}
47
48
/*
49
 * ACTIONS
50
 *
51
 * Put here all code to do according to value of "action" parameter
52
 */
53
54
/*
55
 * VIEW
56
 *
57
 * Put here all code to build page
58
 */
59
60
llxHeader('', $langs->trans('Read flights'), '');
61
62
$form = new Form($db);
63
64
// Put here content of your page
65
$data = array();
66
$tmp = array();
67
$legend = array();
68
69
//tableau par pilote
70
$sqlYear = "SELECT DISTINCT(YEAR(llx_bbc_vols.date)) as annee FROM llx_bbc_vols ";
71
$resql_years = $db->query($sqlYear);
72
73
$num = $db->num_rows($resql_years);
74
$i = 0;
75
if ($num) {
76
    print '<div class="tabs">';
77
    print '<a class="tabTitle"><img src="../theme/eldy/img/object_user.png" border="0" alt="" title=""> Recap / utilisateur </a>'; //title
78
79
    while ($i < $num) {
80
        $obj = $db->fetch_object($resql_years); //vol
81
        if ($obj->annee) {
82
            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>';
83
        }
84
        $i++;
85
    }
86
    print '</div>';
87
}
88
89
90
print '<div class="tabBar">';
91
print '<table class="" width="100%">';
92
93
print '<tbody>';
94
print '<tr class="liste_titre">';
95
print '<td colspan="2">Nom</td>';
96
print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 1 : <br/>Sponsor") . '</td>';
97
print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 2 : <br/>Baptême") . '</td>';
98
print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Orga. <br/>(T1/T2)") . '</td>';
99
print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Instructeur <br/>(orga T6)") . '</td>';
100
print '<td class="liste_titre _alignCenter" >' . $langs->trans("Total bonus") . '</td>';
101
print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 3 : <br/>Privé") . '</td>';
102
print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 4: <br/>Meeting") . '</td>';
103
print '<td class="liste_titre _alignCenter" colspan="1">' . $langs->trans("Type 5: <br/>Chambley") . '</td>';
104
print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 6: <br/>instruction") . '</td>';
105
print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Type 7: <br/>vols < 50 ") . '</td>';
106
print '<td class="liste_titre _alignCenter" colspan="2">' . $langs->trans("Réparations") . '</td>';
107
print '<td class="liste_titre _alignCenter" colspan="1">' . $langs->trans("Facture") . '</td>';
108
print '<td class="liste_titre _alignCenter" colspan="1">' . $langs->trans("A payer") . '</td>';
109
print '<tr>';
110
111
print '<tr class="liste_titre">';
112
print '<td colspan="2" class="liste_titre"></td>';
113
114
print '<td class="liste_titre"> # </td>';
115
print '<td class="liste_titre"> Pts </td>';
116
117
print '<td class="liste_titre"> # </td>';
118
print '<td class="liste_titre"> Pts </td>';
119
120
print '<td class="liste_titre"> # </td>';
121
print '<td class="liste_titre"> Pts </td>';
122
123
print '<td class="liste_titre"> # </td>';
124
print '<td class="liste_titre"> Pts </td>';
125
126
print '<td class="liste_titre"> Pts</td>';
127
128
print '<td class="liste_titre"> # </td>';
129
print '<td class="liste_titre"> € </td>';
130
131
print '<td class="liste_titre"> # </td>';
132
print '<td class="liste_titre"> € </td>';
133
134
print '<td class="liste_titre"> # </td>';
135
136
print '<td class="liste_titre"> # </td>';
137
print '<td class="liste_titre"> € </td>';
138
139
// T7
140
print '<td class="liste_titre"> #</td>';
141
print '<td class="liste_titre"> €</td>';
142
143
// Damage
144
print '<td class="liste_titre"> €</td>';
145
print '<td class="liste_titre"> fact. €</td>';
146
147
print '<td class="liste_titre"> € </td>';
148
print '<td class="liste_titre"> Balance (A payer) €</td>';
149
150
print'</tr>';
151
$tableQuery = new BillableFlightQuery(true, (GETPOST("year") ?: date("Y")));
152
$tableQueryHandler = new BillableFlightQueryHandler($db, $conf->global);
153
154
$total = 0;
155
$totalT1 = 0;
156
$totalT2 = 0;
157
$totalT3 = 0;
158
$totalT4 = 0;
159
$totalT5 = 0;
160
$totalT6 = 0;
161
$totalT7 = 0;
162
/**
163
 * @var int   $key
164
 * @var Pilot $pilot
165
 */
166
foreach ($tableQueryHandler->__invoke($tableQuery) as $key => $pilot) {
167
    $total += $pilot->getTotalBill()->getValue();
168
    $totalT1 += $pilot->getCountForType('1')->getCount();
169
    $totalT2 += $pilot->getCountForType('2')->getCount();
170
    $totalT3 += $pilot->getCountForType('3')->getCount();
171
    $totalT4 += $pilot->getCountForType('4')->getCount();
172
    $totalT5 += $pilot->getCountForType('5')->getCount();
173
    $totalT6 += $pilot->getCountForType('6')->getCount();
174
    $totalT7 += $pilot->getCountForType('7')->getCount();
175
176
    print '<tr class="oddeven">';
177
    print '<td>' . $pilot->getId() . '</td>';
178
    print '<td>' . $pilot->getName() . '</td>';
179
180
    print '<td>' . $pilot->getCountForType('1')->getCount() . '</td>';
181
    print '<td>' . $pilot->getCountForType('1')->getCost()->getValue() . '</td>';
182
183
    print '<td>' . $pilot->getCountForType('2')->getCount() . '</td>';
184
    print '<td>' . $pilot->getCountForType('2')->getCost()->getValue() . '</td>';
185
186
    print '<td>' . $pilot->getCountForType('orga')->getCount() . '</td>';
187
    print '<td>' . $pilot->getCountForType('orga')->getCost()->getValue() . '</td>';
188
189
    print '<td>' . $pilot->getCountForType('orga_T6')->getCount() . '</td>';
190
    print '<td>' . $pilot->getCountForType('orga_T6')->getCost()->getValue() . '</td>';
191
192
    print sprintf('<td class="%s">', $pilot->getFlightBonus()->getValue() === 0?'text-muted':'text-bold'). $pilot->getFlightBonus()->getValue() . ' pts</td>';
193
194
    print '<td>' . $pilot->getCountForType('3')->getCount() . '</td>';
195
    print '<td>' . price($pilot->getCountForType('3')->getCost()->getValue()) . '€</td>';
196
197
    print '<td>' . $pilot->getCountForType('4')->getCount() . '</td>';
198
    print '<td>' . price($pilot->getCountForType('4')->getCost()->getValue()) . '€</td>';
199
200
    print '<td>' . $pilot->getCountForType('5')->getCount() . '</td>';
201
202
    print '<td>' . $pilot->getCountForType('6')->getCount() . '</td>';
203
    print '<td>' . price($pilot->getCountForType('6')->getCost()->getValue()) . '€</td>';
204
205
    print '<td>' . $pilot->getCountForType('7')->getCount() . '</td>';
206
    print '<td>' . price($pilot->getCountForType('7')->getCost()->getValue()) . '€</td>';
207
208
    print '<td>' . price($pilot->damageCost()->getValue()) . '€</td>';
209
    print '<td>' . price($pilot->invoicedDamageCost()->getValue()) . '€</td>';
210
211
    print sprintf('<td class="%s">', $pilot->getFlightsCost()->getValue() === 0?'text-muted':'text-bold'). price($pilot->getFlightsCost()->getValue()) . '€ </td>';
212
    print sprintf('<td class="%s">', $pilot->isBillable(FlightBonus::zero())?'text-bold':'text-muted'). price($pilot->getTotalBill()->getValue()) . '€</td>';
213
    print '</tr>';
214
}
215
216
print '<tr class="oddeven">';
217
print '<td></td>';
218
print '<td></td>';
219
220
print '<td>' . $totalT1 . '</td>';
221
print '<td></td>';
222
223
print '<td>' . $totalT2 . '</td>';
224
print '<td>' . '</td>';
225
226
print '<td>' . '</td>';
227
print '<td>' . '</td>';
228
229
print '<td>' . '</td>';
230
print '<td>' . '</td>';
231
232
print '<td><b>' . '</b></td>';
233
234
print '<td>' . $totalT3 . '</td>';
235
print '<td></td>';
236
237
print '<td>' . $totalT4. '</td>';
238
print '<td></td>';
239
240
print '<td>' . $totalT5 . '</td>';
241
242
print '<td>' . $totalT6 . '</td>';
243
print '<td></td>';
244
245
print '<td>' . $totalT7 . '</td>';
246
print '<td></td>';
247
248
print '<td></td>';
249
print '<td></td>';
250
251
print '<td>Total à reçevoir </td>';
252
print "<td>" . price($total) . "€</td>";
253
print '</tr>';
254
255
256
print '</tbody>';
257
print'</table>';
258
259
260
print '<br/>';
261
print '<h3>' . $langs->trans("Remboursement aux pilotes") . '</h3>';
262
263
//table km
264
$tauxRemb = isset($conf->global->BBC_FLIGHT_LOG_TAUX_REMB_KM) ? $conf->global->BBC_FLIGHT_LOG_TAUX_REMB_KM : 0;
265
$year = GETPOST("year", 'int');
266
if(empty($year)){
267
    $year = date('Y');
268
}
269
270
$queryHandler = new GetPilotsWithMissionsQueryHandler($db);
271
$query = new GetPilotsWithMissionsQuery($year);
272
273
printBbcKilometersByQuartil($queryHandler->__invoke($query), $tauxRemb, $unitPriceMission);
274
275
print '</div>';
276
277
print '<br/>';
278
279
print '<div class="tabsAction">';
280
281
282
if ($conf->facture->enabled && $user->rights->flightlog->vol->status && $user->rights->flightlog->vol->financialGenerateDocuments) {
283
    print '<a class="butAction" href="generateBilling.php?year=' . (GETPOST("year",
284
            'int') ?: date("Y")) . '">Générer Factures</a>';
285
}
286
287
if ($conf->expensereport->enabled && $user->rights->flightlog->vol->financialGenerateDocuments) {
288
    print '<a class="butAction" href="generateExpenseNote.php?year=' . (GETPOST("year",
289
            'int') ?: date("Y")) . '">Générer notes de frais</a>';
290
}
291
292
print '</div>';
293
294
295
?>
296
297
    <div class="fichecenter">
298
        <?php include $ctrl->graphByType(getGraphByTypeAndYearData())->getTemplate(); ?>
299
    </div>
300
301
    <div class="fichecenter">
302
        <?php include $ctrl->billableFlightsPerMonth()->getTemplate(); ?>
303
    </div>
304
305
<?php
306
llxFooter();
307