dolibarr 24.0.1
paiement_vat.php
1<?php
2/* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2016-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
32
41// Load translation files required by the page
42$langs->loadLangs(array("banks", "bills"));
43
44$action = GETPOST('action', 'alpha');
45$confirm = GETPOST('confirm', 'alpha');
46$cancel = GETPOST('cancel', 'alpha');
47
48$chid = GETPOSTINT("id");
49$amounts = array();
50
51// Security check
52$socid = 0;
53if ($user->socid > 0) {
54 $socid = $user->socid;
55}
56
57$permissiontoadd = $user->hasRight('tax', 'charges', 'creer');
58
59// The page has no access check at all: main.inc.php only requires a session, and Tva::fetch()
60// selects on rowid without filtering the entity. Same call as compta/tva/card.php makes on the
61// declaration itself, so reading and paying one requires the rights on it.
62restrictedArea($user, 'tax', $chid, 'tva', 'charges');
63
64
65/*
66 * Actions
67 */
68
69if (($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) && $permissiontoadd) {
70 $error = 0;
71
72 if ($cancel) {
73 $loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid;
74 header("Location: ".$loc);
75 exit;
76 }
77
78 $datepaye = dol_mktime(12, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear"));
79
80 if (!(GETPOSTINT("paiementtype") > 0)) {
81 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
82 $error++;
83 $action = 'create';
84 }
85 if ($datepaye == '') {
86 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
87 $error++;
88 $action = 'create';
89 }
90 if (isModEnabled("bank") && !(GETPOSTINT("accountid") > 0)) {
91 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors');
92 $error++;
93 $action = 'create';
94 }
95
96 // Read possible payments
97 foreach ($_POST as $key => $value) {
98 if (substr($key, 0, 7) == 'amount_') {
99 $other_chid = substr($key, 7);
100 $amounts[$other_chid] = (float) price2num(GETPOST($key));
101 }
102 }
103
104 if (empty($amounts[key($amounts)])) {
105 $error++;
106 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
107 $action = 'create';
108 }
109
110 if (!$error) {
111 $paymentid = 0;
112
113 if (!$error) {
114 $db->begin();
115
116 // Create a line of payments
117 $paiement = new PaymentVAT($db);
118 $paiement->chid = $chid;
119 $paiement->datepaye = $datepaye;
120 $paiement->amounts = $amounts; // Tableau de montant
121 $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml');
122 $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
123 $paiement->note = (string) GETPOST("note", 'restricthtml');
124 $paiement->note_private = (string) GETPOST("note", 'restricthtml');
125
126 if (!$error) {
127 $paymentid = $paiement->create($user, (GETPOST('closepaidvat') == 'on' ? 1 : 0));
128 if ($paymentid < 0) {
129 $error++;
130 setEventMessages($paiement->error, null, 'errors');
131 $action = 'create';
132 }
133 }
134
135 if (!$error) {
136 $result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOSTINT('accountid'), '', '');
137 if (!($result > 0)) {
138 $error++;
139 setEventMessages($paiement->error, null, 'errors');
140 $action = 'create';
141 }
142 }
143
144 if (!$error) {
145 $db->commit();
146 $loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid;
147 header('Location: '.$loc);
148 exit;
149 } else {
150 $db->rollback();
151 }
152 }
153 }
154}
155
156
157/*
158 * View
159 */
160
161llxHeader();
162
163$form = new Form($db);
164
165
166// Payment charge payment form
167if ($action == 'create') {
168 $tva = new Tva($db);
169
170 $tva->fetch($chid);
171
172 $tva->accountid = $tva->fk_account ? $tva->fk_account : $tva->accountid;
173 $tva->paiementtype = $tva->type_payment;
174
175 if (!empty($conf->use_javascript_ajax)) {
176 print "\n".'<script type="text/javascript">';
177
178 //Add js for AutoFill
179 print ' $(document).ready(function () {';
180 print ' $(".AutoFillAmount").on(\'click touchstart\', function(){
181 var amount = $(this).data("value");
182 document.getElementById($(this).data(\'rowid\')).value = amount ;
183 });';
184 print ' });'."\n";
185
186 print ' </script>'."\n";
187 }
188
189 print load_fiche_titre($langs->trans("DoPayment"));
190
191 print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">';
192 print '<input type="hidden" name="token" value="'.newToken().'">';
193 print '<input type="hidden" name="id" value="'.$chid.'">';
194 print '<input type="hidden" name="chid" value="'.$chid.'">';
195 print '<input type="hidden" name="action" value="add_payment">';
196
197 print dol_get_fiche_head([], '');
198
199 print '<table class="border centpercent">';
200
201 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td><a href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid.'">'.$chid.'</a></td></tr>';
202 //print '<tr><td>'.$langs->trans("Type")."</td><td>".$tva->type_label."</td></tr>\n";
203 print '<tr><td>'.$langs->trans("Period")."</td><td>".dol_print_date($tva->datev, 'day')."</td></tr>\n";
204 print '<tr><td>'.$langs->trans("Label").'</td><td>'.$tva->label."</td></tr>\n";
205 /*print '<tr><td>'.$langs->trans("DateDue")."</td><td>".dol_print_date($tva->date_ech,'day')."</td></tr>\n";
206 print '<tr><td>'.$langs->trans("Amount")."</td><td>".price($tva->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';*/
207
208 $sql = "SELECT sum(p.amount) as total";
209 $sql .= " FROM ".MAIN_DB_PREFIX."payment_vat as p";
210 $sql .= " WHERE p.fk_tva = ".((int) $chid);
211 $sumpaid = 0;
212 $resql = $db->query($sql);
213 if ($resql) {
214 $obj = $db->fetch_object($resql);
215 $sumpaid = $obj->total;
216 $db->free($resql);
217 }
218 /*print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td>'.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
219 print '<tr><td class="tdtop">'.$langs->trans("RemainderToPay").'</td><td>'.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';*/
220
221 print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
222 $datepaye = dol_mktime(12, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear"));
223 $datepayment = getDolGlobalString('MAIN_AUTOFILL_DATE') ? 0 : (GETPOSTINT("remonth") ? $datepaye : -1);
224 print $form->selectDate($datepayment, '', 0, 0, 0, "add_payment", 1, 1);
225 print "</td>";
226 print '</tr>';
227
228 print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
229 print $form->select_types_paiements(GETPOSTISSET("paiementtype") ? GETPOSTINT("paiementtype") : $tva->paiementtype, "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx', 1);
230 print "</td>\n";
231 print '</tr>';
232
233 print '<tr>';
234 print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>';
235 print '<td>';
236 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
237 $form->select_comptes(GETPOSTINT("accountid") ? GETPOSTINT("accountid") : $tva->accountid, "accountid", 0, '', 1, '', 0, 'maxwidth500 widthcentpercentminusx'); // Show opened bank account list
238 print '</td></tr>';
239
240 // Number
241 print '<tr><td>'.$langs->trans('Numero');
242 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
243 print '</td>';
244 print '<td><input name="num_payment" type="text" value="'.GETPOST('num_payment', 'alphanohtml').'"></td></tr>'."\n";
245
246 print '<tr>';
247 print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
248 print '<td class="tdtop"><textarea name="note" class="quatrevingtpercent" wrap="soft" rows="'.ROWS_3.'"></textarea></td>';
249 print '</tr>';
250
251 print '</table>';
252
253 print dol_get_fiche_end();
254
255 print '<br>';
256
257
258 // List of VAT unpaid
259 $num = 1;
260 $i = 0;
261
262 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
263 print '<table class="noborder centpercent">';
264 print '<tr class="liste_titre">';
265 //print '<td>'.$langs->trans("SocialContribution").'</td>';
266 print '<td class="left">'.$langs->trans("DateDue").'</td>';
267 print '<td class="right">'.$langs->trans("Amount").'</td>';
268 print '<td class="right">'.$langs->trans("AlreadyPaid").'</td>';
269 print '<td class="right">'.$langs->trans("RemainderToPay").'</td>';
270 print '<td class="center">'.$langs->trans("Amount").'</td>';
271 print "</tr>\n";
272
273 $total = 0;
274 $total_ttc = 0.;
275 $totalrecu = 0;
276
277 while ($i < $num) {
278 $objp = $tva;
279
280 print '<tr class="oddeven">';
281
282 if ($objp->datev > 0) {
283 print '<td class="left">'.dol_print_date($objp->datev, 'day').'</td>'."\n";
284 } else {
285 print '<td class="center"><b>!!!</b></td>'."\n";
286 }
287
288 print '<td class="right nowraponall"><span class="amount">'.price($objp->amount)."</span></td>";
289
290 print '<td class="right nowraponall"><span class="amount">'.price($sumpaid)."</span></td>";
291
292 print '<td class="right nowraponall"><span class="amount">'.price((float) $objp->amount - $sumpaid)."</span></td>";
293
294 print '<td class="center">';
295
296 if ($sumpaid != $objp->amount) {
297 $namef = "amount_".$objp->id;
298 $nameRemain = "remain_".$objp->id;
299 /* Disabled, we autofil the amount with remain to pay by default
300 if (!empty($conf->use_javascript_ajax)) {
301 print img_picto("Auto fill", 'rightarrow.png', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'");
302 } */
303 $remaintopay = (float) $objp->amount - $sumpaid;
304 print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
305 print '<input type="text" class="right width75" name="'.$namef.'" id="'.$namef.'" value="'.$remaintopay.'">';
306 } else {
307 print '-';
308 }
309 print "</td>";
310
311 print "</tr>\n";
312 $total += $objp->amount;
313 $total_ttc += $objp->total_ttc; // same than ->amount for vat object
314 $totalrecu += $objp->amount;
315 $i++;
316 }
317 if ($i > 1) {
318 // Print total
319 print '<tr class="oddeven">';
320 print '<td colspan="2" class="left">'.$langs->trans("Total").':</td>';
321 print '<td class="right"><b>'.price($total_ttc).'</b></td>';
322 print '<td class="right"><b>'.price($totalrecu).'</b></td>';
323 print '<td class="right"><b>'.price($total_ttc - $totalrecu).'</b></td>';
324 print '<td align="center">&nbsp;</td>';
325 print "</tr>\n";
326 }
327
328 print "</table>";
329 print '</div>';
330
331 // Bouton Save payment
332 print '<br><div class="center"><input type="checkbox" checked name="closepaidvat" id="closepaidvat" class="marginrightonly opecitymedium"><label for="closepaidvat" class="opacitymedium">'.$langs->trans("ClosePaidVATAutomatically").'</label>';
333 print '<br>';
334 print '<input type="submit" class="button" name="save" value="'.$langs->trans('ToMakePayment').'">';
335 print ' &nbsp; &nbsp;';
336 print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
337 print '</div>';
338
339 print "</form>\n";
340}
341
342llxFooter();
343$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
Class to manage payments of social contributions.
Class to manage VAT - Value-added tax (also known in French as TVA)
Definition tva.class.php:39
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.