Issues (2811)

public/htdocs/takepos/receipt.php (1 issue)

1
<?php
2
3
/* Copyright (C) 2007-2008  Jeremie Ollivier            <[email protected]>
4
 * Copyright (C) 2011-2023  Laurent Destailleur         <[email protected]>
5
 * Copyright (C) 2012       Marcos García               <[email protected]>
6
 * Copyright (C) 2018       Andreu Bisquerra            <[email protected]>
7
 * Copyright (C) 2019       Josep Lluís Amador          <[email protected]>
8
 * Copyright (C) 2021       Nicolas ZABOURI             <[email protected]>
9
 * Copyright (C) 2024       Rafael San José             <[email protected]>
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23
 */
24
25
use Dolibarr\Code\Compta\Classes\Facture;
26
use Dolibarr\Lib\ViewMain;
27
28
/**
29
 *  \file       htdocs/takepos/receipt.php
30
 *  \ingroup    takepos
31
 *  \brief      Page to show a receipt.
32
 */
33
34
use Dolibarr\Code\MultiCurrency\Classes\MultiCurrency;
35
use Dolibarr\Code\Societe\Classes\Societe;
36
37
// Include main (when fie in included into send.php, $action is set and main was already loaded)
38
if (!isset($action)) {
39
    //if (! defined('NOREQUIREUSER'))   define('NOREQUIREUSER', '1');   // Not disabled cause need to load personalized language
40
    //if (! defined('NOREQUIREDB'))     define('NOREQUIREDB', '1');     // Not disabled cause need to load personalized language
41
    //if (! defined('NOREQUIRESOC'))        define('NOREQUIRESOC', '1');
42
    //if (! defined('NOREQUIRETRAN'))       define('NOREQUIRETRAN', '1');
43
    if (!defined('NOTOKENRENEWAL')) {
44
        define('NOTOKENRENEWAL', '1');
45
    }
46
    if (!defined('NOREQUIREMENU')) {
47
        define('NOREQUIREMENU', '1');
48
    }
49
    if (!defined('NOREQUIREHTML')) {
50
        define('NOREQUIREHTML', '1');
51
    }
52
    if (!defined('NOREQUIREAJAX')) {
53
        define('NOREQUIREAJAX', '1');
54
    }
55
56
    require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php'; // If this file is called from send.php avoid load again
57
}
58
59
$langs->loadLangs(array("main", "bills", "cashdesk", "companies"));
60
61
$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
62
63
$facid = GETPOSTINT('facid');
64
65
$action = GETPOST('action', 'aZ09');
66
$gift = GETPOSTINT('gift');
67
68
if (!$user->hasRight('takepos', 'run')) {
69
    accessforbidden();
70
}
71
72
73
/*
74
 * View
75
 */
76
77
ViewMain::topHttpHead('text/html', 1);
78
79
if ($place > 0) {
80
    $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture where ref='(PROV-POS" . $db->escape($_SESSION["takeposterminal"] . "-" . $place) . ")'";
81
    $resql = $db->query($sql);
82
    $obj = $db->fetch_object($resql);
83
    if ($obj) {
84
        $facid = $obj->rowid;
85
    }
86
}
87
$object = new Facture($db);
88
$object->fetch($facid);
89
90
// Call to external receipt modules if exist
91
$parameters = array();
92
$hookmanager->initHooks(array('takeposfrontend'));
93
$reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
94
if (!empty($hookmanager->resPrint)) {
95
    print $hookmanager->resPrint;
96
    return; // Receipt page can be called by the takepos/send.php page that use ob_start/end so we must use return and not exit to stop page
97
}
98
99
// IMPORTANT: This file is sended to 'Takepos Printing' application. Keep basic file. No external files as css, js... If you need images use absolute path.
100
?>
101
<body>
102
<style>
103
    .right {
104
        text-align: right;
105
    }
106
107
    .center {
108
        text-align: center;
109
    }
110
111
    .left {
112
        text-align: left;
113
    }
114
</style>
115
<center>
116
    <div style="font-size: 1.5em">
