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