dolibarr  16.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 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadlangs(array('banks', 'categories', 'bills', 'withdrawals'));
37 
38 // Get supervariables
39 $action = GETPOST('action', 'aZ09');
40 $id = GETPOST('id', 'int');
41 $socid = GETPOST('socid', 'int');
42 
43 $type = GETPOST('type', 'aZ09');
44 
45 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
46 $sortorder = GETPOST('sortorder', 'aZ09comma');
47 $sortfield = GETPOST('sortfield', 'aZ09comma');
48 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
49 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
50  // If $page is not defined, or '' or -1 or if we click on clear filters
51  $page = 0;
52 }
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
56 
57 if ($sortorder == "") {
58  $sortorder = "DESC";
59 }
60 if ($sortfield == "") {
61  $sortfield = "pl.fk_soc";
62 }
63 
64 
65 if ($type == 'bank-transfer') {
66  $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
67 } else {
68  $result = restrictedArea($user, 'prelevement', '', '', 'bons');
69 }
70 
71 
72 /*
73  * Actions
74  */
75 
76 if ($action == 'confirm_rejet') {
77  if (GETPOST("confirm") == 'yes') {
78  if (GETPOST('remonth', 'int')) {
79  $daterej = mktime(2, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
80  }
81 
82  if (empty($daterej)) {
83  $error++;
84  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
85  } elseif ($daterej > dol_now()) {
86  $error++;
87  $langs->load("error");
88  setEventMessages($langs->transnoentities("ErrorDateMustBeBeforeToday"), null, 'errors');
89  }
90 
91  if (GETPOST('motif', 'alpha') == 0) {
92  $error++;
93  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefusedReason")), null, 'errors');
94  }
95 
96  if (!$error) {
97  $lipre = new LignePrelevement($db);
98 
99  if ($lipre->fetch($id) == 0) {
100  $rej = new RejetPrelevement($db, $user, $type);
101 
102  $rej->create($user, $id, GETPOST('motif', 'alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer', 'int'));
103 
104  header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
105  exit;
106  }
107  } else {
108  $action = "rejet";
109  }
110  } else {
111  header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
112  exit;
113  }
114 }
115 
116 
117 /*
118  * View
119  */
120 
121 if ($type == 'bank-transfer') {
122  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
123  $invoicestatic = new FactureFournisseur($db);
124 } else {
125  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
126  $invoicestatic = new Facture($db);
127 }
128 
129 $title = $langs->trans("WithdrawalsLine");
130 if ($type == 'bank-transfer') {
131  $title = $langs->trans("CreditTransferLine");
132 }
133 
134 llxHeader('', $title);
135 
136 $head = array();
137 
138 $h = 0;
139 $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$id.'&type='.$type;
140 $head[$h][1] = $title;
141 $hselected = $h;
142 $h++;
143 
144 if ($id) {
145  $lipre = new LignePrelevement($db);
146 
147  if ($lipre->fetch($id) >= 0) {
148  $bon = new BonPrelevement($db);
149  $bon->fetch($lipre->bon_rowid);
150 
151  print dol_get_fiche_head($head, $hselected, $title);
152 
153  print '<table class="border centpercent tableforfield">';
154 
155  print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
156  print $id.'</td></tr>';
157 
158  print '<tr><td class="titlefield">'.$langs->trans("WithdrawalsReceipts").'</td><td>';
159  print $bon->getNomUrl(1).'</td></tr>';
160 
161  print '<tr><td>'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec, 'day').'</td></tr>';
162 
163  print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($lipre->amount).'</span></td></tr>';
164 
165  print '<tr><td>'.$langs->trans("Status").'</td><td>'.$lipre->LibStatut($lipre->statut, 1).'</td></tr>';
166 
167  if ($lipre->statut == 3) {
168  $rej = new RejetPrelevement($db, $user, $type);
169  $resf = $rej->fetch($lipre->id);
170  if ($resf == 0) {
171  print '<tr><td>'.$langs->trans("RefusedReason").'</td><td>'.$rej->motif.'</td></tr>';
172 
173  print '<tr><td>'.$langs->trans("RefusedData").'</td><td>';
174  if ($rej->date_rejet == 0) {
175  /* Historique pour certaines install */
176  print $langs->trans("Unknown");
177  } else {
178  print dol_print_date($rej->date_rejet, 'day');
179  }
180  print '</td></tr>';
181 
182  print '<tr><td>'.$langs->trans("RefusedInvoicing").'</td><td>'.$rej->invoicing.'</td></tr>';
183  } else {
184  print '<tr><td>'.$resf.'</td></tr>';
185  }
186  }
187 
188  print '</table>';
189  print dol_get_fiche_end();
190  } else {
191  dol_print_error($db);
192  }
193 
194  if ($action == 'rejet' && $user->rights->prelevement->bons->credit) {
195  $form = new Form($db);
196 
197  $soc = new Societe($db);
198  $soc->fetch($lipre->socid);
199 
200  $rej = new RejetPrelevement($db, $user, $type);
201 
202  print '<form name="confirm_rejet" method="post" action="line.php?id='.$id.'">';
203  print '<input type="hidden" name="token" value="'.newToken().'">';
204  print '<input type="hidden" name="action" value="confirm_rejet">';
205  print '<input type="hidden" name="type" value="'.$type.'">';
206  print '<table class="noborder centpercent">';
207 
208  print '<tr class="liste_titre">';
209  print '<td colspan="3">'.$langs->trans("WithdrawalRefused").'</td></tr>';
210 
211  //Select yes/no
212  print '<tr><td class="valid">'.$langs->trans("WithdrawalRefusedConfirm").' '.$soc->name.' ?</td>';
213  print '<td colspan="2" class="valid">';
214  print $form->selectyesno("confirm", 1, 0);
215  print '</td></tr>';
216 
217  //Date
218  print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedData").'</td>';
219  print '<td colspan="2" class="valid">';
220  print $form->selectDate('', '', '', '', '', "confirm_rejet");
221  print '</td></tr>';
222 
223  //Reason
224  print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedReason").'</td>';
225  print '<td class="valid">';
226  print $form->selectarray("motif", $rej->motifs, GETPOSTISSET('motif') ? GETPOST('motif', 'int') : '');
227  print '</td></tr>';
228 
229  //Facturer
230  print '<tr><td class="valid">'.$langs->trans("RefusedInvoicing").'</td>';
231  print '<td class="valid" colspan="2">';
232  print $form->selectarray("facturer", $rej->facturer, GETPOSTISSET('facturer') ? GETPOST('facturer', 'int') : '');
233  print '</td></tr>';
234  print '</table><br>';
235 
236  //Confirm Button
237  print '<div class="center"><input type="submit" class="button button-save" value='.$langs->trans("Confirm").'></div>';
238  print '</form>';
239  }
240 
241  /*
242  * Action bar
243  */
244  print '<div class="tabsAction">';
245 
246  if ($action == '') {
247  if ($bon->statut == BonPrelevement::STATUS_CREDITED) {
248  if ($lipre->statut == 2) {
249  if ($user->rights->prelevement->bons->credit) {
250  print '<a class="butActionDelete" href="line.php?action=rejet&type='.$type.'&id='.$lipre->id.'">'.$langs->trans("StandingOrderReject").'</a>';
251  } else {
252  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
253  }
254  }
255  } else {
256  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
257  }
258  }
259 
260  print '</div>';
261 
262  /*
263  * List of invoices
264  */
265  $sql = "SELECT pf.rowid";
266  $sql .= " ,f.rowid as facid, f.ref as ref, f.total_ttc, f.paye, f.fk_statut";
267  $sql .= " , s.rowid as socid, s.nom as name";
268  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
269  $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
270  $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
271  if ($type == 'bank-transfer') {
272  $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
273  } else {
274  $sql .= " , ".MAIN_DB_PREFIX."facture as f";
275  }
276  $sql .= " , ".MAIN_DB_PREFIX."societe as s";
277  $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
278  $sql .= " AND pl.fk_prelevement_bons = p.rowid";
279  $sql .= " AND f.fk_soc = s.rowid";
280  if ($type == 'bank-transfer') {
281  $sql .= " AND pf.fk_facture_fourn = f.rowid";
282  } else {
283  $sql .= " AND pf.fk_facture = f.rowid";
284  }
285  $sql .= " AND f.entity IN (".getEntity('invoice').")";
286  $sql .= " AND pl.rowid = ".((int) $id);
287  if ($socid) {
288  $sql .= " AND s.rowid = ".((int) $socid);
289  }
290  $sql .= $db->order($sortfield, $sortorder);
291  $sql .= $db->plimit($conf->liste_limit + 1, $offset);
292 
293  $result = $db->query($sql);
294 
295  if ($result) {
296  $num = $db->num_rows($result);
297  $i = 0;
298 
299  $urladd = "&id=".urlencode($id);
300 
301  print_barre_liste($langs->trans("Bills"), $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, '');
302 
303  print"\n<!-- debut table -->\n";
304  print '<table class="noborder" width="100%" cellpadding="4">';
305  print '<tr class="liste_titre">';
306  print '<td>'.$langs->trans("Invoice").'</td><td>'.$langs->trans("ThirdParty").'</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">'.$langs->trans("Status").'</td>';
307  print '</tr>';
308 
309  $total = 0;
310 
311  while ($i < min($num, $conf->liste_limit)) {
312  $obj = $db->fetch_object($result);
313 
314  print '<tr class="oddeven"><td>';
315 
316  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">';
317  print img_object($langs->trans("ShowBill"), "bill");
318  print '</a>&nbsp;';
319 
320  if ($type == 'bank-transfer') {
321  print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
322  } else {
323  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
324  }
325 
326  if ($type == 'bank-transfer') {
327  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">';
328  } else {
329  print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">';
330  }
331  print img_object($langs->trans("ShowCompany"), "company").' '.$obj->name."</a></td>\n";
332 
333  print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
334 
335  print '<td class="right">';
336  $invoicestatic->fetch($obj->facid);
337  print $invoicestatic->getLibStatut(5);
338  print "</td>\n";
339 
340  print "</tr>\n";
341 
342  $i++;
343  }
344 
345  print "</table>";
346 
347  $db->free($result);
348  } else {
349  dol_print_error($db);
350  }
351 }
352 
353 // End of page
354 llxFooter();
355 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
LignePrelevement
Class to manage withdrawals.
Definition: ligneprelevement.class.php:32
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:53
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Facture
Class to manage invoices.
Definition: facture.class.php:60
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
BonPrelevement
Class to manage withdrawal receipts.
Definition: bonprelevement.class.php:43
print_barre_liste
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.
Definition: functions.lib.php:5257
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
RejetPrelevement
Class to manage standing orders rejects.
Definition: rejetprelevement.class.php:31
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
price
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.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59