117
        <?php echo '<b>' . $mysoc->name . '</b>'; ?>
118
    </div>
119
</center>
120
<br>
121
<p class="left">
122
    <?php
123
    $constFreeText = 'TAKEPOS_HEADER' . (empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
124
    if (getDolGlobalString('TAKEPOS_HEADER') || getDolGlobalString($constFreeText)) {
125
        $newfreetext = '';
126
        $substitutionarray = getCommonSubstitutionArray($langs);
127
        if (getDolGlobalString('TAKEPOS_HEADER')) {
128
            $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_HEADER'), $substitutionarray);
129
        }
130
        if (getDolGlobalString($constFreeText)) {
131
            $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
132
        }
133
        print nl2br($newfreetext);
134
    }
135
    ?>
136
</p>
137
<p class="right">
138
    <?php
139
    print $langs->trans('Date') . " " . dol_print_date($object->date, 'day') . '<br>';
140
    if (getDolGlobalString('TAKEPOS_RECEIPT_NAME')) {
141
        print getDolGlobalString('TAKEPOS_RECEIPT_NAME') . " ";
142
    }
143
    if ($object->statut == Facture::STATUS_DRAFT) {
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$statut has been deprecated: Use $status instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

143
    if (/** @scrutinizer ignore-deprecated */ $object->statut == Facture::STATUS_DRAFT) {

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
144
        print str_replace(")", "", str_replace("-", " " . $langs->trans('Place') . " ", str_replace("(PROV-POS", $langs->trans("Terminal") . " ", $object->ref)));
145
    } else {
146
        print $object->ref;
147
    }
148
    if (getDolGlobalString('TAKEPOS_SHOW_CUSTOMER')) {
149
        if ($object->socid != getDolGlobalInt('CASHDESK_ID_THIRDPARTY' . $_SESSION["takeposterminal"])) {
150
            $soc = new Societe($db);
151
            if ($object->socid > 0) {
152
                $soc->fetch($object->socid);
153
            } else {
154
                $soc->fetch(getDolGlobalInt('CASHDESK_ID_THIRDPARTY' . $_SESSION["takeposterminal"]));
155
            }
156
            print "<br>" . $langs->trans("Customer") . ': ' . $soc->name;
157
        }
158
    }
159
    if (getDolGlobalString('TAKEPOS_SHOW_DATE_OF_PRINING')) {
160
        print "<br>" . $langs->trans("DateOfPrinting") . ': ' . dol_print_date(dol_now(), 'dayhour', 'tzuserrel') . '<br>';
161
    }
162
    ?>
163
</p>
164
<br>
165
166
<table width="100%" style="border-top-style: double;">
167
    <thead>
168
    <tr>
169
        <th class="center"><?php print $langs->trans("Label"); ?></th>
170
        <th class="right"><?php print $langs->trans("Qty"); ?></th>
171
        <th class="right"><?php if ($gift != 1) {
172
                print $langs->trans("Price");
173
            } ?></th>
174
        <?php if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
175
            <th class="right"><?php if ($gift != 1) {
176
                    print $langs->trans("TotalHT");
177
                } ?></th>
178
        <?php } ?>
179
        <th class="right"><?php if ($gift != 1) {
180
                print $langs->trans("TotalTTC");
181
            } ?></th>
182
    </tr>
183
    </thead>
184
    <tbody>
185
    <?php
186
    if ($action == 'without_details') {
187
        $qty = GETPOSTINT('qty') > 0 ? GETPOSTINT('qty') : 1;
188
        print '<tr>';
189
        print '<td>' . GETPOST('label', 'alphanohtml') . '</td>';
190
        print '<td class="right">' . $qty . '</td>';
191
        print '<td class="right">' . price(price2num($object->total_ttc / $qty, 'MU'), 1) . '</td>';
192
        if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) {
193
            print '<td class="right">' . price($object->total_ht, 1) . '</td>';
194
        }
195
        print '<td class="right">' . price($object->total_ttc, 1) . '</td>';
196
        print '</tr>';
197
    } else {
198
        foreach ($object->lines as $line) {
199
            ?>
200
            <tr>
201
                <td>
202
                    <?php if (!empty($line->product_label)) {
203
                        echo $line->product_label;
204
                    } else {
205
                        echo $line->description;
206
                    } ?>
207
                </td>
208
                <td class="right"><?php echo $line->qty; ?></td>
209
                <td class="right"><?php if ($gift != 1) {
210
                        echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
211
                    } ?></td>
212
                <?php
213
                if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
214
                    <td class="right"><?php if ($gift != 1) {
215
                            echo price($line->total_ht, 1);
216
                        } ?></td>
217
                    <?php
218
                } ?>
219
                <td class="right"><?php if ($gift != 1) {
220
                        echo price($line->total_ttc, 1);
221
                    } ?></td>
222
            </tr>
223
            <?php
224
        }
