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');
49 $socid =
GETPOST(
'socid',
'int');
if ($socid < 0) {
55 $hookmanager->initHooks(array(
'paymentcard',
'globalcard'));
58 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
60 $result =
restrictedArea($user, $object->element, $object->id,
'paiement');
64 $socid = $user->socid;
68 if ($socid && $socid != $object->thirdparty->id) {
78 if ($action ==
'setnote' && $user->hasRight(
'facture',
'paiement')) {
81 $result = $object->update_note(
GETPOST(
'note',
'restricthtml'));
91 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->rights->facture->paiement) {
94 $result = $object->delete();
99 header(
"Location: ".$backtopage);
102 header(
"Location: list.php");
106 $langs->load(
"errors");
112 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->rights->facture->paiement) {
115 if ($object->validate($user) > 0) {
119 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
120 $outputlangs = $langs;
121 if (
GETPOST(
'lang_id',
'aZ09')) {
123 $outputlangs->setDefaultLang(
GETPOST(
'lang_id',
'aZ09'));
126 $hidedetails = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0;
127 $hidedesc = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0;
128 $hideref = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0;
130 $sql =
'SELECT f.rowid as facid';
131 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
132 $sql .=
' WHERE pf.fk_facture = f.rowid';
133 $sql .=
' AND f.fk_soc = s.rowid';
134 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
135 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
136 $resql = $db->query($sql);
139 $num = $db->num_rows(
$resql);
143 $objp = $db->fetch_object(
$resql);
147 if ($invoice->fetch($objp->facid) <= 0) {
153 if ($invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref) < 0) {
171 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
177 $langs->load(
"errors");
182 if ($action ==
'setnum_paiement' &&
GETPOST(
'num_paiement')) {
183 $res = $object->update_num(
GETPOST(
'num_paiement'));
185 setEventMessages($langs->trans(
'PaymentNumberUpdateSucceeded'),
null,
'mesgs');
187 setEventMessages($langs->trans(
'PaymentNumberUpdateFailed'),
null,
'errors');
191 if ($action ==
'setdatep' &&
GETPOST(
'datepday')) {
192 $datepaye =
dol_mktime(
GETPOST(
'datephour',
'int'),
GETPOST(
'datepmin',
'int'),
GETPOST(
'datepsec',
'int'),
GETPOST(
'datepmonth',
'int'),
GETPOST(
'datepday',
'int'),
GETPOST(
'datepyear',
'int'));
193 $res = $object->update_date($datepaye);
195 setEventMessages($langs->trans(
'PaymentDateUpdateSucceeded'),
null,
'mesgs');
200 if ($action ==
'createbankpayment' && !empty($user->rights->facture->paiement)) {
205 $label =
'(CustomerInvoicePayment)';
207 $label =
'(CustomerInvoicePaymentBack)';
210 $bankaccountid =
GETPOST(
'accountid',
'int');
211 if ($bankaccountid > 0) {
212 $object->paiementcode = $object->type_code;
213 $object->amounts = $object->getAmountsArray();
215 $result = $object->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
221 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
241 $thirdpartystatic =
new Societe($db);
243 $result = $object->fetch($id, $ref);
251 $head = payment_prepare_head($object);
253 print
dol_get_fiche_head($head,
'payment', $langs->trans(
"PaymentCustomerInvoice"), -1,
'payment');
256 if ($action ==
'delete') {
257 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
"DeletePayment"), $langs->trans(
"ConfirmDeletePayment"),
'confirm_delete',
'', 0, 2);
261 if ($action ==
'valide') {
262 $facid = $_GET[
'facid'];
263 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&facid='.$facid, $langs->trans(
"ValidatePayment"), $langs->trans(
"ConfirmValidatePayment"),
'confirm_validate',
'', 0, 2);
266 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
271 print
'<div class="fichecenter">';
272 print
'<div class="underbanner clearboth"></div>';
274 print
'<table class="border centpercent">'.
"\n";
277 print
'<tr><td class="titlefield">'.$form->editfieldkey(
"Date",
'datep', $object->date, $object, $user->rights->facture->paiement).
'</td><td>';
278 print
$form->editfieldval(
"Date",
'datep', $object->date, $object, $user->rights->facture->paiement,
'datehourpicker',
'',
null, $langs->trans(
'PaymentDateUpdateSucceeded'),
'', 0,
'',
'id',
'tzuser');
282 $labeltype = $langs->trans(
"PaymentType".$object->type_code) != (
"PaymentType".$object->type_code) ? $langs->trans(
"PaymentType".$object->type_code) : $object->type_label;
283 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>'.$labeltype;
284 print $object->num_payment ?
' - '.$object->num_payment :
'';
288 print
'<tr><td>'.$langs->trans(
'Amount').
'</td><td>'.
price($object->amount,
'', $langs, 0, -1, -1, $conf->currency).
'</td></tr>';
295 if ($object->fk_account > 0) {
296 $bankline->fetch($object->bank_line);
297 if ($bankline->rappro) {
299 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemoveConciliatedPayment"));
303 print
'<td>'.$langs->trans(
'BankAccount').
'</td>';
305 $accountstatic =
new Account($db);
306 $accountstatic->fetch($bankline->fk_account);
307 print $accountstatic->getNomUrl(1);
335 if ($object->fk_account > 0) {
336 if ($object->type_code ==
'CHQ' && $bankline->fk_bordereau > 0) {
337 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
339 $bordereau->fetch($bankline->fk_bordereau);
342 print
'<td>'.$langs->trans(
'CheckReceipt').
'</td>';
344 print $bordereau->getNomUrl(1);
351 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
353 if ($object->fk_account > 0) {
354 print $bankline->getNomUrl(1, 0,
'showconciliatedandaccounted');
356 $langs->load(
"admin");
357 print
'<span class="opacitymedium">';
358 print $langs->trans(
"NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv(
"Module85Name"));
360 if (!empty($user->rights->facture->paiement)) {
363 $amountofpayments = $object->getAmountsArray();
364 $bankaccountidofinvoices =
null;
365 foreach ($amountofpayments as $idinvoice => $amountofpayment) {
366 $tmpinvoice =
new Facture($db);
367 $tmpinvoice->fetch($idinvoice);
368 if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
369 if (is_null($bankaccountidofinvoices)) {
370 $bankaccountidofinvoices = $tmpinvoice->fk_account;
371 } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
372 $bankaccountidofinvoices = 0;
377 print
'<form method="POST" name="createbankpayment">';
378 print
'<input type="hidden" name="token" value="'.newToken().
'">';
379 print
'<input type="hidden" name="action" value="createbankpayment">';
380 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
381 print
' '.$langs->trans(
"ToCreateRelatedRecordIntoBank").
': ';
382 print
$form->select_comptes($bankaccountidofinvoices,
'accountid', 0,
'', 2,
'', 0,
'', 1);
384 print
'<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans(
"ClickHere").
'">';
394 print
'<tr><td class="tdtop">'.$form->editfieldkey(
"Comments",
'note', $object->note, $object, $user->rights->facture->paiement).
'</td><td>';
395 print
$form->editfieldval(
"Note",
'note', $object->note, $object, $user->rights->facture->paiement,
'textarea:'.ROWS_3.
':90%');
409 $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';
410 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
411 $sql .=
' WHERE pf.fk_facture = f.rowid';
412 $sql .=
' AND f.fk_soc = s.rowid';
413 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
414 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
415 $resql = $db->query($sql);
417 $num = $db->num_rows(
$resql);
426 print
'<div class="div-table-responsive">';
427 print
'<table class="noborder centpercent">';
429 print
'<tr class="liste_titre">';
430 print
'<td>'.$langs->trans(
'Bill').
'</td>';
431 print
'<td>'.$langs->trans(
'Company').
'</td>';
432 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
433 print
'<td>'.$langs->trans(
'Entity').
'</td>';
435 print
'<td class="right">'.$langs->trans(
'ExpectedToPay').
'</td>';
436 print
'<td class="right">'.$langs->trans(
'PayedByThisPayment').
'</td>';
437 print
'<td class="right">'.$langs->trans(
'RemainderToPay').
'</td>';
438 print
'<td class="right">'.$langs->trans(
'Status').
'</td>';
443 $objp = $db->fetch_object(
$resql);
445 $thirdpartystatic->fetch($objp->socid);
448 $invoice->fetch($objp->facid);
450 $paiement = $invoice->getSommePaiement();
451 $creditnotes = $invoice->getSumCreditNotesUsed();
452 $deposits = $invoice->getSumDepositsUsed();
453 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
454 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
456 print
'<tr class="oddeven">';
460 print $invoice->getNomUrl(1);
464 print
'<td class="tdoverflowmax150">';
465 print $thirdpartystatic->getNomUrl(1);
469 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
471 $mc->getInfo($objp->entity);
476 print
'<td class="right"><span class="amount">'.price($objp->total_ttc).
'</span></td>';
479 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
482 print
'<td class="right"><span class="amount">'.price($remaintopay).
'</span></td>';
485 print
'<td class="right">'.$invoice->getLibStatut(5, $alreadypayed).
'</td>';
490 if ($objp->paye == 1 && empty($conf->global->INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED)) {
492 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemovePaymentWithOneInvoicePaid"));
495 $total = $total + $objp->amount;
515 print
'<div class="tabsAction">';
517 if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
518 if ($user->socid == 0 && $object->statut == 0 && $_GET[
'action'] ==
'') {
519 if ($user->rights->facture->paiement) {
520 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&facid='.$objp->facid.
'&action=valide&token='.
newToken().
'">'.$langs->trans(
'Valid').
'</a>';
526 if (! empty($title_button)) {
527 $params[
'attr'] = array(
'title' => $title_button);
530 if ($user->socid == 0 && $action ==
'') {
531 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'delete', $user->rights->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.
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.