dolibarr  19.0.0-dev
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'));
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 $invoicetmp = new Facture($db);
88 $thirdpartytmp = new Societe($db);
89 
90 llxHeader('', $langs->trans("WithdrawalsReceipts"));
91 
92 if ($id > 0 || $ref) {
93  if ($object->fetch($id, $ref) >= 0) {
94  $head = prelevement_prepare_head($object);
95  print dol_get_fiche_head($head, 'invoices', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
96 
97  $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>';
98 
99  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
100 
101  print '<div class="fichecenter">';
102  print '<div class="underbanner clearboth"></div>';
103  print '<table class="border centpercent tableforfield">'."\n";
104 
105  //print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
106  print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
107  print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
108 
109  if (!empty($object->date_trans)) {
110  $muser = new User($db);
111  $muser->fetch($object->user_trans);
112 
113  print '<tr><td>'.$langs->trans("TransData").'</td><td>';
114  print dol_print_date($object->date_trans, 'day');
115  print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
116  print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
117  print $object->methodes_trans[$object->method_trans];
118  print '</td></tr>';
119  }
120  if (!empty($object->date_credit)) {
121  print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
122  print dol_print_date($object->date_credit, 'day');
123  print '</td></tr>';
124  }
125 
126  print '</table>';
127 
128  print '<br>';
129 
130  print '<div class="underbanner clearboth"></div>';
131  print '<table class="border centpercent tableforfield">';
132 
133  // Get bank account for the payment
134  $acc = new Account($db);
135  $fk_bank_account = $object->fk_bank_account;
136  if (empty($fk_bank_account)) {
137  $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
138  }
139  if ($fk_bank_account > 0) {
140  $result = $acc->fetch($fk_bank_account);
141  }
142 
143  $labelofbankfield = "BankToReceiveWithdraw";
144  if ($object->type == 'bank-transfer') {
145  $labelofbankfield = 'BankToPayCreditTransfer';
146  }
147 
148  print '<tr><td class="titlefieldcreate">';
149  print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
150  print '</td>';
151 
152  print '<td>';
153  if ($acc->id > 0) {
154  print $acc->getNomUrl(1);
155  }
156  print '</td>';
157  print '</tr>';
158 
159  $modulepart = 'prelevement';
160  if ($object->type == 'bank-transfer') {
161  $modulepart = 'paymentbybanktransfer';
162  }
163 
164  print '<tr><td class="titlefieldcreate">';
165  $labelfororderfield = 'WithdrawalFile';
166  if ($object->type == 'bank-transfer') {
167  $labelfororderfield = 'CreditTransferFile';
168  }
169  print $langs->trans($labelfororderfield).'</td><td>';
170 
171  if (isModEnabled('multicompany')) {
172  $labelentity = $conf->entity;
173  $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
174 
175  if ($type != 'bank-transfer') {
176  $dir = $conf->prelevement->dir_output;
177  } else {
178  $dir = $conf->paymentbybanktransfer->dir_output;
179  }
180  if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
181  $relativepath = 'receipts/'.$object->ref.'.xml';
182  }
183  } else {
184  $relativepath = 'receipts/'.$object->ref.'.xml';
185  }
186 
187  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
188  print img_picto('', 'download', 'class="paddingleft"');
189  print '</a>';
190  print '</td></tr></table>';
191 
192  print '</div>';
193 
194  print dol_get_fiche_end();
195  } else {
196  dol_print_error($db);
197  }
198 }
199 
200 
201 // List of invoices
202 $sql = "SELECT pf.rowid, p.type,";
203 $sql .= " f.rowid as facid, f.ref as ref, f.total_ttc,";
204 if ($object->type == 'bank-transfer') {
205  $sql .= " f.ref_supplier,";
206 }
207 $sql .= " s.rowid as socid, s.nom as name, pl.statut, pl.amount as amount_requested";
208 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
209 $sql .= ", ".MAIN_DB_PREFIX."prelevement_lignes as pl";
210 $sql .= ", ".MAIN_DB_PREFIX."prelevement as pf";
211 if ($object->type != 'bank-transfer') {
212  $sql .= ", ".MAIN_DB_PREFIX."facture as f";
213 } else {
214  $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
215 }
216 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
217 $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
218 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
219 $sql .= " AND f.fk_soc = s.rowid";
220 if ($object->type != 'bank-transfer') {
221  $sql .= " AND pf.fk_facture = f.rowid";
222 } else {
223  $sql .= " AND pf.fk_facture_fourn = f.rowid";
224 }
225 if ($object->type != 'bank-transfer') {
226  $sql .= " AND f.entity IN (".getEntity('invoice').")";
227 } else {
228  $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
229 }
230 if ($object->id > 0) {
231  $sql .= " AND p.rowid = ".((int) $object->id);
232 }
233 if ($socid) {
234  $sql .= " AND s.rowid = ".((int) $socid);
235 }
236 $sql .= $db->order($sortfield, $sortorder);
237 
238 // Count total nb of records
239 $nbtotalofrecords = '';
240 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
241  $resql = $db->query($sql);
242  $nbtotalofrecords = $db->num_rows($resql);
243  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
244  $page = 0;
245  $offset = 0;
246  }
247 }
248 
249 $sql .= $db->plimit($limit + 1, $offset);
250 
251 $resql = $db->query($sql);
252 if ($resql) {
253  $num = $db->num_rows($resql);
254  $i = 0;
255 
256  if ($limit > 0 && $limit != $conf->liste_limit) {
257  $param.='&limit='.((int) $limit);
258  }
259  $param = "&id=".urlencode($id);
260 
261  // Lines of title fields
262  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
263  if ($optioncss != '') {
264  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
265  }
266  print '<input type="hidden" name="token" value="'.newToken().'">';
267  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
268  print '<input type="hidden" name="action" value="list">';
269  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
270  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
271  print '<input type="hidden" name="page" value="'.$page.'">';
272  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
273  print '<input type="hidden" name="id" value="'.$id.'">';
274 
275  $massactionbutton = '';
276 
277  print_barre_liste($langs->trans("Invoices"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
278 
279  print"\n<!-- debut table -->\n";
280  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
281  print '<table class="liste centpercent">';
282  print '<tr class="liste_titre">';
283  print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
284  if ($object->type == 'bank-transfer') {
285  print_liste_field_titre("RefSupplierShort", $_SERVER["PHP_SELF"], "f.ref_supplier", '', $param, '', $sortfield, $sortorder);
286  }
287  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
288  print_liste_field_titre("AmountInvoice", $_SERVER["PHP_SELF"], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder);
289  print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "pl.amount", "", $param, 'class="right"', $sortfield, $sortorder);
290  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, 'align="center"', $sortfield, $sortorder);
292  print "</tr>\n";
293 
294  $totalinvoices = 0;
295  $totalamount_requested = 0;
296 
297  $invoicetmpcustomer = new Facture($db);
298  $invoicetmpsupplier = new FactureFournisseur($db);
299 
300  while ($i < min($num, $limit)) {
301  $obj = $db->fetch_object($resql);
302 
303  if ($obj->type == 'bank-transfer') {
304  $invoicetmp = $invoicetmpsupplier;
305  } else {
306  $invoicetmp = $invoicetmpcustomer;
307  }
308  $invoicetmp->fetch($obj->facid);
309 
310  $thirdpartytmp->fetch($obj->socid);
311 
312  print '<tr class="oddeven">';
313 
314  print "<td>";
315  print $invoicetmp->getNomUrl(1);
316  print "</td>\n";
317 
318  if ($object->type == 'bank-transfer') {
319  print '<td>';
320  print dol_escape_htmltag($invoicetmp->ref_supplier);
321  print "</td>\n";
322  }
323 
324  print '<td>';
325  print $thirdpartytmp->getNomUrl(1);
326  print "</td>\n";
327 
328  // Amount of invoice
329  print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
330 
331  // Amount requested
332  print '<td class="right"><span class="amount">'.price($obj->amount_requested)."</span></td>\n";
333 
334  // Status of requests
335  print '<td class="center">';
336 
337  if ($obj->statut == 0) {
338  print '-';
339  } elseif ($obj->statut == 2) {
340  if ($obj->type == 'bank-transfer') {
341  print $langs->trans("StatusDebited");
342  } else {
343  print $langs->trans("StatusCredited");
344  }
345  } elseif ($obj->statut == 3) {
346  print '<b>'.$langs->trans("StatusRefused").'</b>';
347  }
348 
349  print "</td>";
350 
351  print "<td></td>";
352 
353  print "</tr>\n";
354 
355  $totalinvoices += $obj->total_ttc;
356  $totalamount_requested += $obj->amount_requested;
357 
358  $i++;
359  }
360 
361  if ($num > 0) {
362  print '<tr class="liste_total">';
363  print '<td>'.$langs->trans("Total").'</td>';
364  if ($object->type == 'bank-transfer') {
365  print '<td>&nbsp;</td>';
366  }
367  print '<td>&nbsp;</td>';
368  print '<td class="right">';
369  print "</td>\n";
370  print '<td class="right">';
371  // If the page show all record (no pagination) and total does not match total of file, we show a warning. Should not happen.
372  if (($nbtotalofrecords <= $num) && $totalamount_requested != $object->amount) {
373  print img_warning("AmountOfFileDiffersFromSumOfInvoices");
374  }
375  print price($totalamount_requested);
376  print "</td>\n";
377  print '<td>&nbsp;</td>';
378  print '<td>&nbsp;</td>';
379  print "</tr>\n";
380  }
381 
382  print "</table>";
383  print '</div>';
384 
385  $db->free($result);
386 } else {
387  dol_print_error($db);
388 }
389 
390 // End of page
391 llxFooter();
392 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:51
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
dol_escape_htmltag
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...
Definition: functions.lib.php:1600
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:609
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:51
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4784
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
Facture
Class to manage invoices.
Definition: facture.class.php:60
dol_banner_tab
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.
Definition: functions.lib.php:2205
dol_is_file
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:483
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2675
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4135
llxHeader
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
BonPrelevement
Class to manage withdrawal receipts.
Definition: bonprelevement.class.php:43
print_barre_liste
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.
Definition: functions.lib.php:5530
$sql
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
restrictedArea
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.
Definition: security.lib.php:353
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2177
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
dol_get_fiche_head
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.
Definition: functions.lib.php:1979
User
Class to manage Dolibarr users.
Definition: user.class.php:47
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:509
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5295
price
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.
Definition: functions.lib.php:5829
prelevement_prepare_head
prelevement_prepare_head(BonPrelevement $object)
Prepare array with list of tabs.
Definition: prelevement.lib.php:34
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1169
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:156
Account
Class to manage bank accounts.
Definition: account.class.php:40