dolibarr  17.0.4
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  *
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 
28 // Load Dolibarr environment
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31 if (isModEnabled('accounting')) {
32  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
33 }
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('admin', 'objects', 'companies', 'products'));
37 
38 if (!$user->admin) {
40 }
41 
42 $action = GETPOST('action', 'aZ09');
43 
44 
45 
46 /*
47  * Actions
48  */
49 
50 // 0=normal, 1=option vat for services is on debit
51 
52 // TAX_MODE=0 (most cases):
53 // Buy Sell
54 // Product On delivery On delivery
55 // Service On payment On payment
56 
57 // TAX_MODE=1 (option):
58 // Buy Sell
59 // Product On delivery On delivery
60 // Service On invoice On invoice
61 
62 $tax_mode = empty($conf->global->TAX_MODE) ? 0 : $conf->global->TAX_MODE;
63 
64 if ($action == 'update') {
65  $error = 0;
66 
67  // Tax mode
68  $tax_mode = GETPOST('tax_mode', 'alpha');
69 
70  $db->begin();
71 
72  $res = dolibarr_set_const($db, 'TAX_MODE', $tax_mode, 'chaine', 0, '', $conf->entity);
73  if (!($res > 0)) {
74  $error++;
75  }
76 
77  switch ($tax_mode) {
78  case 0:
79  $valuesellproduct = 'invoice';
80  $valuebuyproduct = 'invoice';
81  $valuesellservice = 'payment';
82  $valuebuyservice = 'payment';
83  break;
84  case 1:
85  $valuesellproduct = 'invoice';
86  $valuebuyproduct = 'invoice';
87  $valuesellservice = 'invoice';
88  $valuebuyservice = 'invoice';
89  break;
90  case 2:
91  $valuesellproduct = 'payment';
92  $valuebuyproduct = 'payment';
93  $valuesellservice = 'payment';
94  $valuebuyservice = 'payment';
95  break;
96  }
97 
98  $res = dolibarr_set_const($db, 'TAX_MODE_SELL_PRODUCT', $valuesellproduct, 'chaine', 0, '', $conf->entity);
99  if (!($res > 0)) {
100  $error++;
101  }
102  $res = dolibarr_set_const($db, 'TAX_MODE_BUY_PRODUCT', $valuebuyproduct, 'chaine', 0, '', $conf->entity);
103  if (!($res > 0)) {
104  $error++;
105  }
106  $res = dolibarr_set_const($db, 'TAX_MODE_SELL_SERVICE', $valuesellservice, 'chaine', 0, '', $conf->entity);
107  if (!($res > 0)) {
108  $error++;
109  }
110  $res = dolibarr_set_const($db, 'TAX_MODE_BUY_SERVICE', $valuebuyservice, 'chaine', 0, '', $conf->entity);
111  if (!($res > 0)) {
112  $error++;
113  }
114 
115  dolibarr_set_const($db, "MAIN_INFO_TVAINTRA", GETPOST("tva", 'alpha'), 'chaine', 0, '', $conf->entity);
116 
117  dolibarr_set_const($db, "MAIN_INFO_VAT_RETURN", GETPOST("MAIN_INFO_VAT_RETURN", 'alpha'), 'chaine', 0, '', $conf->entity);
118 
119  dolibarr_set_const($db, "MAIN_INFO_TVA_DAY_DEADLINE_SUBMISSION", GETPOST("deadline_day_vat", 'int'), 'chaine', 0, '', $conf->entity);
120 
121  if (!$error) {
122  $db->commit();
123  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
124  } else {
125  $db->rollback();
126  setEventMessages($langs->trans("Error"), null, 'errors');
127  }
128 } elseif (preg_match('/^(set|del)_?([A-Z_]+)$/', $action, $reg)) {
129  // Set boolean (on/off) constants
130  if (!dolibarr_set_const($db, $reg[2], ($reg[1] === 'set' ? '1' : '0'), 'chaine', 0, '', $conf->entity) > 0) {
131  dol_print_error($db);
132  }
133 }
134 
135 
136 /*
137  * View
138  */
139 
140 llxHeader('', $langs->trans("TaxSetup"));
141 
142 $form = new Form($db);
143 if (isModEnabled('accounting')) {
144  $formaccounting = new FormAccounting($db);
145 }
146 
147 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
148 print load_fiche_titre($langs->trans('TaxSetup'), $linkback, 'title_setup');
149 
150 //print dol_get_fiche_head(null, '', '', -1);
151 
152 if (empty($mysoc->tva_assuj)) {
153  print $langs->trans("YourCompanyDoesNotUseVAT").'<br>';
154 } else {
155  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
156  print '<input type="hidden" name="token" value="'.newToken().'">';
157  print '<input type="hidden" name="action" value="update">';
158 
159  print '<table class="noborder centpercent">';
160  print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("CompanyIds").'</td><td>'.$langs->trans("Value").'</td></tr>';
161 
162  print '<tr class="oddeven"><td><label for="intra_vat">'.$langs->trans("VATIntra").'</label></td><td>';
163  print '<input name="tva" id="intra_vat" class="minwidth200" value="'.(!empty($conf->global->MAIN_INFO_TVAINTRA) ? $conf->global->MAIN_INFO_TVAINTRA : '').'">';
164  print '</td></tr>';
165 
166  print '<tr class="oddeven"><td><label for="activate_MAIN_INFO_VAT_RETURN">'.$langs->trans("VATReturn").'</label></td>';
167  if (!$conf->use_javascript_ajax) {
168  print '<td class="nowrap right">';
169  print $langs->trans("NotAvailableWhenAjaxDisabled");
170  print "</td>";
171  } else {
172  print '<td width="120">';
173  $listval = array(
174  '0'=>$langs->trans(""),
175  '1'=>$langs->trans("Monthly"),
176  '2'=>$langs->trans("Quarterly"),
177  '3'=>$langs->trans("Annual"),
178  );
179  print $form->selectarray("MAIN_INFO_VAT_RETURN", $listval, $conf->global->MAIN_INFO_VAT_RETURN);
180  print "</td>";
181  }
182  print '</tr>';
183 
184  print '<tr class="oddeven"><td><label for="deadline_day_vat">'.$langs->trans("DeadlineDayVATSubmission").'</label></td><td>';
185  print '<input placeholder="'.$langs->trans("Example").':21" name="deadline_day_vat" id="deadline_day_vat" class="minwidth200" value="'.(!empty($conf->global->MAIN_INFO_TVA_DAY_DEADLINE_SUBMISSION) ? $conf->global->MAIN_INFO_TVA_DAY_DEADLINE_SUBMISSION : '').'">';
186  print '</td></tr>';
187 
188  print '</table>';
189 
190  print '<br>';
191 
192  print '<table class="noborder centpercent">';
193 
194  // Cas des parametres TAX_MODE_SELL/BUY_SERVICE/PRODUCT
195  print '<tr class="liste_titre">';
196  print '<td class="titlefield">'.$langs->trans('OptionVatMode').'</td><td>'.$langs->trans('Description').'</td>';
197  print "</tr>\n";
198  // Standard
199  print '<tr class="oddeven"><td><input type="radio" name="tax_mode" value="0"'.(empty($tax_mode) ? ' checked' : '').'> '.$langs->trans('OptionVATDefault').'</td>';
200  print '<td>'.nl2br($langs->trans('OptionVatDefaultDesc'));
201  print "</td></tr>\n";
202  // On debit for services
203  print '<tr class="oddeven"><td><input type="radio" name="tax_mode" value="1"'.($tax_mode == 1 ? ' checked' : '').'> '.$langs->trans('OptionVATDebitOption').'</td>';
204  print '<td>'.nl2br($langs->trans('OptionVatDebitOptionDesc'))."</td></tr>\n";
205  // On payment for both products and services
206  if ($conf->global->MAIN_FEATURES_LEVEL >= 1) {
207  print '<tr class="oddeven"><td><input type="radio" name="tax_mode" value="2"'.($tax_mode == 2 ? ' checked' : '').'> '.$langs->trans('OptionPaymentForProductAndServices').'</td>';
208  print '<td>'.nl2br($langs->trans('OptionPaymentForProductAndServicesDesc'))."</td></tr>\n";
209  }
210  print "</table>\n";
211 
212  print '<br>';
213  print load_fiche_titre('', '', '', 0, 0, '', '-> '.$langs->trans("SummaryOfVatExigibilityUsedByDefault"));
214  //print ' ('.$langs->trans("CanBeChangedWhenMakingInvoice").')';
215 
216 
217  print '<table class="noborder centpercent">';
218  print '<tr class="oddeven"><td class="titlefield">&nbsp;</td><td>'.$langs->trans("Buy").'</td><td>'.$langs->trans("Sell").'</td></tr>';
219 
220  // Products
221  print '<tr class="oddeven"><td>'.$langs->trans("Product").'</td>';
222  print '<td>';
223  if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment') {
224  print $langs->trans("OnPayment");
225  print ' ('.$langs->trans("SupposedToBePaymentDate").')';
226  } else {
227  print $langs->trans("OnDelivery");
228  print ' ('.$langs->trans("SupposedToBeInvoiceDate").')';
229  }
230  print '</td>';
231  print '<td>';
232  if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') {
233  print $langs->trans("OnPayment");
234  print ' ('.$langs->trans("SupposedToBePaymentDate").')';
235  } else {
236  print $langs->trans("OnDelivery");
237  print ' ('.$langs->trans("SupposedToBeInvoiceDate").')';
238  }
239  print '</td></tr>';
240 
241  // Services
242  print '<tr class="oddeven"><td>'.$langs->trans("Services").'</td>';
243  print '<td>';
244  if ($conf->global->TAX_MODE_BUY_SERVICE == 'payment') {
245  print $langs->trans("OnPayment");
246  print ' ('.$langs->trans("SupposedToBePaymentDate").')';
247  } else {
248  print $langs->trans("OnInvoice");
249  print ' ('.$langs->trans("InvoiceDateUsed").')';
250  }
251  print '</td>';
252  print '<td>';
253  if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') {
254  print $langs->trans("OnPayment");
255  print ' ('.$langs->trans("SupposedToBePaymentDate").')';
256  } else {
257  print $langs->trans("OnInvoice");
258  print ' ('.$langs->trans("InvoiceDateUsed").')';
259  }
260  print '</td></tr>';
261 
262  print '</table>';
263 }
264 
265 print "<br>\n";
266 
267 
268 print '<div class="center">';
269 print '<input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'">';
270 print '<br><br>';
271 print '</div>';
272 
273 print '</form>';
274 
275 // Options
276 
277 echo '<div>';
278 echo '<table class="noborder centpercent">';
279 echo '<thead>';
280 echo '<tr class="liste_titre"><th>'.$langs->trans('Parameter').'</th><th>'.$langs->trans('Value').'</th></tr>';
281 echo '</thead>';
282 echo '<tbody>';
283 
284 $key = 'CREATE_NEW_VAT_WITHOUT_AUTO_PAYMENT';
285 echo '<tr><td>', $langs->trans($key), '</td><td>', ajax_constantonoff($key), '</td></tr>';
286 
287 echo '</tbody>';
288 echo '</table>';
289 echo '</div>';
290 
291 
292 if (isModEnabled('accounting')) {
293  $langs->load("accountancy");
294  print '<br><br><span class="opacitymedium">'.$langs->trans("AccountingAccountForSalesTaxAreDefinedInto", $langs->transnoentitiesnoconv("MenuAccountancy"), $langs->transnoentitiesnoconv("Setup")).'</span>';
295 }
296 
297 // End of page
298 llxFooter();
299 $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:632
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='')
On/off button for constant.
Definition: ajax.lib.php:600
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.