dolibarr  13.0.2
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 // Security check
39 if ($user->socid > 0) accessforbidden();
40 
41 // Get supervariables
42 $action = GETPOST('action', 'aZ09');
43 $id = GETPOST('id', 'int');
44 $socid = GETPOST('socid', 'int');
45 
46 $type = GETPOST('type', 'aZ09');
47 
48 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
49 $sortorder = GETPOST('sortorder', 'aZ09comma');
50 $sortfield = GETPOST('sortfield', 'aZ09comma');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if ($page == -1 || $page == null) { $page = 0; }
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
56 
57 if ($sortorder == "") $sortorder = "DESC";
58 if ($sortfield == "") $sortfield = "pl.fk_soc";
59 
60 
61 /*
62  * Actions
63  */
64 
65 if ($action == 'confirm_rejet')
66 {
67  if (GETPOST("confirm") == 'yes')
68  {
69  if (GETPOST('remonth', 'int'))
70  {
71  $daterej = mktime(2, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
72  }
73 
74  if (empty($daterej))
75  {
76  $error++;
77  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
78  } elseif ($daterej > dol_now())
79  {
80  $error++;
81  $langs->load("error");
82  setEventMessages($langs->transnoentities("ErrorDateMustBeBeforeToday"), null, 'errors');
83  }
84 
85  if (GETPOST('motif', 'alpha') == 0)
86  {
87  $error++;
88  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefusedReason")), null, 'errors');
89  }
90 
91  if (!$error)
92  {
93  $lipre = new LignePrelevement($db);
94 
95  if ($lipre->fetch($id) == 0)
96 
97  {
98  $rej = new RejetPrelevement($db, $user, $type);
99 
100  $rej->create($user, $id, GETPOST('motif', 'alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer', 'int'));
101 
102  header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
103  exit;
104  }
105  } else {
106  $action = "rejet";
107  }
108  } else {
109  header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
110  exit;
111  }
112 }
113 
114 
115 /*
116  * View
117  */
118 
119 $invoicestatic = new Facture($db);
120 
121 $title = $langs->trans("WithdrawalsLine");
122 if ($type == 'bank-transfer') {
123  $title = $langs->trans("CreditTransferLine");
124 }
125 
126 llxHeader('', $title);
127 
128 $head = array();
129 
130 $h = 0;
131 $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$id.'&type='.$type;
132 $head[$h][1] = $title;
133 $hselected = $h;
134 $h++;
135 
136 if ($id)
137 {
138  $lipre = new LignePrelevement($db);
139 
140  if ($lipre->fetch($id) >= 0)
141  {
142  $bon = new BonPrelevement($db);
143  $bon->fetch($lipre->bon_rowid);
144 
145  print dol_get_fiche_head($head, $hselected, $title);
146 
147  print '<table class="border centpercent tableforfield">';
148 
149  print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
150  print $id.'</td></tr>';
151 
152  print '<tr><td class="titlefield">'.$langs->trans("WithdrawalsReceipts").'</td><td>';
153  print $bon->getNomUrl(1).'</td></tr>';
154 
155  print '<tr><td>'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec, 'day').'</td></tr>';
156  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($lipre->amount).'</td></tr>';
157  print '<tr><td>'.$langs->trans("Status").'</td><td>'.$lipre->LibStatut($lipre->statut, 1).'</td></tr>';
158 
159  if ($lipre->statut == 3)
160  {
161  $rej = new RejetPrelevement($db, $user, $type);
162  $resf = $rej->fetch($lipre->id);
163  if ($resf == 0)
164  {
165  print '<tr><td>'.$langs->trans("RefusedReason").'</td><td>'.$rej->motif.'</td></tr>';
166  print '<tr><td>'.$langs->trans("RefusedData").'</td><td>';
167  if ($rej->date_rejet == 0)
168  {
169  /* Historique pour certaines install */
170  print $langs->trans("Unknown");
171  } else {
172  print dol_print_date($rej->date_rejet, 'day');
173  }
174  print '</td></tr>';
175  print '<tr><td>'.$langs->trans("RefusedInvoicing").'</td><td>'.$rej->invoicing.'</td></tr>';
176  } else {
177  print '<tr><td>'.$resf.'</td></tr>';
178  }
179  }
180 
181  print '</table>';
183  } else {
184  dol_print_error($db);
185  }
186 
187  if ($action == 'rejet' && $user->rights->prelevement->bons->credit)
188  {
189  $form = new Form($db);
190 
191  $soc = new Societe($db);
192  $soc->fetch($lipre->socid);
193 
194  $rej = new RejetPrelevement($db, $user, $type);
195 
196  print '<form name="confirm_rejet" method="post" action="line.php?id='.$id.'">';
197  print '<input type="hidden" name="token" value="'.newToken().'">';
198  print '<input type="hidden" name="action" value="confirm_rejet">';
199  print '<input type="hidden" name="type" value="'.$type.'">';
200  print '<table class="noborder centpercent">';
201 
202  print '<tr class="liste_titre">';
203  print '<td colspan="3">'.$langs->trans("WithdrawalRefused").'</td></tr>';
204 
205  //Select yes/no
206  print '<tr><td class="valid">'.$langs->trans("WithdrawalRefusedConfirm").' '.$soc->name.' ?</td>';
207  print '<td colspan="2" class="valid">';
208  print $form->selectyesno("confirm", 1, 0);
209  print '</td></tr>';
210 
211  //Date
212  print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedData").'</td>';
213  print '<td colspan="2" class="valid">';
214  print $form->selectDate('', '', '', '', '', "confirm_rejet");
215  print '</td></tr>';
216 
217  //Reason
218  print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedReason").'</td>';
219  print '<td class="valid">';
220  print $form->selectarray("motif", $rej->motifs, GETPOSTISSET('motif') ? GETPOST('motif', 'int') : '');
221  print '</td></tr>';
222 
223  //Facturer
224  print '<tr><td class="valid">'.$langs->trans("RefusedInvoicing").'</td>';
225  print '<td class="valid" colspan="2">';
226  print $form->selectarray("facturer", $rej->facturer, GETPOSTISSET('facturer') ? GETPOST('facturer', 'int') : '');
227  print '</td></tr>';
228  print '</table><br>';
229 
230  //Confirm Button
231  print '<div class="center"><input type="submit" class="button" value='.$langs->trans("Confirm").'></div>';
232  print '</form>';
233  }
234 
235  /* ************************************************************************** */
236  /* */
237  /* Barre d'action */
238  /* */
239  /* ************************************************************************** */
240 
241  print "<div class=\"tabsAction\">";
242 
243  if ($action == '')
244  {
245  if ($bon->statut == BonPrelevement::STATUS_CREDITED)
246  {
247  if ($lipre->statut == 2) {
248  if ($user->rights->prelevement->bons->credit)
249  {
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  $sql .= " , ".MAIN_DB_PREFIX."facture as f";
272  $sql .= " , ".MAIN_DB_PREFIX."societe as s";
273  $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
274  $sql .= " AND pl.fk_prelevement_bons = p.rowid";
275  $sql .= " AND f.fk_soc = s.rowid";
276  $sql .= " AND pf.fk_facture = f.rowid";
277  $sql .= " AND f.entity IN (".getEntity('invoice').")";
278  $sql .= " AND pl.rowid=".$id;
279  if ($socid) $sql .= " AND s.rowid = ".$socid;
280  $sql .= " ORDER BY $sortfield $sortorder ";
281  $sql .= $db->plimit($conf->liste_limit + 1, $offset);
282 
283  $result = $db->query($sql);
284 
285  if ($result)
286  {
287  $num = $db->num_rows($result);
288  $i = 0;
289 
290  $urladd = "&amp;id=".$id;
291 
292  print_barre_liste($langs->trans("Bills"), $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, '');
293 
294  print"\n<!-- debut table -->\n";
295  print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
296  print '<tr class="liste_titre">';
297  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>';
298  print '</tr>';
299 
300  $total = 0;
301 
302  while ($i < min($num, $conf->liste_limit))
303  {
304  $obj = $db->fetch_object($result);
305 
306  print '<tr class="oddeven"><td>';
307 
308  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">';
309  print img_object($langs->trans("ShowBill"), "bill");
310  print '</a>&nbsp;';
311 
312  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
313 
314  print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">';
315  print img_object($langs->trans("ShowCompany"), "company").' '.$obj->name."</a></td>\n";
316 
317  print '<td class="right">'.price($obj->total_ttc)."</td>\n";
318 
319  print '<td class="right">';
320  $invoicestatic->fetch($obj->facid);
321  print $invoicestatic->getLibStatut(5);
322  print "</td>\n";
323 
324  print "</tr>\n";
325 
326  $i++;
327  }
328 
329  print "</table>";
330 
331  $db->free($result);
332  } else {
333  dol_print_error($db);
334  }
335 }
336 
337 // End of page
338 llxFooter();
339 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage withdrawal receipts.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
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_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:59
Class to manage standing orders rejects.
Class to manage withdrawals.