dolibarr  13.0.2
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@open-dsi.fr>
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 <https://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 $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int'));
42 $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int'));
43 
44 
45 // Security check
46 $socid = GETPOST('socid', 'int');
47 if ($user->socid) $socid = $user->socid;
48 $result = restrictedArea($user, 'tax', '', '', 'charges');
49 
50 $object = new Tva($db);
51 
52 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
53 $hookmanager->initHooks(array('taxvatcard', 'globalcard'));
54 
55 
60 if ($_POST["cancel"] == $langs->trans("Cancel") && !$id)
61 {
62  header("Location: list.php");
63  exit;
64 }
65 
66 if ($action == 'setlib' && $user->rights->tax->charges->creer)
67 {
68  $object->fetch($id);
69  $result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', '', 'text', '', $user, 'TAX_MODIFY');
70  if ($result < 0)
71  setEventMessages($object->error, $object->errors, 'errors');
72 }
73 
74 if ($action == 'setdatev' && $user->rights->tax->charges->creer)
75 {
76  $object->fetch($id);
77  $object->datev = $datev;
78  $result = $object->update($user);
79  if ($result < 0) dol_print_error($db, $object->error);
80 
81  $action = '';
82 }
83 
84 if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
85 {
86  $error = 0;
87 
88  $object->accountid = GETPOST("accountid", 'int');
89  $object->type_payment = GETPOST("type_payment", 'alphanohtml');
90  $object->num_payment = GETPOST("num_payment", 'alphanohtml');
91 
92  $object->datev = $datev;
93  $object->datep = $datep;
94 
95  $amount = price2num(GETPOST("amount", 'alpha'));
96  if ($refund == 1) {
97  $amount = -$amount;
98  }
99  $object->amount = $amount;
100  $object->label = GETPOST("label", 'alpha');
101  $object->note_private = GETPOST("note", 'restricthtml');
102 
103  if (empty($object->datep))
104  {
105  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
106  $error++;
107  }
108  if (empty($object->datev))
109  {
110  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors');
111  $error++;
112  }
113  if (empty($object->type_payment) || $object->type_payment < 0)
114  {
115  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
116  $error++;
117  }
118  if (empty($object->amount))
119  {
120  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
121  $error++;
122  }
123 
124  if (!$error)
125  {
126  $db->begin();
127 
128  $ret = $object->addPayment($user);
129  if ($ret > 0)
130  {
131  $db->commit();
132  header("Location: list.php");
133  exit;
134  } else {
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  } else {
168  $object->error = $accountline->error;
169  $db->rollback();
170  setEventMessages($object->error, $object->errors, 'errors');
171  }
172  } else {
173  $db->rollback();
174  setEventMessages($object->error, $object->errors, 'errors');
175  }
176  } else {
177  $mesg = 'Error try do delete a line linked to a conciliated bank transaction';
178  setEventMessages($mesg, null, 'errors');
179  }
180 }
181 
182 
183 /*
184  * View
185  */
186 
187 $form = new Form($db);
188 
189 $title = $langs->trans("VAT")." - ".$langs->trans("Card");
190 $help_url = '';
191 llxHeader("", $title, $helpurl);
192 
193 
194 if ($id)
195 {
196  $result = $object->fetch($id);
197  if ($result <= 0)
198  {
199  dol_print_error($db);
200  exit;
201  }
202 }
203 
204 // Form to enter VAT
205 if ($action == 'create')
206 {
207  print load_fiche_titre($langs->trans("VAT").' - '.$langs->trans("New"));
208 
209  if (!empty($conf->use_javascript_ajax))
210  {
211  print "\n".'<script type="text/javascript" language="javascript">';
212  print '$(document).ready(function () {
213  $("#radiopayment").click(function() {
214  $("#label").val($(this).data("label"));
215 
216  });
217  $("#radiorefund").click(function() {
218  $("#label").val($(this).data("label"));
219 
220  });
221  });';
222  print '</script>'."\n";
223  }
224 
225  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formvat" method="post">';
226  print '<input type="hidden" name="token" value="'.newToken().'">';
227  print '<input type="hidden" name="action" value="add">';
228 
229  print '<div id="selectmethod">';
230  print '<div class="hideonsmartphone float">';
231  print $langs->trans("Type").':&nbsp;&nbsp;&nbsp;';
232  print '</div>';
233  print '<label for="radiopayment">';
234  print '<input type="radio" id="radiopayment" data-label="'.$langs->trans('VATPayment').'" class="flat" name="refund" value="0"'.($refund ? '' : ' checked="checked"').'>';
235  print '&nbsp;';
236  print $langs->trans("Payment");
237  print '</label>';
238  print '&nbsp;&nbsp;&nbsp;';
239  print '<label for="radiorefund">';
240  print '<input type="radio" id="radiorefund" data-label="'.$langs->trans('VATRefund').'" class="flat" name="refund" value="1"'.($refund ? ' checked="checked"' : '').'>';
241  print '&nbsp;';
242  print $langs->trans("PaymentBack");
243  print '</label>';
244  print '</div>';
245  print "<br>\n";
246 
248 
249  print '<table class="border centpercent">';
250 
251  print "<tr>";
252  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
253  print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
254  print '</td></tr>';
255 
256  print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
257  print $form->selectDate((GETPOST("datevmonth", 'int') ? $datev : -1), "datev", '', '', '', 'add', 1, 1);
258  print '</td></tr>';
259 
260  // Label
261  if ($refund == 1) {
262  $label = $langs->trans("VATRefund");
263  } else {
264  $label = $langs->trans("VATPayment");
265  }
266  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>';
267 
268  // Amount
269  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount", "alpha").'"></td></tr>';
270 
271  if (!empty($conf->banque->enabled))
272  {
273  print '<tr><td class="fieldrequired">'.$langs->trans("BankAccount").'</td><td>';
274  $form->select_comptes(GETPOST("accountid", 'int'), "accountid", 0, "courant=1", 2); // List of bank account available
275  print '</td></tr>';
276  }
277 
278  // Type payment
279  print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
280  $form->select_types_paiements(GETPOST("type_payment"), "type_payment");
281  print "</td>\n";
282  print "</tr>";
283 
284  // Number
285  print '<tr><td>'.$langs->trans('Numero');
286  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
287  print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
288 
289  // Other attributes
290  $parameters = array();
291  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
292  print $hookmanager->resPrint;
293 
294  print '</table>';
295 
297 
298  print '<div class="center">';
299  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
300  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
301  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
302  print '</div>';
303 
304  print '</form>';
305 }
306 
307 // View mode
308 if ($id)
309 {
310  $head = vat_prepare_head($object);
311 
312  print dol_get_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment');
313 
314  $morehtmlref = '<div class="refidno">';
315  // Label of social contribution
316  $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
317  $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
318  // Project
319  $morehtmlref .= '</div>';
320 
321  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
322 
323  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
324 
325  print '<div class="fichecenter">';
326  print '<div class="underbanner clearboth"></div>';
327 
328  print '<table class="border centpercent">';
329 
330  // Label
331  //print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
332 
333  print "<tr>";
334  print '<td class="titlefield">'.$langs->trans("DatePayment").'</td><td>';
335  print dol_print_date($object->datep, 'day');
336  print '</td></tr>';
337 
338  print '<tr><td>';
339  print $form->editfieldkey($form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")), 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
340  print '</td><td>';
341  print $form->editfieldval("PeriodEndDate", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
342  //print dol_print_date($object->datev,'day');
343  print '</td></tr>';
344 
345  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
346 
347  if (!empty($conf->banque->enabled))
348  {
349  if ($object->fk_account > 0)
350  {
351  $bankline = new AccountLine($db);
352  $bankline->fetch($object->fk_bank);
353 
354  print '<tr>';
355  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
356  print '<td>';
357  print $bankline->getNomUrl(1, 0, 'showall');
358  print '</td>';
359  print '</tr>';
360  }
361  }
362 
363  // Other attributes
364  $parameters = array();
365  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
366  print $hookmanager->resPrint;
367 
368  print '</table>';
369 
370  print '</div>';
371 
373 
374  /*
375  * Action buttons
376  */
377  print "<div class=\"tabsAction\">\n";
378  if ($object->rappro == 0)
379  {
380  if (!empty($user->rights->tax->charges->supprimer))
381  {
382  print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
383  } else {
384  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a></div>';
385  }
386  } else {
387  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a></div>';
388  }
389  print "</div>";
390 }
391 
392 llxFooter();
393 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage bank transaction lines.
Put here description of your class.
Definition: tva.class.php:34
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
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.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $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
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59