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