-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddFlight.php
executable file
·541 lines (454 loc) · 21.8 KB
/
addFlight.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
<?php
// Load Dolibarr environment
if (false === (@include '../main.inc.php')) { // From htdocs directory
require '../../documents/custom/main.inc.php'; // From "custom" directory
}
global $db, $langs, $user, $conf;
dol_include_once('/commande/class/commande.class.php');
dol_include_once('/flightlog/class/bbcvols.class.php');
dol_include_once('/flightlog/class/bbctypes.class.php');
dol_include_once("/flightlog/lib/flightLog.lib.php");
dol_include_once("/flightlog/flightlog.inc.php");
// Load translation files required by the page
$langs->load("mymodule@flightlog");
$validator = new FlightValidator($langs, $db, $conf->global->BBC_FLIGHT_TYPE_CUSTOMER, $user->id);
$createFlightHandler = new CreateFlightCommandHandler($db, $conf, $user, $langs, $validator);
if (!$user->rights->flightlog->vol->add) {
accessforbidden();
}
/* * *****************************************************************
* ACTIONS
*
* Put here all code to do according to value of "action" parameter
* ****************************************************************** */
$msg = '';
if (GETPOST("action") == 'add') {
if (!$_POST["cancel"]) {
$isGroupedFlight = (int) GETPOST('grouped_flight', 'int', 2) === 1;
$orderIds = GETPOST('order_id', 'array', 2);
$orderPassengersCount = GETPOST('order_passengers_count', 'array', 2);
try {
$volCommand = new CreateFlightCommand();
$volCommand
->setDate(new DateTimeImmutable($_POST['flight_date']))
->setLieuD($_POST['lieuD'])
->setLieuA($_POST['lieuA'])
->setHeureD(new DateTimeImmutable($_POST['flight_date'].' '.$_POST['heureD']))
->setHeureA(new DateTimeImmutable($_POST['flight_date'].' '.$_POST['heureA']))
->setBBCBallonsIdBBCBallons($_POST['ballon'])
->setNbrPax($_POST['nbrPax'])
->setRemarque($_POST['comm'])
->setIncidents($_POST['inci'])
->setFkType($_POST['type'])
->setFkPilot($_POST['pilot'])
->setFkOrganisateur($_POST['orga'])
->setKilometers($_POST['kilometers'])
->setCost($_POST['cost'])
->setFkReceiver($_POST['fk_receiver'])
->setJustifKilometers($_POST['justif_kilometers'])
->setPassengerNames($_POST['passenger_names'])
->setGroupedFlight($isGroupedFlight)
->setOrderIds($orderPassengersCount);
$vol = $createFlightHandler->handle($volCommand);
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface = new Interfaces($db);
$triggerResult = $interface->run_triggers('BBC_FLIGHT_LOG_ADD_FLIGHT', $vol, $user, $langs, $conf);
$msg = '<div class="ok">L\'ajout du vol du : ' . $_POST["reday"] . '/' . $_POST["remonth"] . '/' . $_POST["reyear"] . ' s\'est correctement effectue ! </div>';
Header("Location: card.php?id=" . $vol->id);
}catch (\Exception $e){
$msg = '<div class="error">Erreur lors de l\'ajout du vol : ' . ($vol->error?:$e->getMessage()) . '! </div>';
}
}
}
/* * *************************************************
* PAGE
*
* Put here all code to build page
* ************************************************** */
llxHeader('', 'Carnet de vol', '');
$html = new Form($db);
$commande = new Commande($db);
$orders = $commande->liste_array(2);
$datec = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
$takeOffPlaces = (new \FlightLog\Infrastructure\Flight\Query\Repository\TakeOffQueryRepository($db))->__invoke($user->id);
$mostUsedBalloon = (new \FlightLog\Infrastructure\Flight\Query\Repository\BalloonQueryRepository($db))->query([
'pilot' => $user->id,
]);
if ($msg) {
print $msg;
}
?>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap" rel="stylesheet">
<section class="bbc-style">
<?php if(!empty($takeOffPlaces)): ?>
<datalist id="take_off_places_id">
<?php foreach ($takeOffPlaces as $takeOffPlace): ?>
<option value="<?php echo $takeOffPlace->getPlace(); ?>"></option>
<?php endforeach; ?>
</datalist>
<?php endif; ?>
<div class="errors error-messages">
<?php
foreach ($validator->getErrors() as $errorMessage) {
print sprintf('<div class="error"><span>%s</span></div>', $errorMessage);
}
?>
</div>
<form class="flight-form js-form" name='add' action="addFlight.php" method="post">
<input type="hidden" name="action" value="add"/>
<input type="hidden" name="user_id" value="<?php echo $user->id; ?>"/>
<input type="hidden" name="token" value="<?php echo newToken();?>"/>
<!-- Date et heures -->
<section class="form-section">
<h1 class="form-section-title"><?php echo $langs->trans('Date & heures'); ?></h1>
<div>
<div class="form-group">
<label class="fieldrequired"> Type du vol</label>
<div class="inline-radio">
<?php foreach (fetchBbcFlightTypes() as $flightType) : ?>
<label class="">
<input type="radio" class="js-flight-type" name="type" value="<?php echo $flightType->id ?>" <?php echo $flightType->numero == $_POST['type'] ? 'checked' : '' ?>>
<span class="text-bold"><?php echo "T" . $flightType->numero ?></span>
<span class="font-italic hide-sm"><?php echo $flightType->nom; ?></span>
</label>
<?php endforeach; ?>
</div>
</div>
<div class="form-group">
<label class="fieldrequired"> Date du vol</label>
<input
type="date"
name="flight_date"
value="<?php print (isset($_POST['flight_date']) && !empty($_POST['flight_date'])) ? $_POST['flight_date'] : (new DateTimeImmutable())->format('Y-m-d')?>"
max="<?php print (new DateTimeImmutable())->format('Y-m-d')?>"
min="<?php print (new DateTimeImmutable())->sub(new DateInterval('P3M'))->format('Y-m-d')?>"
/>
</div>
<div class="form-group">
<label class="fieldrequired">Heure de départ</label>
<input type="time"
name="heureD"
class="flat <?php echo($validator->hasError('heureD') ? 'error' : '') ?>"
value="<?php echo $_POST['heureD'] ?>"/>
</div>
<div class="form-group ">
<label class="fieldrequired">Heure d'arrivée</label>
<input type="time"
name="heureA"
class="flat <?php echo($validator->hasError('heureA') ? 'error' : '') ?>"
value="<?php echo $_POST['heureA'] ?>"/>
</div>
</div>
</section>
<!-- Pilote et Ballon -->
<section class="form-section">
<h1 class="form-section-title"><?php echo $langs->trans('Vol') ?></h1>
<div >
<div class="form-group">
<label class="fieldrequired"> Pilote</label>
<?php print $html->select_dolusers($_POST["pilot"] ? $_POST["pilot"] : $user->id, 'pilot', 0, null, 0, '', '', 0,0,0,'',0,'','', true); ?>
</div>
<div class="form-group ">
<label class="fieldrequired">
<span class="js-organisator-field">Organisateur</span>
<span class="js-instructor-field">Instructeur</span>
</label>
<?php
//organisateur
print $html->select_dolusers($_POST["orga"] ? $_POST["orga"] : $user->id, 'orga', 0, null, 0, [], '', 0,0,0,'',0,'','', true);
?>
</div>
<div class="form-group">
<label class="fieldrequired">Lieu de départ </label>
<input type="text" name="lieuD" list="take_off_places_id" class="flat" value="<?php print $_POST['lieuD'] ?>"/>
</div>
<div class="form-group ">
<label class="fieldrequired">Lieu d'arrivée </label>
<input type="text" name="lieuA" class="flat" value="<?php print $_POST['lieuA'] ?>"/>
</div>
<div class="form-group">
<label class="fieldrequired">Ballon</label>
<?php select_balloons($_POST['ballon']?: ($mostUsedBalloon ? $mostUsedBalloon->getId() : ''), 'ballon', 0, false, true); ?>
</div>
<div class="form-group">
<label>Il y'avait-il plusieurs ballons ?</label>
<input type="checkbox" value="1" name="grouped_flight"/> - Oui
</div>
</div>
</section>
<!-- Movements -->
<section class="form-section js-expensable-field">
<h1 class="form-section-title"><?php echo $langs->trans('Déplacements') ?></h1>
<div >
<!-- number of kilometers done for the flight -->
<div class="form-group">
<label class="fieldrequired">Nombre de kilometres effectués pour le vol</label>
<input type="number" name="kilometers" class="flat <?php echo($validator->hasError('kilometers') ? 'error' : '') ?>" value="<?php echo $_POST['kilometers'] ?>"/>
</div>
<!-- Justif Kilometers -->
<div class="form-group">
<label class="fieldrequired">Justificatif des KM </label>
<textarea name="justif_kilometers" rows="2" cols="60" class="flat <?php echo($validator->hasError('justif_kilometers') ? 'error' : '') ?>"><?php echo $_POST['justif_kilometers'] ?></textarea>
</div>
</div>
</section>
<!-- Passagers -->
<section class="form-section">
<h1 class="form-section-title"><?php echo $langs->trans('Passagers') ?></h1>
<div >
<div class="form-group">
<label class="fieldrequired"><?php echo $langs->trans('Nombre de passagers'); ?></label>
<input type="number"
name="nbrPax"
min="0"
max="5"
class="flat <?php echo $validator->hasError('nbrPax') ? 'error' : '' ?>"
value="<?php echo $_POST['nbrPax']?: 0 ?>"/>
</div>
<!-- passenger names -->
<div class="form-group">
<label class="fieldrequired"><?php echo $langs->trans('Noms des passagers'); ?><br/>(Séparé par des ; )</label>
<textarea name="passenger_names" cols="60" rows="2" class="flat <?php echo $validator->hasError('passenger_names') ? 'error' : '' ?>"><?php echo $_POST['passenger_names'] ?></textarea>
</div>
</div>
</section>
<!-- billing information -->
<section class="form-section js-billable-field">
<h1 class="form-section-title"><?php echo $langs->trans('Facturation') ?></h1>
<div>
<p class="text-muted">
Le bloc sur la facturation permet de savoir où retrouver l'argent du vol. Sur des commandes, au près d'un membre, ... <br/>
Il est donc normal de devoir réencoder le nombre de passagers.
</p>
<!-- Order -->
<div id="list_order" class="js-base-form js-billable-field form-group">
<!-- BASE form -->
<table class="bill style-default">
<!-- Cash -->
<tr>
<th colspan="2">A. Cash <small>(ou virement)</small></th>
</tr>
<tr>
<td colspan="2">
A compléter si de l'argent a été perçu par un membre du Belgian Balloon Club.
</td>
</tr>
<tr>
<td class="js-receiver" data-user-id="<?php echo $user->id;?>">
<label class=""><?php echo $langs->trans('Membre ayant perçu l\'argent')?>?</label>
<?php print $html->select_dolusers(
$_POST["fk_receiver"] ? $_POST["fk_receiver"] : -1,
'fk_receiver', true, null, 0, '', '', 0,0,0,'',0,'','', true); ?>
</td>
<td>
<label> </label>
<div class="input-group">
<input type="number" name="cost" step="1" min="0" class="flat js-cost" disabled value="<?php echo $_POST['cost']?:0 ?>"/>
<span class="input-symbol">€</span>
</div>
</td>
</tr>
<!-- Order -->
<tr>
<th>B. Commande(s)</th>
<th>Nombre de passagers.</th>
</tr>
<?php if(is_array($_POST['order_passengers_count']) && !empty($_POST['order_passengers_count'])): ?>
<?php foreach($_POST['order_passengers_count'] as $order => $orderQuantity): ?>
<tr class="order-row">
<td>
<span class="fa fa-trash remove js-remove" data-order-id="<?php echo $order; ?>"></span>
<span class="js-order-ref"><?php echo $orders[$order]?></span>
</td>
<td><input type="number" value="<?php echo $orderQuantity; ?>" min="1" max="5" name="order_passengers_count[<?php echo $order; ?>]" class="js-nbr-pax" /></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<tr class="js-order">
<td>
<?php
echo $html::selectarray(
'order_id',
$orders,
$_POST['order_id'],
1,
0,
$validator->hasError('order_id') ? 'error' : '',
0,
'100%',
0,
0,
'',
'js-order-select',
true
);
?>
<span class="text-muted">Sélection de la commande réalisée en totalité (ou en partie)</span>
</td>
<td > </td>
</tr>
</table>
</div>
</div>
</section>
<!-- Comments -->
<section class="form-section">
<h1 class="form-section-title"><?php echo $langs->trans('Commentaires') ?></h1>
<div>
<!-- commentaires -->
<div class=" form-group">
<label class="fieldrequired"> Note sur le vol </label>
<textarea rows="2" cols="60" class="flat" name="comm" placeholder="RAS"><?php print $_POST['comm']; ?></textarea>
</div>
<!-- incidents -->
<div class=" form-group">
<label class="fieldrequired"> Incidents, Brulure, ...</label>
<textarea rows="2" cols="60" class="flat" name="inci" placeholder="RAS"><?php print $_POST['inci']; ?></textarea>
<p class="text-muted">
Incidents ou dégâts occasionés ou constatés sur le matériel.<br/>
Ce champ enverra un e-mail automatique aux titulaires ainsi qu'au repsonsable matériel volant et non volant.
</p>
</div>
</div>
</section>
<div class="d-grid">
<div class="grid-col grid-col-6">
<button class="button _info" type="button" name="cancel" ><?php print $langs->trans("Cancel") ?></button>
</div>
<div class="grid-col grid-col-6">
<button class="button _success" type="submit" ><span class="fa fa-check"></span> <?php print $langs->trans("Save") ?></button>
</div>
</div>
</form>
<?php
$db->close();
?>
<script type="text/html" id="orderRow">
<tr class="order-row">
<td><span class="fa fa-trash remove js-remove"></span> <span class="js-order-ref"></span></td>
<td><input type="number" value="1" min="1" max="5" name="" class="js-nbr-pax" /></td>
</tr>
</script>
<script type="application/javascript">
/**
* get the flight type object from an id.
*/
function getFlightType(flightTypeId){
var types = {
1:{
'billable' : 1,
'expensable' : 1,
'id' : 1
},
2:{
'billable' : 1,
'expensable' : 1,
'id' : 2
},
3:{
'billable' : 0,
'expensable' : 0,
'id' : 3
},
4:{
'billable' : 0,
'expensable' : 0,
'id' : 4
},
5:{
'billable' : 0,
'expensable' : 0,
'id' : 5
},
6:{
'billable' : 0,
'expensable' : 0,
'id' : 6
},
7:{
'billable' : 0,
'expensable' : 0,
'id' : 7
}
};
var flightTypeNull = {
'billable' : 0,
'expensable' : 0,
'id' : 0
};
return typeof types[flightTypeId] === 'undefined' ? flightTypeNull : types[flightTypeId];
}
function flightTypeChanged($this){
var typeId = $this.val();
var flightType = getFlightType(typeId);
if(flightType.billable === 1){
$('.js-form .js-billable-field').removeClass('hidden');
}else{
$('.js-form .js-billable-field').addClass('hidden');
}
if(flightType.expensable === 1){
$('.js-form .js-expensable-field').removeClass('hidden');
}else{
$('.js-form .js-expensable-field').addClass('hidden');
}
if(flightType.id === 6){
//instruction flight
$('.js-form .js-instructor-field').removeClass('hidden');
$('.js-form .js-organisator-field').addClass('hidden');
} else {
$('.js-form .js-instructor-field').addClass('hidden');
$('.js-form .js-organisator-field').removeClass('hidden');
}
}
function removeOrderLine(){
var $this = $(this);
$('.js-base-form .js-order select option[value="'+$this.data('orderId')+'"]').attr('disabled', false);
$this.parents('tr').remove();
}
function addOrder(){
var orderId = parseInt($('.js-base-form .js-order select').val(), 10);
var $option = $('.js-base-form .js-order select option[value="'+orderId+'"]');
var orderRef = $option.html();
var $addingElement = $($('#orderRow').html());
var $removeButton = $addingElement.find('.js-remove');
var nbrPax = 1;
if(orderId <= 0){
return;
}
// Manage remove button
$removeButton.data('orderId', orderId);
$removeButton.on('click', removeOrderLine);
// Add the reference
$addingElement.find('.js-order-ref').html(orderRef);
// Add the number of pax
$addingElement.find('.js-nbr-pax').html(nbrPax);
$addingElement.find('input.js-nbr-pax').val(nbrPax);
$addingElement.find('input.js-nbr-pax').attr('name', 'order_passengers_count['+orderId+']');
// disable the option
$option.attr('disabled', true);
$('.js-base-form .js-order').before($addingElement);
}
function changeReceiver(){
var $select = $(this);
var userId = parseInt($select.val(), 10);
var currentUserId = parseInt($select.parents('.js-receiver').data('userId'), 10);
var $cost = $('input.js-cost');
$cost.val(0);
$cost.prop('disabled', true);
if(userId === currentUserId){
$cost.val(0);
$cost.prop('disabled', false);
}
}
$(function(){
$('.js-base-form .js-order select').on('change', addOrder);
$('.js-base-form .js-receiver select').on('change', changeReceiver);
$('.js-flight-type').on('change', function(){
var $this = $(this);
flightTypeChanged($this);
});
$('.js-remove').on('click', removeOrderLine);
flightTypeChanged($('.js-flight-type:checked'));
});
</script>
</section>