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