dolibarr  17.0.4
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 if ($type == 'bank-transfer') {
123  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
124  $invoicestatic = new FactureFournisseur($db);
125 } else {
126  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
127  $invoicestatic = new Facture($db);
128 }
129 
130 $title = $langs->trans("WithdrawalsLine");
131 if ($type == 'bank-transfer') {
132  $title = $langs->trans("CreditTransferLine");
133 }
134 
135 llxHeader('', $title);
136 
137 $head = array();
138 
139 $h = 0;
140 $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$id.'&type='.$type;
141 $head[$h][1] = $title;
142 $hselected = $h;
143 $h++;
144 
145 if ($id) {
146  $lipre = new LignePrelevement($db);
147 
148  if ($lipre->fetch($id) >= 0) {
149  $bon = new BonPrelevement($db);
150  $bon->fetch($lipre->bon_rowid);
151 
152  print dol_get_fiche_head($head, $hselected, $title);
153 
154  print '<table class="border centpercent tableforfield">';
155 
156  print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
157  print $id.'</td></tr>';
158 
159  print '<tr><td class="titlefield">'.$langs->trans("WithdrawalsReceipts").'</td><td>';
160  print $bon->getNomUrl(1).'</td></tr>';
161 
162  print '<tr><td>'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec, 'day').'</td></tr>';
163 
164  print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($lipre->amount).'</span></td></tr>';
165 
166  print '<tr><td>'.$langs->trans("Status").'</td><td>'.$lipre->LibStatut($lipre->statut, 1).'</td></tr>';
167 
168  if ($lipre->statut == 3) {
169  $rej = new RejetPrelevement($db, $user, $type);
170  $resf = $rej->fetch($lipre->id);
171  if ($resf == 0) {
172  print '<tr><td>'.$langs->trans("RefusedReason").'</td><td>'.$rej->motif.'</td></tr>';
173 
174  print '<tr><td>'.$langs->trans("RefusedData").'</td><td>';
175  if ($rej->date_rejet == 0) {
176  /* Historique pour certaines install */
177  print $langs->trans("Unknown");
178  } else {
179  print dol_print_date($rej->date_rejet, 'day');
180  }
181  print '</td></tr>';
182 
183  print '<tr><td>'.$langs->trans("RefusedInvoicing").'</td><td>'.$rej->invoicing.'</td></tr>';
184  } else {
185  print '<tr><td>'.$resf.'</td></tr>';
186  }
187  }
188 
189  print '</table>';
190  print dol_get_fiche_end();
191  } else {
192  dol_print_error($db);
193  }
194 
195  if ($action == 'rejet' && $user->rights->prelevement->bons->credit) {
196  $form = new Form($db);
197 
198  $soc = new Societe($db);
199  $soc->fetch($lipre->socid);
200 
201  $rej = new RejetPrelevement($db, $user, $type);
202 
203  print '<form name="confirm_rejet" method="post" action="line.php?id='.$id.'">';
204  print '<input type="hidden" name="token" value="'.newToken().'">';
205  print '<input type="hidden" name="action" value="confirm_rejet">';
206  print '<input type="hidden" name="type" value="'.$type.'">';
207  print '<table class="noborder centpercent">';
208 
209  print '<tr class="liste_titre">';
210  print '<td colspan="3">'.$langs->trans("WithdrawalRefused").'</td></tr>';
211 
212  //Select yes/no
213  print '<tr><td class="valid">'.$langs->trans("WithdrawalRefusedConfirm").' '.$soc->name.' ?</td>';
214  print '<td colspan="2" class="valid">';
215  print $form->selectyesno("confirm", 1, 0);
216  print '</td></tr>';
217 
218  //Date
219  print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedData").'</td>';
220  print '<td colspan="2" class="valid">';
221  print $form->selectDate('', '', '', '', '', "confirm_rejet");
222  print '</td></tr>';
223 
224  //Reason
225  print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedReason").'</td>';
226  print '<td class="valid">';
227  print $form->selectarray("motif", $rej->motifs, GETPOSTISSET('motif') ? GETPOST('motif', 'int') : '');
228  print '</td></tr>';
229 
230  //Facturer
231  print '<tr><td class="valid">'.$langs->trans("RefusedInvoicing").'</td>';
232  print '<td class="valid" colspan="2">';
233  print $form->selectarray("facturer", $rej->facturer, GETPOSTISSET('facturer') ? GETPOST('facturer', 'int') : '');
234  print '</td></tr>';
235  print '</table><br>';
236 
237  //Confirm Button
238  print '<div class="center"><input type="submit" class="button button-save" value='.$langs->trans("Confirm").'></div>';
239  print '</form>';
240  }
241 
242  /*
243  * Action bar
244  */
245  print '<div class="tabsAction">';
246 
247  if ($action == '') {
248  if ($bon->statut == BonPrelevement::STATUS_CREDITED) {
249  if ($lipre->statut == 2) {
250  if ($user->rights->prelevement->bons->credit) {
251  print '<a class="butActionDelete" href="line.php?action=rejet&type='.$type.'&id='.$lipre->id.'">'.$langs->trans("StandingOrderReject").'</a>';
252  } else {
253  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
254  }
255  }
256  } else {
257  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
258  }
259  }
260 
261  print '</div>';
262 
263  /*
264  * List of invoices
265  */
266  $sql = "SELECT pf.rowid";
267  $sql .= " ,f.rowid as facid, f.ref 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 as pf";
272  if ($type == 'bank-transfer') {
273  $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
274  } else {
275  $sql .= " , ".MAIN_DB_PREFIX."facture as f";
276  }
277  $sql .= " , ".MAIN_DB_PREFIX."societe as s";
278  $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
279  $sql .= " AND pl.fk_prelevement_bons = p.rowid";
280  $sql .= " AND f.fk_soc = s.rowid";
281  if ($type == 'bank-transfer') {
282  $sql .= " AND pf.fk_facture_fourn = f.rowid";
283  } else {
284  $sql .= " AND pf.fk_facture = f.rowid";
285  }
286  $sql .= " AND f.entity IN (".getEntity('invoice').")";
287  $sql .= " AND pl.rowid = ".((int) $id);
288  if ($socid) {
289  $sql .= " AND s.rowid = ".((int) $socid);
290  }
291  $sql .= $db->order($sortfield, $sortorder);
292  $sql .= $db->plimit($conf->liste_limit + 1, $offset);
293 
294  $result = $db->query($sql);
295 
296  if ($result) {
297  $num = $db->num_rows($result);
298  $i = 0;
299 
300  $urladd = "&id=".urlencode($id);
301 
302  print_barre_liste($langs->trans("Bills"), $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, '');
303 
304  print"\n<!-- debut table -->\n";
305  print '<table class="noborder" width="100%" cellpadding="4">';
306  print '<tr class="liste_titre">';
307  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>';
308  print '</tr>';
309 
310  $total = 0;
311 
312  while ($i < min($num, $conf->liste_limit)) {
313  $obj = $db->fetch_object($result);
314 
315  print '<tr class="oddeven"><td>';
316 
317  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">';
318  print img_object($langs->trans("ShowBill"), "bill");
319  print '</a>&nbsp;';
320 
321  if ($type == 'bank-transfer') {
322  print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
323  } else {
324  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
325  }
326 
327  if ($type == 'bank-transfer') {
328  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">';
329  } else {
330  print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">';
331  }
332  print img_object($langs->trans("ShowCompany"), "company").' '.$obj->name."</a></td>\n";
333 
334  print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
335 
336  print '<td class="right">';
337  $invoicestatic->fetch($obj->facid);
338  print $invoicestatic->getLibStatut(5);
339  print "</td>\n";
340 
341  print "</tr>\n";
342 
343  $i++;
344  }
345 
346  print "</table>";
347 
348  $db->free($result);
349  } else {
350  dol_print_error($db);
351  }
352 }
353 
354 // End of page
355 llxFooter();
356 $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 suppliers invoices.
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.