Completed
Push — master ( 3a683c...464735 )
by Laurent
01: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->cost / $flight->nbrPax;
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',
97
    'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
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
115
116
/*
117
 * VIEW
118
 *
119
 * Put here all code to build page
120
 */
121
llxHeader('', $langs->trans('Generate billing'), '');
122
123
124
/*
125
 * ACTIONS
126
 *
127
 * Put here all code to do according to value of "action" parameter
128
 */
129
if ($action == EXPENSE_REPORT_GENERATOR_ACTION_GENERATE) {
130
    try{
131
        $command = new CreateFlightBillCommand($flight->getId(), $modeReglement, $conditionReglement, $documentModel, $type, $publicNote, $privateNote,$bankAccount);
132
        $handler->handle($command);
133
        Header("Location: card.php?id=" . $flight->getId());
134
    }catch (\Exception $e){
135
        dol_syslog($e->getMessage(),LOG_ERR);
136
        dol_htmloutput_mesg("Facture non créée", '', 'error');
137
    }
138
}
139
140
print load_fiche_titre("Créer facture");
141
$form = new Form($db);
142
143
if (!$flightProduct) {
144
    dol_htmloutput_mesg("Le produit -vol- n'est pas configuré", '', 'warning');
145
}
146
147
if ($puFlight > $flightProduct->price_ttc) {
148
    dol_htmloutput_mesg("Le prix unitaire encodé pour ce vol est suppérieur au prix unitaire du produit", '',
149
        'warning');
150
}
151
152
if ($pilot->id != $receiver->id || $pilot->id != $organisator->id) {
153
    dol_htmloutput_mesg("L'organisateur / la personne ayant reçu l'argent n'est pas le pilote.", '',
154
        'warning');
155
}
156
157
?>
158
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> <?php echo $flight->nbrPax ?> </td>
190
        </tr>
191
192
        <tr>
193
            <td class="fieldrequired"><?php echo $langs->trans("Fieldis_facture") ?> </td>
194
            <td> <?php echo $flight->getLibStatut(5) ?> </td>
195
        </tr>
196
197
        <tr>
198
            <td class="fieldrequired">Prix standard</td>
199
            <td> <?php echo $flightProduct->price_ttc . " " . $langs->getCurrencySymbol($conf->currency) ?> </td>
200
        </tr>
201
        <tr>
202
            <td class="fieldrequired"><?php echo $langs->trans("Fieldcost") ?> </td>
203
            <td> <?php echo $flight->cost . " " . $langs->getCurrencySymbol($conf->currency) ?> </td>
204
        </tr>
205
        <tr>
206
            <td class="fieldrequired"><?php echo $langs->trans("UnitPrice") ?> </td>
207
            <td> <?php echo $puFlight . " " . $langs->getCurrencySymbol($conf->currency) ?> </td>
208
        </tr>
209
    </table>
210
211
    <br/>
212
    <br/>
213
214
    <form method="POST">
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
        <!-- Billing type -->
221
        <label><?= $langs->trans("Type de facture"); ?></label><br/>
222
        <input type="radio" id="radio_standard" name="type" value="0" checked="checked"/>
223
        <?= $form->textwithpicto($langs->trans("InvoiceStandardAsk"), $langs->transnoentities("InvoiceStandardDesc"), 1,
224
            'help', '', 0, 3) ?>
225
        <br/>
226
        <br/>
227
228
        <!-- Payment mode -->
229
        <label><?= $langs->trans("Mode de payement"); ?></label><br/>
230
        <?php $form->select_types_paiements($customer->mode_reglement_id, 'mode_reglement_id', 'CRDT'); ?>
231
        <br/>
232
        <br/>
233
234
        <!-- Payment condition -->
235
        <label><?= $langs->trans("Condition de payement"); ?></label><br/>
236
        <?php $form->select_conditions_paiements($customer->cond_reglement_id, 'cond_reglement_id'); ?>
237
        <br/>
238
        <br/>
239
240
        <!-- bank account -->
241
        <label><?= $langs->trans("Compte en banque"); ?></label><br/>
242
        <?php $form->select_comptes($customer->fk_account, 'fk_account', 0, '', 1); ?>
243
        <br/>
244
        <br/>
245
246
        <!-- Public note -->
247
        <label><?= $langs->trans("Note publique"); ?></label><br/>
248
        <textarea name="public_note" wrap="soft" class="quatrevingtpercent" rows="2">
249
        Vol (identifiant : <?php echo $flight->getId(); ?>) de <?php echo $flight->lieuD; ?>
250
            à <?php echo $flight->lieuA; ?> avec <?php echo $pilot->getFullName($langs); ?>
251
        </textarea>
252
        <br/>
253
        <br/>
254
255
        <!-- Private note -->
256
        <label><?= $langs->trans("Note privée"); ?></label><br/>
257
        <textarea name="private_note" wrap="soft" class="quatrevingtpercent" rows="2">
258
        </textarea>
259
        <br/>
260
261
        <!-- model document -->
262
        <label><?= $langs->trans("Model de document "); ?></label><br/>
263
        <?php $liste = ModelePDFFactures::liste_modeles($db); ?>
264
        <?= $form->selectarray('model', $liste, $conf->global->FACTURE_ADDON_PDF); ?>
265
        <br/>
266
        <br/>
267
268
        <?php if (!$flightProduct) : ?>
269
            <a class="butActionRefused" href="#">Générer</a>
270
        <?php else: ?>
271
            <button class="butAction" type="submit">Générer</button>
272
        <?php endif; ?>
273
274
        <a class="butAction" href="<?php echo DOL_URL_ROOT . '/flightlog/card.php?id=' . $flight->id; ?>">Retour au
275
            vol</a>
276
277
    </form>
278
279
<?php
280
llxFooter();