dolibarr  16.0.5
receipt.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2011-2017 Juanjo Menent <jmenent@2byte.es>
4  * Copyright (C) 2019 Andreu Bisquerra Gaya <jove@bisquerra.com>
5  * Copyright (C) 2021 Nicolas ZABOURI <info@inovea-conseil.com>
6  * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
28 require '../../main.inc.php'; // Load $user and permissions
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
32 require_once DOL_DOCUMENT_ROOT."/core/lib/takepos.lib.php";
33 
34 // Security check
35 if (!$user->admin) {
37 }
38 
39 $langs->loadLangs(array("admin", "cashdesk", "commercial"));
40 
41 /*
42  * Actions
43  */
44 
45 if (GETPOST('action', 'alpha') == 'set') {
46  $db->begin();
47 
48  $res = dolibarr_set_const($db, "TAKEPOS_HEADER", GETPOST('TAKEPOS_HEADER', 'restricthtml'), 'chaine', 0, '', $conf->entity);
49  $res = dolibarr_set_const($db, "TAKEPOS_FOOTER", GETPOST('TAKEPOS_FOOTER', 'restricthtml'), 'chaine', 0, '', $conf->entity);
50  $res = dolibarr_set_const($db, "TAKEPOS_RECEIPT_NAME", GETPOST('TAKEPOS_RECEIPT_NAME', 'alpha'), 'chaine', 0, '', $conf->entity);
51  $res = dolibarr_set_const($db, "TAKEPOS_PRINT_SERVER", GETPOST('TAKEPOS_PRINT_SERVER', 'alpha'), 'chaine', 0, '', $conf->entity);
52  $res = dolibarr_set_const($db, 'TAKEPOS_PRINT_WITHOUT_DETAILS_LABEL_DEFAULT', GETPOST('TAKEPOS_PRINT_WITHOUT_DETAILS_LABEL_DEFAULT', 'alphanohtml'), 'chaine', 0, '', $conf->entity);
53 
54  dol_syslog("admin/cashdesk: level ".GETPOST('level', 'alpha'));
55 
56  if (!($res > 0)) {
57  $error++;
58  }
59 
60  if (!$error) {
61  $db->commit();
62  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
63  } else {
64  $db->rollback();
65  setEventMessages($langs->trans("Error"), null, 'errors');
66  }
67 } elseif (GETPOST('action', 'alpha') == 'setmethod') {
68  dolibarr_set_const($db, "TAKEPOS_PRINT_METHOD", GETPOST('value', 'alpha'), 'chaine', 0, '', $conf->entity);
69  // TakePOS connector require ReceiptPrinter module
70  if ($conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector" && !isModEnabled('receiptprinter')) {
71  activateModule("modReceiptPrinter");
72  }
73 }
74 
75 
76 /*
77  * View
78  */
79 
80 $form = new Form($db);
81 $formproduct = new FormProduct($db);
82 
83 llxHeader('', $langs->trans("CashDeskSetup"));
84 
85 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
86 print load_fiche_titre($langs->trans("CashDeskSetup").' (TakePOS)', $linkback, 'title_setup');
88 print dol_get_fiche_head($head, 'receipt', 'TakePOS', -1, 'cash-register');
89 
90 print '<form action="'.$_SERVER["PHP_SELF"].'?terminal='.(empty($terminal) ? 1 : $terminal).'" method="post">';
91 print '<input type="hidden" name="token" value="'.newToken().'">';
92 print '<input type="hidden" name="action" value="set">';
93 
94 print load_fiche_titre($langs->trans("PrintMethod"), '', '');
95 
96 print '<div class="div-table-responsive-no-min">';
97 print '<table class="noborder centpercent">';
98 print '<tr class="liste_titre">';
99 print '<td>'.$langs->trans("Name").'</td><td>'.$langs->trans("Description").'</td><td class="right">'.$langs->trans("Status").'</td>';
100 print "</tr>\n";
101 
102 // Browser method
103 print '<tr class="oddeven"><td>';
104 print $langs->trans('Browser');
105 print '<td>';
106 print $langs->trans('BrowserMethodDescription');
107 print '</td><td class="right">';
108 if ($conf->global->TAKEPOS_PRINT_METHOD == "browser") {
109  print img_picto($langs->trans("Activated"), 'switch_on');
110 } else {
111  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmethod&token='.newToken().'&value=browser">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
112 }
113 print "</td></tr>\n";
114 
115 // Receipt printer module
116 print '<tr class="oddeven"><td>';
117 print $langs->trans('DolibarrReceiptPrinter');
118 print '<td>';
119 print $langs->trans('ReceiptPrinterMethodDescription');
120 if (isModEnabled('receiptprinter')) {
121  if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
122  print '<br>';
123  print img_picto('', 'printer', 'class="paddingright"').'<a href="'.DOL_URL_ROOT.'/admin/receiptprinter.php">'.$langs->trans("Setup").'</a>';
124  }
125 }
126 print '</td><td class="right">';
127 if (isModEnabled('receiptprinter')) {
128  if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
129  print img_picto($langs->trans("Activated"), 'switch_on');
130  } else {
131  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmethod&token='.newToken().'&value=receiptprinter">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
132  }
133 } else {
134  print '<span class="opacitymedium">';
135  print $langs->trans("ModuleReceiptPrinterMustBeEnabled");
136  print '</span>';
137 }
138 print "</td></tr>\n";
139 
140 // TakePOS Connector
141 print '<tr class="oddeven"><td>';
142 print "TakePOS Connector";
143 print '<td>';
144 print $langs->trans('TakeposConnectorMethodDescription');
145 
146 if ($conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") {
147  print '<br>';
148  print $langs->trans("URL")." / ".$langs->trans("IPAddress").' (<a href="http://en.takepos.com/connector" target="_blank" rel="noopener noreferrer external">'.$langs->trans("TakeposConnectorNecesary").'</a>)';
149  print ' <input type="text" class="minwidth200" id="TAKEPOS_PRINT_SERVER" name="TAKEPOS_PRINT_SERVER" value="'.getDolGlobalString('TAKEPOS_PRINT_SERVER').'">';
150 }
151 
152 print '</td><td class="right">';
153 if ($conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") {
154  print img_picto($langs->trans("Activated"), 'switch_on');
155 } else {
156  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmethod&token='.newToken().'&value=takeposconnector">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
157 }
158 print "</td></tr>\n";
159 print '</table>';
160 print '</div>';
161 
162 
163 print load_fiche_titre($langs->trans("Receipt"), '', '');
164 
165 print '<div class="div-table-responsive-no-min">';
166 print '<table class="noborder centpercent">';
167 print '<tr class="liste_titre">';
168 print '<td>'.$langs->trans("Parameters").'</td><td>'.$langs->trans("Value").'</td>';
169 print "</tr>\n";
170 
171 // VAT Grouped on ticket
172 print '<tr class="oddeven"><td>';
173 print $langs->trans('TicketVatGrouped');
174 print '<td colspan="2">';
175 print ajax_constantonoff("TAKEPOS_TICKET_VAT_GROUPPED", array(), $conf->entity, 0, 0, 1, 0);
176 //print $form->selectyesno("TAKEPOS_TICKET_VAT_GROUPPED", $conf->global->TAKEPOS_TICKET_VAT_GROUPPED, 1);
177 print "</td></tr>\n";
178 
179 if ($conf->global->TAKEPOS_PRINT_METHOD == "browser" || $conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") {
180  $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
181  $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
182  $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
183  foreach ($substitutionarray as $key => $val) {
184  $htmltext .= $key.'<br>';
185  }
186  $htmltext .= '</i>';
187 
188  print '<tr class="oddeven"><td>';
189  print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices")." - ".$langs->trans("Header"), $htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
190  print '</td><td>';
191  $variablename = 'TAKEPOS_HEADER';
192  if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
193  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
194  } else {
195  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
196  $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
197  print $doleditor->Create();
198  }
199  print "</td></tr>\n";
200 
201  print '<tr class="oddeven"><td>';
202  print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices")." - ".$langs->trans("Footer"), $htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
203  print '</td><td>';
204  $variablename = 'TAKEPOS_FOOTER';
205  if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
206  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
207  } else {
208  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
209  $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
210  print $doleditor->Create();
211  }
212  print "</td></tr>\n";
213 
214  print '<tr class="oddeven"><td><label for="receipt_name">'.$langs->trans("ReceiptName").'</label></td><td>';
215  print '<input name="TAKEPOS_RECEIPT_NAME" id="TAKEPOS_RECEIPT_NAME" class="minwidth200" value="'.(!empty($conf->global->TAKEPOS_RECEIPT_NAME) ? $conf->global->TAKEPOS_RECEIPT_NAME : '').'">';
216  print '</td></tr>';
217 
218  // Customer information
219  print '<tr class="oddeven"><td>';
220  print $langs->trans('PrintCustomerOnReceipts');
221  print '<td colspan="2">';
222  print ajax_constantonoff("TAKEPOS_SHOW_CUSTOMER", array(), $conf->entity, 0, 0, 1, 0);
223  print "</td></tr>\n";
224 
225  // Print payment method
226  print '<tr class="oddeven"><td>';
227  print $langs->trans('PrintPaymentMethodOnReceipts');
228  print '<td colspan="2">';
229  print ajax_constantonoff("TAKEPOS_PRINT_PAYMENT_METHOD", array(), $conf->entity, 0, 0, 1, 0);
230  print "</td></tr>\n";
231 }
232 
233 // Auto print tickets
234 print '<tr class="oddeven"><td>';
235 print $langs->trans("AutoPrintTickets");
236 print '<td colspan="2">';
237 print ajax_constantonoff("TAKEPOS_AUTO_PRINT_TICKETS", array(), $conf->entity, 0, 0, 1, 0);
238 print "</td></tr>\n";
239 
240 
241 // Show price without vat
242 print '<tr class="oddeven"><td>';
243 print $langs->trans('ShowPriceHTOnReceipt');
244 print '<td colspan="2">';
245 print ajax_constantonoff("TAKEPOS_SHOW_HT_RECEIPT", array(), $conf->entity, 0, 0, 1, 0);
246 print "</td></tr>\n";
247 
248 if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector" && filter_var(getDolGlobalString('TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) == true) {
249  print '<tr class="oddeven"><td>';
250  print $langs->trans('WeighingScale');
251  print '<td colspan="2">';
252  print ajax_constantonoff("TAKEPOS_WEIGHING_SCALE", array(), $conf->entity, 0, 0, 1, 0);
253  print "</td></tr>\n";
254 }
255 
256 if ($conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector" && filter_var(getDolGlobalString('TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) == true) {
257  print '<tr class="oddeven"><td>';
258  print $langs->trans('CustomerDisplay');
259  print '<td colspan="2">';
260  print ajax_constantonoff("TAKEPOS_CUSTOMER_DISPLAY", array(), $conf->entity, 0, 0, 1, 0);
261  print "</td></tr>\n";
262 }
263 
264 // Print without details
265 print '<tr class="oddeven"><td>';
266 print $langs->trans('PrintWithoutDetailsButton');
267 print '<td colspan="2">';
268 print ajax_constantonoff('TAKEPOS_PRINT_WITHOUT_DETAILS', array(), $conf->entity, 0, 0, 1, 0);
269 print "</td></tr>\n";
270 if (!empty($conf->global->TAKEPOS_PRINT_WITHOUT_DETAILS)) {
271  print '<tr class="oddeven"><td>';
272  print $langs->trans('PrintWithoutDetailsLabelDefault');
273  print '<td colspan="2">';
274  print '<input type="text" name="TAKEPOS_PRINT_WITHOUT_DETAILS_LABEL_DEFAULT" value="' . getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS_LABEL_DEFAULT') . '" />';
275  print "</td></tr>\n";
276 }
277 
278 print '</table>';
279 print '</div>';
280 
281 print '<br>';
282 
283 print $form->buttonsSaveCancel("Save", '');
284 
285 print "</form>\n";
286 
287 print '<br>';
288 
289 llxFooter();
290 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
activateModule
activateModule($value, $withdeps=1)
Enable a module.
Definition: admin.lib.php:1075
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
takepos_admin_prepare_head
takepos_admin_prepare_head()
Prepare array with list of tabs.
Definition: takepos.lib.php:30
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
ajax_constantonoff
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='')
On/off button for constant.
Definition: ajax.lib.php:573
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
FormProduct
Class with static methods for building HTML components related to products Only components common to ...
Definition: html.formproduct.class.php:30
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
pdf_getSubstitutionArray
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:737
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30