dolibarr  9.0.0
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@zendsi.com>
6  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.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 <http://www.gnu.org/licenses/>.
20  */
21 
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('compta', 'banks', 'bills'));
35 
36 $id=GETPOST("id",'int');
37 $action=GETPOST("action","alpha");
38 $refund=GETPOST("refund","int");
39 if (empty($refund)) $refund=0;
40 
41 // Security check
42 $socid = GETPOST('socid','int');
43 if ($user->societe_id) $socid=$user->societe_id;
44 $result = restrictedArea($user, 'tax', '', '', 'charges');
45 
46 $object = new Tva($db);
47 
48 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
49 $hookmanager->initHooks(array('taxvatcard','globalcard'));
50 
51 
56 if ($_POST["cancel"] == $langs->trans("Cancel") && ! $id)
57 {
58  header("Location: list.php");
59  exit;
60 }
61 
62 if ($action == 'setlib' && $user->rights->tax->charges->creer)
63 {
64  $object->fetch($id);
65  $result = $object->setValueFrom('label', GETPOST('lib','alpha'), '', '', 'text', '', $user, 'TAX_MODIFY');
66  if ($result < 0)
67  setEventMessages($object->error, $object->errors, 'errors');
68 }
69 
70 if ($action == 'setdatev' && $user->rights->tax->charges->creer)
71 {
72  $object->fetch($id);
73  $object->datev=dol_mktime(12,0,0,GETPOST('datevmonth','int'),GETPOST('datevday','int'),GETPOST('datevyear','int'));
74  $result=$object->update($user);
75  if ($result < 0) dol_print_error($db,$object->error);
76 
77  $action='';
78 }
79 
80 if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
81 {
82  $error=0;
83 
84  $datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
85  $datep=dol_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
86 
87  $object->accountid=GETPOST("accountid");
88  $object->type_payment=GETPOST("type_payment");
89  $object->num_payment=GETPOST("num_payment");
90  $object->datev=$datev;
91  $object->datep=$datep;
92 
93  $amount = price2num(GETPOST("amount",'alpha'));
94  if ($refund == 1) {
95  $amount= -$amount;
96  }
97  $object->amount= $amount;
98  $object->label=GETPOST("label",'alpha');
99  $object->note=GETPOST("note",'none');
100 
101  if (empty($object->datev))
102  {
103  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateValue")), null, 'errors');
104  $error++;
105  }
106  if (empty($object->datep))
107  {
108  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
109  $error++;
110  }
111  if (empty($object->type_payment) || $object->type_payment < 0)
112  {
113  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
114  $error++;
115  }
116  if (empty($object->amount))
117  {
118  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
119  $error++;
120  }
121 
122  if (! $error)
123  {
124  $db->begin();
125 
126  $ret=$object->addPayment($user);
127  if ($ret > 0)
128  {
129  $db->commit();
130  header("Location: list.php");
131  exit;
132  }
133  else
134  {
135  $db->rollback();
136  setEventMessages($object->error, $object->errors, 'errors');
137  $action="create";
138  }
139  }
140 
141  $action='create';
142 }
143 
144 if ($action == 'delete')
145 {
146  $result=$object->fetch($id);
147 
148  if ($object->rappro == 0)
149  {
150  $db->begin();
151 
152  $ret=$object->delete($user);
153  if ($ret > 0)
154  {
155  if ($object->fk_bank)
156  {
157  $accountline=new AccountLine($db);
158  $result=$accountline->fetch($object->fk_bank);
159  if ($result > 0) $result=$accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
160  }
161 
162  if ($result >= 0)
163  {
164  $db->commit();
165  header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php');
166  exit;
167  }
168  else
169  {
170  $object->error=$accountline->error;
171  $db->rollback();
172  setEventMessages($object->error, $object->errors, 'errors');
173  }
174  }
175  else
176  {
177  $db->rollback();
178  setEventMessages($object->error, $object->errors, 'errors');
179  }
180  }
181  else
182  {
183  $mesg='Error try do delete a line linked to a conciliated bank transaction';
184  setEventMessages($mesg, null, 'errors');
185  }
186 }
187 
188 
189 /*
190  * View
191  */
192 
193 $form = new Form($db);
194 
195 $title=$langs->trans("VAT") . " - " . $langs->trans("Card");
196 $help_url='';
197 llxHeader("",$title,$helpurl);
198 
199 
200 if ($id)
201 {
202  $result = $object->fetch($id);
203  if ($result <= 0)
204  {
205  dol_print_error($db);
206  exit;
207  }
208 }
209 
210 // Formulaire saisie tva
211 if ($action == 'create')
212 {
213  print load_fiche_titre($langs->trans("VAT") . ' - ' . $langs->trans("New"));
214 
215  if (! empty($conf->use_javascript_ajax))
216  {
217  print "\n".'<script type="text/javascript" language="javascript">';
218  print '$(document).ready(function () {
219  $("#radiopayment").click(function() {
220  $("#label").val($(this).data("label"));
221 
222  });
223  $("#radiorefund").click(function() {
224  $("#label").val($(this).data("label"));
225 
226  });
227  });';
228  print '</script>'."\n";
229  }
230 
231  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formvat" method="post">';
232  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
233  print '<input type="hidden" name="action" value="add">';
234 
235  print '<div id="selectmethod">';
236  print '<div class="hideonsmartphone float">';
237  print $langs->trans("Type").':&nbsp;&nbsp;&nbsp;';
238  print '</div>';
239  print '<label for="radiopayment">';
240  print '<input type="radio" id="radiopayment" data-label="'.$langs->trans('VATPayment').'" class="flat" name="refund" value="0"'.($refund?'':' checked="checked"').'>';
241  print '&nbsp;';
242  print $langs->trans("Payment");
243  print '</label>';
244  print '&nbsp;&nbsp;&nbsp;';
245  print '<label for="radiorefund">';
246  print '<input type="radio" id="radiorefund" data-label="'.$langs->trans('VATRefund').'" class="flat" name="refund" value="1"'.($refund?' checked="checked"':'').'>';
247  print '&nbsp;';
248  print $langs->trans("Refund");
249  print '</label>';
250  print '</div>';
251  print "<br>\n";
252 
253  dol_fiche_head();
254 
255  print '<table class="border" width="100%">';
256 
257  print "<tr>";
258  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
259  print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
260  print '</td></tr>';
261 
262  print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
263  print $form->selectDate($datev, "datev", '', '', '', 'add', 1, 1);
264  print '</td></tr>';
265 
266  // Label
267  if ($refund == 1) {
268  $label = $langs->trans("VATRefund");
269  } else {
270  $label = $langs->trans("VATPayment");
271  }
272  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input class="minwidth300" name="label" id="label" value="'.($_POST["label"]?GETPOST("label",'',2):$label).'"></td></tr>';
273 
274  // Amount
275  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount","alpha").'"></td></tr>';
276 
277  if (! empty($conf->banque->enabled))
278  {
279  print '<tr><td class="fieldrequired">'.$langs->trans("BankAccount").'</td><td>';
280  $form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Affiche liste des comptes courant
281  print '</td></tr>';
282  }
283 
284  // Type payment
285  print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
286  $form->select_types_paiements(GETPOST("type_payment"), "type_payment");
287  print "</td>\n";
288  print "</tr>";
289 
290  // Number
291  print '<tr><td>'.$langs->trans('Numero');
292  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
293  print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
294 
295  // Other attributes
296  $parameters=array();
297  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
298  print $hookmanager->resPrint;
299 
300  print '</table>';
301 
302  dol_fiche_end();
303 
304  print '<div class="center">';
305  print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
306  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
307  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
308  print '</div>';
309 
310  print '</form>';
311 }
312 
313 // View mode
314 if ($id)
315 {
316  $head=vat_prepare_head($object);
317 
318  dol_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment');
319 
320  $morehtmlref='<div class="refidno">';
321  // Label of social contribution
322  $morehtmlref.=$form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
323  $morehtmlref.=$form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
324  // Project
325  $morehtmlref.='</div>';
326 
327  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
328 
329  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
330 
331  print '<div class="fichecenter">';
332  print '<div class="underbanner clearboth"></div>';
333 
334  print '<table class="border" width="100%">';
335 
336  // Label
337  //print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
338 
339  print "<tr>";
340  print '<td class="titlefield">'.$langs->trans("DatePayment").'</td><td>';
341  print dol_print_date($object->datep,'day');
342  print '</td></tr>';
343 
344  print '<tr><td>';
345  print $form->editfieldkey($form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")), 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
346  print '</td><td>';
347  print $form->editfieldval("PeriodEndDate", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
348  //print dol_print_date($object->datev,'day');
349  print '</td></tr>';
350 
351  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
352 
353  if (! empty($conf->banque->enabled))
354  {
355  if ($object->fk_account > 0)
356  {
357  $bankline=new AccountLine($db);
358  $bankline->fetch($object->fk_bank);
359 
360  print '<tr>';
361  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
362  print '<td>';
363  print $bankline->getNomUrl(1,0,'showall');
364  print '</td>';
365  print '</tr>';
366  }
367  }
368 
369  // Other attributes
370  $parameters=array();
371  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
372  print $hookmanager->resPrint;
373 
374  print '</table>';
375 
376  print '</div>';
377 
378  dol_fiche_end();
379 
380  /*
381  * Action buttons
382  */
383  print "<div class=\"tabsAction\">\n";
384  if ($object->rappro == 0)
385  {
386  if (! empty($user->rights->tax->charges->supprimer))
387  {
388  print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>';
389  }
390  else
391  {
392  print '<a class="butActionRefused" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a>';
393  }
394  }
395  else
396  {
397  print '<a class="butActionRefused" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a>';
398  }
399  print "</div>";
400 }
401 
402 llxFooter();
403 $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.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Class to manage bank transaction lines.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Put here description of your class.
Definition: tva.class.php:35
Class to manage generation of HTML components Only common components must be here.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
vat_prepare_head($object)
Prepare array with list of tabs.
Definition: vat.lib.php:32
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
$parameters
Actions.
Definition: card.php:114