123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- <?php
- /**
- * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
- * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
- * Copyright (C) 2020 Abbes Bahfir <bafbes@gmail.com>
- * Copyright (C) 2021 Waël Almoman <info@almoman.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- * or see https://www.gnu.org/
- */
- /**
- * Returns an array with the tabs for the "Payment" section
- * It loads tabs from modules looking for the entity payment
- *
- * @param Paiement $object Current payment object
- * @return array Tabs for the payment section
- */
- function payment_prepare_head(Paiement $object)
- {
- global $langs, $conf;
- $h = 0;
- $head = array();
- $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$object->id;
- $head[$h][1] = $langs->trans("Payment");
- $head[$h][2] = 'payment';
- $h++;
- // Show more tabs from modules
- // Entries must be declared in modules descriptor with line
- // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
- // $this->tabs = array('entity:-tabname); to remove a tab
- complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment');
- $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/info.php?id='.$object->id;
- $head[$h][1] = $langs->trans("Info");
- $head[$h][2] = 'info';
- $h++;
- complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment', 'remove');
- return $head;
- }
- /**
- * Returns an array with the tabs for the "Bannkline" section
- * It loads tabs from modules looking for the entity payment
- *
- * @param int $id ID of bank line
- * @return array Tabs for the Bankline section
- */
- function bankline_prepare_head($id)
- {
- global $langs, $conf;
- $h = 0;
- $head = array();
- $head[$h][0] = DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$id;
- $head[$h][1] = $langs->trans('BankTransaction');
- $head[$h][2] = 'bankline';
- $h++;
- // Show more tabs from modules
- // Entries must be declared in modules descriptor with line
- // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
- // $this->tabs = array('entity:-tabname); to remove a tab
- complete_head_from_modules($conf, $langs, null, $head, $h, 'bankline');
- $head[$h][0] = DOL_URL_ROOT.'/compta/bank/info.php?rowid='.$id;
- $head[$h][1] = $langs->trans("Info");
- $head[$h][2] = 'info';
- $h++;
- complete_head_from_modules($conf, $langs, null, $head, $h, 'bankline', 'remove');
- return $head;
- }
- /**
- * Returns an array with the tabs for the "Supplier payment" section
- * It loads tabs from modules looking for the entity payment_supplier
- *
- * @param Paiement $object Current payment object
- * @return array Tabs for the payment section
- */
- function payment_supplier_prepare_head(Paiement $object)
- {
- global $db, $langs, $conf;
- $h = 0;
- $head = array();
- $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$object->id;
- $head[$h][1] = $langs->trans("Payment");
- $head[$h][2] = 'payment';
- $h++;
- // Show more tabs from modules
- // Entries must be declared in modules descriptor with line
- // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
- // $this->tabs = array('entity:-tabname); to remove a tab
- complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_supplier');
- $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$object->id;
- $head[$h][1] = $langs->trans('Info');
- $head[$h][2] = 'info';
- $h++;
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
- $upload_dir = $conf->fournisseur->payment->dir_output.'/'.$object->ref;
- $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
- $nbLinks = Link::count($db, $object->element, $object->id);
- $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/document.php?id='.$object->id;
- $head[$h][1] = $langs->trans('Documents');
- if (($nbFiles + $nbLinks) > 0) {
- $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
- }
- $head[$h][2] = 'documents';
- $h++;
- complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_supplier', 'remove');
- return $head;
- }
- /**
- * Return array of valid payment mode
- *
- * @param string $paymentmethod Filter on this payment method (''=none, 'paypal', ...)
- * @return array Array of valid payment method
- */
- function getValidOnlinePaymentMethods($paymentmethod = '')
- {
- global $conf, $langs, $db;// @todo, $user;
- $validpaymentmethod = array();
- if ((empty($paymentmethod) || $paymentmethod == 'paypal') && !empty($conf->paypal->enabled)) {
- $langs->load("paypal");
- $validpaymentmethod['paypal'] = 'valid';
- }
- if ((empty($paymentmethod) || $paymentmethod == 'paybox') && !empty($conf->paybox->enabled)) {
- $langs->load("paybox");
- $validpaymentmethod['paybox'] = 'valid';
- }
- if ((empty($paymentmethod) || $paymentmethod == 'stripe') && !empty($conf->stripe->enabled)) {
- $langs->load("stripe");
- $validpaymentmethod['stripe'] = 'valid';
- }
- // Added by MMI Mathieu Moulin iProspective
- if ((empty($paymentmethod) || $paymentmethod == 'mbietransactions') && !empty($conf->mbietransactions->enabled)) {
- $langs->load("mbietransactions@mbietransactions");
- $validpaymentmethod['mbietransactions'] = 'valid';
- }
- // TODO Add trigger
- //include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
- //$interface = new Interfaces($db);
- //$result = $interface->run_triggers('', NULL, $user, $langs, $conf);
- //var_dump($validpaymentmethod);
- return $validpaymentmethod;
- }
- /**
- * Return string with full online payment Url
- *
- * @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'member' ...)
- * @param string $ref Ref of object
- * @return string Url string
- */
- function showOnlinePaymentUrl($type, $ref)
- {
- global $langs;
- // Load translation files required by the page
- $langs->loadLangs(array('payment', 'stripe'));
- $servicename = ''; // Link is a generic link for all payments services (paypal, stripe, ...)
- $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'</span><br>';
- $url = getOnlinePaymentUrl(0, $type, $ref);
- $out .= '<div class="urllink"><input type="text" id="onlinepaymenturl" class="quatrevingtpercentminusx" value="'.$url.'">';
- $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
- $out .= '</div>';
- $out .= ajax_autoselect("onlinepaymenturl", 0);
- return $out;
- }
- /**
- * Return string with HTML link for online payment
- *
- * @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'member' ...)
- * @param string $ref Ref of object
- * @param string $label Text or HTML tag to display, if empty it display the URL
- * @return string Url string
- */
- function getHtmlOnlinePaymentLink($type, $ref, $label = '')
- {
- $url = getOnlinePaymentUrl(0, $type, $ref);
- $label = $label ? $label : $url;
- return '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$label.'</a>';
- }
- /**
- * Return string with full Url
- *
- * @param int $mode 0=True url, 1=Url formated with colors
- * @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'member', 'boothlocation', ...)
- * @param string $ref Ref of object
- * @param int $amount Amount (required and used for $type='free' only)
- * @param string $freetag Free tag (required and used for $type='free' only)
- * @param string $localorexternal 0=Url for browser, 1=Url for external access
- * @return string Url string
- */
- function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag', $localorexternal = 1)
- {
- global $conf, $dolibarr_main_url_root;
- $ref = str_replace(' ', '', $ref);
- $out = '';
- // Define $urlwithroot
- $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
- $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
- //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
- $urltouse = DOL_MAIN_URL_ROOT;
- if ($localorexternal) {
- $urltouse = $urlwithroot;
- }
- if ($type == 'free') {
- $out = $urltouse.'/public/payment/newpayment.php?amount='.($mode ? '<span style="color: #666666">' : '').$amount.($mode ? '</span>' : '').'&tag='.($mode ? '<span style="color: #666666">' : '').$freetag.($mode ? '</span>' : '');
- if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
- if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
- $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
- } else {
- $out .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2));
- }
- }
- //if ($mode) $out.='&noidempotency=1';
- // Added by MMI Mathieu Moulin iProspective
- } elseif ($type == 'propal') {
- $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= 'propal_ref';
- }
- if ($mode == 0) {
- $out .= urlencode($ref);
- }
- $out .= ($mode ? '</font>' : '');
- if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
- if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
- $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
- } else {
- $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
- if ($mode == 1) {
- $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + propal_ref)";
- }
- if ($mode == 0) {
- $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
- }
- $out .= ($mode ? '</font>' : '');
- }
- }
- } elseif ($type == 'order') {
- $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= 'order_ref';
- }
- if ($mode == 0) {
- $out .= urlencode($ref);
- }
- $out .= ($mode ? '</span>' : '');
- if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
- if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
- $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
- } else {
- $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + order_ref)";
- }
- if ($mode == 0) {
- $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
- }
- $out .= ($mode ? '</span>' : '');
- }
- }
- } elseif ($type == 'invoice') {
- $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= 'invoice_ref';
- }
- if ($mode == 0) {
- $out .= urlencode($ref);
- }
- $out .= ($mode ? '</span>' : '');
- if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
- if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
- $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
- } else {
- $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
- }
- if ($mode == 0) {
- $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
- }
- $out .= ($mode ? '</span>' : '');
- }
- }
- } elseif ($type == 'contractline') {
- $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= 'contractline_ref';
- }
- if ($mode == 0) {
- $out .= urlencode($ref);
- }
- $out .= ($mode ? '</span>' : '');
- if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
- if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
- $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
- } else {
- $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
- }
- if ($mode == 0) {
- $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
- }
- $out .= ($mode ? '</span>' : '');
- }
- }
- } elseif ($type == 'member' || $type == 'membersubscription') {
- $newtype = 'member';
- $out = $urltouse.'/public/payment/newpayment.php?source=member&ref='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= 'member_ref';
- }
- if ($mode == 0) {
- $out .= urlencode($ref);
- }
- $out .= ($mode ? '</span>' : '');
- if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
- if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
- $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
- } else {
- $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$newtype."' + member_ref)";
- }
- if ($mode == 0) {
- $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$newtype.$ref, 2);
- }
- $out .= ($mode ? '</span>' : '');
- }
- }
- } elseif ($type == 'donation') {
- $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= 'donation_ref';
- }
- if ($mode == 0) {
- $out .= urlencode($ref);
- }
- $out .= ($mode ? '</span>' : '');
- if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
- if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
- $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
- } else {
- $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + donation_ref)";
- }
- if ($mode == 0) {
- $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
- }
- $out .= ($mode ? '</span>' : '');
- }
- }
- } elseif ($type == 'boothlocation') {
- $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= 'invoice_ref';
- }
- if ($mode == 0) {
- $out .= urlencode($ref);
- }
- $out .= ($mode ? '</span>' : '');
- if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
- if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
- $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
- } else {
- $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
- if ($mode == 1) {
- $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
- }
- if ($mode == 0) {
- $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
- }
- $out .= ($mode ? '</span>' : '');
- }
- }
- }
- // For multicompany
- if (!empty($out) && !empty($conf->multicompany->enabled)) {
- $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
- }
- return $out;
- }
- /**
- * Show footer of company in HTML pages
- *
- * @param Societe $fromcompany Third party
- * @param Translate $langs Output language
- * @param int $addformmessage Add the payment form message
- * @param string $suffix Suffix to use on constants
- * @param Object $object Object related to payment
- * @return void
- */
- function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
- {
- global $conf;
- // Juridical status
- $line1 = "";
- if ($fromcompany->forme_juridique_code) {
- $line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
- }
- // Capital
- if ($fromcompany->capital) {
- $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
- }
- // Prof Id 1
- if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
- $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
- if (preg_match('/\((.*)\)/i', $field, $reg)) {
- $field = $reg[1];
- }
- $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
- }
- // Prof Id 2
- if ($fromcompany->idprof2) {
- $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
- if (preg_match('/\((.*)\)/i', $field, $reg)) {
- $field = $reg[1];
- }
- $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
- }
- // Second line of company infos
- $line2 = "";
- // Prof Id 3
- if ($fromcompany->idprof3) {
- $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
- if (preg_match('/\((.*)\)/i', $field, $reg)) {
- $field = $reg[1];
- }
- $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
- }
- // Prof Id 4
- if ($fromcompany->idprof4) {
- $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
- if (preg_match('/\((.*)\)/i', $field, $reg)) {
- $field = $reg[1];
- }
- $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
- }
- // IntraCommunautary VAT
- if ($fromcompany->tva_intra != '') {
- $line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
- }
- print '<!-- htmlPrintOnlinePaymentFooter -->'."\n";
- print '<br>';
- print '<div class="center paddingleft paddingright">'."\n";
- if ($addformmessage) {
- print '<!-- object = '.$object->element.' -->';
- print '<br>';
- $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
- if (!empty($conf->global->$parammessageform)) {
- print $langs->transnoentities($conf->global->$parammessageform);
- } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORM)) {
- print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORM);
- }
- // Add other message if VAT exists
- if ($object->total_vat != 0 || $object->total_tva != 0) {
- $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
- if (!empty($conf->global->$parammessageform)) {
- print $langs->transnoentities($conf->global->$parammessageform);
- } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT)) {
- print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT);
- }
- }
- }
- print '<span style="font-size: 10px;"><br><hr>'."\n";
- print $fromcompany->name.'<br>';
- print $line1;
- if (strlen($line1.$line2) > 50) {
- print '<br>';
- } else {
- print ' - ';
- }
- print $line2;
- print '</span></div>'."\n";
- }
|