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