dolibarr  18.0.0-alpha
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('amount', 'alphanohtml')) {
337  $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
338  }
339 
340  if (GETPOST('clone_label', 'alphanohtml')) {
341  $object->label = GETPOST('clone_label', 'alphanohtml');
342  } else {
343  $object->label = $langs->trans("CopyOf").' '.$object->label;
344  }
345 
346  $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int'));
347  if ($newdateperiod) {
348  $object->datev = $newdateperiod;
349  }
350 
351  //if ($object->check()) {
352  $id = $object->create($user);
353  if ($id > 0) {
354  $db->commit();
355  $db->close();
356 
357  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
358  exit;
359  } else {
360  $id = $originalId;
361  $db->rollback();
362 
363  setEventMessages($object->error, $object->errors, 'errors');
364  }
365  //}
366  } else {
367  $db->rollback();
368  dol_print_error($db, $object->error);
369  }
370 }
371 
372 
373 /*
374  * View
375  */
376 
377 $form = new Form($db);
378 $formfile = new FormFile($db);
379 $formproject = new FormProjets($db);
380 
381 $title = $langs->trans("VAT")." - ".$langs->trans("Card");
382 $help_url = '';
383 llxHeader('', $title, $help_url);
384 
385 
386 if ($id) {
387  $result = $object->fetch($id);
388  if ($result <= 0) {
389  dol_print_error($db);
390  exit;
391  }
392 }
393 
394 // Form to enter VAT
395 if ($action == 'create') {
396  print load_fiche_titre($langs->trans("VAT").' - '.$langs->trans("New"));
397 
398  if (!empty($conf->use_javascript_ajax)) {
399  print "\n".'<script type="text/javascript">';
400  print '
401  $(document).ready(function () {
402  let onAutoCreatePaiementChange = function () {
403  if($("#auto_create_paiement").is(":checked")) {
404  $("#label_fk_account").addClass("fieldrequired");
405  $("#label_type_payment").addClass("fieldrequired");
406  $(".hide_if_no_auto_create_payment").show();
407  } else {
408  $("#label_fk_account").removeClass("fieldrequired");
409  $("#label_type_payment").removeClass("fieldrequired");
410  $(".hide_if_no_auto_create_payment").hide();
411  }
412  }
413  $("#radiopayment").click(function() {
414  $("#label").val($(this).data("label"));
415  });
416  $("#radiorefund").click(function() {
417  $("#label").val($(this).data("label"));
418 
419  });
420  $("#auto_create_paiement").click(function () {
421  onAutoCreatePaiementChange();
422  });
423  onAutoCreatePaiementChange();
424  });
425  ';
426 
427  print '</script>'."\n";
428  }
429 
430  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formvat" method="post">';
431  print '<input type="hidden" name="token" value="'.newToken().'">';
432  print '<input type="hidden" name="action" value="add">';
433 
434  print dol_get_fiche_head();
435 
436  print '<table class="border centpercent">';
437 
438  print '<tr><td class="titlefieldcreate fieldrequired">';
439  //print $langs->trans("Type");
440  print '</td><td>';
441 
442  print '<div id="selectmethod">';
443  print '<label for="radiopayment">';
444  print '<input type="radio" id="radiopayment" data-label="'.$langs->trans('VATPayment').'" class="flat" name="refund" value="0"'.($refund ? '' : ' checked="checked"').'>';
445  print '&nbsp;';
446  print $langs->trans("Payment");
447  print '</label>';
448  print '&nbsp;&nbsp;&nbsp;';
449  print '<label for="radiorefund">';
450  print '<input type="radio" id="radiorefund" data-label="'.$langs->trans('VATRefund').'" class="flat" name="refund" value="1"'.($refund ? ' checked="checked"' : '').'>';
451  print '&nbsp;';
452  print $langs->trans("Refund");
453  print '</label>';
454  print '</div>';
455 
456  print '</td>';
457  print "</tr>\n";
458 
459  // Label
460  if ($refund == 1) {
461  $label = $langs->trans("VATRefund");
462  } else {
463  $label = $langs->trans("VATPayment");
464  }
465  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>';
466 
467  print '<tr><td class="titlefieldcreate fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
468  print $form->selectDate((GETPOST("datevmonth", 'int') ? $datev : -1), "datev", '', '', '', 'add', 1, 1);
469  print '</td></tr>';
470 
471  // Amount
472  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" class="right width75" value="'.GETPOST("amount", "alpha").'"></td></tr>';
473 
474  print '<tr><td colspan="2"><hr></td></tr>';
475 
476  // Auto create payment
477  print '<tr><td><label for="auto_create_paiement">'.$langs->trans('AutomaticCreationPayment').'</label></td>';
478  print '<td><input id="auto_create_paiement" name="auto_create_paiement" type="checkbox" ' . (empty($auto_create_payment) ? '' : 'checked="checked"') . ' value="1"></td></tr>'."\n";
479 
480  print '<tr class="hide_if_no_auto_create_payment">';
481  print '<td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
482  print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
483  print '</td></tr>';
484 
485  // Type payment
486  print '<tr><td class="fieldrequired" id="label_type_payment">'.$langs->trans("PaymentMode").'</td><td>';
487  print $form->select_types_paiements(GETPOST("type_payment", 'int'), "type_payment", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx', 1);
488  print "</td>\n";
489  print "</tr>";
490 
491  if (isModEnabled("banque")) {
492  // Bank account
493  print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("BankAccount").'</td><td>';
494  print img_picto('', 'bank_account', 'pictofixedwidth');
495  $form->select_comptes(GETPOST("accountid", 'int'), "accountid", 0, "courant=1", 1, '', 0, 'maxwidth500 widthcentpercentminusx'); // List of bank account available
496  print '</td></tr>';
497  }
498 
499  // Number
500  print '<tr class="hide_if_no_auto_create_payment"><td>'.$langs->trans('Numero');
501  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
502  print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
503 
504  // Comments
505  print '<tr class="hide_if_no_auto_create_payment">';
506  print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
507  print '<td class="tdtop"><textarea name="note" wrap="soft" rows="'.ROWS_3.'" class="quatrevingtpercent">'.GETPOST('note', 'restricthtml').'</textarea></td>';
508  print '</tr>';
509 
510  // Other attributes
511  $parameters = array();
512  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
513  print $hookmanager->resPrint;
514 
515  print '</table>';
516 
517  print dol_get_fiche_end();
518 
519  print '<div class="center">';
520  print '<div class="hide_if_no_auto_create_payment paddingbottom">';
521  print '<input type="checkbox" checked value="1" name="closepaidtva"> <span class="">'.$langs->trans("ClosePaidVATAutomatically").'</span>';
522  print '<br>';
523  print '</div>';
524 
525  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
526  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
527  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
528  print '</div>';
529 
530  print '</form>';
531 }
532 
533 // View mode
534 if ($id > 0) {
535  $head = vat_prepare_head($object);
536 
537  $totalpaid = $object->getSommePaiement();
538 
539  // Clone confirmation
540  if ($action === 'clone') {
541  $formquestion = array(
542  array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
543  );
544 
545  //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
546  $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
547  $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100');
548 
549  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVAT', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240);
550  }
551 
552  if ($action == 'paid') {
553  $text = $langs->trans('ConfirmPayVAT');
554  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayVAT'), $text, "confirm_paid", '', '', 2);
555  }
556 
557  if ($action == 'delete') {
558  $text = $langs->trans('ConfirmDeleteVAT');
559  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVAT'), $text, 'confirm_delete', '', '', 2);
560  }
561 
562  if ($action == 'edit') {
563  print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
564  print '<input type="hidden" name="token" value="'.newToken().'">';
565  }
566 
567  print dol_get_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment');
568 
569  $morehtmlref = '<div class="refidno">';
570  // Label of social contribution
571  $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
572  $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
573  // Project
574  $morehtmlref .= '</div>';
575 
576  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
577 
578  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
579 
580  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
581 
582  print '<div class="fichecenter">';
583  print '<div class="fichehalfleft">';
584  print '<div class="underbanner clearboth"></div>';
585 
586  print '<table class="border centpercent">';
587 
588  // Label
589  //print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
590 
591  /*print "<tr>";
592  print '<td class="titlefield">'.$langs->trans("DatePayment").'</td><td>';
593  print dol_print_date($object->datep, 'day');
594  print '</td></tr>';*/
595 
596  print '<tr><td>';
597  print $form->editfieldkey($form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")), 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
598  print '</td><td>';
599  print $form->editfieldval("PeriodEndDate", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
600  //print dol_print_date($object->datev,'day');
601  print '</td></tr>';
602 
603  if ($action == 'edit') {
604  print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
605  } else {
606  print '<tr><td>' . $langs->trans("Amount") . '</td><td>' . price($object->amount) . '</td></tr>';
607  }
608 
609  // Mode of payment
610  print '<tr><td>';
611  print '<table class="nobordernopadding" width="100%"><tr><td>';
612  print $langs->trans('PaymentMode');
613  print '</td>';
614  if ($action != 'editmode') {
615  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>';
616  }
617  print '</tr></table>';
618  print '</td><td>';
619  if ($action == 'editmode') {
620  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
621  } else {
622  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
623  }
624  print '</td></tr>';
625 
626  // Bank account
627  if (isModEnabled("banque")) {
628  print '<tr><td class="nowrap">';
629  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
630  print $langs->trans('BankAccount');
631  print '<td>';
632  if ($action != 'editbankaccount' && $user->rights->tax->charges->creer) {
633  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>';
634  }
635  print '</tr></table>';
636  print '</td><td>';
637  if ($action == 'editbankaccount') {
638  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
639  } else {
640  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
641  }
642  print '</td>';
643  print '</tr>';
644  }
645 
646  // Other attributes
647  $parameters = array();
648  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
649  print $hookmanager->resPrint;
650 
651  print '</table>';
652 
653  print '</div>';
654 
655  print '<div class="fichehalfright">';
656 
657  $nbcols = 3;
658  if (isModEnabled("banque")) {
659  $nbcols++;
660  }
661 
662  /*
663  * Payments
664  */
665  $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,";
666  $sql .= " c.code as type_code,c.libelle as paiement_type,";
667  $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';
668  $sql .= " FROM ".MAIN_DB_PREFIX."payment_vat as p";
669  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
670  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
671  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
672  $sql .= ", ".MAIN_DB_PREFIX."tva as tva";
673  $sql .= " WHERE p.fk_tva = ".((int) $id);
674  $sql .= " AND p.fk_tva = tva.rowid";
675  $sql .= " AND tva.entity IN (".getEntity('tax').")";
676  $sql .= " ORDER BY dp DESC";
677 
678  //print $sql;
679  $resql = $db->query($sql);
680  if ($resql) {
681  $totalpaid = 0;
682 
683  $num = $db->num_rows($resql);
684  $i = 0;
685  $total = 0;
686 
687  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
688  print '<table class="noborder paymenttable">';
689  print '<tr class="liste_titre">';
690  print '<td>'.$langs->trans("RefPayment").'</td>';
691  print '<td>'.$langs->trans("Date").'</td>';
692  print '<td>'.$langs->trans("Type").'</td>';
693  if (isModEnabled("banque")) {
694  print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
695  }
696  print '<td class="right">'.$langs->trans("Amount").'</td>';
697  print '</tr>';
698 
699  if ($num > 0) {
700  $bankaccountstatic = new Account($db);
701  while ($i < $num) {
702  $objp = $db->fetch_object($resql);
703 
704  print '<tr class="oddeven"><td>';
705  print '<a href="'.DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a>';
706  print '</td>';
707  print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
708  $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
709  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
710  if (isModEnabled("banque")) {
711  $bankaccountstatic->id = $objp->baid;
712  $bankaccountstatic->ref = $objp->baref;
713  $bankaccountstatic->label = $objp->baref;
714  $bankaccountstatic->number = $objp->banumber;
715  $bankaccountstatic->currency_code = $objp->bacurrency_code;
716 
717  if (isModEnabled('accounting')) {
718  $bankaccountstatic->account_number = $objp->account_number;
719 
720  $accountingjournal = new AccountingJournal($db);
721  $accountingjournal->fetch($objp->fk_accountancy_journal);
722  $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
723  }
724 
725  print '<td class="right">';
726  if ($bankaccountstatic->id) {
727  print $bankaccountstatic->getNomUrl(1, 'transactions');
728  }
729  print '</td>';
730  }
731  print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
732  print "</tr>";
733  $totalpaid += $objp->amount;
734  $i++;
735  }
736  } else {
737  print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
738  print '<td></td><td></td><td></td><td></td>';
739  print '</tr>';
740  }
741 
742  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid")." :</td><td class=\"right\">".price($totalpaid)."</td></tr>\n";
743  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected")." :</td><td class=\"right\">".price($object->amount)."</td></tr>\n";
744 
745  $resteapayer = $object->amount - $totalpaid;
746  $cssforamountpaymentcomplete = 'amountpaymentcomplete';
747 
748  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
749  print '<td class="right'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
750 
751  print "</table>";
752  print '</div>';
753 
754  $db->free($resql);
755  } else {
756  dol_print_error($db);
757  }
758 
759  print '</div>';
760  print '</div>';
761 
762  print '<div class="clearboth"></div>';
763 
764  print dol_get_fiche_end();
765 
766  if ($action == 'edit') {
767  print $form->buttonsSaveCancel();
768 
769  print "</form>\n";
770  }
771 
772 
773  // Buttons for actions
774 
775  print '<div class="tabsAction">'."\n";
776 
777  if ($action != 'edit') {
778  // Reopen
779  if ($object->paye && $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=reopen&token='.newToken().'">'.$langs->trans("ReOpen")."</a></div>";
781  }
782 
783  // Edit
784  if ($object->paye == 0 && $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=edit&token='.newToken().'">'.$langs->trans("Modify")."</a></div>";
786  }
787 
788  // Emit payment
789  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) {
790  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>';
791  }
792 
793  // Classify 'paid'
794  if ($object->paye == 0
795  && (
796  (round($resteapayer) <= 0 && $object->amount > 0)
797  || (round($resteapayer) >= 0 && $object->amount < 0)
798  )
799  && $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=paid">'.$langs->trans("ClassifyPaid")."</a></div>";
801  }
802 
803  // Clone
804  if ($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=clone">'.$langs->trans("ToClone")."</a></div>";
806  }
807 
808  if (!empty($user->rights->tax->charges->supprimer) && empty($totalpaid)) {
809  print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
810  } else {
811  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("DisabledBecausePayments"))).'">'.$langs->trans("Delete").'</a></div>';
812  }
813  }
814  print '</div>'."\n";
815 
816 
817 
818  // Select mail models is same action as presend
819  if (GETPOST('modelselected')) {
820  $action = 'presend';
821  }
822 
823  if ($action != 'presend') {
824  print '<div class="fichecenter"><div class="fichehalfleft">';
825  print '<a name="builddoc"></a>'; // ancre
826 
827  $includedocgeneration = 1;
828 
829  // Documents
830  if ($includedocgeneration) {
831  $objref = dol_sanitizeFileName($object->ref);
832  $relativepath = $objref.'/'.$objref.'.pdf';
833  $filedir = $conf->tax->dir_output.'/vat/'.$objref;
834  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
835  //$genallowed = $user->rights->tax->charges->lire; // If you can read, you can build the PDF to read content
836  $genallowed = 0;
837  $delallowed = $user->rights->tax->charges->creer; // If you can create/edit, you can remove a file on card
838  print $formfile->showdocuments('tax-vat', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
839  }
840 
841  // Show links to link elements
842  //$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
843  //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
844 
845 
846  print '</div><div class="fichehalfright">';
847 
848  /*
849  $MAXEVENT = 10;
850 
851  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
852 
853  // List of actions on element
854  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
855  $formactions = new FormActions($db);
856  $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
857  */
858 
859  print '</div></div>';
860  }
861 
862  //Select mail models is same action as presend
863  if (GETPOST('modelselected')) {
864  $action = 'presend';
865  }
866 
867  // Presend form
868  $modelmail = 'vat';
869  $defaulttopic = 'InformationMessage';
870  $diroutput = $conf->tax->dir_output;
871  $trackid = 'vat'.$object->id;
872 
873  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
874 }
875 
876 llxFooter();
877 $db->close();
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1236
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
vat_prepare_head
vat_prepare_head($object)
Prepare array with list of tabs.
Definition: vat.lib.php:33
$sql
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)) $sql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5363
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:530
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4994
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
PaymentVAT
Class to manage payments of social contributions.
Definition: paymentvat.class.php:33
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4539
dol_banner_tab
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.
Definition: functions.lib.php:2097
$help_url
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
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5834
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4025
llxHeader
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
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
AccountingJournal
Class to manage accounting accounts.
Definition: accountingjournal.class.php:27
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1873
restrictedArea
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.
Definition: security.lib.php:341
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11317
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2069
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:147
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:431
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$parameters
$parameters
Actions.
Definition: card.php:79
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4361
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1863
price
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.
Definition: functions.lib.php:5708
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8509
dol_mktime
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...
Definition: functions.lib.php:2859
Account
Class to manage bank accounts.
Definition: account.class.php:39
Tva
Put here description of your class.
Definition: tva.class.php:35