dolibarr 20.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-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 *
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.'/fourn/class/fournisseur.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';
37require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
38
39// Load translation files required by the page
40$langs->loadLangs(array('banks', 'categories', 'withdrawals'));
41
42// Security check
43$socid = GETPOSTINT('socid');
44if ($user->socid) {
45 $socid = $user->socid;
46}
47$result = restrictedArea($user, 'paymentbybanktransfer', '', '');
48
49$usercancreate = $user->hasRight('paymentbybanktransfer', 'create');
50
51
52/*
53 * Actions
54 */
55
56// None
57
58
59/*
60 * View
61 */
62
63llxHeader('', $langs->trans("SuppliersStandingOrdersArea"));
64
65if (prelevement_check_config('bank-transfer') < 0) {
66 $langs->load("errors");
67 setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByBankTransfer")), null, 'errors');
68}
69
70$thirdpartystatic = new Societe($db);
71$invoicestatic = new FactureFournisseur($db);
72$bprev = new BonPrelevement($db);
73$salary = new Salary($db);
74$user = new User($db);
75
76$newcardbutton = '';
77if ($usercancreate) {
78 $newcardbutton .= dolGetButtonTitle($langs->trans('NewPaymentByBankTransfer'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type=bank-transfer');
79}
80
81print load_fiche_titre($langs->trans("SuppliersStandingOrdersArea"), $newcardbutton);
82
83
84print '<div class="fichecenter"><div class="fichethirdleft">';
85
86
87print '<div class="div-table-responsive-no-min">';
88print '<table class="noborder centpercent">';
89print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
90
91$totaltoshow = 0;
92
93if (isModEnabled('supplier_invoice')) {
94 print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToPayByBankTransfer").'</td>';
95 print '<td class="right">';
96 $amounttoshow = $bprev->SommeAPrelever('bank-transfer');
97 print '<a class="badge badge-info" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0&type=bank-transfer" title="'.price($amounttoshow).'">';
98 print $bprev->nbOfInvoiceToPay('bank-transfer');
99 print '</a>';
100 print '</td></tr>';
101 $totaltoshow += $amounttoshow;
102}
103
104if (isModEnabled('salaries')) {
105 print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToPayByBankTransferForSalaries").'</td>';
106 print '<td class="right">';
107 $amounttoshow = $bprev->SommeAPrelever('bank-transfer', 'salary');
108 print '<a class="badge badge-info" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0&type=bank-transfer&sourcetype=salary" title="'.price($amounttoshow).'">';
109 print $bprev->nbOfInvoiceToPay('bank-transfer', 'salary');
110 print '</a>';
111 print '</td></tr>';
112 $totaltoshow += $amounttoshow;
113}
114
115print '<tr class="oddeven"><td>'.$langs->trans("Total").'</td>';
116print '<td class="right"><span class="amount nowraponall">';
117print price($totaltoshow, 0, '', 1, -1, -1, 'auto');
118print '</span></td></tr></table></div><br>';
119
120
121/*
122 * Invoices waiting for credit transfer
123 */
124if (isModEnabled('supplier_invoice')) {
125 $sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type, f.datef, f.date_lim_reglement,";
126 $sql .= " pfd.date_demande, pfd.amount,";
127 $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";
128 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
129 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
130 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pfd";
131 $sql .= " WHERE s.rowid = f.fk_soc";
132 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
133 $sql .= " AND f.total_ttc > 0";
134 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
135 $sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
136 }
137 $sql .= " AND pfd.traite = 0";
138 $sql .= " AND pfd.ext_payment_id IS NULL";
139 $sql .= " AND pfd.fk_facture_fourn = f.rowid";
140 if ($socid) {
141 $sql .= " AND f.fk_soc = ".((int) $socid);
142 }
143
144 $resql = $db->query($sql);
145
146 if ($resql) {
147 $num = $db->num_rows($resql);
148 $i = 0;
149
150 print '<div class="div-table-responsive-no-min">';
151 print '<table class="noborder centpercent">';
152 print '<tr class="liste_titre">';
153 print '<th colspan="5">'.$langs->trans("SupplierInvoiceWaitingWithdraw").' <span class="opacitymedium">('.$num.')</span></th></tr>';
154 if ($num) {
155 while ($i < $num && $i < 20) {
156 $obj = $db->fetch_object($resql);
157
158 $invoicestatic->id = $obj->rowid;
159 $invoicestatic->ref = $obj->ref;
160 $invoicestatic->status = $obj->fk_statut;
161 $invoicestatic->statut = $obj->fk_statut; // For backward compatibility
162 $invoicestatic->paye = $obj->paye;
163 $invoicestatic->paid = $obj->paye;
164 $invoicestatic->type = $obj->type;
165 $invoicestatic->date = $db->jdate($obj->datef);
166 $invoicestatic->date_echeance = $db->jdate($obj->date_lim_reglement);
167 $invoicestatic->total_ttc = $obj->total_ttc;
168
169 $alreadypayed = $invoicestatic->getSommePaiement();
170
171 $thirdpartystatic->id = $obj->socid;
172 $thirdpartystatic->name = $obj->name;
173 $thirdpartystatic->email = $obj->email;
174 $thirdpartystatic->tva_intra = $obj->tva_intra;
175 $thirdpartystatic->idprof1 = $obj->idprof1;
176 $thirdpartystatic->idprof2 = $obj->idprof2;
177 $thirdpartystatic->idprof3 = $obj->idprof3;
178 $thirdpartystatic->idprof4 = $obj->idprof4;
179 $thirdpartystatic->idprof5 = $obj->idprof5;
180 $thirdpartystatic->idprof6 = $obj->idprof6;
181
182
183 print '<tr class="oddeven"><td class="nowraponall">';
184 print $invoicestatic->getNomUrl(1, 'withdraw');
185 print '</td>';
186
187 print '<td class="tdoverflowmax150">';
188 print $thirdpartystatic->getNomUrl(1, 'supplier');
189 print '</td>';
190
191 print '<td class="right">';
192 print '<span class="amount">'.price($obj->amount).'</span>';
193 print '</td>';
194
195 print '<td class="right">';
196 print dol_print_date($db->jdate($obj->date_demande), 'day');
197 print '</td>';
198
199 print '<td class="right">';
200 print $invoicestatic->getLibStatut(3, $alreadypayed);
201 print '</td>';
202 print '</tr>';
203 $i++;
204 }
205 } else {
206 $titlefortab = $langs->transnoentitiesnoconv("BankTransfer");
207 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoSupplierInvoiceToWithdraw", $titlefortab, $titlefortab).'</span></td></tr>';
208 }
209 print "</table></div><br>";
210 } else {
211 dol_print_error($db);
212 }
213}
214
215if (isModEnabled('salaries')) {
216 $sqlForSalary = "SELECT * FROM ".MAIN_DB_PREFIX."salary as s, ".MAIN_DB_PREFIX."prelevement_demande as pd";
217 $sqlForSalary .= " WHERE s.rowid = pd.fk_salary AND s.paye = 0 AND pd.traite = 0";
218 $sqlForSalary .= " AND s.entity IN (".getEntity('salary').")";
219
220 $resql2 = $db->query($sqlForSalary);
221 if ($resql2) {
222 $numRow = $db->num_rows($resql2);
223 $j = 0 ;
224
225 print '<div class="div-table-responsive-no-min">';
226 print '<table class="noborder rightpercent">';
227 print '<tr class="liste_titre">';
228 print '<th colspan="5">'.$langs->trans("SalaryInvoiceWaitingWithdraw").' <span class="opacitymedium">('.$numRow.')</span></th></tr>';
229
230 if ($numRow) {
231 while ($j < $numRow && $j < 10) {
232 $objSalary = $db->fetch_object($resql2);
233
234 $user->fetch($objSalary->fk_user);
235
236 $salary->fetch($objSalary->fk_salary);
237
238 $alreadypayedS = $salary->getSommePaiement();
239
240 print '<tr class="oddeven"><td class="nowraponall">';
241 print $salary->getNomUrl(1);
242 print '</td>';
243
244 print '<td class="tdoverflowmax150">';
245 print $user->getNomUrl(-1);
246 print '</td>';
247
248 print '<td class="right">';
249 print '<span class="amount">'.price($objSalary->amount).'</span>';
250 print '</td>';
251
252 print '<td class="right" title="'.$langs->trans("DateRequest").'">';
253 print dol_print_date($db->jdate($objSalary->date_demande), 'day');
254 print '</td>';
255
256 print '<td class="right">';
257 print $salary->getLibStatut(3, $alreadypayedS);
258 print '</td>';
259 print '</tr>';
260 $j++;
261 }
262 } else {
263 $titlefortab = $langs->transnoentitiesnoconv("BankTransfer");
264 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoSalaryInvoiceToWithdraw", $titlefortab, $titlefortab).'</span></td></tr>';
265 }
266 print "</table></div><br>";
267 } else {
268 dol_print_error($db);
269 }
270}
271
272
273print '</div><div class="fichetwothirdright">';
274
275/*
276 * Withdraw receipts
277 */
278
279$limit = 5;
280$sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
281$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
282$sql .= " WHERE p.type = 'bank-transfer'";
283$sql .= " AND p.entity IN (".getEntity('invoice').")";
284$sql .= " ORDER BY datec DESC";
285$sql .= $db->plimit($limit);
286
287$result = $db->query($sql);
288if ($result) {
289 $num = $db->num_rows($result);
290 $i = 0;
291
292 print"\n<!-- debut table -->\n";
293 print '<div class="div-table-responsive-no-min">';
294 print '<table class="noborder centpercent">';
295 print '<tr class="liste_titre">';
296 print '<th>'.$langs->trans("LatestBankTransferReceipts", $limit).'</th>';
297 print '<th>'.$langs->trans("Date").'</th>';
298 print '<th class="right">'.$langs->trans("Amount").'</th>';
299 print '<th class="right">'.$langs->trans("Status").'</th>';
300 print '</tr>';
301
302 if ($num > 0) {
303 while ($i < min($num, $limit)) {
304 $obj = $db->fetch_object($result);
305
306 print '<tr class="oddeven">';
307
308 print '<td class="nowraponall">';
309 $bprev->id = $obj->rowid;
310 $bprev->ref = $obj->ref;
311 $bprev->statut = $obj->statut;
312 print $bprev->getNomUrl(1);
313 print "</td>\n";
314 print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
315 print '<td class="right nowraponall"><span class="amount">'.price($obj->amount)."</span></td>\n";
316 print '<td class="right"><span class="amount">'.$bprev->getLibStatut(3)."</span></td>\n";
317
318 print "</tr>\n";
319 $i++;
320 }
321 } else {
322 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
323 }
324
325 print "</table></div><br>";
326 $db->free($result);
327} else {
328 dol_print_error($db);
329}
330
331
332print '</div></div>';
333
334// End of page
335llxFooter();
336$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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).
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.