dolibarr 21.0.0-beta
taxes.php
Go to the documentation of this file.
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-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
7 * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Load Dolibarr environment
32require '../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34if (isModEnabled('accounting')) {
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
36}
37
46// Load translation files required by the page
47$langs->loadLangs(array('admin', 'objects', 'companies', 'products'));
48
49if (!$user->admin) {
51}
52
53$action = GETPOST('action', 'aZ09');
54
55
56
57/*
58 * Actions
59 */
60
61// 0=normal, 1=option vat for services is on debit, 2=option vat for product and service on credit
62
63// TAX_MODE=0 (most cases in FR):
64// Buy Sell
65// Product On delivery On delivery
66// Service On payment On payment
67
68// TAX_MODE=1 (option, VAT is due at invoice date):
69// Buy Sell
70// Product On delivery/invoice On delivery/invoice
71// Service On invoice On invoice
72
73// TAX_MODE=2 (option, VAT is due on payment date):
74// Buy Sell
75// Product On payment On payment
76// Service On payment On payment
77
78$tax_mode = getDolGlobalInt('TAX_MODE');
79
80if ($action == 'update') {
81 $error = 0;
82
83 // Tax mode
84 $tax_mode = GETPOSTINT('tax_mode');
85
86 $db->begin();
87
88 $res = dolibarr_set_const($db, 'TAX_MODE', $tax_mode, 'chaine', 0, '', $conf->entity);
89 if (!($res > 0)) {
90 $error++;
91 }
92
93 switch ($tax_mode) {
94 case 0:
95 $valuesellproduct = 'invoice';
96 $valuebuyproduct = 'invoice';
97 $valuesellservice = 'payment';
98 $valuebuyservice = 'payment';
99 break;
100 case 1:
101 $valuesellproduct = 'invoice';
102 $valuebuyproduct = 'invoice';
103 $valuesellservice = 'invoice';
104 $valuebuyservice = 'invoice';
105 break;
106 case 2:
107 $valuesellproduct = 'payment';
108 $valuebuyproduct = 'payment';
109 $valuesellservice = 'payment';
110 $valuebuyservice = 'payment';
111 break;
112 default:
113 $valuesellproduct = null;
114 $valuebuyproduct = null;
115 $valuesellservice = null;
116 $valuebuyservice = null;
117 break;
118 }
119
120 $res = dolibarr_set_const($db, 'TAX_MODE_SELL_PRODUCT', $valuesellproduct, 'chaine', 0, '', $conf->entity);
121 if (!($res > 0)) {
122 $error++;
123 }
124 $res = dolibarr_set_const($db, 'TAX_MODE_BUY_PRODUCT', $valuebuyproduct, 'chaine', 0, '', $conf->entity);
125 if (!($res > 0)) {
126 $error++;
127 }
128 $res = dolibarr_set_const($db, 'TAX_MODE_SELL_SERVICE', $valuesellservice, 'chaine', 0, '', $conf->entity);
129 if (!($res > 0)) {
130 $error++;
131 }
132 $res = dolibarr_set_const($db, 'TAX_MODE_BUY_SERVICE', $valuebuyservice, 'chaine', 0, '', $conf->entity);
133 if (!($res > 0)) {
134 $error++;
135 }
136
137 dolibarr_set_const($db, "MAIN_INFO_TVAINTRA", GETPOST("tva", 'alpha'), 'chaine', 0, '', $conf->entity);
138
139 dolibarr_set_const($db, "MAIN_INFO_VAT_RETURN", GETPOST("MAIN_INFO_VAT_RETURN", 'alpha'), 'chaine', 0, '', $conf->entity);
140
141 dolibarr_set_const($db, "MAIN_INFO_TVA_DAY_DEADLINE_SUBMISSION", GETPOSTINT("deadline_day_vat"), 'chaine', 0, '', $conf->entity);
142
143 if (!$error) {
144 $db->commit();
145 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
146 } else {
147 $db->rollback();
148 setEventMessages($langs->trans("Error"), null, 'errors');
149 }
150} elseif (preg_match('/^(set|del)_?([A-Z_]+)$/', $action, $reg)) {
151 // Set boolean (on/off) constants
152 if (!dolibarr_set_const($db, $reg[2], ($reg[1] === 'set' ? '1' : '0'), 'chaine', 0, '', $conf->entity) > 0) {
153 dol_print_error($db);
154 }
155}
156
157
158/*
159 * View
160 */
161
162llxHeader('', $langs->trans("TaxSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-taxes');
163
164$form = new Form($db);
165if (isModEnabled('accounting')) {
166 $formaccounting = new FormAccounting($db);
167}
168
169$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
170print load_fiche_titre($langs->trans('TaxSetup'), $linkback, 'title_setup');
171
172//print dol_get_fiche_head([], '', '', -1);
173
174if (empty($mysoc->tva_assuj)) {
175 print $langs->trans("YourCompanyDoesNotUseVAT").'<br>';
176} else {
177 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
178 print '<input type="hidden" name="token" value="'.newToken().'">';
179 print '<input type="hidden" name="action" value="update">';
180
181 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
182 print '<table class="noborder centpercent">';
183 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameters").'</td><td>'.$langs->trans("Value").'</td></tr>';
184
185 print '<tr class="oddeven"><td><label for="intra_vat">'.$langs->trans("VATIntra").'</label></td><td>';
186 print '<input name="tva" id="intra_vat" class="minwidth200" value="'.getDolGlobalString('MAIN_INFO_TVAINTRA').'">';
187 print '</td></tr>';
188
189 print '<tr class="oddeven"><td><label for="activate_MAIN_INFO_VAT_RETURN">'.$langs->trans("VATPaymentFrequency").'</label></td>';
190 if (!$conf->use_javascript_ajax) {
191 print '<td class="nowrap right">';
192 print $langs->trans("NotAvailableWhenAjaxDisabled");
193 print "</td>";
194 } else {
195 print '<td width="120">';
196 $listval = array(
197 '0' => $langs->trans(""),
198 '1' => $langs->trans("Monthly"),
199 '2' => $langs->trans("Quarterly"),
200 '3' => $langs->trans("Annual"),
201 );
202 print $form->selectarray("MAIN_INFO_VAT_RETURN", $listval, getDolGlobalString('MAIN_INFO_VAT_RETURN'));
203 print "</td>";
204 }
205 print '</tr>';
206
207 print '<tr class="oddeven"><td><label for="deadline_day_vat">'.$langs->trans("DeadlineDayVATSubmission").'</label></td><td>';
208 print '<input placeholder="'.$langs->trans("Example").':21" name="deadline_day_vat" id="deadline_day_vat" class="minwidth200" value="'.(getDolGlobalString('MAIN_INFO_TVA_DAY_DEADLINE_SUBMISSION') ? $conf->global->MAIN_INFO_TVA_DAY_DEADLINE_SUBMISSION : '').'">';
209 print '</td></tr>';
210
211 $key = 'CREATE_NEW_VAT_WITHOUT_AUTO_PAYMENT';
212 print '<tr><td>'.$langs->trans($key).'</td><td>'.ajax_constantonoff($key).'</td></tr>';
213
214 print '</table>';
215 print '</div>';
216
217 print '<br>';
218
219
220 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
221 print '<table class="noborder centpercent">';
222
223 // Case for the parameters TAX_MODE_SELL/BUY_SERVICE/PRODUCT
224 print '<tr class="liste_titre">';
225 print '<td class="titlefield">'.$langs->trans('OptionVatMode').'</td><td>'.$langs->trans('Description').'</td>';
226 print "</tr>\n";
227 // Standard
228 print '<tr class="oddeven"><td><input type="radio" id="tax_mode0" name="tax_mode" value="0"'.(empty($tax_mode) ? ' checked' : '').'> <label for="tax_mode0">'.$langs->trans('OptionVATDefault').'</label></td>';
229 print '<td>'.nl2br($langs->trans('OptionVatDefaultDesc'));
230 print "</td></tr>\n";
231 // On debit for services
232 print '<tr class="oddeven"><td><input type="radio" id="tax_mode1" name="tax_mode" value="1"'.($tax_mode == 1 ? ' checked' : '').'> <label for="tax_mode1">'.$langs->trans('OptionVATDebitOption').'</label></td>';
233 print '<td>'.nl2br($langs->trans('OptionVatDebitOptionDesc'))."</td></tr>\n";
234 // On payment for both products and services
235 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1) {
236 print '<tr class="oddeven"><td><input type="radio" id="tax_mode2" name="tax_mode" value="2"'.($tax_mode == 2 ? ' checked' : '').'> <label for="tax_mode2">'.$langs->trans('OptionPaymentForProductAndServices').'</label></td>';
237 print '<td>'.nl2br($langs->trans('OptionPaymentForProductAndServicesDesc'))."</td></tr>\n";
238 }
239 print "</table>\n";
240 print '</div>';
241
242
243 print '<br>';
244 print load_fiche_titre('', '', '', 0, '', '', '-> '.$langs->trans("SummaryOfVatExigibilityUsedByDefault"));
245 //print ' ('.$langs->trans("CanBeChangedWhenMakingInvoice").')';
246
247
248 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
249 print '<table class="noborder centpercent">';
250 print '<tr class="oddeven"><td class="titlefield">&nbsp;</td><td>'.$langs->trans("Buy").'</td><td>'.$langs->trans("Sell").'</td></tr>';
251
252 // Products
253 print '<tr class="oddeven"><td>'.$langs->trans("Product").'</td>';
254 print '<td>';
255 if (getDolGlobalString('TAX_MODE_BUY_PRODUCT') == 'payment') {
256 print $langs->trans("OnPayment");
257 print ' ('.$langs->trans("SupposedToBePaymentDate").')';
258 } else {
259 print $langs->trans("OnDelivery");
260 print ' ('.$langs->trans("SupposedToBeInvoiceDate").')';
261 }
262 print '</td>';
263 print '<td>';
264 if (getDolGlobalString('TAX_MODE_SELL_PRODUCT') == 'payment') {
265 print $langs->trans("OnPayment");
266 print ' ('.$langs->trans("SupposedToBePaymentDate").')';
267 } else {
268 print $langs->trans("OnDelivery");
269 print ' ('.$langs->trans("SupposedToBeInvoiceDate").')';
270 }
271 print '</td></tr>';
272
273 // Services
274 print '<tr class="oddeven"><td>'.$langs->trans("Services").'</td>';
275 print '<td>';
276 if (getDolGlobalString('TAX_MODE_BUY_SERVICE') == 'payment') {
277 print $langs->trans("OnPayment");
278 print ' ('.$langs->trans("SupposedToBePaymentDate").')';
279 } else {
280 print $langs->trans("OnInvoice");
281 print ' ('.$langs->trans("InvoiceDateUsed").')';
282 }
283 print '</td>';
284 print '<td>';
285 if (getDolGlobalString('TAX_MODE_SELL_SERVICE') == 'payment') {
286 print $langs->trans("OnPayment");
287 print ' ('.$langs->trans("SupposedToBePaymentDate").')';
288 } else {
289 print $langs->trans("OnInvoice");
290 print ' ('.$langs->trans("InvoiceDateUsed").')';
291 }
292 print '</td></tr>';
293
294 print '</table>';
295 print '</div>';
296}
297
298print "<br>\n";
299
300
301print '<div class="center">';
302print '<input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'">';
303print '<br><br>';
304print '</div>';
305
306print '</form>';
307
308
309print '<br>';
310
311if (isModEnabled('accounting')) {
312 $langs->load("accountancy");
313 print '<br><br><span class="opacitymedium">'.$langs->trans("AccountingAccountForSalesTaxAreDefinedInto", $langs->transnoentitiesnoconv("MenuAccountancy"), $langs->transnoentitiesnoconv("Setup")).'</span>';
314}
315
316// End of page
317llxFooter();
318$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.