* Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2013-2024 Alexandre Spangaro * Copyright (C) 2014-2015 Ari Elbaz (elarifr) * Copyright (C) 2014 Marcos García * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2017 Laurent Destailleur * Copyright (C) 2021 Ferran Marcet * Copyright (C) 2024 Frédéric France * * 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/accountancy/admin/index.php * \ingroup Accountancy (Double entries) * \brief Setup page to configure accounting expert module */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php'; /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ // Load translation files required by the page $langs->loadLangs(array("compta", "bills", "admin", "accountancy", "other")); // Security access if (!$user->hasRight('accounting', 'chartofaccount')) { accessforbidden(); } $action = GETPOST('action', 'aZ09'); $nbletter = GETPOSTINT('ACCOUNTING_LETTERING_NBLETTERS'); // Parameters ACCOUNTING_* and others $list = array( 'ACCOUNTING_LENGTH_GACCOUNT', 'ACCOUNTING_LENGTH_AACCOUNT', ); $list_binding = array( 'ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER', 'ACCOUNTING_DATE_START_BINDING', 'ACCOUNTING_LABEL_OPERATION_ON_TRANSFER' ); // Parameters for export options $main_option = array( 'ACCOUNTING_EXPORT_PREFIX_SPEC', ); $accountancyexport = new AccountancyExport($db); $configuration = $accountancyexport->getTypeConfig(); $listparam = $configuration['param']; $listformat = $configuration['format']; $listcr = $configuration['cr']; $model_option = array( '1' => array( 'label' => 'ACCOUNTING_EXPORT_FORMAT', 'param' => $listformat, ), '2' => array( 'label' => 'ACCOUNTING_EXPORT_SEPARATORCSV', 'param' => '', ), '3' => array( 'label' => 'ACCOUNTING_EXPORT_ENDLINE', 'param' => $listcr, ), '4' => array( 'label' => 'ACCOUNTING_EXPORT_DATE', 'param' => '', ), ); $error = 0; /* * Actions */ if (in_array($action, array('setBANK_DISABLE_DIRECT_INPUT', 'setACCOUNTANCY_ER_DATE_RECORD', 'setACCOUNTANCY_COMBO_FOR_AUX', 'setACCOUNTING_MANAGE_ZERO', 'setACCOUNTING_BANK_CONCILIATED'))) { $constname = preg_replace('/^set/', '', $action); $constvalue = GETPOSTINT('value'); $res = dolibarr_set_const($db, $constname, $constvalue, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } if ($action == 'update') { $error = 0; if (!$error) { foreach ($list as $constname) { $constvalue = GETPOST($constname, 'alpha'); if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { $error++; } } if ($error) { setEventMessages($langs->trans("Error"), null, 'errors'); } // option in section binding foreach ($list_binding as $constname) { $constvalue = GETPOST($constname, 'alpha'); if ($constname == 'ACCOUNTING_DATE_START_BINDING') { $constvalue = dol_mktime(0, 0, 0, GETPOSTINT($constname.'month'), GETPOSTINT($constname.'day'), GETPOSTINT($constname.'year')); } if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { $error++; } } // options in section other if (GETPOSTISSET('ACCOUNTING_LETTERING_NBLETTERS')) { if (!dolibarr_set_const($db, 'ACCOUNTING_LETTERING_NBLETTERS', GETPOST('ACCOUNTING_LETTERING_NBLETTERS'), 'chaine', 0, '', $conf->entity)) { $error++; } } // Export options $modelcsv = GETPOSTINT('ACCOUNTING_EXPORT_MODELCSV'); if (!empty($modelcsv)) { if (!dolibarr_set_const($db, 'ACCOUNTING_EXPORT_MODELCSV', $modelcsv, 'chaine', 0, '', $conf->entity)) { $error++; } //if ($modelcsv==AccountancyExport::$EXPORT_TYPE_QUADRATUS || $modelcsv==AccountancyExport::$EXPORT_TYPE_CIEL) { // dolibarr_set_const($db, 'ACCOUNTING_EXPORT_FORMAT', 'txt', 'chaine', 0, '', $conf->entity); //} } else { $error++; } foreach ($main_option as $constname) { $constvalue = GETPOST($constname, 'alpha'); if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { $error++; } } foreach ($listparam[$modelcsv] as $key => $value) { $constante = $key; if (strpos($constante, 'ACCOUNTING') !== false) { $constvalue = GETPOST($key, 'alpha'); if (!dolibarr_set_const($db, $constante, $constvalue, 'chaine', 0, '', $conf->entity)) { $error++; } } } if (!$error) { // reload $configuration = $accountancyexport->getTypeConfig(); $listparam = $configuration['param']; } } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'errors'); } } if ($action == 'setmanagezero') { $setmanagezero = GETPOSTINT('value'); $res = dolibarr_set_const($db, "ACCOUNTING_MANAGE_ZERO", $setmanagezero, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } if ($action == 'setenabledraftexport') { $setenabledraftexport = GETPOSTINT('value'); $res = dolibarr_set_const($db, "ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL", $setenabledraftexport, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } if ($action == 'setenablesubsidiarylist') { $setenablesubsidiarylist = GETPOSTINT('value'); $res = dolibarr_set_const($db, "ACCOUNTANCY_COMBO_FOR_AUX", $setenablesubsidiarylist, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } if ($action == 'setdisablebindingonsales') { $setdisablebindingonsales = GETPOSTINT('value'); $res = dolibarr_set_const($db, "ACCOUNTING_DISABLE_BINDING_ON_SALES", $setdisablebindingonsales, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } if ($action == 'setdisablebindingonpurchases') { $setdisablebindingonpurchases = GETPOSTINT('value'); $res = dolibarr_set_const($db, "ACCOUNTING_DISABLE_BINDING_ON_PURCHASES", $setdisablebindingonpurchases, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } if ($action == 'setdisablebindingonexpensereports') { $setdisablebindingonexpensereports = GETPOSTINT('value'); $res = dolibarr_set_const($db, "ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS", $setdisablebindingonexpensereports, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } if ($action == 'setenablelettering') { $setenablelettering = GETPOSTINT('value'); $res = dolibarr_set_const($db, "ACCOUNTING_ENABLE_LETTERING", $setenablelettering, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } if ($action == 'setenableautolettering') { $setenableautolettering = GETPOSTINT('value'); $res = dolibarr_set_const($db, "ACCOUNTING_ENABLE_AUTOLETTERING", $setenableautolettering, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } if ($action == 'setenablevatreversecharge') { $setenablevatreversecharge = GETPOSTINT('value'); $res = dolibarr_set_const($db, "ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE", $setenablevatreversecharge, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } if ($action == 'setenabletabonthirdparty') { $setenabletabonthirdparty = GETPOSTINT('value'); $res = dolibarr_set_const($db, "ACCOUNTING_ENABLE_TABONTHIRDPARTY", $setenabletabonthirdparty, 'yesno', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'mesgs'); } } /* * View */ $form = new Form($db); $title = $langs->trans('ConfigAccountingExpert'); $help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration'; llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_index'); $linkback = ''; //$linkback = '' . $langs->trans("BackToModuleList") . ''; print load_fiche_titre($title, $linkback, 'accountancy'); // Show message if accountancy hidden options are activated to help to resolve some problems if (!$user->admin) { if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { print '
' . $langs->trans("ConstantIsOn", "FACTURE_DEPOSITS_ARE_JUST_PAYMENTS") . '
'; } if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { print '
' . $langs->trans("ConstantIsOn", "FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS") . '
'; } if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) { print '
' . $langs->trans("ConstantIsOn", "ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY") . '
'; } if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { print '
' . $langs->trans("ConstantIsOn", "MAIN_COMPANY_PERENTITY_SHARED") . '
'; } if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { print '
' . $langs->trans("ConstantIsOn", "MAIN_PRODUCT_PERENTITY_SHARED") . '
'; } } print '
'; print ''; print ''; print ''; // Params print '
'; print ''; print ''; print ''; print "\n"; // TO DO Mutualize code for yes/no constants /* Set this option as a hidden option but keep it for some needs. print ''; print ''; if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL')) { print ''; } else { print ''; } print ''; */ print ''; print ''; if (getDolGlobalString('BANK_DISABLE_DIRECT_INPUT')) { print ''; } else { print ''; } print ''; print ''; print ''; if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) { print ''; } else { print ''; } print ''; print ''; print ''; if (getDolGlobalInt('ACCOUNTING_MANAGE_ZERO')) { print ''; } else { print ''; } print ''; // Param a user $user->hasRight('accounting', 'chartofaccount') can access foreach ($list as $key) { print ''; if (getDolGlobalInt('ACCOUNTING_MANAGE_ZERO') && ($key == 'ACCOUNTING_LENGTH_GACCOUNT' || $key == 'ACCOUNTING_LENGTH_AACCOUNT')) { continue; } // Param $label = $langs->trans($key); print ''; // Value print ''; print ''; } print '
'.$langs->trans('Options').'
'.$langs->trans("ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL").''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'.$langs->trans("BANK_DISABLE_DIRECT_INPUT").''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'.$langs->trans("ACCOUNTANCY_COMBO_FOR_AUX"); print ' - '.$langs->trans("NotRecommended").''; print ''; print img_picto($langs->trans("Activated").' - '.$langs->trans("NotRecommended"), 'switch_on', 'class="warning"'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'.$langs->trans("ACCOUNTING_MANAGE_ZERO").''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'.$label.''; print ''; print '
'; print '
'; print '
'; print '

