dolibarr  19.0.0-dev
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
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array("banks", "categories", 'withdrawals', 'bills'));
38 
39 // Security check
40 if ($user->socid > 0) {
42 }
43 
44 // Get supervariables
45 $id = GETPOST('id', 'int');
46 $ref = GETPOST('ref', 'alpha');
47 
48 $type = GETPOST('type', 'aZ09');
49 
50 // Load variable for pagination
51 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
52 $sortfield = GETPOST('sortfield', 'aZ09comma');
53 $sortorder = GETPOST('sortorder', 'aZ09comma');
54 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
55 if (empty($page) || $page == -1) {
56  $page = 0;
57 } // If $page is not defined, or '' or -1
58 $offset = $limit * $page;
59 $pageprev = $page - 1;
60 $pagenext = $page + 1;
61 
62 $object = new BonPrelevement($db);
63 
64 // Load object
65 include 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
66 
67 // Security check
68 if ($user->socid > 0) {
70 }
71 
72 $type = $object->type;
73 if ($type == 'bank-transfer') {
74  $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
75 } else {
76  $result = restrictedArea($user, 'prelevement', '', '', 'bons');
77 }
78 
79 
80 
81 /*
82  * View
83  */
84 
85 llxHeader('', $langs->trans("WithdrawalsReceipts"));
86 
87 if ($id > 0 || $ref) {
88  if ($object->fetch($id, $ref) >= 0) {
89  $head = prelevement_prepare_head($object);
90  print dol_get_fiche_head($head, 'rejects', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
91 
92  $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>';
93 
94  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
95 
96  print '<div class="fichecenter">';
97  print '<div class="underbanner clearboth"></div>';
98  print '<table class="border centpercent tableforfield">'."\n";
99 
100  //print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
101  print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
102  print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
103 
104  if (!empty($object->date_trans)) {
105  $muser = new User($db);
106  $muser->fetch($object->user_trans);
107 
108  print '<tr><td>'.$langs->trans("TransData").'</td><td>';
109  print dol_print_date($object->date_trans, 'day');
110  print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td></tr>';
111  print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
112  print $object->methodes_trans[$object->method_trans];
113  print '</td></tr>';
114  }
115  if (!empty($object->date_credit)) {
116  print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
117  print dol_print_date($object->date_credit, 'day');
118  print '</td></tr>';
119  }
120 
121  print '</table>';
122 
123  print '<br>';
124 
125  print '<div class="underbanner clearboth"></div>';
126  print '<table class="border centpercent tableforfield">';
127 
128  // Get bank account for the payment
129  $acc = new Account($db);
130  $fk_bank_account = $object->fk_bank_account;
131  if (empty($fk_bank_account)) {
132  $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
133  }
134  if ($fk_bank_account > 0) {
135  $result = $acc->fetch($fk_bank_account);
136  }
137 
138  $labelofbankfield = "BankToReceiveWithdraw";
139  if ($object->type == 'bank-transfer') {
140  $labelofbankfield = 'BankToPayCreditTransfer';
141  }
142 
143  print '<tr><td class="titlefieldcreate">';
144  print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
145  print '</td>';
146  print '<td>';
147  if ($acc->id > 0) {
148  print $acc->getNomUrl(1);
149  }
150  print '</td>';
151  print '</tr>';
152 
153  $modulepart = 'prelevement';
154  if ($object->type == 'bank-transfer') {
155  $modulepart = 'paymentbybanktransfer';
156  }
157 
158  print '<tr><td class="titlefieldcreate">';
159  $labelfororderfield = 'WithdrawalFile';
160  if ($object->type == 'bank-transfer') {
161  $labelfororderfield = 'CreditTransferFile';
162  }
163  print $langs->trans($labelfororderfield).'</td><td>';
164 
165  if (isModEnabled('multicompany')) {
166  $labelentity = $conf->entity;
167  $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
168 
169  if ($type != 'bank-transfer') {
170  $dir = $conf->prelevement->dir_output;
171  } else {
172  $dir = $conf->paymentbybanktransfer->dir_output;
173  }
174  if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
175  $relativepath = 'receipts/'.$object->ref.'.xml';
176  }
177  } else {
178  $relativepath = 'receipts/'.$object->ref.'.xml';
179  }
180 
181  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
182  print img_picto('', 'download', 'class="paddingleft"');
183  print '</a>';
184  print '</td></tr></table>';
185 
186  print '</div>';
187 
188  print dol_get_fiche_end();
189  } else {
190  dol_print_error($db);
191  }
192 }
193 
194 
195 $rej = new RejetPrelevement($db, $user, $type);
196 
197 /*
198  * List errors
199  */
200 $sql = "SELECT pl.rowid, pl.amount, pl.statut";
201 $sql .= " , s.rowid as socid, s.nom as name";
202 $sql .= " , pr.motif, pr.afacturer, pr.fk_facture";
203 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
204 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
205 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
206 $sql .= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr";
207 $sql .= " WHERE p.rowid=".((int) $object->id);
208 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
209 $sql .= " AND p.entity = ".$conf->entity;
210 $sql .= " AND pl.fk_soc = s.rowid";
211 $sql .= " AND pl.statut = 3 ";
212 $sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
213 /*if ($socid) {
214  $sql .= " AND s.rowid = ".((int) $socid);
215 }*/
216 $sql .= " ORDER BY pl.amount DESC";
217 
218 // Count total nb of records
219 $nbtotalofrecords = '';
220 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
221  $result = $db->query($sql);
222  $nbtotalofrecords = $db->num_rows($result);
223  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
224  $page = 0;
225  $offset = 0;
226  }
227 }
228 
229 $sql .= $db->plimit($limit + 1, $offset);
230 
231 $resql = $db->query($sql);
232 if ($resql) {
233  $num = $db->num_rows($resql);
234 
235  print_barre_liste($langs->trans("Rejects"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
236 
237  print"\n<!-- debut table -->\n";
238  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
239  print '<table class="noborder centpercent">';
240  print '<tr class="liste_titre">';
241  print '<td>'.$langs->trans("Line").'</td><td>'.$langs->trans("ThirdParty").'</td><td class="right">'.$langs->trans("Amount").'</td>';
242  print '<td>'.$langs->trans("Reason").'</td><td align="center">'.$langs->trans("ToBill").'</td><td class="center">'.$langs->trans("Invoice").'</td></tr>';
243 
244  $total = 0;
245 
246  if ($num > 0) {
247  $i = 0;
248  while ($i < $num) {
249  $obj = $db->fetch_object($resql);
250 
251  print '<tr class="oddeven"><td>';
252 
253  print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'">';
254  print img_picto('', 'statut'.$obj->statut).' ';
255  print substr('000000'.$obj->rowid, -6);
256  print '</a></td>';
257  print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name."</a></td>\n";
258 
259  print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
260  print '<td>'.$rej->motifs[$obj->motif].'</td>';
261 
262  print '<td class="center">'.yn($obj->afacturer).'</td>';
263  print '<td class="center">'.$obj->fk_facture.'</td>';
264  print "</tr>\n";
265 
266  $total += $obj->amount;
267 
268  $i++;
269  }
270  } else {
271  print '<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
272  }
273 
274  if ($num > 0) {
275  print '<tr class="liste_total"><td>&nbsp;</td>';
276  print '<td class="liste_total">'.$langs->trans("Total").'</td>';
277  print '<td class="right"><span class="amount">'.price($total)."</span></td>\n";
278  print '<td colspan="3">&nbsp;</td>';
279  print "</tr>\n";
280  }
281  print "</table>\n";
282  print '</div>';
283 
284  $db->free($resql);
285 } else {
286  dol_print_error($db);
287 }
288 
289 // End of page
290 llxFooter();
291 $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:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage bank accounts.
Class to manage withdrawal receipts.
Class to manage standing orders rejects.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:483
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 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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.