Completed
Push — master ( 0cae82...3ae2ae )
by Laurent
02:11
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('/core/class/dolgraph.class.php');
18
dol_include_once('/flightlog/class/bbcvols.class.php');
19
dol_include_once('/flightlog/class/bbctypes.class.php');
20
dol_include_once('/flightlog/class/GraphicalData.php');
21
dol_include_once('/flightlog/class/GraphicalType.php');
22
dol_include_once('/flightlog/class/GraphicalValue.php');
23
dol_include_once('/flightlog/class/GraphicalValueType.php');
24
dol_include_once('/flightlog/class/YearGraphicalData.php');
25
26
dol_include_once("/flightlog/lib/flightLog.lib.php");
27
28
29
30
$langs->load("mymodule@flightlog");
31
32
// Get parametersI
33
//TODO get all parameters from here
34
$id = GETPOST('id', 'int');
35
$action = GETPOST('action', 'alpha');
36
$myparam = GETPOST('myparam', 'alpha');
37
38
$unitPriceMission = $conf->global->BBC_FLIGHT_LOG_UNIT_PRICE_MISSION;
39
40
//variables
41
$WIDTH = DolGraph::getDefaultGraphSizeForStats('width', 768);
42
$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
43
44
$year = strftime("%Y", dol_now());
45
$dir = $conf->expensereport->dir_temp;
46
47
$filenamenb = $dir . "/test2-" . $year . ".png";
48
$fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=flightlog&amp;file=' . $fileurlnb;
49
50
$graphByTypeAndYear = new DolGraph();
51
$mesg = $graphByTypeAndYear->isGraphKo();
52
if (!$mesg) {
53
    $data = getGraphByTypeAndYearData();
54
    $graphByTypeAndYear->SetData($data->export());
55
    $graphByTypeAndYear->SetPrecisionY(0);
56
57
    $legend = [];
58
    $graphByTypeAndYear->type = [];
59
    foreach (fetchBbcFlightTypes() as $flightType) {
60
61
        if (!in_array($flightType->numero, [1, 2, 3, 6])) {
62
            continue;
63
        }
64
65
        $legend[] = $flightType->nom;
66
        $graphByTypeAndYear->type[] = "lines";
67
    }
68
    $graphByTypeAndYear->SetLegend($legend);
69
    $graphByTypeAndYear->SetMaxValue($graphByTypeAndYear->GetCeilMaxValue());
70
    $graphByTypeAndYear->SetWidth($WIDTH + 100);
71
    $graphByTypeAndYear->SetHeight($HEIGHT);
72
    $graphByTypeAndYear->SetYLabel($langs->trans("YEAR"));
73
    $graphByTypeAndYear->SetShading(3);
74
    $graphByTypeAndYear->SetHorizTickIncrement(1);
75
    $graphByTypeAndYear->SetPrecisionY(0);
76
77
    $graphByTypeAndYear->SetTitle($langs->trans("Par type et par année"));
78
79
    $graphByTypeAndYear->draw($filenamenb, $fileurlnb);
80
}
81
82
// Default action
83
if (empty($action) && empty($id) && empty($ref)) {
84
    $action = 'create';
85
}
86
87
// Load object if id or ref is provided as parameter
88
$object = new Bbcvols($db);
89 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...
90
    $result = $object->fetch($id, $ref);
91
    if ($result < 0) {
92
        dol_print_error($db);
93
    }
94
}
95
96
/*
97
 * ACTIONS
98
 *
99
 * Put here all code to do according to value of "action" parameter
100
 */
101
102
/*
103
 * VIEW
104
 *
105
 * Put here all code to build page
106
 */
