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