Completed
Push — feature/api ( de88d6...6cf568 )
by Laurent
02:01
created

addOrder.php (2 issues)

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
// Load Dolibarr environment
4
if (false === (@include '../main.inc.php')) {  // From htdocs directory
5
    require '../../documents/custom/main.inc.php'; // From "custom" directory
6
}
7
8
global $db, $langs, $user, $conf;
9
10
dol_include_once('/flightlog/class/bbcvols.class.php');
11
dol_include_once('/flightlog/class/bbctypes.class.php');
12
dol_include_once("/flightlog/lib/flightLog.lib.php");
13
dol_include_once("/flightlog/validators/SimpleOrderValidator.php");
14
dol_include_once("/flightlog/command/CreateOrderCommandHandler.php");
15
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
16
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
17
18
// Load object modCodeTiers
19
$module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
20 View Code Duplication
if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
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...
21
{
22
    $module = substr($module, 0, dol_strlen($module)-4);
23
}
24
$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
25
foreach ($dirsociete as $dirroot)
26
{
27
    $res=dol_include_once($dirroot.$module.'.php');
28
    if ($res) break;
29
}
30
$modCodeClient = new $module;
31
// Load object modCodeFournisseur
32
$module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
33 View Code Duplication
if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
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...
34
{
35
    $module = substr($module, 0, dol_strlen($module)-4);
36
}
37
$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
38
foreach ($dirsociete as $dirroot)
39
{
40
    $res=dol_include_once($dirroot.$module.'.php');
41
    if ($res) break;
42
}
43
$modCodeFournisseur = new $module;
44
45
// Load translation files required by the page
46
$langs->load("mymodule@flightlog");
47
48
$validator = new SimpleOrderValidator($langs, $db, $conf->global->BBC_FLIGHT_TYPE_CUSTOMER);
49
50
$customer = new Societe($db);
51
52
$successMessage = false;
53
54
/* * *****************************************************************
55
 * ACTIONS
56
 *
57
 * Put here all code to do according to value of "action" parameter
58
 * ****************************************************************** */
59
$msg = '';
60
$socid = null;
61
62
if (GETPOST('socid', 'int') > 0){
63
    $socid = GETPOST('socid', 'int');
64
    $customer->fetch($socid);
65
}
66
67
68
if (GETPOST("action") == 'add') {
69
    if (!$_POST["cancel"]) {
70
71
        $formObject = new stdClass();
72
        $formObject->socid = $socid;
73
        $formObject->name = GETPOST('name','alpha');
74
        $formObject->firstname = GETPOST('firstname','alpha');
75
        $formObject->zip = GETPOST('zipcode','alpha');
76
        $formObject->town = GETPOST('town', 'alpha');
77
        $formObject->state = GETPOST('state_id', 'int');
78
        $formObject->phone = GETPOST('phone', 'alpha');
79
        $formObject->origine = GETPOST('origine', 'int');
80
        $formObject->email = trim(GETPOST('mail', 'custom', 0, FILTER_SANITIZE_EMAIL));
81
        $formObject->tva = GETPOST('tva_intra', 'alpha');
82
        $formObject->nbrPax = GETPOST('nbrPax', 'int');
83
        $formObject->region = GETPOST('region', 'alpha');
84
        $formObject->cost = GETPOST('cost');
85
        $formObject->comment = GETPOST('comm', 'alpha');
86
        $formObject->civilityId = GETPOST('civility', 'alpha');
87
        $formObject->language = GETPOST('default_lang', 'int');
88
        $formObject->isCommentPublic = GETPOST('public_comment', 'int');
89
90
        if ($validator->isValid($formObject, $_REQUEST)) {
91
            $createOrderCommand = new CreateOrderCommand($formObject, $user->id);
92
            try{
93
                $handler = new CreateOrderCommandHandler($db, $conf,$user,$langs,$modCodeClient, $modCodeFournisseur);
94
                $handler->handle($createOrderCommand);
95
96
                $msg = '<div class="success ok">Commande et tiers créés. </div>';
97
                $successMessage = true;
98
            } catch (\Exception $e) {
99
                // Creation KO
100
                $msg = '<div class="error">Erreur lors de l\'ajout de la commande</div>';
101
            }
102
        }
103
    }
104
}
105
106
107
/* * *************************************************
108
 * PAGE
109
 *
110
 * Put here all code to build page
111
 * ************************************************** */
