dolibarr  9.0.0
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@inodbox.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 // Load translation files required by the page
38 $langs->loadLangs(array('bills','banks','companies'));
39 
40 $id=GETPOST('id','int');
41 $ref=GETPOST('ref', 'alpha');
42 $action=GETPOST('action','alpha');
43 $confirm=GETPOST('confirm','alpha');
44 $backtopage=GETPOST('backtopage','alpha');
45 
46 // Security check
47 if ($user->societe_id) $socid=$user->societe_id;
48 // TODO ajouter regle pour restreindre acces paiement
49 //$result = restrictedArea($user, 'facture', $id,'');
50 
51 $object = new Paiement($db);
52 
53 
54 /*
55  * Actions
56  */
57 
58 if ($action == 'setnote' && $user->rights->facture->paiement)
59 {
60  $db->begin();
61 
62  $object->fetch($id);
63  $result = $object->update_note(GETPOST('note','none'));
64  if ($result > 0)
65  {
66  $db->commit();
67  $action='';
68  }
69  else
70  {
71  setEventMessages($object->error, $object->errors, 'errors');
72  $db->rollback();
73  }
74 }
75 
76 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->paiement)
77 {
78  $db->begin();
79 
80  $object->fetch($id);
81  $result = $object->delete();
82  if ($result > 0)
83  {
84  $db->commit();
85 
86  if ($backtopage)
87  {
88  header("Location: ".$backtopage);
89  exit;
90  }
91  else
92  {
93  header("Location: list.php");
94  exit;
95  }
96  }
97  else
98  {
99  $langs->load("errors");
100  setEventMessages($object->error, $object->errors, 'errors');
101  $db->rollback();
102  }
103 }
104 
105 if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->facture->paiement)
106 {
107  $db->begin();
108 
109  $object->fetch($id);
110  if ($object->valide($user) > 0)
111  {
112  $db->commit();
113 
114  // Loop on each invoice linked to this payment to rebuild PDF
115  $factures=array();
116  foreach($factures as $id)
117  {
118  $fac = new Facture($db);
119  $fac->fetch($id);
120 
121  $outputlangs = $langs;
122  if (! empty($_REQUEST['lang_id']))
123  {
124  $outputlangs = new Translate("",$conf);
125  $outputlangs->setDefaultLang($_REQUEST['lang_id']);
126  }
127  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
128  $fac->generateDocument($fac->modelpdf, $outputlangs);
129  }
130  }
131 
132  header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
133  exit;
134  }
135  else
136  {
137  $langs->load("errors");
138  setEventMessages($object->error, $object->errors, 'errors');
139  $db->rollback();
140  }
141 }
142 
143 if ($action == 'setnum_paiement' && ! empty($_POST['num_paiement']))
144 {
145  $object->fetch($id);
146  $res = $object->update_num($_POST['num_paiement']);
147  if ($res === 0)
148  {
149  setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
150  }
151  else
152  {
153  setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
154  }
155 }
156 
157 if ($action == 'setdatep' && ! empty($_POST['datepday']))
158 {
159  $object->fetch($id);
160  $datepaye = dol_mktime(GETPOST('datephour','int'), GETPOST('datepmin','int'), GETPOST('datepsec','int'), GETPOST('datepmonth','int'), GETPOST('datepday','int'), GETPOST('datepyear','int'));
161  $res = $object->update_date($datepaye);
162  if ($res === 0)
163  {
164  setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
165  }
166  else
167  {
168  setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
169  }
170 }
171 
172 
173 /*
174  * View
175  */
176 
177 llxHeader('', $langs->trans("Payment"));
178 
179 $thirdpartystatic=new Societe($db);
180 
181 $result=$object->fetch($id, $ref);
182 if ($result <= 0)
183 {
184  dol_print_error($db,'Payement '.$id.' not found in database');
185  exit;
186 }
187 
188 $form = new Form($db);
189 
190 $head = payment_prepare_head($object);
191 
192 dol_fiche_head($head, 'payment', $langs->trans("PaymentCustomerInvoice"), -1, 'payment');
193 
194 // Confirmation de la suppression du paiement
195 if ($action == 'delete')
196 {
197  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
198 }
199 
200 // Confirmation de la validation du paiement
201 if ($action == 'valide')
202 {
203  $facid = $_GET['facid'];
204  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
205 }
206 
207 $linkback = '<a href="' . DOL_URL_ROOT . '/compta/paiement/list.php">' . $langs->trans("BackToList") . '</a>';
208 
209 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
210 
211 
212 print '<div class="fichecenter">';
213 print '<div class="underbanner clearboth"></div>';
214 
215 print '<table class="border centpercent">'."\n";
216 
217 // Date payment
218 print '<tr><td class="titlefield">'.$form->editfieldkey("Date",'datep',$object->date,$object,$user->rights->facture->paiement).'</td><td>';
219 print $form->editfieldval("Date", 'datep', $object->date, $object,$user->rights->facture->paiement, 'datehourpicker', '', null, $langs->trans('PaymentDateUpdateSucceeded'));
220 print '</td></tr>';
221 
222 // Payment type (VIR, LIQ, ...)
223 $labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->type_libelle;
224 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>'.$labeltype;
225 print $object->num_paiement?' - '.$object->num_paiement:'';
226 print '</td></tr>';
227 
228 // Amount
229 print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount,'',$langs,0,-1,-1,$conf->currency).'</td></tr>';
230 
231 $disable_delete = 0;
232 // Bank account
233 if (! empty($conf->banque->enabled))
234 {
235  $bankline=new AccountLine($db);
236 
237  if ($object->fk_account > 0)
238  {
239  $bankline->fetch($object->bank_line);
240  if ($bankline->rappro)
241  {
242  $disable_delete = 1;
243  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
244  }
245 
246  print '<tr>';
247  print '<td>'.$langs->trans('BankAccount').'</td>';
248  print '<td>';
249  $accountstatic=new Account($db);
250  $accountstatic->fetch($bankline->fk_account);
251  print $accountstatic->getNomUrl(1);
252  print '</td>';
253  print '</tr>';
254  }
255 }
256 
257 // Payment numero
258 /*
259 $titlefield=$langs->trans('Numero').' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
260 print '<tr><td>'.$form->editfieldkey($titlefield,'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
261 print $form->editfieldval($titlefield,'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
262 print '</td></tr>';
263 
264 // Check transmitter
265 $titlefield=$langs->trans('CheckTransmitter').' <em>('.$langs->trans("ChequeMaker").')</em>';
266 print '<tr><td>'.$form->editfieldkey($titlefield,'chqemetteur',$object->,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
267 print $form->editfieldval($titlefield,'chqemetteur',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('ChequeMakeUpdateSucceeded'));
268 print '</td></tr>';
269 
270 // Bank name
271 $titlefield=$langs->trans('Bank').' <em>('.$langs->trans("ChequeBank").')</em>';
272 print '<tr><td>'.$form->editfieldkey($titlefield,'chqbank',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
273 print $form->editfieldval($titlefield,'chqbank',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('ChequeBankUpdateSucceeded'));
274 print '</td></tr>';
275 */
276 
277 // Bank account
278 if (! empty($conf->banque->enabled))
279 {
280  if ($object->fk_account > 0)
281  {
282  if ($object->type_code == 'CHQ' && $bankline->fk_bordereau > 0)
283  {
284  dol_include_once('/compta/paiement/cheque/class/remisecheque.class.php');
285  $bordereau = new RemiseCheque($db);
286  $bordereau->fetch($bankline->fk_bordereau);
287 
288  print '<tr>';
289  print '<td>'.$langs->trans('CheckReceipt').'</td>';
290  print '<td>';
291  print $bordereau->getNomUrl(1);
292  print '</td>';
293  print '</tr>';
294  }
295  }
296 
297  print '<tr>';
298  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
299  print '<td>';
300  print $bankline->getNomUrl(1,0,'showconciliated');
301  print '</td>';
302  print '</tr>';
303 }
304 
305 // Comments
306 print '<tr><td class="tdtop">'.$form->editfieldkey("Comments",'note',$object->note,$object,$user->rights->facture->paiement).'</td><td>';
307 print $form->editfieldval("Note",'note',$object->note,$object,$user->rights->facture->paiement,'textarea:'.ROWS_3.':90%');
308 print '</td></tr>';
309 
310 print '</table>';
311 
312 print '</div>';
313 
314 dol_fiche_end();
315 
316 
317 /*
318  * List of invoices
319  */
320 
321 $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';
322 $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
323 $sql.= ' WHERE pf.fk_facture = f.rowid';
324 $sql.= ' AND f.fk_soc = s.rowid';
325 $sql.= ' AND f.entity = '.$conf->entity;
326 $sql.= ' AND pf.fk_paiement = '.$object->id;
327 $resql=$db->query($sql);
328 if ($resql)
329 {
330  $num = $db->num_rows($resql);
331 
332  $i = 0;
333  $total = 0;
334 
335  $moreforfilter='';
336 
337  print '<br>';
338 
339  print '<div class="div-table-responsive">';
340  print '<table class="noborder" width="100%">';
341 
342  print '<tr class="liste_titre">';
343  print '<td>'.$langs->trans('Bill').'</td>';
344  print '<td>'.$langs->trans('Company').'</td>';
345  print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
346  print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
347  print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
348  print '<td align="right">'.$langs->trans('Status').'</td>';
349  print "</tr>\n";
350 
351  if ($num > 0)
352  {
353  while ($i < $num)
354  {
355  $objp = $db->fetch_object($resql);
356 
357  $thirdpartystatic->fetch($objp->socid);
358 
359  $invoice=new Facture($db);
360  $invoice->fetch($objp->facid);
361 
362  $paiement = $invoice->getSommePaiement();
363  $creditnotes=$invoice->getSumCreditNotesUsed();
364  $deposits=$invoice->getSumDepositsUsed();
365  $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
366  $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
367 
368  print '<tr class="oddeven">';
369 
370  // Invoice
371  print '<td>';
372  print $invoice->getNomUrl(1);
373  print "</td>\n";
374 
375  // Third party
376  print '<td>';
377  print $thirdpartystatic->getNomUrl(1);
378  print '</td>';
379 
380  // Expected to pay
381  print '<td align="right">'.price($objp->total_ttc).'</td>';
382 
383  // Amount payed
384  print '<td align="right">'.price($objp->amount).'</td>';
385 
386  // Remain to pay
387  print '<td align="right">'.price($remaintopay).'</td>';
388 
389  // Status
390  print '<td align="right">'.$invoice->getLibStatut(5, $alreadypayed).'</td>';
391 
392  print "</tr>\n";
393  if ($objp->paye == 1) // If at least one invoice is paid, disable delete
394  {
395  $disable_delete = 1;
396  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
397  }
398  $total = $total + $objp->amount;
399  $i++;
400  }
401  }
402 
403 
404  print "</table>\n";
405  print '</div>';
406 
407  $db->free($resql);
408 }
409 else
410 {
411  dol_print_error($db);
412 }
413 
414 
415 
416 /*
417  * Boutons Actions
418  */
419 
420 print '<div class="tabsAction">';
421 
422 if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
423 {
424  if ($user->societe_id == 0 && $object->statut == 0 && $_GET['action'] == '')
425  {
426  if ($user->rights->facture->paiement)
427  {
428  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
429  }
430  }
431 }
432 
433 if ($user->societe_id == 0 && $action == '')
434 {
435  if ($user->rights->facture->paiement)
436  {
437  if (! $disable_delete)
438  {
439  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
440  }
441  else
442  {
443  print '<a class="butActionRefused" href="#" title="'.$title_button.'">'.$langs->trans('Delete').'</a>';
444  }
445  }
446 }
447 
448 print '</div>';
449 
450 // End of page
451 llxFooter();
452 $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.
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:1053
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_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...
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.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
if(! function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage payments of customer invoices.
llxHeader()
Empty header.
Definition: wrapper.php:44
Class to manage translations.
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
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...
Class to manage invoices.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage cheque delivery receipts.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.