dolibarr 21.0.0-beta
factures.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
37require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
38
47// Load translation files required by the page
48$langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'withdrawals', 'salaries', 'suppliers'));
49
50$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
51$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
52
53// Get supervariables
54$id = GETPOSTINT('id');
55$ref = GETPOST('ref', 'alpha');
56$socid = GETPOSTINT('socid');
57$userid = GETPOSTINT('userid');
58$type = GETPOST('type', 'aZ09');
59
60// Load variable for pagination
61$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
62$sortfield = GETPOST('sortfield', 'aZ09comma');
63$sortorder = GETPOST('sortorder', 'aZ09comma');
64$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
65if (empty($page) || $page == -1) {
66 $page = 0;
67} // If $page is not defined, or '' or -1
68$offset = $limit * $page;
69$pageprev = $page - 1;
70$pagenext = $page + 1;
71if (!$sortfield) {
72 $sortfield = 'p.ref';
73}
74if (!$sortorder) {
75 $sortorder = 'DESC';
76}
77
78$object = new BonPrelevement($db);
79
80// Load object
81include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
82
83$hookmanager->initHooks(array('directdebitprevcard', 'globalcard', 'directdebitprevlist'));
84
85// Security check
86if ($user->socid > 0) {
88}
89
90$type = $object->type;
91$salaryBonPl = $object->checkIfSalaryBonPrelevement();
92if ($type == 'bank-transfer') {
93 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
94} else {
95 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
96}
97
98
99/*
100 * View
101 */
102
103$form = new Form($db);
104$invoicetmp = new Facture($db);
105$thirdpartytmp = new Societe($db);
106
107llxHeader('', $langs->trans("WithdrawalsReceipts"));
108
109if ($id > 0 || $ref) {
110 if (empty($object->id)) {
111 $langs->load('errors');
112 echo '<div class="error">'.$langs->trans("ErrorRecordNotFound").'</div>';
113 llxFooter();
114 exit;
115 }
116
117 $head = prelevement_prepare_head($object);
118
119 print dol_get_fiche_head($head, 'invoices', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
120
121 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/orders_list.php?restore_lastsearch_values=1'.($object->type != 'bank-transfer' ? '' : '&type=bank-transfer').'">'.$langs->trans("BackToList").'</a>';
122
123 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
124
125 print '<div class="fichecenter">';
126 print '<div class="underbanner clearboth"></div>';
127 print '<table class="border centpercent tableforfield">'."\n";
128
129 //print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
130 print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
131 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
132
133 if (!empty($object->date_trans)) {
134 $muser = new User($db);
135 $muser->fetch($object->user_trans);
136
137 print '<tr><td>'.$langs->trans("TransData").'</td><td>';
138 print dol_print_date($object->date_trans, 'day');
139 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
140 print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
141 print $object->methodes_trans[$object->method_trans];
142 print '</td></tr>';
143 }
144 if (!empty($object->date_credit)) {
145 print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
146 print dol_print_date($object->date_credit, 'day');
147 print '</td></tr>';
148 }
149
150 print '</table>';
151
152 print '<br>';
153
154 print '<div class="underbanner clearboth"></div>';
155 print '<table class="border centpercent tableforfield">';
156
157 // Get bank account for the payment
158 $acc = new Account($db);
159 $fk_bank_account = $object->fk_bank_account;
160 if (empty($fk_bank_account)) {
161 $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
162 }
163 if ($fk_bank_account > 0) {
164 $result = $acc->fetch($fk_bank_account);
165 }
166
167 $labelofbankfield = "BankToReceiveWithdraw";
168 if ($object->type == 'bank-transfer') {
169 $labelofbankfield = 'BankToPayCreditTransfer';
170 }
171
172 print '<tr><td class="titlefieldcreate">';
173 print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
174 print '</td>';
175
176 print '<td>';
177 if ($acc->id > 0) {
178 print $acc->getNomUrl(1);
179 }
180 print '</td>';
181 print '</tr>';
182
183 $modulepart = 'prelevement';
184 if ($object->type == 'bank-transfer') {
185 $modulepart = 'paymentbybanktransfer';
186 }
187
188 print '<tr><td class="titlefieldcreate">';
189 $labelfororderfield = 'WithdrawalFile';
190 if ($object->type == 'bank-transfer') {
191 $labelfororderfield = 'CreditTransferFile';
192 }
193 print $langs->trans($labelfororderfield).'</td><td>';
194
195 if (isModEnabled('multicompany')) {
196 $labelentity = $conf->entity;
197 $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
198
199 if ($type != 'bank-transfer') {
200 $dir = $conf->prelevement->dir_output;
201 } else {
202 $dir = $conf->paymentbybanktransfer->dir_output;
203 }
204 if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
205 $relativepath = 'receipts/'.$object->ref.'.xml';
206 }
207 } else {
208 $relativepath = 'receipts/'.$object->ref.'.xml';
209 }
210
211 print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
212 print img_picto('', 'download', 'class="paddingleft"');
213 print '</a>';
214 print '</td></tr></table>';
215
216 print '</div>';
217
218 print dol_get_fiche_end();
219}
220
221
222// List of invoices or salaries
223if ($salaryBonPl) {
224 $sql = "SELECT pf.rowid, p.type,";
225 $sql .= " f.rowid as salaryid, f.ref as ref, f.amount,";
226 $sql .= " u.rowid as userid, u.firstname, u.lastname, pl.statut as status, pl.amount as amount_requested";
227 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
228 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."prelevement_lignes as pl ON pl.fk_prelevement_bons = p.rowid";
229 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."prelevement as pf ON pf.fk_prelevement_lignes = pl.rowid";
230 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as f ON f.rowid = pf.fk_salary AND f.entity IN (".getEntity('salary').")";
231 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON f.fk_user = u.rowid";
232 $sql .= " WHERE 1 = 1";
233 if ($object->id > 0) {
234 $sql .= " AND p.rowid = ".((int) $object->id);
235 }
236 if ($userid > 0) {
237 $sql .= " AND u.rowid = ".((int) $userid);
238 }
239} else {
240 $sql = "SELECT pf.rowid, p.type,";
241 $sql .= " f.rowid as facid, f.ref as ref, f.total_ttc,";
242 if ($object->type == 'bank-transfer') {
243 $sql .= " f.ref_supplier,";
244 }
245 $sql .= " s.rowid as socid, s.nom as name, pl.statut as status, pl.amount as amount_requested";
246 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p,";
247 $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,";
248 $sql .= " ".MAIN_DB_PREFIX."prelevement as pf";
249 if ($object->type != 'bank-transfer') {
250 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
251 } else {
252 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
253 }
254 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
255 $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
256 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
257 $sql .= " AND f.fk_soc = s.rowid";
258 if ($object->type != 'bank-transfer') {
259 $sql .= " AND pf.fk_facture = f.rowid";
260 } else {
261 $sql .= " AND pf.fk_facture_fourn = f.rowid";
262 }
263 if ($object->type != 'bank-transfer') {
264 $sql .= " AND f.entity IN (".getEntity('invoice').")";
265 } else {
266 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
267 }
268 if ($object->id > 0) {
269 $sql .= " AND p.rowid = ".((int) $object->id);
270 }
271 if ($socid > 0) {
272 $sql .= " AND s.rowid = ".((int) $socid);
273 }
274 $sql .= $db->order($sortfield, $sortorder);
275}
276// Count total nb of records
277$nbtotalofrecords = '';
278if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
279 $resql = $db->query($sql);
280 $nbtotalofrecords = $db->num_rows($resql);
281 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
282 $page = 0;
283 $offset = 0;
284 }
285}
286
287$sql .= $db->plimit($limit + 1, $offset);
288$resql = $db->query($sql);
289if ($resql) {
290 $num = $db->num_rows($resql);
291 $i = 0;
292
293 $param = "&id=".((int) $id);
294 if ($limit > 0 && $limit != $conf->liste_limit) {
295 $param .= '&limit='.((int) $limit);
296 }
297
298 // Lines of title fields
299 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
300 if ($optioncss != '') {
301 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
302 }
303 print '<input type="hidden" name="token" value="'.newToken().'">';
304 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
305 print '<input type="hidden" name="action" value="list">';
306 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
307 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
308 print '<input type="hidden" name="page" value="'.$page.'">';
309 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
310 print '<input type="hidden" name="id" value="'.$id.'">';
311
312 $massactionbutton = '';
313 $title = ($salaryBonPl ? $langs->trans("Salaries") : ($object->type == 'bank-transfer' ? $langs->trans("SupplierInvoices") : $langs->trans("Invoices")));
314
315 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
316
317 print"\n<!-- debut table -->\n";
318 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
319 print '<table class="liste centpercent">';
320 print '<tr class="liste_titre">';
321 print_liste_field_titre(($salaryBonPl ? "Salary" : "Bill"), $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
322 if ($object->type == 'bank-transfer' && !$salaryBonPl) {
323 print_liste_field_titre("RefSupplierShort", $_SERVER["PHP_SELF"], "f.ref_supplier", '', $param, '', $sortfield, $sortorder);
324 }
325 print_liste_field_titre(($salaryBonPl ? "Employee" : "ThirdParty"), $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
326 print_liste_field_titre(($salaryBonPl ? "AmountSalary" : "AmountInvoice"), $_SERVER["PHP_SELF"], "f.total_ttc", "", $param, '', $sortfield, $sortorder, 'right ');
327 print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "pl.amount", "", $param, '', $sortfield, $sortorder, 'right ');
328 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, '"', $sortfield, $sortorder, 'center ');
329 print "</tr>\n";
330
331 $totalinvoices = 0;
332 $totalamount_requested = 0;
333 $salarytmp = null;
334 $usertmp = null;
335 $invoicetmpcustomer = null;
336 $invoicetmpsupplier = null;
337
338 if ($salaryBonPl) {
339 $salarytmp = new Salary($db);
340 $usertmp = new User($db);
341 } else {
342 $invoicetmpcustomer = new Facture($db);
343 $invoicetmpsupplier = new FactureFournisseur($db);
344 }
345
346 $imaxinloop = ($limit ? min($num, $limit) : $num);
347 while ($i < $imaxinloop) {
348 $obj = $db->fetch_object($resql);
349
350 $itemurl = '';
351 $partyurl = '';
352 if ($salaryBonPl && ($salarytmp instanceof Salary) && ($usertmp instanceof User)) {
353 $salarytmp->fetch($obj->salaryid);
354 $usertmp->fetch($obj->userid);
355 $itemurl = $salarytmp->getNomUrl(1);
356 $partyurl = $usertmp->getNomUrl(-1);
357 } elseif ($invoicetmpcustomer instanceof Facture && $invoicetmpsupplier instanceof FactureFournisseur) {
358 if ($obj->type == 'bank-transfer') {
359 $invoicetmp = $invoicetmpsupplier;
360 } else {
361 $invoicetmp = $invoicetmpcustomer;
362 }
363 $invoicetmp->fetch($obj->facid);
364
365 $thirdpartytmp->fetch($obj->socid);
366 $itemurl = $invoicetmp->getNomUrl(1);
367 $partyurl = $thirdpartytmp->getNomUrl(1);
368 }
369
370 print '<tr class="oddeven">';
371
372 print '<td class="nowraponall">';
373 print $itemurl;
374 print "</td>\n";
375
376 if ($object->type == 'bank-transfer' && !$salaryBonPl) {
377 $labeltoshow = '';
378 if ($invoicetmp instanceof Facture) {
379 $labeltoshow = $invoicetmp->ref_supplier;
380 }
381 print '<td class="tdoverflowmax150" title="'.dolPrintHTMLForAttribute($labeltoshow).'">';
382 if ($invoicetmp instanceof Facture) {
383 print dol_escape_htmltag($invoicetmp->ref_supplier);
384 }
385 print "</td>\n";
386 }
387
388 print '<td class="tdoverflowmax125">';
389 print $partyurl;
390 print "</td>\n";
391
392 // Amount of invoice
393 print '<td class="right"><span class="amount">'.price(($salaryBonPl ? $obj->amount : $obj->total_ttc))."</span></td>\n";
394
395 // Amount requested
396 print '<td class="right"><span class="amount">'.price($obj->amount_requested)."</span></td>\n";
397
398 // Status of requests
399 print '<td class="center">';
400 if ($obj->status == 0) {
401 print $langs->trans("StatusWaiting");
402 } elseif ($obj->status == 2) {
403 if ($obj->type == 'bank-transfer') {
404 print $langs->trans("StatusDebited");
405 } else {
406 print $langs->trans("StatusCredited");
407 }
408 } elseif ($obj->status == 3) {
409 print '<span class="error">'.$langs->trans("StatusRefused").'</span>';
410 }
411 print "</td>";
412
413 print "</tr>\n";
414
415 $totalinvoices += $obj->total_ttc;
416 $totalamount_requested += $obj->amount_requested;
417
418 $i++;
419 }
420
421 if ($num > 0) {
422 print '<tr class="liste_total">';
423 print '<td>'.$langs->trans("Total").'</td>';
424 if ($object->type == 'bank-transfer' && !$salaryBonPl) {
425 print '<td>&nbsp;</td>';
426 }
427 print '<td>&nbsp;</td>';
428 print '<td class="right">';
429 print "</td>\n";
430 print '<td class="right">';
431 // If the page show all record (no pagination) and total does not match total of file, we show a warning. Should not happen.
432 if (($nbtotalofrecords <= $num) && $totalamount_requested != (float) $object->amount) {
433 $langs->load("errors");
434 // Warning, amount of file (%s) differs from the sum of lines (%s)
435 print img_warning($langs->trans("WarningAmountOfFileDiffersFromSumOfLines", price((float) $object->amount), price($totalamount_requested)));
436 }
437 print price($totalamount_requested);
438 print "</td>\n";
439 print '<td>&nbsp;</td>';
440 print "</tr>\n";
441 }
442
443 print "</table>";
444 print '</div>';
445
446 $db->free($resql);
447} else {
448 dol_print_error($db);
449}
450
451// End of page
452llxFooter();
453$db->close();
$id
Definition account.php:48
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 withdrawal receipts.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
llxFooter()
Footer empty.
Definition document.php:107
dol_is_file($pathoffile)
Return if path is a file.
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.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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
prelevement_prepare_head(BonPrelevement $object)
Prepare array with list of tabs.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.