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