dolibarr 23.0.3
fiche-rejet.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2025 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
38require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
39
48// Load translation files required by the page
49$langs->loadLangs(array("banks", "categories", "companies", 'withdrawals', 'bills'));
50
51// Security check
52if ($user->socid > 0) {
54}
55
56// Get supervariables
57$id = GETPOSTINT('id');
58$ref = GETPOST('ref', 'alpha');
59
60$type = GETPOST('type', 'aZ09');
61
62// Load variable for pagination
63$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
64$sortfield = GETPOST('sortfield', 'aZ09comma');
65$sortorder = GETPOST('sortorder', 'aZ09comma');
66$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
67if (empty($page) || $page == -1) {
68 $page = 0;
69} // If $page is not defined, or '' or -1
70$offset = $limit * $page;
71$pageprev = $page - 1;
72$pagenext = $page + 1;
73
74$object = new BonPrelevement($db);
75
76// Load object
77include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
78
79// Check if salary or invoice
80$salaryBonPl = $object->checkIfSalaryBonPrelevement();
81
82// Security check
83if ($user->socid > 0) {
85}
86
87$type = $object->type;
88if ($type == 'bank-transfer') {
89 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
90} else {
91 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
92}
93
94
95/*
96 * View
97 */
98
99$form = new Form($db);
100
101$thirdpartystatic = new Societe($db);
102$invoicestatic = new Facture($db);
103$invoicesupplierstatic = new FactureFournisseur($db);
104$rej = new RejetPrelevement($db, $user, $type);
105
106
107llxHeader('', $langs->trans("WithdrawalsReceipts"));
108
109if ($id > 0 || $ref) {
110 if ($object->fetch($id, $ref) >= 0) {
111 $head = prelevement_prepare_head($object);
112 print dol_get_fiche_head($head, 'rejects', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
113
114 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/orders_list.php?restore_lastsearch_values=1'.($object->type != 'bank-transfer' ? '' : '&type=bank-transfer').'">'.$langs->trans("BackToList").'</a>';
115
116 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
117
118 print '<div class="fichecenter">';
119 print '<div class="underbanner clearboth"></div>';
120 print '<table class="border centpercent tableforfield">'."\n";
121
122 //print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
123 print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
124 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
125
126 if (!empty($object->date_trans)) {
127 $muser = new User($db);
128 $muser->fetch($object->user_trans);
129
130 print '<tr><td>'.$langs->trans("TransData").'</td><td>';
131 print dol_print_date($object->date_trans, 'day');
132 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
133 print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
134 print $object->methodes_trans[$object->method_trans];
135 print '</td></tr>';
136 }
137 if (!empty($object->date_credit)) {
138 print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
139 print dol_print_date($object->date_credit, 'day');
140 print '</td></tr>';
141 }
142
143 print '</table>';
144
145 print '<br>';
146
147 print '<div class="underbanner clearboth"></div>';
148 print '<table class="border centpercent tableforfield">';
149
150 // Get bank account for the payment
151 $acc = new Account($db);
152 $fk_bank_account = $object->fk_bank_account;
153 if (empty($fk_bank_account)) {
154 $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
155 }
156 if ($fk_bank_account > 0) {
157 $result = $acc->fetch($fk_bank_account);
158 }
159
160 $labelofbankfield = "BankToReceiveWithdraw";
161 if ($object->type == 'bank-transfer') {
162 $labelofbankfield = 'BankToPayCreditTransfer';
163 }
164
165 print '<tr><td class="titlefieldcreate">';
166 print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
167 print '</td>';
168 print '<td>';
169 if ($acc->id > 0) {
170 print $acc->getNomUrl(1);
171 }
172 print '</td>';
173 print '</tr>';
174
175 $modulepart = 'prelevement';
176 if ($object->type == 'bank-transfer') {
177 $modulepart = 'paymentbybanktransfer';
178 }
179
180 print '<tr><td class="titlefieldcreate">';
181 $labelfororderfield = 'WithdrawalFile';
182 if ($object->type == 'bank-transfer') {
183 $labelfororderfield = 'CreditTransferFile';
184 }
185 print $langs->trans($labelfororderfield).'</td><td>';
186
187 if (isModEnabled('multicompany')) {
188 $labelentity = $conf->entity;
189 $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
190
191 if ($type != 'bank-transfer') {
192 $dir = $conf->prelevement->dir_output;
193 } else {
194 $dir = $conf->paymentbybanktransfer->dir_output;
195 }
196 if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
197 $relativepath = 'receipts/'.$object->ref.'.xml';
198 }
199 } else {
200 $relativepath = 'receipts/'.$object->ref.'.xml';
201 }
202
203 print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
204 print img_picto('', 'download', 'class="paddingleft"');
205 print '</a>';
206 print '</td></tr></table>';
207
208 print '</div>';
209
210 print dol_get_fiche_end();
211 } else {
212 dol_print_error($db);
213 }
214}
215
216
217// List errors
218
219$sql = "SELECT pl.rowid, pl.amount, pl.statut";
220$sql .= " , s.rowid as socid, s.nom as name";
221$sql .= " , pr.motif, pr.afacturer, pr.fk_facture";
222$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
223$sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
224$sql .= " , ".MAIN_DB_PREFIX."societe as s";
225$sql .= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr";
226$sql .= " WHERE p.rowid=".((int) $object->id);
227$sql .= " AND pl.fk_prelevement_bons = p.rowid";
228$sql .= " AND p.entity IN (".getEntity('facture').")";
229$sql .= " AND pl.fk_soc = s.rowid";
230$sql .= " AND pl.statut = 3";
231$sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
232$sql .= " ORDER BY pl.amount DESC";
233
234// Count total nb of records
235$nbtotalofrecords = '';
236if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
237 $result = $db->query($sql);
238 $nbtotalofrecords = $db->num_rows($result);
239 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
240 $page = 0;
241 $offset = 0;
242 }
243}
244
245$sql .= $db->plimit($limit + 1, $offset);
246
247$resql = $db->query($sql);
248if ($resql) {
249 $num = $db->num_rows($resql);
250
251 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
252 print_barre_liste($langs->trans("Rejects"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
253
254 $param = '&id='.((int) $object->id);
255
256 print"\n<!-- debut table -->\n";
257 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
258 print '<table class="noborder centpercent">';
259 print '<tr class="liste_titre">';
260 print_liste_field_titre("Line", $_SERVER["PHP_SELF"], "pl.rowid", '', $param, '', $sortfield, $sortorder);
261 print_liste_field_titre((!$salaryBonPl ? "ThirdParty" : "Employee"), $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
262 print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", '', $param, '', $sortfield, $sortorder, 'right ');
263 print_liste_field_titre("Reason", $_SERVER["PHP_SELF"], "pr.motif", '', $param, '', $sortfield, $sortorder);
264 print_liste_field_titre("ToBill", $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
266 // Invoice to charge the error. No yet implemented.
267 //print $langs->trans("Invoice");
268 print '</tr>';
269
270 $total = 0;
271
272 if ($num > 0) {
273 $i = 0;
274 while ($i < $num) {
275 $obj = $db->fetch_object($resql);
276
277 $thirdpartystatic->id = $obj->socid;
278 $thirdpartystatic->name = $obj->name;
279
280 if ($obj->fk_facture > 0) {
281 $invoicestatic->fetch($obj->fk_facture);
282 }
283
284 print '<tr class="oddeven">';
285 print '<td>';
286 print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'">';
287 print img_picto('', 'statut'.$obj->statut).' ';
288 print substr('000000'.$obj->rowid, -6);
289 print '</a></td>';
290 print '<td>';
291 if ($type != 'bank-transfer') {
292 print $thirdpartystatic->getNomUrl(1, 'customer');
293 } else {
294 print $thirdpartystatic->getNomUrl(1, 'supplier');
295 }
296 print '</td>'."\n";
297
298 print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
299 print '<td>'.dol_escape_htmltag($rej->motifs[$obj->motif]).'</td>';
300
301 print '<td class="center">'.yn($obj->afacturer).'</td>';
302
303 // Invoice used to charge the error
304 print '<td class="center">';
305 if ($obj->fk_facture > 0) {
306 print $invoicestatic->getNomUrl(1);
307 }
308 print '</td>';
309
310 print "</tr>\n";
311
312 $total += $obj->amount;
313
314 $i++;
315 }
316 } else {
317 print '<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
318 }
319
320 if ($num > 0) {
321 print '<tr class="liste_total"><td>&nbsp;</td>';
322 print '<td class="liste_total">'.$langs->trans("Total").'</td>';
323 print '<td class="right"><span class="amount">'.price($total)."</span></td>\n";
324 print '<td colspan="3">&nbsp;</td>';
325 print "</tr>\n";
326 }
327 print "</table>\n";
328 print '</div>';
329
330 $db->free($resql);
331} else {
332 dol_print_error($db);
333}
334
335// End of page
336llxFooter();
337$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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 bank accounts.
Class to manage withdrawal receipts.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage standing orders rejects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_is_file($pathoffile)
Return if path is a file.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
isModEnabled($module)
Is Dolibarr module enabled.
prelevement_prepare_head(BonPrelevement $object)
Prepare array with list of tabs.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.