Completed
Push — master ( 3c5c0f...ec5ff6 )
by Laurent
01:40
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
    }catch (\Exception $e){
131
        dol_syslog($e->getMessage(),LOG_ERR);
132
        dol_htmloutput_mesg("Facture non créée", '', 'error');
133
    }
134
}
135
136
print load_fiche_titre("Créer facture");
137
$form = new Form($db);
138
139
if (!$flightProduct) {
140
    dol_htmloutput_mesg("Le produit -vol- n'est pas configuré", '', 'warning');
141
}
142
143
if ($puFlight > $flightProduct->price_ttc) {
144
    dol_htmloutput_mesg("Le prix unitaire encodé pour ce vol est suppérieur au prix unitaire du produit", '',
145
        'warning');
146
}
147
148
if ($pilot->id != $receiver->id || $pilot->id != $organisator->id) {
149
    dol_htmloutput_mesg("L'organisateur / la personne ayant reçu l'argent n'est pas le pilote.", '',
150
        'warning');
151
}
152
if (!$flight->hasReceiver()) {
153
    dol_htmloutput_mesg("Personne n'aurait touché l'argent.", '',
154
        'error');
155
}
156
157
?>
158
159
    <form method="POST">
160
        <table class="border centpercent">
161
162
            <tr>
163
                <td class="fieldrequired"><?php echo $langs->trans("FieldidBBC_vols") ?> </td>
164
                <td> <?php echo $flight->idBBC_vols ?> </td>
165
            </tr>
166
            <tr>
167
                <td class="fieldrequired"><?php echo $langs->trans("Fielddate") ?> </td>
168
                <td> <?php echo dol_print_date($flight->date) ?> </td>
169
            </tr>
170
            <tr>
171
                <td class="fieldrequired"><?php echo $langs->trans("FieldBBC_ballons_idBBC_ballons") ?> </td>
172
                <td> <?php echo $balloon->immat ?> </td>
173
            </tr>
174
175
            <tr>
176
                <td class="fieldrequired"><?php echo $langs->trans("Fieldfk_pilot") ?> </td>
177
                <td> <?php echo $pilot->getNomUrl() ?> </td>
178
            </tr>
179
            <tr>
180
                <td class="fieldrequired"><?php echo $langs->trans("Fieldfk_organisateur") ?> </td>
181
                <td> <?php echo $organisator->getNomUrl() ?> </td>
182
            </tr>
183
            <tr>
184
                <td class="fieldrequired"><?php echo $langs->trans("Fieldfk_receiver") ?> </td>
185
                <td> <?php echo $receiver->getNomUrl() ?> </td>
186
            </tr>
187
188
            <tr>
189
                <td class="fieldrequired"><?php echo $langs->trans("FieldnbrPax") ?> </td>
190
                <td>
191
                    <input type="number" name="nbr_pax" value="<?php echo $flight->nbrPax ?>" />
192
                </td>
193
            </tr>
194
195
            <tr>
196
                <td class="fieldrequired"><?php echo $langs->trans("Fieldis_facture") ?> </td>
197
                <td> <?php echo $flight->getLibStatut(5) ?> </td>
198
            </tr>
199
200
            <tr>
201
                <td class="fieldrequired">Prix standard</td>
202
                <td> <?php echo $flightProduct->price_ttc . " " . $langs->getCurrencySymbol($conf->currency) ?> </td>
203
            </tr>
204
            <tr>
205
                <td class="fieldrequired"><?php echo $langs->trans("Fieldcost") ?> </td>
206
                <td> <?php echo $flight->cost . " " . $langs->getCurrencySymbol($conf->currency) ?> </td>
207
            </tr>
208
            <tr>
209
                <td class="fieldrequired"><?php echo $langs->trans("UnitPrice") ?> </td>
210
                <td> <?php echo $puFlight . " " . $langs->getCurrencySymbol($conf->currency) ?> </td>
211
            </tr>
212
        </table>
213
214
        <br>
215
        <br>
216
217
        <!-- action -->
218
        <input type="hidden" name="action" value="<?= EXPENSE_REPORT_GENERATOR_ACTION_GENERATE ?>">
219
        <input type="hidden" name="id" value="<?= $id ?>">
220
221
        <!-- Billing type -->
222
        <label><?= $langs->trans("Type de facture"); ?></label><br/>
223
        <input type="radio" id="radio_standard" name="type" value="0" checked="checked"/>
224
        <?= $form->textwithpicto($langs->trans("InvoiceStandardAsk"), $langs->transnoentities("InvoiceStandardDesc"), 1,
225
            'help', '', 0, 3) ?>
226
        <br/>
227
        <br/>
228
229
        <!-- Payment mode -->
230
        <label><?= $langs->trans("Mode de payement"); ?></label><br/>
231
        <?php $form->select_types_paiements($customer->mode_reglement_id, 'mode_reglement_id', 'CRDT'); ?>
232
        <br/>
233
        <br/>
234
235
        <!-- Payment condition -->
236
        <label><?= $langs->trans("Condition de payement"); ?></label><br/>
237
        <?php $form->select_conditions_paiements($customer->cond_reglement_id, 'cond_reglement_id'); ?>
238
        <br/>
239
        <br/>
240
241
        <!-- bank account -->
242
        <label><?= $langs->trans("Compte en banque"); ?></label><br/>
243
        <?php $form->select_comptes($customer->fk_account, 'fk_account', 0, '', 1); ?>
244
        <br/>
245
        <br/>
246
247
        <!-- Public note -->
248
        <label><?= $langs->trans("Note publique"); ?></label><br/>
249
        <textarea name="public_note" wrap="soft" class="quatrevingtpercent" rows="2">
250
        Vol (identifiant : <?php echo $flight->getId(); ?>) de <?php echo $flight->lieuD; ?>
251
            à <?php echo $flight->lieuA; ?> avec <?php echo $pilot->getFullName($langs); ?>
252
        </textarea>
253
        <br/>
254
        <br/>
255
256
        <!-- Private note -->
257
        <label><?= $langs->trans("Note privée"); ?></label><br/>
258
        <textarea name="private_note" wrap="soft" class="quatrevingtpercent" rows="2">
259
        </textarea>
260
        <br/>
261
262
        <!-- model document -->
263
        <label><?= $langs->trans("Model de document "); ?></label><br/>
264
        <?php $liste = ModelePDFFactures::liste_modeles($db); ?>
265
        <?= $form->selectarray('model', $liste, $conf->global->FACTURE_ADDON_PDF); ?>
266
        <br/>
267
        <br/>
268
269
        <?php if (!$flightProduct || !$flight->hasReceiver()) : ?>
270
            <a class="butActionRefused" href="#">Générer</a>
271
        <?php else: ?>
272
            <button class="butAction" type="submit">Générer</button>
273
        <?php endif; ?>
274
275
        <a class="butAction" href="<?php echo DOL_URL_ROOT . '/flightlog/card.php?id=' . $flight->id; ?>">Retour au
276
            vol</a>
277
278
    </form>
279
280
<?php
281
llxFooter();