dolibarr  9.0.0
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@inodbox.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 // Load translation files required by the page
37 $langs->loadLangs(array('banks', 'categories', 'withdrawals'));
38 
39 // Security check
40 $socid = GETPOST('socid','int');
41 if ($user->societe_id) $socid=$user->societe_id;
42 $result = restrictedArea($user, 'prelevement','','');
43 
44 
45 /*
46  * Actions
47  */
48 
49 
50 
51 
52 /*
53  * View
54  */
55 
56 llxHeader('',$langs->trans("CustomersStandingOrdersArea"));
57 
58 if (prelevement_check_config() < 0)
59 {
60  $langs->load("errors");
61  setEventMessages($langs->trans("ErrorModuleSetupNotComplete"), null, 'errors');
62 }
63 
64 print load_fiche_titre($langs->trans("CustomersStandingOrdersArea"));
65 
66 
67 print '<div class="fichecenter"><div class="fichethirdleft">';
68 
69 
70 $thirdpartystatic=new Societe($db);
71 $invoicestatic=new Facture($db);
72 $bprev = new BonPrelevement($db);
73 
74 print '<table class="noborder" width="100%">';
75 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
76 
77 print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToWithdraw").'</td>';
78 print '<td align="right">';
79 print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0">';
80 print $bprev->NbFactureAPrelever();
81 print '</a>';
82 print '</td></tr>';
83 
84 print '<tr class="oddeven"><td>'.$langs->trans("AmountToWithdraw").'</td>';
85 print '<td align="right">';
86 print price($bprev->SommeAPrelever(),'','',1,-1,-1,'auto');
87 print '</td></tr></table><br>';
88 
89 
90 
91 /*
92  * Invoices waiting for withdraw
93  */
94 $sql = "SELECT f.facnumber, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type,";
95 $sql.= " pfd.date_demande, pfd.amount,";
96 $sql.= " s.nom as name, s.rowid as socid";
97 $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
98 $sql.= " ".MAIN_DB_PREFIX."societe as s";
99 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
100 $sql.= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
101 $sql.= " WHERE s.rowid = f.fk_soc";
102 $sql.= " AND f.entity = ".$conf->entity;
103 $sql.= " AND pfd.traite = 0 AND pfd.fk_facture = f.rowid";
104 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
105 if ($socid) $sql.= " AND f.fk_soc = ".$socid;
106 
107 $resql=$db->query($sql);
108 if ($resql)
109 {
110  $num = $db->num_rows($resql);
111  $i = 0;
112 
113  print '<table class="noborder" width="100%">';
114  print '<tr class="liste_titre">';
115  print '<th colspan="5">'.$langs->trans("InvoiceWaitingWithdraw").' ('.$num.')</th></tr>';
116  if ($num)
117  {
118  while ($i < $num && $i < 20)
119  {
120  $obj = $db->fetch_object($resql);
121 
122  $invoicestatic->id=$obj->rowid;
123  $invoicestatic->ref=$obj->facnumber;
124  $invoicestatic->statut=$obj->fk_statut;
125  $invoicestatic->paye=$obj->paye;
126  $invoicestatic->type=$obj->type;
127  $alreadypayed=$invoicestatic->getSommePaiement();
128 
129 
130  print '<tr class="oddeven"><td>';
131  print $invoicestatic->getNomUrl(1,'withdraw');
132  print '</td>';
133 
134  print '<td>';
135  $thirdpartystatic->id=$obj->socid;
136  $thirdpartystatic->name=$obj->name;
137  print $thirdpartystatic->getNomUrl(1,'customer');
138  print '</td>';
139 
140  print '<td align="right">';
141  print price($obj->amount);
142  print '</td>';
143 
144  print '<td align="right">';
145  print dol_print_date($db->jdate($obj->date_demande),'day');
146  print '</td>';
147 
148  print '<td align="right">';
149  print $invoicestatic->getLibStatut(3,$alreadypayed);
150  print '</td>';
151  print '</tr>';
152  $i++;
153  }
154  }
155  else
156  {
157  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("NoInvoiceToWithdraw", $langs->transnoentitiesnoconv("StandingOrders")).'</td></tr>';
158  }
159  print "</table><br>";
160 }
161 else
162 {
163  dol_print_error($db);
164 }
165 
166 
167 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
168 
169 
170 /*
171  * Withdraw receipts
172  */
173 $limit=5;
174 $sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
175 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
176 $sql.= " ORDER BY datec DESC";
177 $sql.= $db->plimit($limit);
178 
179 $result = $db->query($sql);
180 if ($result)
181 {
182  $num = $db->num_rows($result);
183  $i = 0;
184 
185  print"\n<!-- debut table -->\n";
186  print '<table class="noborder" width="100%">';
187  print '<tr class="liste_titre"><th>'.$langs->trans("LastWithdrawalReceipt",$limit).'</th>';
188  print '<th>'.$langs->trans("Date").'</th>';
189  print '<th align="right">'.$langs->trans("Amount").'</th>';
190  print '<th align="right">'.$langs->trans("Status").'</th>';
191  print '</tr>';
192 
193  while ($i < min($num,$limit))
194  {
195  $obj = $db->fetch_object($result);
196 
197 
198  print '<tr class="oddeven">';
199 
200  print "<td>";
201  $bprev->id=$obj->rowid;
202  $bprev->ref=$obj->ref;
203  $bprev->statut=$obj->statut;
204  print $bprev->getNomUrl(1);
205  print "</td>\n";
206  print '<td>'.dol_print_date($db->jdate($obj->datec),"dayhour")."</td>\n";
207  print '<td align="right">'.price($obj->amount)."</td>\n";
208  print '<td align="right">'.$bprev->getLibStatut(3)."</td>\n";
209 
210  print "</tr>\n";
211  $i++;
212  }
213  print "</table><br>";
214  $db->free($result);
215 }
216 else
217 {
218  dol_print_error($db);
219 }
220 
221 
222 print '</div></div></div>';
223 
224 // End of page
225 llxFooter();
226 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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:1053
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...
Class to manage third parties objects (customers, suppliers, prospects...)
llxHeader()
Header empty.
Definition: index.php:36
Class to manage withdrawal receipts.
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).
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage invoices.