1<?php
2/* Copyright (C) 2004      Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin        <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2013 Juanjo Menent	    <jmenent@2byte.es>
6 * Copyright (C) 2013-2017 Philippe Grand	    <philippe.grand@atoo-net.com>
7 * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
8 * Copyright (C) 2020      Maxime DEMAREST      <maxime@indelog.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24/**
25 *	\file       htdocs/admin/compta.php
26 *	\ingroup    compta
27 *	\brief      Page to setup accountancy module
28 */
29
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32
33// Load translation files required by the page
34$langs->loadLangs(array('admin', 'compta', 'accountancy'));
35
36if (!$user->admin)
37accessforbidden();
38
39$action = GETPOST('action', 'aZ09');
40
41// Other parameters ACCOUNTING_*
42$list = array(
43	'ACCOUNTING_PRODUCT_BUY_ACCOUNT',
44	'ACCOUNTING_PRODUCT_SOLD_ACCOUNT',
45	'ACCOUNTING_SERVICE_BUY_ACCOUNT',
46	'ACCOUNTING_SERVICE_SOLD_ACCOUNT',
47	'ACCOUNTING_VAT_SOLD_ACCOUNT',
48	'ACCOUNTING_VAT_BUY_ACCOUNT',
49	'ACCOUNTING_ACCOUNT_CUSTOMER',
50	'ACCOUNTING_ACCOUNT_SUPPLIER'
51);
52
53/*
54 * Actions
55 */
56
57$accounting_mode = empty($conf->global->ACCOUNTING_MODE) ? 'RECETTES-DEPENSES' : $conf->global->ACCOUNTING_MODE;
58
59if ($action == 'update')
60{
61	$error = 0;
62
63	$accounting_modes = array(
64		'RECETTES-DEPENSES',
65		'CREANCES-DETTES'
66	);
67
68	$accounting_mode = GETPOST('accounting_mode', 'alpha');
69
70
71	if (in_array($accounting_mode, $accounting_modes)) {
72		if (!dolibarr_set_const($db, 'ACCOUNTING_MODE', $accounting_mode, 'chaine', 0, '', $conf->entity)) {
73			$error++;
74		}
75	} else {
76		$error++;
77	}
78
79	foreach ($list as $constname) {
80		$constvalue = GETPOST($constname, 'alpha');
81
82		if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
83			$error++;
84		}
85	}
86
87	$report_include_varpay = GETPOST('ACCOUNTING_REPORTS_INCLUDE_VARPAY', 'alpha');
88	if (!empty($report_include_varpay))
89		if ($report_include_varpay == 'yes')
90			if (!dolibarr_set_const($db, 'ACCOUNTING_REPORTS_INCLUDE_VARPAY', 1, 'chaine', 0, '', $conf->entity)) $error++;
91		if ($report_include_varpay == 'no')
92			if (!dolibarr_del_const($db, 'ACCOUNTING_REPORTS_INCLUDE_VARPAY', $conf->entity)) $error++;
93
94	$report_include_loan = GETPOST('ACCOUNTING_REPORTS_INCLUDE_LOAN', 'alpha');
95	if (!empty($report_include_loan))
96		if ($report_include_loan == 'yes')
97			if (!dolibarr_set_const($db, 'ACCOUNTING_REPORTS_INCLUDE_LOAN', 1, 'chaine', 0, '', $conf->entity)) $error++;
98		if ($report_include_loan == 'no')
99			if (!dolibarr_del_const($db, 'ACCOUNTING_REPORTS_INCLUDE_LOAN', $conf->entity)) $error++;
100
101	if (!$error)
102	{
103		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
104	} else {
105		setEventMessages($langs->trans("Error"), null, 'errors');
106	}
107}
108
109/*
110 * View
111 */
112
113llxHeader();
114
115$form = new Form($db);
116
117$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
118print load_fiche_titre($langs->trans('ComptaSetup'), $linkback, 'title_setup');
119
120print '<br>';
121
122print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
123print '<input type="hidden" name="token" value="'.newToken().'">';
124print '<input type="hidden" name="action" value="update">';
125
126print '<table class="noborder centpercent">';
127
128// case of the parameter ACCOUNTING_MODE
129
130print '<tr class="liste_titre">';
131print '<td>'.$langs->trans('OptionMode').'</td><td>'.$langs->trans('Description').'</td>';
132print "</tr>\n";
133print '<tr class="oddeven"><td width="200"><input type="radio" name="accounting_mode" value="RECETTES-DEPENSES"'.($accounting_mode != 'CREANCES-DETTES' ? ' checked' : '').'> '.$langs->trans('OptionModeTrue').'</td>';
134print '<td colspan="2">'.nl2br($langs->trans('OptionModeTrueDesc'));
135// Write info on way to count VAT
136//if (! empty($conf->global->MAIN_MODULE_COMPTABILITE))
137//{
138//	//	print "<br>\n";
139//	//	print nl2br($langs->trans('OptionModeTrueInfoModuleComptabilite'));
140//}
141//else
142//{
143//	//	print "<br>\n";
144//	//	print nl2br($langs->trans('OptionModeTrueInfoExpert'));
145//}
146print "</td></tr>\n";
147print '<tr class="oddeven"><td width="200"><input type="radio" name="accounting_mode" value="CREANCES-DETTES"'.($accounting_mode == 'CREANCES-DETTES' ? ' checked' : '').'> '.$langs->trans('OptionModeVirtual').'</td>';
148print '<td colspan="2">'.nl2br($langs->trans('OptionModeVirtualDesc'))."</td></tr>\n";
149
150print "</table>\n";
151
152print "<br>\n";
153
154print '<table class="noborder centpercent">';
155print '<tr class="liste_titre">';
156print '<td colspan="3">'.$langs->trans('OtherOptions').'</td>';
157print "</tr>\n";
158
159
160foreach ($list as $key)
161{
162	print '<tr class="oddeven value">';
163
164	// Param
165	$libelle = $langs->trans($key);
166	print '<td><label for="'.$key.'">'.$libelle.'</label></td>';
167
168	// Value
169	print '<td>';
170	print '<input type="text" size="20" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
171	print '</td></tr>';
172}
173
174// Option to include various payment in results
175print '<tr class="oddeven value">'."\n";
176print '<td><label for="ACCOUNTING_REPORTS_INCLUDE_VARPAY">'.$langs->trans('IncludeVarpaysInResults').'</label></td>'."\n";
177print '<td class="center">'."\n";
178print $form->selectyesno('ACCOUNTING_REPORTS_INCLUDE_VARPAY', (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY)));
179print '</td></tr>';
180
181// Option to include loan in results
182print '<tr class="oddeven value">'."\n";
183print '<td><label for="ACCOUNTING_REPORTS_INCLUDE_LOAN">'.$langs->trans('IncludeLoansInResults').'</label></td>'."\n";
184print '<td class="center">'."\n";
185print $form->selectyesno('ACCOUNTING_REPORTS_INCLUDE_LOAN', (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN)));
186print '</td></tr>';
187
188print "</table>\n";
189
190print '<br><br><div style="text-align:center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
191print '</form>';
192
193// End of page
194llxFooter();
195$db->close();
196