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