225
    }
226
    ?>
227
    </tbody>
228
</table>
229
<br>
230
<table class="right">
231
    <tr>
232
        <th class="right"><?php if ($gift != 1) {
233
                echo $langs->trans("TotalHT");
234
            } ?></th>
235
        <td class="right"><?php if ($gift != 1) {
236
                echo price($object->total_ht, 1, '', 1, -1, -1, $conf->currency) . "\n";
237
            } ?></td>
238
    </tr>
239
    <?php if (getDolGlobalString('TAKEPOS_TICKET_VAT_GROUPPED')) {
240
        $vat_groups = array();
241
        foreach ($object->lines as $line) {
242
            if (!array_key_exists($line->tva_tx, $vat_groups)) {
243
                $vat_groups[$line->tva_tx] = 0;
244
            }
245
            $vat_groups[$line->tva_tx] += $line->total_tva;
246
        }
247
        // Loop on each VAT group
248
        foreach ($vat_groups as $key => $val) {
249
            ?>
250
            <tr>
251
                <th align="right"><?php if ($gift != 1) {
252
                        echo $langs->trans("VAT") . ' ' . vatrate($key, 1);
253
                    } ?></th>
254
                <td align="right"><?php if ($gift != 1) {
255
                        echo price($val, 1, '', 1, -1, -1, $conf->currency) . "\n";
256
                    } ?></td>
257
            </tr>
258
            <?php
259
        }
260
    } else { ?>
261
        <tr>
262
            <th class="right"><?php if ($gift != 1) {
263
                    echo $langs->trans("TotalVAT") . '</th><td class="right">' . price($object->total_tva, 1, '', 1, -1, -1, $conf->currency) . "\n";
264
                } ?></td>
265
        </tr>
266
    <?php }
267
268
    // Now show local taxes if company uses them
269
270
    if (price2num($object->total_localtax1, 'MU') || $mysoc->useLocalTax(1)) { ?>
271
        <tr>
272
            <th class="right"><?php if ($gift != 1) {
273
                    echo '' . $langs->trans("TotalLT1") . '</th><td class="right">' . price($object->total_localtax1, 1, '', 1, -1, -1, $conf->currency) . "\n";
274
                } ?></td>
275
        </tr>
276
    <?php } ?>
277
    <?php if (price2num($object->total_localtax2, 'MU') || $mysoc->useLocalTax(2)) { ?>
278
        <tr>
279
            <th class="right"><?php if ($gift != 1) {
280
                    echo '' . $langs->trans("TotalLT2") . '</th><td class="right">' . price($object->total_localtax2, 1, '', 1, -1, -1, $conf->currency) . "\n";
281
                } ?></td>
282
        </tr>
283
    <?php } ?>
284
    <tr>
285
        <th class="right"><?php if ($gift != 1) {
286
                echo '' . $langs->trans("TotalTTC") . '</th><td class="right">' . price($object->total_ttc, 1, '', 1, -1, -1, $conf->currency) . "\n";
287
            } ?></td>
288
    </tr>
289
    <?php
290
    if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
291
        //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
292
        $multicurrency = new MultiCurrency($db);
