dolibarr 21.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 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 withdraw
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").' ('.$num.')</th></tr>';
147 if ($num) {
148 while ($i < $num && $i < 20) {
149 $obj = $db->fetch_object($resql);
150
151 $invoicestatic->id = $obj->rowid;
152 $invoicestatic->ref = $obj->ref;
153 $invoicestatic->statut = $obj->status;
154 $invoicestatic->status = $obj->status;
155 $invoicestatic->paye = $obj->paye;
156 $invoicestatic->type = $obj->type;
157
158 $totalallpayments = $invoicestatic->getSommePaiement(0);
159 $totalallpayments += $invoicestatic->getSumCreditNotesUsed(0);
160 $totalallpayments += $invoicestatic->getSumDepositsUsed(0);
161
162 $thirdpartystatic->id = $obj->socid;
163 $thirdpartystatic->name = $obj->name;
164 $thirdpartystatic->email = $obj->email;
165 $thirdpartystatic->tva_intra = $obj->tva_intra;
166 $thirdpartystatic->siren = $obj->idprof1;
167 $thirdpartystatic->siret = $obj->idprof2;
168 $thirdpartystatic->ape = $obj->idprof3;
169 $thirdpartystatic->idprof1 = $obj->idprof1;
170 $thirdpartystatic->idprof2 = $obj->idprof2;
171 $thirdpartystatic->idprof3 = $obj->idprof3;
172 $thirdpartystatic->idprof4 = $obj->idprof4;
173 $thirdpartystatic->idprof5 = $obj->idprof5;
174 $thirdpartystatic->idprof6 = $obj->idprof6;
175
176 print '<tr class="oddeven"><td class="nowraponall">';
177 print $invoicestatic->getNomUrl(1, 'withdraw');
178 print '</td>';
179
180 print '<td class="tdoverflowmax150">';
181 print $thirdpartystatic->getNomUrl(1, 'customer');
182 print '</td>';
183
184 print '<td class="right">';
185 print '<span class="amount">'.price($obj->amount).'</span>';
186 print '</td>';
187
188 print '<td class="right">';
189 print dol_print_date($db->jdate($obj->date_demande), 'day');
190 print '</td>';
191
192 print '<td class="right">';
193 print $invoicestatic->getLibStatut(3, $totalallpayments);
194 print '</td>';
195 print '</tr>';
196 $i++;
197 }
198 } else {
199 $titlefortab = $langs->transnoentitiesnoconv("StandingOrders");
200 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoInvoiceToWithdraw", $titlefortab, $titlefortab).'</span></td></tr>';
201 }
202 print "</table></div><br>";
203} else {
204 dol_print_error($db);
205}
206
207
208print '</div><div class="fichetwothirdright">';
209
210
211/*
212 * Direct debit orders
213 */
214
215$limit = 5;
216$sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
217$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
218$sql .= " WHERE p.type = 'debit-order'";
219$sql .= " AND entity IN (".getEntity('prelevement').")";
220$sql .= " ORDER BY datec DESC";
221$sql .= $db->plimit($limit);
222
223$result = $db->query($sql);
224if ($result) {
225 $num = $db->num_rows($result);
226 $i = 0;
227
228 print"\n<!-- debut table -->\n";
229 print '<div class="div-table-responsive-no-min">';
230 print '<table class="noborder centpercent">';
231 print '<tr class="liste_titre">';
232 print '<th>'.$langs->trans("LastWithdrawalReceipt", $limit).'</th>';
233 print '<th>'.$langs->trans("Date").'</th>';
234 print '<th class="right">'.$langs->trans("Amount").'</th>';
235 print '<th class="right">'.$langs->trans("Status").'</th>';
236 print '</tr>';
237
238 if ($num > 0) {
239 while ($i < min($num, $limit)) {
240 $obj = $db->fetch_object($result);
241
242 $bprev->id = $obj->rowid;
243 $bprev->ref = $obj->ref;
244 $bprev->statut = $obj->statut;
245
246 print '<tr class="oddeven">';
247
248 print '<td class="nowraponall">';
249 print $bprev->getNomUrl(1);
250 print "</td>\n";
251 print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
252 print '<td class="right nowraponall"><span class="amount">'.price($obj->amount)."</span></td>\n";
253 print '<td class="right">'.$bprev->getLibStatut(3)."</td>\n";
254
255 print "</tr>\n";
256 $i++;
257 }
258 } else {
259 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
260 }
261
262 print "</table></div><br>";
263 $db->free($result);
264} else {
265 dol_print_error($db);
266}
267
268
269print '</div></div>';
270
271// End of page
272llxFooter();
273$db->close();
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:71
Class to manage withdrawal receipts.
Class to manage invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
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)
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...
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.