dolibarr  16.0.5
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-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
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 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('compta', 'bills'));
40 
41 $mode = GETPOST("mode", 'alpha');
42 $year = GETPOST("year", 'int');
43 $filtre = GETPOST("filtre", 'alpha');
44 if (!$year && $mode != 'tvaonly') {
45  $year = date("Y", time());
46 }
47 
48 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
49 $sortfield = GETPOST('sortfield', 'aZ09comma');
50 $sortorder = GETPOST('sortorder', 'aZ09comma');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if (empty($page) || $page == -1) {
53  $page = 0;
54 } // If $page is not defined, or '' or -1
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 if (!$sortfield) {
59  $sortfield = "ptva.datep";
60 }
61 if (!$sortorder) {
62  $sortorder = "DESC";
63 }
64 
65 $object = new Tva($db);
66 
67 // Security check
68 if ($user->socid) {
69  $socid = $user->socid;
70 }
71 //$result = restrictedArea($user, 'tax|salaries', '', '', 'charges|');
72 $result = restrictedArea($user, 'tax', '', 'tva', 'charges');
73 
74 
75 /*
76  * View
77  */
78 
79 $tva_static = new Tva($db);
80 $tva = new Tva($db);
81 $accountlinestatic = new AccountLine($db);
82 $payment_vat_static = new PaymentVAT($db);
83 $sal_static = new PaymentSalary($db);
84 
85 llxHeader('', $langs->trans("VATExpensesArea"));
86 
87 $title = $langs->trans("VATPayments");
88 
89 $param = '';
90 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
91  $param .= '&contextpage='.$contextpage;
92 }
93 if ($limit > 0 && $limit != $conf->liste_limit) {
94  $param .= '&limit='.$limit;
95 }
96 if ($sortfield) {
97  $param .= '&sortfield='.$sortfield;
98 }
99 if ($sortorder) {
100  $param .= '&sortorder='.$sortorder;
101 }
102 
103 
104 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
105 if ($optioncss != '') {
106  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
107 }
108 print '<input type="hidden" name="token" value="'.newToken().'">';
109 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
110 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
111 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
112 print '<input type="hidden" name="page" value="'.$page.'">';
113 print '<input type="hidden" name="mode" value="'.$mode.'">';
114 
115 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'title_accountancy', 0, '', '', $limit);
116 
117 if ($year) {
118  $param .= '&year='.$year;
119 }
120 
121 if (isModEnabled('tax') && $user->rights->tax->charges->lire) {
122  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
123  print '<table class="noborder centpercent">';
124  print '<tr class="liste_titre">';
125  print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "ptva.rowid", "", $param, '', $sortfield, $sortorder);
126  print_liste_field_titre("VATDeclaration", $_SERVER["PHP_SELF"], "tva.rowid", "", $param, '', $sortfield, $sortorder);
127  print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "tva.label", "", $param, '', $sortfield, $sortorder);
128  print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "tva.datev", "", $param, '', $sortfield, $sortorder, 'nowraponall');
129  print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "ptva.datep", "", $param, 'align="center"', $sortfield, $sortorder);
130  print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
131  print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "ptva.num_paiement", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber');
132  if (isModEnabled('banque')) {
133  print_liste_field_titre("BankTransactionLine", $_SERVER["PHP_SELF"], "ptva.fk_bank", "", $param, '', $sortfield, $sortorder);
134  print_liste_field_titre("BankAccount", $_SERVER["PHP_SELF"], "bank.ref", "", $param, '', $sortfield, $sortorder);
135  }
136  //print_liste_field_titre("TypeContrib", $_SERVER["PHP_SELF"], "tva.fk_type", "", $param, '', $sortfield, $sortorder);
137  print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "tva.amount", "", $param, 'class="right"', $sortfield, $sortorder);
138  print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "ptva.amount", "", $param, 'class="right"', $sortfield, $sortorder);
139  print "</tr>\n";
140 
141  $sql = "SELECT tva.rowid, tva.label as label, b.fk_account, ptva.fk_bank";
142  $sql .= ", tva.datev";
143  $sql .= ", tva.amount as total,";
144  $sql .= " ptva.rowid as pid, ptva.datep, ptva.amount as totalpaid, ptva.num_paiement as num_payment,";
145  $sql .= " pct.code as payment_code";
146  $sql .= " FROM ".MAIN_DB_PREFIX."tva as tva,";
147  $sql .= " ".MAIN_DB_PREFIX."payment_vat as ptva";
148  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."bank as b ON (b.rowid = ptva.fk_bank)";
149  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."bank_account as bank ON (bank.rowid = b.fk_account)";
150  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON ptva.fk_typepaiement = pct.id";
151  $sql .= " WHERE ptva.fk_tva = tva.rowid";
152  $sql .= " AND tva.entity = ".$conf->entity;
153  if ($year > 0) {
154  $sql .= " AND (";
155  // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
156  // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
157  $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))."')";
158  $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))."')";
159  $sql .= ")";
160  }
161  if (preg_match('/^cs\./', $sortfield)
162  || preg_match('/^tva\./', $sortfield)
163  || preg_match('/^ptva\./', $sortfield)
164  || preg_match('/^pct\./', $sortfield)
165  || preg_match('/^bank\./', $sortfield)) {
166  $sql .= $db->order($sortfield, $sortorder);
167  }
168  //$sql.= $db->plimit($limit+1,$offset);
169  //print $sql;
170 
171  dol_syslog("compta/tva/payments.php: select payment", LOG_DEBUG);
172  $resql = $db->query($sql);
173  if ($resql) {
174  $num = $db->num_rows($resql);
175  $i = 0;
176  $total = 0;
177  $totalnb = 0;
178  $totalpaid = 0;
179 
180  while ($i < min($num, $limit)) {
181  $obj = $db->fetch_object($resql);
182 
183  $tva->id = $obj->rowid;
184  $tva->ref = $obj->rowid;
185  $tva->label = $obj->label;
186 
187  $payment_vat_static->id = $obj->pid;
188  $payment_vat_static->ref = $obj->pid;
189 
190  print '<tr class="oddeven">';
191 
192  // Ref payment
193  print '<td>'.$payment_vat_static->getNomUrl(1)."</td>\n";
194 
195  // VAT
196  print '<td>';
197  print $tva->getNomUrl(1, '20');
198  print '</td>';
199 
200  // Label
201  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->label).'">'.dol_escape_htmltag($obj->label).'</td>';
202 
203  // Date
204  $date = $db->jdate($obj->datev);
205  print '<td class="center nowraponall">'.dol_print_date($date, 'day').'</td>';
206 
207  // Date payment
208  $datep = $db->jdate($obj->datep);
209  print '<td class="center nowraponalls">'.dol_print_date($datep, 'day').'</td>';
210 
211  // Type payment
212  $labelpaymenttype = '';
213  if ($obj->payment_code) {
214  $labelpaymenttype = $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
215  }
216 
217  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labelpaymenttype).'">';
218  print dol_escape_htmltag($labelpaymenttype);
219  print '</td>';
220 
221  // Chq number
222  print '<td>'.dol_escape_htmltag($obj->num_payment).'</td>';
223 
224  if (isModEnabled('banque')) {
225  // Bank transaction
226  print '<td>';
227  $accountlinestatic->id = $obj->fk_bank;
228  print $accountlinestatic->getNomUrl(1);
229  print '</td>';
230 
231  // Account
232  print '<td>';
233  $account = new Account($db);
234  $account->fetch($obj->fk_account);
235  print $account->getNomUrl(1);
236  print '</td>';
237  }
238 
239  // Expected to pay
240  print '<td class="right"><span class="amount">'.price($obj->total).'</span></td>';
241 
242  // Paid
243  print '<td class="right"><span class="amount">';
244  if ($obj->totalpaid) {
245  print price($obj->totalpaid);
246  }
247  print '</span></td>';
248  print '</tr>';
249 
250  $total = $total + $obj->total;
251  $totalnb = $totalnb + $obj->nb;
252  $totalpaid = $totalpaid + $obj->totalpaid;
253  $i++;
254  }
255 
256  // Total
257  print '<tr class="liste_total"><td colspan="3" class="liste_total">'.$langs->trans("Total").'</td>';
258  print '<td class="liste_total right"></td>'; // A total here has no sense
259  print '<td align="center" class="liste_total">&nbsp;</td>';
260  print '<td align="center" class="liste_total">&nbsp;</td>';
261  if (isModEnabled('banque')) {
262  print '<td align="center" class="liste_total">&nbsp;</td>';
263  print '<td align="center" class="liste_total">&nbsp;</td>';
264  }
265  print '<td align="center" class="liste_total">&nbsp;</td>';
266  print '<td align="center" class="liste_total">&nbsp;</td>';
267  print '<td class="liste_total right">'.price($totalpaid)."</td>";
268  print "</tr>";
269  } else {
270  dol_print_error($db);
271  }
272  print '</table>';
273  print '</div>';
274 }
275 
276 print '</form>';
277 
278 // End of page
279 llxFooter();
280 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
PaymentSalary
Class to manage payments of salaries.
Definition: paymentsalary.class.php:34
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
PaymentVAT
Class to manage payments of social contributions.
Definition: paymentvat.class.php:33
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
print_barre_liste
print_barre_liste($titre, $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.
Definition: functions.lib.php:5257
dol_get_first_day
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:551
dol_get_last_day
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:570
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1757
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
price
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.
Definition: functions.lib.php:5541
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
Account
Class to manage bank accounts.
Definition: account.class.php:38
Tva
Put here description of your class.
Definition: tva.class.php:35