1<?php
2/* Copyright (C) 2007-2008 Jeremie Ollivier    <jeremie.o@laposte.net>
3 * Copyright (C) 2011      Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012      Marcos García       <marcosgdf@gmail.com>
5 * Copyright (C) 2018      Andreu Bisquerra    <jove@bisquerra.com>
6 * Copyright (C) 2019      Josep Lluís Amador  <joseplluis@lliuretic.cat>
7 * Copyright (C) 2021    Nicolas ZABOURI    <info@inovea-conseil.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23/**
24 *	\file       htdocs/takepos/receipt.php
25 *	\ingroup    takepos
26 *	\brief      Page to show a receipt.
27 */
28
29if (!isset($action)) {
30	//if (! defined('NOREQUIREUSER'))	define('NOREQUIREUSER', '1');	// Not disabled cause need to load personalized language
31	//if (! defined('NOREQUIREDB'))		define('NOREQUIREDB', '1');		// Not disabled cause need to load personalized language
32	//if (! defined('NOREQUIRESOC'))		define('NOREQUIRESOC', '1');
33	//if (! defined('NOREQUIRETRAN'))		define('NOREQUIRETRAN', '1');
34	if (!defined('NOTOKENRENEWAL')) {
35		define('NOTOKENRENEWAL', '1');
36	}
37	if (!defined('NOREQUIREMENU')) {
38		define('NOREQUIREMENU', '1');
39	}
40	if (!defined('NOREQUIREHTML')) {
41		define('NOREQUIREHTML', '1');
42	}
43	if (!defined('NOREQUIREAJAX')) {
44		define('NOREQUIREAJAX', '1');
45	}
46
47	require '../main.inc.php'; // If this file is called from send.php avoid load again
48}
49include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
50
51$langs->loadLangs(array("main", "cashdesk", "companies"));
52
53$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
54
55$facid = GETPOST('facid', 'int');
56
57$gift = GETPOST('gift', 'int');
58
59if (empty($user->rights->takepos->run)) {
60	accessforbidden();
61}
62
63
64/*
65 * View
66 */
67
68top_httphead('text/html');
69
70if ($place > 0) {
71	$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
72	$resql = $db->query($sql);
73	$obj = $db->fetch_object($resql);
74	if ($obj) {
75		$facid = $obj->rowid;
76	}
77}
78$object = new Facture($db);
79$object->fetch($facid);
80
81// Call to external receipt modules if exist
82$hookmanager->initHooks(array('takeposfrontend'), $facid);
83$reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
84if (!empty($hookmanager->resPrint)) {
85	print $hookmanager->resPrint;
86	exit;
87}
88
89// 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.
90?>
91<html>
92<body>
93<style>
94.right {
95	text-align: right;
96}
97.center {
98	text-align: center;
99}
100.left {
101	text-align: left;
102}
103</style>
104<center>
105<font size="4">
106<?php echo '<b>'.$mysoc->name.'</b>'; ?>
107</font>
108</center>
109<br>
110<p class="left">
111<?php
112$constFreeText = 'TAKEPOS_HEADER'.$_SESSION['takeposterminal'];
113if (!empty($conf->global->TAKEPOS_HEADER) || !empty($conf->global->{$constFreeText})) {
114	$newfreetext = '';
115	$substitutionarray = getCommonSubstitutionArray($langs);
116	if (!empty($conf->global->TAKEPOS_HEADER)) {
117		$newfreetext .= make_substitutions($conf->global->TAKEPOS_HEADER, $substitutionarray);
118	}
119	if (!empty($conf->global->{$constFreeText})) {
120		$newfreetext .= make_substitutions($conf->global->{$constFreeText}, $substitutionarray);
121	}
122	print nl2br($newfreetext);
123}
124?>
125</p>
126<p class="right">
127<?php
128print $langs->trans('Date')." ".dol_print_date($object->date, 'day').'<br>';
129if (!empty($conf->global->TAKEPOS_RECEIPT_NAME)) {
130	print $conf->global->TAKEPOS_RECEIPT_NAME." ";
131}
132if ($object->statut == Facture::STATUS_DRAFT) {
133	print str_replace(")", "", str_replace("-", " ".$langs->trans('Place')." ", str_replace("(PROV-POS", $langs->trans("Terminal")." ", $object->ref)));
134} else {
135	print $object->ref;
136}
137if ($conf->global->TAKEPOS_SHOW_CUSTOMER) {
138	if ($object->socid != $conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]}) {
139		$soc = new Societe($db);
140		if ($object->socid > 0) {
141			$soc->fetch($object->socid);
142		} else {
143			$soc->fetch($conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]});
144		}
145		print "<br>".$langs->trans("Customer").': '.$soc->name;
146	}
147}
148?>
149</p>
150<br>
151
152<table width="100%" style="border-top-style: double;">
153	<thead>
154	<tr>
155		<th class="center"><?php print $langs->trans("Label"); ?></th>
156		<th class="right"><?php print $langs->trans("Qty"); ?></th>
157		<th class="right"><?php if ($gift != 1) {
158			print $langs->trans("Price");
159						  } ?></th>
160		<?php  if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) { ?>
161		<th class="right"><?php if ($gift != 1) {
162			print $langs->trans("TotalHT");
163						  } ?></th>
164		<?php } ?>
165		<th class="right"><?php if ($gift != 1) {
166			print $langs->trans("TotalTTC");
167						  } ?></th>
168	</tr>
169	</thead>
170	<tbody>
171	<?php
172	foreach ($object->lines as $line) {
173		?>
174	<tr>
175		<td>
176		<?php if (!empty($line->product_label)) {
177			echo $line->product_label;
178		} else {
179			echo $line->description;
180		} ?>
181		</td>
182		<td class="right"><?php echo $line->qty; ?></td>
183		<td class="right"><?php if ($gift != 1) {
184			echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
185						  } ?></td>
186		<?php
187		if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) { ?>
188					<td class="right"><?php if ($gift != 1) {
189						echo price($line->total_ht, 1);
190									  } ?></td>
191			<?php
192		}
193		?>
194		<td class="right"><?php if ($gift != 1) {
195			echo price($line->total_ttc, 1);
196						  } ?></td>
197	</tr>
198		<?php
199	}
200	?>
201	</tbody>
202</table>
203<br>
204<table class="right">
205<tr>
206	<th class="right"><?php if ($gift != 1) {
207		echo $langs->trans("TotalHT");
208					  } ?></th>
209	<td class="right"><?php if ($gift != 1) {
210		echo price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency)."\n";
211					  } ?></td>
212</tr>
213<?php if ($conf->global->TAKEPOS_TICKET_VAT_GROUPPED) {
214	$vat_groups = array();
215	foreach ($object->lines as $line) {
216		if (!array_key_exists($line->tva_tx, $vat_groups)) {
217			$vat_groups[$line->tva_tx] = 0;
218		}
219		$vat_groups[$line->tva_tx] += $line->total_tva;
220	}
221	foreach ($vat_groups as $key => $val) {
222		?>
223	<tr>
224		<th align="right"><?php if ($gift != 1) {
225			echo $langs->trans("VAT").' '.vatrate($key, 1);
226						  } ?></th>
227		<td align="right"><?php if ($gift != 1) {
228			echo price($val, 1, '', 1, - 1, - 1, $conf->currency)."\n";
229						  } ?></td>
230	</tr>
231		<?php
232	}
233} else { ?>
234<tr>
235	<th class="right"><?php if ($gift != 1) {
236		echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n";
237					  } ?></td>
238</tr>
239<?php } ?>
240<tr>
241	<th class="right"><?php if ($gift != 1) {
242		echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";
243					  } ?></td>
244</tr>
245<?php
246if (!empty($conf->multicurrency->enabled) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
247	//Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
248	include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
249	$multicurrency = new MultiCurrency($db);
250	$multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
251	echo '<tr><th class="right">';
252	if ($gift != 1) {
253		echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
254	}
255	echo '</td></tr>';
256}
257
258if ($conf->global->TAKEPOS_PRINT_PAYMENT_METHOD) {
259	$sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
260	$sql .= " cp.code";
261	$sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
262	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
263	$sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
264	$sql .= " ORDER BY p.datep";
265	$resql = $db->query($sql);
266	if ($resql) {
267		$num = $db->num_rows($resql);
268		$i = 0;
269		while ($i < $num) {
270			$row = $db->fetch_object($resql);
271			echo '<tr>';
272			echo '<td class="right">';
273			echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
274			echo '</td>';
275			echo '<td class="right">';
276			$amount_payment = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
277			if ($row->code == "LIQ") {
278				$amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if is cash payment
279			}
280			echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
281			echo '</td>';
282			echo '</tr>';
283			if ($row->code == "LIQ" && $row->pos_change > 0) { // Print change only in cash payments
284				echo '<tr>';
285				echo '<td class="right">';
286				echo $langs->trans("Change");
287				echo '</td>';
288				echo '<td class="right">';
289				echo price($row->pos_change, 1, '', 1, - 1, - 1, $conf->currency);
290				echo '</td>';
291				echo '</tr>';
292			}
293			$i++;
294		}
295	}
296}
297?>
298</table>
299<div style="border-top-style: double;">
300<br>
301<br>
302<br>
303<?php
304$constFreeText = 'TAKEPOS_FOOTER'.$_SESSION['takeposterminal'];
305if (!empty($conf->global->TAKEPOS_FOOTER) || !empty($conf->global->{$constFreeText})) {
306	$newfreetext = '';
307	$substitutionarray = getCommonSubstitutionArray($langs);
308	if (!empty($conf->global->{$constFreeText})) {
309		$newfreetext .= make_substitutions($conf->global->{$constFreeText}, $substitutionarray);
310	}
311	if (!empty($conf->global->TAKEPOS_FOOTER)) {
312		$newfreetext .= make_substitutions($conf->global->TAKEPOS_FOOTER, $substitutionarray);
313	}
314	print $newfreetext;
315}
316?>
317
318<script type="text/javascript">
319	window.print();
320</script>
321
322</body>
323</html>
324