dolibarr 21.0.0-beta
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 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';
34require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.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 . '/salaries/class/paymentsalary.class.php';
39require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
40
49// Load translation files required by the page
50$langs->loadLangs(array('compta', 'bills'));
51
52$mode = GETPOST("mode", 'alpha');
53$year = GETPOSTINT("year");
54$filtre = GETPOST("filtre", 'alpha');
55$optioncss = GETPOST('optioncss', 'alpha');
56if (!$year && $mode != 'tvaonly') {
57 $year = date("Y", time());
58}
59
60$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
61$sortfield = GETPOST('sortfield', 'aZ09comma');
62$sortorder = GETPOST('sortorder', 'aZ09comma');
63$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
64if (empty($page) || $page == -1) {
65 $page = 0;
66} // If $page is not defined, or '' or -1
67$offset = $limit * $page;
68$pageprev = $page - 1;
69$pagenext = $page + 1;
70if (empty($sortfield)) {
71 $sortfield = "ptva.datep";
72}
73if (!$sortorder) {
74 $sortorder = "DESC";
75}
76
77$object = new Tva($db);
78
79// Security check
80if ($user->socid) {
81 $socid = $user->socid;
82}
83//$result = restrictedArea($user, 'tax|salaries', '', '', 'charges|');
84$result = restrictedArea($user, 'tax', '', 'tva', 'charges');
85
86
87/*
88 * View
89 */
90
91$tva_static = new Tva($db);
92$tva = new Tva($db);
93$accountlinestatic = new AccountLine($db);
94$payment_vat_static = new PaymentVAT($db);
95$sal_static = new PaymentSalary($db);
96
97llxHeader('', $langs->trans("VATExpensesArea"));
98
99$title = $langs->trans("VATPayments");
100
101$param = '';
102if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
103 $param .= '&contextpage=' . $contextpage;
104}
105if ($limit > 0 && $limit != $conf->liste_limit) {
106 $param .= '&limit=' . $limit;
107}
108if ($sortfield) {
109 $param .= '&sortfield=' . $sortfield;
110}
111if ($sortorder) {
112 $param .= '&sortorder=' . $sortorder;
113}
114
115$center = '';
116
117if ($year) {
118 $param .= '&year=' . $year;
119}
120
121$sql = "SELECT tva.rowid, tva.label as label, b.fk_account, ptva.fk_bank";
122$sql .= ", tva.datev";
123$sql .= ", tva.amount as total,";
124$sql .= " ptva.rowid as pid, ptva.datep, ptva.amount as totalpaid, ptva.num_paiement as num_payment,";
125$sql .= " pct.code as payment_code";
126$sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva,";
127$sql .= " " . MAIN_DB_PREFIX . "payment_vat as ptva";
128$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank as b ON (b.rowid = ptva.fk_bank)";
129$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_account as bank ON (bank.rowid = b.fk_account)";
130$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_paiement as pct ON ptva.fk_typepaiement = pct.id";
131$sql .= " WHERE ptva.fk_tva = tva.rowid";
132$sql .= " AND tva.entity = " . $conf->entity;
133if ($year > 0) {
134 $sql .= " AND (";
135 // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
136 // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
137 $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)) . "')";
138 $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)) . "')";
139 $sql .= ")";
140}
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, $sortorder);
147}
148//$sql.= $db->plimit($limit+1,$offset);
149//print $sql;
150
151dol_syslog("compta/tva/payments.php: select payment", LOG_DEBUG);
152$resql = $db->query($sql);
153if ($resql) {
154 $num = $db->num_rows($resql);
155} else {
156 setEventMessages($db->lasterror, null, 'errors');
157}
158
159// @phan-suppress-next-line PhanPluginSuspiciousParamPosition, PhanPluginSuspiciousParamOrder
160print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $num, 'title_accountancy', 0, '', '', $limit);
161
162if (isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) {
163 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
164 if ($optioncss != '') {
165 print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
166 }
167 print '<input type="hidden" name="token" value="' . newToken() . '">';
168 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
169 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
170 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
171 print '<input type="hidden" name="page" value="' . $page . '">';
172 print '<input type="hidden" name="mode" value="' . $mode . '">';
173
174 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
175 print '<table class="noborder centpercent">';
176 print '<tr class="liste_titre">';
177 print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "ptva.rowid", "", $param, '', $sortfield, $sortorder);
178 print_liste_field_titre("VATDeclaration", $_SERVER["PHP_SELF"], "tva.rowid", "", $param, '', $sortfield, $sortorder);
179 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "tva.label", "", $param, '', $sortfield, $sortorder);
180 print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "tva.datev", "", $param, '', $sortfield, $sortorder, 'nowraponall');
181 print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "ptva.datep", "", $param, 'align="center"', $sortfield, $sortorder);
182 print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
183 print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "ptva.num_paiement", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber');
184 if (isModEnabled("bank")) {
185 print_liste_field_titre("BankTransactionLine", $_SERVER["PHP_SELF"], "ptva.fk_bank", "", $param, '', $sortfield, $sortorder);
186 print_liste_field_titre("BankAccount", $_SERVER["PHP_SELF"], "bank.ref", "", $param, '', $sortfield, $sortorder);
187 }
188 //print_liste_field_titre("TypeContrib", $_SERVER["PHP_SELF"], "tva.fk_type", "", $param, '', $sortfield, $sortorder);
189 print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "tva.amount", "", $param, 'class="right"', $sortfield, $sortorder);
190 print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "ptva.amount", "", $param, 'class="right"', $sortfield, $sortorder);
191 print "</tr>\n";
192
193 $sql = "SELECT tva.rowid, tva.label as label, b.fk_account, ptva.fk_bank";
194 $sql .= ", tva.datev";
195 $sql .= ", tva.amount as total,";
196 $sql .= " ptva.rowid as pid, ptva.datep, ptva.amount as totalpaid, ptva.num_paiement as num_payment,";
197 $sql .= " pct.code as payment_code";
198 $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva,";
199 $sql .= " " . MAIN_DB_PREFIX . "payment_vat as ptva";
200 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank as b ON (b.rowid = ptva.fk_bank)";
201 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_account as bank ON (bank.rowid = b.fk_account)";
202 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_paiement as pct ON ptva.fk_typepaiement = pct.id";
203 $sql .= " WHERE ptva.fk_tva = tva.rowid";
204 $sql .= " AND tva.entity = " . $conf->entity;
205 if ($year > 0) {
206 $sql .= " AND (";
207 // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
208 // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
209 $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)) . "')";
210 $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)) . "')";
211 $sql .= ")";
212 }
213 if ($sortfield !== null
214 && preg_match('/^(cs|tva|ptva|pct|bank)\./', $sortfield)
215 ) {
216 $sql .= $db->order($sortfield, $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( $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 payments of salaries.
Class to manage payments of social contributions.
Class to manage VAT - Value-added tax (also known in French as TVA - Taxe sur la valeur ajoutée)
Definition tva.class.php:38
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:600
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
llxFooter()
Footer empty.
Definition document.php:107
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.