dolibarr 21.0.3
line.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
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
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36
45// Load translation files required by the page
46$langs->loadlangs(array('banks', 'categories', 'bills', 'companies', 'withdrawals'));
47
48// Get supervariables
49$action = GETPOST('action', 'aZ09');
50$id = GETPOSTINT('id');
51$socid = GETPOSTINT('socid');
52
53$type = GETPOST('type', 'aZ09');
54
55$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
56$sortorder = GETPOST('sortorder', 'aZ09comma');
57$sortfield = GETPOST('sortfield', 'aZ09comma');
58$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
59if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
60 // If $page is not defined, or '' or -1 or if we click on clear filters
61 $page = 0;
62}
63$offset = $limit * $page;
64$pageprev = $page - 1;
65$pagenext = $page + 1;
66
67if ($sortorder == "") {
68 $sortorder = "DESC";
69}
70if ($sortfield == "") {
71 $sortfield = "pl.fk_soc";
72}
73
74
75if ($type == 'bank-transfer') {
76 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
77} else {
78 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
79}
80
81if ($type == 'bank-transfer') {
82 $permissiontoadd = $user->hasRight('paymentbybanktransfer', 'create');
83} else {
84 $permissiontoadd = $user->hasRight('prelevement', 'bons', 'creer');
85}
86
87$error = 0;
88
89
90/*
91 * Actions
92 */
93
94if ($action == 'confirm_rejet' && $permissiontoadd) {
95 if (GETPOST("confirm") == 'yes') {
96 $daterej = null;
97 if (GETPOSTINT('remonth')) {
98 $daterej = dol_mktime(0, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
99 }
100
101 if (empty($daterej)) {
102 $error++;
103 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
104 } elseif ($daterej > dol_now()) {
105 $error++;
106 $langs->load("error");
107 setEventMessages($langs->transnoentities("ErrorDateMustBeBeforeToday"), null, 'errors');
108 }
109
110 if (GETPOST('motif', 'alpha') == 0) {
111 $error++;
112 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefusedReason")), null, 'errors');
113 }
114
115 if (!$error) {
116 $lipre = new LignePrelevement($db);
117
118 if ($lipre->fetch($id) == 0) {
119 $rej = new RejetPrelevement($db, $user, $type);
120
121 $result = $rej->create($user, $id, GETPOSTINT('motif'), $daterej, $lipre->bon_rowid, GETPOSTINT('facturer'));
122
123 if ($result > 0) {
124 header("Location: line.php?id=".urlencode((string) ($id)).'&type='.urlencode((string) ($type)));
125 exit;
126 }
127 }
128 } else {
129 $action = "rejet";
130 }
131 } else {
132 header("Location: line.php?id=".urlencode((string) ($id)).'&type='.urlencode((string) ($type)));
133 exit;
134 }
135}
136
137
138/*
139 * View
140 */
141
142$form = new Form($db);
143
144if ($type == 'bank-transfer') {
145 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
146 $invoicestatic = new FactureFournisseur($db);
147} else {
148 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
149 $invoicestatic = new Facture($db);
150}
151
152$title = $langs->trans("WithdrawalsLine");
153if ($type == 'bank-transfer') {
154 $title = $langs->trans("CreditTransferLine");
155}
156
157llxHeader('', $title);
158
159$head = array();
160
161$h = 0;
162$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/line.php?id='.((int) $id).'&type='.urlencode($type);
163$head[$h][1] = $title;
164$hselected = (string) $h;
165$h++;
166
167if ($id) {
168 $lipre = new LignePrelevement($db);
169 $bon = null;
170
171 if ($lipre->fetch($id) >= 0) {
172 $bon = new BonPrelevement($db);
173 $bon->fetch($lipre->bon_rowid);
174
175 print dol_get_fiche_head($head, $hselected, $title, -1, 'payment');
176
177 print '<table class="border centpercent tableforfield">';
178
179 print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
180 print $id.'</td></tr>';
181
182 if ($type == 'bank-transfer') {
183 print '<tr><td class="titlefield">'.$langs->trans("BankTransfers").'</td><td>';
184 } else {
185 print '<tr><td class="titlefield">'.$langs->trans("WithdrawalsReceipts").'</td><td>';
186 }
187
188 print $bon->getNomUrl(1).'</td></tr>';
189
190 print '<tr><td>'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec, 'day').'</td></tr>';
191
192 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($lipre->amount).'</span></td></tr>';
193
194 print '<tr><td>'.$langs->trans("Status").'</td><td>'.$lipre->LibStatut($lipre->statut, 1).'</td></tr>';
195
196 if ($lipre->statut == 3) {
197 $rej = new RejetPrelevement($db, $user, $type);
198 $resf = $rej->fetch($lipre->id);
199 if ($resf == 0) {
200 print '<tr><td>'.$langs->trans("RefusedReason").'</td><td>'.$rej->motif.'</td></tr>';
201
202 print '<tr><td>'.$langs->trans("RefusedData").'</td><td>';
203 if ($rej->date_rejet == 0) {
204 /* Historique pour certaines install */
205 print $langs->trans("Unknown");
206 } else {
207 print dol_print_date($rej->date_rejet, 'day');
208 }
209 print '</td></tr>';
210
211 print '<tr><td>'.$langs->trans("RefusedInvoicing").'</td><td>'.$rej->invoicing.'</td></tr>';
212 } else {
213 print '<tr><td>'.$resf.'</td></tr>';
214 }
215 }
216
217 print '</table>';
218 print dol_get_fiche_end();
219 } else {
220 dol_print_error($db);
221 }
222
223 // Form to record a reject
224 if ($action == 'rejet' && $user->hasRight('prelevement', 'bons', 'credit')) {
225 $soc = new Societe($db);
226 $soc->fetch($lipre->socid);
227
228 $rej = new RejetPrelevement($db, $user, $type);
229
230 print '<form name="confirm_rejet" method="post" action="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$id.'">';
231 print '<input type="hidden" name="token" value="'.newToken().'">';
232 print '<input type="hidden" name="action" value="confirm_rejet">';
233 print '<input type="hidden" name="type" value="'.$type.'">';
234
235 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
236 print '<table class="noborder centpercent">';
237
238 print '<tr class="liste_titre">';
239 print '<td>'.$langs->trans("WithdrawalRefused").'</td>';
240 print '<td></td>';
241 print '</tr>';
242
243 //Select yes/no
244 print '<tr><td class="valid">'.$langs->trans("WithdrawalRefusedConfirm").' '.$soc->name.' ?</td>';
245 print '<td class="valid">';
246 print $form->selectyesno("confirm", 1, 0);
247 print '</td></tr>';
248
249 //Date
250 print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedData").'</td>';
251 print '<td class="valid">';
252 print $form->selectDate('', '', 0, 0, 0, "confirm_rejet");
253 print '</td></tr>';
254
255 //Reason
256 print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedReason").'</td>';
257 print '<td class="valid">';
258 print $form->selectarray("motif", $rej->motifs, GETPOSTISSET('motif') ? GETPOSTINT('motif') : '');
259 print '</td></tr>';
260
261 //Facturer
262 print '<tr><td class="fieldrequired valid">';
263 print $form->textwithpicto($langs->trans("RefusedInvoicing"), $langs->trans("DirectDebitRefusedInvoicingDesc"));
264 print '</td>';
265 print '<td class="valid">';
266 print $form->selectarray("facturer", $rej->labelsofinvoicing, GETPOSTISSET('facturer') ? GETPOSTINT('facturer') : '', 0);
267 print '</td></tr>';
268
269 print '</table>';
270 print '</div>';
271
272 //Confirm Button
273 print '<div class="center"><input type="submit" class="button button-save" value='.$langs->trans("Confirm").'></div>';
274 print '</form>';
275 }
276
277 /*
278 * Action bar
279 */
280 print '<div class="tabsAction">';
281
282 if ($action == '') {
283 if (is_object($bon) && $bon->statut == BonPrelevement::STATUS_CREDITED) {
284 if ($lipre->statut == 2) {
285 if ($user->hasRight('prelevement', 'bons', 'credit')) {
286 print '<a class="butActionDelete" href="line.php?action=rejet&type='.$type.'&id='.$lipre->id.'">'.$langs->trans("StandingOrderReject").'</a>';
287 } else {
288 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
289 }
290 }
291 } else {
292 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
293 }
294 }
295
296 print '</div>';
297
298 /*
299 * List of invoices
300 */
301 $sql = "SELECT pf.rowid";
302 $sql .= " ,f.rowid as facid, f.ref as ref, f.total_ttc, f.paye, f.fk_statut";
303 $sql .= " , s.rowid as socid, s.nom as name";
304
305 $sqlfields = $sql; // $sql fields to remove for count total
306
307 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
308 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
309 $sql .= " , ".MAIN_DB_PREFIX."prelevement as pf";
310 if ($type == 'bank-transfer') {
311 $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
312 } else {
313 $sql .= " , ".MAIN_DB_PREFIX."facture as f";
314 }
315 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
316 $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
317 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
318 $sql .= " AND f.fk_soc = s.rowid";
319 if ($type == 'bank-transfer') {
320 $sql .= " AND pf.fk_facture_fourn = f.rowid";
321 } else {
322 $sql .= " AND pf.fk_facture = f.rowid";
323 }
324 $sql .= " AND f.entity IN (".getEntity('invoice').")";
325 $sql .= " AND pl.rowid = ".((int) $id);
326 if ($socid) {
327 $sql .= " AND s.rowid = ".((int) $socid);
328 }
329
330 // Count total nb of records
331 $nbtotalofrecords = '';
332 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
333 /* The fast and low memory method to get and count full list converts the sql into a sql count */
334 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
335 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
336 $resql = $db->query($sqlforcount);
337 if ($resql) {
338 $objforcount = $db->fetch_object($resql);
339 $nbtotalofrecords = $objforcount->nbtotalofrecords;
340 } else {
341 dol_print_error($db);
342 }
343
344 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
345 $page = 0;
346 $offset = 0;
347 }
348 $db->free($resql);
349 }
350
351 $result = $db->query($sql);
352
353 $sql .= $db->order($sortfield, $sortorder);
354 $sql .= $db->plimit($conf->liste_limit + 1, $offset);
355
356 $result = $db->query($sql);
357
358 if ($result) {
359 $num = $db->num_rows($result);
360 $i = 0;
361
362 $urladd = "&id=".urlencode((string) ($id));
363 $title = $langs->trans("Bills");
364 if ($type == 'bank-transfer') {
365 $title = $langs->trans("SupplierInvoices");
366 }
367
368 print_barre_liste($title, $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
369
370 print"\n<!-- debut table -->\n";
371 print '<table class="noborder" width="100%" cellpadding="4">';
372 print '<tr class="liste_titre">';
373 print '<td>'.$langs->trans("Invoice").'</td>';
374 print '<td>'.$langs->trans("ThirdParty").'</td>';
375 print '<td class="right">'.$langs->trans("Amount").'</td><td class="right">'.$langs->trans("Status").'</td>';
376 print '</tr>';
377
378 $total = 0;
379
380 while ($i < min($num, $conf->liste_limit)) {
381 $obj = $db->fetch_object($result);
382
383 print '<tr class="oddeven"><td>';
384
385 print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">';
386 print img_object($langs->trans("ShowBill"), "bill");
387 print '</a>&nbsp;';
388
389 if ($type == 'bank-transfer') {
390 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
391 } else {
392 print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
393 }
394
395 if ($type == 'bank-transfer') {
396 print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">';
397 } else {
398 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">';
399 }
400 print img_object($langs->trans("ShowCompany"), "company").' '.$obj->name."</a></td>\n";
401
402 print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
403
404 print '<td class="right">';
405 $invoicestatic->fetch($obj->facid);
406 print $invoicestatic->getLibStatut(5);
407 print "</td>\n";
408
409 print "</tr>\n";
410
411 $i++;
412 }
413
414 print "</table>";
415
416 $db->free($result);
417 } else {
418 dol_print_error($db);
419 }
420}
421
422// End of page
423llxFooter();
424$db->close();
$id
Definition account.php:48
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
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 withdrawals.
Class to manage standing orders rejects.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.