dolibarr  18.0.6
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
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'withdrawals', 'suppliers'));
38 
39 // Get supervariables
40 $id = GETPOST('id', 'int');
41 $ref = GETPOST('ref', 'alpha');
42 $socid = GETPOST('socid', 'int');
43 $type = GETPOST('type', 'aZ09');
44 
45 // Load variable for pagination
46 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
47 $sortfield = GETPOST('sortfield', 'aZ09comma');
48 $sortorder = GETPOST('sortorder', 'aZ09comma');
49 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
50 if (empty($page) || $page == -1) {
51  $page = 0;
52 } // If $page is not defined, or '' or -1
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
56 if (!$sortfield) {
57  $sortfield = 'p.ref';
58 }
59 if (!$sortorder) {
60  $sortorder = 'DESC';
61 }
62 
63 $object = new BonPrelevement($db);
64 
65 // Load object
66 include 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
67 
68 $hookmanager->initHooks(array('directdebitprevcard', 'globalcard', 'directdebitprevlist'));
69 
70 // Security check
71 if ($user->socid > 0) {
73 }
74 
75 $type = $object->type;
76 if ($type == 'bank-transfer') {
77  $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
78 } else {
79  $result = restrictedArea($user, 'prelevement', '', '', 'bons');
80 }
81 
82 
83 /*
84  * View
85  */
86 
87 $form = new Form($db);
88 $invoicetmp = new Facture($db);
89 $thirdpartytmp = new Societe($db);
90 
91 llxHeader('', $langs->trans("WithdrawalsReceipts"));
92 
93 if ($id > 0 || $ref) {
94  if ($object->fetch($id, $ref) >= 0) {
95  $head = prelevement_prepare_head($object);
96  print dol_get_fiche_head($head, 'invoices', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
97 
98  $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>';
99 
100  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
101 
102  print '<div class="fichecenter">';
103  print '<div class="underbanner clearboth"></div>';
104  print '<table class="border centpercent tableforfield">'."\n";
105 
106  //print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
107  print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
108  print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
109 
110  if (!empty($object->date_trans)) {
111  $muser = new User($db);
112  $muser->fetch($object->user_trans);
113 
114  print '<tr><td>'.$langs->trans("TransData").'</td><td>';
115  print dol_print_date($object->date_trans, 'day');
116  print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
117  print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
118  print $object->methodes_trans[$object->method_trans];
119  print '</td></tr>';
120  }
121  if (!empty($object->date_credit)) {
122  print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
123  print dol_print_date($object->date_credit, 'day');
124  print '</td></tr>';
125  }
126 
127  print '</table>';
128 
129  print '<br>';
130 
131  print '<div class="underbanner clearboth"></div>';
132  print '<table class="border centpercent tableforfield">';
133 
134  // Get bank account for the payment
135  $acc = new Account($db);
136  $fk_bank_account = $object->fk_bank_account;
137  if (empty($fk_bank_account)) {
138  $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
139  }
140  if ($fk_bank_account > 0) {
141  $result = $acc->fetch($fk_bank_account);
142  }
143 
144  $labelofbankfield = "BankToReceiveWithdraw";
145  if ($object->type == 'bank-transfer') {
146  $labelofbankfield = 'BankToPayCreditTransfer';
147  }
148 
149  print '<tr><td class="titlefieldcreate">';
150  print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
151  print '</td>';
152 
153  print '<td>';
154  if ($acc->id > 0) {
155  print $acc->getNomUrl(1);
156  }
157  print '</td>';
158  print '</tr>';
159 
160  $modulepart = 'prelevement';
161  if ($object->type == 'bank-transfer') {
162  $modulepart = 'paymentbybanktransfer';
163  }
164 
165  print '<tr><td class="titlefieldcreate">';
166  $labelfororderfield = 'WithdrawalFile';
167  if ($object->type == 'bank-transfer') {
168  $labelfororderfield = 'CreditTransferFile';
169  }
170  print $langs->trans($labelfororderfield).'</td><td>';
171 
172  if (isModEnabled('multicompany')) {
173  $labelentity = $conf->entity;
174  $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
175 
176  if ($type != 'bank-transfer') {
177  $dir = $conf->prelevement->dir_output;
178  } else {
179  $dir = $conf->paymentbybanktransfer->dir_output;
180  }
181  if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
182  $relativepath = 'receipts/'.$object->ref.'.xml';
183  }
184  } else {
185  $relativepath = 'receipts/'.$object->ref.'.xml';
186  }
187 
188  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
189  print img_picto('', 'download', 'class="paddingleft"');
190  print '</a>';
191  print '</td></tr></table>';
192 
193  print '</div>';
194 
195  print dol_get_fiche_end();
196  } else {
197  dol_print_error($db);
198  }
199 }
200 
201 
202 // List of invoices
203 $sql = "SELECT pf.rowid, p.type,";
204 $sql .= " f.rowid as facid, f.ref as ref, f.total_ttc,";
205 if ($object->type == 'bank-transfer') {
206  $sql .= " f.ref_supplier,";
207 }
208 $sql .= " s.rowid as socid, s.nom as name, pl.statut, pl.amount as amount_requested";
209 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
210 $sql .= ", ".MAIN_DB_PREFIX."prelevement_lignes as pl";
211 $sql .= ", ".MAIN_DB_PREFIX."prelevement as pf";
212 if ($object->type != 'bank-transfer') {
213  $sql .= ", ".MAIN_DB_PREFIX."facture as f";
214 } else {
215  $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
216 }
217 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
218 $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
219 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
220 $sql .= " AND f.fk_soc = s.rowid";
221 if ($object->type != 'bank-transfer') {
222  $sql .= " AND pf.fk_facture = f.rowid";
223 } else {
224  $sql .= " AND pf.fk_facture_fourn = f.rowid";
225 }
226 if ($object->type != 'bank-transfer') {
227  $sql .= " AND f.entity IN (".getEntity('invoice').")";
228 } else {
229  $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
230 }
231 if ($object->id > 0) {
232  $sql .= " AND p.rowid = ".((int) $object->id);
233 }
234 if ($socid > 0) {
235  $sql .= " AND s.rowid = ".((int) $socid);
236 }
237 $sql .= $db->order($sortfield, $sortorder);
238 
239 // Count total nb of records
240 $nbtotalofrecords = '';
241 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
242  $resql = $db->query($sql);
243  $nbtotalofrecords = $db->num_rows($resql);
244  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
245  $page = 0;
246  $offset = 0;
247  }
248 }
249 
250 $sql .= $db->plimit($limit + 1, $offset);
251 
252 $resql = $db->query($sql);
253 if ($resql) {
254  $num = $db->num_rows($resql);
255  $i = 0;
256 
257  if ($limit > 0 && $limit != $conf->liste_limit) {
258  $param.='&limit='.((int) $limit);
259  }
260  $param = "&id=".urlencode($id);
261 
262  // Lines of title fields
263  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
264  if ($optioncss != '') {
265  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
266  }
267  print '<input type="hidden" name="token" value="'.newToken().'">';
268  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
269  print '<input type="hidden" name="action" value="list">';
270  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
271  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
272  print '<input type="hidden" name="page" value="'.$page.'">';
273  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
274  print '<input type="hidden" name="id" value="'.$id.'">';
275 
276  $massactionbutton = '';
277 
278  print_barre_liste($langs->trans("Invoices"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
279 
280  print"\n<!-- debut table -->\n";
281  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
282  print '<table class="liste centpercent">';
283  print '<tr class="liste_titre">';
284  print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
285  if ($object->type == 'bank-transfer') {
286  print_liste_field_titre("RefSupplierShort", $_SERVER["PHP_SELF"], "f.ref_supplier", '', $param, '', $sortfield, $sortorder);
287  }
288  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
289  print_liste_field_titre("AmountInvoice", $_SERVER["PHP_SELF"], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder);
290  print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "pl.amount", "", $param, 'class="right"', $sortfield, $sortorder);
291  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, 'align="center"', $sortfield, $sortorder);
293  print "</tr>\n";
294 
295  $totalinvoices = 0;
296  $totalamount_requested = 0;
297 
298  $invoicetmpcustomer = new Facture($db);
299  $invoicetmpsupplier = new FactureFournisseur($db);
300 
301  while ($i < min($num, $limit)) {
302  $obj = $db->fetch_object($resql);
303 
304  if ($obj->type == 'bank-transfer') {
305  $invoicetmp = $invoicetmpsupplier;
306  } else {
307  $invoicetmp = $invoicetmpcustomer;
308  }
309  $invoicetmp->fetch($obj->facid);
310 
311  $thirdpartytmp->fetch($obj->socid);
312 
313  print '<tr class="oddeven">';
314 
315  print '<td class="nowraponall">';
316  print $invoicetmp->getNomUrl(1);
317  print "</td>\n";
318 
319  if ($object->type == 'bank-transfer') {
320  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($invoicetmp->ref_supplier).'">';
321  print dol_escape_htmltag($invoicetmp->ref_supplier);
322  print "</td>\n";
323  }
324 
325  print '<td class="tdoverflowmax125">';
326  print $thirdpartytmp->getNomUrl(1);
327  print "</td>\n";
328 
329  // Amount of invoice
330  print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
331 
332  // Amount requested
333  print '<td class="right"><span class="amount">'.price($obj->amount_requested)."</span></td>\n";
334 
335  // Status of requests
336  print '<td class="center">';
337 
338  if ($obj->statut == 0) {
339  print '-';
340  } elseif ($obj->statut == 2) {
341  if ($obj->type == 'bank-transfer') {
342  print $langs->trans("StatusDebited");
343  } else {
344  print $langs->trans("StatusCredited");
345  }
346  } elseif ($obj->statut == 3) {
347  print '<span class="error">'.$langs->trans("StatusRefused").'</span>';
348  }
349 
350  print "</td>";
351 
352  print "<td></td>";
353 
354  print "</tr>\n";
355 
356  $totalinvoices += $obj->total_ttc;
357  $totalamount_requested += $obj->amount_requested;
358 
359  $i++;
360  }
361 
362  if ($num > 0) {
363  print '<tr class="liste_total">';
364  print '<td>'.$langs->trans("Total").'</td>';
365  if ($object->type == 'bank-transfer') {
366  print '<td>&nbsp;</td>';
367  }
368  print '<td>&nbsp;</td>';
369  print '<td class="right">';
370  print "</td>\n";
371  print '<td class="right">';
372  // If the page show all record (no pagination) and total does not match total of file, we show a warning. Should not happen.
373  if (($nbtotalofrecords <= $num) && $totalamount_requested != $object->amount) {
374  print img_warning("AmountOfFileDiffersFromSumOfInvoices");
375  }
376  print price($totalamount_requested);
377  print "</td>\n";
378  print '<td>&nbsp;</td>';
379  print '<td>&nbsp;</td>';
380  print "</tr>\n";
381  }
382 
383  print "</table>";
384  print '</div>';
385 
386  $db->free($result);
387 } else {
388  dol_print_error($db);
389 }
390 
391 // End of page
392 llxFooter();
393 $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:56
llxFooter()
Empty footer.
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 third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:483
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 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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
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.