'; // Binding params print '
'; print ''; print ''; print ''; print "\n"; // Param a user $user->hasRight('accounting', 'chartofaccount') can access foreach ($list_binding as $key) { print ''; // Param $label = $langs->trans($key); print ''; // Value print ''; print ''; } print ''; print ''; if (getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_SALES')) { print ''; } else { print ''; } print ''; print ''; print ''; if (getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_PURCHASES')) { print ''; } else { print ''; } print ''; print ''; print ''; if (getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS')) { print ''; } else { print ''; } print ''; if (!getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS')) { print ''; print ''; if (getDolGlobalInt('ACCOUNTANCY_ER_DATE_RECORD')) { print ''; } else { print ''; } print ''; } print ''; print ''; if (getDolGlobalInt('ACCOUNTING_BANK_CONCILIATED') == 2) { print ''; } else { print ''; } print ''; print '
'.$langs->trans('BindingOptions').'
'.$label.''; if ($key == 'ACCOUNTING_DATE_START_BINDING') { print $form->selectDate((getDolGlobalInt($key) ? (int) getDolGlobalInt($key) : -1), $key, 0, 0, 1); } elseif ($key == 'ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER') { $array = array(0=>$langs->trans("PreviousMonth"), 1=>$langs->trans("CurrentMonth"), 2=>$langs->trans("Fiscalyear")); print $form->selectarray($key, $array, getDolGlobalInt('ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER', 0), 0, 0, 0, '', 0, 0, 0, '', 'onrightofpage width200'); } elseif ($key == 'ACCOUNTING_LABEL_OPERATION_ON_TRANSFER') { $array = array( 0=>$langs->trans("ThirdPartyName") . ' - ' . $langs->trans("NumPiece") . ' - ' . $langs->trans("LabelAccount"), 1=>$langs->trans("ThirdPartyName") . ' - ' . $langs->trans("NumPiece"), 2=>$langs->trans("ThirdPartyName") ); print $form->selectarray($key, $array, getDolGlobalInt('ACCOUNTING_LABEL_OPERATION_ON_TRANSFER', 0), 0, 0, 0, '', 0, 0, 0, '', 'onrightofpage width200'); } else { print ''; } print '
'.$langs->trans("ACCOUNTING_DISABLE_BINDING_ON_SALES").''; print img_picto($langs->trans("Activated"), 'switch_on', '', 0, 0, 0, '', 'warning'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'.$langs->trans("ACCOUNTING_DISABLE_BINDING_ON_PURCHASES").''; print img_picto($langs->trans("Activated"), 'switch_on', '', 0, 0, 0, '', 'warning'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'.$langs->trans("ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS").''; print img_picto($langs->trans("Activated"), 'switch_on', '', 0, 0, 0, '', 'warning'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'.$langs->trans("ACCOUNTANCY_ER_DATE_RECORD").''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'.$langs->trans("ACCOUNTING_BANK_CONCILIATED").''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'; print '
'; print '
'; // Show advanced options print '

'; // Advanced params print '
'; print ''; print ''; print ''; print "\n"; print ''; print ''; if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) { print ''; } else { print ''; } print ''; if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) { // Number of letters for lettering (3 by default (AAA), min 2 (AA)) print ''; print ''; print ''; // Auto Lettering when transfer in accountancy is realized print ''; print ''; if (getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) { print ''; } else { print ''; } print ''; } print ''; print ''; if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) { print ''; } else { print ''; } print ''; print ''; print ''; if (getDolGlobalString('ACCOUNTING_ENABLE_TABONTHIRDPARTY')) { print ''; } else { print ''; } print ''; print '
' . $langs->trans('OptionsAdvanced') . '
'; print $form->textwithpicto($langs->trans("ACCOUNTING_ENABLE_LETTERING"), $langs->trans("ACCOUNTING_ENABLE_LETTERING_DESC", $langs->transnoentitiesnoconv("NumMvts")).'
'.$langs->trans("EnablingThisFeatureIsNotNecessary")).'
'; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'; print $form->textwithpicto($langs->trans("ACCOUNTING_LETTERING_NBLETTERS"), $langs->trans("ACCOUNTING_LETTERING_NBLETTERS_DESC")) . ''; if (empty($letter)) { if (getDolGlobalInt('ACCOUNTING_LETTERING_NBLETTERS')) { $nbletter = getDolGlobalInt('ACCOUNTING_LETTERING_NBLETTERS'); } else { $nbletter = 3; } } print '' . "\n"; print '
'; print $form->textwithpicto($langs->trans("ACCOUNTING_ENABLE_AUTOLETTERING"), $langs->trans("ACCOUNTING_ENABLE_AUTOLETTERING_DESC")) . ''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'; print $form->textwithpicto($langs->trans("ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE"), $langs->trans("ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE_DESC", $langs->transnoentities("MenuDefaultAccounts"))).''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'; print $form->textwithpicto($langs->trans("ACCOUNTING_ENABLE_TABONTHIRDPARTY"), $langs->trans("ACCOUNTING_ENABLE_TABONTHIRDPARTY_DESC")).''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print '
'; print '
'; print '
'; print '

'; // Export options print "\n".''."\n"; // Main Options print ''; print ''; print ''; print "\n"; $num = count($main_option); if ($num) { foreach ($main_option as $key) { print ''; // Param $label = $langs->trans($key); print ''; // Value print ''; } } print ''; print ''; if (!$conf->use_javascript_ajax) { print '"; } else { print ''; } print ""; $num2 = count($model_option); if ($num2) { foreach ($model_option as $key) { print ''; // Param $label = $key['label']; print ''; // Value print ''; } print "
'.$langs->trans('ExportOptions').'
'.dol_escape_htmltag($label).''; print ''; print '
'.$langs->trans("Selectmodelcsv").''; print $langs->trans("NotAvailableWhenAjaxDisabled"); print "'; $listofexporttemplates = $accountancyexport->getType(1); print $form->selectarray("ACCOUNTING_EXPORT_MODELCSV", $listofexporttemplates, getDolGlobalString('ACCOUNTING_EXPORT_MODELCSV'), 0, 0, 0, '', 0, 0, 0, '', '', 1); print '
'.$langs->trans($label).''; if (is_array($key['param'])) { print $form->selectarray($label, $key['param'], getDolGlobalString($label), 0); } else { print ''; } print '
\n"; } print '
'; print '
'; // End of page llxFooter(); $db->close();