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