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