dolibarr  13.0.2
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 <https://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', 'aZ09');
43 $confirm = GETPOST('confirm', 'alpha');
44 $backtopage = GETPOST('backtopage', 'alpha');
45 
46 $object = new Paiement($db);
47 
48 // Load object
49 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
50 
51 $result = restrictedArea($user, $object->element, $object->id, 'paiement', '');
52 
53 // Security check
54 if ($user->socid) $socid = $user->socid;
55 // Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
56 // It should be enough because all payments are done on invoices of the same thirdparty.
57 if ($socid && $socid != $object->thirdparty->id) {
59 }
60 
61 
62 /*
63  * Actions
64  */
65 
66 if ($action == 'setnote' && $user->rights->facture->paiement)
67 {
68  $db->begin();
69 
70  $result = $object->update_note(GETPOST('note', 'restricthtml'));
71  if ($result > 0)
72  {
73  $db->commit();
74  $action = '';
75  } else {
76  setEventMessages($object->error, $object->errors, 'errors');
77  $db->rollback();
78  }
79 }
80 
81 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->paiement)
82 {
83  $db->begin();
84 
85  $result = $object->delete();
86  if ($result > 0)
87  {
88  $db->commit();
89 
90  if ($backtopage)
91  {
92  header("Location: ".$backtopage);
93  exit;
94  } else {
95  header("Location: list.php");
96  exit;
97  }
98  } else {
99  $langs->load("errors");
100  setEventMessages($object->error, $object->errors, 'errors');
101  $db->rollback();
102  }
103 }
104 
105 if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->facture->paiement)
106 {
107  $db->begin();
108 
109  if ($object->validate($user) > 0)
110  {
111  $db->commit();
112 
113  // Loop on each invoice linked to this payment to rebuild PDF
114  $factures = array();
115  foreach ($factures as $id)
116  {
117  $fac = new Facture($db);
118  $fac->fetch($id);
119 
120  $outputlangs = $langs;
121  if (!empty($_REQUEST['lang_id']))
122  {
123  $outputlangs = new Translate("", $conf);
124  $outputlangs->setDefaultLang($_REQUEST['lang_id']);
125  }
126  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
127  $fac->generateDocument($fac->modelpdf, $outputlangs);
128  }
129  }
130 
131  header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
132  exit;
133  } else {
134  $langs->load("errors");
135  setEventMessages($object->error, $object->errors, 'errors');
136  $db->rollback();
137  }
138 }
139 
140 if ($action == 'setnum_paiement' && !empty($_POST['num_paiement']))
141 {
142  $res = $object->update_num($_POST['num_paiement']);
143  if ($res === 0)
144  {
145  setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
146  } else {
147  setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
148  }
149 }
150 
151 if ($action == 'setdatep' && !empty($_POST['datepday']))
152 {
153  $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'));
154  $res = $object->update_date($datepaye);
155  if ($res === 0)
156  {
157  setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
158  } else {
159  setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
160  }
161 }
162 
163 
164 /*
165  * View
166  */
167 
168 llxHeader('', $langs->trans("Payment"));
169 
170 $thirdpartystatic = new Societe($db);
171 
172 $result = $object->fetch($id, $ref);
173 if ($result <= 0)
174 {
175  dol_print_error($db, 'Payement '.$id.' not found in database');
176  exit;
177 }
178 
179 $form = new Form($db);
180 
181 $head = payment_prepare_head($object);
182 
183 print dol_get_fiche_head($head, 'payment', $langs->trans("PaymentCustomerInvoice"), -1, 'payment');
184 
185 // Confirmation of payment delete
186 if ($action == 'delete')
187 {
188  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
189 }
190 
191 // Confirmation of payment validation
192 if ($action == 'valide')
193 {
194  $facid = $_GET['facid'];
195  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_validate', '', 0, 2);
196 }
197 
198 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
199 
200 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
201 
202 
203 print '<div class="fichecenter">';
204 print '<div class="underbanner clearboth"></div>';
205 
206 print '<table class="border centpercent">'."\n";
207 
208 // Date payment
209 print '<tr><td class="titlefield">'.$form->editfieldkey("Date", 'datep', $object->date, $object, $user->rights->facture->paiement).'</td><td>';
210 print $form->editfieldval("Date", 'datep', $object->date, $object, $user->rights->facture->paiement, 'datehourpicker', '', null, $langs->trans('PaymentDateUpdateSucceeded'));
211 print '</td></tr>';
212 
213 // Payment type (VIR, LIQ, ...)
214 $labeltype = $langs->trans("PaymentType".$object->type_code) != ("PaymentType".$object->type_code) ? $langs->trans("PaymentType".$object->type_code) : $object->type_label;
215 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>'.$labeltype;
216 print $object->num_payment ? ' - '.$object->num_payment : '';
217 print '</td></tr>';
218 
219 // Amount
220 print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, '', $langs, 0, -1, -1, $conf->currency).'</td></tr>';
221 
222 $disable_delete = 0;
223 // Bank account
224 if (!empty($conf->banque->enabled))
225 {
226  $bankline = new AccountLine($db);
227 
228  if ($object->fk_account > 0)
229  {
230  $bankline->fetch($object->bank_line);
231  if ($bankline->rappro)
232  {
233  $disable_delete = 1;
234  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
235  }
236 
237  print '<tr>';
238  print '<td>'.$langs->trans('BankAccount').'</td>';
239  print '<td>';
240  $accountstatic = new Account($db);
241  $accountstatic->fetch($bankline->fk_account);
242  print $accountstatic->getNomUrl(1);
243  print '</td>';
244  print '</tr>';
245  }
246 }
247 
248 // Payment numero
249 /*
250 $titlefield=$langs->trans('Numero').' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
251 print '<tr><td>'.$form->editfieldkey($titlefield,'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
252 print $form->editfieldval($titlefield,'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
253 print '</td></tr>';
254 
255 // Check transmitter
256 $titlefield=$langs->trans('CheckTransmitter').' <em>('.$langs->trans("ChequeMaker").')</em>';
257 print '<tr><td>'.$form->editfieldkey($titlefield,'chqemetteur',$object->,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
258 print $form->editfieldval($titlefield,'chqemetteur',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('ChequeMakeUpdateSucceeded'));
259 print '</td></tr>';
260 
261 // Bank name
262 $titlefield=$langs->trans('Bank').' <em>('.$langs->trans("ChequeBank").')</em>';
263 print '<tr><td>'.$form->editfieldkey($titlefield,'chqbank',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
264 print $form->editfieldval($titlefield,'chqbank',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('ChequeBankUpdateSucceeded'));
265 print '</td></tr>';
266 */
267 
268 // Bank account
269 if (!empty($conf->banque->enabled))
270 {
271  if ($object->fk_account > 0) {
272  if ($object->type_code == 'CHQ' && $bankline->fk_bordereau > 0) {
273  dol_include_once('/compta/paiement/cheque/class/remisecheque.class.php');
274  $bordereau = new RemiseCheque($db);
275  $bordereau->fetch($bankline->fk_bordereau);
276 
277  print '<tr>';
278  print '<td>'.$langs->trans('CheckReceipt').'</td>';
279  print '<td>';
280  print $bordereau->getNomUrl(1);
281  print '</td>';
282  print '</tr>';
283  }
284  }
285 
286  print '<tr>';
287  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
288  print '<td>';
289  if ($object->fk_account > 0) {
290  print $bankline->getNomUrl(1, 0, 'showconciliatedandaccounted');
291  } else {
292  $langs->load("admin");
293  print '<span class="opacitymedium">'.$langs->trans("NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv("Module85Name")).'</span>';
294  }
295  print '</td>';
296  print '</tr>';
297 }
298 
299 // Comments
300 print '<tr><td class="tdtop">'.$form->editfieldkey("Comments", 'note', $object->note, $object, $user->rights->facture->paiement).'</td><td>';
301 print $form->editfieldval("Note", 'note', $object->note, $object, $user->rights->facture->paiement, 'textarea:'.ROWS_3.':90%');
302 print '</td></tr>';
303 
304 print '</table>';
305 
306 print '</div>';
307 
309 
310 
311 /*
312  * List of invoices
313  */
314 
315 $sql = 'SELECT f.rowid as facid, f.ref, f.type, f.total_ttc, f.paye, f.entity, f.fk_statut, pf.amount, s.nom as name, s.rowid as socid';
316 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
317 $sql .= ' WHERE pf.fk_facture = f.rowid';
318 $sql .= ' AND f.fk_soc = s.rowid';
319 $sql .= ' AND f.entity IN ('.getEntity('invoice').')';
320 $sql .= ' AND pf.fk_paiement = '.$object->id;
321 $resql = $db->query($sql);
322 if ($resql)
323 {
324  $num = $db->num_rows($resql);
325 
326  $i = 0;
327  $total = 0;
328 
329  $moreforfilter = '';
330 
331  print '<br>';
332 
333  print '<div class="div-table-responsive">';
334  print '<table class="noborder centpercent">';
335 
336  print '<tr class="liste_titre">';
337  print '<td>'.$langs->trans('Bill').'</td>';
338  print '<td>'.$langs->trans('Company').'</td>';
339  if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) print '<td>'.$langs->trans('Entity').'</td>';
340  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
341  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
342  print '<td class="right">'.$langs->trans('RemainderToPay').'</td>';
343  print '<td class="right">'.$langs->trans('Status').'</td>';
344  print "</tr>\n";
345 
346  if ($num > 0)
347  {
348  while ($i < $num)
349  {
350  $objp = $db->fetch_object($resql);
351 
352  $thirdpartystatic->fetch($objp->socid);
353 
354  $invoice = new Facture($db);
355  $invoice->fetch($objp->facid);
356 
357  $paiement = $invoice->getSommePaiement();
358  $creditnotes = $invoice->getSumCreditNotesUsed();
359  $deposits = $invoice->getSumDepositsUsed();
360  $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
361  $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
362 
363  print '<tr class="oddeven">';
364 
365  // Invoice
366  print '<td>';
367  print $invoice->getNomUrl(1);
368  print "</td>\n";
369 
370  // Third party
371  print '<td>';
372  print $thirdpartystatic->getNomUrl(1);
373  print '</td>';
374 
375  // Expected to pay
376  if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
377  print '<td>';
378  $mc->getInfo($objp->entity);
379  print $mc->label;
380  print '</td>';
381  }
382  // Expected to pay
383  print '<td class="right">'.price($objp->total_ttc).'</td>';
384 
385  // Amount payed
386  print '<td class="right">'.price($objp->amount).'</td>';
387 
388  // Remain to pay
389  print '<td class="right">'.price($remaintopay).'</td>';
390 
391  // Status
392  print '<td class="right">'.$invoice->getLibStatut(5, $alreadypayed).'</td>';
393 
394  print "</tr>\n";
395  if ($objp->paye == 1) // If at least one invoice is paid, disable delete
396  {
397  $disable_delete = 1;
398  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
399  }
400  $total = $total + $objp->amount;
401  $i++;
402  }
403  }
404 
405 
406  print "</table>\n";
407  print '</div>';
408 
409  $db->free($resql);
410 } else {
411  dol_print_error($db);
412 }
413 
414 
415 
416 /*
417  * Actions Buttons
418  */
419 
420 print '<div class="tabsAction">';
421 
422 if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
423 {
424  if ($user->socid == 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->socid == 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  } else {
441  print '<a class="butActionRefused classfortooltip" href="#" title="'.$title_button.'">'.$langs->trans('Delete').'</a>';
442  }
443  }
444 }
445 
446 print '</div>';
447 
448 // End of page
449 llxFooter();
450 $db->close();
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage bank transaction lines.
Class to manage bank accounts.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage payments of customer invoices.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage translations.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage invoices.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
Class to manage cheque delivery receipts.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...