dolibarr  7.0.0-beta
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@capnetworks.com>
5  * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 require('../../main.inc.php');
28 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33 
34 $langs->load("banks");
35 $langs->load("categories");
36 
37 // Security check
38 if ($user->societe_id > 0) accessforbidden();
39 
40 $langs->load("bills");
41 $langs->load("withdrawals");
42 
43 // Get supervariables
44 $action = GETPOST('action','alpha');
45 $id = GETPOST('id','int');
46 $socid = GETPOST('socid','int');
47 
48 $page = GETPOST('page','int');
49 $sortorder = GETPOST('sortorder','alpha');
50 $sortfield = GETPOST('sortfield','alpha');
51 
52 if ($action == 'confirm_rejet')
53 {
54  if ( GETPOST("confirm") == 'yes')
55  {
56  if (GETPOST('remonth','int'))
57  {
58  $daterej = mktime(2, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
59  }
60 
61  if (empty($daterej))
62  {
63  $error++;
64  setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Date")), null, 'errors');
65  }
66 
67  elseif ($daterej > dol_now())
68  {
69  $error++;
70  $langs->load("error");
71  setEventMessages($langs->transnoentities("ErrorDateMustBeBeforeToday"), null, 'errors');
72  }
73 
74  if (GETPOST('motif','alpha') == 0)
75  {
76  $error++;
77  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefusedReason")), null, 'errors');
78  }
79 
80  if ( ! $error )
81  {
82  $lipre = new LignePrelevement($db, $user);
83 
84  if ($lipre->fetch($id) == 0)
85 
86  {
87  $rej = new RejetPrelevement($db, $user);
88 
89  $rej->create($user, $id, GETPOST('motif','alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer','int'));
90 
91  header("Location: ligne.php?id=".$id);
92  exit;
93  }
94 
95  }
96  else
97  {
98  $action="rejet";
99  }
100  }
101  else
102  {
103  header("Location: ligne.php?id=".$id);
104  exit;
105  }
106 }
107 
108 
109 /*
110  * View
111  */
112 
113 $invoicestatic=new Facture($db);
114 
115 llxHeader('',$langs->trans("StandingOrder"));
116 
117 $h = 0;
118 $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/ligne.php?id='.$id;
119 $head[$h][1] = $langs->trans("Card");
120 $hselected = $h;
121 $h++;
122 
123 if ($id)
124 {
125  $lipre = new LignePrelevement($db, $user);
126 
127  if ($lipre->fetch($id) == 0)
128  {
129  $bon = new BonPrelevement($db);
130  $bon->fetch($lipre->bon_rowid);
131 
132  dol_fiche_head($head, $hselected, $langs->trans("StandingOrder"));
133 
134  print '<table class="border" width="100%">';
135 
136  print '<tr><td width="20%">'.$langs->trans("WithdrawalsReceipts").'</td><td>';
137  print $bon->getNomUrl(1).'</td></tr>';
138  print '<tr><td width="20%">'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec,'day').'</td></tr>';
139  print '<tr><td width="20%">'.$langs->trans("Amount").'</td><td>'.price($lipre->amount).'</td></tr>';
140  print '<tr><td width="20%">'.$langs->trans("Status").'</td><td>'.$lipre->LibStatut($lipre->statut,1).'</td></tr>';
141 
142  if ($lipre->statut == 3)
143  {
144  $rej = new RejetPrelevement($db, $user);
145  $resf = $rej->fetch($lipre->id);
146  if ($resf == 0)
147  {
148  print '<tr><td width="20%">'.$langs->trans("RefusedReason").'</td><td>'.$rej->motif.'</td></tr>';
149  print '<tr><td width="20%">'.$langs->trans("RefusedData").'</td><td>';
150  if ($rej->date_rejet == 0)
151  {
152  /* Historique pour certaines install */
153  print $langs->trans("Unknown");
154  }
155  else
156  {
157  print dol_print_date($rej->date_rejet,'day');
158  }
159  print '</td></tr>';
160  print '<tr><td width="20%">'.$langs->trans("RefusedInvoicing").'</td><td>'.$rej->invoicing.'</td></tr>';
161  }
162  else
163  {
164  print '<tr><td width="20%">'.$resf.'</td></tr>';
165  }
166  }
167 
168  print '</table>';
169  dol_fiche_end();
170  }
171  else
172  {
173  dol_print_error($db);
174  }
175 
176  if ($action == 'rejet' && $user->rights->prelevement->bons->credit)
177  {
178  $form = new Form($db);
179 
180  $soc = new Societe($db);
181  $soc->fetch($lipre->socid);
182 
183  $rej = new RejetPrelevement($db, $user);
184 
185  print '<form name="confirm_rejet" method="post" action="ligne.php?id='.$id.'">';
186  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
187  print '<input type="hidden" name="action" value="confirm_rejet">';
188  print '<table class="border" width="100%">';
189 
190  print '<tr class="liste_titre">';
191  print '<td colspan="3">'.$langs->trans("WithdrawalRefused").'</td></tr>';
192 
193  //Select yes/no
194  print '<tr><td class="valid">'.$langs->trans("WithdrawalRefusedConfirm").' '.$soc->name.' ?</td>';
195  print '<td colspan="2" class="valid">';
196  print $form->selectyesno("confirm",1,0);
197  print '</td></tr>';
198 
199  //Date
200  print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedData").'</td>';
201  print '<td colspan="2" class="valid">';
202  print $form->select_date('','','','','',"confirm_rejet");
203  print '</td></tr>';
204 
205  //Reason
206  print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedReason").'</td>';
207  print '<td class="valid">';
208  print $form->selectarray("motif", $rej->motifs);
209  print '</td></tr>';
210 
211  //Facturer
212  print '<tr><td class="valid">'.$langs->trans("RefusedInvoicing").'</td>';
213  print '<td class="valid" colspan="2">';
214  print $form->selectarray("facturer", $rej->facturer);
215  print '</td></tr>';
216  print '</table><br>';
217 
218  //Confirm Button
219  print '<div class="center"><input type="submit" class="button" value='.$langs->trans("Confirm").'></div>';
220  print '</form>';
221  }
222 
223  /* ************************************************************************** */
224  /* */
225  /* Barre d'action */
226  /* */
227  /* ************************************************************************** */
228 
229  print "<div class=\"tabsAction\">";
230 
231  if ($action == '')
232  {
233  if ($bon->statut == 2 && $lipre->statut == 2)
234  {
235  if ($user->rights->prelevement->bons->credit)
236  {
237  print "<a class=\"butAction\" href=\"ligne.php?action=rejet&amp;id=$lipre->id\">".$langs->trans("StandingOrderReject")."</a>";
238  }
239  else
240  {
241  print "<a class=\"butActionRefused\" href=\"#\" title=\"".$langs->trans("NotAllowed")."\">".$langs->trans("StandingOrderReject")."</a>";
242  }
243  }
244  else
245  {
246  print "<a class=\"butActionRefused\" href=\"#\" title=\"".$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine")."\">".$langs->trans("StandingOrderReject")."</a>";
247  }
248  }
249 
250  print "</div>";
251 
252 
253 
254  if ($page == -1 || $page == null) { $page = 0 ; }
255 
256  $offset = $conf->liste_limit * $page ;
257  $pageprev = $page - 1;
258  $pagenext = $page + 1;
259 
260  if ($sortorder == "") $sortorder="DESC";
261  if ($sortfield == "") $sortfield="pl.fk_soc";
262 
263  /*
264  * List of invoices
265  */
266  $sql = "SELECT pf.rowid";
267  $sql.= " ,f.rowid as facid, f.facnumber as ref, f.total_ttc, f.paye, f.fk_statut";
268  $sql.= " , s.rowid as socid, s.nom as name";
269  $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
270  $sql.= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
271  $sql.= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
272  $sql.= " , ".MAIN_DB_PREFIX."facture as f";
273  $sql.= " , ".MAIN_DB_PREFIX."societe as s";
274  $sql.= " WHERE pf.fk_prelevement_lignes = pl.rowid";
275  $sql.= " AND pl.fk_prelevement_bons = p.rowid";
276  $sql.= " AND f.fk_soc = s.rowid";
277  $sql.= " AND pf.fk_facture = f.rowid";
278  $sql.= " AND f.entity = ".$conf->entity;
279  $sql.= " AND pl.rowid=".$id;
280  if ($socid) $sql.= " AND s.rowid = ".$socid;
281  $sql.= " ORDER BY $sortfield $sortorder ";
282  $sql.= $db->plimit($conf->liste_limit+1, $offset);
283 
284  $result = $db->query($sql);
285 
286  if ($result)
287  {
288  $num = $db->num_rows($result);
289  $i = 0;
290 
291  $urladd = "&amp;id=".$id;
292 
293  print_barre_liste($langs->trans("Bills"), $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, '');
294 
295  print"\n<!-- debut table -->\n";
296  print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
297  print '<tr class="liste_titre">';
298  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>';
299  print '</tr>';
300 
301  $total = 0;
302 
303  while ($i < min($num,$conf->liste_limit))
304  {
305  $obj = $db->fetch_object($result);
306 
307  print '<tr class="oddeven"><td>';
308 
309  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">';
310  print img_object($langs->trans("ShowBill"),"bill");
311  print '</a>&nbsp;';
312 
313  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
314 
315  print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">';
316  print img_object($langs->trans("ShowCompany"),"company"). ' '.$obj->name."</a></td>\n";
317 
318  print '<td align="right">'.price($obj->total_ttc)."</td>\n";
319 
320  print '<td align="right">';
321  $invoicestatic->fetch($obj->facid);
322  print $invoicestatic->getLibStatut(5);
323  print "</td>\n";
324 
325  print "</tr>\n";
326 
327  $i++;
328  }
329 
330  print "</table>";
331 
332  $db->free($result);
333  }
334  else
335  {
336  dol_print_error($db);
337  }
338 }
339 
340 llxFooter();
341 
342 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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).
print
Draft customers invoices.
Definition: index.php:91
Class to manage invoices.
Class to manage standing orders rejects.
Class to manage withdrawals.