dolibarr 21.0.0-beta
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015-2023 Alexandre Spangaro <aspangaro@easya.solutions>
6 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 * 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
116$parameters = array('socid' => $socid);
117$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
118if ($reshook < 0) {
119 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
120}
121
122if (empty($reshook)) {
123 if ($cancel && !$id) {
124 header("Location: list.php");
125 exit;
126 }
127
128 if ($action == 'setlib' && $user->hasRight('tax', 'charges', 'creer')) {
129 $object->fetch($id);
130 $result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', null, 'text', '', $user, 'TAX_MODIFY');
131 if ($result < 0) {
132 setEventMessages($object->error, $object->errors, 'errors');
133 }
134 }
135
136 if ($action == 'setdatev' && $user->hasRight('tax', 'charges', 'creer')) {
137 $object->fetch($id);
138 $object->datev = $datev;
139 $result = $object->update($user);
140 if ($result < 0) {
141 dol_print_error($db, $object->error);
142 }
143
144 $action = '';
145 }
146
147 // payment mode
148 if ($action == 'setmode' && $user->hasRight('tax', 'charges', 'creer')) {
149 $object->fetch($id);
150 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
151 if ($result < 0) {
152 setEventMessages($object->error, $object->errors, 'errors');
153 }
154 }
155
156 // Bank account
157 if ($action == 'setbankaccount' && $user->hasRight('tax', 'charges', 'creer')) {
158 $object->fetch($id);
159 $result = $object->setBankAccount(GETPOSTINT('fk_account'));
160 if ($result < 0) {
161 setEventMessages($object->error, $object->errors, 'errors');
162 }
163 }
164
165 // Classify paid
166 if ($action == 'confirm_paid' && $user->hasRight('tax', 'charges', 'creer') && $confirm == 'yes') {
167 $object->fetch($id);
168 $result = $object->setPaid($user);
169 }
170
171 if ($action == 'reopen' && $user->hasRight('tax', 'charges', 'creer')) {
172 $result = $object->fetch($id);
173 if ($object->paye) {
174 $result = $object->setUnpaid($user);
175 if ($result > 0) {
176 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
177 exit();
178 } else {
179 setEventMessages($object->error, $object->errors, 'errors');
180 }
181 }
182 }
183
184 if ($action == 'add' && !$cancel && $permissiontoadd) {
185 $error = 0;
186
187 $object->fk_account = GETPOSTINT("accountid");
188 $object->type_payment = GETPOSTINT("type_payment");
189 $object->num_payment = GETPOST("num_payment", 'alphanohtml');
190
191 $object->datev = $datev;
192 $object->datep = $datep;
193
194 $amount = (float) price2num(GETPOST("amount", 'alpha'));
195 if ($refund == 1) {
196 $amount = price2num(-1 * $amount);
197 }
198 $object->amount = $amount;
199 $object->label = GETPOST("label", 'alpha');
200 $object->note = GETPOST("note", 'restricthtml');
201 $object->note_private = GETPOST("note", 'restricthtml');
202
203 if (empty($object->datep)) {
204 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
205 $error++;
206 }
207 if (empty($object->datev)) {
208 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors');
209 $error++;
210 }
211 if (!empty($auto_create_payment) && (empty($object->type_payment) || $object->type_payment < 0)) {
212 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
213 $error++;
214 }
215 if (empty($object->amount)) {
216 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
217 $error++;
218 }
219 if (!empty($auto_create_payment) && ($object->fk_account <= 0)) {
220 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountToCredit")), null, 'errors');
221 $error++;
222 }
223
224 if (!$error) {
225 $ret = $object->create($user);
226 if ($ret < 0) {
227 $error++;
228 }
229
230 // Auto create payment
231 if (!empty($auto_create_payment) && !$error) {
232 $db->begin();
233
234 // Create a line of payments
235 $paiement = new PaymentVAT($db);
236 $paiement->chid = $object->id;
237 $paiement->datepaye = $datep;
238 $paiement->amounts = array($object->id => $amount); // Tableau de montant
239 $paiement->paiementtype = GETPOST("type_payment", 'alphanohtml');
240 $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
241 $paiement->note = GETPOST("note", 'restricthtml');
242 $paiement->note_private = GETPOST("note", 'restricthtml');
243
244 if (!$error) {
245 $paymentid = $paiement->create($user, (int) GETPOST('closepaidtva'));
246 if ($paymentid < 0) {
247 $error++;
248 setEventMessages($paiement->error, null, 'errors');
249 $action = 'create';
250 }
251 }
252
253 if (!$error) {
254 $result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOSTINT('accountid'), '', '');
255 if (!($result > 0)) {
256 $error++;
257 setEventMessages($paiement->error, null, 'errors');
258 }
259 }
260
261 if (!$error) {
262 $db->commit();
263 } else {
264 $db->rollback();
265 }
266 }
267 if (empty($error)) {
268 header("Location: card.php?id=" . $object->id);
269 exit;
270 }
271 }
272
273 $action = 'create';
274 }
275
276 if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
277 $result = $object->fetch($id);
278 $totalpaid = $object->getSommePaiement();
279
280 if (empty($totalpaid)) {
281 $db->begin();
282
283 $ret = $object->delete($user);
284 if ($ret > 0) {
285 $accountline = null;
286 if ($object->fk_bank) {
287 $accountline = new AccountLine($db);
288 $result = $accountline->fetch($object->fk_bank);
289 if ($result > 0) {
290 $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
291 }
292 }
293
294 if ($result >= 0) {
295 $db->commit();
296 header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php');
297 exit;
298 } else {
299 $object->error = $accountline !== null ? $accountline->error : 'No account line (no bank)';
300 $db->rollback();
301 setEventMessages($object->error, $object->errors, 'errors');
302 }
303 } else {
304 $db->rollback();
305 setEventMessages($object->error, $object->errors, 'errors');
306 }
307 } else {
308 setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
309 }
310 }
311
312 if ($action == 'update' && !GETPOST("cancel") && $user->hasRight('tax', 'charges', 'creer')) {
313 $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
314
315 if (empty($amount)) {
316 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
317 $action = 'edit';
318 } elseif (!is_numeric($amount)) {
319 setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
320 $action = 'create';
321 } else {
322 $result = $object->fetch($id);
323
324 $object->amount = $amount;
325
326 $result = $object->update($user);
327 if ($result <= 0) {
328 setEventMessages($object->error, $object->errors, 'errors');
329 }
330 }
331 }
332
333 // Action clone object
334 if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required here
335 $action = '';
336 }
337
338 if ($action == 'confirm_clone' && $confirm == 'yes' && $user->hasRight('tax', 'charges', 'creer')) {
339 $db->begin();
340
341 $originalId = $id;
342
343 $object->fetch($id);
344
345 if ($object->id > 0) {
346 $object->id = 0;
347 $object->ref = '';
348 $object->paye = 0;
349
350 if (GETPOST('amount', 'alphanohtml')) {
351 $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
352 }
353
354 if (GETPOST('clone_label', 'alphanohtml')) {
355 $object->label = GETPOST('clone_label', 'alphanohtml');
356 } else {
357 $object->label = $langs->trans("CopyOf").' '.$object->label;
358 }
359
360 $newdateperiod = dol_mktime(0, 0, 0, GETPOSTINT('clone_periodmonth'), GETPOSTINT('clone_periodday'), GETPOSTINT('clone_periodyear'));
361 if ($newdateperiod) {
362 $object->datev = $newdateperiod;
363 }
364
365 //if ($object->check()) {
366 $id = $object->create($user);
367 if ($id > 0) {
368 $db->commit();
369 $db->close();
370
371 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
372 exit;
373 } else {
374 $id = $originalId;
375 $db->rollback();
376
377 setEventMessages($object->error, $object->errors, 'errors');
378 }
379 //}
380 } else {
381 $db->rollback();
382 dol_print_error($db, $object->error);
383 }
384 }
385
386 // Actions to build doc
387 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
388}
389
390
391/*
392 * View
393 */
394
395$form = new Form($db);
396$formfile = new FormFile($db);
397$formproject = new FormProjets($db);
398
399$title = $langs->trans("VAT")." - ".$langs->trans("Card");
400$help_url = '';
401llxHeader('', $title, $help_url);
402
403// Form to create a VAT
404if ($action == 'create') {
405 print load_fiche_titre($langs->trans("VAT").' - '.$langs->trans("New"));
406
407 if (!empty($conf->use_javascript_ajax)) {
408 print "\n".'<script type="text/javascript">';
409 print '
410 $(document).ready(function () {
411 let onAutoCreatePaiementChange = function () {
412 if($("#auto_create_paiement").is(":checked")) {
413 $("#label_fk_account").addClass("fieldrequired");
414 $("#label_type_payment").addClass("fieldrequired");
415 $(".hide_if_no_auto_create_payment").show();
416 } else {
417 $("#label_fk_account").removeClass("fieldrequired");
418 $("#label_type_payment").removeClass("fieldrequired");
419 $(".hide_if_no_auto_create_payment").hide();
420 }
421 }
422 $("#radiopayment").click(function() {
423 $("#label").val($(this).data("label"));
424 });
425 $("#radiorefund").click(function() {
426 $("#label").val($(this).data("label"));
427
428 });
429 $("#auto_create_paiement").click(function () {
430 onAutoCreatePaiementChange();
431 });
432 onAutoCreatePaiementChange();
433 });
434 ';
435
436 print '</script>'."\n";
437 }
438
439 print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formvat" method="post">';
440 print '<input type="hidden" name="token" value="'.newToken().'">';
441 print '<input type="hidden" name="action" value="add">';
442
443 print dol_get_fiche_head();
444
445 print '<table class="border centpercent">';
446
447 print '<tr><td class="titlefieldcreate fieldrequired">';
448 //print $langs->trans("Type");
449 print '</td><td>';
450
451 print '<div id="selectmethod">';
452 print '<label for="radiopayment">';
453 print '<input type="radio" id="radiopayment" data-label="'.$langs->trans('VATPayment').'" class="flat" name="refund" value="0"'.($refund ? '' : ' checked="checked"').'>';
454 print '&nbsp;';
455 print $langs->trans("Payment");
456 print '</label>';
457 print '&nbsp;&nbsp;&nbsp;';
458 print '<label for="radiorefund">';
459 print '<input type="radio" id="radiorefund" data-label="'.$langs->trans('VATRefund').'" class="flat" name="refund" value="1"'.($refund ? ' checked="checked"' : '').'>';
460 print '&nbsp;';
461 print $langs->trans("Refund");
462 print '</label>';
463 print '</div>';
464
465 print '</td>';
466 print "</tr>\n";
467
468 // Label
469 if ($refund == 1) {
470 $label = $langs->trans("VATRefund");
471 } else {
472 $label = $langs->trans("VATPayment");
473 }
474 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>';
475
476 print '<tr><td class="titlefieldcreate fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
477 print $form->selectDate((GETPOSTINT("datevmonth") ? $datev : -1), "datev", 0, 0, 0, 'add', 1, 1);
478 print '</td></tr>';
479
480 // Amount
481 print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" class="right width75" value="'.GETPOST("amount", "alpha").'"></td></tr>';
482
483 print '<tr><td colspan="2"><hr></td></tr>';
484
485 // Auto create payment
486 print '<tr><td><label for="auto_create_paiement">'.$langs->trans('AutomaticCreationPayment').'</label></td>';
487 print '<td><input id="auto_create_paiement" name="auto_create_paiement" type="checkbox" ' . (empty($auto_create_payment) ? '' : 'checked="checked"') . ' value="1"></td></tr>'."\n";
488
489 print '<tr class="hide_if_no_auto_create_payment">';
490 print '<td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
491 print $form->selectDate($datep, "datep", 0, 0, 0, 'add', 1, 1);
492 print '</td></tr>';
493
494 // Type payment
495 print '<tr><td class="fieldrequired" id="label_type_payment">'.$langs->trans("PaymentMode").'</td><td>';
496 print $form->select_types_paiements(GETPOSTINT("type_payment"), "type_payment", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx', 1);
497 print "</td>\n";
498 print "</tr>";
499
500 if (isModEnabled("bank")) {
501 // Bank account
502 print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("BankAccount").'</td><td>';
503 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
504 $form->select_comptes(GETPOSTINT("accountid"), "accountid", 0, "courant=1", 1, '', 0, 'maxwidth500 widthcentpercentminusx'); // List of bank account available
505 print '</td></tr>';
506 }
507
508 // Number
509 print '<tr class="hide_if_no_auto_create_payment"><td>'.$langs->trans('Numero');
510 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
511 print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
512
513 // Comments
514 print '<tr class="hide_if_no_auto_create_payment">';
515 print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
516 print '<td class="tdtop"><textarea name="note" wrap="soft" rows="'.ROWS_3.'" class="quatrevingtpercent">'.GETPOST('note', 'restricthtml').'</textarea></td>';
517 print '</tr>';
518
519 // Other attributes
520 $parameters = array();
521 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
522 print $hookmanager->resPrint;
523
524 print '</table>';
525
526 print dol_get_fiche_end();
527
528 print '<div class="center">';
529 print '<div class="hide_if_no_auto_create_payment paddingbottom">';
530 print '<input type="checkbox" checked value="1" name="closepaidtva"> <span class="">'.$langs->trans("ClosePaidVATAutomatically").'</span>';
531 print '<br>';
532 print '</div>';
533
534 print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
535 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
536 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
537 print '</div>';
538
539 print '</form>';
540}
541
542// View mode
543if ($id > 0) {
544 $formconfirm = '';
545
546 $head = vat_prepare_head($object);
547
548 $totalpaid = $object->getSommePaiement();
549
550 // Clone confirmation
551 if ($action === 'clone') {
552 $formquestion = array(
553 array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
554 );
555
556 //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
557 $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
558 $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100');
559
560 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVAT', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240);
561 }
562
563 if ($action == 'paid') {
564 $text = $langs->trans('ConfirmPayVAT');
565 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayVAT'), $text, "confirm_paid", '', '', 2);
566 }
567
568 if ($action == 'delete') {
569 $text = $langs->trans('ConfirmDeleteVAT');
570 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVAT'), $text, 'confirm_delete', '', '', 2);
571 }
572
573 if ($action == 'edit') {
574 print '<form name="charge" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
575 print '<input type="hidden" name="token" value="'.newToken().'">';
576 print '<input type="hidden" name="action" value="update">';
577 }
578 // Call Hook formConfirm
579 $parameters = array('formConfirm' => $formconfirm);
580 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
581 if (empty($reshook)) {
582 $formconfirm .= $hookmanager->resPrint;
583 } elseif ($reshook > 0) {
584 $formconfirm = $hookmanager->resPrint;
585 }
586
587 print dol_get_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment', 0, '', '', 0, '', 1);
588
589 // Print form confirm
590 print $formconfirm;
591
592 $morehtmlref = '<div class="refidno">';
593 // Label of social contribution
594 $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->hasRight('tax', 'charges', 'creer'), 'string', '', 0, 1);
595 $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->hasRight('tax', 'charges', 'creer'), 'string', '', null, null, '', 1);
596 // Project
597 $morehtmlref .= '</div>';
598
599 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
600
601 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
602
603 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
604
605 print '<div class="fichecenter">';
606 print '<div class="fichehalfleft">';
607 print '<div class="underbanner clearboth"></div>';
608
609 print '<table class="border centpercent">';
610
611 // Label
612 //print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
613
614 /*print "<tr>";
615 print '<td class="titlefield">'.$langs->trans("DatePayment").'</td><td>';
616 print dol_print_date($object->datep, 'day');
617 print '</td></tr>';*/
618
619 print '<tr><td>';
620 print $form->editfieldkey($form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")), 'datev', $object->datev, $object, $user->hasRight('tax', 'charges', 'creer'), 'day');
621 print '</td><td>';
622 print $form->editfieldval("PeriodEndDate", 'datev', $object->datev, $object, $user->hasRight('tax', 'charges', 'creer'), 'day');
623 //print dol_print_date($object->datev,'day');
624 print '</td></tr>';
625
626 if ($action == 'edit') {
627 print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
628 } else {
629 print '<tr><td>' . $langs->trans("Amount") . '</td><td>' . price($object->amount) . '</td></tr>';
630 }
631
632 // Mode of payment
633 print '<tr><td>';
634 print '<table class="nobordernopadding" width="100%"><tr><td>';
635 print $langs->trans('PaymentMode');
636 print '</td>';
637 if ($action != 'editmode') {
638 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
639 }
640 print '</tr></table>';
641 print '</td><td>';
642 if ($action == 'editmode') {
643 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
644 } else {
645 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
646 }
647 print '</td></tr>';
648
649 // Bank account
650 if (isModEnabled("bank")) {
651 print '<tr><td class="nowrap">';
652 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
653 print $langs->trans('BankAccount');
654 print '<td>';
655 if ($action != 'editbankaccount' && $user->hasRight('tax', 'charges', 'creer')) {
656 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
657 }
658 print '</tr></table>';
659 print '</td><td>';
660 if ($action == 'editbankaccount') {
661 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
662 } else {
663 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
664 }
665 print '</td>';
666 print '</tr>';
667 }
668
669 // Other attributes
670 $parameters = array();
671 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
672 print $hookmanager->resPrint;
673
674 print '</table>';
675
676 print '</div>';
677
678 print '<div class="fichehalfright">';
679
680 $nbcols = 3;
681 if (isModEnabled("bank")) {
682 $nbcols++;
683 }
684
685 /*
686 * Payments
687 */
688 $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,";
689 $sql .= " c.code as type_code,c.libelle as paiement_type,";
690 $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.currency_code as bacurrency_code, ba.fk_accountancy_journal';
691 $sql .= " FROM ".MAIN_DB_PREFIX."payment_vat as p";
692 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
693 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
694 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
695 $sql .= ", ".MAIN_DB_PREFIX."tva as tva";
696 $sql .= " WHERE p.fk_tva = ".((int) $id);
697 $sql .= " AND p.fk_tva = tva.rowid";
698 $sql .= " AND tva.entity IN (".getEntity('tax').")";
699 $sql .= " ORDER BY dp DESC";
700
701 //print $sql;
702 $resql = $db->query($sql);
703 if ($resql) {
704 $totalpaid = 0;
705
706 $num = $db->num_rows($resql);
707 $i = 0;
708 $total = 0;
709
710 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
711 print '<table class="noborder paymenttable">';
712 print '<tr class="liste_titre">';
713 print '<td>'.$langs->trans("RefPayment").'</td>';
714 print '<td>'.$langs->trans("Date").'</td>';
715 print '<td>'.$langs->trans("Type").'</td>';
716 if (isModEnabled("bank")) {
717 print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
718 }
719 print '<td class="right">'.$langs->trans("Amount").'</td>';
720 print '</tr>';
721
722 if ($num > 0) {
723 $bankaccountstatic = new Account($db);
724 while ($i < $num) {
725 $objp = $db->fetch_object($resql);
726
727 print '<tr class="oddeven"><td>';
728 print '<a href="'.DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a>';
729 print '</td>';
730 print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
731 $labeltype = $langs->trans("PaymentType".$objp->type_code) != "PaymentType".$objp->type_code ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
732 print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
733 if (isModEnabled("bank")) {
734 $bankaccountstatic->id = $objp->baid;
735 $bankaccountstatic->ref = $objp->baref;
736 $bankaccountstatic->label = $objp->baref;
737 $bankaccountstatic->number = $objp->banumber;
738 $bankaccountstatic->currency_code = $objp->bacurrency_code;
739
740 if (isModEnabled('accounting')) {
741 $bankaccountstatic->account_number = $objp->account_number;
742
743 $accountingjournal = new AccountingJournal($db);
744 $accountingjournal->fetch($objp->fk_accountancy_journal);
745 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
746 }
747
748 print '<td class="right">';
749 if ($bankaccountstatic->id) {
750 print $bankaccountstatic->getNomUrl(1, 'transactions');
751 }
752 print '</td>';
753 }
754 print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
755 print "</tr>";
756 $totalpaid += $objp->amount;
757 $i++;
758 }
759 } else {
760 print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
761 print '<td></td><td></td><td></td><td></td>';
762 print '</tr>';
763 }
764
765 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid")." :</td><td class=\"right\">".price($totalpaid)."</td></tr>\n";
766 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected")." :</td><td class=\"right\">".price($object->amount)."</td></tr>\n";
767
768 $resteapayer = $object->amount - $totalpaid;
769 $cssforamountpaymentcomplete = 'amountpaymentcomplete';
770
771 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
772 print '<td class="right'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
773
774 print "</table>";
775 print '</div>';
776
777 $db->free($resql);
778 } else {
779 dol_print_error($db);
780 }
781
782 print '</div>';
783 print '</div>';
784
785 print '<div class="clearboth"></div>';
786
787 print dol_get_fiche_end();
788
789 if ($action == 'edit') {
790 print $form->buttonsSaveCancel();
791
792 print "</form>\n";
793 }
794
795
796 // Buttons for actions
797
798 print '<div class="tabsAction">'."\n";
799
800 if ($action != 'edit') {
801 // Reopen
802 if ($object->paye && $user->hasRight('tax', 'charges', 'creer')) {
803 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen")."</a></div>";
804 }
805
806 // Edit
807 if ($object->paye == 0 && $user->hasRight('tax', 'charges', 'creer')) {
808 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify")."</a></div>";
809 }
810
811 // Emit payment
812 if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->hasRight('tax', 'charges', 'creer')) {
813 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/paiement_vat.php?id='.$object->id.'&action=create&token='.newToken().'">'.$langs->trans("DoPayment").'</a></div>';
814 }
815
816 // Classify 'paid'
817 if ($object->paye == 0
818 && (
819 (round($resteapayer) <= 0 && $object->amount > 0)
820 || (round($resteapayer) >= 0 && $object->amount < 0)
821 )
822 && $user->hasRight('tax', 'charges', 'creer')) {
823 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&token='.newToken().'&action=paid">'.$langs->trans("ClassifyPaid")."</a></div>";
824 }
825
826 // Clone
827 if ($user->hasRight('tax', 'charges', 'creer')) {
828 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&token='.newToken().'&action=clone">'.$langs->trans("ToClone")."</a></div>";
829 }
830
831 if ($user->hasRight('tax', 'charges', 'supprimer') && empty($totalpaid)) {
832 print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
833 } else {
834 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("DisabledBecausePayments"))).'">'.$langs->trans("Delete").'</a></div>';
835 }
836 }
837 print '</div>'."\n";
838
839
840
841 // Select mail models is same action as presend
842 if (GETPOST('modelselected')) {
843 $action = 'presend';
844 }
845
846 if ($action != 'presend') {
847 print '<div class="fichecenter"><div class="fichehalfleft">';
848 print '<a name="builddoc"></a>'; // ancre
849
850 $includedocgeneration = 1;
851
852 // Documents
853 if ($includedocgeneration) {
854 $objref = dol_sanitizeFileName($object->ref);
855 $relativepath = $objref.'/'.$objref.'.pdf';
856 $filedir = $conf->tax->dir_output.'/vat/'.$objref;
857 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
858 $genallowed = 0;
859 $delallowed = $user->hasRight('tax', 'charges', 'creer'); // If you can create/edit, you can remove a file on card
860 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
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
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.
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