Completed
Pull Request — master (#9)
by Laurent
04:26 queued 02:17
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>
118
            <p class="cadre_msg1">
119
                Vous avez généré la facture et créé un tiers.<br/>
120
                Merci,
121
            </p>
122
123
            <table class="table_resume">
124
125
                <tr>
126
                    <td></td>
127
                    <td>Statut</td>
128
                    <td>Référence</td>
129
                </tr>
130
131
                <!-- tiers -->
132
                <tr>
133
                    <td>Tiers</td>
134
                    <td><span class="dashboardlineok">OK</span></td>
135
                    <td><?php echo $handler->getCustomer()->getNomUrl(); ?></td>
136
                </tr>
137
138
                <!-- Commande -->
139
                <tr>
140
                    <td>Commande</td>
141
                    <td><span class="dashboardlineok">OK</span></td>
142
                    <td><?php echo $handler->getOrder()->getNomUrl(); ?></td>
143
                </tr>
144
145
                <tr>
146
                    <td colspan="3">
147
                        Le passager doit faire le payement avec ce numéro de commande.<br/>
148
                        Cette référence doit aussi être communiquée au(x) pilote(s) qui feront le vol.
149
                    </td>
150
                </tr>
151
            </table>
152
153
            <p>
154
                Si le passager demande un document, merci de me le communiquer, je ferais le nécessaire.
155
            </p>
156
157
        </div>
158
159
        <?php return; ?>
160
    <?php endif; ?>
161
162
163
    <div class="errors error-messages">
164
        <?php
165
        foreach ($validator->getErrors() as $errorMessage) {
166
            print sprintf('<div class="error"><span>%s</span></div>', $errorMessage);
167
        }
168
        ?>
169
    </div>
170
171
    <div>
172
        <p>
173
            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>
174
            Si vous avre un doute sur la manière d'encoder la commande, veuillez me contacter.<br/>
175
            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>
176
        </p>
177
    </div>
178
    <form class="flight-form" name='add' method="post">
179
    <input type="hidden" name="action" value="add"/>
180
181
    <!-- Commanditaire -->
182
    <section class="form-section">
183
        <h1 class="form-section-title"><?php echo $langs->trans('Commanditaire') ?></h1>
184
        <table class="border" width="100%">
185
186
            <!-- Nom -->
187
            <tr>
188
                <td class="fieldrequired">
189
                    <?php echo $langs->trans('Nom'); ?>
190
                </td>
191
                <td>
192
                    <input type="text"
193
                           name="name"
194
                           class="flat <?php echo $validator->hasError('name') ? 'error' : '' ?>"
195
                           value="<?php echo $formObject->name ?>"/>
196
                </td>
197
            </tr>
198
199
            <!-- Firstname -->
200
            <tr>
201
                <td class="">
202
                    <?php echo $langs->trans('Prénom'); ?>
203
                </td>
204
                <td>
205
                    <input type="text"
206
                           name="firstname"
207
                           class="flat <?php echo $validator->hasError('firstname') ? 'error' : '' ?>"
208
                           value="<?php echo $formObject->firstname ?>"/>
209
                </td>
210
            </tr>
211
212
            <!-- civility-->
213
            <tr>
214
                <td class="fieldrequired">
215
                    <?php echo $langs->trans('UserTitle'); ?>
216
                </td>
217
                <td>
218
                    <?php echo $formcompany->select_civility($formObject->civilityId, 'civility'); ?>
219
                </td>
220
            </tr>
221
222
            <!-- Phone -->
223
            <tr>
224
                <td class="fieldrequired">
225
                    <?php echo $langs->trans('Téléphone'); ?>
226
                </td>
227
                <td>
228
                    <input type="text"
229
                           name="phone"
230
                           class="flat <?php echo $validator->hasError('phone') ? 'error' : '' ?>"
231
                           value="<?php echo $formObject->phone ?>"/>
232
                </td>
233
            </tr>
234
235
            <!-- Mail -->
236
            <tr>
237
                <td class="fieldrequired">
238
                    <?php echo $langs->trans('E-mail'); ?>
239
                </td>
240
                <td>
241
                    <input type="text"
242
                           name="mail"
243
                           class="flat <?php echo $validator->hasError('email') ? 'error' : '' ?>"
244
                           value="<?php echo $formObject->email; ?>"/>
245
                </td>
246
            </tr>
247
248
            <!-- Language -->
249
            <tr>
250
                <td class="fieldrequired">
251
                    <?php echo $langs->trans('DefaultLang'); ?>
252
                </td>
253
                <td>
254
                    <?php echo $formAdmin->select_language($conf->global->MAIN_LANG_DEFAULT,'default_lang',0,0,1,0,0,'maxwidth200onsmartphone'); ?>
255
                </td>
256
            </tr>
257
258
            <!-- Region -->
259
            <tr>
260
                <td class="">
261
                    <?php echo $langs->trans('Region'); ?>
262
                </td>
263
                <td>
264
                    <?php print $formcompany->select_state($formObject->state,'BE'); ?>
265
                </td>
266
            </tr>
267
268
            <?php
269
            // Zip / Town
270
            print '<tr><td>'.fieldLabel('Zip','zipcode').'</td><td>';
271
                    print $formcompany->select_ziptown($formObject->town,'zipcode',array('town','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
272
                    print '</td><td>'.fieldLabel('Town','town').'</td><td>';
273
                    print $formcompany->select_ziptown($formObject->zip,'town',array('zipcode','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
274
                    print '</td></tr>';
275
            ?>
276
277
            <!-- origine -->
278
            <tr>
279
                <td class="">
280
                    <?php echo $langs->trans('Origine'); ?>
281
                </td>
282
                <td>
283
                    <?php $html->selectInputReason($formObject->origine, 'origine', 1); ?>
284
                </td>
285
            </tr>
286
287
            <!-- TVA -->
288
            <tr>
289
                <td class="">
290
                    Numéro de TVA
291
                </td>
292
                <td>
293
                    <input type="text" class="flat" name="tva_intra" id="intra_vat" maxlength="20" value="<?php echo $_POST['tva_intra']; ?>">
294
                    <?php
295
                    if (empty($conf->global->MAIN_DISABLEVATCHECK)): ?>
296
297
                        <?php if (! empty($conf->use_javascript_ajax)): ?>
298
                            <script language="JavaScript" type="text/javascript">
299
                            function CheckVAT(a) {
300
                                <?php print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,300);"; ?>
301
                            }
302
                            </script>
303
                            <a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.add.tva_intra.value);"><?php echo $langs->trans("VATIntraCheck"); ?></a>
304
                            <?php echo $html->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1); ?>
305
                        <?php else: ?>
306
                            <a href="<?php echo $langs->transcountry("VATIntraCheckURL",$object->country_id); ?>" target="_blank"><?php echo img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help'); ?></a>
307
                        <?php endif; ?>
308
                   <?php endif; ?>
309
                </td>
310
            </tr>
311
312
        </table>
313
    </section>
314
315
    <!-- Passagers -->
316
    <section class="form-section">
317
        <h1 class="form-section-title"><?php echo $langs->trans('Données du vol') ?></h1>
318
        <table class="border" width="50%">
319
320
            <!-- Nombre -->
321
            <tr>
322
                <td class="fieldrequired"><?php echo $langs->trans('Nombre de passagers'); ?></td>
323
                <td>
324
                    <input type="number"
325
                           name="nbrPax"
326
                           class="flat <?php echo $validator->hasError('nbrPax') ? 'error' : '' ?>"
327
                           value="<?php echo $_POST['nbrPax'] ?>"/>
328
                </td>
329
            </tr>
330
331
            <!-- Flight cost -->
332
            <tr>
333
                <td class="fieldrequired"><?php echo $langs->trans('Montant demandé') ?></td>
334
                <td>
335
                    <input type="text" name="cost" class="flat  <?php echo $validator->hasError('cost') ? 'error' : '' ?>" value="<?php echo $_POST['cost'] ?> "/>
336
                    &euro;
337
                </td>
338
            </tr>
339
340
            <!-- Region où ils veulent voler -->
341
            <tr>
342
                <td class="fieldrequired"><?php echo $langs->trans('Où veulent ils décoller ?'); ?></td>
343
                <td>
344
                    <input type="text"
345
                           name="region"
346
                           class="flat <?php echo $validator->hasError('region') ? 'error' : '' ?>"
347
                           value="<?php echo $_POST['region'] ?>"/>
348
                </td>
349
            </tr>
350
        </table>
351
    </section>
352
353
    <!-- Commentaire -->
354
    <section class="form-section">
355
        <h1 class="form-section-title"><?php echo $langs->trans('Commentaire') ?></h1>
356
        <table class="border" width="50%">
357
358
            <!-- Comment -->
359
            <tr>
360
                <td><?php echo $langs->trans('Le commentaire doit-il figurer sur la facture') ?></td>
361
                <td>
362
                    <input type="radio" id="public_comment" name="public_comment" value="1" <?php echo ($formObject->isCommentPublic == 1)?'checked="checked"' : ''; ?>/>
363
                    <label for="public_comment">Oui</label>
364
                    -
365
                    <input type="radio" id="private_comment" name="public_comment" value="0" <?php echo ($formObject == null || $formObject->isCommentPublic === null || $formObject->isCommentPublic === 0)?'checked="checked"' : ''; ?>/>
366
                    <label for="private_comment">Non</label>
367
                </td>
368
            </tr>
369
370
            <tr>
371
                <td class="fieldrequired"> Commentaire </td>
372
                <td>
373
                    <?php
374
                        print '<textarea rows="2" cols="60" class="flat" name="comm" placeholder="">' . $_POST['comm'] . '</textarea> ';
375
                    ?>
376
                </td>
377
            </tr>
378
        </table>
379
    </section>
380
<?php
381
382
print '<br><input class="button" type="submit" value="' . $langs->trans("Save") . '"> &nbsp; &nbsp; ';
383
print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
384
385
print '</form>';
386
387
$db->close();
388