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) 2015-2018 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/**
23 *     \file       htdocs/admin/taxes.php
24 *     \ingroup    tax
25 *     \brief      Page de configuration du module tax
26 */
27
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
31
32// Load translation files required by the page
33$langs->loadLangs(array('admin', 'objects', 'companies', 'products'));
34
35if (!$user->admin) accessforbidden();
36
37$action = GETPOST('action', 'aZ09');
38
39
40
41/*
42 * Actions
43 */
44
45// 0=normal, 1=option vat for services is on debit
46
47// TAX_MODE=0 (most cases):
48//              Buy                     Sell
49// Product      On delivery             On delivery
50// Service      On payment              On payment
51
52// TAX_MODE=1 (option):
53//              Buy                     Sell
54// Product      On delivery             On delivery
55// Service      On invoice              On invoice
56
57$tax_mode = empty($conf->global->TAX_MODE) ? 0 : $conf->global->TAX_MODE;
58
59if ($action == 'update') {
60	$error = 0;
61
62	// Tax mode
63	$tax_mode = GETPOST('tax_mode', 'alpha');
64
65	$db->begin();
66
67	$res = dolibarr_set_const($db, 'TAX_MODE', $tax_mode, 'chaine', 0, '', $conf->entity);
68	if (!($res > 0)) $error++;
69
70	switch ($tax_mode)
71	{
72		case 0:
73			$valuesellproduct = 'invoice';
74			$valuebuyproduct = 'invoice';
75			$valuesellservice = 'payment';
76			$valuebuyservice = 'payment';
77			break;
78		case 1:
79			$valuesellproduct = 'invoice';
80			$valuebuyproduct = 'invoice';
81			$valuesellservice = 'invoice';
82			$valuebuyservice = 'invoice';
83			break;
84		case 2:
85			$valuesellproduct = 'payment';
86			$valuebuyproduct = 'payment';
87			$valuesellservice = 'payment';
88			$valuebuyservice = 'payment';
89			break;
90	}
91
92	$res = dolibarr_set_const($db, 'TAX_MODE_SELL_PRODUCT', $valuesellproduct, 'chaine', 0, '', $conf->entity);
93	if (!($res > 0)) $error++;
94	$res = dolibarr_set_const($db, 'TAX_MODE_BUY_PRODUCT', $valuebuyproduct, 'chaine', 0, '', $conf->entity);
95	if (!($res > 0)) $error++;
96	$res = dolibarr_set_const($db, 'TAX_MODE_SELL_SERVICE', $valuesellservice, 'chaine', 0, '', $conf->entity);
97	if (!($res > 0)) $error++;
98	$res = dolibarr_set_const($db, 'TAX_MODE_BUY_SERVICE', $valuebuyservice, 'chaine', 0, '', $conf->entity);
99	if (!($res > 0)) $error++;
100
101	dolibarr_set_const($db, "MAIN_INFO_TVAINTRA", GETPOST("tva", 'alpha'), 'chaine', 0, '', $conf->entity);
102
103	dolibarr_set_const($db, "MAIN_INFO_VAT_RETURN", GETPOST("MAIN_INFO_VAT_RETURN", 'alpha'), 'chaine', 0, '', $conf->entity);
104
105	if (!$error) {
106		$db->commit();
107		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
108	} else {
109		$db->rollback();
110		setEventMessages($langs->trans("Error"), null, 'errors');
111	}
112}
113
114
115
116/*
117 * View
118 */
119
120llxHeader('', $langs->trans("TaxSetup"));
121
122$form = new Form($db);
123if (!empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
124
125$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
126print load_fiche_titre($langs->trans('TaxSetup'), $linkback, 'title_setup');
127
128//print dol_get_fiche_head(null, '', '', -1);
129
130if (empty($mysoc->tva_assuj))
131{
132	print $langs->trans("YourCompanyDoesNotUseVAT").'<br>';
133} else {
134	print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
135	print '<input type="hidden" name="token" value="'.newToken().'">';
136	print '<input type="hidden" name="action" value="update">';
137
138	print '<table class="noborder centpercent">';
139	print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("CompanyIds").'</td><td>'.$langs->trans("Value").'</td></tr>';
140
141	print '<tr class="oddeven"><td><label for="intra_vat">'.$langs->trans("VATIntra").'</label></td><td>';
142	print '<input name="tva" id="intra_vat" class="minwidth200" value="'.(!empty($conf->global->MAIN_INFO_TVAINTRA) ? $conf->global->MAIN_INFO_TVAINTRA : '').'">';
143	print '</td></tr>';
144
145	print '<tr class="oddeven"><td><label for="activate_MAIN_INFO_VAT_RETURN">'.$langs->trans("VATReturn").'</label></td>';
146	if (!$conf->use_javascript_ajax)
147	{
148		print '<td class="nowrap right">';
149		print $langs->trans("NotAvailableWhenAjaxDisabled");
150		print "</td>";
151	} else {
152		print '<td width="120">';
153		$listval = array(
154			'0'=>$langs->trans(""),
155			'1'=>$langs->trans("Monthly"),
156			'2'=>$langs->trans("Quarterly"),
157			'3'=>$langs->trans("Annual"),
158		);
159		print $form->selectarray("MAIN_INFO_VAT_RETURN", $listval, $conf->global->MAIN_INFO_VAT_RETURN);
160		print "</td>";
161	}
162	print '</tr>';
163
164	print '</table>';
165
166	print '<br>';
167
168	print '<table class="noborder centpercent">';
169
170	// Cas des parametres TAX_MODE_SELL/BUY_SERVICE/PRODUCT
171	print '<tr class="liste_titre">';
172	print '<td class="titlefield">'.$langs->trans('OptionVatMode').'</td><td>'.$langs->trans('Description').'</td>';
173	print "</tr>\n";
174	// Standard
175	print '<tr class="oddeven"><td><input type="radio" name="tax_mode" value="0"'.(empty($tax_mode) ? ' checked' : '').'> '.$langs->trans('OptionVATDefault').'</td>';
176	print '<td>'.nl2br($langs->trans('OptionVatDefaultDesc'));
177	print "</td></tr>\n";
178	// On debit for services
179	print '<tr class="oddeven"><td><input type="radio" name="tax_mode" value="1"'.($tax_mode == 1 ? ' checked' : '').'> '.$langs->trans('OptionVATDebitOption').'</td>';
180	print '<td>'.nl2br($langs->trans('OptionVatDebitOptionDesc'))."</td></tr>\n";
181	// On payment for both products and services
182	if ($conf->global->MAIN_FEATURES_LEVEL >= 1)
183	{
184		print '<tr class="oddeven"><td><input type="radio" name="tax_mode" value="2"'.($tax_mode == 2 ? ' checked' : '').'> '.$langs->trans('OptionPaymentForProductAndServices').'</td>';
185		print '<td>'.nl2br($langs->trans('OptionPaymentForProductAndServicesDesc'))."</td></tr>\n";
186	}
187	print "</table>\n";
188
189	print '<br>';
190	print load_fiche_titre('', '', '', 0, 0, '', '-> '.$langs->trans("SummaryOfVatExigibilityUsedByDefault"));
191	//print ' ('.$langs->trans("CanBeChangedWhenMakingInvoice").')';
192
193
194	print '<table class="noborder centpercent">';
195	print '<tr class="oddeven"><td class="titlefield">&nbsp;</td><td>'.$langs->trans("Buy").'</td><td>'.$langs->trans("Sell").'</td></tr>';
196
197	// Products
198	print '<tr class="oddeven"><td>'.$langs->trans("Product").'</td>';
199	print '<td>';
200	if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment')
201	{
202		print $langs->trans("OnPayment");
203		print ' ('.$langs->trans("SupposedToBePaymentDate").')';
204	} else {
205		print $langs->trans("OnDelivery");
206		print ' ('.$langs->trans("SupposedToBeInvoiceDate").')';
207	}
208	print '</td>';
209	print '<td>';
210	if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment')
211	{
212		print $langs->trans("OnPayment");
213		print ' ('.$langs->trans("SupposedToBePaymentDate").')';
214	} else {
215		print $langs->trans("OnDelivery");
216		print ' ('.$langs->trans("SupposedToBeInvoiceDate").')';
217	}
218	print '</td></tr>';
219
220	// Services
221	print '<tr class="oddeven"><td>'.$langs->trans("Services").'</td>';
222	print '<td>';
223	if ($conf->global->TAX_MODE_BUY_SERVICE == 'payment')
224	{
225		print $langs->trans("OnPayment");
226		print ' ('.$langs->trans("SupposedToBePaymentDate").')';
227	} else {
228		print $langs->trans("OnInvoice");
229		print ' ('.$langs->trans("InvoiceDateUsed").')';
230	}
231	print '</td>';
232	print '<td>';
233	if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment')
234	{
235		print $langs->trans("OnPayment");
236		print ' ('.$langs->trans("SupposedToBePaymentDate").')';
237	} else {
238		print $langs->trans("OnInvoice");
239		print ' ('.$langs->trans("InvoiceDateUsed").')';
240	}
241	print '</td></tr>';
242
243	print '</table>';
244}
245
246print "<br>\n";
247
248
249print '<div class="center">';
250print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="button">';
251print '</div>';
252
253print '</form>';
254
255
256
257
258if (!empty($conf->accounting->enabled))
259{
260	$langs->load("accountancy");
261	print '<br><br><span class="opacitymedium">'.$langs->trans("AccountingAccountForSalesTaxAreDefinedInto", $langs->transnoentitiesnoconv("MenuAccountancy"), $langs->transnoentitiesnoconv("Setup")).'</span>';
262}
263
264// End of page
265llxFooter();
266$db->close();
267