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