Completed
Push — master ( 6abb53...f63f4b )
by Laurent
02:02
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="border" width="100%">';
150
151
    print '<tr class="liste_titre">';
152
    print '<td colspan="2">Nom</td>';
153
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 1 : Sponsor") . '</td>';
154
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 2 : Baptême") . '</td>';
155
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Organisateur (T1/T2)") . '</td>';
156
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Instructeur (orga T6)") . '</td>';
157
    print '<td class="liste_titre" >'            . $langs->trans("Total bonus") . '</td>';
158
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 3 : Privé") . '</td>';
159
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 4: Meeting") . '</td>';
160
    print '<td class="liste_titre" colspan="1">' . $langs->trans("Type 5: Chambley") . '</td>';
161
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 6: instruction") . '</td>';
162
    print '<td class="liste_titre" colspan="2">' . $langs->trans("Type 7: vols < 50 ") . '</td>';
163
    print '<td class="liste_titre" colspan="1">' . $langs->trans("Facture") . '</td>';
164
    print '<td class="liste_titre" colspan="1">' . $langs->trans("A payer") . '</td>';
165
    print '<tr>';
166
167
    print '<tr class="liste_titre">';
168
    print '<td colspan="2" class="liste_titre"></td>';
169
170
    print '<td class="liste_titre"> # </td>';
171
    print '<td class="liste_titre"> Pts </td>';
172
173
    print '<td class="liste_titre"> # </td>';
174
    print '<td class="liste_titre"> Pts </td>';
175
176
    print '<td class="liste_titre"> # </td>';
177
    print '<td class="liste_titre"> Pts </td>';
178
179
    print '<td class="liste_titre"> # </td>';
180
    print '<td class="liste_titre"> Pts </td>';
181
182
    print '<td class="liste_titre"> Bonus gagnés </td>';
183
184
    print '<td class="liste_titre"> # </td>';
185
    print '<td class="liste_titre"> € </td>';
186
187
    print '<td class="liste_titre"> # </td>';
188
    print '<td class="liste_titre"> € </td>';
189
190
    print '<td class="liste_titre"> # </td>';
191
192
    print '<td class="liste_titre"> # </td>';
193
    print '<td class="liste_titre"> € </td>';
194
195
    print '<td class="liste_titre"> #</td>';
196
    print '<td class="liste_titre"> €</td>';
197
198
    print '<td class="liste_titre"> € </td>';
199
    print '<td class="liste_titre"> Balance (A payer) €</td>';
200
201
    print'</tr>';
202
    $table = sqlToArray($db, $sql, true, (GETPOST("year") ?: date("Y")));
203
    $total = 0;
204
    foreach ($table as $key => $value) {
205
206
        $totalBonus = $value['1']['count'] * 50 + $value['2']['count'] * 50 + $value['orga']['count'] * 25 + $value['orga_T6']['count'] * 50;
207
        $totalFacture = $value['3']['count'] * 150 + $value['4']['count'] * 100 + $value['6']['count'] * 50 + $value['7']['count'] * 75;
208
        $facturable = ($totalFacture - $totalBonus < 0 ? 0 : $totalFacture - $totalBonus);
209
        $total += $facturable;
210
211
        $pilotNumberFlight[$value['id']] = array(
212
            "1" => $value['1']['count'],
213
            "2" => $value['2']['count'],
214
            "3" => $value['3']['count'],
215
            "4" => $value['4']['count'],
216
            "5" => $value['5']['count'],
217
            "6" => $value['6']['count'],
218
            "7" => $value['7']['count'],
219
        );
220
221
        print '<tr>';
222
        print '<td>' . $key . '</td>';
223
        print '<td>' . $value['name'] . '</td>';
224
225
        print '<td>' . $value['1']['count'] . '</td>';
226
        print '<td>' . $value['1']['count'] * 50 . '</td>';
227
228
        print '<td>' . $value['2']['count'] . '</td>';
229
        print '<td>' . $value['2']['count'] * 50 . '</td>';
230
231
        print '<td>' . $value['orga']['count'] . '</td>';
232
        print '<td>' . $value['orga']['count'] * 25 . '</td>';
233
234
        print '<td>' . $value['orga_T6']['count'] . '</td>';
235
        print '<td>' . $value['orga_T6']['count'] * 50 . '</td>';
236
237
        print '<td><b>' . ($totalBonus) . '</b></td>';
238
239
        print '<td>' . $value['3']['count'] . '</td>';
240
        print '<td>' . price($value['3']['count'] * 150) . '€</td>';
241
242
        print '<td>' . $value['4']['count'] . '</td>';
243
        print '<td>' . price($value['4']['count'] * 100) . '€</td>';
244
245
        print '<td>' . $value['5']['count'] . '</td>';
246
247
        print '<td>' . $value['6']['count'] . '</td>';
248
        print '<td>' . price($value['6']['count'] * 50) . '€</td>';
249
250
        print '<td>' . $value['7']['count'] . '</td>';
251
        print '<td>' . price($value['7']['count'] * 75) . '€</td>';
252
253
        print '<td>' . price($totalFacture) . '€ </td>';
254
        print '<td><b>' . price($facturable) . '€</b></td>';
255
        print '</tr>';
256
    }
257
258
    print "<tr>";
259
    print "<td colspan='20'></td>";
260
    print "<td>Total à reçevoir</td>";
261
    print "<td>".price($total)."€</td>";
262
    print "</tr>";
263
264
265
    print'</table>';
266
267
268
    print '<br/>';
269
    print '<h3>' . $langs->trans("Remboursement aux pilotes") . '</h3>';
270
271
    //table km
272
    $tauxRemb = isset($conf->global->BBC_FLIGHT_LOG_TAUX_REMB_KM) ? $conf->global->BBC_FLIGHT_LOG_TAUX_REMB_KM : 0;
273
    $year = GETPOST("year", 'int');
274
275
    $kmByQuartil = bbcKilometersByQuartil($year);
276
277
    printBbcKilometersByQuartil($kmByQuartil, $tauxRemb, $unitPriceMission);
278
279
    print '</div>';
280
281
282
}
283
print '<br/>';
284
285
print '<div class="tabsAction">';
286
287
288
if ($conf->facture->enabled && $user->rights->flightlog->vol->status && $user->rights->flightlog->vol->financialGenerateDocuments) {
289
    print '<a class="butAction" href="generateBilling.php?year=' . (GETPOST("year",
290
            'int') ?: date("Y")) . '">Générer Factures</a>';
291
}
292
293
if ($conf->expensereport->enabled && $user->rights->flightlog->vol->financialGenerateDocuments) {
294
    print '<a class="butAction" href="generateExpenseNote.php?year=' . (GETPOST("year",
295
            'int') ?: date("Y")) . '">Générer notes de frais</a>';
296
}
297
298
print '</div>';
299
300
301
?>
302
303
304
    <div class="fichecenter">
305
        <?php print $graphByTypeAndYear->show(); ?>
306
    </div>
307
308
<?php
309
llxFooter();
310