dolibarr  16.0.1
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  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
37 
38 if (isModEnabled('accounting')) {
39  include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
40 }
41 
42 // Load translation files required by the page
43 $langs->loadLangs(array('compta', 'banks', 'bills'));
44 
45 $id = GETPOST("id", 'int');
46 $ref = GETPOST('ref', 'alpha');
47 $action = GETPOST("action", "aZ09");
48 $confirm = GETPOST('confirm', 'alpha');
49 $cancel = GETPOST('cancel', 'aZ09');
50 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search
51 $backtopage = GETPOST('backtopage', 'alpha');
52 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
53 
54 $refund = GETPOST("refund", "int");
55 if (GETPOSTISSET('auto_create_paiement') || $action === 'add') {
56  $auto_create_payment = GETPOST("auto_create_paiement", "int");
57 } else {
58  $auto_create_payment = empty($conf->global->CREATE_NEW_VAT_WITHOUT_AUTO_PAYMENT);
59 }
60 
61 if (empty($refund)) {
62  $refund = 0;
63 }
64 
65 $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int'));
66 $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int'));
67 
68 // Initialize technical objects
69 $object = new Tva($db);
70 $extrafields = new ExtraFields($db);
71 $diroutputmassaction = $conf->tax->dir_output.'/temp/massgeneration/'.$user->id;
72 $hookmanager->initHooks(array('taxvatcard', 'globalcard'));
73 
74 // Fetch optionals attributes and labels
75 $extrafields->fetch_name_optionals_label($object->table_element);
76 
77 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
78 
79 // Initialize array of search criterias
80 $search_all = GETPOST("search_all", 'alpha');
81 $search = array();
82 foreach ($object->fields as $key => $val) {
83  if (GETPOST('search_'.$key, 'alpha')) {
84  $search[$key] = GETPOST('search_'.$key, 'alpha');
85  }
86 }
87 
88 if (empty($action) && empty($id) && empty($ref)) {
89  $action = 'view';
90 }
91 
92 // Load object
93 if ($id > 0) {
94  $object->fetch($id);
95 }
96 
97 $permissiontoread = $user->rights->tax->charges->lire;
98 $permissiontoadd = $user->rights->tax->charges->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
99 $permissiontodelete = $user->rights->tax->charges->supprimer || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
100 $permissionnote = $user->rights->tax->charges->creer; // Used by the include of actions_setnotes.inc.php
101 $permissiondellink = $user->rights->tax->charges->creer; // Used by the include of actions_dellink.inc.php
102 $upload_dir = $conf->tax->multidir_output[isset($object->entity) ? $object->entity : 1].'/vat';
103 
104 // Security check
105 $socid = GETPOST('socid', 'int');
106 if ($user->socid) {
107  $socid = $user->socid;
108 }
109 $result = restrictedArea($user, 'tax', '', 'tva', 'charges');
110 
111 
112 /*
113  * Actions
114  */
115 
116 $parameters = array();
117 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
118 if ($reshook < 0) {
119  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
120 }
121 
122 if ($cancel && !$id) {
123  header("Location: list.php");
124  exit;
125 }
126 
127 if ($action == 'setlib' && $user->rights->tax->charges->creer) {
128  $object->fetch($id);
129  $result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', '', 'text', '', $user, 'TAX_MODIFY');
130  if ($result < 0) {
131  setEventMessages($object->error, $object->errors, 'errors');
132  }
133 }
134 
135 if ($action == 'setdatev' && $user->rights->tax->charges->creer) {
136  $object->fetch($id);
137  $object->datev = $datev;
138  $result = $object->update($user);
139  if ($result < 0) {
140  dol_print_error($db, $object->error);
141  }
142 
143  $action = '';
144 }
145 
146 // payment mode
147 if ($action == 'setmode' && $user->rights->tax->charges->creer) {
148  $object->fetch($id);
149  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
150  if ($result < 0) {
151  setEventMessages($object->error, $object->errors, 'errors');
152  }
153 }
154 
155 // Bank account
156 if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) {
157  $object->fetch($id);
158  $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
159  if ($result < 0) {
160  setEventMessages($object->error, $object->errors, 'errors');
161  }
162 }
163 
164 // Classify paid
165 if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') {
166  $object->fetch($id);
167  $result = $object->setPaid($user);
168 }
169 
170 if ($action == 'reopen' && $user->rights->tax->charges->creer) {
171  $result = $object->fetch($id);
172  if ($object->paye) {
173  $result = $object->setUnpaid($user);
174  if ($result > 0) {
175  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
176  exit();
177  } else {
178  setEventMessages($object->error, $object->errors, 'errors');
179  }
180  }
181 }
182 
183 if ($action == 'add' && !$cancel) {
184  $error = 0;
185 
186  $object->fk_account = GETPOST("accountid", 'int');
187  $object->type_payment = GETPOST("type_payment", 'alphanohtml');
188  $object->num_payment = GETPOST("num_payment", 'alphanohtml');
189 
190  $object->datev = $datev;
191  $object->datep = $datep;
192 
193  $amount = price2num(GETPOST("amount", 'alpha'));
194  if ($refund == 1) {
195  $amount = -$amount;
196  }
197  $object->amount = $amount;
198  $object->label = GETPOST("label", 'alpha');
199  $object->note = GETPOST("note", 'restricthtml');
200  $object->note_private = GETPOST("note", 'restricthtml');
201 
202  if (empty($object->datep)) {
203  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
204  $error++;
205  }
206  if (empty($object->datev)) {
207  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors');
208  $error++;
209  }
210  if (!empty($auto_create_payment) && (empty($object->type_payment) || $object->type_payment < 0)) {
211  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
212  $error++;
213  }
214  if (empty($object->amount)) {
215  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
216  $error++;
217  }
218  if (!empty($auto_create_payment) && ($object->fk_account <= 0)) {
219  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountToCredit")), null, 'errors');
220  $error++;
221  }
222 
223  if (!$error) {
224  $ret = $object->create($user);
225  if ($ret < 0) {
226  $error++;
227  }
228 
229  // Auto create payment
230  if (!empty($auto_create_payment) && !$error) {
231  $db->begin();
232 
233  // Create a line of payments
234  $paiement = new PaymentVAT($db);
235  $paiement->chid = $object->id;
236  $paiement->datepaye = $datep;
237  $paiement->amounts = array($object->id=>$amount); // Tableau de montant
238  $paiement->paiementtype = GETPOST("type_payment", 'alphanohtml');
239  $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
240  $paiement->note = GETPOST("note", 'restricthtml');
241 
242  if (!$error) {
243  $paymentid = $paiement->create($user, (int) GETPOST('closepaidtva'));
244  if ($paymentid < 0) {
245  $error++;
246  setEventMessages($paiement->error, null, 'errors');
247  $action = 'create';
248  }
249  }
250 
251  if (!$error) {
252  $result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOST('accountid', 'int'), '', '');
253  if (!($result > 0)) {
254  $error++;
255  setEventMessages($paiement->error, null, 'errors');
256  }
257  }
258 
259  if (!$error) {
260  $db->commit();
261  } else {
262  $db->rollback();
263  }
264  }
265  if (empty($error)) {
266  header("Location: card.php?id=" . $object->id);
267  exit;
268  }
269  }
270 
271  $action = 'create';
272 }
273 
274 if ($action == 'confirm_delete' && $confirm == 'yes') {
275  $result = $object->fetch($id);
276  $totalpaid = $object->getSommePaiement();
277 
278  if (empty($totalpaid)) {
279  $db->begin();
280 
281  $ret = $object->delete($user);
282  if ($ret > 0) {
283  if ($object->fk_bank) {
284  $accountline = new AccountLine($db);
285  $result = $accountline->fetch($object->fk_bank);
286  if ($result > 0) {
287  $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
288  }
289  }
290 
291  if ($result >= 0) {
292  $db->commit();
293  header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php');
294  exit;
295  } else {
296  $object->error = $accountline->error;
297  $db->rollback();
298  setEventMessages($object->error, $object->errors, 'errors');
299  }
300  } else {
301  $db->rollback();
302  setEventMessages($object->error, $object->errors, 'errors');
303  }
304  } else {
305  setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
306  }
307 }
308 
309 if ($action == 'update' && !GETPOST("cancel") && $user->rights->tax->charges->creer) {
310  $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
311 
312  if (empty($amount)) {
313  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
314  $action = 'edit';
315  } elseif (!is_numeric($amount)) {
316  setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
317  $action = 'create';
318  } else {
319  $result = $object->fetch($id);
320 
321  $object->amount = $amount;
322 
323  $result = $object->update($user);
324  if ($result <= 0) {
325  setEventMessages($object->error, $object->errors, 'errors');
326  }
327  }
328 }
329 
330 // Action clone object
331 if ($action == 'confirm_clone' && $confirm != 'yes') {
332  $action = '';
333 }
334 
335 if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) {
336  $db->begin();
337 
338  $originalId = $id;
339 
340  $object->fetch($id);
341 
342  if ($object->id > 0) {
343  $object->id = $object->ref = null;
344  $object->paye = 0;
345 
346  if (GETPOST('clone_label', 'alphanohtml')) {
347  $object->label = GETPOST('clone_label', 'alphanohtml');
348  } else {
349  $object->label = $langs->trans("CopyOf").' '.$object->label;
350  }
351 
352  $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int'));
353  if ($newdateperiod) {
354  $object->datev = $newdateperiod;
355  }
356 
357  //if ($object->check()) {
358  $id = $object->create($user);
359  if ($id > 0) {
360  $db->commit();
361  $db->close();
362 
363  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
364  exit;
365  } else {
366  $id = $originalId;
367  $db->rollback();
368 
369  setEventMessages($object->error, $object->errors, 'errors');
370  }
371  //}
372  } else {
373  $db->rollback();
374  dol_print_error($db, $object->error);
375  }
376 }
377 
378 
379 /*
380  * View
381  */
382 
383 $form = new Form($db);
384 $formfile = new FormFile($db);
385 $formproject = new FormProjets($db);
386 
387 $title = $langs->trans("VAT")." - ".$langs->trans("Card");
388 $help_url = '';
389 llxHeader('', $title, $help_url);
390 
391 
392 if ($id) {
393  $result = $object->fetch($id);
394  if ($result <= 0) {
395  dol_print_error($db);
396  exit;
397  }
398 }
399 
400 // Form to enter VAT
401 if ($action == 'create') {
402  print load_fiche_titre($langs->trans("VAT").' - '.$langs->trans("New"));
403 
404  if (!empty($conf->use_javascript_ajax)) {
405  print "\n".'<script type="text/javascript">';
406  print '
407  $(document).ready(function () {
408  let onAutoCreatePaiementChange = function () {
409  if($("#auto_create_paiement").is(":checked")) {
410  $("#label_fk_account").addClass("fieldrequired");
411  $("#label_type_payment").addClass("fieldrequired");
412  $(".hide_if_no_auto_create_payment").show();
413  } else {
414  $("#label_fk_account").removeClass("fieldrequired");
415  $("#label_type_payment").removeClass("fieldrequired");
416  $(".hide_if_no_auto_create_payment").hide();
417  }
418  };
419  $("#radiopayment").click(function() {
420  $("#label").val($(this).data("label"));
421  });
422  $("#radiorefund").click(function() {
423  $("#label").val($(this).data("label"));
424 
425  });
426  $("#auto_create_paiement").click(function () {
427  onAutoCreatePaiementChange();
428  });
429  onAutoCreatePaiementChange();
430  });
431  ';
432 
433  print '</script>'."\n";
434  }
435 
436  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formvat" method="post">';
437  print '<input type="hidden" name="token" value="'.newToken().'">';
438  print '<input type="hidden" name="action" value="add">';
439 
440  print dol_get_fiche_head();
441 
442  print '<table class="border centpercent">';
443 
444  print '<tr><td class="titlefieldcreate fieldrequired">';
445  //print $langs->trans("Type");
446  print '</td><td>';
447 
448  print '<div id="selectmethod">';
449  print '<label for="radiopayment">';
450  print '<input type="radio" id="radiopayment" data-label="'.$langs->trans('VATPayment').'" class="flat" name="refund" value="0"'.($refund ? '' : ' checked="checked"').'>';
451  print '&nbsp;';
452  print $langs->trans("Payment");
453  print '</label>';
454  print '&nbsp;&nbsp;&nbsp;';
455  print '<label for="radiorefund">';
456  print '<input type="radio" id="radiorefund" data-label="'.$langs->trans('VATRefund').'" class="flat" name="refund" value="1"'.($refund ? ' checked="checked"' : '').'>';
457  print '&nbsp;';
458  print $langs->trans("Refund");
459  print '</label>';
460  print '</div>';
461 
462  print '</td>';
463  print "</tr>\n";
464 
465  // Label
466  if ($refund == 1) {
467  $label = $langs->trans("VATRefund");
468  } else {
469  $label = $langs->trans("VATPayment");
470  }
471  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input class="minwidth300" name="label" id="label" value="'.(GETPOSTISSET("label") ? GETPOST("label", '', 2) : $label).'" autofocus></td></tr>';
472 
473  print '<tr><td class="titlefieldcreate fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
474  print $form->selectDate((GETPOST("datevmonth", 'int') ? $datev : -1), "datev", '', '', '', 'add', 1, 1);
475  print '</td></tr>';
476 
477  // Amount
478  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" class="right width75" value="'.GETPOST("amount", "alpha").'"></td></tr>';
479 
480  print '<tr><td colspan="2"><hr></td></tr>';
481 
482  // Auto create payment
483  print '<tr><td><label for="auto_create_paiement">'.$langs->trans('AutomaticCreationPayment').'</label></td>';
484  print '<td><input id="auto_create_paiement" name="auto_create_paiement" type="checkbox" ' . (empty($auto_create_payment) ? '' : 'checked="checked"') . ' value="1"></td></tr>'."\n";
485 
486  print '<tr class="hide_if_no_auto_create_payment">';
487  print '<td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
488  print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
489  print '</td></tr>';
490 
491  // Type payment
492  print '<tr><td class="fieldrequired" id="label_type_payment">'.$langs->trans("PaymentMode").'</td><td>';
493  $form->select_types_paiements(GETPOST("type_payment", 'int'), "type_payment", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx');
494  print "</td>\n";
495  print "</tr>";
496 
497  if (isModEnabled('banque')) {
498  // Bank account
499  print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("BankAccount").'</td><td>';
500  print img_picto('', 'bank_account', 'pictofixedwidth');
501  $form->select_comptes(GETPOST("accountid", 'int'), "accountid", 0, "courant=1", 1, '', 0, 'maxwidth500 widthcentpercentminusx'); // List of bank account available
502  print '</td></tr>';
503  }
504 
505  // Number
506  print '<tr class="hide_if_no_auto_create_payment"><td>'.$langs->trans('Numero');
507  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
508  print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
509 
510  // Comments
511  print '<tr class="hide_if_no_auto_create_payment">';
512  print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
513  print '<td class="tdtop"><textarea name="note" wrap="soft" rows="'.ROWS_3.'" class="quatrevingtpercent">'.GETPOST('note', 'restricthtml').'</textarea></td>';
514  print '</tr>';
515 
516  // Other attributes
517  $parameters = array();
518  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
519  print $hookmanager->resPrint;
520 
521  print '</table>';
522 
523  print dol_get_fiche_end();
524 
525  print '<div class="center">';
526  print '<div class="hide_if_no_auto_create_payment paddingbottom">';
527  print '<input type="checkbox" checked value="1" name="closepaidtva"> <span class="">'.$langs->trans("ClosePaidVATAutomatically").'</span>';
528  print '<br>';
529  print '</div>';
530 
531  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
532  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
533  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
534  print '</div>';
535 
536  print '</form>';
537 }
538 
539 // View mode
540 if ($id > 0) {
541  $head = vat_prepare_head($object);
542 
543  $totalpaid = $object->getSommePaiement();
544 
545  // Clone confirmation
546  if ($action === 'clone') {
547  $formquestion = array(
548  array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
549  );
550 
551  //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
552  $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
553 
554  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVAT', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240);
555  }
556 
557  if ($action == 'paid') {
558  $text = $langs->trans('ConfirmPayVAT');
559  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayVAT'), $text, "confirm_paid", '', '', 2);
560  }
561 
562  if ($action == 'delete') {
563  $text = $langs->trans('ConfirmDeleteVAT');
564  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVAT'), $text, 'confirm_delete', '', '', 2);
565  }
566 
567  if ($action == 'edit') {
568  print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
569  print '<input type="hidden" name="token" value="'.newToken().'">';
570  }
571 
572  print dol_get_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment');
573 
574  $morehtmlref = '<div class="refidno">';
575  // Label of social contribution
576  $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
577  $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
578  // Project
579  $morehtmlref .= '</div>';
580 
581  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
582 
583  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
584 
585  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
586 
587  print '<div class="fichecenter">';
588  print '<div class="fichehalfleft">';
589  print '<div class="underbanner clearboth"></div>';
590 
591  print '<table class="border centpercent">';
592 
593  // Label
594  //print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
595 
596  /*print "<tr>";
597  print '<td class="titlefield">'.$langs->trans("DatePayment").'</td><td>';
598  print dol_print_date($object->datep, 'day');
599  print '</td></tr>';*/
600 
601  print '<tr><td>';
602  print $form->editfieldkey($form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")), 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
603  print '</td><td>';
604  print $form->editfieldval("PeriodEndDate", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
605  //print dol_print_date($object->datev,'day');
606  print '</td></tr>';
607 
608  if ($action == 'edit') {
609  print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
610  } else {
611  print '<tr><td>' . $langs->trans("Amount") . '</td><td>' . price($object->amount) . '</td></tr>';
612  }
613 
614  // Mode of payment
615  print '<tr><td>';
616  print '<table class="nobordernopadding" width="100%"><tr><td>';
617  print $langs->trans('PaymentMode');
618  print '</td>';
619  if ($action != 'editmode') {
620  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
621  }
622  print '</tr></table>';
623  print '</td><td>';
624  if ($action == 'editmode') {
625  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
626  } else {
627  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
628  }
629  print '</td></tr>';
630 
631  // Bank account
632  if (isModEnabled('banque')) {
633  print '<tr><td class="nowrap">';
634  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
635  print $langs->trans('BankAccount');
636  print '<td>';
637  if ($action != 'editbankaccount' && $user->rights->tax->charges->creer) {
638  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
639  }
640  print '</tr></table>';
641  print '</td><td>';
642  if ($action == 'editbankaccount') {
643  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
644  } else {
645  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
646  }
647  print '</td>';
648  print '</tr>';
649  }
650 
651  // Other attributes
652  $parameters = array();
653  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
654  print $hookmanager->resPrint;
655 
656  print '</table>';
657 
658  print '</div>';
659 
660  print '<div class="fichehalfright">';
661 
662  $nbcols = 3;
663  if (isModEnabled('banque')) {
664  $nbcols++;
665  }
666 
667  /*
668  * Payments
669  */
670  $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,";
671  $sql .= " c.code as type_code,c.libelle as paiement_type,";
672  $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.currency_code as bacurrency_code, ba.fk_accountancy_journal';
673  $sql .= " FROM ".MAIN_DB_PREFIX."payment_vat as p";
674  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
675  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
676  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
677  $sql .= ", ".MAIN_DB_PREFIX."tva as tva";
678  $sql .= " WHERE p.fk_tva = ".((int) $id);
679  $sql .= " AND p.fk_tva = tva.rowid";
680  $sql .= " AND tva.entity IN (".getEntity('tax').")";
681  $sql .= " ORDER BY dp DESC";
682 
683  //print $sql;
684  $resql = $db->query($sql);
685  if ($resql) {
686  $totalpaid = 0;
687 
688  $num = $db->num_rows($resql);
689  $i = 0;
690  $total = 0;
691 
692  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
693  print '<table class="noborder paymenttable">';
694  print '<tr class="liste_titre">';
695  print '<td>'.$langs->trans("RefPayment").'</td>';
696  print '<td>'.$langs->trans("Date").'</td>';
697  print '<td>'.$langs->trans("Type").'</td>';
698  if (isModEnabled('banque')) {
699  print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
700  }
701  print '<td class="right">'.$langs->trans("Amount").'</td>';
702  print '</tr>';
703 
704  if ($num > 0) {
705  $bankaccountstatic = new Account($db);
706  while ($i < $num) {
707  $objp = $db->fetch_object($resql);
708 
709  print '<tr class="oddeven"><td>';
710  print '<a href="'.DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a>';
711  print '</td>';
712  print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
713  $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
714  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
715  if (isModEnabled('banque')) {
716  $bankaccountstatic->id = $objp->baid;
717  $bankaccountstatic->ref = $objp->baref;
718  $bankaccountstatic->label = $objp->baref;
719  $bankaccountstatic->number = $objp->banumber;
720  $bankaccountstatic->currency_code = $objp->bacurrency_code;
721 
722  if (isModEnabled('accounting')) {
723  $bankaccountstatic->account_number = $objp->account_number;
724 
725  $accountingjournal = new AccountingJournal($db);
726  $accountingjournal->fetch($objp->fk_accountancy_journal);
727  $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
728  }
729 
730  print '<td class="right">';
731  if ($bankaccountstatic->id) {
732  print $bankaccountstatic->getNomUrl(1, 'transactions');
733  }
734  print '</td>';
735  }
736  print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
737  print "</tr>";
738  $totalpaid += $objp->amount;
739  $i++;
740  }
741  } else {
742  print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
743  print '<td></td><td></td><td></td><td></td>';
744  print '</tr>';
745  }
746 
747  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid")." :</td><td class=\"right\">".price($totalpaid)."</td></tr>\n";
748  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected")." :</td><td class=\"right\">".price($object->amount)."</td></tr>\n";
749 
750  $resteapayer = $object->amount - $totalpaid;
751  $cssforamountpaymentcomplete = 'amountpaymentcomplete';
752 
753  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
754  print '<td class="right'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
755 
756  print "</table>";
757  print '</div>';
758 
759  $db->free($resql);
760  } else {
761  dol_print_error($db);
762  }
763 
764  print '</div>';
765  print '</div>';
766 
767  print '<div class="clearboth"></div>';
768 
769  print dol_get_fiche_end();
770 
771  if ($action == 'edit') {
772  print $form->buttonsSaveCancel();
773 
774  print "</form>\n";
775  }
776 
777 
778  // Buttons for actions
779 
780  print '<div class="tabsAction">'."\n";
781 
782  if ($action != 'edit') {
783  // Reopen
784  if ($object->paye && $user->rights->tax->charges->creer) {
785  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen")."</a></div>";
786  }
787 
788  // Edit
789  if ($object->paye == 0 && $user->rights->tax->charges->creer) {
790  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify")."</a></div>";
791  }
792 
793  // Emit payment
794  if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->rights->tax->charges->creer) {
795  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/paiement_vat.php?id='.$object->id.'&action=create&token='.newToken().'">'.$langs->trans("DoPayment").'</a></div>';
796  }
797 
798  // Classify 'paid'
799  if ($object->paye == 0
800  && (
801  (round($resteapayer) <= 0 && $object->amount > 0)
802  || (round($resteapayer) >= 0 && $object->amount < 0)
803  )
804  && $user->rights->tax->charges->creer) {
805  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&token='.newToken().'&action=paid">'.$langs->trans("ClassifyPaid")."</a></div>";
806  }
807 
808  // Clone
809  if ($user->rights->tax->charges->creer) {
810  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&token='.newToken().'&action=clone">'.$langs->trans("ToClone")."</a></div>";
811  }
812 
813  if (!empty($user->rights->tax->charges->supprimer) && empty($totalpaid)) {
814  print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
815  } else {
816  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("DisabledBecausePayments"))).'">'.$langs->trans("Delete").'</a></div>';
817  }
818  }
819  print '</div>'."\n";
820 
821 
822 
823  // Select mail models is same action as presend
824  if (GETPOST('modelselected')) {
825  $action = 'presend';
826  }
827 
828  if ($action != 'presend') {
829  print '<div class="fichecenter"><div class="fichehalfleft">';
830  print '<a name="builddoc"></a>'; // ancre
831 
832  $includedocgeneration = 1;
833 
834  // Documents
835  if ($includedocgeneration) {
836  $objref = dol_sanitizeFileName($object->ref);
837  $relativepath = $objref.'/'.$objref.'.pdf';
838  $filedir = $conf->tax->dir_output.'/vat/'.$objref;
839  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
840  //$genallowed = $user->rights->tax->charges->lire; // If you can read, you can build the PDF to read content
841  $genallowed = 0;
842  $delallowed = $user->rights->tax->charges->creer; // If you can create/edit, you can remove a file on card
843  print $formfile->showdocuments('tax-vat', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
844  }
845 
846  // Show links to link elements
847  //$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
848  //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
849 
850 
851  print '</div><div class="fichehalfright">';
852 
853  /*
854  $MAXEVENT = 10;
855 
856  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
857 
858  // List of actions on element
859  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
860  $formactions = new FormActions($db);
861  $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
862  */
863 
864  print '</div></div>';
865  }
866 
867  //Select mail models is same action as presend
868  if (GETPOST('modelselected')) {
869  $action = 'presend';
870  }
871 
872  // Presend form
873  $modelmail = 'vat';
874  $defaulttopic = 'InformationMessage';
875  $diroutput = $conf->tax->dir_output;
876  $trackid = 'vat'.$object->id;
877 
878  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
879 }
880 
881 llxFooter();
882 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
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...
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
Class to manage bank transaction lines.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
Definition: agenda.php:116
Class to manage bank accounts.
Put here description of your class.
Definition: tva.class.php:35
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...
Class to manage standard extra fields.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
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;...
Class to manage building of HTML components.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to offer components to list and upload files.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
vat_prepare_head($object)
Prepare array with list of tabs.
Definition: vat.lib.php:33
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.
Class to manage payments of social contributions.
isModEnabled($module)
Is Dolibarr module enabled.
Class to manage accounting accounts.
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:73