dolibarr 21.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 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Load Dolibarr environment
32require '../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
34require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
35require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/paymentvat.class.php';
36require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
37require_once DOL_DOCUMENT_ROOT . '/salaries/class/paymentsalary.class.php';
38require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
39
40// Load translation files required by the page
41$langs->loadLangs(array('compta', 'bills'));
42
43$mode = GETPOST("mode", 'alpha');
44$year = GETPOSTINT("year");
45$filtre = GETPOST("filtre", 'alpha');
46$optioncss = GETPOST('optioncss', 'alpha');
47if (!$year && $mode != 'tvaonly') {
48 $year = date("Y", time());
49}
50
51$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
52$sortfield = GETPOST('sortfield', 'aZ09comma');
53$sortorder = GETPOST('sortorder', 'aZ09comma');
54$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
55if (empty($page) || $page == -1) {
56 $page = 0;
57} // If $page is not defined, or '' or -1
58$offset = $limit * $page;
59$pageprev = $page - 1;
60$pagenext = $page + 1;
61if (!$sortfield) {
62 $sortfield = "ptva.datep";
63}
64if (!$sortorder) {
65 $sortorder = "DESC";
66}
67
68$object = new Tva($db);
69
70// Security check
71if ($user->socid) {
72 $socid = $user->socid;
73}
74//$result = restrictedArea($user, 'tax|salaries', '', '', 'charges|');
75$result = restrictedArea($user, 'tax', '', 'tva', 'charges');
76
77
78/*
79 * View
80 */
81
82$tva_static = new Tva($db);
83$tva = new Tva($db);
84$accountlinestatic = new AccountLine($db);
85$payment_vat_static = new PaymentVAT($db);
86$sal_static = new PaymentSalary($db);
87
88llxHeader('', $langs->trans("VATExpensesArea"));
89
90$title = $langs->trans("VATPayments");
91
92$param = '';
93if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
94 $param .= '&contextpage=' . $contextpage;
95}
96if ($limit > 0 && $limit != $conf->liste_limit) {
97 $param .= '&limit=' . $limit;
98}
99if ($sortfield) {
100 $param .= '&sortfield=' . $sortfield;
101}
102if ($sortorder) {
103 $param .= '&sortorder=' . $sortorder;
104}
105
106$center = '';
107
108if ($year) {
109 $param .= '&year=' . $year;
110}
111
112$sql = "SELECT tva.rowid, tva.label as label, b.fk_account, ptva.fk_bank";
113$sql .= ", tva.datev";
114$sql .= ", tva.amount as total,";
115$sql .= " ptva.rowid as pid, ptva.datep, ptva.amount as totalpaid, ptva.num_paiement as num_payment,";
116$sql .= " pct.code as payment_code";
117$sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva,";
118$sql .= " " . MAIN_DB_PREFIX . "payment_vat as ptva";
119$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank as b ON (b.rowid = ptva.fk_bank)";
120$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_account as bank ON (bank.rowid = b.fk_account)";
121$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_paiement as pct ON ptva.fk_typepaiement = pct.id";
122$sql .= " WHERE ptva.fk_tva = tva.rowid";
123$sql .= " AND tva.entity = " . $conf->entity;
124if ($year > 0) {
125 $sql .= " AND (";
126 // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
127 // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
128 $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)) . "')";
129 $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)) . "')";
130 $sql .= ")";
131}
132if (preg_match('/^cs\./', $sortfield)
133 || preg_match('/^tva\./', $sortfield)
134 || preg_match('/^ptva\./', $sortfield)
135 || preg_match('/^pct\./', $sortfield)
136 || preg_match('/^bank\./', $sortfield)) {
137 $sql .= $db->order($sortfield, $sortorder);
138}
139//$sql.= $db->plimit($limit+1,$offset);
140//print $sql;
141
142dol_syslog("compta/tva/payments.php: select payment", LOG_DEBUG);
143$resql = $db->query($sql);
144if ($resql) {
145 $num = $db->num_rows($resql);
146} else {
147 setEventMessages($db->lasterror, null, 'errors');
148}
149
150// @phan-suppress-next-line PhanPluginSuspiciousParamPosition, PhanPluginSuspiciousParamOrder
151print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $num, 'title_accountancy', 0, '', '', $limit);
152
153if (isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) {
154 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
155 if ($optioncss != '') {
156 print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
157 }
158 print '<input type="hidden" name="token" value="' . newToken() . '">';
159 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
160 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
161 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
162 print '<input type="hidden" name="page" value="' . $page . '">';
163 print '<input type="hidden" name="mode" value="' . $mode . '">';
164
165 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
166 print '<table class="noborder centpercent">';
167 print '<tr class="liste_titre">';
168 print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "ptva.rowid", "", $param, '', $sortfield, $sortorder);
169 print_liste_field_titre("VATDeclaration", $_SERVER["PHP_SELF"], "tva.rowid", "", $param, '', $sortfield, $sortorder);
170 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "tva.label", "", $param, '', $sortfield, $sortorder);
171 print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "tva.datev", "", $param, '', $sortfield, $sortorder, 'nowraponall');
172 print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "ptva.datep", "", $param, 'align="center"', $sortfield, $sortorder);
173 print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
174 print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "ptva.num_paiement", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber');
175 if (isModEnabled("bank")) {
176 print_liste_field_titre("BankTransactionLine", $_SERVER["PHP_SELF"], "ptva.fk_bank", "", $param, '', $sortfield, $sortorder);
177 print_liste_field_titre("BankAccount", $_SERVER["PHP_SELF"], "bank.ref", "", $param, '', $sortfield, $sortorder);
178 }
179 //print_liste_field_titre("TypeContrib", $_SERVER["PHP_SELF"], "tva.fk_type", "", $param, '', $sortfield, $sortorder);
180 print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "tva.amount", "", $param, 'class="right"', $sortfield, $sortorder);
181 print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "ptva.amount", "", $param, 'class="right"', $sortfield, $sortorder);
182 print "</tr>\n";
183
184 $sql = "SELECT tva.rowid, tva.label as label, b.fk_account, ptva.fk_bank";
185 $sql .= ", tva.datev";
186 $sql .= ", tva.amount as total,";
187 $sql .= " ptva.rowid as pid, ptva.datep, ptva.amount as totalpaid, ptva.num_paiement as num_payment,";
188 $sql .= " pct.code as payment_code";
189 $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva,";
190 $sql .= " " . MAIN_DB_PREFIX . "payment_vat as ptva";
191 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank as b ON (b.rowid = ptva.fk_bank)";
192 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_account as bank ON (bank.rowid = b.fk_account)";
193 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_paiement as pct ON ptva.fk_typepaiement = pct.id";
194 $sql .= " WHERE ptva.fk_tva = tva.rowid";
195 $sql .= " AND tva.entity = " . $conf->entity;
196 if ($year > 0) {
197 $sql .= " AND (";
198 // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
199 // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
200 $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)) . "')";
201 $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)) . "')";
202 $sql .= ")";
203 }
204 if ($sortfield !== null
205 && preg_match('/^(cs|tva|ptva|pct|bank)\./', $sortfield)
206 ) {
207 $sql .= $db->order($sortfield, $sortorder);
208 }
209
210 if ($num) {
211 $num = $db->num_rows($resql);
212 $i = 0;
213 $total = 0;
214 $totalnb = 0;
215 $totalpaid = 0;
216
217 while ($i < min($num, $limit)) {
218 $obj = $db->fetch_object($resql);
219
220 $tva->id = $obj->rowid;
221 $tva->ref = $obj->rowid;
222 $tva->label = $obj->label;
223
224 $payment_vat_static->id = $obj->pid;
225 $payment_vat_static->ref = $obj->pid;
226
227 print '<tr class="oddeven">';
228
229 // Ref payment
230 print '<td>' . $payment_vat_static->getNomUrl(1) . "</td>\n";
231
232 // VAT
233 print '<td>';
234 print $tva->getNomUrl(1, '20');
235 print '</td>';
236
237 // Label
238 print '<td class="tdoverflowmax150" title="' . dol_escape_htmltag($obj->label) . '">' . dol_escape_htmltag($obj->label) . '</td>';
239
240 // Date
241 $date = $db->jdate($obj->datev);
242 print '<td class="center nowraponall">' . dol_print_date($date, 'day') . '</td>';
243
244 // Date payment
245 $datep = $db->jdate($obj->datep);
246 print '<td class="center nowraponall">' . dol_print_date($datep, 'day') . '</td>';
247
248 // Type payment
249 $labelpaymenttype = '';
250 if ($obj->payment_code) {
251 $labelpaymenttype = $langs->trans("PaymentTypeShort" . $obj->payment_code) . ' ';
252 }
253
254 print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($labelpaymenttype) . '">';
255 print dol_escape_htmltag($labelpaymenttype);
256 print '</td>';
257
258 // Chq number
259 print '<td>' . dol_escape_htmltag($obj->num_payment) . '</td>';
260
261 if (isModEnabled("bank")) {
262 // Bank transaction
263 print '<td>';
264 $accountlinestatic->id = $obj->fk_bank;
265 print $accountlinestatic->getNomUrl(1);
266 print '</td>';
267
268 // Account
269 print '<td>';
270 $account = new Account($db);
271 $account->fetch($obj->fk_account);
272 print $account->getNomUrl(1);
273 print '</td>';
274 }
275
276 // Expected to pay
277 print '<td class="right"><span class="amount">' . price($obj->total) . '</span></td>';
278
279 // Paid
280 print '<td class="right"><span class="amount">';
281 if ($obj->totalpaid) {
282 print price($obj->totalpaid);
283 }
284 print '</span></td>';
285 print '</tr>';
286
287 $total += $obj->total;
288 $totalpaid += $obj->totalpaid;
289 $i++;
290 }
291
292 // Total
293 print '<tr class="liste_total"><td colspan="3" class="liste_total">' . $langs->trans("Total") . '</td>';
294 print '<td class="liste_total right"></td>'; // A total here has no sense
295 print '<td class="center liste_total">&nbsp;</td>';
296 print '<td class="center liste_total">&nbsp;</td>';
297 if (isModEnabled("bank")) {
298 print '<td class="center liste_total">&nbsp;</td>';
299 print '<td class="center liste_total">&nbsp;</td>';
300 }
301 print '<td class="center liste_total">&nbsp;</td>';
302 print '<td class="center liste_total">&nbsp;</td>';
303 print '<td class="liste_total right">' . price($totalpaid) . "</td>";
304 print "</tr>";
305 }
306 print '</table>';
307 print '</div>';
308
309 print '</form>';
310}
311
312// End of page
313llxFooter();
314$db->close();
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 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:596
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:615
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...
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.