dolibarr  7.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@capnetworks.com>
5  * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.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 $langs->load('admin');
33 
34 if (!$user->admin) accessforbidden();
35 
36 $action = GETPOST('action','alpha');
37 
38 // Other parameters ACCOUNTING_*
39 $list = array (
40  'ACCOUNTING_VAT_PAY_ACCOUNT'
41 );
42 
43 /*
44  * Actions
45  */
46 
47 // 0=normal, 1=option vat for services is on debit
48 
49 // TAX_MODE=0 (most cases):
50 // Buy Sell
51 // Product On delivery On delivery
52 // Service On payment On payment
53 
54 // TAX_MODE=1 (option):
55 // Buy Sell
56 // Product On delivery On delivery
57 // Service On invoice On invoice
58 
59 $tax_mode = empty($conf->global->TAX_MODE)?0:$conf->global->TAX_MODE;
60 
61 if ($action == 'update') {
62  $error = 0;
63 
64  // Tax mode
65  $tax_mode = GETPOST('tax_mode','alpha');
66 
67  $db->begin();
68 
69  $res = dolibarr_set_const($db, 'TAX_MODE', $tax_mode,'chaine',0,'',$conf->entity);
70  if (! $res > 0) $error++;
71 
72  switch ($tax_mode)
73  {
74  case 0:
75  $value = 'payment';
76  break;
77  case 1:
78  $value = 'invoice';
79  break;
80  }
81 
82  $res = dolibarr_set_const($db, 'TAX_MODE_SELL_PRODUCT', 'invoice','chaine',0,'',$conf->entity);
83  if (! $res > 0) $error++;
84  $res = dolibarr_set_const($db, 'TAX_MODE_BUY_PRODUCT', 'invoice','chaine',0,'',$conf->entity);
85  if (! $res > 0) $error++;
86  $res = dolibarr_set_const($db, 'TAX_MODE_SELL_SERVICE', $value,'chaine',0,'',$conf->entity);
87  if (! $res > 0) $error++;
88  $res = dolibarr_set_const($db, 'TAX_MODE_BUY_SERVICE', $value,'chaine',0,'',$conf->entity);
89  if (! $res > 0) $error++;
90 
91  // Others options
92  foreach ($list as $constname) {
93  $constvalue = GETPOST($constname, 'alpha');
94 
95  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
96  $error++;
97  }
98  }
99 
100  if (! $error) {
101  $db->commit();
102  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
103  } else {
104  $db->rollback();
105  setEventMessages($langs->trans("Error"), null, 'errors');
106  }
107 }
108 
109 
110 /*
111  * View
112  */
113 
114 llxHeader();
115 $form=new Form($db);
116 if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
117 
118 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
119 print load_fiche_titre($langs->trans('TaxSetup'),$linkback,'title_setup');
120 
122 
123 if (empty($mysoc->tva_assuj))
124 {
125  print $langs->trans("YourCompanyDoesNotUseVAT").'<br>';
126 }
127 else
128 {
129  print '<table class="noborder" width="100%">';
130 
131  // Cas des parametres TAX_MODE_SELL/BUY_SERVICE/PRODUCT
132  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
133  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
134  print '<input type="hidden" name="action" value="update">';
135 
136  print '<tr class="liste_titre">';
137  print '<td colspan="2">'.$langs->trans('OptionVatMode').'</td><td>'.$langs->trans('Description').'</td>';
138  print "</tr>\n";
139  print '<tr class="oddeven"><td width="200"><input type="radio" name="tax_mode" value="0"'.($tax_mode != 1 ? ' checked' : '').'> '.$langs->trans('OptionVATDefault').'</td>';
140  print '<td colspan="2">'.nl2br($langs->trans('OptionVatDefaultDesc'));
141  print "</td></tr>\n";
142  print '<tr class="oddeven"><td width="200"><input type="radio" name="tax_mode" value="1"'.($tax_mode == 1 ? ' checked' : '').'> '.$langs->trans('OptionVATDebitOption').'</td>';
143  print '<td colspan="2">'.nl2br($langs->trans('OptionVatDebitOptionDesc'))."</td></tr>\n";
144 
145  print "</table>\n";
146 
147  print '<br>';
148  print load_fiche_titre($langs->trans("SummaryOfVatExigibilityUsedByDefault"),'','');
149  //print ' ('.$langs->trans("CanBeChangedWhenMakingInvoice").')';
150 
151  print '<table class="noborder" width="100%">';
152  print '<tr class="liste_titre"><td>&nbsp;</td><td>'.$langs->trans("Buy").'</td><td>'.$langs->trans("Sell").'</td></tr>';
153 
154  // Products
155  print '<tr class="oddeven"><td>'.$langs->trans("Product").'</td>';
156  print '<td>';
157  print $langs->trans("OnDelivery");
158  print ' ('.$langs->trans("SupposedToBeInvoiceDate").')';
159  print '</td>';
160  print '<td>';
161  print $langs->trans("OnDelivery");
162  print ' ('.$langs->trans("SupposedToBeInvoiceDate").')';
163  print '</td></tr>';
164 
165  // Services
166  print '<tr class="oddeven"><td>'.$langs->trans("Services").'</td>';
167  print '<td>';
168  if ($tax_mode == 0)
169  {
170  print $langs->trans("OnPayment");
171  print ' ('.$langs->trans("SupposedToBePaymentDate").')';
172  }
173  if ($tax_mode == 1)
174  {
175  print $langs->trans("OnInvoice");
176  print ' ('.$langs->trans("InvoiceDateUsed").')';
177  }
178  print '</td>';
179  print '<td>';
180  if ($tax_mode == 0)
181  {
182  print $langs->trans("OnPayment");
183  print ' ('.$langs->trans("SupposedToBePaymentDate").')';
184  }
185  if ($tax_mode == 1)
186  {
187  print $langs->trans("OnInvoice");
188  print ' ('.$langs->trans("InvoiceDateUsed").')';
189  }
190  print '</td></tr>';
191 
192  print '</table>';
193 }
194 
195 print "<br>\n";
196 
197 /*
198  * Others params
199  */
200 print '<table class="noborder" width="100%">';
201 print '<tr class="liste_titre">';
202 print '<td colspan="3">' . $langs->trans('OtherOptions') . '</td>';
203 print "</tr>\n";
204 
205 foreach ($list as $key)
206 {
207 
208 
209  print '<tr class="oddeven value">';
210 
211  // Param
212  $label = $langs->trans($key);
213  print '<td><label for="'.$key.'">'.$label.'</label></td>';
214 
215  // Value
216  print '<td>';
217  if (! empty($conf->accounting->enabled))
218  {
219  print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
220  }
221  else
222  {
223  print '<input type="text" size="20" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
224  }
225  print '</td></tr>';
226 }
227 
228 print '</table>';
229 
230 dol_fiche_end();
231 
232 print '<div class="center">';
233 print '<input type="submit" class="button" value="' . $langs->trans("Modify") . '" name="button">';
234 print '</div>';
235 
236 print '</form>';
237 
238 llxFooter();
239 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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:485
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91
Class to manage generation of HTML components for accounting management.