dolibarr 21.0.0-alpha
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
38// Load translation files required by the page
39$langs->loadLangs(array('admin', 'objects', 'companies', 'products'));
40
41if (!$user->admin) {
43}
44
45$action = GETPOST('action', 'aZ09');
46
47
48
49/*
50 * Actions
51 */
52
53// 0=normal, 1=option vat for services is on debit, 2=option vat for product and service on credit
54
55// TAX_MODE=0 (most cases in FR):
56// Buy Sell
57// Product On delivery On delivery
58// Service On payment On payment
59
60// TAX_MODE=1 (option, VAT is due at invoice date):
61// Buy Sell
62// Product On delivery/invoice On delivery/invoice
63// Service On invoice On invoice
64
65// TAX_MODE=2 (option, VAT is due on payment date):
66// Buy Sell
67// Product On payment On payment
68// Service On payment On payment
69
70$tax_mode = getDolGlobalInt('TAX_MODE');
71
72if ($action == 'update') {
73 $error = 0;
74
75 // Tax mode
76 $tax_mode = GETPOSTINT('tax_mode');
77
78 $db->begin();
79
80 $res = dolibarr_set_const($db, 'TAX_MODE', $tax_mode, 'chaine', 0, '', $conf->entity);
81 if (!($res > 0)) {
82 $error++;
83 }
84
85 switch ($tax_mode) {
86 case 0:
87 $valuesellproduct = 'invoice';
88 $valuebuyproduct = 'invoice';
89 $valuesellservice = 'payment';
90 $valuebuyservice = 'payment';
91 break;
92 case 1:
93 $valuesellproduct = 'invoice';
94 $valuebuyproduct = 'invoice';
95 $valuesellservice = 'invoice';
96 $valuebuyservice = 'invoice';
97 break;
98 case 2:
99 $valuesellproduct = 'payment';
100 $valuebuyproduct = 'payment';
101 $valuesellservice = 'payment';
102 $valuebuyservice = 'payment';
103 break;
104 default:
105 $valuesellproduct = null;
106 $valuebuyproduct = null;
107 $valuesellservice = null;
108 $valuebuyservice = null;
109 break;
110 }
111
112 $res = dolibarr_set_const($db, 'TAX_MODE_SELL_PRODUCT', $valuesellproduct, 'chaine', 0, '', $conf->entity);
113 if (!($res > 0)) {
114 $error++;
115 }
116 $res = dolibarr_set_const($db, 'TAX_MODE_BUY_PRODUCT', $valuebuyproduct, 'chaine', 0, '', $conf->entity);
117 if (!($res > 0)) {
118 $error++;
119 }
120 $res = dolibarr_set_const($db, 'TAX_MODE_SELL_SERVICE', $valuesellservice, 'chaine', 0, '', $conf->entity);
121 if (!($res > 0)) {
122 $error++;
123 }
124 $res = dolibarr_set_const($db, 'TAX_MODE_BUY_SERVICE', $valuebuyservice, 'chaine', 0, '', $conf->entity);
125 if (!($res > 0)) {
126 $error++;
127 }
128
129 dolibarr_set_const($db, "MAIN_INFO_TVAINTRA", GETPOST("tva", 'alpha'), 'chaine', 0, '', $conf->entity);
130
131 dolibarr_set_const($db, "MAIN_INFO_VAT_RETURN", GETPOST("MAIN_INFO_VAT_RETURN", 'alpha'), 'chaine', 0, '', $conf->entity);
132
133 dolibarr_set_const($db, "MAIN_INFO_TVA_DAY_DEADLINE_SUBMISSION", GETPOSTINT("deadline_day_vat"), 'chaine', 0, '', $conf->entity);
134
135 if (!$error) {
136 $db->commit();
137 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
138 } else {
139 $db->rollback();
140 setEventMessages($langs->trans("Error"), null, 'errors');
141 }
142} elseif (preg_match('/^(set|del)_?([A-Z_]+)$/', $action, $reg)) {
143 // Set boolean (on/off) constants
144 if (!dolibarr_set_const($db, $reg[2], ($reg[1] === 'set' ? '1' : '0'), 'chaine', 0, '', $conf->entity) > 0) {
145 dol_print_error($db);
146 }
147}
148
149
150/*
151 * View
152 */
153
154llxHeader('', $langs->trans("TaxSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-taxes');
155
156$form = new Form($db);
157if (isModEnabled('accounting')) {
158 $formaccounting = new FormAccounting($db);
159}
160
161$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
162print load_fiche_titre($langs->trans('TaxSetup'), $linkback, 'title_setup');
163
164//print dol_get_fiche_head([], '', '', -1);
165
166if (empty($mysoc->tva_assuj)) {
167 print $langs->trans("YourCompanyDoesNotUseVAT").'<br>';
168} else {
169 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
170 print '<input type="hidden" name="token" value="'.newToken().'">';
171 print '<input type="hidden" name="action" value="update">';
172
173 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
174 print '<table class="noborder centpercent">';
175 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameters").'</td><td>'.$langs->trans("Value").'</td></tr>';
176
177 print '<tr class="oddeven"><td><label for="intra_vat">'.$langs->trans("VATIntra").'</label></td><td>';
178 print '<input name="tva" id="intra_vat" class="minwidth200" value="'.getDolGlobalString('MAIN_INFO_TVAINTRA').'">';
179 print '</td></tr>';
180
181 print '<tr class="oddeven"><td><label for="activate_MAIN_INFO_VAT_RETURN">'.$langs->trans("VATPaymentFrequency").'</label></td>';
182 if (!$conf->use_javascript_ajax) {
183 print '<td class="nowrap right">';
184 print $langs->trans("NotAvailableWhenAjaxDisabled");
185 print "</td>";
186 } else {
187 print '<td width="120">';
188 $listval = array(
189 '0' => $langs->trans(""),
190 '1' => $langs->trans("Monthly"),
191 '2' => $langs->trans("Quarterly"),
192 '3' => $langs->trans("Annual"),
193 );
194 print $form->selectarray("MAIN_INFO_VAT_RETURN", $listval, getDolGlobalString('MAIN_INFO_VAT_RETURN'));
195 print "</td>";
196 }
197 print '</tr>';
198
199 print '<tr class="oddeven"><td><label for="deadline_day_vat">'.$langs->trans("DeadlineDayVATSubmission").'</label></td><td>';
200 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 : '').'">';
201 print '</td></tr>';
202
203 $key = 'CREATE_NEW_VAT_WITHOUT_AUTO_PAYMENT';
204 print '<tr><td>'.$langs->trans($key).'</td><td>'.ajax_constantonoff($key).'</td></tr>';
205
206 print '</table>';
207 print '</div>';
208
209 print '<br>';
210
211
212 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
213 print '<table class="noborder centpercent">';
214
215 // Case for the parameters TAX_MODE_SELL/BUY_SERVICE/PRODUCT
216 print '<tr class="liste_titre">';
217 print '<td class="titlefield">'.$langs->trans('OptionVatMode').'</td><td>'.$langs->trans('Description').'</td>';
218 print "</tr>\n";
219 // Standard
220 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>';
221 print '<td>'.nl2br($langs->trans('OptionVatDefaultDesc'));
222 print "</td></tr>\n";
223 // On debit for services
224 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>';
225 print '<td>'.nl2br($langs->trans('OptionVatDebitOptionDesc'))."</td></tr>\n";
226 // On payment for both products and services
227 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1) {
228 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>';
229 print '<td>'.nl2br($langs->trans('OptionPaymentForProductAndServicesDesc'))."</td></tr>\n";
230 }
231 print "</table>\n";
232 print '</div>';
233
234
235 print '<br>';
236 print load_fiche_titre('', '', '', 0, '', '', '-> '.$langs->trans("SummaryOfVatExigibilityUsedByDefault"));
237 //print ' ('.$langs->trans("CanBeChangedWhenMakingInvoice").')';
238
239
240 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
241 print '<table class="noborder centpercent">';
242 print '<tr class="oddeven"><td class="titlefield">&nbsp;</td><td>'.$langs->trans("Buy").'</td><td>'.$langs->trans("Sell").'</td></tr>';
243
244 // Products
245 print '<tr class="oddeven"><td>'.$langs->trans("Product").'</td>';
246 print '<td>';
247 if (getDolGlobalString('TAX_MODE_BUY_PRODUCT') == 'payment') {
248 print $langs->trans("OnPayment");
249 print ' ('.$langs->trans("SupposedToBePaymentDate").')';
250 } else {
251 print $langs->trans("OnDelivery");
252 print ' ('.$langs->trans("SupposedToBeInvoiceDate").')';
253 }
254 print '</td>';
255 print '<td>';
256 if (getDolGlobalString('TAX_MODE_SELL_PRODUCT') == 'payment') {
257 print $langs->trans("OnPayment");
258 print ' ('.$langs->trans("SupposedToBePaymentDate").')';
259 } else {
260 print $langs->trans("OnDelivery");
261 print ' ('.$langs->trans("SupposedToBeInvoiceDate").')';
262 }
263 print '</td></tr>';
264
265 // Services
266 print '<tr class="oddeven"><td>'.$langs->trans("Services").'</td>';
267 print '<td>';
268 if (getDolGlobalString('TAX_MODE_BUY_SERVICE') == 'payment') {
269 print $langs->trans("OnPayment");
270 print ' ('.$langs->trans("SupposedToBePaymentDate").')';
271 } else {
272 print $langs->trans("OnInvoice");
273 print ' ('.$langs->trans("InvoiceDateUsed").')';
274 }
275 print '</td>';
276 print '<td>';
277 if (getDolGlobalString('TAX_MODE_SELL_SERVICE') == 'payment') {
278 print $langs->trans("OnPayment");
279 print ' ('.$langs->trans("SupposedToBePaymentDate").')';
280 } else {
281 print $langs->trans("OnInvoice");
282 print ' ('.$langs->trans("InvoiceDateUsed").')';
283 }
284 print '</td></tr>';
285
286 print '</table>';
287 print '</div>';
288}
289
290print "<br>\n";
291
292
293print '<div class="center">';
294print '<input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'">';
295print '<br><br>';
296print '</div>';
297
298print '</form>';
299
300
301print '<br>';
302
303if (isModEnabled('accounting')) {
304 $langs->load("accountancy");
305 print '<br><br><span class="opacitymedium">'.$langs->trans("AccountingAccountForSalesTaxAreDefinedInto", $langs->transnoentitiesnoconv("MenuAccountancy"), $langs->transnoentitiesnoconv("Setup")).'</span>';
306}
307
308// End of page
309llxFooter();
310$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:70
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.