receipt.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/takepos/admin/receipt.php
  23. * \ingroup takepos
  24. * \brief Setup page for TakePos module
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php'; // Load $user and permissions
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  31. require_once DOL_DOCUMENT_ROOT."/core/lib/takepos.lib.php";
  32. // Security check
  33. if (!$user->admin) {
  34. accessforbidden();
  35. }
  36. $langs->loadLangs(array("admin", "cashdesk", "commercial"));
  37. /*
  38. * Actions
  39. */
  40. if (GETPOST('action', 'alpha') == 'set') {
  41. $db->begin();
  42. $res = dolibarr_set_const($db, "TAKEPOS_HEADER", GETPOST('TAKEPOS_HEADER', 'restricthtml'), 'chaine', 0, '', $conf->entity);
  43. $res = dolibarr_set_const($db, "TAKEPOS_FOOTER", GETPOST('TAKEPOS_FOOTER', 'restricthtml'), 'chaine', 0, '', $conf->entity);
  44. $res = dolibarr_set_const($db, "TAKEPOS_RECEIPT_NAME", GETPOST('TAKEPOS_RECEIPT_NAME', 'alpha'), 'chaine', 0, '', $conf->entity);
  45. $res = dolibarr_set_const($db, "TAKEPOS_PRINT_SERVER", GETPOST('TAKEPOS_PRINT_SERVER', 'alpha'), 'chaine', 0, '', $conf->entity);
  46. $res = dolibarr_set_const($db, 'TAKEPOS_PRINT_WITHOUT_DETAILS_LABEL_DEFAULT', GETPOST('TAKEPOS_PRINT_WITHOUT_DETAILS_LABEL_DEFAULT', 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  47. dol_syslog("admin/cashdesk: level ".GETPOST('level', 'alpha'));
  48. if (!($res > 0)) {
  49. $error++;
  50. }
  51. if (!$error) {
  52. $db->commit();
  53. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  54. } else {
  55. $db->rollback();
  56. setEventMessages($langs->trans("Error"), null, 'errors');
  57. }
  58. } elseif (GETPOST('action', 'alpha') == 'setmethod') {
  59. dolibarr_set_const($db, "TAKEPOS_PRINT_METHOD", GETPOST('value', 'alpha'), 'chaine', 0, '', $conf->entity);
  60. // TakePOS connector require ReceiptPrinter module
  61. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector" && !isModEnabled('receiptprinter')) {
  62. activateModule("modReceiptPrinter");
  63. }
  64. }
  65. /*
  66. * View
  67. */
  68. $form = new Form($db);
  69. $formproduct = new FormProduct($db);
  70. llxHeader('', $langs->trans("CashDeskSetup"));
  71. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  72. print load_fiche_titre($langs->trans("CashDeskSetup").' (TakePOS)', $linkback, 'title_setup');
  73. $head = takepos_admin_prepare_head();
  74. print dol_get_fiche_head($head, 'receipt', 'TakePOS', -1, 'cash-register');
  75. print '<form action="'.$_SERVER["PHP_SELF"].'?terminal='.(empty($terminal) ? 1 : $terminal).'" method="post">';
  76. print '<input type="hidden" name="token" value="'.newToken().'">';
  77. print '<input type="hidden" name="action" value="set">';
  78. print load_fiche_titre($langs->trans("Receipt"), '', '');
  79. print '<div class="div-table-responsive-no-min">';
  80. print '<table class="noborder centpercent">';
  81. print '<tr class="liste_titre">';
  82. print '<td>'.$langs->trans("Parameters").'</td><td>'.$langs->trans("Value").'</td>';
  83. print "</tr>\n";
  84. // VAT Grouped on ticket
  85. print '<tr class="oddeven"><td>';
  86. print $langs->trans('TicketVatGrouped');
  87. print '<td colspan="2">';
  88. print ajax_constantonoff("TAKEPOS_TICKET_VAT_GROUPPED", array(), $conf->entity, 0, 0, 1, 0);
  89. print "</td></tr>\n";
  90. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "browser" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
  91. $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
  92. $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
  93. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  94. foreach ($substitutionarray as $key => $val) {
  95. $htmltext .= $key.'<br>';
  96. }
  97. $htmltext .= '</i>';
  98. print '<tr class="oddeven"><td>';
  99. print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices")." - ".$langs->trans("Header"), $htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
  100. print '</td><td>';
  101. $variablename = 'TAKEPOS_HEADER';
  102. if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
  103. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
  104. } else {
  105. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  106. $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
  107. print $doleditor->Create();
  108. }
  109. print "</td></tr>\n";
  110. print '<tr class="oddeven"><td>';
  111. print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices")." - ".$langs->trans("Footer"), $htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
  112. print '</td><td>';
  113. $variablename = 'TAKEPOS_FOOTER';
  114. if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
  115. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
  116. } else {
  117. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  118. $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
  119. print $doleditor->Create();
  120. }
  121. print "</td></tr>\n";
  122. print '<tr class="oddeven"><td><label for="receipt_name">'.$langs->trans("ReceiptName").'</label></td><td>';
  123. print '<input name="TAKEPOS_RECEIPT_NAME" id="TAKEPOS_RECEIPT_NAME" class="minwidth200" value="'.getDolGlobalString('TAKEPOS_RECEIPT_NAME').'">';
  124. print '</td></tr>';
  125. // Customer information
  126. print '<tr class="oddeven"><td>';
  127. print $langs->trans('PrintCustomerOnReceipts');
  128. print '<td colspan="2">';
  129. print ajax_constantonoff("TAKEPOS_SHOW_CUSTOMER", array(), $conf->entity, 0, 0, 1, 0);
  130. print "</td></tr>\n";
  131. // Print payment method
  132. print '<tr class="oddeven"><td>';
  133. print $langs->trans('PrintPaymentMethodOnReceipts');
  134. print '<td colspan="2">';
  135. print ajax_constantonoff("TAKEPOS_PRINT_PAYMENT_METHOD", array(), $conf->entity, 0, 0, 1, 0);
  136. print "</td></tr>\n";
  137. }
  138. // Auto print tickets
  139. print '<tr class="oddeven"><td>';
  140. print $langs->trans("AutoPrintTickets");
  141. print '<td colspan="2">';
  142. print ajax_constantonoff("TAKEPOS_AUTO_PRINT_TICKETS", array(), $conf->entity, 0, 0, 1, 0);
  143. print "</td></tr>\n";
  144. // Show price without vat
  145. print '<tr class="oddeven"><td>';
  146. print $langs->trans('ShowPriceHTOnReceipt');
  147. print '<td colspan="2">';
  148. print ajax_constantonoff("TAKEPOS_SHOW_HT_RECEIPT", array(), $conf->entity, 0, 0, 1, 0);
  149. print "</td></tr>\n";
  150. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector" && filter_var(getDolGlobalString('TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) == true) {
  151. print '<tr class="oddeven"><td>';
  152. print $langs->trans('WeighingScale');
  153. print '<td colspan="2">';
  154. print ajax_constantonoff("TAKEPOS_WEIGHING_SCALE", array(), $conf->entity, 0, 0, 1, 0);
  155. print "</td></tr>\n";
  156. }
  157. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector" && filter_var(getDolGlobalString('TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) == true) {
  158. print '<tr class="oddeven"><td>';
  159. print $langs->trans('CustomerDisplay');
  160. print '<td colspan="2">';
  161. print ajax_constantonoff("TAKEPOS_CUSTOMER_DISPLAY", array(), $conf->entity, 0, 0, 1, 0);
  162. print "</td></tr>\n";
  163. }
  164. // Print without details
  165. print '<tr class="oddeven"><td>';
  166. print $langs->trans('PrintWithoutDetailsButton');
  167. print '<td colspan="2">';
  168. print ajax_constantonoff('TAKEPOS_PRINT_WITHOUT_DETAILS', array(), $conf->entity, 0, 0, 1, 0);
  169. print "</td></tr>\n";
  170. if (getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS')) {
  171. print '<tr class="oddeven"><td>';
  172. print $langs->trans('PrintWithoutDetailsLabelDefault');
  173. print '<td colspan="2">';
  174. print '<input type="text" name="TAKEPOS_PRINT_WITHOUT_DETAILS_LABEL_DEFAULT" value="' . getDolGlobalString('TAKEPOS_PRINT_WITHOUT_DETAILS_LABEL_DEFAULT') . '" />';
  175. print "</td></tr>\n";
  176. }
  177. print '</table>';
  178. print '</div>';
  179. print '<br>';
  180. print $form->buttonsSaveCancel("Save", '');
  181. print "</form>\n";
  182. print load_fiche_titre($langs->trans("Preview"), '', '');
  183. print '<div style="width: 50%; float:center;background-color:#606060">';
  184. print '<center>';
  185. print '<iframe id="iframe" allowtransparency="true" style="background: #FFFFFF;" src="../receipt.php" width="80%" height="600"></iframe>';
  186. print '</center>';
  187. print '</div>';
  188. print '<br>';
  189. llxFooter();
  190. $db->close();