dolibarr 25.0.0-alpha
payments.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2023 Alexandre Spangaro <aspangaro@easya.solutions>
6 * Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
8 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
9 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Load Dolibarr environment
33require '../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
42require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
43require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/paymentvat.class.php';
44require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
45require_once DOL_DOCUMENT_ROOT . '/salaries/class/paymentsalary.class.php';
46require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
47
48// Load translation files required by the page
49$langs->loadLangs(array('compta', 'bills'));
50
51$mode = GETPOST("mode", 'alpha');
52$year = GETPOSTINT("year");
53$filtre = GETPOST("filtre", 'alpha');
54$optioncss = GETPOST('optioncss', 'alpha');
55if (!$year && $mode != 'tvaonly') {
56 $year = (int) dol_print_date(dol_now(), "%Y");
57}
58
59$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
60$sortfield = (string) GETPOST('sortfield', 'aZ09comma');
61$sortorder = (string) GETPOST('sortorder', 'aZ09comma');
62$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
63if (empty($page) || $page == -1) {
64 $page = 0;
65} // If $page is not defined, or '' or -1
66$offset = $limit * $page;
67$pageprev = $page - 1;
68$pagenext = $page + 1;
69if (empty($sortfield)) {
70 $sortfield = "ptva.datep";
71}
72if (!$sortorder) {
73 $sortorder = "DESC";
74}
75
76$object = new Tva($db);
77
78// Security check
79if ($user->socid) {
80 $socid = $user->socid;
81}
82//restrictedArea($user, 'tax|salaries', '', '', 'charges|');
83$result = restrictedArea($user, 'tax', '', 'tva', 'charges');
84
85
86/*
87 * View
88 */
89
90$tva_static = new Tva($db);
91$tva = new Tva($db);
92$accountlinestatic = new AccountLine($db);
93$payment_vat_static = new PaymentVAT($db);
94$sal_static = new PaymentSalary($db);
95
96llxHeader('', $langs->trans("VATExpensesArea"));
97
98$title = $langs->trans("VATPayments");
99
100$param = '';
101if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
102 $param .= '&contextpage=' . $contextpage;
103}
104if ($limit > 0 && $limit != $conf->liste_limit) {
105 $param .= '&limit=' . $limit;
106}
107if ($sortfield) {
108 $param .= '&sortfield=' . $sortfield;
109}
110if ($sortorder) {
111 $param .= '&sortorder=' . $sortorder;
112}
113
114$center = '';
115
116if ($year) {
117 $param .= '&year=' . $year;
118}
119
120$sql = "SELECT tva.rowid, tva.label as label, b.fk_account, ptva.fk_bank";
121$sql .= ", tva.datev";
122$sql .= ", tva.amount as total,";
123$sql .= " ptva.rowid as pid, ptva.datep, ptva.amount as totalpaid, ptva.num_paiement as num_payment,";
124$sql .= " pct.code as payment_code";
125$sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva,";
126$sql .= " " . MAIN_DB_PREFIX . "payment_vat as ptva";
127$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank as b ON (b.rowid = ptva.fk_bank)";
128$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_account as bank ON (bank.rowid = b.fk_account)";
129$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_paiement as pct ON ptva.fk_typepaiement = pct.id";
130$sql .= " WHERE ptva.fk_tva = tva.rowid";
131$sql .= " AND tva.entity = " . ((int) $conf->entity);
132if ($year > 0) {
133 $sql .= " AND (";
134 // If the date range is provided, use it as a lookup condition. Otherwise we use the due date.
135 // This ensures compatibilituy for the cases where the period is not mandatory
136 $sql .= " (tva.datev IS NOT NULL AND tva.datev between '" . $db->idate(dol_get_first_day($year)) . "' AND '" . $db->idate(dol_get_last_day($year)) . "')";
137 $sql .= " OR (tva.datev IS NULL AND tva.datev between '" . $db->idate(dol_get_first_day($year)) . "' AND '" . $db->idate(dol_get_last_day($year)) . "')";
138 $sql .= ")";
139}
140$sortfield = (string) $sortfield; // Avoid phan notice
141if (preg_match('/^cs\./', $sortfield)
142 || preg_match('/^tva\./', $sortfield)
143 || preg_match('/^ptva\./', $sortfield)
144 || preg_match('/^pct\./', $sortfield)
145 || preg_match('/^bank\./', $sortfield)) {
146 $sql .= $db->order($sortfield, (string) $sortorder);
147}
148//$sql.= $db->plimit($limit+1,$offset);
149//print $sql;
150
151dol_syslog("compta/tva/payments.php: select payment", LOG_DEBUG);
152$num = 0;
153$resql = $db->query($sql);
154if ($resql) {
155 $num = $db->num_rows($resql);
156} else {
157 setEventMessages($db->lasterror, null, 'errors');
158}
159
160// @phan-suppress-next-line PhanPluginSuspiciousParamPosition, PhanPluginSuspiciousParamOrder
161print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $num, 'title_accountancy', 0, '', '', $limit);
162
163if (isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) {
164 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
165 if ($optioncss != '') {
166 print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
167 }
168 print '<input type="hidden" name="token" value="' . newToken() . '">';
169 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
170 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
171 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
172 print '<input type="hidden" name="page" value="' . $page . '">';
173 print '<input type="hidden" name="mode" value="' . $mode . '">';
174
175 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
176 print '<table class="noborder centpercent">';
177 print '<tr class="liste_titre">';
178 print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "ptva.rowid", "", $param, '', $sortfield, $sortorder);
179 print_liste_field_titre("VATDeclaration", $_SERVER["PHP_SELF"], "tva.rowid", "", $param, '', $sortfield, $sortorder);
180 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "tva.label", "", $param, '', $sortfield, $sortorder);
181 print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "tva.datev", "", $param, '', $sortfield, $sortorder, 'nowraponall');
182 print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "ptva.datep", "", $param, 'align="center"', $sortfield, $sortorder);
183 print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
184 print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "ptva.num_paiement", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber');
185 if (isModEnabled("bank")) {
186 print_liste_field_titre("BankTransactionLine", $_SERVER["PHP_SELF"], "ptva.fk_bank", "", $param, '', $sortfield, $sortorder);
187 print_liste_field_titre("BankAccount", $_SERVER["PHP_SELF"], "bank.ref", "", $param, '', $sortfield, $sortorder);
188 }
189 //print_liste_field_titre("TypeContrib", $_SERVER["PHP_SELF"], "tva.fk_type", "", $param, '', $sortfield, $sortorder);
190 print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "tva.amount", "", $param, 'class="right"', $sortfield, $sortorder);
191 print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "ptva.amount", "", $param, 'class="right"', $sortfield, $sortorder);
192 print "</tr>\n";
193
194 $sql = "SELECT tva.rowid, tva.label as label, b.fk_account, ptva.fk_bank";
195 $sql .= ", tva.datev";
196 $sql .= ", tva.amount as total,";
197 $sql .= " ptva.rowid as pid, ptva.datep, ptva.amount as totalpaid, ptva.num_paiement as num_payment,";
198 $sql .= " pct.code as payment_code";
199 $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva,";
200 $sql .= " " . MAIN_DB_PREFIX . "payment_vat as ptva";
201 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank as b ON (b.rowid = ptva.fk_bank)";
202 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_account as bank ON (bank.rowid = b.fk_account)";
203 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_paiement as pct ON ptva.fk_typepaiement = pct.id";
204 $sql .= " WHERE ptva.fk_tva = tva.rowid";
205 $sql .= " AND tva.entity = " . ((int) $conf->entity);
206 if ($year > 0) {
207 $sql .= " AND (";
208 // We'll use the specified period as the date filter, unless it's missing, in which case we'll use the due date.
209 // This is to handle situations where the period was optional.
210 $sql .= " (tva.datev IS NOT NULL AND tva.datev between '" . $db->idate(dol_get_first_day($year)) . "' AND '" . $db->idate(dol_get_last_day($year)) . "')";
211 $sql .= " OR (tva.datev IS NULL AND tva.datev between '" . $db->idate(dol_get_first_day($year)) . "' AND '" . $db->idate(dol_get_last_day($year)) . "')";
212 $sql .= ")";
213 }
214 if (preg_match('/^(cs|tva|ptva|pct|bank)\./', $sortfield)
215 ) {
216 $sql .= $db->order($sortfield, (string) $sortorder);
217 }
218
219 if ($num) {
220 $num = $db->num_rows($resql);
221 $i = 0;
222 $total = 0;
223 $totalnb = 0;
224 $totalpaid = 0;
225
226 while ($i < min($num, $limit)) {
227 $obj = $db->fetch_object($resql);
228
229 $tva->id = $obj->rowid;
230 $tva->ref = $obj->rowid;
231 $tva->label = $obj->label;
232
233 $payment_vat_static->id = $obj->pid;
234 $payment_vat_static->ref = $obj->pid;
235
236 print '<tr class="oddeven">';
237
238 // Ref payment
239 print '<td>' . $payment_vat_static->getNomUrl(1) . "</td>\n";
240
241 // VAT
242 print '<td>';
243 print $tva->getNomUrl(1, '20');
244 print '</td>';
245
246 // Label
247 print '<td class="tdoverflowmax150" title="' . dol_escape_htmltag($obj->label) . '">' . dol_escape_htmltag($obj->label) . '</td>';
248
249 // Date
250 $date = $db->jdate($obj->datev);
251 print '<td class="center nowraponall">' . dol_print_date($date, 'day') . '</td>';
252
253 // Date payment
254 $datep = $db->jdate($obj->datep);
255 print '<td class="center nowraponall">' . dol_print_date($datep, 'day') . '</td>';
256
257 // Type payment
258 $labelpaymenttype = '';
259 if ($obj->payment_code) {
260 $labelpaymenttype = $langs->trans("PaymentTypeShort" . $obj->payment_code) . ' ';
261 }
262
263 print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($labelpaymenttype) . '">';
264 print dol_escape_htmltag($labelpaymenttype);
265 print '</td>';
266
267 // Chq number
268 print '<td>' . dol_escape_htmltag($obj->num_payment) . '</td>';
269
270 if (isModEnabled("bank")) {
271 // Bank transaction
272 print '<td>';
273 $accountlinestatic->id = $obj->fk_bank;
274 print $accountlinestatic->getNomUrl(1);
275 print '</td>';
276
277 // Account
278 print '<td>';
279 $account = new Account($db);
280 $account->fetch($obj->fk_account);
281 print $account->getNomUrl(1);
282 print '</td>';
283 }
284
285 // Expected to pay
286 print '<td class="right"><span class="amount">' . price($obj->total) . '</span></td>';
287
288 // Paid
289 print '<td class="right"><span class="amount">';
290 if ($obj->totalpaid) {
291 print price($obj->totalpaid);
292 }
293 print '</span></td>';
294 print '</tr>';
295
296 $total += $obj->total;
297 $totalpaid += $obj->totalpaid;
298 $i++;
299 }
300
301 // Total
302 print '<tr class="liste_total"><td colspan="3" class="liste_total">' . $langs->trans("Total") . '</td>';
303 print '<td class="liste_total right"></td>'; // A total here has no sense
304 print '<td class="center liste_total">&nbsp;</td>';
305 print '<td class="center liste_total">&nbsp;</td>';
306 if (isModEnabled("bank")) {
307 print '<td class="center liste_total">&nbsp;</td>';
308 print '<td class="center liste_total">&nbsp;</td>';
309 }
310 print '<td class="center liste_total">&nbsp;</td>';
311 print '<td class="center liste_total">&nbsp;</td>';
312 print '<td class="liste_total right">' . price($totalpaid) . "</td>";
313 print "</tr>";
314 }
315 print '</table>';
316 print '</div>';
317
318 print '</form>';
319}
320
321// End of page
322llxFooter();
323$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage bank accounts.
Class to manage bank transaction lines.
Class to manage payments of salaries.
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
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:616
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:635
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
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, $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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.