112
113
llxHeader('', 'Creation d\'une commande', '');
114
115
$html = new Form($db);
116
$formcompany = new FormCompany($db);
117
$formAdmin = new FormAdmin($db);
118
119
120
$datec = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
121
if ($msg) {
122
    print $msg;
123
}
124
125
?>
126
127
    <!-- Success message with reference -->
128
    <?php if($successMessage): ?>
129
        <div class="bbc-style">
130
            <p class="cadre_msg1">
131
                Vous avez généré la facture et créé un tiers.<br/>
132
                Merci,
133
            </p>
134
135
            <?php if(count($validator->getWarningMessages()) > 0):?>
136
                <div class="box box-warning">
137
                    <p>Ceci sont des messages d'attention mais qui ne bloquent pas la création de la commande</p>
138
                    <ul>
139
                        <?php foreach($validator->getWarningMessages() as $warningMessage): ?>
140
                            <li class="warning"><?php echo $warningMessage; ?></li>
141
                        <?php endforeach; ?>
142
                    </ul>
143
                </div>
144
            <?php endif; ?>
145
146
            <table class="table_resume">
147
148
                <tr>
149
                    <td></td>
150
                    <td>Statut</td>
151
                    <td>Référence</td>
152
                </tr>
153
154
                <!-- tiers -->
155
                <tr>
156
                    <td>Tiers</td>
157
                    <td><span class="dashboardlineok">OK</span></td>
158
                    <td><?php echo $handler->getCustomer()->getNomUrl(); ?></td>
159
                </tr>
160
161
                <!-- Commande -->
162
                <tr>
163
                    <td>Commande</td>
164
                    <td><span class="dashboardlineok">OK</span></td>
165
                    <td><?php echo $handler->getOrder()->getNomUrl(); ?></td>
166
                </tr>
167
168
                <tr>
169
                    <td colspan="3">
170
                        Le passager doit faire le payement avec ce numéro de commande.<br/>
171
                        Cette référence doit aussi être communiquée au(x) pilote(s) qui feront le vol.
172
                    </td>
173
                </tr>
174
            </table>
175
176
            <p>
177
                Si le passager demande un document, merci de me le communiquer, je ferais le nécessaire.
178
            </p>
179
180
        </div>
181
182
        <?php return; ?>
183
    <?php endif; ?>
184
185
186
    <div class="errors error-messages">
187
        <?php
188
        foreach ($validator->getErrors() as $errorMessage) {
189
            print sprintf('<div class="error"><span>%s</span></div>', $errorMessage);
190
        }
191
        ?>
192
    </div>
193
194
    <div>
195
        <p>
196
            Cette page vous permettra de créer une commande. La commande est <b>obligatoire</b> si vous désirez faire payer les passagers directement sur le compte du club.<br>
197
            Si vous avez un doute sur la manière d'encoder la commande, veuillez me contacter AVANT de soumettre le dit formulaire.<br/>
198
            Si vous avez <b>déjà</b> encodé une commande, et que vous voulez la retrouver veuillez vous rendre sur : <a href="<?php echo sprintf(DOL_URL_ROOT.'/commande/list.php?search_sale=%s', $user->id); ?>">mes commandes.</a>
199
        </p>
200
    </div>
201
    <form class="flight-form" name='add' method="post">
202
    <input type="hidden" name="action" value="add"/>
203
204
    <!-- Commanditaire -->
205
    <section class="form-section">
206
        <h1 class="form-section-title"><?php echo $langs->trans('Commanditaire') ?></h1>
207
        <table class="border" width="100%">
208
209
            <tr>
210
                <td class="">
211
                    <?php echo $langs->trans('Commanditaire'); ?>
212
                </td>
213
214
                <td>
215
                    <?php print $form->select_company($customer->id, 'socid', '((s.client = 1 OR s.client = 3) AND s.status=1)', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); ?>
216
                    <script type="text/javascript">
217
                        $(document).ready(function() {
218
                            $("#socid").change(function() {
219
                                var socid = $(this).val();
220
                                window.location.href = "<?php echo $_SERVER["PHP_SELF"].'?socid="+socid' ?>
221
                            });
222
                        });
223
                    </script>
224
                </td>
225
226
            </tr>
227
228
229
            <?php if($socid === null): ?>
230
                <!-- Nom -->
231
                <tr>
