dolibarr  7.0.0-beta
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
6  * Copyright (C) 2013 Marcos GarcĂ­a <marcosgdf@gmail.com>
7  * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33 require_once DOL_DOCUMENT_ROOT .'/core/modules/facture/modules_facture.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
35 if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36 
37 $langs->load('bills');
38 $langs->load('banks');
39 $langs->load('companies');
40 
41 $id=GETPOST('id','int');
42 $ref=GETPOST('ref', 'alpha');
43 $action=GETPOST('action','alpha');
44 $confirm=GETPOST('confirm','alpha');
45 $backtopage=GETPOST('backtopage','alpha');
46 
47 // Security check
48 if ($user->societe_id) $socid=$user->societe_id;
49 // TODO ajouter regle pour restreindre acces paiement
50 //$result = restrictedArea($user, 'facture', $id,'');
51 
52 $object = new Paiement($db);
53 
54 
55 /*
56  * Actions
57  */
58 
59 if ($action == 'setnote' && $user->rights->facture->paiement)
60 {
61  $db->begin();
62 
63  $object->fetch($id);
64  $result = $object->update_note(GETPOST('note','none'));
65  if ($result > 0)
66  {
67  $db->commit();
68  $action='';
69  }
70  else
71  {
72  setEventMessages($object->error, $object->errors, 'errors');
73  $db->rollback();
74  }
75 }
76 
77 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->paiement)
78 {
79  $db->begin();
80 
81  $object->fetch($id);
82  $result = $object->delete();
83  if ($result > 0)
84  {
85  $db->commit();
86 
87  if ($backtopage)
88  {
89  header("Location: ".$backtopage);
90  exit;
91  }
92  else
93  {
94  header("Location: list.php");
95  exit;
96  }
97  }
98  else
99  {
100  $langs->load("errors");
101  setEventMessages($object->error, $object->errors, 'errors');
102  $db->rollback();
103  }
104 }
105 
106 if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->facture->paiement)
107 {
108  $db->begin();
109 
110  $object->fetch($id);
111  if ($object->valide() > 0)
112  {
113  $db->commit();
114 
115  // Loop on each invoice linked to this payment to rebuild PDF
116  $factures=array();
117  foreach($factures as $id)
118  {
119  $fac = new Facture($db);
120  $fac->fetch($id);
121 
122  $outputlangs = $langs;
123  if (! empty($_REQUEST['lang_id']))
124  {
125  $outputlangs = new Translate("",$conf);
126  $outputlangs->setDefaultLang($_REQUEST['lang_id']);
127  }
128  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
129  $fac->generateDocument($fac->modelpdf, $outputlangs);
130  }
131  }
132 
133  header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
134  exit;
135  }
136  else
137  {
138  $langs->load("errors");
139  setEventMessages($object->error, $object->errors, 'errors');
140  $db->rollback();
141  }
142 }
143 
144 if ($action == 'setnum_paiement' && ! empty($_POST['num_paiement']))
145 {
146  $object->fetch($id);
147  $res = $object->update_num($_POST['num_paiement']);
148  if ($res === 0)
149  {
150  setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
151  }
152  else
153  {
154  setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
155  }
156 }
157 
158 if ($action == 'setdatep' && ! empty($_POST['datepday']))
159 {
160  $object->fetch($id);
161  $datepaye = dol_mktime(12, 0, 0, $_POST['datepmonth'], $_POST['datepday'], $_POST['datepyear']);
162  $res = $object->update_date($datepaye);
163  if ($res === 0)
164  {
165  setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
166  }
167  else
168  {
169  setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
170  }
171 }
172 
173 
174 /*
175  * View
176  */
177 
178 llxHeader('', $langs->trans("Payment"));
179 
180 $thirdpartystatic=new Societe($db);
181 
182 $result=$object->fetch($id, $ref);
183 if ($result <= 0)
184 {
185  dol_print_error($db,'Payement '.$id.' not found in database');
186  exit;
187 }
188 
189 $form = new Form($db);
190 
191 $head = payment_prepare_head($object);
192 
193 dol_fiche_head($head, 'payment', $langs->trans("PaymentCustomerInvoice"), -1, 'payment');
194 
195 /*
196  * Confirmation de la suppression du paiement
197  */
198 if ($action == 'delete')
199 {
200  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
201 
202 }
203 
204 /*
205  * Confirmation de la validation du paiement
206  */
207 if ($action == 'valide')
208 {
209  $facid = $_GET['facid'];
210  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
211 
212 }
213 
214 $linkback = '<a href="' . DOL_URL_ROOT . '/compta/paiement/list.php">' . $langs->trans("BackToList") . '</a>';
215 
216 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
217 
218 
219 print '<div class="fichecenter">';
220 print '<div class="underbanner clearboth"></div>';
221 
222 print '<table class="border centpercent">'."\n";
223 
224 // Date payment
225 print '<tr><td class="titlefield">'.$form->editfieldkey("Date",'datep',$object->date,$object,$user->rights->facture->paiement).'</td><td colspan="3">';
226 print $form->editfieldval("Date",'datep',$object->date,$object,$user->rights->facture->paiement,'datepicker','',null,$langs->trans('PaymentDateUpdateSucceeded'));
227 print '</td></tr>';
228 
229 // Payment type (VIR, LIQ, ...)
230 $labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->type_libelle;
231 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$labeltype.'</td></tr>';
232 
233 // Payment numero
234 print '<tr><td>'.$form->editfieldkey("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
235 print $form->editfieldval("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
236 print '</td></tr>';
237 
238 // Amount
239 print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->montant,'',$langs,0,0,-1,$conf->currency).'</td></tr>';
240 
241 // Note
242 print '<tr><td class="tdtop">'.$form->editfieldkey("Note",'note',$object->note,$object,$user->rights->facture->paiement).'</td><td colspan="3">';
243 print $form->editfieldval("Note",'note',$object->note,$object,$user->rights->facture->paiement,'textarea');
244 print '</td></tr>';
245 
246 $disable_delete = 0;
247 // Bank account
248 if (! empty($conf->banque->enabled))
249 {
250  if ($object->fk_account > 0)
251  {
252  $bankline=new AccountLine($db);
253  $bankline->fetch($object->bank_line);
254  if ($bankline->rappro)
255  {
256  $disable_delete = 1;
257  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
258  }
259 
260  print '<tr>';
261  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
262  print '<td colspan="3">';
263  print $bankline->getNomUrl(1,0,'showconciliated');
264  print '</td>';
265  print '</tr>';
266 
267  print '<tr>';
268  print '<td>'.$langs->trans('BankAccount').'</td>';
269  print '<td colspan="3">';
270  $accountstatic=new Account($db);
271  $accountstatic->fetch($bankline->fk_account);
272  print $accountstatic->getNomUrl(1);
273  print '</td>';
274  print '</tr>';
275 
276  if ($object->type_code == 'CHQ' && $bankline->fk_bordereau > 0)
277  {
278  dol_include_once('/compta/paiement/cheque/class/remisecheque.class.php');
279  $bordereau = new RemiseCheque($db);
280  $bordereau->fetch($bankline->fk_bordereau);
281 
282  print '<tr>';
283  print '<td>'.$langs->trans('CheckReceipt').'</td>';
284  print '<td colspan="3">';
285  print $bordereau->getNomUrl(1);
286  print '</td>';
287  print '</tr>';
288  }
289  }
290 }
291 
292 print '</table>';
293 
294 print '</div>';
295 
296 dol_fiche_end();
297 
298 
299 /*
300  * List of invoices
301  */
302 
303 $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.total_ttc, f.paye, f.fk_statut, pf.amount, s.nom as name, s.rowid as socid';
304 $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
305 $sql.= ' WHERE pf.fk_facture = f.rowid';
306 $sql.= ' AND f.fk_soc = s.rowid';
307 $sql.= ' AND f.entity = '.$conf->entity;
308 $sql.= ' AND pf.fk_paiement = '.$object->id;
309 $resql=$db->query($sql);
310 if ($resql)
311 {
312  $num = $db->num_rows($resql);
313 
314  $i = 0;
315  $total = 0;
316 
317  $moreforfilter='';
318 
319  print '<br>';
320 
321  print '<div class="div-table-responsive">';
322  print '<table class="noborder" width="100%">';
323 
324  print '<tr class="liste_titre">';
325  print '<td>'.$langs->trans('Bill').'</td>';
326  print '<td>'.$langs->trans('Company').'</td>';
327  print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
328  print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
329  print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
330  print '<td align="right">'.$langs->trans('Status').'</td>';
331  print "</tr>\n";
332 
333  if ($num > 0)
334  {
335  $var=True;
336 
337  while ($i < $num)
338  {
339  $objp = $db->fetch_object($resql);
340 
341  print '<tr class="oddeven">';
342 
343  $invoice=new Facture($db);
344  $invoice->fetch($objp->facid);
345  $paiement = $invoice->getSommePaiement();
346  $creditnotes=$invoice->getSumCreditNotesUsed();
347  $deposits=$invoice->getSumDepositsUsed();
348  $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
349  $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
350 
351  // Invoice
352  print '<td>';
353  print $invoice->getNomUrl(1);
354  print "</td>\n";
355 
356  // Third party
357  print '<td>';
358  $thirdpartystatic->id=$objp->socid;
359  $thirdpartystatic->name=$objp->name;
360  print $thirdpartystatic->getNomUrl(1);
361  print '</td>';
362 
363  // Expected to pay
364  print '<td align="right">'.price($objp->total_ttc).'</td>';
365 
366  // Amount payed
367  print '<td align="right">'.price($objp->amount).'</td>';
368 
369  // Remain to pay
370  print '<td align="right">'.price($remaintopay).'</td>';
371 
372  // Status
373  print '<td align="right">'.$invoice->getLibStatut(5, $alreadypayed).'</td>';
374 
375  print "</tr>\n";
376  if ($objp->paye == 1) // If at least one invoice is paid, disable delete
377  {
378  $disable_delete = 1;
379  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
380  }
381  $total = $total + $objp->amount;
382  $i++;
383  }
384  }
385 
386 
387  print "</table>\n";
388  print '</div>';
389 
390  $db->free($resql);
391 }
392 else
393 {
394  dol_print_error($db);
395 }
396 
397 
398 
399 /*
400  * Boutons Actions
401  */
402 
403 print '<div class="tabsAction">';
404 
405 if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
406 {
407  if ($user->societe_id == 0 && $object->statut == 0 && $_GET['action'] == '')
408  {
409  if ($user->rights->facture->paiement)
410  {
411  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
412  }
413  }
414 }
415 
416 if ($user->societe_id == 0 && $action == '')
417 {
418  if ($user->rights->facture->paiement)
419  {
420  if (! $disable_delete)
421  {
422  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
423  }
424  else
425  {
426  print '<a class="butActionRefused" href="#" title="'.$title_button.'">'.$langs->trans('Delete').'</a>';
427  }
428  }
429 }
430 
431 print '</div>';
432 
433 llxFooter();
434 
435 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Class to manage bank transaction lines.
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
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Class to manage bank accounts.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage payments of customer invoices.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage translations.
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...
print
Draft customers invoices.
Definition: index.php:91
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Return a prefix to use for this Dolibarr instance, for session/cookie names or email id...
Class to manage invoices.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
Class to manage cheque delivery receipts.