dolibarr 24.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@inodbox.com>
5 * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
30// Load Dolibarr environment
31require '../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array('banks', 'categories', 'withdrawals'));
48
49// Security check
50$socid = GETPOSTINT('socid');
51if ($user->socid) {
52 $socid = $user->socid;
53}
54$result = restrictedArea($user, 'prelevement', '', 'bons');
55
56$usercancreate = $user->hasRight('prelevement', 'bons', 'creer');
57
58
59/*
60 * Actions
61 */
62
63// None
64
65
66/*
67 * View
68 */
69
70llxHeader('', $langs->trans("CustomersStandingOrdersArea"));
71
72if (prelevement_check_config() < 0) {
73 $langs->load("errors");
74 setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByDirectDebit")), null, 'errors');
75}
76
77$newcardbutton = '';
78if ($usercancreate) {
79 $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type=');
80}
81
82print load_fiche_titre($langs->trans("CustomersStandingOrdersArea"), $newcardbutton);
83
84
85print '<div class="fichecenter"><div class="fichethirdleft">';
86
87
88$thirdpartystatic = new Societe($db);
89$invoicestatic = new Facture($db);
90$bprev = new BonPrelevement($db);
91
92print '<div class="div-table-responsive-no-min">';
93print '<table class="noborder centpercent">';
94print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
95
96print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToWithdraw").'</td>';
97print '<td class="right">';
98print '<a class="badge badge-info" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0">';
99print $bprev->nbOfInvoiceToPay('direct-debit');
100print '</a>';
101print '</td></tr>';
102
103print '<tr class="oddeven"><td>'.$langs->trans("AmountToWithdraw").'</td>';
104print '<td class="right"><span class="amount">';
105print price($bprev->SommeAPrelever('direct-debit'), 0, '', 1, -1, -1, 'auto');
106print '</span></td></tr></table></div><br>';
107
108
109
110/*
111 * Invoices waiting for direct debit
112 */
113$sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut as status, f.paye, f.type,";
114$sql .= " pfd.date_demande, pfd.amount,";
115$sql .= " s.nom as name, s.email, s.rowid as socid, s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
116$sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
117$sql .= " ".MAIN_DB_PREFIX."societe as s";
118if (!$user->hasRight('societe', 'client', 'voir')) {
119 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
120}
121$sql .= " , ".MAIN_DB_PREFIX."prelevement_demande as pfd";
122$sql .= " WHERE s.rowid = f.fk_soc";
123$sql .= " AND f.entity IN (".getEntity('invoice').")";
124$sql .= " AND f.total_ttc > 0";
125if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
126 $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
127}
128$sql .= " AND pfd.traite = 0";
129$sql .= " AND pfd.ext_payment_id IS NULL";
130$sql .= " AND pfd.fk_facture = f.rowid";
131if (!$user->hasRight('societe', 'client', 'voir')) {
132 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
133}
134if ($socid) {
135 $sql .= " AND f.fk_soc = ".((int) $socid);
136}
137
138$resql = $db->query($sql);
139if ($resql) {
140 $num = $db->num_rows($resql);
141 $i = 0;
142
143 print '<div class="div-table-responsive-no-min">';
144 print '<table class="noborder centpercent">';
145 print '<tr class="liste_titre">';
146 print '<th colspan="5">'.$langs->trans("InvoiceWaitingWithdraw");
147 print '<a class="badge badge-info marginleftonly" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0">'.$num.'</a>';
148 print '</th></tr>';
149 if ($num) {
150 while ($i < $num && $i < 20) {
151 $obj = $db->fetch_object($resql);
152
153 $invoicestatic->id = $obj->rowid;
154 $invoicestatic->ref = $obj->ref;
155 $invoicestatic->statut = $obj->status; // deprecated
156 $invoicestatic->status = $obj->status;
157 $invoicestatic->paye = $obj->paye;
158 $invoicestatic->paid = $obj->paye;
159 $invoicestatic->type = $obj->type;
160
161 $totalallpayments = $invoicestatic->getSommePaiement(0);
162 $totalallpayments += $invoicestatic->getSumCreditNotesUsed(0);
163 $totalallpayments += $invoicestatic->getSumDepositsUsed(0);
164
165 $thirdpartystatic->id = $obj->socid;
166 $thirdpartystatic->name = $obj->name;
167 $thirdpartystatic->email = $obj->email;
168 $thirdpartystatic->tva_intra = $obj->tva_intra;
169 $thirdpartystatic->siren = $obj->idprof1;
170 $thirdpartystatic->siret = $obj->idprof2;
171 $thirdpartystatic->ape = $obj->idprof3;
172 $thirdpartystatic->idprof1 = $obj->idprof1;
173 $thirdpartystatic->idprof2 = $obj->idprof2;
174 $thirdpartystatic->idprof3 = $obj->idprof3;
175 $thirdpartystatic->idprof4 = $obj->idprof4;
176 $thirdpartystatic->idprof5 = $obj->idprof5;
177 $thirdpartystatic->idprof6 = $obj->idprof6;
178
179 print '<tr class="oddeven"><td class="nowraponall">';
180 print $invoicestatic->getNomUrl(1, 'withdraw');
181 print '</td>';
182
183 print '<td class="tdoverflowmax150">';
184 print $thirdpartystatic->getNomUrl(1, 'customer');
185 print '</td>';
186
187 print '<td class="right">';
188 print '<span class="amount">'.price($obj->amount).'</span>';
189 print '</td>';
190
191 print '<td class="right">';
192 print dol_print_date($db->jdate($obj->date_demande), 'day');
193 print '</td>';
194
195 print '<td class="right">';
196 print $invoicestatic->getLibStatut(3, $totalallpayments);
197 print '</td>';
198 print '</tr>';
199 $i++;
200 }
201 } else {
202 $titlefortab = $langs->transnoentitiesnoconv("StandingOrders");
203 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoInvoiceToWithdraw", $titlefortab, $titlefortab).'</span></td></tr>';
204 }
205 print "</table></div><br>";
206} else {
208}
209
210
211print '</div><div class="fichetwothirdright">';
212
213
214/*
215 * Direct debit orders
216 */
217
218$limit = 5;
219$sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
220$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
221$sql .= " WHERE p.type = 'debit-order'";
222$sql .= " AND entity IN (".getEntity('prelevement').")";
223$sql .= " ORDER BY datec DESC";
224$sql .= $db->plimit($limit);
225
226$result = $db->query($sql);
227if ($result) {
228 $num = $db->num_rows($result);
229 $i = 0;
230
231 print"\n<!-- debut table -->\n";
232 print '<div class="div-table-responsive-no-min">';
233 print '<table class="noborder centpercent">';
234 print '<tr class="liste_titre">';
235 print '<th>'.$langs->trans("LastWithdrawalReceipt", $limit);
236 print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/orders_list.php?sortfield=p.datec&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
237 print '</th>';
238 print '<th>'.$langs->trans("Date").'</th>';
239 print '<th class="right">'.$langs->trans("Amount").'</th>';
240 print '<th class="right">'.$langs->trans("Status").'</th>';
241 print '</tr>';
242
243 if ($num > 0) {
244 while ($i < min($num, $limit)) {
245 $obj = $db->fetch_object($result);
246
247 $bprev->id = $obj->rowid;
248 $bprev->ref = $obj->ref;
249 $bprev->statut = $obj->statut;
250
251 print '<tr class="oddeven">';
252
253 print '<td class="nowraponall">';
254 print $bprev->getNomUrl(1);
255 print "</td>\n";
256 print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
257 print '<td class="right nowraponall"><span class="amount">'.price($obj->amount)."</span></td>\n";
258 print '<td class="right">'.$bprev->getLibStatut(3)."</td>\n";
259
260 print "</tr>\n";
261 $i++;
262 }
263 } else {
264 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
265 }
266
267 print "</table></div><br>";
268 $db->free($result);
269} else {
271}
272
273
274print '</div></div>';
275
276// End of page
277llxFooter();
278$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage withdrawal receipts.
Class to manage invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
prelevement_check_config($type='direct-debit')
Check need data to create standigns orders receipt file.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.