dolibarr/htdocs/accountancy/admin/defaultaccounts.php
Laurent Destailleur c689248211 The setup that must be done by the bookkeeper is removed from admin
setup and move into setup of accountancy
2016-10-15 14:38:43 +02:00

352 lines
11 KiB
PHP

<?php
/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2014-2015 Ari Elbaz (elarifr) <github@accedinfo.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
/**
* \file htdocs/accountancy/admin/index.php
* \ingroup Advanced accountancy
* \brief Setup page to configure accounting expert module
*/
require '../../main.inc.php';
// Class
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 . '/accountancy/class/html.formventilation.class.php';
$langs->load("compta");
$langs->load("bills");
$langs->load("admin");
$langs->load("accountancy");
$langs->load("salaries");
// Security check
if (! empty($user->rights->accountancy->chartofaccount))
{
accessforbidden();
}
$action = GETPOST('action', 'alpha');
// Parameters ACCOUNTING_* and others
$list = array (
//'ACCOUNTING_LIMIT_LIST_VENTILATION', Useless, we can change value dynamically, so we use default global setup
'ACCOUNTING_MANAGE_ZERO',
'ACCOUNTING_LENGTH_GACCOUNT',
'ACCOUNTING_LENGTH_AACCOUNT' ,
'ACCOUNTING_LENGTH_DESCRIPTION', // adjust size displayed for lines description for dol_trunc
'ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT', // adjust size displayed for select account description for dol_trunc
);
$list_account = array (
'ACCOUNTING_ACCOUNT_SUPPLIER',
'ACCOUNTING_ACCOUNT_CUSTOMER',
'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
'ACCOUNTING_PRODUCT_BUY_ACCOUNT',
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT',
'ACCOUNTING_SERVICE_BUY_ACCOUNT',
'ACCOUNTING_SERVICE_SOLD_ACCOUNT',
'ACCOUNTING_VAT_BUY_ACCOUNT',
'ACCOUNTING_VAT_SOLD_ACCOUNT',
'ACCOUNTING_VAT_PAY_ACCOUNT',
'ACCOUNTING_ACCOUNT_SUSPENSE',
'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
'DONATION_ACCOUNTINGACCOUNT'
);
/*
* Actions
*/
$accounting_mode = defined('ACCOUNTING_MODE') ? ACCOUNTING_MODE : 'RECETTES-DEPENSES';
if (GETPOST('change_chart'))
{
$chartofaccounts = GETPOST('chartofaccounts', 'int');
if (! empty($chartofaccounts)) {
if (! dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
$error ++;
}
} else {
$error ++;
}
}
if ($action == 'update') {
$error = 0;
$chartofaccounts = GETPOST('chartofaccounts', 'int');
if (! empty($chartofaccounts)) {
if (! dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
$error ++;
}
} else {
$error ++;
}
foreach ( $list as $constname ) {
$constvalue = GETPOST($constname, 'alpha');
if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
$error ++;
}
}
foreach ( $list_account as $constname ) {
$constvalue = GETPOST($constname, 'alpha');
if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
$error ++;
}
}
if (! $error) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
setEventMessages($langs->trans("Error"), null, 'errors');
}
}
// TO DO Mutualize code for yes/no constants
if ($action == 'setlistsorttodo') {
$setlistsorttodo = GETPOST('value', 'int');
$res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_TODO", $setlistsorttodo, '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 == 'setlistsortdone') {
$setlistsortdone = GETPOST('value', 'int');
$res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_DONE", $setlistsortdone, '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 == 'setmanagezero') {
$setmanagezero = GETPOST('value', 'int');
$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 == 'setdisabledirectinput') {
$setdisabledirectinput = GETPOST('value', 'int');
$res = dolibarr_set_const($db, "BANK_DISABLE_DIRECT_INPUT", $setdisabledirectinput, 'yesno', 0, '', $conf->entity);
if (! $res > 0)
$error ++;
if (! $error) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
setEventMessages($langs->trans("Error"), null, 'mesgs');
}
}
/*
* View
*/
llxHeader();
$form = new Form($db);
$formaccountancy = new FormVentilation($db);
$linkback = '';
print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="update">';
// Box to select active chart of accoun
$var = ! $var;
print $langs->trans("Selectchartofaccounts") . " : ";
print '<select class="flat" name="chartofaccounts" id="chartofaccounts">';
$sql = "SELECT rowid, pcg_version, label, active";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_system";
$sql .= " WHERE active = 1";
dol_syslog('accountancy/admin/index.php:: $sql=' . $sql);
$resql = $db->query($sql);
$var = true;
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ( $i < $num ) {
$var = ! $var;
$row = $db->fetch_row($resql);
print '<option value="' . $row[0] . '"';
print $pcgver == $row[0] ? ' selected' : '';
print '>' . $row[1] . ' - ' . $row[2] . '</option>';
$i ++;
}
}
print "</select>";
print '<input type="submit" class="button" name="change_chart" value="'.dol_escape_htmltag($langs->trans("ChangeAndLoad")).'">';
print '<br>';
print "<br>\n";
/*
* Define Chart of accounts
*/
// Others params
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="2">' . $langs->trans('OtherOptions') . '</td>';
print "</tr>\n";
if (! empty($user->admin))
{
// TO DO Mutualize code for yes/no constants
$var = ! $var;
print "<tr " . $bc[$var] . ">";
print '<td>' . $langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_TODO") . '</td>';
if (! empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO)) {
print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsorttodo&value=0">';
print img_picto($langs->trans("Activated"), 'switch_on');
print '</a></td>';
} else {
print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsorttodo&value=1">';
print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a></td>';
}
print '</tr>';
$var = ! $var;
print "<tr " . $bc[$var] . ">";
print '<td>' . $langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_DONE") . '</td>';
if (! empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE)) {
print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsortdone&value=0">';
print img_picto($langs->trans("Activated"), 'switch_on');
print '</a></td>';
} else {
print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsortdone&value=1">';
print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a></td>';
}
print '</tr>';
$var = ! $var;
print "<tr " . $bc[$var] . ">";
print '<td>' . $langs->trans("BANK_DISABLE_DIRECT_INPUT") . '</td>';
if (! empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) {
print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setdisabledirectinput&value=0">';
print img_picto($langs->trans("Activated"), 'switch_on');
print '</a></td>';
} else {
print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setdisabledirectinput&value=1">';
print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a></td>';
}
print '</tr>';
}
// Param a user $user->rights->accountancy->chartofaccount can access
if (! empty($user->admin) || ! empty($user->rights->accountancy->chartofaccount))
{
foreach ( $list as $key ) {
$var = ! $var;
if ($key != 'ACCOUNTING_MANAGE_ZERO')
{
print '<tr ' . $bc[$var] . ' class="value">';
// Param
$label = $langs->trans($key);
print '<td>'.$label.'</td>';
// Value
print '<td align="right">';
print '<input type="text" size="20" id="' . $key . '" name="' . $key . '" value="' . $conf->global->$key . '">';
print '</td>';
print '</tr>';
}
if ($key == 'ACCOUNTING_MANAGE_ZERO')
{
$var = ! $var;
print "<tr " . $bc[$var] . ">";
print '<td>' . $langs->trans("ACCOUNTING_MANAGE_ZERO") . '</td>';
if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) {
print '<td align="right""><a href="' . $_SERVER['PHP_SELF'] . '?action=setmanagezero&value=0">';
print img_picto($langs->trans("Activated"), 'switch_on');
print '</a></td>';
} else {
print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setmanagezero&value=1">';
print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a></td>';
}
print '</tr>';
}
}
foreach ( $list_account as $key ) {
$var = ! $var;
print '<tr ' . $bc[$var] . ' class="value">';
// Param
$label = $langs->trans($key);
print '<td>' . $label . '</td>';
// Value
print '<td align="right">';
print $formaccountancy->select_account($conf->global->$key, $key, 1, '', 1, 1);
print '</td>';
print '</tr>';
}
}
print "</table>\n";
print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('Modify') . '" name="button"></div>';
print '</form>';
llxFooter();
$db->close();