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