dolibarr  7.0.0-beta
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
29 require('../../main.inc.php');
30 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35 
36 $langs->load("banks");
37 $langs->load("categories");
38 $langs->load("withdrawals");
39 
40 // Security check
41 $socid = GETPOST('socid','int');
42 if ($user->societe_id) $socid=$user->societe_id;
43 $result = restrictedArea($user, 'prelevement','','');
44 
45 
46 /*
47  * Actions
48  */
49 
50 
51 
52 
53 /*
54  * View
55  */
56 
57 llxHeader('',$langs->trans("CustomersStandingOrdersArea"));
58 
59 if (prelevement_check_config() < 0)
60 {
61  $langs->load("errors");
62  setEventMessages($langs->trans("ErrorModuleSetupNotComplete"), null, 'errors');
63 }
64 
65 print load_fiche_titre($langs->trans("CustomersStandingOrdersArea"));
66 
67 
68 print '<div class="fichecenter"><div class="fichethirdleft">';
69 
70 
71 $thirdpartystatic=new Societe($db);
72 $invoicestatic=new Facture($db);
73 $bprev = new BonPrelevement($db);
74 $var=true;
75 
76 print '<table class="noborder" width="100%">';
77 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
78 
79 print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToWithdraw").'</td>';
80 print '<td align="right">';
81 print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0">';
82 print $bprev->NbFactureAPrelever();
83 print '</a>';
84 print '</td></tr>';
85 
86 print '<tr class="oddeven"><td>'.$langs->trans("AmountToWithdraw").'</td>';
87 print '<td align="right">';
88 print price($bprev->SommeAPrelever(),'','',1,-1,-1,'auto');
89 print '</td></tr></table><br>';
90 
91 
92 
93 /*
94  * Invoices waiting for withdraw
95  */
96 $sql = "SELECT f.facnumber, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type,";
97 $sql.= " pfd.date_demande, pfd.amount,";
98 $sql.= " s.nom as name, s.rowid as socid";
99 $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
100 $sql.= " ".MAIN_DB_PREFIX."societe as s";
101 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
102 $sql.= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
103 $sql.= " WHERE s.rowid = f.fk_soc";
104 $sql.= " AND f.entity = ".$conf->entity;
105 $sql.= " AND pfd.traite = 0 AND pfd.fk_facture = f.rowid";
106 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
107 if ($socid) $sql.= " AND f.fk_soc = ".$socid;
108 
109 $resql=$db->query($sql);
110 if ($resql)
111 {
112  $num = $db->num_rows($resql);
113  $i = 0;
114 
115  print '<table class="noborder" width="100%">';
116  print '<tr class="liste_titre">';
117  print '<th colspan="5">'.$langs->trans("InvoiceWaitingWithdraw").' ('.$num.')</th></tr>';
118  if ($num)
119  {
120  $var = True;
121  while ($i < $num && $i < 20)
122  {
123  $obj = $db->fetch_object($resql);
124 
125  $invoicestatic->id=$obj->rowid;
126  $invoicestatic->ref=$obj->facnumber;
127  $invoicestatic->statut=$obj->fk_statut;
128  $invoicestatic->paye=$obj->paye;
129  $invoicestatic->type=$obj->type;
130  $alreadypayed=$invoicestatic->getSommePaiement();
131 
132 
133  print '<tr class="oddeven"><td>';
134  print $invoicestatic->getNomUrl(1,'withdraw');
135  print '</td>';
136 
137  print '<td>';
138  $thirdpartystatic->id=$obj->socid;
139  $thirdpartystatic->name=$obj->name;
140  print $thirdpartystatic->getNomUrl(1,'customer');
141  print '</td>';
142 
143  print '<td align="right">';
144  print price($obj->amount);
145  print '</td>';
146 
147  print '<td align="right">';
148  print dol_print_date($db->jdate($obj->date_demande),'day');
149  print '</td>';
150 
151  print '<td align="right">';
152  print $invoicestatic->getLibStatut(3,$alreadypayed);
153  print '</td>';
154  print '</tr>';
155  $i++;
156  }
157  }
158  else
159  {
160  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("NoInvoiceToWithdraw", $langs->transnoentitiesnoconv("StandingOrders")).'</td></tr>';
161  }
162  print "</table><br>";
163 }
164 else
165 {
166  dol_print_error($db);
167 }
168 
169 
170 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
171 
172 
173 /*
174  * Withdraw receipts
175  */
176 $limit=5;
177 $sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
178 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
179 $sql.= " ORDER BY datec DESC";
180 $sql.= $db->plimit($limit);
181 
182 $result = $db->query($sql);
183 if ($result)
184 {
185  $num = $db->num_rows($result);
186  $i = 0;
187  $var=True;
188 
189  print"\n<!-- debut table -->\n";
190  print '<table class="noborder" width="100%">';
191  print '<tr class="liste_titre"><th>'.$langs->trans("LastWithdrawalReceipt",$limit).'</th>';
192  print '<th>'.$langs->trans("Date").'</th>';
193  print '<th align="right">'.$langs->trans("Amount").'</th>';
194  print '<th align="right">'.$langs->trans("Status").'</th>';
195  print '</tr>';
196 
197  while ($i < min($num,$limit))
198  {
199  $obj = $db->fetch_object($result);
200 
201 
202  print '<tr class="oddeven">';
203 
204  print "<td>";
205  $bprev->id=$obj->rowid;
206  $bprev->ref=$obj->ref;
207  $bprev->statut=$obj->statut;
208  print $bprev->getNomUrl(1);
209  print "</td>\n";
210  print '<td>'.dol_print_date($db->jdate($obj->datec),"dayhour")."</td>\n";
211  print '<td align="right">'.price($obj->amount)."</td>\n";
212  print '<td align="right">'.$bprev->getLibStatut(3)."</td>\n";
213 
214  print "</tr>\n";
215  $i++;
216  }
217  print "</table><br>";
218  $db->free($result);
219 }
220 else
221 {
222  dol_print_error($db);
223 }
224 
225 
226 print '</div></div></div>';
227 
228 llxFooter();
229 
230 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
prelevement_check_config()
Check need data to create standigns orders receipt file.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage third parties objects (customers, suppliers, prospects...)
llxHeader()
Header empty.
Definition: index.php:37
Class to manage withdrawal receipts.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->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)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
Class to manage invoices.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.