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

facture.php (1 issue)

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
 * When a user generates the expense report for all pilots
4
 */
5
define("EXPENSE_REPORT_GENERATOR_ACTION_GENERATE", "generate");
6
7
/**
8
 * When a user has to select year and quartil
9
 */
10
define("EXPENSE_REPORT_GENERATOR_ACTION_CREATE", "select");
11
12
/**
13
 * \file    generateExpenseNote.php
14
 * \ingroup flightlog
15
 * \brief   Generate expense notes for a quartil
16
 *
17
 */
18
19
// Load Dolibarr environment
20
if (false === (@include '../main.inc.php')) {  // From htdocs directory
21
    require '../../documents/custom/main.inc.php'; // From "custom" directory
22
}
23
24
dol_include_once('/core/modules/facture/modules_facture.php');
25
dol_include_once('/adherents/class/adherent.class.php');
26
dol_include_once('/compta/facture/class/facture.class.php');
27
dol_include_once('/flightballoon/bbc_ballons.class.php');
28
dol_include_once("/product/class/product.class.php");
29
dol_include_once('/fourn/class/fournisseur.class.php');
30
dol_include_once("/flightlog/flightlog.inc.php");
31
32
global $db, $langs, $user, $conf;
33
34
// Load translation files required by the page
35
$langs->load("trips");
36
$langs->load("bills");
37
$langs->load("mymodule@flightlog");
38
$langs->load("other");
39
40
// Get parameters
41
$id = GETPOST('id', 'int', 3);
42
$action = GETPOST('action', 'alpha');
43
$year = GETPOST('year', 'int', 3);
44
45
//post parameters
46
$customerId = GETPOST('customerid', 'int');
47
$additionalBonus = GETPOST('additional_bonus', 'array', 2);
48
$pilotIds = GETPOST('pilot', 'array', 2);
49
$amouts = GETPOST('amout', 'array', 2);
50
$amoutDiscounts = GETPOST('amoutDiscount', 'array', 2);
51
$publicNote = GETPOST('public_note', 'alpha', 2);
52
$privateNote = GETPOST('private_note', 'alpha', 2);
53
$type = GETPOST("type", "int", 3);
54
$conditionReglement = GETPOST("cond_reglement_id", "int", 3);
55
$modeReglement = GETPOST("mode_reglement_id", "int", 3);
56
$bankAccount = GETPOST("fk_account", "int", 3);
57
$documentModel = GETPOST("model", "alpha", 3);
58
59
//variables
60
$flightProduct = new Product($db);
61
$flightProduct->fetch($conf->global->BBC_FLIGHT_TYPE_CUSTOMER);
62
63
$flight = new Bbcvols($db);
64
$flight->fetch($id);
65
$puFlight = $flight->getAmountPerPassenger();
66
67
$organisator = new User($db);
68
$organisator->fetch($flight->fk_organisateur);
69
70
$receiver = new User($db);
71
$receiver->fetch($flight->fk_receiver);
72
$memberReceiver = new Adherent($db);
73
$memberReceiver->fetch($receiver->fk_member);
74
75
$pilot = new User($db);
76
$pilot->fetch($flight->fk_pilot);
77
78
$adherent = new Adherent($db);
79
$adherent->fetch($pilot->fk_member);
80
81
$customer = new Fournisseur($db);
82
$customer->fetch($conf->global->BBC_FLIGHT_DEFAULT_CUSTOMER ?: $adherent->fk_soc);
83
84
$balloon = new Bbc_ballons($db);
85
$balloon->fetch($flight->BBC_ballons_idBBC_ballons);
86
$handler = CreateFlightBillCommandHandlerFactory::factory($db, $conf->global, $user, $langs);
87
88
//Query
89
90
//pdf
91
$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails',
92
    'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
93
$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc',
94
    'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
95
$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
96
$nbrPax = (GETPOST('nbr_pax', 'int') ? GETPOST('nbr_pax', 'int') : null);
97
98
$object = new Facture($db);
99
$vatrate = "0.000";
100
101
// Access control
102 View Code Duplication
if (!$conf->facture->enabled || !$user->rights->flightlog->vol->financial || !$user->rights->flightlog->vol->financialGenerateDocuments) {
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...
103
    accessforbidden();
104
}
105
106
// Default action
107
if (empty($action)) {
108
    $action = EXPENSE_REPORT_GENERATOR_ACTION_CREATE;
109
}
110
111
112
/*
113
 * VIEW
114
 *
115
 * Put here all code to build page
116
 */