293
        $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
294
        echo '<tr><th class="right">';
295
        if ($gift != 1) {
296
            echo '' . $langs->trans("TotalTTC") . ' ' . $_SESSION["takeposcustomercurrency"] . '</th><td class="right">' . price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, -1, -1, $_SESSION["takeposcustomercurrency"]) . "\n";
297
        }
298
        echo '</td></tr>';
299
    }
300
301
    if (getDolGlobalString('TAKEPOS_PRINT_PAYMENT_METHOD')) {
302
        if (empty($facid)) {
303
            // Case of specimen
304
            echo '<tr>';
305
            echo '<td class="right">';
306
            echo $langs->transnoentitiesnoconv("PaymentTypeShortLIQ");
307
            echo '</td>';
308
            echo '<td class="right">';
309
            $amount_payment = 0;
310
            echo price($amount_payment, 1, '', 1, -1, -1, $conf->currency);
311
            echo '</td>';
312
            echo '</tr>';
313
        } else {
314
            $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num,";
315
            $sql .= " f.multicurrency_code,";
316
            $sql .= " pf.amount as amount, pf.multicurrency_amount,";
317
            $sql .= " cp.code";
318
            $sql .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf, " . MAIN_DB_PREFIX . "facture as f, " . MAIN_DB_PREFIX . "paiement as p";
319
            $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_paiement as cp ON p.fk_paiement = cp.id";
320
            $sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid AND pf.fk_facture = " . ((int)$facid);
321
            $sql .= " ORDER BY p.datep";
322
323
            $resql = $db->query($sql);
324
            if ($resql) {
325
                $num = $db->num_rows($resql);
326
327
                $i = 0;
328
                while ($i < $num) {
329
                    $row = $db->fetch_object($resql);
330
331
                    echo '<tr>';
332
                    echo '<td class="right">';
333
                    echo $langs->transnoentitiesnoconv("PaymentTypeShort" . $row->code);
334
                    echo '</td>';
335
                    echo '<td class="right">';
336
                    $amount_payment = (isModEnabled('multicurrency') && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
337
                    //print "xx ".$row->multicurrency_amount." - ".$row->amount." - ".$amount_payment." - ".$object->multicurrency_tx;
338
                    if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
339
                        $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if it's cash payment
340
                        $currency = $conf->currency;
341
                    } else {
342
                        // We do not show change if payment into a different currency because not yet supported
343
                        $currency = $row->multicurrency_code;
344
                    }
345
                    echo price($amount_payment, 1, '', 1, -1, -1, $currency);
346
                    echo '</td>';
347
                    echo '</tr>';
348
                    if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
349
                        echo '<tr>';
350
                        echo '<td class="right">';
351
                        echo $langs->trans("Change");   // ChangeBack ?
352
                        echo '</td>';
353
                        echo '<td class="right">';
354
                        echo price($row->pos_change, 1, '', 1, -1, -1, $currency);
355
                        echo '</td>';
356
                        echo '</tr>';
357
                    }
358
                    $i++;
359
                }
360
            }
361
        }
362
    }
363
    ?>
364
</table>
365
<div style="border-top-style: double;">
366
    <br>
367
    <br>
368
    <br>
369
    <?php
370
    $constFreeText = 'TAKEPOS_FOOTER' . (empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
371
    if (getDolGlobalString('TAKEPOS_FOOTER') || getDolGlobalString($constFreeText)) {
372
        $newfreetext = '';
373
        $substitutionarray = getCommonSubstitutionArray($langs);
374
        if (getDolGlobalString($constFreeText)) {
375
            $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
376
        }
377
        if (getDolGlobalString('TAKEPOS_FOOTER')) {
378
            $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_FOOTER'), $substitutionarray);
379
        }
380
        print $newfreetext;
381
    }
382
    ?>
383
384
    <script type="text/javascript">
385
        <?php
386
        if ($facid) {
387
            print 'window.print();';
388
        } //Avoid print when is specimen
389
        ?>
390
    </script>
391
392
</body>
393
</html>
394