dolibarr 23.0.3
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-2020 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 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
31// Load Dolibarr environment
32require '../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
35require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
38require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
39
48// Load translation files required by the page
49$langs->loadLangs(array('banks', 'categories', 'withdrawals'));
50
51// Security check
52$socid = GETPOSTINT('socid');
53if ($user->socid) {
54 $socid = $user->socid;
55}
56$result = restrictedArea($user, 'paymentbybanktransfer', '', '');
57
58$usercancreate = $user->hasRight('paymentbybanktransfer', 'create');
59
60
61/*
62 * Actions
63 */
64
65// None
66
67
68/*
69 * View
70 */
71
72llxHeader('', $langs->trans("SuppliersStandingOrdersArea"));
73
74if (prelevement_check_config('bank-transfer') < 0) {
75 $langs->load("errors");
76 setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByBankTransfer")), null, 'errors');
77}
78
79$thirdpartystatic = new Societe($db);
80$invoicestatic = new FactureFournisseur($db);
81$bprev = new BonPrelevement($db);
82$salary = new Salary($db);
83$userstatic = new User($db);
84
85$newcardbutton = '';
86if ($usercancreate) {
87 $newcardbutton .= dolGetButtonTitle($langs->trans('NewPaymentByBankTransfer'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type=bank-transfer');
88}
89
90print load_fiche_titre($langs->trans("SuppliersStandingOrdersArea"), $newcardbutton);
91
92
93print '<div class="fichecenter"><div class="fichethirdleft">';
94
95
96print '<div class="div-table-responsive-no-min">';
97print '<table class="noborder centpercent">';
98print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
99
100$totaltoshow = 0;
101
102if (isModEnabled('supplier_invoice')) {
103 print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToPayByBankTransfer").'</td>';
104 print '<td class="right">';
105 $amounttoshow = $bprev->SommeAPrelever('bank-transfer');
106 print '<a class="badge badge-info" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0&type=bank-transfer" title="'.price($amounttoshow).'">';
107 print $bprev->nbOfInvoiceToPay('bank-transfer');
108 print '</a>';
109 print '</td></tr>';
110 $totaltoshow += $amounttoshow;
111}
112
113if (isModEnabled('salaries')) {
114 print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToPayByBankTransferForSalaries").'</td>';
115 print '<td class="right">';
116 $amounttoshow = $bprev->SommeAPrelever('bank-transfer', 'salary');
117 print '<a class="badge badge-info" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0&type=bank-transfer&sourcetype=salary" title="'.price($amounttoshow).'">';
118 print $bprev->nbOfInvoiceToPay('bank-transfer', 'salary');
119 print '</a>';
120 print '</td></tr>';
121 $totaltoshow += $amounttoshow;
122}
123
124print '<tr class="oddeven"><td>'.$langs->trans("Total").'</td>';
125print '<td class="right"><span class="amount nowraponall">';
126print price($totaltoshow, 0, '', 1, -1, -1, 'auto');
127print '</span></td></tr></table></div><br>';
128
129
130/*
131 * Invoices waiting for credit transfer
132 */
133if (isModEnabled('supplier_invoice')) {
134 $sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type, f.datef, f.date_lim_reglement,";
135 $sql .= " pfd.date_demande, pfd.amount,";
136 $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";
137 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
138 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
139 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pfd";
140 $sql .= " WHERE s.rowid = f.fk_soc";
141 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
142 $sql .= " AND f.total_ttc > 0";
143 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
144 $sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
145 }
146 $sql .= " AND pfd.traite = 0";
147 $sql .= " AND pfd.ext_payment_id IS NULL";
148 $sql .= " AND pfd.fk_facture_fourn = f.rowid";
149 if ($socid) {
150 $sql .= " AND f.fk_soc = ".((int) $socid);
151 }
152
153 $resql = $db->query($sql);
154
155 if ($resql) {
156 $num = $db->num_rows($resql);
157 $i = 0;
158
159 print '<div class="div-table-responsive-no-min">';
160 print '<table class="noborder centpercent">';
161 print '<tr class="liste_titre">';
162 print '<th colspan="5">'.$langs->trans("SupplierInvoiceWaitingWithdraw");
163 print '<a class="badge badge-info marginleftonly" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0&type=bank-transfer">'.$num.'</a>';
164 print '</th></tr>';
165 if ($num) {
166 while ($i < $num && $i < 20) {
167 $obj = $db->fetch_object($resql);
168
169 $invoicestatic->id = $obj->rowid;
170 $invoicestatic->ref = $obj->ref;
171 $invoicestatic->status = $obj->fk_statut;
172 $invoicestatic->statut = $obj->fk_statut; // For backward compatibility
173 $invoicestatic->paye = $obj->paye;
174 $invoicestatic->paid = $obj->paye;
175 $invoicestatic->type = $obj->type;
176 $invoicestatic->date = $db->jdate($obj->datef);
177 $invoicestatic->date_echeance = $db->jdate($obj->date_lim_reglement);
178 $invoicestatic->total_ttc = $obj->total_ttc;
179
180 $alreadypayed = $invoicestatic->getSommePaiement();
181
182 $thirdpartystatic->id = $obj->socid;
183 $thirdpartystatic->name = $obj->name;
184 $thirdpartystatic->email = $obj->email;
185 $thirdpartystatic->tva_intra = $obj->tva_intra;
186 $thirdpartystatic->idprof1 = $obj->idprof1;
187 $thirdpartystatic->idprof2 = $obj->idprof2;
188 $thirdpartystatic->idprof3 = $obj->idprof3;
189 $thirdpartystatic->idprof4 = $obj->idprof4;
190 $thirdpartystatic->idprof5 = $obj->idprof5;
191 $thirdpartystatic->idprof6 = $obj->idprof6;
192
193
194 print '<tr class="oddeven"><td class="nowraponall">';
195 print $invoicestatic->getNomUrl(1, 'withdraw');
196 print '</td>';
197
198 print '<td class="tdoverflowmax150">';
199 print $thirdpartystatic->getNomUrl(1, 'supplier');
200 print '</td>';
201
202 print '<td class="right">';
203 print '<span class="amount">'.price($obj->amount).'</span>';
204 print '</td>';
205
206 print '<td class="right">';
207 print dol_print_date($db->jdate($obj->date_demande), 'day');
208 print '</td>';
209
210 print '<td class="right">';
211 print $invoicestatic->getLibStatut(3, $alreadypayed);
212 print '</td>';
213 print '</tr>';
214 $i++;
215 }
216 } else {
217 $titlefortab = $langs->transnoentitiesnoconv("BankTransfer");
218 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoSupplierInvoiceToWithdraw", $titlefortab, $titlefortab).'</span></td></tr>';
219 }
220 print "</table></div><br>";
221 } else {
222 dol_print_error($db);
223 }
224}
225
226if (isModEnabled('salaries')) {
227 $sqlForSalary = "SELECT * FROM ".MAIN_DB_PREFIX."salary as s, ".MAIN_DB_PREFIX."prelevement_demande as pd";
228 $sqlForSalary .= " WHERE s.rowid = pd.fk_salary AND s.paye = 0 AND pd.traite = 0";
229 $sqlForSalary .= " AND s.entity IN (".getEntity('salary').")";
230
231 $resql2 = $db->query($sqlForSalary);
232 if ($resql2) {
233 $numRow = $db->num_rows($resql2);
234 $j = 0 ;
235
236 print '<div class="div-table-responsive-no-min">';
237 print '<table class="noborder rightpercent">';
238 print '<tr class="liste_titre">';
239 print '<th colspan="5">'.$langs->trans("SalaryInvoiceWaitingWithdraw");
240 print '<a class="badge badge-info marginleftonly" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0&type=bank-transfer&sourcetype=salary">'.$numRow.'</a>';
241 print '</th></tr>';
242
243 if ($numRow) {
244 while ($j < $numRow && $j < 10) {
245 $objSalary = $db->fetch_object($resql2);
246
247 $userstatic->fetch($objSalary->fk_user);
248
249 $salary->fetch($objSalary->fk_salary);
250
251 $alreadypayedS = $salary->getSommePaiement();
252
253 print '<tr class="oddeven"><td class="nowraponall">';
254 print $salary->getNomUrl(1);
255 print '</td>';
256
257 print '<td class="tdoverflowmax150">';
258 print $userstatic->getNomUrl(-1);
259 print '</td>';
260
261 print '<td class="right">';
262 print '<span class="amount">'.price($objSalary->amount).'</span>';
263 print '</td>';
264
265 print '<td class="right" title="'.$langs->trans("DateRequest").'">';
266 print dol_print_date($db->jdate($objSalary->date_demande), 'day');
267 print '</td>';
268
269 print '<td class="right">';
270 print $salary->getLibStatut(3, $alreadypayedS);
271 print '</td>';
272 print '</tr>';
273 $j++;
274 }
275 } else {
276 $titlefortab = $langs->transnoentitiesnoconv("BankTransfer");
277 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoSalaryInvoiceToWithdraw", $titlefortab, $titlefortab).'</span></td></tr>';
278 }
279 print "</table></div><br>";
280 } else {
281 dol_print_error($db);
282 }
283}
284
285
286print '</div><div class="fichetwothirdright">';
287
288/*
289 * Withdraw receipts
290 */
291
292$limit = 5;
293$sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.date_trans, p.statut as status, p.type";
294$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
295$sql .= " WHERE p.type = 'bank-transfer'";
296$sql .= " AND p.entity IN (".getEntity('invoice').")";
297$sql .= " ORDER BY datec DESC";
298$sql .= $db->plimit($limit);
299
300$result = $db->query($sql);
301if ($result) {
302 $num = $db->num_rows($result);
303 $i = 0;
304
305 print"\n<!-- debut table -->\n";
306 print '<div class="div-table-responsive-no-min">';
307 print '<table class="noborder centpercent">';
308 print '<tr class="liste_titre">';
309 print '<th>'.$langs->trans("LatestBankTransferReceipts", $limit);
310 print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/orders_list.php?type=bank-transfer&sortfield=p.datec&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
311 print '</th>';
312 print '<th>'.$langs->trans("Date").'</th>';
313 print '<th class="right">'.$langs->trans("Amount").'</th>';
314 print '<th class="right">'.$langs->trans("Status").'</th>';
315 print '</tr>';
316
317 if ($num > 0) {
318 while ($i < min($num, $limit)) {
319 $obj = $db->fetch_object($result);
320
321 $bprev->id = $obj->rowid;
322 $bprev->ref = $obj->ref;
323 $bprev->type = $obj->type;
324 $bprev->amount = $obj->amount;
325 $bprev->date_trans = $db->jdate($obj->date_trans);
326 $bprev->status = $obj->status;
327
328 print '<tr class="oddeven">';
329 // Ref
330 print '<td class="nowraponall">';
331 print $bprev->getNomUrl(1);
332 print "</td>\n";
333 // Date
334 print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
335 // Amount
336 print '<td class="right nowraponall"><span class="amount">'.price($obj->amount)."</span></td>\n";
337 // Status
338 print '<td class="right"><span class="amount">'.$bprev->getLibStatut(3)."</span></td>\n";
339
340 print "</tr>\n";
341 $i++;
342 }
343 } else {
344 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
345 }
346
347 print "</table></div><br>";
348 $db->free($result);
349} else {
350 dol_print_error($db);
351}
352
353
354print '</div></div>';
355
356// End of page
357llxFooter();
358$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 suppliers invoices.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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, $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.
isModEnabled($module)
Is Dolibarr module enabled.
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.