dolibarr 21.0.3
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 * Copyright (C) 2024 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';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
39
40if (isModEnabled('accounting')) {
41 include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
42}
43
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', 'aZ09');
60$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectcard'; // 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$extrafields = new ExtraFields($db);
81$diroutputmassaction = $conf->tax->dir_output.'/temp/massgeneration/'.$user->id;
82$hookmanager->initHooks(array('taxvatcard', 'globalcard'));
83
84// Fetch optionals attributes and labels
85$extrafields->fetch_name_optionals_label($object->table_element);
86
87if (empty($action) && empty($id) && empty($ref)) {
88 $action = 'view';
89}
90
91// Load object
92include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
93
94$permissiontoread = $user->hasRight('tax', 'charges', 'lire');
95$permissiontoadd = $user->hasRight('tax', 'charges', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
96$permissiontodelete = $user->rights->tax->charges->supprimer || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID);
97$permissionnote = $user->hasRight('tax', 'charges', 'creer'); // Used by the include of actions_setnotes.inc.php
98$permissiondellink = $user->hasRight('tax', 'charges', 'creer'); // Used by the include of actions_dellink.inc.php
99$upload_dir = $conf->tax->multidir_output[isset($object->entity) ? $object->entity : 1].'/vat';
100
101// Security check
102$socid = GETPOSTINT('socid');
103if (!empty($user->socid)) {
104 $socid = $user->socid;
105}
106$result = restrictedArea($user, 'tax', $object->id, 'tva', 'charges');
107
108
109$resteapayer = 0;
110
111/*
112 * Actions
113 */
114
115$parameters = array('socid' => $socid);
116$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
117if ($reshook < 0) {
118 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
119}
120
121if (empty($reshook)) {
122 if ($cancel && !$id) {
123 header("Location: list.php");
124 exit;
125 }
126
127 if ($action == 'setlib' && $user->hasRight('tax', 'charges', 'creer')) {
128 $object->fetch($id);
129 $result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', null, 'text', '', $user, 'TAX_MODIFY');
130 if ($result < 0) {
131 setEventMessages($object->error, $object->errors, 'errors');
132 }
133 }
134
135 if ($action == 'setdatev' && $user->hasRight('tax', 'charges', 'creer')) {
136 $object->fetch($id);
137 $object->datev = $datev;
138 $result = $object->update($user);
139 if ($result < 0) {
140 dol_print_error($db, $object->error);
141 }
142
143 $action = '';
144 }
145
146 // payment mode
147 if ($action == 'setmode' && $user->hasRight('tax', 'charges', 'creer')) {
148 $object->fetch($id);
149 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
150 if ($result < 0) {
151 setEventMessages($object->error, $object->errors, 'errors');
152 }
153 }
154
155 // Bank account
156 if ($action == 'setbankaccount' && $user->hasRight('tax', 'charges', 'creer')) {
157 $object->fetch($id);
158 $result = $object->setBankAccount(GETPOSTINT('fk_account'));
159 if ($result < 0) {
160 setEventMessages($object->error, $object->errors, 'errors');
161 }
162 }
163
164 // Classify paid
165 if ($action == 'confirm_paid' && $user->hasRight('tax', 'charges', 'creer') && $confirm == 'yes') {
166 $object->fetch($id);
167 $result = $object->setPaid($user);
168 }
169
170 if ($action == 'reopen' && $user->hasRight('tax', 'charges', 'creer')) {
171 $result = $object->fetch($id);
172 if ($object->paye) {
173 $result = $object->setUnpaid($user);
174 if ($result > 0) {
175 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
176 exit();
177 } else {
178 setEventMessages($object->error, $object->errors, 'errors');
179 }
180 }
181 }
182
183 if ($action == 'add' && !$cancel && $permissiontoadd) {
184 $error = 0;
185
186 $object->fk_account = GETPOSTINT("accountid");
187 $object->type_payment = GETPOSTINT("type_payment");
188 $object->num_payment = GETPOST("num_payment", 'alphanohtml');
189
190 $object->datev = $datev;
191 $object->datep = $datep;
192
193 $amount = (float) price2num(GETPOST("amount", 'alpha'));
194 if ($refund == 1) {
195 $amount = price2num(-1 * $amount);
196 }
197 $object->amount = $amount;
198 $object->label = GETPOST("label", 'alpha');
199 $object->note = GETPOST("note", 'restricthtml');
200 $object->note_private = GETPOST("note", 'restricthtml');
201
202 if (empty($object->datep)) {
203 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
204 $error++;
205 }
206 if (empty($object->datev)) {
207 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors');
208 $error++;
209 }
210 if (!empty($auto_create_payment) && (empty($object->type_payment) || $object->type_payment < 0)) {
211 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
212 $error++;
213 }
214 if (empty($object->amount)) {
215 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
216 $error++;
217 }
218 if (!empty($auto_create_payment) && ($object->fk_account <= 0)) {
219 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountToCredit")), null, 'errors');
220 $error++;
221 }
222
223 if (!$error) {
224 $ret = $object->create($user);
225 if ($ret < 0) {
226 $error++;
227 }
228
229 // Auto create payment
230 if (!empty($auto_create_payment) && !$error) {
231 $db->begin();
232
233 // Create a line of payments
234 $paiement = new PaymentVAT($db);
235 $paiement->chid = $object->id;
236 $paiement->datepaye = $datep;
237 $paiement->amounts = array($object->id => $amount); // Tableau de montant
238 $paiement->paiementtype = GETPOST("type_payment", 'alphanohtml');
239 $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
240 $paiement->note = GETPOST("note", 'restricthtml');
241 $paiement->note_private = GETPOST("note", 'restricthtml');
242
243 if (!$error) {
244 $paymentid = $paiement->create($user, (int) GETPOST('closepaidtva'));
245 if ($paymentid < 0) {
246 $error++;
247 setEventMessages($paiement->error, null, 'errors');
248 $action = 'create';
249 }
250 }
251
252 if (!$error) {
253 $result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOSTINT('accountid'), '', '');
254 if (!($result > 0)) {
255 $error++;
256 setEventMessages($paiement->error, null, 'errors');
257 }
258 }
259
260 if (!$error) {
261 $db->commit();
262 } else {
263 $db->rollback();
264 }
265 }
266 if (empty($error)) {
267 header("Location: card.php?id=" . $object->id);
268 exit;
269 }
270 }
271
272 $action = 'create';
273 }
274
275 if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
276 $result = $object->fetch($id);
277 $totalpaid = $object->getSommePaiement();
278
279 if (empty($totalpaid)) {
280 $db->begin();
281
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", '', 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(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" name="closepaidtva"> <span class="">'.$langs->trans("ClosePaidVATAutomatically").'</span>';
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, 240);
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', $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, $object->type_payment, 'mode_reglement_id');
643 } else {
644 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $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, $object->fk_account, 'fk_account', 1);
661 } else {
662 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $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 {
778 dol_print_error($db);
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" 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
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
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.
Class to manage VAT - Value-added tax (also known in French as TVA - Taxe sur la valeur ajoutée)
Definition tva.class.php:38
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.
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)
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)
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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:34