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