117
llxHeader('', $langs->trans('Generate billing'), '');
118
119
120
/*
121
 * ACTIONS
122
 *
123
 * Put here all code to do according to value of "action" parameter
124
 */
125
if ($action == EXPENSE_REPORT_GENERATOR_ACTION_GENERATE) {
126
    try{
127
        $command = new CreateFlightBillCommand($flight->getId(), $modeReglement, $conditionReglement, $documentModel, $type, $publicNote, $privateNote,$bankAccount, $nbrPax, $customerId);
128
        $handler->handle($command);
129
    }catch (\Exception $e){
130
        dol_syslog($e->getMessage(),LOG_ERR);
131
        dol_htmloutput_mesg("Facture non créée", '', 'error');
132
    }
133
}
134
135
print load_fiche_titre("Créer facture");
136
$form = new Form($db);
137
138
if (!$flightProduct) {
139
    dol_htmloutput_mesg("Le produit -vol- n'est pas configuré", '', 'warning');
140
}
141
142
if ($puFlight > $flightProduct->price_ttc) {
143
    dol_htmloutput_mesg("Le prix unitaire encodé pour ce vol est suppérieur au prix unitaire du produit", '',
144
        'warning');
145
}
146
147
if ($pilot->id != $receiver->id || $pilot->id != $organisator->id) {
148
    dol_htmloutput_mesg("L'organisateur / la personne ayant reçu l'argent n'est pas le pilote.", '',
149
        'warning');
150
}
151
if (!$flight->hasReceiver()) {
152
    dol_htmloutput_mesg("Personne n'aurait touché l'argent.", '',
153
        'error');
154
}
155
156
?>
157
158
    <form method="POST">
159
        <table class="border centpercent">
160
161
            <tr>
162
                <td class="fieldrequired"><?php echo $langs->trans("FieldidBBC_vols") ?> </td>
163
                <td> <?php echo $flight->idBBC_vols ?> </td>
164
            </tr>
165
            <tr>
166
                <td class="fieldrequired"><?php echo $langs->trans("Fielddate") ?> </td>
167
                <td> <?php echo dol_print_date($flight->date) ?> </td>
168
            </tr>
169
            <tr>
170
                <td class="fieldrequired"><?php echo $langs->trans("FieldBBC_ballons_idBBC_ballons") ?> </td>
171
                <td> <?php echo $balloon->immat ?> </td>
172
            </tr>
173
174
            <tr>
175
                <td class="fieldrequired"><?php echo $langs->trans("Fieldfk_pilot") ?> </td>
176
                <td> <?php echo $pilot->getNomUrl() ?> </td>
177
            </tr>
178
            <tr>
179
                <td class="fieldrequired"><?php echo $langs->trans("Fieldfk_organisateur") ?> </td>
180
                <td> <?php echo $organisator->getNomUrl() ?> </td>
181
            </tr>
182
            <tr>
183
                <td class="fieldrequired"><?php echo $langs->trans("Fieldfk_receiver") ?> </td>
184
                <td> <?php echo $receiver->getNomUrl() ?> </td>
185
            </tr>
186
187
            <tr>
188
                <td class="fieldrequired"><?php echo $langs->trans("FieldnbrPax") ?> </td>
189
                <td>
190
                    <input type="number" name="nbr_pax" value="<?php echo $flight->nbrPax ?>" />
191
                </td>
192
            </tr>
193
194
            <tr>
195
                <td class="fieldrequired"><?php echo $langs->trans("Fieldis_facture") ?> </td>
196
                <td> <?php echo $flight->getLibStatut(5) ?> </td>
197
            </tr>
198
199
            <tr>
200
                <td class="fieldrequired">Prix standard</td>
201
                <td> <?php echo $flightProduct->price_ttc . " " . $langs->getCurrencySymbol($conf->currency) ?> </td>
202
            </tr>
203
            <tr>
204
                <td class="fieldrequired"><?php echo $langs->trans("Fieldcost") ?> </td>
205
                <td> <?php echo $flight->cost . " " . $langs->getCurrencySymbol($conf->currency) ?> </td>
206
            </tr>
207
            <tr>
