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) {
77if (isModEnabled(
'stripe')) {
78 require_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
80 $service =
'StripeTest';
83 $service =
'StripeLive';
88 global $stripearrayofkeysbyenv;
89 $site_account = $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
92 $stripeacc = $stripe->getStripeAccount($service);
100$parameters = array(
'socid'=>$socid);
101$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
106if (empty($reshook)) {
107 if ($action ==
'setnote' && $user->hasRight(
'facture',
'paiement')) {
110 $result = $object->update_note(
GETPOST(
'note',
'restricthtml'));
120 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
123 $result = $object->delete();
128 header(
"Location: ".$backtopage);
131 header(
"Location: list.php");
135 $langs->load(
"errors");
141 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
144 if ($object->validate($user) > 0) {
149 $outputlangs = $langs;
150 if (
GETPOST(
'lang_id',
'aZ09')) {
152 $outputlangs->setDefaultLang(
GETPOST(
'lang_id',
'aZ09'));
159 $sql =
'SELECT f.rowid as facid';
160 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
161 $sql .=
' WHERE pf.fk_facture = f.rowid';
162 $sql .=
' AND f.fk_soc = s.rowid';
163 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
164 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
165 $resql = $db->query($sql);
168 $num = $db->num_rows($resql);
172 $objp = $db->fetch_object($resql);
176 if ($invoice->fetch($objp->facid) <= 0) {
182 if ($invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref) < 0) {
200 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
206 $langs->load(
"errors");
211 if ($action ==
'setnum_paiement' &&
GETPOST(
'num_paiement') && $user->hasRight(
'facture',
'paiement')) {
212 $res = $object->update_num(
GETPOST(
'num_paiement'));
214 setEventMessages($langs->trans(
'PaymentNumberUpdateSucceeded'),
null,
'mesgs');
216 setEventMessages($langs->trans(
'PaymentNumberUpdateFailed'),
null,
'errors');
220 if ($action ==
'setdatep' &&
GETPOST(
'datepday') && $user->hasRight(
'facture',
'paiement')) {
221 $datepaye =
dol_mktime(
GETPOST(
'datephour',
'int'),
GETPOST(
'datepmin',
'int'),
GETPOST(
'datepsec',
'int'),
GETPOST(
'datepmonth',
'int'),
GETPOST(
'datepday',
'int'),
GETPOST(
'datepyear',
'int'));
222 $res = $object->update_date($datepaye);
224 setEventMessages($langs->trans(
'PaymentDateUpdateSucceeded'),
null,
'mesgs');
230 if ($action ==
'createbankpayment' && $user->hasRight(
'facture',
'paiement')) {
235 $label =
'(CustomerInvoicePayment)';
237 $label =
'(CustomerInvoicePaymentBack)';
240 $bankaccountid =
GETPOST(
'accountid',
'int');
241 if ($bankaccountid > 0) {
242 $object->paiementcode = $object->type_code;
243 $object->amounts = $object->getAmountsArray();
245 $result = $object->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
251 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
270$thirdpartystatic =
new Societe($db);
272$result = $object->fetch($id, $ref);
278$form =
new Form($db);
280$head = payment_prepare_head($object);
282print
dol_get_fiche_head($head,
'payment', $langs->trans(
"PaymentCustomerInvoice"), -1,
'payment');
285if ($action ==
'delete') {
286 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
"DeletePayment"), $langs->trans(
"ConfirmDeletePayment"),
'confirm_delete',
'', 0, 2);
290if ($action ==
'valide') {
292 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&facid='.((
int) $facid), $langs->trans(
"ValidatePayment"), $langs->trans(
"ConfirmValidatePayment"),
'confirm_validate',
'', 0, 2);
295$linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
300print
'<div class="fichecenter">';
301print
'<div class="underbanner clearboth"></div>';
303print
'<table class="border centpercent">'.
"\n";
306print
'<tr><td class="titlefield">'.$form->editfieldkey(
"Date",
'datep', $object->date, $object, $user->hasRight(
'facture',
'paiement')).
'</td><td>';
307print $form->editfieldval(
"Date",
'datep', $object->date, $object, $user->hasRight(
'facture',
'paiement'),
'datehourpicker',
'',
null, $langs->trans(
'PaymentDateUpdateSucceeded'),
'', 0,
'',
'id',
'tzuser');
311$labeltype = $langs->trans(
"PaymentType".$object->type_code) !=
"PaymentType".$object->type_code ? $langs->trans(
"PaymentType".$object->type_code) : $object->type_label;
312print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>'.$labeltype;
313print $object->num_payment ?
' - '.$object->num_payment :
'';
317print
'<tr><td>'.$langs->trans(
'Amount').
'</td><td>'.
price($object->amount,
'', $langs, 0, -1, -1, $conf->currency).
'</td></tr>';
321if (isModEnabled(
"banque")) {
324 if ($object->fk_account > 0) {
325 $bankline->fetch($object->bank_line);
326 if ($bankline->rappro) {
328 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemoveConciliatedPayment"));
332 print
'<td>'.$langs->trans(
'BankAccount').
'</td>';
334 $accountstatic =
new Account($db);
335 $accountstatic->fetch($bankline->fk_account);
336 print $accountstatic->getNomUrl(1);
363if (isModEnabled(
"banque")) {
364 if ($object->fk_account > 0) {
365 if ($object->type_code ==
'CHQ' && $bankline->fk_bordereau > 0) {
366 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
368 $bordereau->fetch($bankline->fk_bordereau);
371 print
'<td>'.$langs->trans(
'CheckReceipt').
'</td>';
373 print $bordereau->getNomUrl(1);
380 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
382 if ($object->fk_account > 0) {
383 print $bankline->getNomUrl(1, 0,
'showconciliatedandaccounted');
385 $langs->load(
"admin");
386 print
'<span class="opacitymedium">';
387 print $langs->trans(
"NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv(
"Module85Name"));
389 if ($user->hasRight(
'facture',
'paiement')) {
392 $amountofpayments = $object->getAmountsArray();
393 $bankaccountidofinvoices =
null;
394 foreach ($amountofpayments as $idinvoice => $amountofpayment) {
395 $tmpinvoice =
new Facture($db);
396 $tmpinvoice->fetch($idinvoice);
397 if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
398 if (is_null($bankaccountidofinvoices)) {
399 $bankaccountidofinvoices = $tmpinvoice->fk_account;
400 } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
401 $bankaccountidofinvoices = 0;
406 print
'<form method="POST" name="createbankpayment">';
407 print
'<input type="hidden" name="token" value="'.newToken().
'">';
408 print
'<input type="hidden" name="action" value="createbankpayment">';
409 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
410 print
' '.$langs->trans(
"ToCreateRelatedRecordIntoBank").
': ';
411 print $form->select_comptes($bankaccountidofinvoices,
'accountid', 0,
'', 2,
'', 0,
'', 1);
413 print
'<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans(
"ClickHere").
'">';
423print
'<tr><td class="tdtop">'.$form->editfieldkey(
"Comments",
'note', $object->note_private, $object, $user->hasRight(
'facture',
'paiement')).
'</td><td>';
424print $form->editfieldval(
"Note",
'note', $object->note_private, $object, $user->hasRight(
'facture',
'paiement'),
'textarea:'.ROWS_3.
':90%');
427if (!empty($object->ext_payment_id)) {
429 print
'<tr><td class="tdtop">'.$langs->trans(
"StripePaymentId").
'</td><td>';
430 if (isModEnabled(
'stripe') && in_array($object->ext_payment_site, array(
'Stripe',
'StripeLive'))) {
431 $tmp1 = explode(
'@', $object->ext_payment_id);
432 if (!empty($tmp1[1])) {
433 $site_account_payment = $tmp1[1];
435 $tmp2 = explode(
':', $tmp1[0]);
436 if (!empty($tmp2[1])) {
437 $stripecu = $tmp2[1];
443 if (!empty($stripeacc)) {
444 $connect = $stripeacc.
'/';
446 $url =
'https://dashboard.stripe.com/'.$connect.
'test/customers/'.$stripecu;
447 if (!empty($stripearrayofkeysbyenv[1][
'publishable_key']) && $stripearrayofkeysbyenv[1][
'publishable_key'] == $site_account_payment) {
448 $url =
'https://dashboard.stripe.com/'.$connect.
'customers/'.$stripecu;
450 print
' <a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe').
' - Publishable key = '.$site_account_payment,
'globe').
'</a>';
468$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';
469$sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
470$sql .=
' WHERE pf.fk_facture = f.rowid';
471$sql .=
' AND f.fk_soc = s.rowid';
472$sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
473$sql .=
' AND pf.fk_paiement = '.((int) $object->id);
474$resql = $db->query($sql);
476 $num = $db->num_rows($resql);
483 print
'<div class="div-table-responsive">';
484 print
'<table class="noborder centpercent">';
486 print
'<tr class="liste_titre">';
487 print
'<td>'.$langs->trans(
'Bill').
'</td>';
488 print
'<td>'.$langs->trans(
'Company').
'</td>';
489 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
490 print
'<td>'.$langs->trans(
'Entity').
'</td>';
493 if (isModEnabled(
'margin') &&
getDolGlobalInt(
'MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
494 print
'<td class="right">'.$langs->trans(
'Margin').
'</td>';
496 print
'<td class="right">'.$langs->trans(
'ExpectedToPay').
'</td>';
497 print
'<td class="right">'.$langs->trans(
'PayedByThisPayment').
'</td>';
498 print
'<td class="right">'.$langs->trans(
'RemainderToPay').
'</td>';
499 print
'<td class="right">'.$langs->trans(
'Status').
'</td>';
501 $parameters = array();
502 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $object, $action);
508 $objp = $db->fetch_object($resql);
510 $thirdpartystatic->fetch($objp->socid);
513 $invoice->fetch($objp->facid);
516 if (isModEnabled(
'margin') &&
getDolGlobalInt(
'MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
518 $marginInfo = array();
519 $invoice->fetch_lines();
520 $marginInfo = $formmargin->getMarginInfosArray($invoice);
523 $paiement = $invoice->getSommePaiement();
524 $creditnotes = $invoice->getSumCreditNotesUsed();
525 $deposits = $invoice->getSumDepositsUsed();
526 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
527 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
529 print
'<tr class="oddeven">';
533 print $invoice->getNomUrl(1);
537 print
'<td class="tdoverflowmax150">';
538 print $thirdpartystatic->getNomUrl(1);
542 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
544 $mc->getInfo($objp->entity);
550 if (isModEnabled(
'margin') &&
getDolGlobalInt(
'MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
551 print
'<td class="right">'.price($marginInfo[
'total_margin']).
'</td>';
555 print
'<td class="right"><span class="amount">'.price($objp->total_ttc).
'</span></td>';
558 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
561 print
'<td class="right"><span class="amount">'.price($remaintopay).
'</span></td>';
564 print
'<td class="right">'.$invoice->getLibStatut(5, $alreadypayed).
'</td>';
566 $parameters = array(
'fk_paiement'=> (
int) $object->id);
567 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $objp, $action);
572 if ($objp->paye == 1 && !
getDolGlobalString(
'INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED')) {
574 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemovePaymentWithOneInvoicePaid"));
577 $total = $total + $objp->amount;
597print
'<div class="tabsAction">';
600 if ($user->socid == 0 && $object->statut == 0 && $action ==
'') {
601 if ($user->hasRight(
'facture',
'paiement')) {
602 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&action=valide&token='.newToken().
'">'.$langs->trans(
'Valid').
'</a>';
608if (! empty($title_button)) {
609 $params[
'attr'] = array(
'title' => $title_button);
612if ($user->socid == 0 && $action ==
'') {
613 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...
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
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 a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.