232
                    <td class="fieldrequired">
233
                        <?php echo $langs->trans('Nom'); ?>
234
                    </td>
235
                    <td>
236
                        <input type="text"
237
                               name="name"
238
                               class="flat <?php echo $validator->hasError('name') ? 'error' : '' ?>"
239
                               value="<?php echo $formObject->name ?>"/>
240
                    </td>
241
                </tr>
242
243
                <!-- Firstname -->
244
                <tr>
245
                    <td class="">
246
                        <?php echo $langs->trans('Prénom'); ?>
247
                    </td>
248
                    <td>
249
                        <input type="text"
250
                               name="firstname"
251
                               class="flat <?php echo $validator->hasError('firstname') ? 'error' : '' ?>"
252
                               value="<?php echo $formObject->firstname ?>"/>
253
                    </td>
254
                </tr>
255
256
                <!-- civility-->
257
                <tr>
258
                    <td class="">
259
                        <?php echo $langs->trans('UserTitle'); ?>
260
                    </td>
261
                    <td>
262
                        <?php echo $formcompany->select_civility($formObject->civilityId, 'civility'); ?>
263
                    </td>
264
                </tr>
265
266
                <!-- Phone -->
267
                <tr>
268
                    <td class="">
269
                        <?php echo $langs->trans('Téléphone'); ?>
270
                    </td>
271
                    <td>
272
                        <input type="text"
273
                               name="phone"
274
                               class="flat <?php echo $validator->hasError('phone') ? 'error' : '' ?>"
275
                               value="<?php echo $formObject->phone ?>"/>
276
                    </td>
277
                </tr>
278
279
                <!-- Mail -->
280
                <tr>
281
                    <td class="">
282
                        <?php echo $langs->trans('E-mail'); ?>
283
                    </td>
284
                    <td>
285
                        <input type="text"
286
                               name="mail"
287
                               class="flat <?php echo $validator->hasError('email') ? 'error' : '' ?>"
288
                               value="<?php echo $formObject->email; ?>"/>
289
                    </td>
290
                </tr>
291
292
                <!-- Language -->
293
                <tr>
294
                    <td class="fieldrequired">
295
                        <?php echo $langs->trans('DefaultLang'); ?>
296
                    </td>
297
                    <td>
298
                        <?php echo $formAdmin->select_language($conf->global->MAIN_LANG_DEFAULT,'default_lang',0,0,1,0,0,'maxwidth200onsmartphone'); ?>
299
                    </td>
300
                </tr>
301
302
                <!-- Region -->
303
                <tr>
304
                    <td class="">
305
                        <?php echo $langs->trans('Region'); ?>
306
                    </td>
307
                    <td>
308
                        <?php print $formcompany->select_state($formObject->state,'BE'); ?>
309
                    </td>
310
                </tr>
311
312
                <?php
313
                // Zip / Town
314
                print '<tr><td>'.fieldLabel('Zip','zipcode').'</td><td>';
