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