33require
'../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
38if (isModEnabled(
"bank")) {
39 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
41if (isModEnabled(
'margin')) {
42 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
54$langs->loadLangs(array(
'bills',
'banks',
'companies'));
58$action =
GETPOST(
'action',
'aZ09');
59$confirm =
GETPOST(
'confirm',
'alpha');
60$backtopage =
GETPOST(
'backtopage',
'alpha');
69$hookmanager->initHooks(array(
'paymentcard',
'globalcard'));
72include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
78 $socid = $user->socid;
82if ($socid && $socid !=
$object->thirdparty->id) {
90if (isModEnabled(
'stripe')) {
91 require_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
93 $service =
'StripeTest';
96 $service =
'StripeLive';
101 global $stripearrayofkeysbyenv;
102 $site_account = $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
104 $stripe =
new Stripe($db);
105 $stripeacc = $stripe->getStripeAccount($service);
113$parameters = array(
'socid' => $socid);
114$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
119if (empty($reshook)) {
120 if ($action ==
'setnote' && $user->hasRight(
'facture',
'paiement')) {
133 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
136 $result =
$object->delete($user);
141 header(
"Location: ".$backtopage);
144 header(
"Location: list.php");
148 $langs->load(
"errors");
154 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
157 if (
$object->validate($user) > 0) {
162 $outputlangs = $langs;
163 if (
GETPOST(
'lang_id',
'aZ09')) {
165 $outputlangs->setDefaultLang(
GETPOST(
'lang_id',
'aZ09'));
172 $sql =
'SELECT f.rowid as facid';
173 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
174 $sql .=
' WHERE pf.fk_facture = f.rowid';
175 $sql .=
' AND f.fk_soc = s.rowid';
176 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
177 $sql .=
' AND pf.fk_paiement = '.((int)
$object->id);
178 $resql = $db->query($sql);
181 $num = $db->num_rows($resql);
185 $objp = $db->fetch_object($resql);
189 if ($invoice->fetch($objp->facid) <= 0) {
195 if ($invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref) < 0) {
213 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
219 $langs->load(
"errors");
224 if ($action ==
'setnum_paiement' &&
GETPOST(
'num_paiement') && $user->hasRight(
'facture',
'paiement')) {
227 setEventMessages($langs->trans(
'PaymentNumberUpdateSucceeded'),
null,
'mesgs');
229 setEventMessages($langs->trans(
'PaymentNumberUpdateFailed'),
null,
'errors');
233 if ($action ==
'setdatep' &&
GETPOST(
'datepday') && $user->hasRight(
'facture',
'paiement')) {
235 $res =
$object->update_date($datepaye);
237 setEventMessages($langs->trans(
'PaymentDateUpdateSucceeded'),
null,
'mesgs');
243 if ($action ==
'createbankpayment' && $user->hasRight(
'facture',
'paiement')) {
248 $label =
'(CustomerInvoicePayment)';
250 $label =
'(CustomerInvoicePaymentBack)';
254 if ($bankaccountid > 0) {
258 $result =
$object->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
264 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
283$thirdpartystatic =
new Societe($db);
285$result =
$object->fetch($id, $ref);
291$form =
new Form($db);
293$head = payment_prepare_head(
$object);
295print
dol_get_fiche_head($head,
'payment', $langs->trans(
"PaymentCustomerInvoice"), -1,
'payment');
298if ($action ==
'delete') {
299 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
"DeletePayment"), $langs->trans(
"ConfirmDeletePayment"),
'confirm_delete',
'', 0, 2);
303if ($action ==
'valide') {
305 print $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&facid='.((
int) $facid), $langs->trans(
"ValidatePayment"), $langs->trans(
"ConfirmValidatePayment"),
'confirm_validate',
'', 0, 2);
308$linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
310dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref',
'');
313print
'<div class="fichecenter">';
314print
'<div class="underbanner clearboth"></div>';
316print
'<table class="border centpercent">'.
"\n";
319print
'<tr><td class="titlefield">'.$form->editfieldkey(
"Date",
'datep',
$object->date,
$object, $user->hasRight(
'facture',
'paiement')).
'</td><td>';
320print $form->editfieldval(
"Date",
'datep',
$object->date,
$object, $user->hasRight(
'facture',
'paiement'),
'datehourpicker',
'',
null, $langs->trans(
'PaymentDateUpdateSucceeded'),
'', 0,
'',
'id',
'tzuser');
324$labeltype = $langs->trans(
"PaymentType".
$object->type_code) !=
"PaymentType".$object->type_code ? $langs->trans(
"PaymentType".
$object->type_code) :
$object->type_label;
325print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>'.$labeltype;
326print
$object->num_payment ?
' - '.$object->num_payment :
'';
330print
'<tr><td>'.$langs->trans(
'Amount').
'</td><td>'.
price(
$object->amount, 0, $langs, 0, -1, -1,
$conf->currency).
'</td></tr>';
336if (isModEnabled(
"bank")) {
340 $bankline->fetch(
$object->bank_line);
341 if ($bankline->rappro) {
343 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemoveConciliatedPayment"));
347 print
'<td>'.$langs->trans(
'BankAccount').
'</td>';
349 $accountstatic =
new Account($db);
350 $accountstatic->fetch($bankline->fk_account);
351 print $accountstatic->getNomUrl(1);
378if (isModEnabled(
"bank")) {
380 if (
$object->type_code ==
'CHQ' && $bankline->fk_bordereau > 0) {
381 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
383 $bordereau->fetch($bankline->fk_bordereau);
386 print
'<td>'.$langs->trans(
'CheckReceipt').
'</td>';
388 print $bordereau->getNomUrl(1);
395 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
397 if (
$object->fk_account > 0 && $bankline !==
null) {
398 print $bankline->getNomUrl(1, 0,
'showconciliatedandaccounted');
400 $langs->load(
"admin");
401 print
'<span class="opacitymedium">';
402 print $langs->trans(
"NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv(
"Module85Name"));
404 if ($user->hasRight(
'facture',
'paiement')) {
407 $amountofpayments =
$object->getAmountsArray();
408 $bankaccountidofinvoices =
null;
409 foreach ($amountofpayments as $idinvoice => $amountofpayment) {
410 $tmpinvoice =
new Facture($db);
411 $tmpinvoice->fetch($idinvoice);
412 if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
413 if (is_null($bankaccountidofinvoices)) {
414 $bankaccountidofinvoices = $tmpinvoice->fk_account;
415 } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
416 $bankaccountidofinvoices = 0;
421 print
'<form method="POST" name="createbankpayment">';
422 print
'<input type="hidden" name="token" value="'.newToken().
'">';
423 print
'<input type="hidden" name="action" value="createbankpayment">';
424 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
425 print
' '.$langs->trans(
"ToCreateRelatedRecordIntoBank").
': ';
426 print $form->select_comptes($bankaccountidofinvoices,
'accountid', 0,
'', 2,
'', 0,
'', 1);
428 print
'<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans(
"ClickHere").
'">';
438print
'<tr><td class="tdtop">'.$form->editfieldkey(
"Comments",
'note',
$object->note_private,
$object, $user->hasRight(
'facture',
'paiement')).
'</td><td class="wordbreak">';
439print $form->editfieldval(
"Note",
'note',
$object->note_private,
$object, $user->hasRight(
'facture',
'paiement'),
'textarea:'.ROWS_3.
':90%');
442if (!empty(
$object->ext_payment_id)) {
444 print
'<tr><td class="tdtop">'.$langs->trans(
"StripePaymentId").
'</td><td class="wordbreak">';
445 if (isModEnabled(
'stripe') && in_array(
$object->ext_payment_site, array(
'Stripe',
'StripeLive'))) {
446 $tmp1 = explode(
'@',
$object->ext_payment_id);
447 $site_account_payment =
'';
448 if (!empty($tmp1[1])) {
449 $site_account_payment = $tmp1[1];
451 $tmp2 = explode(
':', $tmp1[0]);
452 if (!empty($tmp2[1])) {
453 $stripecu = $tmp2[1];
459 if (!empty($stripeacc)) {
460 $connect = $stripeacc.
'/';
462 $url =
'https://dashboard.stripe.com/'.$connect.
'test/customers/'.$stripecu;
463 if (!empty($stripearrayofkeysbyenv[1][
'publishable_key']) && $stripearrayofkeysbyenv[1][
'publishable_key'] == $site_account_payment) {
464 $url =
'https://dashboard.stripe.com/'.$connect.
'customers/'.$stripecu;
466 print
' <a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe').
' - Publishable key = '.$site_account_payment,
'globe').
'</a>';
484$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';
485$sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
486$sql .=
' WHERE pf.fk_facture = f.rowid';
487$sql .=
' AND f.fk_soc = s.rowid';
488$sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
489$sql .=
' AND pf.fk_paiement = '.((int)
$object->id);
490$resql = $db->query($sql);
492 $num = $db->num_rows($resql);
499 print
'<div class="div-table-responsive">';
500 print
'<table class="noborder centpercent">';
502 print
'<tr class="liste_titre">';
503 print
'<td>'.$langs->trans(
'Bill').
'</td>';
504 print
'<td>'.$langs->trans(
'Company').
'</td>';
505 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
506 print
'<td>'.$langs->trans(
'Entity').
'</td>';
509 if (isModEnabled(
'margin') &&
getDolGlobalInt(
'MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
510 print
'<td class="right">'.$langs->trans(
'Margin').
'</td>';
512 print
'<td class="right">'.$langs->trans(
'ExpectedToPay').
'</td>';
513 print
'<td class="right">'.$langs->trans(
'PayedByThisPayment').
'</td>';
514 print
'<td class="right">'.$langs->trans(
'RemainderToPay').
'</td>';
515 print
'<td class="right">'.$langs->trans(
'Status').
'</td>';
517 $parameters = array();
518 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters,
$object, $action);
524 $objp = $db->fetch_object($resql);
526 $thirdpartystatic->fetch($objp->socid);
529 $invoice->fetch($objp->facid);
532 if (isModEnabled(
'margin') &&
getDolGlobalInt(
'MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
534 $marginInfo = array();
535 $invoice->fetch_lines();
536 $marginInfo = $formmargin->getMarginInfosArray($invoice);
539 $paiement = $invoice->getSommePaiement();
540 $creditnotes = $invoice->getSumCreditNotesUsed();
541 $deposits = $invoice->getSumDepositsUsed();
542 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
543 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
545 print
'<tr class="oddeven">';
548 print
'<td class="tdoverflowmax150">';
549 print $invoice->getNomUrl(1);
553 print
'<td class="tdoverflowmax150">';
554 print $thirdpartystatic->getNomUrl(1);
558 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
560 $mc->getInfo($objp->entity);
566 if (isModEnabled(
'margin') &&
getDolGlobalInt(
'MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
567 print
'<td class="right">'.price($marginInfo[
'total_margin']).
'</td>';
571 print
'<td class="right"><span class="amount">'.price($objp->total_ttc).
'</span></td>';
574 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
577 print
'<td class="right"><span class="amount">'.price($remaintopay).
'</span></td>';
580 print
'<td class="right">'.$invoice->getLibStatut(5, $alreadypayed).
'</td>';
582 $parameters = array(
'fk_paiement' => (
int)
$object->id);
583 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $objp, $action);
588 if ($objp->paye == 1 && !
getDolGlobalString(
'INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED')) {
590 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemovePaymentWithOneInvoicePaid"));
593 $total += $objp->amount;
613print
'<div class="tabsAction">';
616 if ($user->socid == 0 &&
$object->statut == 0 && $action ==
'') {
617 if ($user->hasRight(
'facture',
'paiement')) {
618 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$id.
'&action=valide&token='.
newToken().
'">'.$langs->trans(
'Valid').
'</a>';
624if (! empty($title_button)) {
625 $params[
'attr'] = array(
'title' => $title_button);
628if ($user->socid == 0 && $action ==
'') {
629 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( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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...)
Stripe class @TODO No reason to extends CommonObject.
Class to manage translations.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_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.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.