dolibarr 19.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 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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
38
39// Load translation files required by the page
40$langs->loadLangs(array("banks", "categories", 'withdrawals', 'bills'));
41
42// Security check
43if ($user->socid > 0) {
45}
46
47// Get supervariables
48$id = GETPOST('id', 'int');
49$ref = GETPOST('ref', 'alpha');
50
51$type = GETPOST('type', 'aZ09');
52
53// Load variable for pagination
54$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
55$sortfield = GETPOST('sortfield', 'aZ09comma');
56$sortorder = GETPOST('sortorder', 'aZ09comma');
57$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
58if (empty($page) || $page == -1) {
59 $page = 0;
60} // If $page is not defined, or '' or -1
61$offset = $limit * $page;
62$pageprev = $page - 1;
63$pagenext = $page + 1;
64
65$object = new BonPrelevement($db);
66
67// Load object
68include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
69
70// Security check
71if ($user->socid > 0) {
73}
74
75$type = $object->type;
76if ($type == 'bank-transfer') {
77 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
78} else {
79 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
80}
81
82
83
84/*
85 * View
86 */
87
88$form = new Form($db);
89
90$thirdpartystatic = new Societe($db);
91$invoicestatic = new Facture($db);
92$invoicesupplierstatic = new FactureFournisseur($db);
93$rej = new RejetPrelevement($db, $user, $type);
94
95
96llxHeader('', $langs->trans("WithdrawalsReceipts"));
97
98if ($id > 0 || $ref) {
99 if ($object->fetch($id, $ref) >= 0) {
100 $head = prelevement_prepare_head($object);
101 print dol_get_fiche_head($head, 'rejects', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
102
103 $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>';
104
105 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
106
107 print '<div class="fichecenter">';
108 print '<div class="underbanner clearboth"></div>';
109 print '<table class="border centpercent tableforfield">'."\n";
110
111 //print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
112 print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
113 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
114
115 if (!empty($object->date_trans)) {
116 $muser = new User($db);
117 $muser->fetch($object->user_trans);
118
119 print '<tr><td>'.$langs->trans("TransData").'</td><td>';
120 print dol_print_date($object->date_trans, 'day');
121 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
122 print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
123 print $object->methodes_trans[$object->method_trans];
124 print '</td></tr>';
125 }
126 if (!empty($object->date_credit)) {
127 print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
128 print dol_print_date($object->date_credit, 'day');
129 print '</td></tr>';
130 }
131
132 print '</table>';
133
134 print '<br>';
135
136 print '<div class="underbanner clearboth"></div>';
137 print '<table class="border centpercent tableforfield">';
138
139 // Get bank account for the payment
140 $acc = new Account($db);
141 $fk_bank_account = $object->fk_bank_account;
142 if (empty($fk_bank_account)) {
143 $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
144 }
145 if ($fk_bank_account > 0) {
146 $result = $acc->fetch($fk_bank_account);
147 }
148
149 $labelofbankfield = "BankToReceiveWithdraw";
150 if ($object->type == 'bank-transfer') {
151 $labelofbankfield = 'BankToPayCreditTransfer';
152 }
153
154 print '<tr><td class="titlefieldcreate">';
155 print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
156 print '</td>';
157 print '<td>';
158 if ($acc->id > 0) {
159 print $acc->getNomUrl(1);
160 }
161 print '</td>';
162 print '</tr>';
163
164 $modulepart = 'prelevement';
165 if ($object->type == 'bank-transfer') {
166 $modulepart = 'paymentbybanktransfer';
167 }
168
169 print '<tr><td class="titlefieldcreate">';
170 $labelfororderfield = 'WithdrawalFile';
171 if ($object->type == 'bank-transfer') {
172 $labelfororderfield = 'CreditTransferFile';
173 }
174 print $langs->trans($labelfororderfield).'</td><td>';
175
176 if (isModEnabled('multicompany')) {
177 $labelentity = $conf->entity;
178 $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
179
180 if ($type != 'bank-transfer') {
181 $dir = $conf->prelevement->dir_output;
182 } else {
183 $dir = $conf->paymentbybanktransfer->dir_output;
184 }
185 if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
186 $relativepath = 'receipts/'.$object->ref.'.xml';
187 }
188 } else {
189 $relativepath = 'receipts/'.$object->ref.'.xml';
190 }
191
192 print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
193 print img_picto('', 'download', 'class="paddingleft"');
194 print '</a>';
195 print '</td></tr></table>';
196
197 print '</div>';
198
199 print dol_get_fiche_end();
200 } else {
201 dol_print_error($db);
202 }
203}
204
205
206// List errors
207
208$sql = "SELECT pl.rowid, pl.amount, pl.statut";
209$sql .= " , s.rowid as socid, s.nom as name";
210$sql .= " , pr.motif, pr.afacturer, pr.fk_facture";
211$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
212$sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
213$sql .= " , ".MAIN_DB_PREFIX."societe as s";
214$sql .= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr";
215$sql .= " WHERE p.rowid=".((int) $object->id);
216$sql .= " AND pl.fk_prelevement_bons = p.rowid";
217$sql .= " AND p.entity IN (".getEntity('facture').")";
218$sql .= " AND pl.fk_soc = s.rowid";
219$sql .= " AND pl.statut = 3 ";
220$sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
221/*if ($socid) {
222 $sql .= " AND s.rowid = ".((int) $socid);
223}*/
224$sql .= " ORDER BY pl.amount DESC";
225
226// Count total nb of records
227$nbtotalofrecords = '';
228if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
229 $result = $db->query($sql);
230 $nbtotalofrecords = $db->num_rows($result);
231 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
232 $page = 0;
233 $offset = 0;
234 }
235}
236
237$sql .= $db->plimit($limit + 1, $offset);
238
239$resql = $db->query($sql);
240if ($resql) {
241 $num = $db->num_rows($resql);
242
243 print_barre_liste($langs->trans("Rejects"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
244
245 print"\n<!-- debut table -->\n";
246 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
247 print '<table class="noborder centpercent">';
248 print '<tr class="liste_titre">';
249 print '<td>'.$langs->trans("Line").'</td><td>'.$langs->trans("ThirdParty").'</td><td class="right">'.$langs->trans("Amount").'</td>';
250 print '<td>'.$langs->trans("Reason").'</td><td align="center">'.$langs->trans("ToBill").'</td>';
251 print '<td class="center">';
252 // Invoice to charge the error. No yet implemented.
253 //print $langs->trans("Invoice");
254 print '</td>';
255 print '</tr>';
256
257 $total = 0;
258
259 if ($num > 0) {
260 $i = 0;
261 while ($i < $num) {
262 $obj = $db->fetch_object($resql);
263
264 $thirdpartystatic->id = $obj->socid;
265 $thirdpartystatic->name = $obj->name;
266
267 if ($obj->fk_facture > 0) {
268 $invoicestatic->fetch($obj->fk_facture);
269 }
270
271 print '<tr class="oddeven">';
272 print '<td>';
273 print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'">';
274 print img_picto('', 'statut'.$obj->statut).' ';
275 print substr('000000'.$obj->rowid, -6);
276 print '</a></td>';
277 print '<td>';
278 if ($type != 'bank-transfer') {
279 print $thirdpartystatic->getNomUrl(1, 'customer');
280 } else {
281 print $thirdpartystatic->getNomUrl(1, 'supplier');
282 }
283 print '</td>'."\n";
284
285 print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
286 print '<td>'.dol_escape_htmltag($rej->motifs[$obj->motif]).'</td>';
287
288 print '<td class="center">'.yn($obj->afacturer).'</td>';
289
290 // Invoice used to charge the error
291 print '<td class="center">';
292 if ($obj->fk_facture > 0) {
293 print $invoicestatic->getNomUrl(1);
294 }
295 print '</td>';
296
297 print "</tr>\n";
298
299 $total += $obj->amount;
300
301 $i++;
302 }
303 } else {
304 print '<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
305 }
306
307 if ($num > 0) {
308 print '<tr class="liste_total"><td>&nbsp;</td>';
309 print '<td class="liste_total">'.$langs->trans("Total").'</td>';
310 print '<td class="right"><span class="amount">'.price($total)."</span></td>\n";
311 print '<td colspan="3">&nbsp;</td>';
312 print "</tr>\n";
313 }
314 print "</table>\n";
315 print '</div>';
316
317 $db->free($resql);
318} else {
319 dol_print_error($db);
320}
321
322// End of page
323llxFooter();
324$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 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.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.