dolibarr  13.0.2
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 // Securite acces client
38 if ($user->socid > 0) accessforbidden();
39 
40 // Get supervariables
41 $id = GETPOST('id', 'int');
42 $ref = GETPOST('ref', 'alpha');
43 $socid = GETPOST('socid', 'int');
44 $type = GETPOST('type', 'aZ09');
45 
46 // Load variable for pagination
47 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
48 $sortfield = GETPOST('sortfield', 'aZ09comma');
49 $sortorder = GETPOST('sortorder', 'aZ09comma');
50 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
51 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
52 $offset = $limit * $page;
53 $pageprev = $page - 1;
54 $pagenext = $page + 1;
55 if (!$sortfield) $sortfield = 'p.ref';
56 if (!$sortorder) $sortorder = 'DESC';
57 
58 $object = new BonPrelevement($db);
59 
60 // Load object
61 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
62 
63 $hookmanager->initHooks(array('directdebitprevcard', 'globalcard', 'directdebitprevlist'));
64 
65 if (!$user->rights->prelevement->bons->lire && $object->type != 'bank-transfer') {
67 }
68 if (!$user->rights->paymentbybanktransfer->read && $object->type == 'bank-transfer') {
70 }
71 
72 
73 /*
74  * View
75  */
76 
77 $invoicetmp = new Facture($db);
78 $thirdpartytmp = new Societe($db);
79 
80 llxHeader('', $langs->trans("WithdrawalsReceipts"));
81 
82 if ($id > 0 || $ref)
83 {
84  if ($object->fetch($id, $ref) >= 0)
85  {
86  $head = prelevement_prepare_head($object);
87  print dol_get_fiche_head($head, 'invoices', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
88 
89  $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>';
90 
91  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
92 
93  print '<div class="fichecenter">';
94  print '<div class="underbanner clearboth"></div>';
95  print '<table class="border centpercent tableforfield">'."\n";
96 
97  //print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
98  print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
99  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
100 
101  if ($object->date_trans <> 0)
102  {
103  $muser = new User($db);
104  $muser->fetch($object->user_trans);
105 
106  print '<tr><td>'.$langs->trans("TransData").'</td><td>';
107  print dol_print_date($object->date_trans, 'day');
108  print ' <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getFullName($langs).'</td></tr>';
109  print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
110  print $object->methodes_trans[$object->method_trans];
111  print '</td></tr>';
112  }
113  if ($object->date_credit <> 0)
114  {
115  print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
116  print dol_print_date($object->date_credit, 'day');
117  print '</td></tr>';
118  }
119 
120  print '</table>';
121 
122  print '<br>';
123 
124  print '<div class="underbanner clearboth"></div>';
125  print '<table class="border centpercent tableforfield">';
126 
127  $acc = new Account($db);
128  $result = $acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT);
129 
130  print '<tr><td class="titlefield">';
131  $labelofbankfield = "BankToReceiveWithdraw";
132  if ($object->type == 'bank-transfer') $labelofbankfield = 'BankToPayCreditTransfer';
133  print $langs->trans($labelofbankfield);
134  print '</td>';
135  print '<td>';
136  if ($acc->id > 0)
137  print $acc->getNomUrl(1);
138  print '</td>';
139  print '</tr>';
140 
141  print '<tr><td class="titlefield">';
142  $labelfororderfield = 'WithdrawalFile';
143  if ($object->type == 'bank-transfer') $labelfororderfield = 'CreditTransferFile';
144  print $langs->trans($labelfororderfield).'</td><td>';
145  $relativepath = 'receipts/'.$object->ref.'.xml';
146  $modulepart = 'prelevement';
147  if ($object->type == 'bank-transfer') $modulepart = 'paymentbybanktransfer';
148  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath.'</a>';
149  print '</td></tr></table>';
150 
151  print '</div>';
152 
154  } else {
155  dol_print_error($db);
156  }
157 }
158 
159 
160 // List of invoices
161 $sql = "SELECT pf.rowid, p.type,";
162 $sql .= " f.rowid as facid, f.ref as ref, f.total_ttc,";
163 $sql .= " s.rowid as socid, s.nom as name, pl.statut, pl.amount as amount_requested";
164 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
165 $sql .= ", ".MAIN_DB_PREFIX."prelevement_lignes as pl";
166 $sql .= ", ".MAIN_DB_PREFIX."prelevement_facture as pf";
167 if ($object->type != 'bank-transfer') {
168  $sql .= ", ".MAIN_DB_PREFIX."facture as f";
169 } else {
170  $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
171 }
172 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
173 $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
174 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
175 $sql .= " AND f.fk_soc = s.rowid";
176 if ($object->type != 'bank-transfer') {
177  $sql .= " AND pf.fk_facture = f.rowid";
178 } else {
179  $sql .= " AND pf.fk_facture_fourn = f.rowid";
180 }
181 if ($object->type != 'bank-transfer') {
182  $sql .= " AND f.entity IN (".getEntity('invoice').")";
183 } else {
184  $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
185 }
186 if ($object->id > 0) $sql .= " AND p.rowid=".$object->id;
187 if ($socid) $sql .= " AND s.rowid = ".$socid;
188 $sql .= $db->order($sortfield, $sortorder);
189 
190 // Count total nb of records
191 $nbtotalofrecords = '';
192 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
193 {
194  $resql = $db->query($sql);
195  $nbtotalofrecords = $db->num_rows($resql);
196  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
197  {
198  $page = 0;
199  $offset = 0;
200  }
201 }
202 
203 $sql .= $db->plimit($limit + 1, $offset);
204 
205 $resql = $db->query($sql);
206 if ($resql)
207 {
208  $num = $db->num_rows($resql);
209  $i = 0;
210 
211  $param = "&id=".$id;
212 
213  // Lines of title fields
214  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
215  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
216  print '<input type="hidden" name="token" value="'.newToken().'">';
217  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
218  print '<input type="hidden" name="action" value="list">';
219  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
220  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
221  print '<input type="hidden" name="page" value="'.$page.'">';
222  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
223  print '<input type="hidden" name="id" value="'.$id.'">';
224 
225  $massactionbutton = '';
226 
227  print_barre_liste($langs->trans("Invoices"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
228 
229  print"\n<!-- debut table -->\n";
230  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
231  print '<table class="liste centpercent">';
232  print '<tr class="liste_titre">';
233  print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
234  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
235  print_liste_field_titre("AmountInvoice", $_SERVER["PHP_SELF"], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder);
236  print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "pl.amount", "", $param, 'class="right"', $sortfield, $sortorder);
237  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, 'align="center"', $sortfield, $sortorder);
239  print "</tr>\n";
240 
241  $totalinvoices = 0;
242  $totalamount_requested = 0;
243 
244  $invoicetmpcustomer = new Facture($db);
245  $invoicetmpsupplier = new FactureFournisseur($db);
246 
247  while ($i < min($num, $limit))
248  {
249  $obj = $db->fetch_object($resql);
250 
251  if ($obj->type == 'bank-transfer') {
252  $invoicetmp = $invoicetmpsupplier;
253  } else {
254  $invoicetmp = $invoicetmpcustomer;
255  }
256  $invoicetmp->fetch($obj->facid);
257 
258  $thirdpartytmp->fetch($obj->socid);
259 
260  print '<tr class="oddeven">';
261 
262  print "<td>";
263  print $invoicetmp->getNomUrl(1);
264  print "</td>\n";
265 
266  print '<td>';
267  print $thirdpartytmp->getNomUrl(1);
268  print "</td>\n";
269 
270  // Amount of invoice
271  print '<td class="right">'.price($obj->total_ttc)."</td>\n";
272 
273  // Amount requested
274  print '<td class="right">'.price($obj->amount_requested)."</td>\n";
275 
276  // Status of requests
277  print '<td class="center">';
278 
279  if ($obj->statut == 0) {
280  print '-';
281  } elseif ($obj->statut == 2) {
282  if ($obj->type == 'bank-transfer') {
283  print $langs->trans("StatusDebited");
284  } else {
285  print $langs->trans("StatusCredited");
286  }
287  } elseif ($obj->statut == 3) {
288  print '<b>'.$langs->trans("StatusRefused").'</b>';
289  }
290 
291  print "</td>";
292 
293  print "<td></td>";
294 
295  print "</tr>\n";
296 
297  $totalinvoices += $obj->total_ttc;
298  $totalamount_requested += $obj->amount_requested;
299 
300  $i++;
301  }
302 
303  if ($num > 0)
304  {
305  print '<tr class="liste_total">';
306  print '<td>'.$langs->trans("Total").'</td>';
307  print '<td>&nbsp;</td>';
308  print '<td class="right">';
309  //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.
310  if ($totalamount_requested != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices");
311  print "</td>\n";
312  print '<td class="right">';
313  print price($totalamount_requested);
314  print "</td>\n";
315  print '<td>&nbsp;</td>';
316  print '<td>&nbsp;</td>';
317  print "</tr>\n";
318  }
319 
320  print "</table>";
321  print '</div>';
322 
323  $db->free($result);
324 } else {
325  dol_print_error($db);
326 }
327 
328 // End of page
329 llxFooter();
330 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage suppliers invoices.
Class to manage bank accounts.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
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.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage withdrawal receipts.
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 ...
prelevement_prepare_head(BonPrelevement $object)
Prepare array with list of tabs.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
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.
Class to manage invoices.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59