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