dolibarr  x.y.z
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
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
34 require_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', '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');
50 if (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 
58 if ($sortorder == "") {
59  $sortorder = "DESC";
60 }
61 if ($sortfield == "") {
62  $sortfield = "pl.fk_soc";
63 }
64 
65 
66 if ($type == 'bank-transfer') {
67  $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
68 } else {
69  $result = restrictedArea($user, 'prelevement', '', '', 'bons');
70 }
71 
72 
73 /*
74  * Actions
75  */
76 
77 if ($action == 'confirm_rejet') {
78  if (GETPOST("confirm") == 'yes') {
79  if (GETPOST('remonth', 'int')) {
80  $daterej = mktime(2, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
81  }
82 
83  if (empty($daterej)) {
84  $error++;
85  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
86  } elseif ($daterej > dol_now()) {
87  $error++;
88  $langs->load("error");
89  setEventMessages($langs->transnoentities("ErrorDateMustBeBeforeToday"), null, 'errors');
90  }
91 
92  if (GETPOST('motif', 'alpha') == 0) {
93  $error++;
94  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefusedReason")), null, 'errors');
95  }
96 
97  if (!$error) {
98  $lipre = new LignePrelevement($db);
99 
100  if ($lipre->fetch($id) == 0) {
101  $rej = new RejetPrelevement($db, $user, $type);
102 
103  $rej->create($user, $id, GETPOST('motif', 'alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer', 'int'));
104 
105  header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
106  exit;
107  }
108  } else {
109  $action = "rejet";
110  }
111  } else {
112  header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
113  exit;
114  }
115 }
116 
117 
118 /*
119  * View
120  */
121 
122 $invoicestatic = new Facture($db);
123 
124 $title = $langs->trans("WithdrawalsLine");
125 if ($type == 'bank-transfer') {
126  $title = $langs->trans("CreditTransferLine");
127 }
128 
129 llxHeader('', $title);
130 
131 $head = array();
132 
133 $h = 0;
134 $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$id.'&type='.$type;
135 $head[$h][1] = $title;
136 $hselected = $h;
137 $h++;
138 
139 if ($id) {
140  $lipre = new LignePrelevement($db);
141 
142  if ($lipre->fetch($id) >= 0) {
143  $bon = new BonPrelevement($db);
144  $bon->fetch($lipre->bon_rowid);
145 
146  print dol_get_fiche_head($head, $hselected, $title);
147 
148  print '<table class="border centpercent tableforfield">';
149 
150  print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
151  print $id.'</td></tr>';
152 
153  print '<tr><td class="titlefield">'.$langs->trans("WithdrawalsReceipts").'</td><td>';
154  print $bon->getNomUrl(1).'</td></tr>';
155 
156  print '<tr><td>'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec, 'day').'</td></tr>';
157 
158  print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($lipre->amount).'</span></td></tr>';
159 
160  print '<tr><td>'.$langs->trans("Status").'</td><td>'.$lipre->LibStatut($lipre->statut, 1).'</td></tr>';
161 
162  if ($lipre->statut == 3) {
163  $rej = new RejetPrelevement($db, $user, $type);
164  $resf = $rej->fetch($lipre->id);
165  if ($resf == 0) {
166  print '<tr><td>'.$langs->trans("RefusedReason").'</td><td>'.$rej->motif.'</td></tr>';
167 
168  print '<tr><td>'.$langs->trans("RefusedData").'</td><td>';
169  if ($rej->date_rejet == 0) {
170  /* Historique pour certaines install */
171  print $langs->trans("Unknown");
172  } else {
173  print dol_print_date($rej->date_rejet, 'day');
174  }
175  print '</td></tr>';
176 
177  print '<tr><td>'.$langs->trans("RefusedInvoicing").'</td><td>'.$rej->invoicing.'</td></tr>';
178  } else {
179  print '<tr><td>'.$resf.'</td></tr>';
180  }
181  }
182 
183  print '</table>';
184  print dol_get_fiche_end();
185  } else {
186  dol_print_error($db);
187  }
188 
189  if ($action == 'rejet' && $user->rights->prelevement->bons->credit) {
190  $form = new Form($db);
191 
192  $soc = new Societe($db);
193  $soc->fetch($lipre->socid);
194 
195  $rej = new RejetPrelevement($db, $user, $type);
196 
197  print '<form name="confirm_rejet" method="post" action="line.php?id='.$id.'">';
198  print '<input type="hidden" name="token" value="'.newToken().'">';
199  print '<input type="hidden" name="action" value="confirm_rejet">';
200  print '<input type="hidden" name="type" value="'.$type.'">';
201  print '<table class="noborder centpercent">';
202 
203  print '<tr class="liste_titre">';
204  print '<td colspan="3">'.$langs->trans("WithdrawalRefused").'</td></tr>';
205 
206  //Select yes/no
207  print '<tr><td class="valid">'.$langs->trans("WithdrawalRefusedConfirm").' '.$soc->name.' ?</td>';
208  print '<td colspan="2" class="valid">';
209  print $form->selectyesno("confirm", 1, 0);
210  print '</td></tr>';
211 
212  //Date
213  print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedData").'</td>';
214  print '<td colspan="2" class="valid">';
215  print $form->selectDate('', '', '', '', '', "confirm_rejet");
216  print '</td></tr>';
217 
218  //Reason
219  print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedReason").'</td>';
220  print '<td class="valid">';
221  print $form->selectarray("motif", $rej->motifs, GETPOSTISSET('motif') ? GETPOST('motif', 'int') : '');
222  print '</td></tr>';
223 
224  //Facturer
225  print '<tr><td class="valid">'.$langs->trans("RefusedInvoicing").'</td>';
226  print '<td class="valid" colspan="2">';
227  print $form->selectarray("facturer", $rej->facturer, GETPOSTISSET('facturer') ? GETPOST('facturer', 'int') : '');
228  print '</td></tr>';
229  print '</table><br>';
230 
231  //Confirm Button
232  print '<div class="center"><input type="submit" class="button button-save" value='.$langs->trans("Confirm").'></div>';
233  print '</form>';
234  }
235 
236  /*
237  * Action bar
238  */
239  print '<div class="tabsAction">';
240 
241  if ($action == '') {
242  if ($bon->statut == BonPrelevement::STATUS_CREDITED) {
243  if ($lipre->statut == 2) {
244  if ($user->rights->prelevement->bons->credit) {
245  print '<a class="butActionDelete" href="line.php?action=rejet&type='.$type.'&id='.$lipre->id.'">'.$langs->trans("StandingOrderReject").'</a>';
246  } else {
247  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
248  }
249  }
250  } else {
251  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
252  }
253  }
254 
255  print '</div>';
256 
257  /*
258  * List of invoices
259  */
260  $sql = "SELECT pf.rowid";
261  $sql .= " ,f.rowid as facid, f.ref as ref, f.total_ttc, f.paye, f.fk_statut";
262  $sql .= " , s.rowid as socid, s.nom as name";
263  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
264  $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
265  $sql .= " , ".MAIN_DB_PREFIX."prelevement as pf";
266  if ($type == 'bank-transfer') {
267  $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
268  } else {
269  $sql .= " , ".MAIN_DB_PREFIX."facture as f";
270  }
271  $sql .= " , ".MAIN_DB_PREFIX."societe as s";
272  $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
273  $sql .= " AND pl.fk_prelevement_bons = p.rowid";
274  $sql .= " AND f.fk_soc = s.rowid";
275  if ($type == 'bank-transfer') {
276  $sql .= " AND pf.fk_facture_fourn = f.rowid";
277  } else {
278  $sql .= " AND pf.fk_facture = f.rowid";
279  }
280  $sql .= " AND f.entity IN (".getEntity('invoice').")";
281  $sql .= " AND pl.rowid = ".((int) $id);
282  if ($socid) {
283  $sql .= " AND s.rowid = ".((int) $socid);
284  }
285  $sql .= $db->order($sortfield, $sortorder);
286  $sql .= $db->plimit($conf->liste_limit + 1, $offset);
287 
288  $result = $db->query($sql);
289 
290  if ($result) {
291  $num = $db->num_rows($result);
292  $i = 0;
293 
294  $urladd = "&id=".urlencode($id);
295 
296  print_barre_liste($langs->trans("Bills"), $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, '');
297 
298  print"\n<!-- debut table -->\n";
299  print '<table class="noborder" width="100%" cellpadding="4">';
300  print '<tr class="liste_titre">';
301  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>';
302  print '</tr>';
303 
304  $total = 0;
305 
306  while ($i < min($num, $conf->liste_limit)) {
307  $obj = $db->fetch_object($result);
308 
309  print '<tr class="oddeven"><td>';
310 
311  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">';
312  print img_object($langs->trans("ShowBill"), "bill");
313  print '</a>&nbsp;';
314 
315  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
316 
317  print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">';
318  print img_object($langs->trans("ShowCompany"), "company").' '.$obj->name."</a></td>\n";
319 
320  print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
321 
322  print '<td class="right">';
323  $invoicestatic->fetch($obj->facid);
324  print $invoicestatic->getLibStatut(5);
325  print "</td>\n";
326 
327  print "</tr>\n";
328 
329  $i++;
330  }
331 
332  print "</table>";
333 
334  $db->free($result);
335  } else {
336  dol_print_error($db);
337  }
338 }
339 
340 // End of page
341 llxFooter();
342 $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 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...)
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.