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