dolibarr  9.0.0
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 <http://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', 'companies', 'withdrawals', 'bills'));
36 
37 // Securite acces client
38 if ($user->societe_id > 0) accessforbidden();
39 
40 // Get supervariables
41 $prev_id = GETPOST('id','int');
42 $socid = GETPOST('socid','int');
43 $ref = GETPOST('ref', 'alpha');
44 
45 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
46 $sortfield = GETPOST("sortfield",'alpha');
47 $sortorder = GETPOST("sortorder",'alpha');
48 $page = GETPOST("page",'int');
49 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
50 $offset = $limit * $page;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (! $sortfield) $sortfield='p.ref';
54 if (! $sortorder) $sortorder='DESC';
55 
56 $object = new BonPrelevement($db,"");
57 
58 
59 
60 /*
61  * View
62  */
63 
64 $invoicetmp = new Facture($db);
65 $thirdpartytmp = new Societe($db);
66 
67 llxHeader('',$langs->trans("WithdrawalsReceipts"));
68 
69 if ($prev_id > 0 || $ref)
70 {
71  if ($object->fetch($prev_id, $ref) >= 0)
72  {
73  $head = prelevement_prepare_head($object);
74  dol_fiche_head($head, 'invoices', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
75 
76  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/bons.php">'.$langs->trans("BackToList").'</a>';
77 
78  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
79 
80  print '<div class="fichecenter">';
81  print '<div class="underbanner clearboth"></div>';
82  print '<table class="border" width="100%">';
83 
84  //print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
85  print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec,'day').'</td></tr>';
86  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
87  // Status
88  //print '<tr><td>'.$langs->trans('Status').'</td><td>'.$object->getLibStatut(1).'</td></tr>';
89 
90  if($object->date_trans <> 0)
91  {
92  $muser = new User($db);
93  $muser->fetch($object->user_trans);
94 
95  print '<tr><td>'.$langs->trans("TransData").'</td><td>';
96  print dol_print_date($object->date_trans,'day');
97  print ' '.$langs->trans("By").' '.$muser->getFullName($langs).'</td></tr>';
98  print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
99  print $object->methodes_trans[$object->method_trans];
100  print '</td></tr>';
101  }
102  if($object->date_credit <> 0)
103  {
104  print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
105  print dol_print_date($object->date_credit,'day');
106  print '</td></tr>';
107  }
108 
109  print '</table>';
110 
111  print '<br>';
112 
113  print '<div class="underbanner clearboth"></div>';
114  print '<table class="border" width="100%">';
115 
116  $acc = new Account($db);
117  $result=$acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT);
118 
119  print '<tr><td class="titlefield">';
120  print $langs->trans("BankToReceiveWithdraw");
121  print '</td>';
122  print '<td>';
123  if ($acc->id > 0)
124  print $acc->getNomUrl(1);
125  print '</td>';
126  print '</tr>';
127 
128  print '<tr><td class="titlefield">';
129  print $langs->trans("WithdrawalFile").'</td><td>';
130  $relativepath = 'receipts/'.$object->ref.'.xml';
131  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart=prelevement&amp;file='.urlencode($relativepath).'">'.$relativepath.'</a>';
132  print '</td></tr></table>';
133 
134  print '</div>';
135 
136  dol_fiche_end();
137  }
138  else
139  {
140  dol_print_error($db);
141  }
142 }
143 
144 
145 // List of invoices
146 $sql = "SELECT pf.rowid,";
147 $sql.= " f.rowid as facid, f.facnumber as ref, f.total_ttc,";
148 $sql.= " s.rowid as socid, s.nom as name, pl.statut, pl.amount as amount_requested";
149 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
150 $sql.= ", ".MAIN_DB_PREFIX."prelevement_lignes as pl";
151 $sql.= ", ".MAIN_DB_PREFIX."prelevement_facture as pf";
152 $sql.= ", ".MAIN_DB_PREFIX."facture as f";
153 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
154 $sql.= " WHERE pf.fk_prelevement_lignes = pl.rowid";
155 $sql.= " AND pl.fk_prelevement_bons = p.rowid";
156 $sql.= " AND f.fk_soc = s.rowid";
157 $sql.= " AND pf.fk_facture = f.rowid";
158 $sql.= " AND f.entity = ".$conf->entity;
159 if ($prev_id) $sql.= " AND p.rowid=".$prev_id;
160 if ($socid) $sql.= " AND s.rowid = ".$socid;
161 $sql.= $db->order($sortfield,$sortorder);
162 
163 // Count total nb of records
164 $nbtotalofrecords = '';
165 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
166 {
167  $result = $db->query($sql);
168  $nbtotalofrecords = $db->num_rows($result);
169  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
170  {
171  $page = 0;
172  $offset = 0;
173  }
174 }
175 
176 $sql.= $db->plimit($limit + 1,$offset);
177 
178 $result = $db->query($sql);
179 if ($result)
180 {
181  $num = $db->num_rows($result);
182  $i = 0;
183 
184  $param = "&amp;id=".$prev_id;
185 
186  // Lines of title fields
187  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
188  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
189  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
190  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
191  print '<input type="hidden" name="action" value="list">';
192  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
193  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
194  print '<input type="hidden" name="page" value="'.$page.'">';
195  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
196  print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
197 
198  $massactionbutton='';
199 
200  print_barre_liste($langs->trans("Invoices"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
201 
202  print"\n<!-- debut table -->\n";
203  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
204  print '<table class="liste" width="100%">';
205  print '<tr class="liste_titre">';
206  print_liste_field_titre("Bill",$_SERVER["PHP_SELF"],"p.ref",'',$param,'',$sortfield,$sortorder);
207  print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],"s.nom",'',$param,'',$sortfield,$sortorder);
208  print_liste_field_titre("AmountInvoice",$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
209  print_liste_field_titre("AmountRequested",$_SERVER["PHP_SELF"],"pl.amount","",$param,'align="right"',$sortfield,$sortorder);
210  print_liste_field_titre("StatusDebitCredit",$_SERVER["PHP_SELF"],"","",$param,'align="center"',$sortfield,$sortorder);
212  print "</tr>\n";
213 
214  $totalinvoices = 0;
215  $totalamount_requested = 0;
216 
217  while ($i < min($num, $limit))
218  {
219  $obj = $db->fetch_object($result);
220 
221  $invoicetmp->id = $obj->facid;
222  $invoicetmp->ref = $obj->ref;
223 
224  $thirdpartytmp->id = $obj->socid;
225  $thirdpartytmp->name = $obj->name;
226 
227  print '<tr class="oddeven">';
228 
229  print "<td>";
230  print $invoicetmp->getNomUrl(1);
231  print "</td>\n";
232 
233  print '<td>';
234  print $thirdpartytmp->getNomUrl(1);
235  print "</td>\n";
236 
237  // Amount of invoice
238  print '<td align="right">'.price($obj->total_ttc)."</td>\n";
239 
240  // Amount requested
241  print '<td align="right">'.price($obj->amount_requested)."</td>\n";
242 
243  // Status of requests
244  print '<td align="center">';
245 
246  if ($obj->statut == 0)
247  {
248  print '-';
249  }
250  elseif ($obj->statut == 2)
251  {
252  print $langs->trans("StatusCredited");
253  }
254  elseif ($obj->statut == 3)
255  {
256  print '<b>'.$langs->trans("StatusRefused").'</b>';
257  }
258 
259  print "</td>";
260 
261  print "<td></td>";
262 
263  print "</tr>\n";
264 
265  $totalinvoices += $obj->total_ttc;
266  $totalamount_requested += $obj->amount_requested;
267 
268  $i++;
269  }
270 
271  if ($num > 0)
272  {
273  print '<tr class="liste_total">';
274  print '<td>'.$langs->trans("Total").'</td>';
275  print '<td>&nbsp;</td>';
276  print '<td align="right">';
277  //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.
278  if ($totalamount_requested != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices");
279  print "</td>\n";
280  print '<td align="right">';
281  print price($totalamount_requested);
282  print "</td>\n";
283  print '<td>&nbsp;</td>';
284  print '<td>&nbsp;</td>';
285  print "</tr>\n";
286  }
287 
288  print "</table>";
289  print '</div>';
290 
291  $db->free($result);
292 }
293 else
294 {
295  dol_print_error($db);
296 }
297 
298 // End of page
299 llxFooter();
300 $db->close();
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
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.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage bank accounts.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage withdrawal receipts.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
prelevement_prepare_head(BonPrelevement $object)
Prepare array with list of tabs.
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
Class to manage invoices.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.