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