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