31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
41 $langs->loadLangs(array(
'bills',
'banks',
'companies'));
45 $action =
GETPOST(
'action',
'aZ09');
46 $confirm =
GETPOST(
'confirm',
'alpha');
47 $backtopage =
GETPOST(
'backtopage',
'alpha');
51 $hookmanager->initHooks(array(
'paymentcard',
'globalcard'));
54 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
56 $result =
restrictedArea($user, $object->element, $object->id,
'paiement');
60 $socid = $user->socid;
64 if ($socid && $socid != $object->thirdparty->id) {
74 if ($action ==
'setnote' && $user->hasRight(
'facture',
'paiement')) {
77 $result = $object->update_note(
GETPOST(
'note',
'restricthtml'));
87 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
90 $result = $object->delete();
95 header(
"Location: ".$backtopage);
98 header(
"Location: list.php");
102 $langs->load(
"errors");
108 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
111 if ($object->validate($user) > 0) {
115 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
116 $outputlangs = $langs;
117 if (
GETPOST(
'lang_id',
'aZ09')) {
119 $outputlangs->setDefaultLang(
GETPOST(
'lang_id',
'aZ09'));
122 $hidedetails = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0;
123 $hidedesc = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0;
124 $hideref = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0;
126 $sql =
'SELECT f.rowid as facid';
127 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
128 $sql .=
' WHERE pf.fk_facture = f.rowid';
129 $sql .=
' AND f.fk_soc = s.rowid';
130 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
131 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
132 $resql = $db->query($sql);
135 $num = $db->num_rows(
$resql);
139 $objp = $db->fetch_object(
$resql);
143 if ($invoice->fetch($objp->facid) <= 0) {
149 if ($invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref) < 0) {
167 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
173 $langs->load(
"errors");
178 if ($action ==
'setnum_paiement' &&
GETPOST(
'num_paiement') && $user->hasRight(
'facture',
'paiement')) {
179 $res = $object->update_num(
GETPOST(
'num_paiement'));
181 setEventMessages($langs->trans(
'PaymentNumberUpdateSucceeded'),
null,
'mesgs');
183 setEventMessages($langs->trans(
'PaymentNumberUpdateFailed'),
null,
'errors');
187 if ($action ==
'setdatep' &&
GETPOST(
'datepday') && $user->hasRight(
'facture',
'paiement')) {
188 $datepaye =
dol_mktime(
GETPOST(
'datephour',
'int'),
GETPOST(
'datepmin',
'int'),
GETPOST(
'datepsec',
'int'),
GETPOST(
'datepmonth',
'int'),
GETPOST(
'datepday',
'int'),
GETPOST(
'datepyear',
'int'));
189 $res = $object->update_date($datepaye);
191 setEventMessages($langs->trans(
'PaymentDateUpdateSucceeded'),
null,
'mesgs');
197 if ($action ==
'createbankpayment' && $user->hasRight(
'facture',
'paiement')) {
202 $label =
'(CustomerInvoicePayment)';
204 $label =
'(CustomerInvoicePaymentBack)';
207 $bankaccountid =
GETPOST(
'accountid',
'int');
208 if ($bankaccountid > 0) {
209 $object->paiementcode = $object->type_code;
210 $object->amounts = $object->getAmountsArray();
212 $result = $object->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
218 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
238 $thirdpartystatic =
new Societe($db);
240 $result = $object->fetch($id, $ref);
248 $head = payment_prepare_head($object);
250 print
dol_get_fiche_head($head,
'payment', $langs->trans(
"PaymentCustomerInvoice"), -1,
'payment');
253 if ($action ==
'delete') {
254 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
"DeletePayment"), $langs->trans(
"ConfirmDeletePayment"),
'confirm_delete',
'', 0, 2);
258 if ($action ==
'valide') {
259 $facid = $_GET[
'facid'];
260 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&facid='.$facid, $langs->trans(
"ValidatePayment"), $langs->trans(
"ConfirmValidatePayment"),
'confirm_validate',
'', 0, 2);
263 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
268 print
'<div class="fichecenter">';
269 print
'<div class="underbanner clearboth"></div>';
271 print
'<table class="border centpercent">'.
"\n";
274 print
'<tr><td class="titlefield">'.$form->editfieldkey(
"Date",
'datep', $object->date, $object, $user->rights->facture->paiement).
'</td><td>';
275 print
$form->editfieldval(
"Date",
'datep', $object->date, $object, $user->rights->facture->paiement,
'datehourpicker',
'',
null, $langs->trans(
'PaymentDateUpdateSucceeded'),
'', 0,
'',
'id',
'tzuser');
279 $labeltype = $langs->trans(
"PaymentType".$object->type_code) != (
"PaymentType".$object->type_code) ? $langs->trans(
"PaymentType".$object->type_code) : $object->type_label;
280 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>'.$labeltype;
281 print $object->num_payment ?
' - '.$object->num_payment :
'';
285 print
'<tr><td>'.$langs->trans(
'Amount').
'</td><td>'.
price($object->amount,
'', $langs, 0, -1, -1, $conf->currency).
'</td></tr>';
292 if ($object->fk_account > 0) {
293 $bankline->fetch($object->bank_line);
294 if ($bankline->rappro) {
296 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemoveConciliatedPayment"));
300 print
'<td>'.$langs->trans(
'BankAccount').
'</td>';
302 $accountstatic =
new Account($db);
303 $accountstatic->fetch($bankline->fk_account);
304 print $accountstatic->getNomUrl(1);
332 if ($object->fk_account > 0) {
333 if ($object->type_code ==
'CHQ' && $bankline->fk_bordereau > 0) {
334 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
336 $bordereau->fetch($bankline->fk_bordereau);
339 print
'<td>'.$langs->trans(
'CheckReceipt').
'</td>';
341 print $bordereau->getNomUrl(1);
348 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
350 if ($object->fk_account > 0) {
351 print $bankline->getNomUrl(1, 0,
'showconciliatedandaccounted');
353 $langs->load(
"admin");
354 print
'<span class="opacitymedium">';
355 print $langs->trans(
"NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv(
"Module85Name"));
357 if (!empty($user->rights->facture->paiement)) {
360 $amountofpayments = $object->getAmountsArray();
361 $bankaccountidofinvoices =
null;
362 foreach ($amountofpayments as $idinvoice => $amountofpayment) {
363 $tmpinvoice =
new Facture($db);
364 $tmpinvoice->fetch($idinvoice);
365 if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
366 if (is_null($bankaccountidofinvoices)) {
367 $bankaccountidofinvoices = $tmpinvoice->fk_account;
368 } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
369 $bankaccountidofinvoices = 0;
374 print
'<form method="POST" name="createbankpayment">';
375 print
'<input type="hidden" name="token" value="'.newToken().
'">';
376 print
'<input type="hidden" name="action" value="createbankpayment">';
377 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
378 print
' '.$langs->trans(
"ToCreateRelatedRecordIntoBank").
': ';
379 print
$form->select_comptes($bankaccountidofinvoices,
'accountid', 0,
'', 2,
'', 0,
'', 1);
381 print
'<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans(
"ClickHere").
'">';
391 print
'<tr><td class="tdtop">'.$form->editfieldkey(
"Comments",
'note', $object->note, $object, $user->rights->facture->paiement).
'</td><td>';
392 print
$form->editfieldval(
"Note",
'note', $object->note, $object, $user->rights->facture->paiement,
'textarea:'.ROWS_3.
':90%');
406 $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';
407 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
408 $sql .=
' WHERE pf.fk_facture = f.rowid';
409 $sql .=
' AND f.fk_soc = s.rowid';
410 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
411 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
412 $resql = $db->query($sql);
414 $num = $db->num_rows(
$resql);
421 print
'<div class="div-table-responsive">';
422 print
'<table class="noborder centpercent">';
424 print
'<tr class="liste_titre">';
425 print
'<td>'.$langs->trans(
'Bill').
'</td>';
426 print
'<td>'.$langs->trans(
'Company').
'</td>';
427 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
428 print
'<td>'.$langs->trans(
'Entity').
'</td>';
430 print
'<td class="right">'.$langs->trans(
'ExpectedToPay').
'</td>';
431 print
'<td class="right">'.$langs->trans(
'PayedByThisPayment').
'</td>';
432 print
'<td class="right">'.$langs->trans(
'RemainderToPay').
'</td>';
433 print
'<td class="right">'.$langs->trans(
'Status').
'</td>';
438 $objp = $db->fetch_object(
$resql);
440 $thirdpartystatic->fetch($objp->socid);
443 $invoice->fetch($objp->facid);
445 $paiement = $invoice->getSommePaiement();
446 $creditnotes = $invoice->getSumCreditNotesUsed();
447 $deposits = $invoice->getSumDepositsUsed();
448 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
449 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
451 print
'<tr class="oddeven">';
455 print $invoice->getNomUrl(1);
459 print
'<td class="tdoverflowmax150">';
460 print $thirdpartystatic->getNomUrl(1);
464 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
466 $mc->getInfo($objp->entity);
471 print
'<td class="right"><span class="amount">'.price($objp->total_ttc).
'</span></td>';
474 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
477 print
'<td class="right"><span class="amount">'.price($remaintopay).
'</span></td>';
480 print
'<td class="right">'.$invoice->getLibStatut(5, $alreadypayed).
'</td>';
485 if ($objp->paye == 1 && empty($conf->global->INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED)) {
487 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemovePaymentWithOneInvoicePaid"));
490 $total = $total + $objp->amount;
510 print
'<div class="tabsAction">';
512 if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
513 if ($user->socid == 0 && $object->statut == 0 && $action ==
'') {
514 if ($user->rights->facture->paiement) {
515 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&action=valide&token='.
newToken().
'">'.$langs->trans(
'Valid').
'</a>';
520 if ($user->socid == 0 && $action ==
'') {
521 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'delete', $user->rights->facture->paiement && !$disable_delete);
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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='')
Show tabs of a record.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.