dolibarr 19.0.3
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 = GETPOST('id', 'int');
42$ref = GETPOST('ref', 'alpha');
43$socid = GETPOST('socid', 'int');
44$userid = GETPOST('userid', 'int');
45$type = GETPOST('type', 'aZ09');
46
47// Load variable for pagination
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');
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 if ($object->fetch($id, $ref) >= 0) {
98 $head = prelevement_prepare_head($object);
99
100 print dol_get_fiche_head($head, 'invoices', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
101
102 $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>';
103
104 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
105
106 print '<div class="fichecenter">';
107 print '<div class="underbanner clearboth"></div>';
108 print '<table class="border centpercent tableforfield">'."\n";
109
110 //print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
111 print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
112 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
113
114 if (!empty($object->date_trans)) {
115 $muser = new User($db);
116 $muser->fetch($object->user_trans);
117
118 print '<tr><td>'.$langs->trans("TransData").'</td><td>';
119 print dol_print_date($object->date_trans, 'day');
120 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
121 print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
122 print $object->methodes_trans[$object->method_trans];
123 print '</td></tr>';
124 }
125 if (!empty($object->date_credit)) {
126 print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
127 print dol_print_date($object->date_credit, 'day');
128 print '</td></tr>';
129 }
130
131 print '</table>';
132
133 print '<br>';
134
135 print '<div class="underbanner clearboth"></div>';
136 print '<table class="border centpercent tableforfield">';
137
138 // Get bank account for the payment
139 $acc = new Account($db);
140 $fk_bank_account = $object->fk_bank_account;
141 if (empty($fk_bank_account)) {
142 $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
143 }
144 if ($fk_bank_account > 0) {
145 $result = $acc->fetch($fk_bank_account);
146 }
147
148 $labelofbankfield = "BankToReceiveWithdraw";
149 if ($object->type == 'bank-transfer') {
150 $labelofbankfield = 'BankToPayCreditTransfer';
151 }
152
153 print '<tr><td class="titlefieldcreate">';
154 print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
155 print '</td>';
156
157 print '<td>';
158 if ($acc->id > 0) {
159 print $acc->getNomUrl(1);
160 }
161 print '</td>';
162 print '</tr>';
163
164 $modulepart = 'prelevement';
165 if ($object->type == 'bank-transfer') {
166 $modulepart = 'paymentbybanktransfer';
167 }
168
169 print '<tr><td class="titlefieldcreate">';
170 $labelfororderfield = 'WithdrawalFile';
171 if ($object->type == 'bank-transfer') {
172 $labelfororderfield = 'CreditTransferFile';
173 }
174 print $langs->trans($labelfororderfield).'</td><td>';
175
176 if (isModEnabled('multicompany')) {
177 $labelentity = $conf->entity;
178 $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
179
180 if ($type != 'bank-transfer') {
181 $dir = $conf->prelevement->dir_output;
182 } else {
183 $dir = $conf->paymentbybanktransfer->dir_output;
184 }
185 if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
186 $relativepath = 'receipts/'.$object->ref.'.xml';
187 }
188 } else {
189 $relativepath = 'receipts/'.$object->ref.'.xml';
190 }
191
192 print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
193 print img_picto('', 'download', 'class="paddingleft"');
194 print '</a>';
195 print '</td></tr></table>';
196
197 print '</div>';
198
199 print dol_get_fiche_end();
200 } else {
201 dol_print_error($db);
202 }
203}
204
205
206// List of invoices or salaries
207if ($salaryBonPl) {
208 $sql = "SELECT pf.rowid, p.type,";
209 $sql .= " f.rowid as salaryid, f.ref as ref, f.amount,";
210 $sql .= " u.rowid as userid, u.firstname, u.lastname, pl.statut as status, pl.amount as amount_requested";
211 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
212 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."prelevement_lignes as pl ON pl.fk_prelevement_bons = p.rowid";
213 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."prelevement as pf ON pf.fk_prelevement_lignes = pl.rowid";
214 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as f ON f.rowid = pf.fk_salary AND f.entity IN (".getEntity('salary').")";
215 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON f.fk_user = u.rowid";
216 $sql .= " WHERE 1 = 1";
217 if ($object->id > 0) {
218 $sql .= " AND p.rowid = ".((int) $object->id);
219 }
220 if ($userid > 0) {
221 $sql .= " AND u.rowid = ".((int) $userid);
222 }
223} else {
224 $sql = "SELECT pf.rowid, p.type,";
225 $sql .= " f.rowid as facid, f.ref as ref, f.total_ttc,";
226 if ($object->type == 'bank-transfer') {
227 $sql .= " f.ref_supplier,";
228 }
229 $sql .= " s.rowid as socid, s.nom as name, pl.statut as status, pl.amount as amount_requested";
230 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p,";
231 $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,";
232 $sql .= " ".MAIN_DB_PREFIX."prelevement as pf";
233 if ($object->type != 'bank-transfer') {
234 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
235 } else {
236 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
237 }
238 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
239 $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
240 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
241 $sql .= " AND f.fk_soc = s.rowid";
242 if ($object->type != 'bank-transfer') {
243 $sql .= " AND pf.fk_facture = f.rowid";
244 } else {
245 $sql .= " AND pf.fk_facture_fourn = f.rowid";
246 }
247 if ($object->type != 'bank-transfer') {
248 $sql .= " AND f.entity IN (".getEntity('invoice').")";
249 } else {
250 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
251 }
252 if ($object->id > 0) {
253 $sql .= " AND p.rowid = ".((int) $object->id);
254 }
255 if ($socid > 0) {
256 $sql .= " AND s.rowid = ".((int) $socid);
257 }
258 $sql .= $db->order($sortfield, $sortorder);
259}
260// Count total nb of records
261$nbtotalofrecords = '';
262if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
263 $resql = $db->query($sql);
264 $nbtotalofrecords = $db->num_rows($resql);
265 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
266 $page = 0;
267 $offset = 0;
268 }
269}
270
271$sql .= $db->plimit($limit + 1, $offset);
272$resql = $db->query($sql);
273if ($resql) {
274 $num = $db->num_rows($resql);
275 $i = 0;
276
277 if ($limit > 0 && $limit != $conf->liste_limit) {
278 $param.='&limit='.((int) $limit);
279 }
280 $param = "&id=".urlencode($id);
281
282 // Lines of title fields
283 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
284 if ($optioncss != '') {
285 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
286 }
287 print '<input type="hidden" name="token" value="'.newToken().'">';
288 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
289 print '<input type="hidden" name="action" value="list">';
290 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
291 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
292 print '<input type="hidden" name="page" value="'.$page.'">';
293 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
294 print '<input type="hidden" name="id" value="'.$id.'">';
295
296 $massactionbutton = '';
297 $title = ($salaryBonPl ? $langs->trans("Salaries") : ($object->type == 'bank-transfer' ? $langs->trans("SupplierInvoices") : $langs->trans("Invoices")));
298
299 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
300
301 print"\n<!-- debut table -->\n";
302 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
303 print '<table class="liste centpercent">';
304 print '<tr class="liste_titre">';
305 print_liste_field_titre(($salaryBonPl ? "Salary" : "Bill"), $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
306 if ($object->type == 'bank-transfer' && !$salaryBonPl) {
307 print_liste_field_titre("RefSupplierShort", $_SERVER["PHP_SELF"], "f.ref_supplier", '', $param, '', $sortfield, $sortorder);
308 }
309 print_liste_field_titre(($salaryBonPl ? "Employee" : "ThirdParty"), $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
310 print_liste_field_titre(($salaryBonPl ? "AmountSalary" : "AmountInvoice"), $_SERVER["PHP_SELF"], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder);
311 print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "pl.amount", "", $param, 'class="right"', $sortfield, $sortorder);
312 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, 'align="center"', $sortfield, $sortorder);
313 print "</tr>\n";
314
315 $totalinvoices = 0;
316 $totalamount_requested = 0;
317
318 if ($salaryBonPl) {
319 $salarytmp = new Salary($db);
320 $usertmp = new User($db);
321 } else {
322 $invoicetmpcustomer = new Facture($db);
323 $invoicetmpsupplier = new FactureFournisseur($db);
324 }
325
326 while ($i < min($num, $limit)) {
327 $obj = $db->fetch_object($resql);
328 if ($salaryBonPl) {
329 $salarytmp->fetch($obj->salaryid);
330 $usertmp->fetch($obj->userid);
331 } else {
332 if ($obj->type == 'bank-transfer') {
333 $invoicetmp = $invoicetmpsupplier;
334 } else {
335 $invoicetmp = $invoicetmpcustomer;
336 }
337 $invoicetmp->fetch($obj->facid);
338
339 $thirdpartytmp->fetch($obj->socid);
340 }
341
342 print '<tr class="oddeven">';
343
344 print '<td class="nowraponall">';
345 print ($salaryBonPl ? $salarytmp->getNomUrl(1) : $invoicetmp->getNomUrl(1));
346 print "</td>\n";
347
348 if ($object->type == 'bank-transfer' && !$salaryBonPl) {
349 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($invoicetmp->ref_supplier).'">';
350 print dol_escape_htmltag($invoicetmp->ref_supplier);
351 print "</td>\n";
352 }
353
354 print '<td class="tdoverflowmax125">';
355 print($salaryBonPl ? $usertmp->getNomUrl(-1) : $thirdpartytmp->getNomUrl(1));
356 print "</td>\n";
357
358 // Amount of invoice
359 print '<td class="right"><span class="amount">'.price(($salaryBonPl ? $obj->amount : $obj->total_ttc))."</span></td>\n";
360
361 // Amount requested
362 print '<td class="right"><span class="amount">'.price($obj->amount_requested)."</span></td>\n";
363
364 // Status of requests
365 print '<td class="center">';
366 if ($obj->status == 0) {
367 print $langs->trans("StatusWaiting");
368 } elseif ($obj->status == 2) {
369 if ($obj->type == 'bank-transfer') {
370 print $langs->trans("StatusDebited");
371 } else {
372 print $langs->trans("StatusCredited");
373 }
374 } elseif ($obj->status == 3) {
375 print '<span class="error">'.$langs->trans("StatusRefused").'</span>';
376 }
377 print "</td>";
378
379 print "</tr>\n";
380
381 $totalinvoices += $obj->total_ttc;
382 $totalamount_requested += $obj->amount_requested;
383
384 $i++;
385 }
386
387 if ($num > 0) {
388 print '<tr class="liste_total">';
389 print '<td>'.$langs->trans("Total").'</td>';
390 if ($object->type == 'bank-transfer' && !$salaryBonPl) {
391 print '<td>&nbsp;</td>';
392 }
393 print '<td>&nbsp;</td>';
394 print '<td class="right">';
395 print "</td>\n";
396 print '<td class="right">';
397 // If the page show all record (no pagination) and total does not match total of file, we show a warning. Should not happen.
398 if (($nbtotalofrecords <= $num) && $totalamount_requested != $object->amount) {
399 print img_warning("AmountOfFileDiffersFromSumOfInvoices");
400 }
401 print price($totalamount_requested);
402 print "</td>\n";
403 print '<td>&nbsp;</td>';
404 print "</tr>\n";
405 }
406
407 print "</table>";
408 print '</div>';
409
410 $db->free($resql);
411} else {
412 dol_print_error($db);
413}
414
415// End of page
416llxFooter();
417$db->close();
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.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
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.
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.