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