208
                <td class="fieldrequired"><?php echo $langs->trans("UnitPrice") ?> </td>
209
                <td> <?php echo $puFlight . " " . $langs->getCurrencySymbol($conf->currency) ?> </td>
210
            </tr>
211
        </table>
212
213
        <br>
214
        <br>
215
216
        <!-- action -->
217
        <input type="hidden" name="action" value="<?= EXPENSE_REPORT_GENERATOR_ACTION_GENERATE ?>">
218
        <input type="hidden" name="id" value="<?= $id ?>">
219
220
        <table>
221
            <tr>
222
                <td class="">
223
                    <?php echo $langs->trans('Commanditaire'); ?>
224
                </td>
225
226
                <td>
227
                    <?php print $form->select_company($memberReceiver->fk_soc, 'customerid', '((s.client = 1 OR s.client = 3) AND s.status=1)', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); ?>
228
                </td>
229
230
            </tr>
231
232
            <!-- Billing type -->
233
            <tr>
234
                <td><label for="type"><?= $langs->trans("Type de facture"); ?></label></td>
235
236
                <td><input type="radio" id="radio_standard" name="type" value="0" checked="checked"/>
237
                    <?php echo $form->textwithpicto($langs->trans("InvoiceStandardAsk"), $langs->transnoentities("InvoiceStandardDesc"), 1,
238
                        'help', '', 0, 3) ?>
239
                </td>
240
            </tr>
241
242
            <!-- Payment mode -->
243
            <tr>
244
                <td><label><?php echo $langs->trans("Mode de payement"); ?></label></td>
245
                <td><?php $form->select_types_paiements($customer->mode_reglement_id, 'mode_reglement_id', 'CRDT'); ?></td>
246
            </tr>
247
248
            <!-- Payment condition -->
249
            <tr>
250
                <td>
251
                    <label><?= $langs->trans("Condition de payement"); ?></label>
252
                </td>
253
                <td>
254
                    <?php $form->select_conditions_paiements($customer->cond_reglement_id, 'cond_reglement_id'); ?>
255
                </td>
256
            </tr>
257
258
            <!-- bank account -->
259
            <tr>
260
                <td>
261
                    <label><?php echo $langs->trans("Compte en banque"); ?></label>
262
                </td>
263
264
                <td>
265
                    <?php $form->select_comptes($customer->fk_account, 'fk_account', 0, '', 1); ?>
266
                </td>
267
268
            </tr>
269
270
271
            <!-- Public note -->
272
            <tr>
273
                <td>
274
                    <label><?= $langs->trans("Note publique"); ?></label>
275
                </td>
276
277
                <td>
278
                <textarea name="public_note" wrap="soft" class="quatrevingtpercent" rows="2">
279
                    Vol (identifiant : <?php echo $flight->getId(); ?>) de <?php echo $flight->lieuD; ?>
280
                    à <?php echo $flight->lieuA; ?> avec <?php echo $pilot->getFullName($langs); ?>
281
                </textarea>
282
                </td>
283
284
285
            </tr>
286
287
            <!-- Private note -->
288
            <tr>
289
                <td>
290
                    <label><?= $langs->trans("Note privée"); ?></label>
291
                </td>
292
293
                <td>
294
                    <textarea name="private_note" wrap="soft" class="quatrevingtpercent" rows="2"></textarea>
295
                </td>
296
            </tr>
297
298
            <!-- model document -->
299
            <tr>
300
                <td>
301
                    <label><?= $langs->trans("Model de document "); ?></label>
302
                </td>
303
                <td>
304
                    <?php $liste = ModelePDFFactures::liste_modeles($db); ?>
305
                    <?= $form->selectarray('model', $liste, $conf->global->FACTURE_ADDON_PDF); ?>
306
                </td>
307
            </tr>
308
309
        </table>
310
311
312
        <?php if (!$flightProduct || !$flight->hasReceiver()) : ?>
313
            <a class="butActionRefused" href="#">Générer</a>
314
        <?php else: ?>
315
            <button class="butAction" type="submit">Générer</button>
316
        <?php endif; ?>
317
318
        <a class="butAction" href="<?php echo DOL_URL_ROOT . '/flightlog/card.php?id=' . $flight->id; ?>">Retour au
319
            vol</a>
320
321
    </form>
322
323
<?php
324
llxFooter();