* Copyright (C) 2011-2017 Juanjo Menent * Copyright (C) 2021 Nicolas ZABOURI * Copyright (C) 2022 Alexandre Spangaro * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/takepos/admin/setup.php * \ingroup takepos * \brief Setup page for TakePos module */ // Load Dolibarr environment require '../../main.inc.php'; // Load $user and permissions require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT."/core/lib/takepos.lib.php"; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; // If socid provided by ajax company selector if (GETPOST('CASHDESK_ID_THIRDPARTY_id', 'alpha')) { $_GET['CASHDESK_ID_THIRDPARTY'] = GETPOST('CASHDESK_ID_THIRDPARTY_id', 'alpha'); $_POST['CASHDESK_ID_THIRDPARTY'] = GETPOST('CASHDESK_ID_THIRDPARTY_id', 'alpha'); $_REQUEST['CASHDESK_ID_THIRDPARTY'] = GETPOST('CASHDESK_ID_THIRDPARTY_id', 'alpha'); } // Security check if (!$user->admin) { accessforbidden(); } $langs->loadLangs(array("admin", "cashdesk")); global $db, $mysoc; $sql = "SELECT code, libelle FROM ".MAIN_DB_PREFIX."c_paiement"; $sql .= " WHERE entity IN (".getEntity('c_paiement').")"; $sql .= " AND active = 1"; $sql .= " ORDER BY libelle"; $resql = $db->query($sql); $paiements = array(); if ($resql) { while ($obj = $db->fetch_object($resql)) { array_push($paiements, $obj); } } $action = GETPOST('action', 'aZ09'); /* * Actions */ $error = 0; if ($action == 'set') { $db->begin(); $res = dolibarr_set_const($db, "TAKEPOS_ROOT_CATEGORY_ID", GETPOST('TAKEPOS_ROOT_CATEGORY_ID', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_SUPPLEMENTS_CATEGORY", GETPOST('TAKEPOS_SUPPLEMENTS_CATEGORY', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_NUMPAD", GETPOST('TAKEPOS_NUMPAD', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_SORTPRODUCTFIELD", GETPOST('TAKEPOS_SORTPRODUCTFIELD', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_NUM_TERMINALS", GETPOST('TAKEPOS_NUM_TERMINALS', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_ADDON", GETPOST('TAKEPOS_ADDON', 'alpha'), 'int', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_EMAIL_TEMPLATE_INVOICE", GETPOST('TAKEPOS_EMAIL_TEMPLATE_INVOICE', 'alpha'), 'chaine', 0, '', $conf->entity); if (getDolGlobalInt('TAKEPOS_ENABLE_SUMUP')) { $res = dolibarr_set_const($db, "TAKEPOS_SUMUP_AFFILIATE", GETPOST('TAKEPOS_SUMUP_AFFILIATE', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_SUMUP_APPID", GETPOST('TAKEPOS_SUMUP_APPID', 'alpha'), 'chaine', 0, '', $conf->entity); } if (isModEnabled('barcode')) { $res = dolibarr_set_const($db, 'TAKEPOS_BARCODE_RULE_TO_INSERT_PRODUCT', GETPOST('TAKEPOS_BARCODE_RULE_TO_INSERT_PRODUCT', 'alpha'), 'chaine', 0, '', $conf->entity); } dol_syslog("admin/cashdesk: level ".GETPOST('level', 'alpha')); if (!($res > 0)) { $error++; } if (!$error) { $db->commit(); } else { $db->rollback(); } } elseif ($action == 'updateMask') { $maskconst = GETPOST('maskconst', 'aZ09'); $maskvalue = GETPOST('maskvalue', 'alpha'); if ($maskconst && preg_match('/_MASK$/', $maskconst)) { $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity); } if (!($res > 0)) { $error++; } } elseif ($action == 'setrefmod') { $value = GETPOST('value', 'alpha'); dolibarr_set_const($db, "TAKEPOS_REF_ADDON", $value, 'chaine', 0, '', $conf->entity); } if ($action != '') { if (!$error) { setEventMessage($langs->trans('SetupSaved')); } else { setEventMessages($langs->trans('Error'), null, 'errors'); } } /* * View */ $form = new Form($db); $formproduct = new FormProduct($db); $help_url = 'EN:Module_Point_of_sale_(TakePOS)'; llxHeader('', $langs->trans("CashDeskSetup"), $help_url, '', 0, 0, '', '', '', 'mod-takepos page-admin_setup'); $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("CashDeskSetup").' (TakePOS)', $linkback, 'title_setup'); $head = takepos_admin_prepare_head(); print dol_get_fiche_head($head, 'setup', 'TakePOS', -1, 'cash-register'); // Numbering modules $now = dol_now(); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); print load_fiche_titre($langs->trans('CashDeskRefNumberingModules'), '', ''); print '
'; // You can use div-table-responsive-no-min if you don't need reserved height for your table print ''; print ''; print '\n"; print '\n"; print '\n"; print ''; print ''; print ''."\n"; clearstatcache(); foreach ($dirmodels as $reldir) { $dir = dol_buildpath($reldir."core/modules/takepos/"); if (is_dir($dir)) { $handle = opendir($dir); if (is_resource($handle)) { $var = true; while (($file = readdir($handle)) !== false) { if (substr($file, 0, 16) == 'mod_takepos_ref_' && substr($file, dol_strlen($file) - 3, 3) == 'php') { $file = substr($file, 0, dol_strlen($file) - 4); require_once $dir.$file.'.php'; $module = new $file(); '@phan-var-force ModeleNumRefTakepos $module'; // Show modules according to features level if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) { continue; } if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) { continue; } if ($module->isEnabled()) { print ''; // Show example of numbering module print ''."\n"; print ''; // example for next value $invoice = new Facture($db); $invoice->date = $now; $invoice->module_source = 'takepos'; $invoice->pos_source = 1; // Info $htmltooltip = ''; $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
'; $nextval = $module->getNextValue($mysoc, $invoice); if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval $htmltooltip .= ''.$langs->trans("NextValue").': '; if ($nextval) { if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') { $nextval = $langs->trans($nextval); } $htmltooltip .= $nextval.'
'; } else { $htmltooltip .= $langs->trans($module->error).'
'; } } print ''; print "\n"; } } } closedir($handle); } } } print "
'.$langs->trans("Name")."'.$langs->trans("Description")."'.$langs->trans("Example")."'.$langs->trans("Status").''.$langs->trans("ShortInfo").'
'.$module->getName($langs)."\n"; print $module->info($langs); print ''; $tmp = $module->getExample(); if (preg_match('/^Error/', $tmp)) { $langs->load("errors"); print '
'.$langs->trans($tmp).'
'; } elseif ($tmp == 'NotConfigured') { print $langs->trans($tmp); } else { print $tmp; } print '
'; if (getDolGlobalString('TAKEPOS_REF_ADDON') == "$file") { print img_picto($langs->trans("Activated"), 'switch_on'); } else { print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; } print ''; print $form->textwithpicto('', $htmltooltip, 1, 0); print '
\n"; print '
'; print "\n"; print '
'; print load_fiche_titre($langs->trans('Options'), '', ''); // Mode print '
'; print ''; print ''; print '
'; print ''; print ''; print ''; print "\n"; // Terminals print '\n"; // Services if (isModEnabled("service")) { print '\n"; } // Root category for products print '\n"; // Sort product print '\n"; print '\n"; $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2); $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation"); $htmltext = ''.$langs->trans("AvailableVariables").':
'; foreach ($substitutionarray as $key => $val) { $htmltext .= $key.'
'; } $htmltext .= '
'; // Payment numpad print '\n"; // Numpad use payment icons /*print '\n"; */ // Direct Payment print '\n"; // Head Bar /*print '\n"; */ // Email template for send invoice print '\n"; // Control cash box at opening pos print '\n"; // Gift receipt print '\n"; // Delayed Pay Button print '\n"; // Show price without vat print '\n"; // Use price excl. taxes (HT) and not price incl. taxes (TTC) print '\n"; // Barcode rule to insert product if (isModEnabled('barcode')) { print '\n"; } // Numbering module //print '\n"; print '
'.$langs->trans("Parameters").'
'; print $langs->trans("NumberOfTerminals"); print ''; print ''; print "
'; print $langs->trans("CashdeskShowServices"); print ''; print ajax_constantonoff("CASHDESK_SERVICES", array(), $conf->entity, 0, 0, 1, 0); //print $form->selectyesno("CASHDESK_SERVICES", $conf->global->CASHDESK_SERVICES, 1); print "
'; print $form->textwithpicto($langs->trans("RootCategoryForProductsToSell"), $langs->trans("RootCategoryForProductsToSellDesc")); print ''; print img_object('', 'category', 'class="paddingright"').$form->select_all_categories(Categorie::TYPE_PRODUCT, getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID'), 'TAKEPOS_ROOT_CATEGORY_ID', 64, 0, 0, 0, 'maxwidth500 widthcentpercentminusx'); print ajax_combobox('TAKEPOS_ROOT_CATEGORY_ID'); print "
'; print $langs->trans("SortProductField"); print ''; $prod = new Product($db); $array = array('rowid' => 'ID', 'ref' => 'Ref', 'label' => 'Label', 'datec' => 'DateCreation', 'tms' => 'DateModification'); print $form->selectarray('TAKEPOS_SORTPRODUCTFIELD', $array, getDolGlobalString('TAKEPOS_SORTPRODUCTFIELD', 'rowid'), 0, 0, 0, '', 1); print "
'; print $langs->trans('TakeposGroupSameProduct'); print ''; print ajax_constantonoff("TAKEPOS_GROUP_SAME_PRODUCT", array(), $conf->entity, 0, 0, 1, 0); print "
'; print $langs->trans("Paymentnumpad"); print ''; $array = array(0 => $langs->trans("Numberspad"), 1 => $langs->trans("BillsCoinsPad")); print $form->selectarray('TAKEPOS_NUMPAD', $array, (!getDolGlobalString('TAKEPOS_NUMPAD') ? '0' : $conf->global->TAKEPOS_NUMPAD), 0); print "
'; print $langs->trans('TakeposNumpadUsePaymentIcon'); print ''; print ajax_constantonoff("TAKEPOS_NUMPAD_USE_PAYMENT_ICON", array(), $conf->entity, 0, 0, 1, 0); print "
'; print $langs->trans('DirectPaymentButton'); print ''; print ajax_constantonoff("TAKEPOS_DIRECT_PAYMENT", array(), $conf->entity, 0, 0, 1, 0); //print $form->selectyesno("TAKEPOS_DIRECT_PAYMENT", $conf->global->TAKEPOS_DIRECT_PAYMENT, 1); print "
'; print $langs->trans('HeadBar'); print ''; print $form->selectyesno("TAKEPOS_HEAD_BAR", $conf->global->TAKEPOS_HEAD_BAR, 1); print "
'; print $langs->trans('EmailTemplate'); print ''; include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); $nboftemplates = $formmail->fetchAllEMailTemplate('facture_send', $user, null, -1); // We set lang=null to get in priority record with no lang //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, ''); $arrayofmessagename = array(); if (is_array($formmail->lines_model)) { foreach ($formmail->lines_model as $modelmail) { //var_dump($modelmail); $moreonlabel = ''; if (!empty($arrayofmessagename[$modelmail->label])) { $moreonlabel = ' ('.$langs->trans("SeveralLangugeVariatFound").')'; } $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->topic)).$moreonlabel; } } //var_dump($arraydefaultmessage); //var_dump($arrayofmessagename); print $form->selectarray('TAKEPOS_EMAIL_TEMPLATE_INVOICE', $arrayofmessagename, getDolGlobalString('TAKEPOS_EMAIL_TEMPLATE_INVOICE'), 'None', 1, 0, '', 0, 0, 0, '', 'maxwidth500 widthcentpercentminusx', 1); print "
'; print $langs->trans('ControlCashOpening'); print ''; print ajax_constantonoff("TAKEPOS_CONTROL_CASH_OPENING", array(), $conf->entity, 0, 0, 1, 0); print "
'; print $langs->trans('GiftReceiptButton'); print ''; print ajax_constantonoff("TAKEPOS_GIFT_RECEIPT", array(), $conf->entity, 0, 0, 1, 0); print "
'; print $langs->trans('AllowDelayedPayment'); print ''; print ajax_constantonoff("TAKEPOS_DELAYED_PAYMENT", array(), $conf->entity, 0, 0, 1, 0); print "
'; print $langs->trans('ShowPriceHT'); print ''; print ajax_constantonoff("TAKEPOS_SHOW_HT", array(), $conf->entity, 0, 0, 1, 0); print "
'; print $langs->trans('UsePriceHT'); print ''; print ajax_constantonoff("TAKEPOS_CHANGE_PRICE_HT", array(), $conf->entity, 0, 0, 1, 0); print "
'; print $form->textwithpicto($langs->trans("TakeposBarcodeRuleToInsertProduct"), $langs->trans("TakeposBarcodeRuleToInsertProductDesc"), 1, 'help', '', 0, 3, 'barcoderuleonsmartphone'); print ''; print ''; print "
'; //print $langs->trans("BillsNumberingModule"); //print ''; //$array = array(0=>$langs->trans("Default"), "terminal"=>$langs->trans("ByTerminal")); //$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); //foreach ($dirmodels as $reldir) //{ // $dir = dol_buildpath($reldir."core/modules/facture/"); // if (is_dir($dir)) // { // $handle = opendir($dir); // if (is_resource($handle)) // { // while (($file = readdir($handle)) !== false) // { // if (!is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) // { // $filebis = $file; // $classname = preg_replace('/\.php$/', '', $file); // // For compatibility // if (!is_file($dir.$filebis)) // { // $filebis = $file."/".$file.".modules.php"; // $classname = "mod_facture_".$file; // } // // Check if there is a filter on country // preg_match('/\-(.*)_(.*)$/', $classname, $reg); // if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) continue; // // $classname = preg_replace('/\-.*$/', '', $classname); // if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') // { // // Charging the numbering class // require_once $dir.$filebis; // // $module = new $classname($db); // // // Show modules according to features level // if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; // if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; // // if ($module->isEnabled()) // { // $array[preg_replace('/\-.*$/', '', preg_replace('/\.php$/', '', $file))] = preg_replace('/\-.*$/', '', preg_replace('/mod_facture_/', '', preg_replace('/\.php$/', '', $file))); // } // } // } // } // closedir($handle); // } // } //} // //print $form->selectarray('TAKEPOS_ADDON', $array, (empty($conf->global->TAKEPOS_ADDON) ? '0' : $conf->global->TAKEPOS_ADDON), 0); //print "
'; print '
'; // Sumup options if (getDolGlobalInt('TAKEPOS_ENABLE_SUMUP')) { print '
'; print '
'; print ''; print ''; print ''; print "\n"; print '\n"; print '\n"; print '
'.$langs->trans("Sumup").'
'; print $langs->trans("SumupAffiliate"); print ''; print ''; print "
'; print $langs->trans("SumupAppId"); print ''; print ''; print "
'; print '
'; } print $form->buttonsSaveCancel("Save", ''); print "
\n"; llxFooter(); $db->close();