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