dolibarr 18.0.7
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 = GETPOST('id', 'int');
42$socid = GETPOST('socid', 'int');
43
44$type = GETPOST('type', 'aZ09');
45
46$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
47$sortorder = GETPOST('sortorder', 'aZ09comma');
48$sortfield = GETPOST('sortfield', 'aZ09comma');
49$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
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 (GETPOST('remonth', 'int')) {
88 $daterej = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
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 $rej->create($user, $id, GETPOST('motif', 'alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer', 'int'));
112
113 header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
114 exit;
115 }
116 } else {
117 $action = "rejet";
118 }
119 } else {
120 header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
121 exit;
122 }
123}
124
125
126/*
127 * View
128 */
129
130$form = new Form($db);
131
132if ($type == 'bank-transfer') {
133 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
134 $invoicestatic = new FactureFournisseur($db);
135} else {
136 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
137 $invoicestatic = new Facture($db);
138}
139
140$title = $langs->trans("WithdrawalsLine");
141if ($type == 'bank-transfer') {
142 $title = $langs->trans("CreditTransferLine");
143}
144
145llxHeader('', $title);
146
147$head = array();
148
149$h = 0;
150$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/line.php?id='.((int) $id).'&type='.urlencode($type);
151$head[$h][1] = $title;
152$hselected = $h;
153$h++;
154
155if ($id) {
156 $lipre = new LignePrelevement($db);
157
158 if ($lipre->fetch($id) >= 0) {
159 $bon = new BonPrelevement($db);
160 $bon->fetch($lipre->bon_rowid);
161
162 print dol_get_fiche_head($head, $hselected, $title, -1, 'payment');
163
164 print '<table class="border centpercent tableforfield">';
165
166 print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
167 print $id.'</td></tr>';
168
169 if ($type == 'bank-transfer') {
170 print '<tr><td class="titlefield">'.$langs->trans("BankTransfers").'</td><td>';
171 } else {
172 print '<tr><td class="titlefield">'.$langs->trans("WithdrawalsReceipts").'</td><td>';
173 }
174
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 if ($action == 'rejet' && $user->rights->prelevement->bons->credit) {
211 $soc = new Societe($db);
212 $soc->fetch($lipre->socid);
213
214 $rej = new RejetPrelevement($db, $user, $type);
215
216 print '<form name="confirm_rejet" method="post" action="line.php?id='.$id.'">';
217 print '<input type="hidden" name="token" value="'.newToken().'">';
218 print '<input type="hidden" name="action" value="confirm_rejet">';
219 print '<input type="hidden" name="type" value="'.$type.'">';
220 print '<table class="noborder centpercent">';
221
222 print '<tr class="liste_titre">';
223 print '<td colspan="3">'.$langs->trans("WithdrawalRefused").'</td></tr>';
224
225 //Select yes/no
226 print '<tr><td class="valid">'.$langs->trans("WithdrawalRefusedConfirm").' '.$soc->name.' ?</td>';
227 print '<td colspan="2" class="valid">';
228 print $form->selectyesno("confirm", 1, 0);
229 print '</td></tr>';
230
231 //Date
232 print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedData").'</td>';
233 print '<td colspan="2" class="valid">';
234 print $form->selectDate('', '', '', '', '', "confirm_rejet");
235 print '</td></tr>';
236
237 //Reason
238 print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedReason").'</td>';
239 print '<td class="valid">';
240 print $form->selectarray("motif", $rej->motifs, GETPOSTISSET('motif') ? GETPOST('motif', 'int') : '');
241 print '</td></tr>';
242
243 //Facturer
244 print '<tr><td class="valid">'.$langs->trans("RefusedInvoicing").'</td>';
245 print '<td class="valid" colspan="2">';
246 print $form->selectarray("facturer", $rej->facturer, GETPOSTISSET('facturer') ? GETPOST('facturer', 'int') : '');
247 print '</td></tr>';
248 print '</table><br>';
249
250 //Confirm Button
251 print '<div class="center"><input type="submit" class="button button-save" value='.$langs->trans("Confirm").'></div>';
252 print '</form>';
253 }
254
255 /*
256 * Action bar
257 */
258 print '<div class="tabsAction">';
259
260 if ($action == '') {
261 if ($bon->statut == BonPrelevement::STATUS_CREDITED) {
262 if ($lipre->statut == 2) {
263 if ($user->rights->prelevement->bons->credit) {
264 print '<a class="butActionDelete" href="line.php?action=rejet&type='.$type.'&id='.$lipre->id.'">'.$langs->trans("StandingOrderReject").'</a>';
265 } else {
266 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
267 }
268 }
269 } else {
270 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
271 }
272 }
273
274 print '</div>';
275
276 /*
277 * List of invoices
278 */
279 $sql = "SELECT pf.rowid";
280 $sql .= " ,f.rowid as facid, f.ref as ref, f.total_ttc, f.paye, f.fk_statut";
281 $sql .= " , s.rowid as socid, s.nom as name";
282 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
283 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
284 $sql .= " , ".MAIN_DB_PREFIX."prelevement as pf";
285 if ($type == 'bank-transfer') {
286 $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
287 } else {
288 $sql .= " , ".MAIN_DB_PREFIX."facture as f";
289 }
290 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
291 $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
292 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
293 $sql .= " AND f.fk_soc = s.rowid";
294 if ($type == 'bank-transfer') {
295 $sql .= " AND pf.fk_facture_fourn = f.rowid";
296 } else {
297 $sql .= " AND pf.fk_facture = f.rowid";
298 }
299 $sql .= " AND f.entity IN (".getEntity('invoice').")";
300 $sql .= " AND pl.rowid = ".((int) $id);
301 if ($socid) {
302 $sql .= " AND s.rowid = ".((int) $socid);
303 }
304 $sql .= $db->order($sortfield, $sortorder);
305 $sql .= $db->plimit($conf->liste_limit + 1, $offset);
306
307 $result = $db->query($sql);
308
309 if ($result) {
310 $num = $db->num_rows($result);
311 $i = 0;
312
313 $urladd = "&id=".urlencode($id);
314
315 print_barre_liste($langs->trans("Bills"), $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, '');
316
317 print"\n<!-- debut table -->\n";
318 print '<table class="noborder" width="100%" cellpadding="4">';
319 print '<tr class="liste_titre">';
320 print '<td>'.$langs->trans("Invoice").'</td>';
321 print '<td>'.$langs->trans("ThirdParty").'</td>';
322 print '<td class="right">'.$langs->trans("Amount").'</td><td class="right">'.$langs->trans("Status").'</td>';
323 print '</tr>';
324
325 $total = 0;
326
327 while ($i < min($num, $conf->liste_limit)) {
328 $obj = $db->fetch_object($result);
329
330 print '<tr class="oddeven"><td>';
331
332 print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">';
333 print img_object($langs->trans("ShowBill"), "bill");
334 print '</a>&nbsp;';
335
336 if ($type == 'bank-transfer') {
337 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
338 } else {
339 print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
340 }
341
342 if ($type == 'bank-transfer') {
343 print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">';
344 } else {
345 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">';
346 }
347 print img_object($langs->trans("ShowCompany"), "company").' '.$obj->name."</a></td>\n";
348
349 print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
350
351 print '<td class="right">';
352 $invoicestatic->fetch($obj->facid);
353 print $invoicestatic->getLibStatut(5);
354 print "</td>\n";
355
356 print "</tr>\n";
357
358 $i++;
359 }
360
361 print "</table>";
362
363 $db->free($result);
364 } else {
365 dol_print_error($db);
366 }
367}
368
369// End of page
370llxFooter();
371$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 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 informations (by default a local PHP server timestamp) Re...
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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).
dol_now($mode='auto')
Return date for now.
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.
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.
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.