107
108
llxHeader('', $langs->trans('Read flights'), '');
109
110
$form = new Form($db);
111
112
// Put here content of your page
113
$data = array();
114
$tmp = array();
115
$legend = array();
116
117
//tableau par pilote
118
$sql = "SELECT USR.lastname AS nom , USR.firstname AS prenom ,COUNT(`idBBC_vols`) AS nbr,fk_pilot as pilot, TT.numero as type,SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(heureA,heureD)))) AS time";
119
$sql .= " FROM llx_bbc_vols, llx_user AS USR,llx_bbc_types AS TT ";
120
$sql .= " WHERE `fk_pilot`= USR.rowid AND fk_type = TT.idType AND YEAR(llx_bbc_vols.date) = " . (GETPOST("year") ? "'" . GETPOST("year") . "'" : 'YEAR(NOW())');
121
$sql .= " GROUP BY fk_pilot,`fk_type`";
122
123
$resql = $db->query($sql);
124
125
$sqlYear = "SELECT DISTINCT(YEAR(llx_bbc_vols.date)) as annee FROM llx_bbc_vols ";
126
$resql_years = $db->query($sqlYear);
127
128
$pilotNumberFlight = array();
129
if ($resql) {
130
131
    $num = $db->num_rows($resql_years);
132
    $i = 0;
133
    if ($num) {
134
        print '<div class="tabs">';
135
        print '<a class="tabTitle"><img src="../theme/eldy/img/object_user.png" border="0" alt="" title=""> Recap / utilisateur </a>'; //title
136
137
        while ($i < $num) {
138
            $obj = $db->fetch_object($resql_years); //vol
139
            if ($obj->annee) {
140
                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>';
141
            }
142
            $i++;
143
        }
144
        print '</div>';
145
    }
146
147
148
    print '<div class="tabBar">';
149
    print '<table class="" width="100%">';
150
151
    print '<tbody>';
152
    print '<tr class="liste_titre">';
153
    print '<td colspan="2">Nom</td>';
154
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 1 : Sponsor") . '</td>';
155
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 2 : Baptême") . '</td>';
156
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Organisateur (T1/T2)") . '</td>';
157
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Instructeur (orga T6)") . '</td>';
158
    print '<td class="liste_titre" >'            . $langs->trans("Total bonus") . '</td>';
159
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 3 : Privé") . '</td>';
160
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 4: Meeting") . '</td>';
161
    print '<td class="liste_titre" colspan="1">' . $langs->trans("Type 5: Chambley") . '</td>';
162
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 6: instruction") . '</td>';
163
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 7: vols < 50 ") . '</td>';
164
    print '<td class="liste_titre" colspan="1">' . $langs->trans("Facture") . '</td>';
165
    print '<td class="liste_titre" colspan="1">' . $langs->trans("A payer") . '</td>';
166
    print '<tr>';
167
168
    print '<tr class="liste_titre">';
169
    print '<td colspan="2" class="liste_titre"></td>';
170
171
    print '<td class="liste_titre"> # </td>';
172
    print '<td class="liste_titre"> Pts </td>';
173
174
    print '<td class="liste_titre"> # </td>';
175
    print '<td class="liste_titre"> Pts </td>';
176
177
    print '<td class="liste_titre"> # </td>';
178
    print '<td class="liste_titre"> Pts </td>';
179
180
    print '<td class="liste_titre"> # </td>';
181
    print '<td class="liste_titre"> Pts </td>';
182
183
    print '<td class="liste_titre"> Bonus gagnés </td>';
184
185
    print '<td class="liste_titre"> # </td>';
186
    print '<td class="liste_titre"> € </td>';
187
188
    print '<td class="liste_titre"> # </td>';
189
    print '<td class="liste_titre"> € </td>';
190
191
    print '<td class="liste_titre"> # </td>';
192
193
    print '<td class="liste_titre"> # </td>';
194
    print '<td class="liste_titre"> € </td>';
195
196
    print '<td class="liste_titre"> #</td>';
197
    print '<td class="liste_titre"> €</td>';
198
199
    print '<td class="liste_titre"> € </td>';
200
    print '<td class="liste_titre"> Balance (A payer) €</td>';
201
202
    print'</tr>';
203
    $table = sqlToArray($db, $sql, true, (GETPOST("year") ?: date("Y")));
204
    $total = 0;
205
    foreach ($table as $key => $value) {
206
207
        $totalBonus = $value['1']['count'] * 50 + $value['2']['count'] * 50 + $value['orga']['count'] * 25 + $value['orga_T6']['count'] * 50;
208
        $totalFacture = $value['3']['count'] * 150 + $value['4']['count'] * 100 + $value['6']['count'] * 50 + $value['7']['count'] * 75;
209
        $facturable = ($totalFacture - $totalBonus < 0 ? 0 : $totalFacture - $totalBonus);
210
        $total += $facturable;
211
212
        $pilotNumberFlight[$value['id']] = array(
213
            "1" => $value['1']['count'],
214
            "2" => $value['2']['count'],
215
            "3" => $value['3']['count'],
216
            "4" => $value['4']['count'],
217
            "5" => $value['5']['count'],
218
            "6" => $value['6']['count'],
219
            "7" => $value['7']['count'],
220
        );
221
222
        print '<tr class="oddeven">';
223
        print '<td>' . $key . '</td>';
224
        print '<td>' . $value['name'] . '</td>';
225
226
        print '<td>' . $value['1']['count'] . '</td>';
227
        print '<td>' . $value['1']['count'] * 50 . '</td>';
228
229
        print '<td>' . $value['2']['count'] . '</td>';
230
        print '<td>' . $value['2']['count'] * 50 . '</td>';
231
232
        print '<td>' . $value['orga']['count'] . '</td>';
233
        print '<td>' . $value['orga']['count'] * 25 . '</td>';
234
235
        print '<td>' . $value['orga_T6']['count'] . '</td>';
236
        print '<td>' . $value['orga_T6']['count'] * 50 . '</td>';
237
238
        print '<td><b>' . ($totalBonus) . '</b></td>';
239
240
        print '<td>' . $value['3']['count'] . '</td>';
241
        print '<td>' . price($value['3']['count'] * 150) . '€</td>';
242
243
        print '<td>' . $value['4']['count'] . '</td>';
244
        print '<td>' . price($value['4']['count'] * 100) . '€</td>';
245
246
        print '<td>' . $value['5']['count'] . '</td>';
247
248
        print '<td>' . $value['6']['count'] . '</td>';
249
        print '<td>' . price($value['6']['count'] * 50) . '€</td>';
250
251
        print '<td>' . $value['7']['count'] . '</td>';
252
        print '<td>' . price($value['7']['count'] * 75) . '€</td>';
253
254
        print '<td>' . price($totalFacture) . '€ </td>';
255
        print '<td><b>' . price($facturable) . '€</b></td>';
256
        print '</tr>';
257
    }
258
259
    print "<tr>";
260
    print "<td colspan='20'></td>";
261
    print "<td>Total à reçevoir</td>";
262
    print "<td>".price($total)."€</td>";
263
    print "</tr>";
264
265
    print '</tbody>';
266
    print'</table>';
267
268
269
    print '<br/>';
270
    print '<h3>' . $langs->trans("Remboursement aux pilotes") . '</h3>';
271
272
    //table km
273
    $tauxRemb = isset($conf->global->BBC_FLIGHT_LOG_TAUX_REMB_KM) ? $conf->global->BBC_FLIGHT_LOG_TAUX_REMB_KM : 0;
274
    $year = GETPOST("year", 'int');
275
276
    $kmByQuartil = bbcKilometersByQuartil($year);
277
278
    printBbcKilometersByQuartil($kmByQuartil, $tauxRemb, $unitPriceMission);
279
280
    print '</div>';
281
282
283
}
284
print '<br/>';
285
286
print '<div class="tabsAction">';
287
288
289
if ($conf->facture->enabled && $user->rights->flightlog->vol->status && $user->rights->flightlog->vol->financialGenerateDocuments) {
290
    print '<a class="butAction" href="generateBilling.php?year=' . (GETPOST("year",
291
            'int') ?: date("Y")) . '">Générer Factures</a>';
292
}
293
294
if ($conf->expensereport->enabled && $user->rights->flightlog->vol->financialGenerateDocuments) {
295
    print '<a class="butAction" href="generateExpenseNote.php?year=' . (GETPOST("year",
296
            'int') ?: date("Y")) . '">Générer notes de frais</a>';
297
}
298
299
print '</div>';
300
301
302
?>
303
304
305
    <div class="fichecenter">
306
        <?php print $graphByTypeAndYear->show(); ?>
307
    </div>
308
309
<?php
310
llxFooter();
311