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