dolibarr  13.0.2
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 <https://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->socid) $socid = $user->socid;
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", $langs->transnoentitiesnoconv("Withdraw")), 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 '<div class="div-table-responsive-no-min">';
75 print '<table class="noborder centpercent">';
76 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
77 
78 print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToWithdraw").'</td>';
79 print '<td class="right">';
80 print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0">';
81 print $bprev->nbOfInvoiceToPay('direct-debit');
82 print '</a>';
83 print '</td></tr>';
84 
85 print '<tr class="oddeven"><td>'.$langs->trans("AmountToWithdraw").'</td>';
86 print '<td class="right">';
87 print price($bprev->SommeAPrelever('direct-debit'), '', '', 1, -1, -1, 'auto');
88 print '</td></tr></table></div><br>';
89 
90 
91 
92 /*
93  * Invoices waiting for withdraw
94  */
95 $sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type,";
96 $sql .= " pfd.date_demande, pfd.amount,";
97 $sql .= " s.nom as name, s.email, s.rowid as socid";
98 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
99 $sql .= " ".MAIN_DB_PREFIX."societe as s";
100 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
101 $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
102 $sql .= " WHERE s.rowid = f.fk_soc";
103 $sql .= " AND f.entity IN (".getEntity('invoice').")";
104 $sql .= " AND f.total_ttc > 0";
105 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS))
106 {
107  $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
108 }
109 $sql .= " AND pfd.traite = 0";
110 $sql .= " AND pfd.ext_payment_id IS NULL";
111 $sql .= " AND pfd.fk_facture = f.rowid";
112 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
113 if ($socid) $sql .= " AND f.fk_soc = ".$socid;
114 
115 $resql = $db->query($sql);
116 if ($resql)
117 {
118  $num = $db->num_rows($resql);
119  $i = 0;
120 
121  print '<div class="div-table-responsive-no-min">';
122  print '<table class="noborder centpercent">';
123  print '<tr class="liste_titre">';
124  print '<th colspan="5">'.$langs->trans("InvoiceWaitingWithdraw").' ('.$num.')</th></tr>';
125  if ($num)
126  {
127  while ($i < $num && $i < 20)
128  {
129  $obj = $db->fetch_object($resql);
130 
131  $invoicestatic->id = $obj->rowid;
132  $invoicestatic->ref = $obj->ref;
133  $invoicestatic->statut = $obj->fk_statut;
134  $invoicestatic->paye = $obj->paye;
135  $invoicestatic->type = $obj->type;
136  $alreadypayed = $invoicestatic->getSommePaiement();
137 
138  $thirdpartystatic->id = $obj->socid;
139  $thirdpartystatic->name = $obj->name;
140  $thirdpartystatic->email = $obj->email;
141 
142  print '<tr class="oddeven"><td>';
143  print $invoicestatic->getNomUrl(1, 'withdraw');
144  print '</td>';
145 
146  print '<td>';
147  print $thirdpartystatic->getNomUrl(1, 'customer');
148  print '</td>';
149 
150  print '<td class="right">';
151  print price($obj->amount);
152  print '</td>';
153 
154  print '<td class="right">';
155  print dol_print_date($db->jdate($obj->date_demande), 'day');
156  print '</td>';
157 
158  print '<td class="right">';
159  print $invoicestatic->getLibStatut(3, $alreadypayed);
160  print '</td>';
161  print '</tr>';
162  $i++;
163  }
164  } else {
165  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("NoInvoiceToWithdraw", $langs->transnoentitiesnoconv("StandingOrders")).'</td></tr>';
166  }
167  print "</table></div><br>";
168 } else {
169  dol_print_error($db);
170 }
171 
172 
173 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
174 
175 
176 /*
177  * Direct debit orders
178  */
179 
180 $limit = 5;
181 $sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
182 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
183 $sql .= " WHERE p.type = 'debit-order'";
184 $sql .= " AND entity IN (".getEntity('prelevement').")";
185 $sql .= " ORDER BY datec DESC";
186 $sql .= $db->plimit($limit);
187 
188 $result = $db->query($sql);
189 if ($result)
190 {
191  $num = $db->num_rows($result);
192  $i = 0;
193 
194  print"\n<!-- debut table -->\n";
195  print '<div class="div-table-responsive-no-min">';
196  print '<table class="noborder centpercent">';
197  print '<tr class="liste_titre">';
198  print '<th>'.$langs->trans("LastWithdrawalReceipt", $limit).'</th>';
199  print '<th>'.$langs->trans("Date").'</th>';
200  print '<th class="right">'.$langs->trans("Amount").'</th>';
201  print '<th class="right">'.$langs->trans("Status").'</th>';
202  print '</tr>';
203 
204  if ($num > 0) {
205  while ($i < min($num, $limit))
206  {
207  $obj = $db->fetch_object($result);
208 
209 
210  print '<tr class="oddeven">';
211 
212  print "<td>";
213  $bprev->id = $obj->rowid;
214  $bprev->ref = $obj->ref;
215  $bprev->statut = $obj->statut;
216  print $bprev->getNomUrl(1);
217  print "</td>\n";
218  print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
219  print '<td class="right">'.price($obj->amount)."</td>\n";
220  print '<td class="right">'.$bprev->getLibStatut(3)."</td>\n";
221 
222  print "</tr>\n";
223  $i++;
224  }
225  } else {
226  print '<tr><td class="opacitymedium" colspan="4">'.$langs->trans("None").'</td></tr>';
227  }
228 
229  print "</table></div><br>";
230  $db->free($result);
231 } else {
232  dol_print_error($db);
233 }
234 
235 
236 print '</div></div></div>';
237 
238 // End of page
239 llxFooter();
240 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
prelevement_check_config()
Check need data to create standigns orders receipt file.
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
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage withdrawal receipts.
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.
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...
Class to manage invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:59