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