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