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