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