31require
'../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
36if (isModEnabled(
"banque")) {
37 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
39if (isModEnabled(
'margin')) {
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
44$langs->loadLangs(array(
'bills',
'banks',
'companies'));
48$action =
GETPOST(
'action',
'aZ09');
49$confirm =
GETPOST(
'confirm',
'alpha');
50$backtopage =
GETPOST(
'backtopage',
'alpha');
52$socid =
GETPOST(
'socid',
'int');
59$hookmanager->initHooks(array(
'paymentcard',
'globalcard'));
62include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
64$result =
restrictedArea($user, $object->element, $object->id,
'paiement');
68 $socid = $user->socid;
72if ($socid && $socid != $object->thirdparty->id) {
82if ($action ==
'setnote' && $user->hasRight(
'facture',
'paiement')) {
85 $result = $object->update_note(
GETPOST(
'note',
'restricthtml'));
95if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
98 $result = $object->delete();
103 header(
"Location: ".$backtopage);
106 header(
"Location: list.php");
110 $langs->load(
"errors");
116if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
119 if ($object->validate($user) > 0) {
123 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
124 $outputlangs = $langs;
125 if (
GETPOST(
'lang_id',
'aZ09')) {
127 $outputlangs->setDefaultLang(
GETPOST(
'lang_id',
'aZ09'));
130 $hidedetails = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0;
131 $hidedesc = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0;
132 $hideref = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0;
134 $sql =
'SELECT f.rowid as facid';
135 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
136 $sql .=
' WHERE pf.fk_facture = f.rowid';
137 $sql .=
' AND f.fk_soc = s.rowid';
138 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
139 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
140 $resql = $db->query($sql);
143 $num = $db->num_rows($resql);
147 $objp = $db->fetch_object($resql);
151 if ($invoice->fetch($objp->facid) <= 0) {
157 if ($invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref) < 0) {
175 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
181 $langs->load(
"errors");
186if ($action ==
'setnum_paiement' &&
GETPOST(
'num_paiement') && $user->hasRight(
'facture',
'paiement')) {
187 $res = $object->update_num(
GETPOST(
'num_paiement'));
189 setEventMessages($langs->trans(
'PaymentNumberUpdateSucceeded'),
null,
'mesgs');
191 setEventMessages($langs->trans(
'PaymentNumberUpdateFailed'),
null,
'errors');
195if ($action ==
'setdatep' &&
GETPOST(
'datepday') && $user->hasRight(
'facture',
'paiement')) {
196 $datepaye =
dol_mktime(
GETPOST(
'datephour',
'int'),
GETPOST(
'datepmin',
'int'),
GETPOST(
'datepsec',
'int'),
GETPOST(
'datepmonth',
'int'),
GETPOST(
'datepday',
'int'),
GETPOST(
'datepyear',
'int'));
197 $res = $object->update_date($datepaye);
199 setEventMessages($langs->trans(
'PaymentDateUpdateSucceeded'),
null,
'mesgs');
205if ($action ==
'createbankpayment' && $user->hasRight(
'facture',
'paiement')) {
210 $label =
'(CustomerInvoicePayment)';
212 $label =
'(CustomerInvoicePaymentBack)';
215 $bankaccountid =
GETPOST(
'accountid',
'int');
216 if ($bankaccountid > 0) {
217 $object->paiementcode = $object->type_code;
218 $object->amounts = $object->getAmountsArray();
220 $result = $object->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
226 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
246$thirdpartystatic =
new Societe($db);
248$result = $object->fetch($id, $ref);
254$form =
new Form($db);
256$head = payment_prepare_head($object);
258print
dol_get_fiche_head($head,
'payment', $langs->trans(
"PaymentCustomerInvoice"), -1,
'payment');
261if ($action ==
'delete') {
262 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
"DeletePayment"), $langs->trans(
"ConfirmDeletePayment"),
'confirm_delete',
'', 0, 2);
266if ($action ==
'valide') {
267 $facid = $_GET[
'facid'];
268 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&facid='.$facid, $langs->trans(
"ValidatePayment"), $langs->trans(
"ConfirmValidatePayment"),
'confirm_validate',
'', 0, 2);
271$linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
276print
'<div class="fichecenter">';
277print
'<div class="underbanner clearboth"></div>';
279print
'<table class="border centpercent">'.
"\n";
282print
'<tr><td class="titlefield">'.$form->editfieldkey(
"Date",
'datep', $object->date, $object, $user->hasRight(
'facture',
'paiement')).
'</td><td>';
283print $form->editfieldval(
"Date",
'datep', $object->date, $object, $user->hasRight(
'facture',
'paiement'),
'datehourpicker',
'',
null, $langs->trans(
'PaymentDateUpdateSucceeded'),
'', 0,
'',
'id',
'tzuser');
287$labeltype = $langs->trans(
"PaymentType".$object->type_code) != (
"PaymentType".$object->type_code) ? $langs->trans(
"PaymentType".$object->type_code) : $object->type_label;
288print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>'.$labeltype;
289print $object->num_payment ?
' - '.$object->num_payment :
'';
293print
'<tr><td>'.$langs->trans(
'Amount').
'</td><td>'.
price($object->amount,
'', $langs, 0, -1, -1, $conf->currency).
'</td></tr>';
297if (isModEnabled(
"banque")) {
300 if ($object->fk_account > 0) {
301 $bankline->fetch($object->bank_line);
302 if ($bankline->rappro) {
304 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemoveConciliatedPayment"));
308 print
'<td>'.$langs->trans(
'BankAccount').
'</td>';
310 $accountstatic =
new Account($db);
311 $accountstatic->fetch($bankline->fk_account);
312 print $accountstatic->getNomUrl(1);
339if (isModEnabled(
"banque")) {
340 if ($object->fk_account > 0) {
341 if ($object->type_code ==
'CHQ' && $bankline->fk_bordereau > 0) {
342 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
344 $bordereau->fetch($bankline->fk_bordereau);
347 print
'<td>'.$langs->trans(
'CheckReceipt').
'</td>';
349 print $bordereau->getNomUrl(1);
356 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
358 if ($object->fk_account > 0) {
359 print $bankline->getNomUrl(1, 0,
'showconciliatedandaccounted');
361 $langs->load(
"admin");
362 print
'<span class="opacitymedium">';
363 print $langs->trans(
"NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv(
"Module85Name"));
365 if ($user->hasRight(
'facture',
'paiement')) {
368 $amountofpayments = $object->getAmountsArray();
369 $bankaccountidofinvoices =
null;
370 foreach ($amountofpayments as $idinvoice => $amountofpayment) {
371 $tmpinvoice =
new Facture($db);
372 $tmpinvoice->fetch($idinvoice);
373 if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
374 if (is_null($bankaccountidofinvoices)) {
375 $bankaccountidofinvoices = $tmpinvoice->fk_account;
376 } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
377 $bankaccountidofinvoices = 0;
382 print
'<form method="POST" name="createbankpayment">';
383 print
'<input type="hidden" name="token" value="'.newToken().
'">';
384 print
'<input type="hidden" name="action" value="createbankpayment">';
385 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
386 print
' '.$langs->trans(
"ToCreateRelatedRecordIntoBank").
': ';
387 print $form->select_comptes($bankaccountidofinvoices,
'accountid', 0,
'', 2,
'', 0,
'', 1);
389 print
'<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans(
"ClickHere").
'">';
399print
'<tr><td class="tdtop">'.$form->editfieldkey(
"Comments",
'note', $object->note, $object, $user->hasRight(
'facture',
'paiement')).
'</td><td>';
400print $form->editfieldval(
"Note",
'note', $object->note, $object, $user->hasRight(
'facture',
'paiement'),
'textarea:'.ROWS_3.
':90%');
414$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';
415$sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
416$sql .=
' WHERE pf.fk_facture = f.rowid';
417$sql .=
' AND f.fk_soc = s.rowid';
418$sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
419$sql .=
' AND pf.fk_paiement = '.((int) $object->id);
420$resql = $db->query($sql);
422 $num = $db->num_rows($resql);
429 print
'<div class="div-table-responsive">';
430 print
'<table class="noborder centpercent">';
432 print
'<tr class="liste_titre">';
433 print
'<td>'.$langs->trans(
'Bill').
'</td>';
434 print
'<td>'.$langs->trans(
'Company').
'</td>';
435 if (isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
436 print
'<td>'.$langs->trans(
'Entity').
'</td>';
439 if (isModEnabled(
'margin') &&
getDolGlobalInt(
'MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
440 print
'<td class="right">'.$langs->trans(
'Margin').
'</td>';
442 print
'<td class="right">'.$langs->trans(
'ExpectedToPay').
'</td>';
443 print
'<td class="right">'.$langs->trans(
'PayedByThisPayment').
'</td>';
444 print
'<td class="right">'.$langs->trans(
'RemainderToPay').
'</td>';
445 print
'<td class="right">'.$langs->trans(
'Status').
'</td>';
450 $objp = $db->fetch_object($resql);
452 $thirdpartystatic->fetch($objp->socid);
455 $invoice->fetch($objp->facid);
458 if (isModEnabled(
'margin') &&
getDolGlobalInt(
'MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
460 $marginInfo = array();
461 $invoice->fetch_lines();
462 $marginInfo = $formmargin->getMarginInfosArray($invoice);
465 $paiement = $invoice->getSommePaiement();
466 $creditnotes = $invoice->getSumCreditNotesUsed();
467 $deposits = $invoice->getSumDepositsUsed();
468 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
469 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
471 print
'<tr class="oddeven">';
475 print $invoice->getNomUrl(1);
479 print
'<td class="tdoverflowmax150">';
480 print $thirdpartystatic->getNomUrl(1);
484 if (isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
486 $mc->getInfo($objp->entity);
492 if (isModEnabled(
'margin') &&
getDolGlobalInt(
'MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
493 print
'<td class="right">'.price($marginInfo[
'total_margin']).
'</td>';
497 print
'<td class="right"><span class="amount">'.price($objp->total_ttc).
'</span></td>';
500 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
503 print
'<td class="right"><span class="amount">'.price($remaintopay).
'</span></td>';
506 print
'<td class="right">'.$invoice->getLibStatut(5, $alreadypayed).
'</td>';
511 if ($objp->paye == 1 && empty($conf->global->INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED)) {
513 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemovePaymentWithOneInvoicePaid"));
516 $total = $total + $objp->amount;
536print
'<div class="tabsAction">';
538if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
539 if ($user->socid == 0 && $object->statut == 0 && $action ==
'') {
540 if ($user->hasRight(
'facture',
'paiement')) {
541 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&action=valide&token='.newToken().
'">'.$langs->trans(
'Valid').
'</a>';
547if (! empty($title_button)) {
548 $params[
'attr'] = array(
'title' => $title_button);
551if ($user->socid == 0 && $action ==
'') {
552 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.newToken(),
'delete', $user->hasRight(
'facture',
'paiement') && !$disable_delete, $params);
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage bank transaction lines.
Class to manage invoices.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage payments of customer invoices.
Class to manage cheque delivery receipts.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
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.
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...
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.