315
                        print $formcompany->select_ziptown($formObject->town,'zipcode',array('town','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
316
                        print '</td><td>'.fieldLabel('Town','town').'</td><td>';
317
                        print $formcompany->select_ziptown($formObject->zip,'town',array('zipcode','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
318
                        print '</td></tr>';
319
                ?>
320
321
                <!-- origine -->
322
                <tr>
323
                    <td class="">
324
                        <?php echo $langs->trans('Origine'); ?>
325
                    </td>
326
                    <td>
327
                        <?php $html->selectInputReason($formObject->origine, 'origine', 1); ?>
328
                    </td>
329
                </tr>
330
331
                <!-- TVA -->
332
                <tr>
333
                    <td class="">
334
                        Numéro de TVA
335
                    </td>
336
                    <td>
337
                        <input type="text" class="flat" name="tva_intra" id="intra_vat" maxlength="20" value="<?php echo $_POST['tva_intra']; ?>">
338
                        <?php
339
                        if (empty($conf->global->MAIN_DISABLEVATCHECK)): ?>
340
341
                            <?php if (! empty($conf->use_javascript_ajax)): ?>
342
                                <script language="JavaScript" type="text/javascript">
343
                                function CheckVAT(a) {
344
                                    <?php print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,300);"; ?>
345
                                }
346
                                </script>
347
                                <a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.add.tva_intra.value);"><?php echo $langs->trans("VATIntraCheck"); ?></a>
348
                                <?php echo $html->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1); ?>
349
                            <?php else: ?>
350
                                <a href="<?php echo $langs->transcountry("VATIntraCheckURL",$object->country_id); ?>" target="_blank"><?php echo img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help'); ?></a>
351
                            <?php endif; ?>
352
                       <?php endif; ?>
353
                    </td>
354
                </tr>
355
356
            <?php endif; ?>
357
358
        </table>
359
    </section>
360
361
    <!-- Passagers -->
362
    <section class="form-section">
363
        <h1 class="form-section-title"><?php echo $langs->trans('Données du vol') ?></h1>
364
        <table class="border js-compute" width="50%">
365
366
            <!-- Nombre -->
367
            <tr>
368
                <td class="fieldrequired"><?php echo $langs->trans('Nombre de passagers'); ?></td>
369
                <td>
370
                    <input type="number"
371
                           name="nbrPax"
372
                           class="flat <?php echo $validator->hasError('nbrPax') ? 'error' : '' ?>"
373
                           value="<?php echo $_POST['nbrPax'] ?>"/>
374
                </td>
375
            </tr>
376
377
            <!-- Flight cost -->
378
            <tr>
379
                <td class="fieldrequired"><?php echo $langs->trans('Montant demandé (au total)') ?></td>
380
                <td>
381
                    <input type="text" name="cost" class="flat  <?php echo $validator->hasError('cost') ? 'error' : '' ?>" value="<?php echo $_POST['cost'] ?> "/>
382
                    &euro;
383
                </td>
384
            </tr>
385
386
            <!-- Total / pax -->
387
            <tr class="cadre_prix_total">
388
                <td class="fieldrequired"><?php echo $langs->trans('Montant / passager') ?></td>
389
                <td>
390
                    <span class="js-total">0</span>&euro;
391
                </td>
392
            </tr>
393
        </table>
394
    </section>
395
396
    <!-- Commentaire -->
397
    <section class="form-section">
398
        <h1 class="form-section-title"><?php echo $langs->trans('Commentaire') ?></h1>
399
        <table class="border" width="50%">
400
401
            <!-- Comment -->
402
            <tr>
403
                <td><?php echo $langs->trans('Le commentaire doit-il figurer sur la commande') ?></td>
404
                <td>
405
                    <input type="radio" id="public_comment" name="public_comment" value="1" <?php echo ($formObject->isCommentPublic == 1)?'checked="checked"' : ''; ?>/>
406
                    <label for="public_comment">Oui</label>
407
                    -
408
                    <input type="radio" id="private_comment" name="public_comment" value="0" <?php echo ($formObject == null || $formObject->isCommentPublic === null || $formObject->isCommentPublic === 0)?'checked="checked"' : ''; ?>/>
409
                    <label for="private_comment">Non</label>
410
                </td>
411
            </tr>
412
413
            <tr>
414
                <td class=""> Commentaire </td>
415
                <td>
416
                    <?php
417
                        print '<textarea rows="2" cols="60" class="flat" name="comm" placeholder="">' . $_POST['comm'] . '</textarea> ';
418
                    ?>
419
                </td>
420
            </tr>
421
        </table>
422
    </section>
423
424
    <script type="application/javascript">
425
        (function($){
426
427
            var cost = $('.js-compute input[name="cost"]').val();
428
            var nbrPax = $('.js-compute input[name="nbrPax"]').val();
429
            compute();
430
431
            $('.js-compute input[name="nbrPax"]').on('change', function(){
432
                nbrPax = $(this).val();
433
                compute();
434
            });
435
436
            $('.js-compute input[name="cost"]').on('change', function(){
437
                cost = $(this).val();
438
                compute();
439
            });
440
441
            function compute(){
442
                if(isNaN(parseInt(nbrPax, 10)) || parseInt(nbrPax, 10) === 0){
443
                    $('.js-compute .js-total').text(0);
444
                    return;
445
                }
446
447
                var total = parseInt((cost / nbrPax)*100, 10    );
448
                $('.js-compute .js-total').text(total/100);
449
            }
450
451
452
        })($);
453
    </script>
454
455
<?php
456
457
print '<br><input class="button" type="submit" value="' . $langs->trans("Save") . '"> &nbsp; &nbsp; ';
458
print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
459
460
print '</form>';
461
462
$db->close();
463