dolibarr  20.0.0-beta
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-2023 Alexandre Spangaro <aspangaro@easya.solutions>
6  * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.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 = GETPOSTINT('id');
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 = GETPOSTINT("refund");
56 if (GETPOSTISSET('auto_create_paiement') || $action === 'add') {
57  $auto_create_payment = GETPOSTINT("auto_create_paiement");
58 } else {
59  $auto_create_payment = !getDolGlobalString('CREATE_NEW_VAT_WITHOUT_AUTO_PAYMENT');
60 }
61 
62 if (empty($refund)) {
63  $refund = 0;
64 }
65 
66 $datev = dol_mktime(12, 0, 0, GETPOSTINT("datevmonth"), GETPOSTINT("datevday"), GETPOSTINT("datevyear"));
67 $datep = dol_mktime(12, 0, 0, GETPOSTINT("datepmonth"), GETPOSTINT("datepday"), GETPOSTINT("datepyear"));
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 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
84 
85 $permissiontoread = $user->hasRight('tax', 'charges', 'lire');
86 $permissiontoadd = $user->hasRight('tax', 'charges', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
87 $permissiontodelete = $user->rights->tax->charges->supprimer || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID);
88 $permissionnote = $user->hasRight('tax', 'charges', 'creer'); // Used by the include of actions_setnotes.inc.php
89 $permissiondellink = $user->hasRight('tax', 'charges', 'creer'); // Used by the include of actions_dellink.inc.php
90 $upload_dir = $conf->tax->multidir_output[isset($object->entity) ? $object->entity : 1].'/vat';
91 
92 // Security check
93 $socid = GETPOSTINT('socid');
94 if (!empty($user->socid)) {
95  $socid = $user->socid;
96 }
97 $result = restrictedArea($user, 'tax', $object->id, 'tva', 'charges');
98 
99 
100 /*
101  * Actions
102  */
103 
104 $parameters = array('socid' => $socid);
105 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
106 if ($reshook < 0) {
107  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
108 }
109 
110 if (empty($reshook)) {
111  if ($cancel && !$id) {
112  header("Location: list.php");
113  exit;
114  }
115 
116  if ($action == 'setlib' && $user->hasRight('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->hasRight('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->hasRight('tax', 'charges', 'creer')) {
137  $object->fetch($id);
138  $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
139  if ($result < 0) {
140  setEventMessages($object->error, $object->errors, 'errors');
141  }
142  }
143 
144  // Bank account
145  if ($action == 'setbankaccount' && $user->hasRight('tax', 'charges', 'creer')) {
146  $object->fetch($id);
147  $result = $object->setBankAccount(GETPOSTINT('fk_account'));
148  if ($result < 0) {
149  setEventMessages($object->error, $object->errors, 'errors');
150  }
151  }
152 
153  // Classify paid
154  if ($action == 'confirm_paid' && $user->hasRight('tax', 'charges', 'creer') && $confirm == 'yes') {
155  $object->fetch($id);
156  $result = $object->setPaid($user);
157  }
158 
159  if ($action == 'reopen' && $user->hasRight('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 = GETPOSTINT("accountid");
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 = (float) price2num(GETPOST("amount", 'alpha'));
183  if ($refund == 1) {
184  $amount = price2num(-1 * $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  $paiement->note_private = 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)', GETPOSTINT('accountid'), '', '');
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->hasRight('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->hasRight('tax', 'charges', 'creer'))) {
326  $db->begin();
327 
328  $originalId = $id;
329 
330  $object->fetch($id);
331 
332  if ($object->id > 0) {
333  $object->id = 0;
334  $object->ref = '';
335  $object->paye = 0;
336 
337  if (GETPOST('amount', 'alphanohtml')) {
338  $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
339  }
340 
341  if (GETPOST('clone_label', 'alphanohtml')) {
342  $object->label = GETPOST('clone_label', 'alphanohtml');
343  } else {
344  $object->label = $langs->trans("CopyOf").' '.$object->label;
345  }
346 
347  $newdateperiod = dol_mktime(0, 0, 0, GETPOSTINT('clone_periodmonth'), GETPOSTINT('clone_periodday'), GETPOSTINT('clone_periodyear'));
348  if ($newdateperiod) {
349  $object->datev = $newdateperiod;
350  }
351 
352  //if ($object->check()) {
353  $id = $object->create($user);
354  if ($id > 0) {
355  $db->commit();
356  $db->close();
357 
358  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
359  exit;
360  } else {
361  $id = $originalId;
362  $db->rollback();
363 
364  setEventMessages($object->error, $object->errors, 'errors');
365  }
366  //}
367  } else {
368  $db->rollback();
369  dol_print_error($db, $object->error);
370  }
371  }
372 
373  // Actions to build doc
374  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
375 }
376 
377 
378 /*
379  * View
380  */
381 
382 $form = new Form($db);
383 $formfile = new FormFile($db);
384 $formproject = new FormProjets($db);
385 
386 $title = $langs->trans("VAT")." - ".$langs->trans("Card");
387 $help_url = '';
388 llxHeader('', $title, $help_url);
389 
390 // Form to create a 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((GETPOSTINT("datevmonth") ? $datev : -1), "datev", 0, 0, 0, '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", 0, 0, 0, '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(GETPOSTINT("type_payment"), "type_payment", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx', 1);
484  print "</td>\n";
485  print "</tr>";
486 
487  if (isModEnabled("bank")) {
488  // Bank account
489  print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("BankAccount").'</td><td>';
490  print img_picto('', 'bank_account', 'class="pictofixedwidth"');
491  $form->select_comptes(GETPOSTINT("accountid"), "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  $formconfirm = '';
532 
533  $head = vat_prepare_head($object);
534 
535  $totalpaid = $object->getSommePaiement();
536 
537  // Clone confirmation
538  if ($action === 'clone') {
539  $formquestion = array(
540  array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
541  );
542 
543  //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
544  $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
545  $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100');
546 
547  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVAT', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240);
548  }
549 
550  if ($action == 'paid') {
551  $text = $langs->trans('ConfirmPayVAT');
552  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayVAT'), $text, "confirm_paid", '', '', 2);
553  }
554 
555  if ($action == 'delete') {
556  $text = $langs->trans('ConfirmDeleteVAT');
557  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVAT'), $text, 'confirm_delete', '', '', 2);
558  }
559 
560  if ($action == 'edit') {
561  print '<form name="charge" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
562  print '<input type="hidden" name="token" value="'.newToken().'">';
563  print '<input type="hidden" name="action" value="update">';
564  }
565  // Call Hook formConfirm
566  $parameters = array('formConfirm' => $formconfirm);
567  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
568  if (empty($reshook)) {
569  $formconfirm .= $hookmanager->resPrint;
570  } elseif ($reshook > 0) {
571  $formconfirm = $hookmanager->resPrint;
572  }
573 
574  print dol_get_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment', 0, '', '', 0, '', 1);
575 
576  // Print form confirm
577  print $formconfirm;
578 
579  $morehtmlref = '<div class="refidno">';
580  // Label of social contribution
581  $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->hasRight('tax', 'charges', 'creer'), 'string', '', 0, 1);
582  $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->hasRight('tax', 'charges', 'creer'), 'string', '', null, null, '', 1);
583  // Project
584  $morehtmlref .= '</div>';
585 
586  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
587 
588  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
589 
590  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
591 
592  print '<div class="fichecenter">';
593  print '<div class="fichehalfleft">';
594  print '<div class="underbanner clearboth"></div>';
595 
596  print '<table class="border centpercent">';
597 
598  // Label
599  //print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
600 
601  /*print "<tr>";
602  print '<td class="titlefield">'.$langs->trans("DatePayment").'</td><td>';
603  print dol_print_date($object->datep, 'day');
604  print '</td></tr>';*/
605 
606  print '<tr><td>';
607  print $form->editfieldkey($form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")), 'datev', $object->datev, $object, $user->hasRight('tax', 'charges', 'creer'), 'day');
608  print '</td><td>';
609  print $form->editfieldval("PeriodEndDate", 'datev', $object->datev, $object, $user->hasRight('tax', 'charges', 'creer'), 'day');
610  //print dol_print_date($object->datev,'day');
611  print '</td></tr>';
612 
613  if ($action == 'edit') {
614  print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
615  } else {
616  print '<tr><td>' . $langs->trans("Amount") . '</td><td>' . price($object->amount) . '</td></tr>';
617  }
618 
619  // Mode of payment
620  print '<tr><td>';
621  print '<table class="nobordernopadding" width="100%"><tr><td>';
622  print $langs->trans('PaymentMode');
623  print '</td>';
624  if ($action != 'editmode') {
625  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>';
626  }
627  print '</tr></table>';
628  print '</td><td>';
629  if ($action == 'editmode') {
630  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
631  } else {
632  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
633  }
634  print '</td></tr>';
635 
636  // Bank account
637  if (isModEnabled("bank")) {
638  print '<tr><td class="nowrap">';
639  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
640  print $langs->trans('BankAccount');
641  print '<td>';
642  if ($action != 'editbankaccount' && $user->hasRight('tax', 'charges', 'creer')) {
643  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>';
644  }
645  print '</tr></table>';
646  print '</td><td>';
647  if ($action == 'editbankaccount') {
648  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
649  } else {
650  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
651  }
652  print '</td>';
653  print '</tr>';
654  }
655 
656  // Other attributes
657  $parameters = array();
658  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
659  print $hookmanager->resPrint;
660 
661  print '</table>';
662 
663  print '</div>';
664 
665  print '<div class="fichehalfright">';
666 
667  $nbcols = 3;
668  if (isModEnabled("bank")) {
669  $nbcols++;
670  }
671 
672  /*
673  * Payments
674  */
675  $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,";
676  $sql .= " c.code as type_code,c.libelle as paiement_type,";
677  $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';
678  $sql .= " FROM ".MAIN_DB_PREFIX."payment_vat as p";
679  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
680  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
681  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
682  $sql .= ", ".MAIN_DB_PREFIX."tva as tva";
683  $sql .= " WHERE p.fk_tva = ".((int) $id);
684  $sql .= " AND p.fk_tva = tva.rowid";
685  $sql .= " AND tva.entity IN (".getEntity('tax').")";
686  $sql .= " ORDER BY dp DESC";
687 
688  //print $sql;
689  $resql = $db->query($sql);
690  if ($resql) {
691  $totalpaid = 0;
692 
693  $num = $db->num_rows($resql);
694  $i = 0;
695  $total = 0;
696 
697  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
698  print '<table class="noborder paymenttable">';
699  print '<tr class="liste_titre">';
700  print '<td>'.$langs->trans("RefPayment").'</td>';
701  print '<td>'.$langs->trans("Date").'</td>';
702  print '<td>'.$langs->trans("Type").'</td>';
703  if (isModEnabled("bank")) {
704  print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
705  }
706  print '<td class="right">'.$langs->trans("Amount").'</td>';
707  print '</tr>';
708 
709  if ($num > 0) {
710  $bankaccountstatic = new Account($db);
711  while ($i < $num) {
712  $objp = $db->fetch_object($resql);
713 
714  print '<tr class="oddeven"><td>';
715  print '<a href="'.DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a>';
716  print '</td>';
717  print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
718  $labeltype = $langs->trans("PaymentType".$objp->type_code) != "PaymentType".$objp->type_code ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
719  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
720  if (isModEnabled("bank")) {
721  $bankaccountstatic->id = $objp->baid;
722  $bankaccountstatic->ref = $objp->baref;
723  $bankaccountstatic->label = $objp->baref;
724  $bankaccountstatic->number = $objp->banumber;
725  $bankaccountstatic->currency_code = $objp->bacurrency_code;
726 
727  if (isModEnabled('accounting')) {
728  $bankaccountstatic->account_number = $objp->account_number;
729 
730  $accountingjournal = new AccountingJournal($db);
731  $accountingjournal->fetch($objp->fk_accountancy_journal);
732  $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
733  }
734 
735  print '<td class="right">';
736  if ($bankaccountstatic->id) {
737  print $bankaccountstatic->getNomUrl(1, 'transactions');
738  }
739  print '</td>';
740  }
741  print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
742  print "</tr>";
743  $totalpaid += $objp->amount;
744  $i++;
745  }
746  } else {
747  print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
748  print '<td></td><td></td><td></td><td></td>';
749  print '</tr>';
750  }
751 
752  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid")." :</td><td class=\"right\">".price($totalpaid)."</td></tr>\n";
753  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected")." :</td><td class=\"right\">".price($object->amount)."</td></tr>\n";
754 
755  $resteapayer = $object->amount - $totalpaid;
756  $cssforamountpaymentcomplete = 'amountpaymentcomplete';
757 
758  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
759  print '<td class="right'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
760 
761  print "</table>";
762  print '</div>';
763 
764  $db->free($resql);
765  } else {
766  dol_print_error($db);
767  }
768 
769  print '</div>';
770  print '</div>';
771 
772  print '<div class="clearboth"></div>';
773 
774  print dol_get_fiche_end();
775 
776  if ($action == 'edit') {
777  print $form->buttonsSaveCancel();
778 
779  print "</form>\n";
780  }
781 
782 
783  // Buttons for actions
784 
785  print '<div class="tabsAction">'."\n";
786 
787  if ($action != 'edit') {
788  // Reopen
789  if ($object->paye && $user->hasRight('tax', 'charges', 'creer')) {
790  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen")."</a></div>";
791  }
792 
793  // Edit
794  if ($object->paye == 0 && $user->hasRight('tax', 'charges', 'creer')) {
795  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>";
796  }
797 
798  // Emit payment
799  if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->hasRight('tax', 'charges', 'creer')) {
800  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>';
801  }
802 
803  // Classify 'paid'
804  if ($object->paye == 0
805  && (
806  (round($resteapayer) <= 0 && $object->amount > 0)
807  || (round($resteapayer) >= 0 && $object->amount < 0)
808  )
809  && $user->hasRight('tax', 'charges', 'creer')) {
810  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&token='.newToken().'&action=paid">'.$langs->trans("ClassifyPaid")."</a></div>";
811  }
812 
813  // Clone
814  if ($user->hasRight('tax', 'charges', 'creer')) {
815  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>";
816  }
817 
818  if ($user->hasRight('tax', 'charges', 'supprimer') && empty($totalpaid)) {
819  print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
820  } else {
821  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("DisabledBecausePayments"))).'">'.$langs->trans("Delete").'</a></div>';
822  }
823  }
824  print '</div>'."\n";
825 
826 
827 
828  // Select mail models is same action as presend
829  if (GETPOST('modelselected')) {
830  $action = 'presend';
831  }
832 
833  if ($action != 'presend') {
834  print '<div class="fichecenter"><div class="fichehalfleft">';
835  print '<a name="builddoc"></a>'; // ancre
836 
837  $includedocgeneration = 1;
838 
839  // Documents
840  if ($includedocgeneration) {
841  $objref = dol_sanitizeFileName($object->ref);
842  $relativepath = $objref.'/'.$objref.'.pdf';
843  $filedir = $conf->tax->dir_output.'/vat/'.$objref;
844  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
845  $genallowed = 0;
846  $delallowed = $user->hasRight('tax', 'charges', 'creer'); // If you can create/edit, you can remove a file on card
847  print $formfile->showdocuments('tax-vat', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
848  }
849 
850  // Show links to link elements
851  //$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
852  //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
853 
854 
855  print '</div><div class="fichehalfright">';
856 
857  /*
858  $MAXEVENT = 10;
859 
860  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
861 
862  // List of actions on element
863  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
864  $formactions = new FormActions($db);
865  $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
866  */
867 
868  print '</div></div>';
869  }
870 
871  //Select mail models is same action as presend
872  if (GETPOST('modelselected')) {
873  $action = 'presend';
874  }
875 
876  // Presend form
877  $modelmail = 'vat';
878  $defaulttopic = 'InformationMessage';
879  $diroutput = $conf->tax->dir_output;
880  $trackid = 'vat'.$object->id;
881 
882  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
883 }
884 
885 llxFooter();
886 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage bank accounts.
Class to manage bank transaction lines.
Class to manage accounting journals.
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:37
$parameters
Actions.
Definition: card.php:84
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
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_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
$formconfirm
if ($action == 'delbookkeepingyear') {
div float
Buy price without taxes.
Definition: style.css.php:960
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