34require
'../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
47 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
50 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) {
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);
116 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
119if (empty($reshook)) {
120 if ($action ==
'setnote' && $user->hasRight(
'facture',
'paiement')) {
133 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
137 $result =
$object->delete($user);
142 header(
"Location: ".$backtopage);
145 header(
"Location: list.php");
149 $langs->load(
"errors");
155 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
158 if (
$object->validate($user) > 0) {
163 $outputlangs = $langs;
164 if (
GETPOST(
'lang_id',
'aZ09')) {
166 $outputlangs->setDefaultLang(
GETPOST(
'lang_id',
'aZ09'));
173 $sql =
'SELECT f.rowid as facid';
174 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
175 $sql .=
' WHERE pf.fk_facture = f.rowid';
176 $sql .=
' AND f.fk_soc = s.rowid';
177 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
178 $sql .=
' AND pf.fk_paiement = '.((int)
$object->id);
179 $resql = $db->query($sql);
182 $num = $db->num_rows($resql);
186 $objp = $db->fetch_object($resql);
190 if ($invoice->fetch($objp->facid) <= 0) {
192 setEventMessages($invoice->error, $invoice->errors,
'errors');
196 if ($invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref) < 0) {
198 setEventMessages($invoice->error, $invoice->errors,
'errors');
209 setEventMessages($db->error,
null,
'errors');
214 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
220 $langs->load(
"errors");
225 if ($action ==
'setnum_paiement' &&
GETPOST(
'num_paiement') && $user->hasRight(
'facture',
'paiement')) {
228 setEventMessages($langs->trans(
'PaymentNumberUpdateSucceeded'),
null,
'mesgs');
230 setEventMessages($langs->trans(
'PaymentNumberUpdateFailed'),
null,
'errors');
234 if ($action ==
'setdatep' &&
GETPOST(
'datepday') && $user->hasRight(
'facture',
'paiement')) {
236 $res =
$object->update_date($datepaye);
238 setEventMessages($langs->trans(
'PaymentDateUpdateSucceeded'),
null,
'mesgs');
240 setEventMessages($langs->trans(
'PaymentDateUpdateFailed'),
null,
'errors');
244 if ($action ==
'createbankpayment' && $user->hasRight(
'facture',
'paiement')) {
249 $label =
'(CustomerInvoicePayment)';
251 $label =
'(CustomerInvoicePaymentBack)';
255 if ($bankaccountid > 0) {
259 $result =
$object->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
265 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
284$thirdpartystatic =
new Societe($db);
286$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', 0,
'',
'', 0,
'', 1);
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 tableforfield 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 :
'';
330$titlefield=$langs->trans(
'Numero').
' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
331print
'<tr><td>'.$form->editfieldkey($titlefield,
'num_paiement',
$object->num_payment, $object,
$object->statut == 0 && $user->hasRight(
"facture",
"creer")).
'</td><td>';
332print $form->editfieldval($titlefield,
'num_paiement',
$object->num_payment, $object,
$object->statut == 0 && $user->hasRight(
"facture",
"creer"),
'string',
'',
null, $langs->trans(
'PaymentNumberUpdateSucceeded'));
336print
'<tr><td>'.$langs->trans(
'Amount').
'</td><td>'.
price(
$object->amount, 0, $langs, 0, -1, -1,
$conf->currency).
'</td></tr>';
346 $bankline->fetch(
$object->bank_line);
347 if ($bankline->rappro) {
349 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemoveConciliatedPayment"));
353 print
'<td>'.$langs->trans(
'BankAccount').
'</td>';
355 $accountstatic =
new Account($db);
356 $accountstatic->fetch($bankline->fk_account);
357 print $accountstatic->getNomUrl(1);
386 if (
$object->type_code ==
'CHQ' && $bankline->fk_bordereau > 0) {
387 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
389 $bordereau->fetch($bankline->fk_bordereau);
392 print
'<td>'.$langs->trans(
'CheckReceipt').
'</td>';
394 print $bordereau->getNomUrl(1);
401 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
403 if (
$object->fk_account > 0 && $bankline !==
null) {
404 print $bankline->getNomUrl(1, 0,
'showconciliatedandaccounted');
406 $langs->load(
"admin");
407 print
'<span class="opacitymedium">';
408 print $langs->trans(
"NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv(
"Module85Name"));
410 if ($user->hasRight(
'facture',
'paiement')) {
413 $amountofpayments =
$object->getAmountsArray();
414 $bankaccountidofinvoices =
null;
415 foreach ($amountofpayments as $idinvoice => $amountofpayment) {
416 $tmpinvoice =
new Facture($db);
417 $tmpinvoice->fetch($idinvoice);
418 if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
419 if (is_null($bankaccountidofinvoices)) {
420 $bankaccountidofinvoices = $tmpinvoice->fk_account;
421 } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
422 $bankaccountidofinvoices = 0;
427 print
'<form method="POST" name="createbankpayment">';
428 print
'<input type="hidden" name="token" value="'.newToken().
'">';
429 print
'<input type="hidden" name="action" value="createbankpayment">';
430 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
431 print
' '.$langs->trans(
"ToCreateRelatedRecordIntoBank").
': ';
432 print $form->select_comptes($bankaccountidofinvoices,
'accountid', 0,
'', 2,
'', 0,
'', 1);
434 print
'<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans(
"ClickHere").
'">';
444print
'<tr><td class="'.($user->hasRight(
'facture',
'paiement') ?
'tdtop' :
'').
'">'.$form->editfieldkey(
"Comments",
'note',
$object->note_private, $object, $user->hasRight(
'facture',
'paiement'),
'string',
'', 0, 0).
'</td><td class="wordbreak">';
445print $form->editfieldval(
"Note",
'note',
$object->note_private, $object, $user->hasRight(
'facture',
'paiement'),
'textarea:'.ROWS_3.
':90%');
448if (!empty(
$object->ext_payment_id)) {
450 print
'<tr><td class="tdtop">'.$langs->trans(
"StripePaymentId").
'</td><td class="wordbreak">';
451 if (
isModEnabled(
'stripe') && in_array(
$object->ext_payment_site, array(
'Stripe',
'StripeLive'))) {
452 $tmp1 = explode(
'@',
$object->ext_payment_id);
453 $site_account_payment =
'';
454 if (!empty($tmp1[1])) {
455 $site_account_payment = $tmp1[1];
457 $tmp2 = explode(
':', $tmp1[0]);
458 if (!empty($tmp2[1])) {
459 $stripecu = $tmp2[1];
465 if (!empty($stripeacc)) {
466 $connect = $stripeacc.
'/';
470 $url =
'https://dashboard.stripe.com/'.$connect.($object->ext_payment_site ==
'Stripe' ?
'test/' :
'').
'customers/'.$stripecu;
471 if (!empty($stripearrayofkeysbyenv[1][
'publishable_key']) && $stripearrayofkeysbyenv[1][
'publishable_key'] == $site_account_payment) {
472 $url =
'https://dashboard.stripe.com/'.$connect.
'customers/'.$stripecu;
475 $url =
'https://dashboard.stripe.com/'.($object->ext_payment_site ==
'Stripe' ?
'test/' :
'').
'payments/'.
$object->ext_payment_id;
478 print
' <a href="'.$url.
'" target="_stripe">'.img_picto($langs->trans(
'ShowInStripe').
' - Publishable key = '.$site_account_payment,
'globe').
'</a>';
487include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
490$parameters = array();
491$reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
492print $hookmanager->resPrint;
505$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';
506$sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
507$sql .=
' WHERE pf.fk_facture = f.rowid';
508$sql .=
' AND f.fk_soc = s.rowid';
509$sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
510$sql .=
' AND pf.fk_paiement = '.((int)
$object->id);
511$resql = $db->query($sql);
513 $num = $db->num_rows($resql);
520 print
'<div class="div-table-responsive">';
521 print
'<table class="noborder centpercent">';
523 print
'<tr class="liste_titre">';
524 print
'<td>'.$langs->trans(
'Bill').
'</td>';
525 print
'<td>'.$langs->trans(
'Company').
'</td>';
527 print
'<td>'.$langs->trans(
'Entity').
'</td>';
531 print
'<td class="right">'.$langs->trans(
'Margin').
'</td>';
533 print
'<td class="right">'.$langs->trans(
'ExpectedToPay').
'</td>';
534 print
'<td class="right">'.$langs->trans(
'PayedByThisPayment').
'</td>';
535 print
'<td class="right">'.$langs->trans(
'RemainderToPay').
'</td>';
536 print
'<td class="right">'.$langs->trans(
'Status').
'</td>';
538 $parameters = array();
539 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $object, $action);
545 $objp = $db->fetch_object($resql);
547 $thirdpartystatic->fetch($objp->socid);
550 $invoice->fetch($objp->facid);
556 $marginInfo = array();
557 $invoice->fetch_lines();
558 $marginInfo = $formmargin->getMarginInfosArray($invoice);
561 $paiement = $invoice->getSommePaiement();
562 $creditnotes = $invoice->getSumCreditNotesUsed();
563 $deposits = $invoice->getSumDepositsUsed();
564 $alreadypaid =
price2num($paiement + $creditnotes + $deposits,
'MT');
565 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
567 print
'<tr class="oddeven">';
570 print
'<td class="tdoverflowmax150">';
571 print $invoice->getNomUrl(1);
575 print
'<td class="tdoverflowmax150">';
576 print $thirdpartystatic->getNomUrl(1);
582 $mc->getInfo($objp->entity);
589 print
'<td class="right">'.price($marginInfo[
'total_margin']).
'</td>';
593 print
'<td class="right"><span class="amount">'.price($objp->total_ttc).
'</span></td>';
596 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
599 print
'<td class="right"><span class="amount">'.price($remaintopay).
'</span></td>';
602 print
'<td class="right">'.$invoice->getLibStatut(5, (
float) $alreadypaid).
'</td>';
604 $parameters = array(
'fk_paiement' => (
int)
$object->id);
605 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $objp, $action);
610 if ($objp->paye == 1 && !
getDolGlobalString(
'INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED')) {
612 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemovePaymentWithOneInvoicePaid"));
615 $total += $objp->amount;
626 dol_print_error($db);
635print
'<div class="tabsAction">';
638 if ($user->socid == 0 &&
$object->statut == 0 && $action ==
'') {
639 if ($user->hasRight(
'facture',
'paiement')) {
640 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$id.
'&action=valide&token='.
newToken().
'">'.$langs->trans(
'Valid').
'</a>';
645$params = array(
'attr' => array(
'class' =>
'reposition'));
646if (! empty($title_button)) {
647 $params[
'attr'][
'title'] = $title_button;
650if ($user->socid == 0 && $action ==
'') {
651 print dolGetButtonAction($langs->trans(
"Delete"), $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'delete', $user->hasRight(
'facture',
'paiement') && !$disable_delete, $params).
"\n";
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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 extend CommonObject.
Class to manage translations.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
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...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
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.