dolibarr  13.0.2
receipt.php
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  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../../main.inc.php'; // Load $user and permissions
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
30 require_once DOL_DOCUMENT_ROOT."/core/lib/takepos.lib.php";
31 
32 // Security check
33 if (!$user->admin) accessforbidden();
34 
35 $langs->loadLangs(array("admin", "cashdesk", "commercial"));
36 
37 /*
38  * Actions
39  */
40 
41 if (GETPOST('action', 'alpha') == 'set')
42 {
43  $db->begin();
44 
45  $res = dolibarr_set_const($db, "TAKEPOS_HEADER", GETPOST('TAKEPOS_HEADER', 'alpha'), 'chaine', 0, '', $conf->entity);
46  $res = dolibarr_set_const($db, "TAKEPOS_FOOTER", GETPOST('TAKEPOS_FOOTER', 'alpha'), 'chaine', 0, '', $conf->entity);
47  $res = dolibarr_set_const($db, "TAKEPOS_RECEIPT_NAME", GETPOST('TAKEPOS_RECEIPT_NAME', 'alpha'), 'chaine', 0, '', $conf->entity);
48  $res = dolibarr_set_const($db, "TAKEPOS_SHOW_CUSTOMER", GETPOST('TAKEPOS_SHOW_CUSTOMER', 'alpha'), 'chaine', 0, '', $conf->entity);
49  $res = dolibarr_set_const($db, "TAKEPOS_AUTO_PRINT_TICKETS", GETPOST('TAKEPOS_AUTO_PRINT_TICKETS', 'int'), 'int', 0, '', $conf->entity);
50  $res = dolibarr_set_const($db, "TAKEPOS_PRINT_SERVER", GETPOST('TAKEPOS_PRINT_SERVER', 'alpha'), 'chaine', 0, '', $conf->entity);
51  $res = dolibarr_set_const($db, "TAKEPOS_PRINT_PAYMENT_METHOD", GETPOST('TAKEPOS_PRINT_PAYMENT_METHOD', 'alpha'), 'chaine', 0, '', $conf->entity);
52 
53  dol_syslog("admin/cashdesk: level ".GETPOST('level', 'alpha'));
54 
55  if (!($res > 0)) $error++;
56 
57  if (!$error)
58  {
59  $db->commit();
60  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
61  } else {
62  $db->rollback();
63  setEventMessages($langs->trans("Error"), null, 'errors');
64  }
65 } elseif (GETPOST('action', 'alpha') == 'setmethod')
66 {
67  dolibarr_set_const($db, "TAKEPOS_PRINT_METHOD", GETPOST('value', 'alpha'), 'chaine', 0, '', $conf->entity);
68  // TakePOS connector require ReceiptPrinter module
69  if ($conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector" && !$conf->receiptprinter->enabled) activateModule("modReceiptPrinter");
70 }
71 
72 
73 /*
74  * View
75  */
76 
77 $form = new Form($db);
78 $formproduct = new FormProduct($db);
79 
80 llxHeader('', $langs->trans("CashDeskSetup"));
81 
82 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
83 print load_fiche_titre($langs->trans("CashDeskSetup").' (TakePOS)', $linkback, 'title_setup');
85 print dol_get_fiche_head($head, 'receipt', 'TakePOS', -1, 'cash-register');
86 
87 print '<form action="'.$_SERVER["PHP_SELF"].'?terminal='.(empty($terminal) ? 1 : $terminal).'" method="post">';
88 print '<input type="hidden" name="token" value="'.newToken().'">';
89 print '<input type="hidden" name="action" value="set">';
90 
91 print load_fiche_titre($langs->trans("PrintMethod"), '', '');
92 
93 print '<div class="div-table-responsive-no-min">';
94 print '<table class="noborder centpercent">';
95 print '<tr class="liste_titre">';
96 print '<td>'.$langs->trans("Name").'</td><td>'.$langs->trans("Description").'</td><td class="right">'.$langs->trans("Status").'</td>';
97 print "</tr>\n";
98 
99 // Browser method
100 print '<tr class="oddeven"><td>';
101 print $langs->trans('Browser');
102 print '<td>';
103 print $langs->trans('BrowserMethodDescription');
104 print '</td><td class="right">';
105 if ($conf->global->TAKEPOS_PRINT_METHOD == "browser")
106 {
107  print img_picto($langs->trans("Activated"), 'switch_on');
108 } else {
109  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmethod&token='.newToken().'&value=browser">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
110 }
111 print "</td></tr>\n";
112 
113 // Receipt printer module
114 print '<tr class="oddeven"><td>';
115 print $langs->trans('DolibarrReceiptPrinter');
116 print '<td>';
117 print $langs->trans('ReceiptPrinterMethodDescription');
118 print '<br>';
119 print '<a href="'.DOL_URL_ROOT.'/admin/receiptprinter.php">'.$langs->trans("Setup").'</a>';
120 print '</td><td class="right">';
121 if ($conf->receiptprinter->enabled) {
122  if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter") {
123  print img_picto($langs->trans("Activated"), 'switch_on');
124  } else {
125  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmethod&token='.newToken().'&value=receiptprinter">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
126  }
127 } else {
128  print '<span class="opacitymedium">';
129  print $langs->trans("ModuleReceiptPrinterMustBeEnabled");
130  print '</span>';
131 }
132 print "</td></tr>\n";
133 
134 // TakePOS Connector
135 print '<tr class="oddeven"><td>';
136 print "TakePOS Connector";
137 print '<td>';
138 print $langs->trans('TakeposConnectorMethodDescription');
139 print '</td><td class="right">';
140 if ($conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector")
141 {
142  print img_picto($langs->trans("Activated"), 'switch_on');
143 } else {
144  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmethod&token='.newToken().'&value=takeposconnector">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
145 }
146 print "</td></tr>\n";
147 print '</table>';
148 print '</div>';
149 
150 
151 print load_fiche_titre($langs->trans("Setup"), '', '');
152 
153 print '<div class="div-table-responsive-no-min">';
154 print '<table class="noborder centpercent">';
155 print '<tr class="liste_titre">';
156 print '<td>'.$langs->trans("Parameters").'</td><td>'.$langs->trans("Value").'</td>';
157 print "</tr>\n";
158 
159 // VAT Grouped on ticket
160 print '<tr class="oddeven"><td>';
161 print $langs->trans('TicketVatGrouped');
162 print '<td colspan="2">';
163 print ajax_constantonoff("TAKEPOS_TICKET_VAT_GROUPPED", array(), $conf->entity, 0, 0, 1, 0);
164 //print $form->selectyesno("TAKEPOS_TICKET_VAT_GROUPPED", $conf->global->TAKEPOS_TICKET_VAT_GROUPPED, 1);
165 print "</td></tr>\n";
166 
167 if ($conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") {
168  print '<tr class="oddeven value"><td>';
169  print $langs->trans("URL")." / ".$langs->trans("IPAddress").' (<a href="http://en.takepos.com/connector" target="_blank">'.$langs->trans("TakeposConnectorNecesary").'</a>)';
170  print '<td colspan="2">';
171  print '<input type="text" size="20" id="TAKEPOS_PRINT_SERVER" name="TAKEPOS_PRINT_SERVER" value="'.$conf->global->TAKEPOS_PRINT_SERVER.'">';
172  print '</td></tr>';
173 }
174 
175 if ($conf->global->TAKEPOS_PRINT_METHOD == "browser" || $conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") {
176  $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
177  $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
178  $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
179  foreach ($substitutionarray as $key => $val) $htmltext .= $key.'<br>';
180  $htmltext .= '</i>';
181 
182  print '<tr class="oddeven"><td>';
183  print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices")." - ".$langs->trans("Header"), $htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
184  print '</td><td>';
185  $variablename = 'TAKEPOS_HEADER';
186  if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
187  {
188  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
189  } else {
190  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
191  $doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes');
192  print $doleditor->Create();
193  }
194  print "</td></tr>\n";
195 
196  print '<tr class="oddeven"><td>';
197  print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices")." - ".$langs->trans("Footer"), $htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
198  print '</td><td>';
199  $variablename = 'TAKEPOS_FOOTER';
200  if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
201  {
202  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
203  } else {
204  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
205  $doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes');
206  print $doleditor->Create();
207  }
208  print "</td></tr>\n";
209 
210  print '<tr class="oddeven"><td><label for="receipt_name">'.$langs->trans("ReceiptName").'</label></td><td>';
211  print '<input name="TAKEPOS_RECEIPT_NAME" id="TAKEPOS_RECEIPT_NAME" class="minwidth200" value="'.(!empty($conf->global->TAKEPOS_RECEIPT_NAME) ? $conf->global->TAKEPOS_RECEIPT_NAME : '').'">';
212  print '</td></tr>';
213 
214  // Customer information
215  print '<tr class="oddeven"><td>';
216  print $langs->trans('PrintCustomerOnReceipts');
217  print '<td colspan="2">';
218  print $form->selectyesno("TAKEPOS_SHOW_CUSTOMER", $conf->global->TAKEPOS_SHOW_CUSTOMER, 1);
219  print "</td></tr>\n";
220 
221  // Print payment method
222  print '<tr class="oddeven"><td>';
223  print $langs->trans('PrintPaymentMethodOnReceipts');
224  print '<td colspan="2">';
225  print $form->selectyesno("TAKEPOS_PRINT_PAYMENT_METHOD", $conf->global->TAKEPOS_PRINT_PAYMENT_METHOD, 1);
226  print "</td></tr>\n";
227 }
228 
229 // Auto print tickets
230 print '<tr class="oddeven"><td>';
231 print $langs->trans("AutoPrintTickets");
232 print '<td colspan="2">';
233 print $form->selectyesno("TAKEPOS_AUTO_PRINT_TICKETS", $conf->global->TAKEPOS_AUTO_PRINT_TICKETS, 1);
234 print "</td></tr>\n";
235 
236 if ($conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector" && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
237  print '<tr class="oddeven"><td>';
238  print $langs->trans('WeighingScale');
239  print '<td colspan="2">';
240  print ajax_constantonoff("TAKEPOS_WEIGHING_SCALE", array(), $conf->entity, 0, 0, 1, 0);
241  print "</td></tr>\n";
242 }
243 
244 print '</table>';
245 print '</div>';
246 
247 print '<br>';
248 
249 print '<div class="center"><input type="submit" class="button button-save" value="'.$langs->trans("Save").'"></div>';
250 
251 print "</form>\n";
252 
253 print '<br>';
254 
255 llxFooter();
256 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:575
Class with static methods for building HTML components related to products Only components common to ...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
takepos_admin_prepare_head()
Prepare array with list of tabs.
Definition: takepos.lib.php:29
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0)
On/off button for constant.
Definition: ajax.lib.php:503
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
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 ...
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:643
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
activateModule($value, $withdeps=1)
Enable a module.
Definition: admin.lib.php:971
Class to manage a WYSIWYG editor.
llxFooter()
Empty footer.
Definition: wrapper.php:59