alxarafe /
alixar
| 1 | <?php |
||||
| 2 | |||||
| 3 | /* Copyright (C) 2002-2004 Rodolphe Quiedeville <[email protected]> |
||||
| 4 | * Copyright (C) 2003 Jean-Louis Bergamo <[email protected]> |
||||
| 5 | * Copyright (C) 2004-2022 Laurent Destailleur <[email protected]> |
||||
| 6 | * Copyright (C) 2005-2009 Regis Houssin <[email protected]> |
||||
| 7 | * Copyright (C) 2013 Peter Fontaine <[email protected]> |
||||
| 8 | * Copyright (C) 2015-2016 Marcos García <[email protected]> |
||||
| 9 | * Copyright (C) 2017 Ferran Marcet <[email protected]> |
||||
| 10 | * Copyright (C) 2018-2023 Thibault FOUCART <[email protected]> |
||||
| 11 | * Copyright (C) 2021 Alexandre Spangaro <[email protected]> |
||||
| 12 | * Copyright (C) 2024 MDW <[email protected]> |
||||
| 13 | * Copyright (C) 2024 Frédéric France <[email protected]> |
||||
| 14 | * Copyright (C) 2024 Rafael San José <[email protected]> |
||||
| 15 | * |
||||
| 16 | * This program is free software; you can redistribute it and/or modify |
||||
| 17 | * it under the terms of the GNU General Public License as published by |
||||
| 18 | * the Free Software Foundation; either version 3 of the License, or |
||||
| 19 | * (at your option) any later version. |
||||
| 20 | * |
||||
| 21 | * This program is distributed in the hope that it will be useful, |
||||
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
| 24 | * GNU General Public License for more details. |
||||
| 25 | * |
||||
| 26 | * You should have received a copy of the GNU General Public License |
||||
| 27 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
| 28 | */ |
||||
| 29 | |||||
| 30 | use Dolibarr\Code\Compta\Classes\BonPrelevement; |
||||
| 31 | use Dolibarr\Code\Core\Classes\ExtraFields; |
||||
| 32 | use Dolibarr\Code\Core\Classes\Form; |
||||
| 33 | use Dolibarr\Code\Core\Classes\FormAdmin; |
||||
| 34 | use Dolibarr\Code\Core\Classes\FormFile; |
||||
| 35 | use Dolibarr\Code\Core\Classes\FormOther; |
||||
| 36 | use Dolibarr\Code\Ecm\Classes\EcmFiles; |
||||
| 37 | use Dolibarr\Code\Societe\Classes\CompanyBankAccount; |
||||
| 38 | use Dolibarr\Code\Societe\Classes\CompanyPaymentMode; |
||||
| 39 | use Dolibarr\Code\Societe\Classes\Societe; |
||||
| 40 | use Dolibarr\Code\Societe\Classes\SocieteAccount; |
||||
| 41 | use Dolibarr\Code\Stripe\Classes\Stripe; |
||||
| 42 | use Dolibarr\Lib\ViewMain; |
||||
| 43 | |||||
| 44 | /** |
||||
| 45 | * \file htdocs/societe/paymentmodes.php |
||||
| 46 | * \ingroup societe |
||||
| 47 | * \brief Tab of payment modes for the customer |
||||
| 48 | */ |
||||
| 49 | |||||
| 50 | // Load Dolibarr environment |
||||
| 51 | require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php'; |
||||
| 52 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/company.lib.php'; |
||||
| 53 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/bank.lib.php'; |
||||
| 54 | |||||
| 55 | // Load translation files required by the page |
||||
| 56 | $langs->loadLangs(array("companies", "commercial", "banks", "bills", 'paypal', 'stripe', 'withdrawals')); |
||||
| 57 | |||||
| 58 | // Get parameters |
||||
| 59 | $action = GETPOST("action", 'alpha', 3); |
||||
| 60 | $cancel = GETPOST('cancel', 'alpha'); |
||||
| 61 | $backtopage = GETPOST('backtopage'); |
||||
| 62 | |||||
| 63 | $id = GETPOSTINT("id"); |
||||
| 64 | $source = GETPOST("source", "alpha"); // source can be a source or a paymentmode |
||||
| 65 | $ribid = GETPOSTINT("ribid"); |
||||
| 66 | |||||
| 67 | // Security check |
||||
| 68 | $socid = GETPOSTINT("socid"); |
||||
| 69 | if ($user->socid) { |
||||
| 70 | $socid = $user->socid; |
||||
| 71 | } |
||||
| 72 | |||||
| 73 | // Initialize objects |
||||
| 74 | $object = new Societe($db); |
||||
| 75 | $object->fetch($socid); |
||||
| 76 | |||||
| 77 | $companybankaccount = new CompanyBankAccount($db); |
||||
| 78 | $companypaymentmode = new CompanyPaymentMode($db); |
||||
| 79 | $prelevement = new BonPrelevement($db); |
||||
| 80 | |||||
| 81 | $extrafields = new ExtraFields($db); |
||||
| 82 | |||||
| 83 | // fetch optionals attributes and labels |
||||
| 84 | $extrafields->fetch_name_optionals_label($object->table_element); |
||||
| 85 | |||||
| 86 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||||
| 87 | $hookmanager->initHooks(array('thirdpartybancard', 'globalcard')); |
||||
| 88 | |||||
| 89 | // Permissions |
||||
| 90 | $permissiontoread = $user->hasRight('societe', 'lire'); |
||||
| 91 | $permissiontoadd = $user->hasRight('societe', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_builddoc.inc.php |
||||
| 92 | |||||
| 93 | $permissiontoaddupdatepaymentinformation = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $permissiontoadd) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('societe', 'thirdparty_paymentinformation_advance', 'write'))); |
||||
| 94 | |||||
| 95 | |||||
| 96 | // Check permission on company |
||||
| 97 | $result = restrictedArea($user, 'societe', '', ''); |
||||
| 98 | |||||
| 99 | |||||
| 100 | // Init Stripe objects |
||||
| 101 | if (isModEnabled('stripe')) { |
||||
| 102 | $service = 'StripeTest'; |
||||
| 103 | $servicestatus = 0; |
||||
| 104 | if (getDolGlobalString('STRIPE_LIVE') && !GETPOST('forcesandbox', 'alpha')) { |
||||
| 105 | $service = 'StripeLive'; |
||||
| 106 | $servicestatus = 1; |
||||
| 107 | } |
||||
| 108 | |||||
| 109 | // Force to use the correct API key |
||||
| 110 | global $stripearrayofkeysbyenv; |
||||
| 111 | $site_account = $stripearrayofkeysbyenv[$servicestatus]['publishable_key']; |
||||
| 112 | |||||
| 113 | $stripe = new Stripe($db); |
||||
| 114 | $stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account (no remote access to Stripe here) |
||||
| 115 | $stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus, $site_account); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here) |
||||
| 116 | } |
||||
| 117 | |||||
| 118 | $error = 0; |
||||
| 119 | |||||
| 120 | |||||
| 121 | /* |
||||
| 122 | * Actions |
||||
| 123 | */ |
||||
| 124 | |||||
| 125 | if ($cancel) { |
||||
| 126 | $action = ''; |
||||
| 127 | } |
||||
| 128 | |||||
| 129 | $morehtmlright = ''; |
||||
| 130 | $parameters = array('id' => $socid); |
||||
| 131 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||||
| 132 | if ($reshook < 0) { |
||||
| 133 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||||
| 134 | } |
||||
| 135 | |||||
| 136 | if (empty($reshook)) { |
||||
| 137 | if ($cancel) { |
||||
| 138 | $action = ''; |
||||
| 139 | if (!empty($backtopage)) { |
||||
| 140 | header("Location: " . $backtopage); |
||||
| 141 | exit; |
||||
| 142 | } |
||||
| 143 | } |
||||
| 144 | |||||
| 145 | if ($action == 'update') { |
||||
| 146 | // Update the bank account |
||||
| 147 | if (!GETPOST('label', 'alpha') || !GETPOST('bank', 'alpha')) { |
||||
| 148 | if (!GETPOST('label', 'alpha')) { |
||||
| 149 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); |
||||
| 150 | } |
||||
| 151 | if (!GETPOST('bank', 'alpha')) { |
||||
| 152 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); |
||||
| 153 | } |
||||
| 154 | $action = 'edit'; |
||||
| 155 | $error++; |
||||
| 156 | } |
||||
| 157 | $companybankaccount->fetch($id); |
||||
| 158 | if ($companybankaccount->needIBAN() == 1) { |
||||
| 159 | if (!GETPOST('iban')) { |
||||
| 160 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("IBAN")), null, 'errors'); |
||||
| 161 | $action = 'edit'; |
||||
| 162 | $error++; |
||||
| 163 | } |
||||
| 164 | if (!GETPOST('bic')) { |
||||
| 165 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BIC")), null, 'errors'); |
||||
| 166 | $action = 'edit'; |
||||
| 167 | $error++; |
||||
| 168 | } |
||||
| 169 | } |
||||
| 170 | |||||
| 171 | if (!$error) { |
||||
| 172 | $companybankaccount->oldcopy = dol_clone($companybankaccount, 2); |
||||
| 173 | |||||
| 174 | $companybankaccount->socid = $object->id; |
||||
| 175 | |||||
| 176 | $companybankaccount->bank = GETPOST('bank', 'alpha'); |
||||
| 177 | $companybankaccount->label = GETPOST('label', 'alpha'); |
||||
|
0 ignored issues
–
show
|
|||||
| 178 | $companybankaccount->status = GETPOSTINT('clos'); |
||||
| 179 | $companybankaccount->clos = $companybankaccount->status; |
||||
|
0 ignored issues
–
show
The property
Dolibarr\Code\Compta\Classes\Account::$clos has been deprecated: Duplicate field. We already have the field $this->status
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This property has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead. Loading history...
The property
$clos is declared private in Dolibarr\Code\Compta\Classes\Account. Since you implement __set, consider adding a @property or @property-write.
Loading history...
|
|||||
| 180 | $companybankaccount->code_banque = GETPOST('code_banque', 'alpha'); |
||||
| 181 | $companybankaccount->code_guichet = GETPOST('code_guichet', 'alpha'); |
||||
| 182 | $companybankaccount->number = GETPOST('number', 'alpha'); |
||||
| 183 | $companybankaccount->cle_rib = GETPOST('cle_rib', 'alpha'); |
||||
| 184 | $companybankaccount->bic = GETPOST('bic', 'alpha'); |
||||
| 185 | $companybankaccount->iban = GETPOST('iban', 'alpha'); |
||||
|
0 ignored issues
–
show
It seems like
GETPOST('iban', 'alpha') can also be of type array or array or array. However, the property $iban is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 186 | |||||
| 187 | $companybankaccount->address = GETPOST('address', 'alpha'); |
||||
|
0 ignored issues
–
show
It seems like
GETPOST('address', 'alpha') can also be of type array or array or array. However, the property $address is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 188 | $companybankaccount->domiciliation = $companybankaccount->address; |
||||
|
0 ignored issues
–
show
The property
$domiciliation is declared private in Dolibarr\Code\Compta\Classes\Account. Since you implement __set, consider adding a @property or @property-write.
Loading history...
It seems like
$companybankaccount->address can also be of type array or array or array. However, the property $domiciliation is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 189 | |||||
| 190 | $companybankaccount->owner_name = GETPOST('proprio', 'alpha'); |
||||
|
0 ignored issues
–
show
It seems like
GETPOST('proprio', 'alpha') can also be of type array or array or array. However, the property $owner_name is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 191 | $companybankaccount->proprio = $companybankaccount->owner_name; |
||||
|
0 ignored issues
–
show
The property
$proprio is declared private in Dolibarr\Code\Compta\Classes\Account. Since you implement __set, consider adding a @property or @property-write.
Loading history...
It seems like
$companybankaccount->owner_name can also be of type array or array or array. However, the property $proprio is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 192 | $companybankaccount->owner_address = GETPOST('owner_address', 'alpha'); |
||||
|
0 ignored issues
–
show
It seems like
GETPOST('owner_address', 'alpha') can also be of type array or array or array. However, the property $owner_address is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 193 | $companybankaccount->frstrecur = GETPOST('frstrecur', 'alpha'); |
||||
|
0 ignored issues
–
show
It seems like
GETPOST('frstrecur', 'alpha') can also be of type array or array or array. However, the property $frstrecur is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 194 | $companybankaccount->rum = GETPOST('rum', 'alpha'); |
||||
|
0 ignored issues
–
show
It seems like
GETPOST('rum', 'alpha') can also be of type array or array or array. However, the property $rum is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 195 | $companybankaccount->date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth'), GETPOST('date_rumday'), GETPOST('date_rumyear')); |
||||
|
0 ignored issues
–
show
It seems like
dol_mktime(0, 0, 0, GETP...ETPOST('date_rumyear')) can also be of type string. However, the property $date_rum is declared as type integer. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 196 | if (empty($companybankaccount->rum)) { |
||||
| 197 | $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id); |
||||
| 198 | } |
||||
| 199 | |||||
| 200 | if (GETPOST('stripe_card_ref', 'alpha') && GETPOST('stripe_card_ref', 'alpha') != $companypaymentmode->stripe_card_ref) { |
||||
| 201 | // If we set a stripe value that is different than previous one, we also set the stripe account |
||||
| 202 | $companypaymentmode->stripe_account = $stripecu . '@' . $site_account; |
||||
| 203 | } |
||||
| 204 | $companybankaccount->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha'); |
||||
|
0 ignored issues
–
show
It seems like
GETPOST('stripe_card_ref', 'alpha') can also be of type array or array or array. However, the property $stripe_card_ref is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 205 | |||||
| 206 | $result = $companybankaccount->update($user); |
||||
| 207 | if ($result <= 0) { |
||||
| 208 | // Display error message and get back to edit mode |
||||
| 209 | setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); |
||||
| 210 | $action = 'edit'; |
||||
| 211 | } else { |
||||
| 212 | // If this account is the default bank account, we disable others |
||||
| 213 | if ($companybankaccount->default_rib) { |
||||
| 214 | $companybankaccount->setAsDefault($id); // This will make sure there is only one default rib |
||||
| 215 | } |
||||
| 216 | |||||
| 217 | if ($companypaymentmode->oldcopy->stripe_card_ref != $companypaymentmode->stripe_card_ref) { |
||||
|
0 ignored issues
–
show
The property
stripe_card_ref does not exist on Dolibarr\Core\Base\CommonObject. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||
| 218 | if ($companybankaccount->oldcopy->iban != $companybankaccount->iban) { |
||||
| 219 | // TODO If we modified the iban, we must also update the pm_ on Stripe side, or break the link completely ? |
||||
| 220 | } |
||||
| 221 | } |
||||
| 222 | |||||
| 223 | $url = $_SERVER["PHP_SELF"] . '?socid=' . $object->id; |
||||
| 224 | header('Location: ' . $url); |
||||
| 225 | exit; |
||||
| 226 | } |
||||
| 227 | } |
||||
| 228 | } |
||||
| 229 | |||||
| 230 | if ($action == 'updatecard') { |
||||
| 231 | // Update credit card |
||||
| 232 | if (!GETPOST('label', 'alpha') || !GETPOST('proprio', 'alpha') || !GETPOST('exp_date_month', 'alpha') || !GETPOST('exp_date_year', 'alpha')) { |
||||
| 233 | if (!GETPOST('label', 'alpha')) { |
||||
| 234 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); |
||||
| 235 | } |
||||
| 236 | if (!GETPOST('proprio', 'alpha')) { |
||||
| 237 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors'); |
||||
| 238 | } |
||||
| 239 | //if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors'); |
||||
| 240 | if (!(GETPOST('exp_date_month', 'alpha') > 0) || !(GETPOST('exp_date_year', 'alpha') > 0)) { |
||||
| 241 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors'); |
||||
| 242 | } |
||||
| 243 | //if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors'); |
||||
| 244 | $action = 'createcard'; |
||||
| 245 | $error++; |
||||
| 246 | } |
||||
| 247 | |||||
| 248 | $companypaymentmode->fetch($id); |
||||
| 249 | if (!$error) { |
||||
| 250 | $companybankaccount->oldcopy = dol_clone($companybankaccount, 2); |
||||
| 251 | |||||
| 252 | $companypaymentmode->fk_soc = $object->id; |
||||
| 253 | |||||
| 254 | $companypaymentmode->bank = GETPOST('bank', 'alpha'); |
||||
| 255 | $companypaymentmode->label = GETPOST('label', 'alpha'); |
||||
|
0 ignored issues
–
show
It seems like
GETPOST('label', 'alpha') can also be of type array or array or array. However, the property $label is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||
| 256 | $companypaymentmode->number = GETPOST('cardnumber', 'alpha'); |
||||
| 257 | $companypaymentmode->last_four = substr(GETPOST('cardnumber', 'alpha'), -4); |
||||
| 258 | $companypaymentmode->proprio = GETPOST('proprio', 'alpha'); |
||||
| 259 | $companypaymentmode->exp_date_month = GETPOSTINT('exp_date_month'); |
||||
| 260 | $companypaymentmode->exp_date_year = GETPOSTINT('exp_date_year'); |
||||
| 261 | $companypaymentmode->cvn = GETPOST('cvn', 'alpha'); |
||||
| 262 | $companypaymentmode->country_code = $object->country_code; |
||||
| 263 | |||||
| 264 | if (GETPOST('stripe_card_ref', 'alpha') && GETPOST('stripe_card_ref', 'alpha') != $companypaymentmode->stripe_card_ref) { |
||||
| 265 | // If we set a stripe value that is different than previous one, we also set the stripe account |
||||
| 266 | $companypaymentmode->stripe_account = $stripecu . '@' . $site_account; |
||||
| 267 | } |
||||
| 268 | $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha'); |
||||
| 269 | |||||
| 270 | $result = $companypaymentmode->update($user); |
||||
| 271 | if (!$result) { |
||||
| 272 | setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); |
||||
| 273 | } else { |
||||
| 274 | // If this account is the default bank account, we disable others |
||||
| 275 | if ($companypaymentmode->default_rib) { |
||||
| 276 | $companypaymentmode->setAsDefault($id); // This will make sure there is only one default rib |
||||
| 277 | } |
||||
| 278 | |||||
| 279 | if ($companypaymentmode->oldcopy->stripe_card_ref != $companypaymentmode->stripe_card_ref) { |
||||
| 280 | if ($companybankaccount->oldcopy->number != $companybankaccount->number) { |
||||
| 281 | // TODO If we modified the card, we must also update the pm_ on Stripe side, or break the link completely ? |
||||
| 282 | } |
||||
| 283 | } |
||||
| 284 | |||||
| 285 | $url = $_SERVER["PHP_SELF"] . '?socid=' . $object->id; |
||||
| 286 | header('Location: ' . $url); |
||||
| 287 | exit; |
||||
| 288 | } |
||||
| 289 | } |
||||
| 290 | } |
||||
| 291 | |||||
| 292 | // Add bank account |
||||
| 293 | if ($action == 'add') { |
||||
| 294 | $error = 0; |
||||
| 295 | |||||
| 296 | if (!GETPOST('label', 'alpha')) { |
||||
| 297 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); |
||||
| 298 | $action = 'create'; |
||||
| 299 | $error++; |
||||
| 300 | } |
||||
| 301 | |||||
| 302 | if (!$error) { |
||||
| 303 | // Ajout |
||||
| 304 | $companybankaccount = new CompanyBankAccount($db); |
||||
| 305 | |||||
| 306 | $companybankaccount->socid = $object->id; |
||||
| 307 | |||||
| 308 | $companybankaccount->fetch_thirdparty(); |
||||
| 309 | |||||
| 310 | $companybankaccount->bank = GETPOST('bank', 'alpha'); |
||||
| 311 | $companybankaccount->label = GETPOST('label', 'alpha'); |
||||
| 312 | $companybankaccount->code_banque = GETPOST('code_banque', 'alpha'); |
||||
| 313 | $companybankaccount->code_guichet = GETPOST('code_guichet', 'alpha'); |
||||
| 314 | $companybankaccount->number = GETPOST('number', 'alpha'); |
||||
| 315 | $companybankaccount->cle_rib = GETPOST('cle_rib', 'alpha'); |
||||
| 316 | $companybankaccount->bic = GETPOST('bic', 'alpha'); |
||||
| 317 | $companybankaccount->iban = GETPOST('iban', 'alpha'); |
||||
| 318 | |||||
| 319 | $companybankaccount->domiciliation = GETPOST('address', 'alpha'); |
||||
| 320 | $companybankaccount->address = GETPOST('address', 'alpha'); |
||||
| 321 | |||||
| 322 | $companybankaccount->proprio = GETPOST('proprio', 'alpha'); |
||||
| 323 | $companybankaccount->owner_address = GETPOST('owner_address', 'alpha'); |
||||
| 324 | $companybankaccount->frstrecur = GETPOST('frstrecur', 'alpha'); |
||||
| 325 | $companybankaccount->rum = GETPOST('rum', 'alpha'); |
||||
| 326 | $companybankaccount->date_rum = dol_mktime(0, 0, 0, GETPOSTINT('date_rummonth'), GETPOSTINT('date_rumday'), GETPOSTINT('date_rumyear')); |
||||
| 327 | $companybankaccount->datec = dol_now(); |
||||
| 328 | |||||
| 329 | //$companybankaccount->clos = GETPOSTINT('clos'); |
||||
| 330 | $companybankaccount->status = GETPOSTINT('clos'); |
||||
| 331 | |||||
| 332 | $companybankaccount->bank = trim($companybankaccount->bank); |
||||
| 333 | if (empty($companybankaccount->bank) && !empty($companybankaccount->thirdparty)) { |
||||
| 334 | $companybankaccount->bank = $langs->trans("Bank") . ' ' . $companybankaccount->thirdparty->name; |
||||
| 335 | } |
||||
| 336 | $companybankaccount->bic = str_replace(' ', '', $companybankaccount->bic); |
||||
| 337 | |||||
| 338 | $db->begin(); |
||||
| 339 | |||||
| 340 | // This test can be done only once properties were set |
||||
| 341 | if ($companybankaccount->needIBAN() == 1) { |
||||
| 342 | if (!GETPOST('iban')) { |
||||
| 343 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("IBAN")), null, 'errors'); |
||||
| 344 | $action = 'create'; |
||||
| 345 | $error++; |
||||
| 346 | } |
||||
| 347 | if (!GETPOST('bic')) { |
||||
| 348 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BIC")), null, 'errors'); |
||||
| 349 | $action = 'create'; |
||||
| 350 | $error++; |
||||
| 351 | } |
||||
| 352 | } |
||||
| 353 | |||||
| 354 | if (!$error) { |
||||
| 355 | $result = $companybankaccount->create($user); |
||||
| 356 | if ($result < 0) { |
||||
| 357 | $error++; |
||||
| 358 | setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); |
||||
| 359 | $action = 'create'; // Force chargement page création |
||||
| 360 | } |
||||
| 361 | |||||
| 362 | if (empty($companybankaccount->rum)) { |
||||
| 363 | $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id); |
||||
| 364 | } |
||||
| 365 | } |
||||
| 366 | |||||
| 367 | if (!$error) { |
||||
| 368 | $result = $companybankaccount->update($user); // This will set the UMR number. |
||||
| 369 | if ($result < 0) { |
||||
| 370 | $error++; |
||||
| 371 | setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); |
||||
| 372 | $action = 'create'; |
||||
| 373 | } |
||||
| 374 | } |
||||
| 375 | |||||
| 376 | if (!$error) { |
||||
| 377 | $db->commit(); |
||||
| 378 | |||||
| 379 | $url = $_SERVER["PHP_SELF"] . '?socid=' . $object->id; |
||||
| 380 | header('Location: ' . $url); |
||||
| 381 | exit; |
||||
| 382 | } else { |
||||
| 383 | $db->rollback(); |
||||
| 384 | } |
||||
| 385 | } |
||||
| 386 | } |
||||
| 387 | |||||
| 388 | // Add credit card |
||||
| 389 | if ($action == 'addcard') { |
||||
| 390 | $error = 0; |
||||
| 391 | |||||
| 392 | if (!GETPOST('label', 'alpha') || !GETPOST('proprio', 'alpha') || !GETPOST('exp_date_month', 'alpha') || !GETPOST('exp_date_year', 'alpha')) { |
||||
| 393 | if (!GETPOST('label', 'alpha')) { |
||||
| 394 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); |
||||
| 395 | } |
||||
| 396 | if (!GETPOST('proprio', 'alpha')) { |
||||
| 397 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors'); |
||||
| 398 | } |
||||
| 399 | //if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors'); |
||||
| 400 | if (!(GETPOST('exp_date_month', 'alpha') > 0) || !(GETPOST('exp_date_year', 'alpha') > 0)) { |
||||
| 401 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors'); |
||||
| 402 | } |
||||
| 403 | //if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors'); |
||||
| 404 | $action = 'createcard'; |
||||
| 405 | $error++; |
||||
| 406 | } |
||||
| 407 | |||||
| 408 | if (!$error) { |
||||
| 409 | // Ajout |
||||
| 410 | $companypaymentmode = new CompanyPaymentMode($db); |
||||
| 411 | |||||
| 412 | $companypaymentmode->fk_soc = $object->id; |
||||
| 413 | $companypaymentmode->bank = GETPOST('bank', 'alpha'); |
||||
| 414 | $companypaymentmode->label = GETPOST('label', 'alpha'); |
||||
| 415 | $companypaymentmode->number = GETPOST('cardnumber', 'alpha'); |
||||
| 416 | $companypaymentmode->last_four = substr(GETPOST('cardnumber', 'alpha'), -4); |
||||
| 417 | $companypaymentmode->proprio = GETPOST('proprio', 'alpha'); |
||||
| 418 | $companypaymentmode->exp_date_month = GETPOSTINT('exp_date_month'); |
||||
| 419 | $companypaymentmode->exp_date_year = GETPOSTINT('exp_date_year'); |
||||
| 420 | $companypaymentmode->cvn = GETPOST('cvn', 'alpha'); |
||||
| 421 | $companypaymentmode->datec = dol_now(); |
||||
| 422 | $companypaymentmode->default_rib = 0; |
||||
| 423 | $companypaymentmode->type = 'card'; |
||||
| 424 | $companypaymentmode->country_code = $object->country_code; |
||||
| 425 | $companypaymentmode->status = $servicestatus; |
||||
| 426 | |||||
| 427 | if (GETPOST('stripe_card_ref', 'alpha')) { |
||||
| 428 | // If we set a stripe value, we also set the stripe account |
||||
| 429 | $companypaymentmode->stripe_account = $stripecu . '@' . $site_account; |
||||
| 430 | } |
||||
| 431 | $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha'); |
||||
| 432 | |||||
| 433 | $db->begin(); |
||||
| 434 | |||||
| 435 | if (!$error) { |
||||
| 436 | $result = $companypaymentmode->create($user); |
||||
| 437 | if ($result < 0) { |
||||
| 438 | $error++; |
||||
| 439 | setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); |
||||
| 440 | $action = 'createcard'; // Force chargement page création |
||||
| 441 | } |
||||
| 442 | } |
||||
| 443 | |||||
| 444 | if (!$error) { |
||||
| 445 | $db->commit(); |
||||
| 446 | |||||
| 447 | $url = $_SERVER["PHP_SELF"] . '?socid=' . $object->id; |
||||
| 448 | header('Location: ' . $url); |
||||
| 449 | exit; |
||||
| 450 | } else { |
||||
| 451 | $db->rollback(); |
||||
| 452 | } |
||||
| 453 | } |
||||
| 454 | } |
||||
| 455 | |||||
| 456 | if ($action == 'setasbankdefault' && GETPOSTINT('ribid') > 0) { |
||||
| 457 | $companybankaccount = new CompanyBankAccount($db); |
||||
| 458 | $res = $companybankaccount->setAsDefault(GETPOSTINT('ribid')); |
||||
| 459 | if ($res) { |
||||
| 460 | $url = constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id; |
||||
| 461 | header('Location: ' . $url); |
||||
| 462 | exit; |
||||
| 463 | } else { |
||||
| 464 | setEventMessages($db->lasterror, null, 'errors'); |
||||
| 465 | } |
||||
| 466 | } |
||||
| 467 | |||||
| 468 | if ($action == 'confirm_deletecard' && GETPOST('confirm', 'alpha') == 'yes') { |
||||
| 469 | // Delete the credi card |
||||
| 470 | $companypaymentmode = new CompanyPaymentMode($db); |
||||
| 471 | if ($companypaymentmode->fetch($ribid ? $ribid : $id)) { |
||||
| 472 | // TODO This is currently done at bottom of page instead of asking confirm |
||||
| 473 | /*if ($companypaymentmode->stripe_card_ref && preg_match('/pm_/', $companypaymentmode->stripe_card_ref)) |
||||
| 474 | { |
||||
| 475 | $payment_method = \Stripe\PaymentMethod::retrieve($companypaymentmode->stripe_card_ref); |
||||
| 476 | if ($payment_method) |
||||
| 477 | { |
||||
| 478 | $payment_method->detach(); |
||||
| 479 | } |
||||
| 480 | }*/ |
||||
| 481 | |||||
| 482 | $result = $companypaymentmode->delete($user); |
||||
| 483 | if ($result > 0) { |
||||
| 484 | $url = $_SERVER['PHP_SELF'] . "?socid=" . $object->id; |
||||
| 485 | |||||
| 486 | header('Location: ' . $url); |
||||
| 487 | exit; |
||||
| 488 | } else { |
||||
| 489 | setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); |
||||
| 490 | } |
||||
| 491 | } else { |
||||
| 492 | setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); |
||||
| 493 | } |
||||
| 494 | } |
||||
| 495 | if ($action == 'confirm_deletebank' && GETPOST('confirm', 'alpha') == 'yes') { |
||||
| 496 | // Delete the bank account |
||||
| 497 | $companybankaccount = new CompanyBankAccount($db); |
||||
| 498 | if ($companybankaccount->fetch($ribid ? $ribid : $id) > 0) { |
||||
| 499 | // TODO This is currently done at bottom of page instead of asking confirm |
||||
| 500 | /*if ($companypaymentmode->stripe_card_ref && preg_match('/pm_/', $companypaymentmode->stripe_card_ref)) |
||||
| 501 | { |
||||
| 502 | $payment_method = \Stripe\PaymentMethod::retrieve($companypaymentmode->stripe_card_ref); |
||||
| 503 | if ($payment_method) |
||||
| 504 | { |
||||
| 505 | $payment_method->detach(); |
||||
| 506 | } |
||||
| 507 | }*/ |
||||
| 508 | |||||
| 509 | $result = $companybankaccount->delete($user); |
||||
| 510 | |||||
| 511 | if ($result > 0) { |
||||
| 512 | $url = $_SERVER['PHP_SELF'] . "?socid=" . $object->id; |
||||
| 513 | |||||
| 514 | header('Location: ' . $url); |
||||
| 515 | exit; |
||||
| 516 | } else { |
||||
| 517 | setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); |
||||
| 518 | } |
||||
| 519 | } else { |
||||
| 520 | setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); |
||||
| 521 | } |
||||
| 522 | } |
||||
| 523 | |||||
| 524 | $savid = $id; |
||||
| 525 | |||||
| 526 | // Actions to build doc |
||||
| 527 | if ($action == 'builddocrib') { |
||||
| 528 | $action = 'builddoc'; |
||||
| 529 | $moreparams = array( |
||||
| 530 | 'use_companybankid' => GETPOST('companybankid'), |
||||
| 531 | 'force_dir_output' => $conf->societe->multidir_output[$object->entity] . '/' . dol_sanitizeFileName($object->id) |
||||
| 532 | ); |
||||
| 533 | $_POST['lang_id'] = GETPOST('lang_idrib' . GETPOSTINT('companybankid'), 'alphanohtml'); // This is required by core/action_builddoc.inc.php |
||||
| 534 | $_POST['model'] = GETPOST('modelrib' . GETPOSTINT('companybankid'), 'alphanohtml'); // This is required by core/action_builddoc.inc.php |
||||
| 535 | } |
||||
| 536 | |||||
| 537 | $id = $socid; |
||||
| 538 | $upload_dir = $conf->societe->multidir_output[$object->entity]; |
||||
| 539 | include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php'; |
||||
| 540 | |||||
| 541 | $id = $savid; |
||||
| 542 | |||||
| 543 | // Action for stripe |
||||
| 544 | if (isModEnabled('stripe') && class_exists('Stripe')) { |
||||
| 545 | if ($action == 'synccustomertostripe' || $action == 'synccustomertostripetest') { |
||||
| 546 | if ($object->client == 0) { |
||||
| 547 | $error++; |
||||
| 548 | setEventMessages('ThisThirdpartyIsNotACustomer', null, 'errors'); |
||||
| 549 | } else { |
||||
| 550 | if ($action == 'synccustomertostripe') { |
||||
| 551 | $tmpservicestatus = 1; |
||||
| 552 | $tmpservice = 'StripeLive'; |
||||
| 553 | } else { |
||||
| 554 | $tmpservicestatus = 0; |
||||
| 555 | $tmpservice = 'StripeTest'; |
||||
| 556 | } |
||||
| 557 | |||||
| 558 | $stripe = new Stripe($db); |
||||
| 559 | $tmpstripeacc = $stripe->getStripeAccount($tmpservice); // Get Stripe OAuth connect account (no remote access to Stripe here) |
||||
| 560 | |||||
| 561 | // Creation of Stripe customer + update of societe_account |
||||
| 562 | $tmpcu = $stripe->customerStripe($object, $tmpstripeacc, $tmpservicestatus, 1); |
||||
| 563 | |||||
| 564 | if (empty($tmpcu)) { |
||||
| 565 | $error++; |
||||
| 566 | setEventMessages($stripe->error, $stripe->errors, 'errors'); |
||||
| 567 | } else { |
||||
| 568 | if ($tmpservicestatus == $servicestatus) { |
||||
| 569 | $stripecu = $tmpcu->id; |
||||
| 570 | } |
||||
| 571 | } |
||||
| 572 | } |
||||
| 573 | } |
||||
| 574 | if ($action == 'synccardtostripe') { |
||||
| 575 | // Create the credit card on current Stripe env |
||||
| 576 | $companypaymentmode = new CompanyPaymentMode($db); |
||||
| 577 | $companypaymentmode->fetch($id); |
||||
| 578 | |||||
| 579 | if ($companypaymentmode->type != 'card') { |
||||
| 580 | $error++; |
||||
| 581 | setEventMessages('ThisPaymentModeIsNotACard', null, 'errors'); |
||||
| 582 | } else { |
||||
| 583 | // Get the Stripe customer |
||||
| 584 | $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus); |
||||
| 585 | if (!$cu) { |
||||
| 586 | $error++; |
||||
| 587 | setEventMessages($stripe->error, $stripe->errors, 'errors'); |
||||
| 588 | } |
||||
| 589 | |||||
| 590 | if (!$error) { |
||||
| 591 | // Creation of Stripe card + update of llx_societe_rib |
||||
| 592 | // Note that with the new Stripe API, option to create a card is no more available, instead an error message will be returned to |
||||
| 593 | // ask to create the crdit card from Stripe backoffice. |
||||
| 594 | $card = $stripe->cardStripe($cu, $companypaymentmode, $stripeacc, $servicestatus, 1); |
||||
| 595 | if (!$card) { |
||||
| 596 | $error++; |
||||
| 597 | setEventMessages($stripe->error, $stripe->errors, 'errors'); |
||||
| 598 | } |
||||
| 599 | } |
||||
| 600 | } |
||||
| 601 | } |
||||
| 602 | if ($action == 'syncsepatostripe') { |
||||
| 603 | // Create the bank account on current Stripe env |
||||
| 604 | $companypaymentmode = new CompanyPaymentMode($db); // Get record in llx_societe_rib |
||||
| 605 | $companypaymentmode->fetch($id); |
||||
| 606 | |||||
| 607 | if ($companypaymentmode->type != 'ban') { |
||||
| 608 | $error++; |
||||
| 609 | $langs->load("errors"); |
||||
| 610 | setEventMessages('ThisPaymentModeIsNotABan', null, 'errors'); |
||||
| 611 | } else { |
||||
| 612 | // Get the Stripe customer |
||||
| 613 | $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus); |
||||
| 614 | // print json_encode($cu); |
||||
| 615 | if (empty($cu)) { |
||||
| 616 | $error++; |
||||
| 617 | $langs->load("errors"); |
||||
| 618 | setEventMessages($langs->trans("ErrorStripeCustomerNotFoundCreateFirst"), null, 'errors'); |
||||
| 619 | } |
||||
| 620 | if (!$error) { |
||||
| 621 | // Creation of Stripe SEPA + update of llx_societe_rib |
||||
| 622 | $card = $stripe->sepaStripe($cu, $companypaymentmode, $stripeacc, $servicestatus, 1); |
||||
| 623 | if (!$card) { |
||||
| 624 | $error++; |
||||
| 625 | setEventMessages($stripe->error, $stripe->errors, 'errors'); |
||||
| 626 | } else { |
||||
| 627 | setEventMessages("", array("Bank Account on Stripe", "BAN is now linked to the Stripe customer account !")); |
||||
| 628 | } |
||||
| 629 | } |
||||
| 630 | } |
||||
| 631 | } |
||||
| 632 | |||||
| 633 | // Set the customer Stripe account (for Live or Test env) |
||||
| 634 | if ($action == 'setkey_account' || $action == 'setkey_accounttest') { |
||||
| 635 | $error = 0; |
||||
| 636 | |||||
| 637 | $tmpservice = 'StripeTest'; |
||||
| 638 | $tmpservicestatus = 0; |
||||
| 639 | if ($action == 'setkey_account') { |
||||
| 640 | $tmpservice = 'StripeLive'; |
||||
| 641 | $tmpservicestatus = 1; |
||||
| 642 | } |
||||
| 643 | |||||
| 644 | // Force to use the correct API key |
||||
| 645 | global $stripearrayofkeysbyenv; |
||||
| 646 | $tmpsite_account = $stripearrayofkeysbyenv[$tmpservicestatus]['publishable_key']; |
||||
| 647 | |||||
| 648 | if ($action == 'setkey_account') { |
||||
| 649 | $newcu = GETPOST('key_account', 'alpha'); |
||||
| 650 | } else { |
||||
| 651 | $newcu = GETPOST('key_accounttest', 'alpha'); |
||||
| 652 | } |
||||
| 653 | |||||
| 654 | $db->begin(); |
||||
| 655 | |||||
| 656 | if (empty($newcu)) { |
||||
| 657 | $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_account WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '" . $db->escape($tmpsite_account) . "') AND fk_soc = " . $object->id . " AND status = " . ((int)$tmpservicestatus) . " AND entity = " . $conf->entity; |
||||
| 658 | } else { |
||||
| 659 | $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . "societe_account"; |
||||
| 660 | $sql .= " WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '" . $db->escape($tmpsite_account) . "') AND fk_soc = " . ((int)$object->id) . " AND status = " . ((int)$tmpservicestatus) . " AND entity = " . $conf->entity; // Keep = here for entity. Only 1 record must be modified ! |
||||
| 661 | } |
||||
| 662 | |||||
| 663 | $resql = $db->query($sql); |
||||
| 664 | $num = $db->num_rows($resql); // Note: $num is always 0 on an update and delete, it is defined for select only. |
||||
| 665 | if (!empty($newcu)) { |
||||
| 666 | if (empty($num)) { |
||||
| 667 | $societeaccount = new SocieteAccount($db); |
||||
| 668 | $societeaccount->fk_soc = $object->id; |
||||
| 669 | $societeaccount->login = ''; |
||||
| 670 | $societeaccount->pass_encoding = ''; |
||||
| 671 | $societeaccount->site = 'stripe'; |
||||
| 672 | $societeaccount->status = $servicestatus; |
||||
| 673 | $societeaccount->key_account = $newcu; |
||||
| 674 | $societeaccount->site_account = $tmpsite_account; |
||||
| 675 | $result = $societeaccount->create($user); |
||||
| 676 | if ($result < 0) { |
||||
| 677 | $error++; |
||||
| 678 | } |
||||
| 679 | } else { |
||||
| 680 | $sql = 'UPDATE ' . MAIN_DB_PREFIX . "societe_account"; |
||||
| 681 | $sql .= " SET key_account = '" . $db->escape($newcu) . "', site_account = '" . $db->escape($tmpsite_account) . "'"; |
||||
| 682 | $sql .= " WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '" . $db->escape($tmpsite_account) . "') AND fk_soc = " . ((int)$object->id) . " AND status = " . ((int)$tmpservicestatus) . " AND entity = " . $conf->entity; // Keep = here for entity. Only 1 record must be modified ! |
||||
| 683 | $resql = $db->query($sql); |
||||
| 684 | } |
||||
| 685 | } |
||||
| 686 | //var_dump($sql); |
||||
| 687 | //var_dump($newcu); |
||||
| 688 | //var_dump($num); exit; |
||||
| 689 | |||||
| 690 | if (!$error) { |
||||
| 691 | if ($tmpservicestatus == $servicestatus) { |
||||
| 692 | $stripecu = $newcu; |
||||
| 693 | } |
||||
| 694 | $db->commit(); |
||||
| 695 | } else { |
||||
| 696 | $db->rollback(); |
||||
| 697 | } |
||||
| 698 | } |
||||
| 699 | |||||
| 700 | // Set the supplier Stripe account (for Live or Test env) |
||||
| 701 | if ($action == 'setkey_account_supplier' || $action == 'setkey_account_suppliertest') { |
||||
| 702 | $error = 0; |
||||
| 703 | |||||
| 704 | $tmpservice = 'StripeTest'; |
||||
| 705 | $tmpservicestatus = 0; |
||||
| 706 | if ($action == 'setkey_account_supplier') { |
||||
| 707 | $tmpservice = 'StripeLive'; |
||||
| 708 | $tmpservicestatus = 1; |
||||
| 709 | } |
||||
| 710 | |||||
| 711 | // Force to use the correct API key |
||||
| 712 | global $stripearrayofkeysbyenv; |
||||
| 713 | $tmpsite_account = $stripearrayofkeysbyenv[$tmpservicestatus]['publishable_key']; |
||||
| 714 | |||||
| 715 | if ($action == 'setkey_account_supplier') { |
||||
| 716 | $newsup = GETPOST('key_account_supplier', 'alpha'); |
||||
| 717 | } else { |
||||
| 718 | $newsup = GETPOST('key_account_suppliertest', 'alpha'); |
||||
| 719 | } |
||||
| 720 | |||||
| 721 | $db->begin(); |
||||
| 722 | |||||
| 723 | if (empty($newsup)) { |
||||
| 724 | $sql = "DELETE FROM " . MAIN_DB_PREFIX . "oauth_token WHERE fk_soc = " . $object->id . " AND service = '" . $db->escape($tmpservice) . "' AND entity = " . $conf->entity; |
||||
| 725 | // TODO Add site and site_account on oauth_token table |
||||
| 726 | //$sql = "DELETE FROM ".MAIN_DB_PREFIX."oauth_token WHERE site = 'stripe' AND (site_account IS NULL or site_account = '".$db->escape($site_account)."') AND fk_soc = ".((int) $object->id)." AND service = '".$db->escape($service)."' AND entity = ".$conf->entity; |
||||
| 727 | } else { |
||||
| 728 | try { |
||||
| 729 | $stripesup = \Stripe\Account::retrieve($newsup); |
||||
| 730 | $tokenstring = array(); |
||||
| 731 | $tokenstring['stripe_user_id'] = $stripesup->id; |
||||
| 732 | $tokenstring['type'] = $stripesup->type; |
||||
| 733 | $sql = "UPDATE " . MAIN_DB_PREFIX . "oauth_token"; |
||||
| 734 | $sql .= " SET tokenstring = '" . $db->escape(json_encode($tokenstring)) . "'"; |
||||
| 735 | $sql .= " WHERE site = 'stripe' AND (site_account IS NULL or site_account = '" . $db->escape($tmpsite_account) . "') AND fk_soc = " . ((int)$object->id) . " AND service = '" . $db->escape($tmpservice) . "' AND entity = " . $conf->entity; // Keep = here for entity. Only 1 record must be modified ! |
||||
| 736 | // TODO Add site and site_account on oauth_token table |
||||
| 737 | $sql .= " WHERE fk_soc = " . $object->id . " AND service = '" . $db->escape($tmpservice) . "' AND entity = " . $conf->entity; // Keep = here for entity. Only 1 record must be modified ! |
||||
| 738 | } catch (Exception $e) { |
||||
| 739 | $error++; |
||||
| 740 | setEventMessages($e->getMessage(), null, 'errors'); |
||||
| 741 | } |
||||
| 742 | } |
||||
| 743 | |||||
| 744 | $resql = $db->query($sql); |
||||
| 745 | $num = $db->num_rows($resql); |
||||
| 746 | if (empty($num) && !empty($newsup)) { |
||||
| 747 | try { |
||||
| 748 | $stripesup = \Stripe\Account::retrieve($newsup); |
||||
| 749 | $tokenstring['stripe_user_id'] = $stripesup->id; |
||||
| 750 | $tokenstring['type'] = $stripesup->type; |
||||
| 751 | $sql = "INSERT INTO " . MAIN_DB_PREFIX . "oauth_token (service, fk_soc, entity, tokenstring)"; |
||||
| 752 | $sql .= " VALUES ('" . $db->escape($tmpservice) . "', " . ((int)$object->id) . ", " . ((int)$conf->entity) . ", '" . $db->escape(json_encode($tokenstring)) . "')"; |
||||
| 753 | // TODO Add site and site_account on oauth_token table |
||||
| 754 | } catch (Exception $e) { |
||||
| 755 | $error++; |
||||
| 756 | setEventMessages($e->getMessage(), null, 'errors'); |
||||
| 757 | } |
||||
| 758 | $resql = $db->query($sql); |
||||
| 759 | } |
||||
| 760 | |||||
| 761 | if (!$error) { |
||||
| 762 | if ($tmpservicestatus == $servicestatus) { |
||||
| 763 | $stripesupplieracc = $newsup; |
||||
| 764 | } |
||||
| 765 | $db->commit(); |
||||
| 766 | } else { |
||||
| 767 | $db->rollback(); |
||||
| 768 | } |
||||
| 769 | } |
||||
| 770 | |||||
| 771 | if ($action == 'setlocalassourcedefault') { // Set as default when payment mode defined locally (and may be also remotely) |
||||
| 772 | try { |
||||
| 773 | $companypaymentmode->setAsDefault($id); |
||||
| 774 | |||||
| 775 | $url = constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id; |
||||
| 776 | header('Location: ' . $url); |
||||
| 777 | exit; |
||||
| 778 | } catch (Exception $e) { |
||||
| 779 | $error++; |
||||
| 780 | setEventMessages($e->getMessage(), null, 'errors'); |
||||
| 781 | } |
||||
| 782 | } elseif ($action == 'setassourcedefault') { // Set as default when payment mode defined remotely only |
||||
| 783 | try { |
||||
| 784 | $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus); |
||||
| 785 | if (preg_match('/pm_|src_/', $source)) { |
||||
| 786 | $cu->invoice_settings->default_payment_method = (string)$source; // New |
||||
| 787 | } else { |
||||
| 788 | $cu->default_source = (string)$source; // Old |
||||
| 789 | } |
||||
| 790 | // @phan-suppress-next-line PhanDeprecatedFunction |
||||
| 791 | $result = $cu->save(); |
||||
| 792 | |||||
| 793 | $url = constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id; |
||||
| 794 | header('Location: ' . $url); |
||||
| 795 | exit; |
||||
| 796 | } catch (Exception $e) { |
||||
| 797 | $error++; |
||||
| 798 | setEventMessages($e->getMessage(), null, 'errors'); |
||||
| 799 | } |
||||
| 800 | } elseif ($action == 'deletecard' && $source) { |
||||
| 801 | // Delete the credit card on Stripe side |
||||
| 802 | try { |
||||
| 803 | if (preg_match('/pm_/', $source)) { |
||||
| 804 | $payment_method = \Stripe\PaymentMethod::retrieve($source, array("stripe_account" => $stripeacc)); |
||||
| 805 | if ($payment_method) { |
||||
| 806 | $payment_method->detach(); |
||||
| 807 | } |
||||
| 808 | } else { |
||||
| 809 | $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus); |
||||
| 810 | $card = $cu->sources->retrieve("$source"); |
||||
| 811 | if ($card) { |
||||
| 812 | // $card->detach(); Does not work with card_, only with src_ |
||||
| 813 | if (method_exists($card, 'detach')) { |
||||
| 814 | $card->detach(); |
||||
| 815 | $sql = "UPDATE " . MAIN_DB_PREFIX . "societe_rib as sr "; |
||||
| 816 | $sql .= " SET stripe_card_ref = null"; |
||||
| 817 | $sql .= " WHERE sr.stripe_card_ref = '" . $db->escape($source) . "'"; |
||||
| 818 | $resql = $db->query($sql); |
||||
| 819 | } else { |
||||
| 820 | $card->delete($user); |
||||
| 821 | } |
||||
| 822 | } |
||||
| 823 | } |
||||
| 824 | |||||
| 825 | $url = constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id; |
||||
| 826 | header('Location: ' . $url); |
||||
| 827 | exit; |
||||
| 828 | } catch (Exception $e) { |
||||
| 829 | $error++; |
||||
| 830 | setEventMessages($e->getMessage(), null, 'errors'); |
||||
| 831 | } |
||||
| 832 | } elseif ($action == 'deletebank' && $source) { |
||||
| 833 | // Delete the bank account on Stripe side |
||||
| 834 | try { |
||||
| 835 | if (preg_match('/pm_/', $source)) { |
||||
| 836 | $payment_method = \Stripe\PaymentMethod::retrieve($source, array("stripe_account" => $stripeacc)); |
||||
| 837 | if ($payment_method) { |
||||
| 838 | $payment_method->detach(); |
||||
| 839 | } |
||||
| 840 | } else { |
||||
| 841 | $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus); |
||||
| 842 | $card = $cu->sources->retrieve("$source"); |
||||
| 843 | if ($card) { |
||||
| 844 | // $card->detach(); Does not work with card_, only with src_ |
||||
| 845 | if (method_exists($card, 'detach')) { |
||||
| 846 | $card->detach(); |
||||
| 847 | $sql = "UPDATE " . MAIN_DB_PREFIX . "societe_rib as sr "; |
||||
| 848 | $sql .= " SET stripe_card_ref = null"; |
||||
| 849 | $sql .= " WHERE sr.stripe_card_ref = '" . $db->escape($source) . "'"; |
||||
| 850 | |||||
| 851 | $resql = $db->query($sql); |
||||
| 852 | } else { |
||||
| 853 | $card->delete($user); |
||||
| 854 | } |
||||
| 855 | } |
||||
| 856 | } |
||||
| 857 | |||||
| 858 | $url = constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id; |
||||
| 859 | if (GETPOSTINT('page_y')) { |
||||
| 860 | $url .= '&page_y=' . GETPOSTINT('page_y'); |
||||
| 861 | } |
||||
| 862 | |||||
| 863 | header('Location: ' . $url); |
||||
| 864 | exit; |
||||
| 865 | } catch (Exception $e) { |
||||
| 866 | $error++; |
||||
| 867 | setEventMessages($e->getMessage(), null, 'errors'); |
||||
| 868 | } |
||||
| 869 | } |
||||
| 870 | } |
||||
| 871 | } |
||||
| 872 | |||||
| 873 | /* |
||||
| 874 | * View |
||||
| 875 | */ |
||||
| 876 | |||||
| 877 | $form = new Form($db); |
||||
| 878 | $formother = new FormOther($db); |
||||
| 879 | $formfile = new FormFile($db); |
||||
| 880 | |||||
| 881 | $title = $langs->trans("ThirdParty"); |
||||
| 882 | if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) { |
||||
| 883 | $title = $object->name . " - " . $langs->trans('PaymentInformation'); |
||||
| 884 | } |
||||
| 885 | $help_url = ''; |
||||
| 886 | |||||
| 887 | ViewMain::llxHeader('', $title, $help_url); |
||||
| 888 | |||||
| 889 | $head = societe_prepare_head($object); |
||||
| 890 | |||||
| 891 | // Show sandbox warning |
||||
| 892 | /*if (isModEnabled('paypal') && (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))) // We can force sand box with param 'forcesandbox' |
||||
| 893 | { |
||||
| 894 | dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Paypal'),'','warning'); |
||||
| 895 | }*/ |
||||
| 896 | if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) { |
||||
| 897 | dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning'); |
||||
| 898 | } |
||||
| 899 | |||||
| 900 | // Load Bank account |
||||
| 901 | if (!$id) { |
||||
| 902 | // @phan-suppress-next-line PhanPluginSuspiciousParamPosition |
||||
| 903 | $companybankaccount->fetch(0, '', $object->id); |
||||
| 904 | // @phan-suppress-next-line PhanPluginSuspiciousParamPosition |
||||
| 905 | $companypaymentmode->fetch(0, null, $object->id, 'card'); |
||||
| 906 | } else { |
||||
| 907 | $companybankaccount->fetch($id); |
||||
| 908 | $companypaymentmode->fetch($id); |
||||
| 909 | } |
||||
| 910 | if (empty($companybankaccount->socid)) { |
||||
| 911 | $companybankaccount->socid = $object->id; |
||||
| 912 | } |
||||
| 913 | |||||
| 914 | if ($socid && ($action == 'edit' || $action == 'editcard') && $permissiontoaddupdatepaymentinformation) { |
||||
| 915 | print '<form action="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '" method="post">'; |
||||
| 916 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||||
| 917 | $actionforadd = 'update'; |
||||
| 918 | if ($action == 'editcard') { |
||||
| 919 | $actionforadd = 'updatecard'; |
||||
| 920 | } |
||||
| 921 | print '<input type="hidden" name="action" value="' . $actionforadd . '">'; |
||||
| 922 | print '<input type="hidden" name="id" value="' . GETPOSTINT("id") . '">'; |
||||
| 923 | } |
||||
| 924 | if ($socid && ($action == 'create' || $action == 'createcard') && $permissiontoaddupdatepaymentinformation) { |
||||
| 925 | print '<form action="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '" method="post">'; |
||||
| 926 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||||
| 927 | $actionforadd = 'add'; |
||||
| 928 | if ($action == 'createcard') { |
||||
| 929 | $actionforadd = 'addcard'; |
||||
| 930 | } |
||||
| 931 | print '<input type="hidden" name="action" value="' . $actionforadd . '">'; |
||||
| 932 | } |
||||
| 933 | |||||
| 934 | |||||
| 935 | // View |
||||
| 936 | if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' && $action != 'createcard') { |
||||
| 937 | print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company'); |
||||
| 938 | |||||
| 939 | // Confirm delete ban |
||||
| 940 | if ($action == 'deletebank') { |
||||
| 941 | print $form->formconfirm($_SERVER["PHP_SELF"] . "?socid=" . $object->id . "&ribid=" . ($ribid ? $ribid : $id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $companybankaccount->getRibLabel()), "confirm_deletebank", '', 0, 1); |
||||
| 942 | } |
||||
| 943 | // Confirm delete card |
||||
| 944 | if ($action == 'deletecard') { |
||||
| 945 | print $form->formconfirm($_SERVER["PHP_SELF"] . "?socid=" . $object->id . "&ribid=" . ($ribid ? $ribid : $id), $langs->trans("DeleteACard"), $langs->trans("ConfirmDeleteCard", $companybankaccount->getRibLabel()), "confirm_deletecard", '', 0, 1); |
||||
| 946 | } |
||||
| 947 | |||||
| 948 | $linkback = '<a href="' . constant('BASE_URL') . '/societe/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>'; |
||||
| 949 | |||||
| 950 | dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); |
||||
| 951 | |||||
| 952 | print '<div class="fichecenter">'; |
||||
| 953 | |||||
| 954 | print '<div class="underbanner clearboth"></div>'; |
||||
| 955 | print '<table class="border tableforfield centpercent">'; |
||||
| 956 | |||||
| 957 | // Type Prospect/Customer/Supplier |
||||
| 958 | print '<tr><td class="titlefield">' . $langs->trans('NatureOfThirdParty') . '</td><td colspan="2">'; |
||||
| 959 | print $object->getTypeUrl(1); |
||||
| 960 | print '</td></tr>'; |
||||
| 961 | |||||
| 962 | if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field |
||||
| 963 | print '<tr><td class="titlefield">' . $langs->trans('Prefix') . '</td><td colspan="2">' . $object->prefix_comm . '</td></tr>'; |
||||
| 964 | } |
||||
| 965 | |||||
| 966 | if ($object->client) { |
||||
| 967 | print '<tr><td class="titlefield">'; |
||||
| 968 | print $langs->trans('CustomerCode') . '</td><td colspan="2">'; |
||||
| 969 | print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client)); |
||||
| 970 | $tmpcheck = $object->check_codeclient(); |
||||
| 971 | if ($tmpcheck != 0 && $tmpcheck != -5) { |
||||
| 972 | print ' <span class="error">(' . $langs->trans("WrongCustomerCode") . ')</span>'; |
||||
| 973 | } |
||||
| 974 | print '</td></tr>'; |
||||
| 975 | $sql = "SELECT count(*) as nb from " . MAIN_DB_PREFIX . "facture where fk_soc = " . ((int)$socid); |
||||
| 976 | $resql = $db->query($sql); |
||||
| 977 | if (!$resql) { |
||||
| 978 | dol_print_error($db); |
||||
| 979 | } |
||||
| 980 | |||||
| 981 | $obj = $db->fetch_object($resql); |
||||
| 982 | $nbFactsClient = $obj->nb; |
||||
| 983 | $thirdTypeArray = array(); |
||||
| 984 | $elementTypeArray = array(); |
||||
| 985 | $thirdTypeArray['customer'] = $langs->trans("customer"); |
||||
| 986 | if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) { |
||||
| 987 | $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals'); |
||||
| 988 | } |
||||
| 989 | if (isModEnabled('order') && $user->hasRight('commande', 'lire')) { |
||||
| 990 | $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders'); |
||||
| 991 | } |
||||
| 992 | if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) { |
||||
| 993 | $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices'); |
||||
| 994 | } |
||||
| 995 | if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) { |
||||
| 996 | $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts'); |
||||
| 997 | } |
||||
| 998 | |||||
| 999 | if (isModEnabled('stripe')) { |
||||
| 1000 | // Force to use the correct API key |
||||
| 1001 | global $stripearrayofkeysbyenv; |
||||
| 1002 | |||||
| 1003 | $tmpservice = 0; |
||||
| 1004 | $tmpsite_account = $stripearrayofkeysbyenv[$tmpservice]['publishable_key']; |
||||
| 1005 | $tmpstripeacc = $stripe->getStripeAccount($tmpservice); // Get Stripe OAuth connect account (no remote access to Stripe here) |
||||
| 1006 | $tmpstripecu = $stripe->getStripeCustomerAccount($object->id, $tmpservice, $tmpsite_account); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here) |
||||
| 1007 | |||||
| 1008 | // Stripe customer key 'cu_....' stored into llx_societe_account |
||||
| 1009 | print '<tr><td class="titlefield">'; |
||||
| 1010 | print $form->editfieldkey($langs->trans("StripeCustomerId") . ' (Test)', 'key_accounttest', $tmpstripecu, $object, $permissiontoaddupdatepaymentinformation, 'string', '', 0, 2, 'socid'); |
||||
| 1011 | print '</td><td>'; |
||||
| 1012 | print $form->editfieldval($langs->trans("StripeCustomerId") . ' (Test)', 'key_accounttest', $tmpstripecu, $object, $permissiontoaddupdatepaymentinformation, 'string', '', null, null, '', 2, '', 'socid'); |
||||
| 1013 | if ($tmpstripecu && $action != 'editkey_accounttest') { |
||||
| 1014 | $connect = ''; |
||||
| 1015 | if (!empty($stripeacc)) { |
||||
| 1016 | $connect = $stripeacc . '/'; |
||||
| 1017 | } |
||||
| 1018 | $url = 'https://dashboard.stripe.com/' . $connect . 'test/customers/' . $tmpstripecu; |
||||
| 1019 | print ' <a href="' . $url . '" target="_stripe">' . img_picto($langs->trans('ShowInStripe') . ' - Publishable key = ' . $tmpsite_account, 'globe') . '</a>'; |
||||
| 1020 | } |
||||
| 1021 | print '</td><td class="right">'; |
||||
| 1022 | if (empty($tmpstripecu)) { |
||||
| 1023 | print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">'; |
||||
| 1024 | print '<input type="hidden" name="action" value="synccustomertostripetest">'; |
||||
| 1025 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||||
| 1026 | print '<input type="hidden" name="socid" value="' . $object->id . '">'; |
||||
| 1027 | print img_picto($langs->trans("CreateCustomerOnStripe"), 'stripe'); |
||||
| 1028 | print '<input type="submit" class="buttonlink nomargintop nomarginbottom noborderbottom nopaddingtopimp nopaddingbottomimp" name="syncstripecustomertest" value="' . $langs->trans("CreateCustomerOnStripe") . '">'; |
||||
| 1029 | print '</form>'; |
||||
| 1030 | } |
||||
| 1031 | print '</td></tr>'; |
||||
| 1032 | |||||
| 1033 | $tmpservice = 1; |
||||
| 1034 | $tmpsite_account = $stripearrayofkeysbyenv[$tmpservice]['publishable_key']; |
||||
| 1035 | $tmpstripeacc = $stripe->getStripeAccount($tmpservice); // Get Stripe OAuth connect account (no remote access to Stripe here) |
||||
| 1036 | $tmpstripecu = $stripe->getStripeCustomerAccount($object->id, $tmpservice, $tmpsite_account); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here) |
||||
| 1037 | |||||
| 1038 | // Stripe customer key 'cu_....' stored into llx_societe_account |
||||
| 1039 | print '<tr><td class="titlefield">'; |
||||
| 1040 | print $form->editfieldkey($langs->trans("StripeCustomerId") . ' (Live)', 'key_account', $tmpstripecu, $object, $permissiontoaddupdatepaymentinformation, 'string', '', 0, 2, 'socid'); |
||||
| 1041 | print '</td><td>'; |
||||
| 1042 | print $form->editfieldval($langs->trans("StripeCustomerId") . ' (Live)', 'key_account', $tmpstripecu, $object, $permissiontoaddupdatepaymentinformation, 'string', '', null, null, '', 2, '', 'socid'); |
||||
| 1043 | if ($tmpstripecu && $action != 'editkey_account') { |
||||
| 1044 | $connect = ''; |
||||
| 1045 | if (!empty($stripeacc)) { |
||||
| 1046 | $connect = $stripeacc . '/'; |
||||
| 1047 | } |
||||
| 1048 | $url = 'https://dashboard.stripe.com/' . $connect . 'customers/' . $tmpstripecu; |
||||
| 1049 | print ' <a href="' . $url . '" target="_stripe">' . img_picto($langs->trans('ShowInStripe') . ' - Publishable key = ' . $tmpsite_account, 'globe') . '</a>'; |
||||
| 1050 | } |
||||
| 1051 | print '</td><td class="right">'; |
||||
| 1052 | if (empty($tmpstripecu)) { |
||||
| 1053 | print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">'; |
||||
| 1054 | print '<input type="hidden" name="action" value="synccustomertostripe">'; |
||||
| 1055 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||||
| 1056 | print '<input type="hidden" name="socid" value="' . $object->id . '">'; |
||||
| 1057 | print img_picto($langs->trans("CreateCustomerOnStripe"), 'stripe'); |
||||
| 1058 | print '<input type="submit" class="buttonlink nomargintop nomarginbottom noborderbottom nopaddingtopimp nopaddingbottomimp" name="syncstripecustomer" value="' . $langs->trans("CreateCustomerOnStripe") . '">'; |
||||
| 1059 | print '</form>'; |
||||
| 1060 | } |
||||
| 1061 | print '</td></tr>'; |
||||
| 1062 | } |
||||
| 1063 | } |
||||
| 1064 | |||||
| 1065 | if ($object->fournisseur) { |
||||
| 1066 | print '<tr><td class="titlefield">'; |
||||
| 1067 | print $langs->trans('SupplierCode') . '</td><td colspan="2">'; |
||||
| 1068 | print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur)); |
||||
| 1069 | $tmpcheck = $object->check_codefournisseur(); |
||||
| 1070 | if ($tmpcheck != 0 && $tmpcheck != -5) { |
||||
| 1071 | print ' <span class="error">(' . $langs->trans("WrongSupplierCode") . ')</span>'; |
||||
| 1072 | } |
||||
| 1073 | print '</td></tr>'; |
||||
| 1074 | $sql = "SELECT count(*) as nb from " . MAIN_DB_PREFIX . "facture where fk_soc = " . ((int)$socid); |
||||
| 1075 | $resql = $db->query($sql); |
||||
| 1076 | if (!$resql) { |
||||
| 1077 | dol_print_error($db); |
||||
| 1078 | } |
||||
| 1079 | $obj = $db->fetch_object($resql); |
||||
| 1080 | $nbFactsClient = $obj->nb; |
||||
| 1081 | $thirdTypeArray['customer'] = $langs->trans("customer"); |
||||
| 1082 | if (isModEnabled('propal') && $user->hasRight('propal', 'lire')) { |
||||
| 1083 | $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals'); |
||||
| 1084 | } |
||||
| 1085 | if (isModEnabled('order') && $user->hasRight('commande', 'lire')) { |
||||
| 1086 | $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders'); |
||||
| 1087 | } |
||||
| 1088 | if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) { |
||||
| 1089 | $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices'); |
||||
| 1090 | } |
||||
| 1091 | if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) { |
||||
| 1092 | $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts'); |
||||
| 1093 | } |
||||
| 1094 | } |
||||
| 1095 | |||||
| 1096 | // Stripe connect |
||||
| 1097 | if (isModEnabled('stripe') && !empty($conf->stripeconnect->enabled) && getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { |
||||
| 1098 | $stripesupplieracc = $stripe->getStripeAccount($service, $object->id); // Get Stripe OAuth connect account (no network access here) |
||||
| 1099 | |||||
| 1100 | // Stripe customer key 'cu_....' stored into llx_societe_account |
||||
| 1101 | print '<tr><td class="titlefield">'; |
||||
| 1102 | print $form->editfieldkey("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, $permissiontoaddupdatepaymentinformation, 'string', '', 0, 2, 'socid'); |
||||
| 1103 | print '</td><td>'; |
||||
| 1104 | print $form->editfieldval("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, $permissiontoaddupdatepaymentinformation, 'string', '', null, null, '', 2, '', 'socid'); |
||||
| 1105 | if (isModEnabled('stripe') && $stripesupplieracc && $action != 'editkey_account_supplier') { |
||||
| 1106 | $connect = ''; |
||||
| 1107 | |||||
| 1108 | $url = 'https://dashboard.stripe.com/test/connect/accounts/' . $stripesupplieracc; |
||||
| 1109 | if ($servicestatus) { |
||||
| 1110 | $url = 'https://dashboard.stripe.com/connect/accounts/' . $stripesupplieracc; |
||||
| 1111 | } |
||||
| 1112 | print ' <a href="' . $url . '" target="_stripe">' . img_picto($langs->trans('ShowInStripe') . ' - Publishable key ' . $site_account, 'globe') . '</a>'; |
||||
| 1113 | } |
||||
| 1114 | print '</td><td class="right">'; |
||||
| 1115 | if (empty($stripesupplieracc)) { |
||||
| 1116 | print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">'; |
||||
| 1117 | print '<input type="hidden" name="action" value="syncsuppliertostripe">'; |
||||
| 1118 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||||
| 1119 | print '<input type="hidden" name="socid" value="' . $object->id . '">'; |
||||
| 1120 | print '<input type="hidden" name="companybankid" value="' . $rib->id . '">'; |
||||
| 1121 | //print '<input type="submit" class="button buttongen" name="syncstripecustomer" value="'.$langs->trans("CreateSupplierOnStripe").'">'; |
||||
| 1122 | print '</form>'; |
||||
| 1123 | } |
||||
| 1124 | print '</td></tr>'; |
||||
| 1125 | } |
||||
| 1126 | |||||
| 1127 | print '</table>'; |
||||
| 1128 | print '</div>'; |
||||
| 1129 | |||||
| 1130 | print dol_get_fiche_end(); |
||||
| 1131 | |||||
| 1132 | print '<br>'; |
||||
| 1133 | |||||
| 1134 | $showcardpaymentmode = 0; |
||||
| 1135 | if (isModEnabled('stripe')) { |
||||
| 1136 | $showcardpaymentmode++; |
||||
| 1137 | } |
||||
| 1138 | |||||
| 1139 | // Get list of remote payment modes |
||||
| 1140 | $listofsources = array(); |
||||
| 1141 | |||||
| 1142 | if (isset($stripe) && is_object($stripe)) { |
||||
| 1143 | try { |
||||
| 1144 | $customerstripe = $stripe->customerStripe($object, $stripeacc, $servicestatus); |
||||
| 1145 | if (!empty($customerstripe->id)) { |
||||
| 1146 | // When using the Charge API architecture |
||||
| 1147 | if (!getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) { |
||||
| 1148 | $listofsources = $customerstripe->sources->data; |
||||
| 1149 | } else { |
||||
| 1150 | $service = 'StripeTest'; |
||||
| 1151 | $servicestatus = 0; |
||||
| 1152 | if (getDolGlobalString('STRIPE_LIVE') && !GETPOST('forcesandbox', 'alpha')) { |
||||
| 1153 | $service = 'StripeLive'; |
||||
| 1154 | $servicestatus = 1; |
||||
| 1155 | } |
||||
| 1156 | |||||
| 1157 | // Force to use the correct API key |
||||
| 1158 | global $stripearrayofkeysbyenv; |
||||
| 1159 | \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']); |
||||
| 1160 | |||||
| 1161 | try { |
||||
| 1162 | if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage |
||||
| 1163 | $paymentmethodobjsA = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "card")); |
||||
| 1164 | $paymentmethodobjsB = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "sepa_debit")); |
||||
| 1165 | } else { |
||||
| 1166 | $paymentmethodobjsA = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "card"), array("stripe_account" => $stripeacc)); |
||||
| 1167 | $paymentmethodobjsB = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "sepa_debit"), array("stripe_account" => $stripeacc)); |
||||
| 1168 | } |
||||
| 1169 | |||||
| 1170 | if ($paymentmethodobjsA->data != null && $paymentmethodobjsB->data != null) { |
||||
| 1171 | $listofsources = array_merge((array)$paymentmethodobjsA->data, (array)$paymentmethodobjsB->data); |
||||
| 1172 | } elseif ($paymentmethodobjsB->data != null) { |
||||
| 1173 | $listofsources = $paymentmethodobjsB->data; |
||||
| 1174 | } else { |
||||
| 1175 | $listofsources = $paymentmethodobjsA->data; |
||||
| 1176 | } |
||||
| 1177 | } catch (Exception $e) { |
||||
| 1178 | $error++; |
||||
| 1179 | setEventMessages($e->getMessage(), null, 'errors'); |
||||
| 1180 | } |
||||
| 1181 | } |
||||
| 1182 | } |
||||
| 1183 | } catch (Exception $e) { |
||||
| 1184 | dol_syslog("Error when searching/loading Stripe customer for thirdparty id =" . $object->id); |
||||
| 1185 | } |
||||
| 1186 | } |
||||
| 1187 | |||||
| 1188 | |||||
| 1189 | // List of Card payment modes |
||||
| 1190 | if ($showcardpaymentmode && $object->client) { |
||||
| 1191 | $morehtmlright = ''; |
||||
| 1192 | if (getDolGlobalString('STRIPE_ALLOW_LOCAL_CARD')) { |
||||
| 1193 | $morehtmlright .= dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&action=createcard'); |
||||
| 1194 | } |
||||
| 1195 | print load_fiche_titre($langs->trans('CreditCard'), $morehtmlright, 'fa-credit-card'); |
||||
| 1196 | //($stripeacc ? ' (Stripe connection with StripeConnect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)') |
||||
| 1197 | |||||
| 1198 | print '<!-- List of card payments -->' . "\n"; |
||||
| 1199 | print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table |
||||
| 1200 | print '<table class="liste centpercent">' . "\n"; |
||||
| 1201 | print '<tr class="liste_titre">'; |
||||
| 1202 | print '<td>' . $langs->trans('Label') . '</td>'; |
||||
| 1203 | print '<td>' . $form->textwithpicto($langs->trans('ExternalSystemID'), $langs->trans("IDOfPaymentInAnExternalSystem")) . '</td>'; // external system ID |
||||
| 1204 | print '<td>' . $langs->trans('Type') . '</td>'; |
||||
| 1205 | print '<td>' . $langs->trans('Informations') . '</td>'; |
||||
| 1206 | print '<td></td>'; |
||||
| 1207 | print '<td class="center">' . $langs->trans('Default') . '</td>'; |
||||
| 1208 | print '<td>' . $langs->trans('Note') . '</td>'; |
||||
| 1209 | print '<td>' . $langs->trans('DateModification') . '</td>'; |
||||
| 1210 | // Hook fields |
||||
| 1211 | $parameters = array('arrayfields' => array(), 'param' => '', 'sortfield' => '', 'sortorder' => '', 'linetype' => 'stripetitle'); |
||||
| 1212 | $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook |
||||
| 1213 | print $hookmanager->resPrint; |
||||
| 1214 | // Action column |
||||
| 1215 | print "<td></td>"; |
||||
| 1216 | print "</tr>\n"; |
||||
| 1217 | |||||
| 1218 | $nbremote = 0; |
||||
| 1219 | $nblocal = 0; |
||||
| 1220 | $arrayofremotecard = array(); |
||||
| 1221 | |||||
| 1222 | // Show local sources |
||||
| 1223 | if (getDolGlobalString('STRIPE_ALLOW_LOCAL_CARD')) { |
||||
| 1224 | //$societeaccount = new SocieteAccount($db); |
||||
| 1225 | $companypaymentmodetemp = new CompanyPaymentMode($db); |
||||
| 1226 | |||||
| 1227 | $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . "societe_rib"; |
||||
| 1228 | $sql .= " WHERE type in ('card')"; |
||||
| 1229 | $sql .= " AND fk_soc = " . ((int)$object->id); |
||||
| 1230 | $sql .= " AND status = " . ((int)$servicestatus); |
||||
| 1231 | |||||
| 1232 | $resql = $db->query($sql); |
||||
| 1233 | if ($resql) { |
||||
| 1234 | $num_rows = $db->num_rows($resql); |
||||
| 1235 | if ($num_rows) { |
||||
| 1236 | $i = 0; |
||||
| 1237 | while ($i < $num_rows) { |
||||
| 1238 | $nblocal++; |
||||
| 1239 | |||||
| 1240 | $obj = $db->fetch_object($resql); |
||||
| 1241 | if ($obj) { |
||||
| 1242 | $companypaymentmodetemp->fetch($obj->rowid); |
||||
| 1243 | |||||
| 1244 | $arrayofremotecard[$companypaymentmodetemp->stripe_card_ref] = $companypaymentmodetemp->stripe_card_ref; |
||||
| 1245 | |||||
| 1246 | print '<tr class="oddeven" data-rowid="' . ((int)$companypaymentmodetemp->id) . '">'; |
||||
| 1247 | // Label |
||||
| 1248 | print '<td class="tdoverflowmax150" title="' . dol_escape_htmltag($companypaymentmodetemp->label) . '">'; |
||||
| 1249 | print dol_escape_htmltag($companypaymentmodetemp->label); |
||||
| 1250 | print '</td>'; |
||||
| 1251 | // External system card ID |
||||
| 1252 | print '<td class="tdoverflowmax150" title="' . dol_escape_htmltag($companypaymentmodetemp->stripe_card_ref . (empty($companypaymentmodetemp->stripe_account) ? '' : ' - ' . $companypaymentmodetemp->stripe_account)) . '">'; |
||||
| 1253 | if (!empty($companypaymentmodetemp->stripe_card_ref) && !empty($companypaymentmodetemp->ext_payment_site)) { |
||||
| 1254 | if (isModEnabled('stripe') && in_array($companypaymentmodetemp->ext_payment_site, array('StripeTest', 'StripeLive'))) { |
||||
| 1255 | $connect = ''; |
||||
| 1256 | if (!empty($stripeacc)) { |
||||
| 1257 | $connect = $stripeacc . '/'; |
||||
| 1258 | } |
||||
| 1259 | if ($companypaymentmodetemp->ext_payment_site == 'StripeLive') { |
||||
| 1260 | $url = 'https://dashboard.stripe.com/' . $connect . 'search?query=' . $companypaymentmodetemp->stripe_card_ref; |
||||
| 1261 | } else { |
||||
| 1262 | $url = 'https://dashboard.stripe.com/' . $connect . 'test/search?query=' . $companypaymentmodetemp->stripe_card_ref; |
||||
| 1263 | } |
||||
| 1264 | print "<a href='" . $url . "' target='_stripe'>" . img_picto($langs->trans('ShowInStripe') . ' - ' . $companypaymentmodetemp->stripe_account, 'globe') . "</a> "; |
||||
| 1265 | } |
||||
| 1266 | // TODO Add hook here for other payment services |
||||
| 1267 | } |
||||
| 1268 | print dol_escape_htmltag($companypaymentmodetemp->stripe_card_ref); |
||||
| 1269 | print '</td>'; |
||||
| 1270 | // Type |
||||
| 1271 | print '<td>'; |
||||
| 1272 | print img_credit_card($companypaymentmodetemp->type); |
||||
| 1273 | print '</td>'; |
||||
| 1274 | // Information (Owner, ...) |
||||
| 1275 | print '<td class="minwidth100">'; |
||||
| 1276 | if ($companypaymentmodetemp->proprio) { |
||||
| 1277 | print '<span class="opacitymedium">' . $companypaymentmodetemp->proprio . '</span><br>'; |
||||
| 1278 | } |
||||
| 1279 | if ($companypaymentmodetemp->last_four) { |
||||
| 1280 | print '....' . $companypaymentmodetemp->last_four; |
||||
| 1281 | } |
||||
| 1282 | if ($companypaymentmodetemp->exp_date_month || $companypaymentmodetemp->exp_date_year) { |
||||
| 1283 | print ' - ' . sprintf("%02d", $companypaymentmodetemp->exp_date_month) . '/' . $companypaymentmodetemp->exp_date_year; |
||||
| 1284 | } |
||||
| 1285 | print '</td>'; |
||||
| 1286 | // Country |
||||
| 1287 | print '<td class="tdoverflowmax100">'; |
||||
| 1288 | if ($companypaymentmodetemp->country_code) { |
||||
| 1289 | $img = picto_from_langcode($companypaymentmodetemp->country_code); |
||||
| 1290 | print $img ? $img . ' ' : ''; |
||||
| 1291 | print getCountry($companypaymentmodetemp->country_code, 1); |
||||
| 1292 | } else { |
||||
| 1293 | print img_warning() . ' <span class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")) . '</span>'; |
||||
| 1294 | } |
||||
| 1295 | print '</td>'; |
||||
| 1296 | // Default |
||||
| 1297 | print '<td class="center">'; |
||||
| 1298 | if (empty($companypaymentmodetemp->default_rib)) { |
||||
| 1299 | print '<a href="' . constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id . '&id=' . $companypaymentmodetemp->id . '&action=setlocalassourcedefault&token=' . newToken() . '">'; |
||||
| 1300 | print img_picto($langs->trans("Default"), 'off'); |
||||
| 1301 | print '</a>'; |
||||
| 1302 | } else { |
||||
| 1303 | print img_picto($langs->trans("Default"), 'on'); |
||||
| 1304 | } |
||||
| 1305 | print '</td>'; |
||||
| 1306 | if (empty($companypaymentmodetemp->stripe_card_ref)) { |
||||
| 1307 | $s = $langs->trans("Local"); |
||||
| 1308 | } else { |
||||
| 1309 | $s = $langs->trans("LocalAndRemote"); |
||||
| 1310 | } |
||||
| 1311 | print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($s) . '">'; |
||||
| 1312 | print $s; |
||||
| 1313 | print '</td>'; |
||||
| 1314 | print '<td>'; |
||||
| 1315 | print dol_print_date($companypaymentmodetemp->date_modification, 'dayhour', 'tzuserrel'); |
||||
| 1316 | print '</td>'; |
||||
| 1317 | // Fields from hook |
||||
| 1318 | $parameters = array('arrayfields' => array(), 'obj' => $obj, 'linetype' => 'stripecard'); |
||||
| 1319 | $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook |
||||
| 1320 | print $hookmanager->resPrint; |
||||
| 1321 | // Action column |
||||
| 1322 | print '<td class="right minwidth50 nowraponall">'; |
||||
| 1323 | if ($permissiontoaddupdatepaymentinformation) { |
||||
| 1324 | if ($stripecu && empty($companypaymentmodetemp->stripe_card_ref)) { |
||||
| 1325 | print '<a href="' . $_SERVER['PHP_SELF'] . '?action=synccardtostripe&socid=' . $object->id . '&id=' . $companypaymentmodetemp->id . '" class="paddingrightonly marginrightonly">' . $langs->trans("CreateCardOnStripe") . '</a>'; |
||||
| 1326 | } |
||||
| 1327 | |||||
| 1328 | print '<a class="editfielda marginleftonly marginrightonly" href="' . constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id . '&id=' . $companypaymentmodetemp->id . '&action=editcard&token=' . newToken() . '">'; |
||||
| 1329 | print img_picto($langs->trans("Modify"), 'edit'); |
||||
| 1330 | print '</a>'; |
||||
| 1331 | print '<a class="marginleftonly marginrightonly" href="' . constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id . '&id=' . $companypaymentmodetemp->id . '&action=deletecard&token=' . newToken() . '">'; // source='.$companypaymentmodetemp->stripe_card_ref.'& |
||||
| 1332 | print img_picto($langs->trans("Delete"), 'delete'); |
||||
| 1333 | print '</a>'; |
||||
| 1334 | } |
||||
| 1335 | print '</td>'; |
||||
| 1336 | print '</tr>'; |
||||
| 1337 | } |
||||
| 1338 | $i++; |
||||
| 1339 | } |
||||
| 1340 | } |
||||
| 1341 | } else { |
||||
| 1342 | dol_print_error($db); |
||||
| 1343 | } |
||||
| 1344 | } |
||||
| 1345 | |||||
| 1346 | // Show remote sources (not already shown as local source) |
||||
| 1347 | if (is_array($listofsources) && count($listofsources)) { |
||||
| 1348 | foreach ($listofsources as $src) { |
||||
| 1349 | if (!empty($arrayofremotecard[$src->id])) { |
||||
| 1350 | continue; // Already in previous list |
||||
| 1351 | } |
||||
| 1352 | |||||
| 1353 | $nbremote++; |
||||
| 1354 | |||||
| 1355 | $imgline = ''; |
||||
| 1356 | if ($src->object == 'card') { |
||||
| 1357 | $imgline = img_credit_card($src->brand); |
||||
| 1358 | } elseif ($src->object == 'source' && $src->type == 'card') { |
||||
| 1359 | $imgline = img_credit_card($src->card->brand); |
||||
| 1360 | } elseif ($src->object == 'payment_method' && $src->type == 'card') { |
||||
| 1361 | $imgline = img_credit_card($src->card->brand); |
||||
| 1362 | } elseif ($src->object == 'source' && $src->type == 'sepa_debit') { |
||||
| 1363 | continue; |
||||
| 1364 | } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit') { |
||||
| 1365 | continue; |
||||
| 1366 | } |
||||
| 1367 | |||||
| 1368 | print '<tr class="oddeven">'; |
||||
| 1369 | print '<td>'; |
||||
| 1370 | print '</td>'; |
||||
| 1371 | // Src ID |
||||
| 1372 | print '<td class="tdoverflowmax150">'; |
||||
| 1373 | $connect = ''; |
||||
| 1374 | if (!empty($stripeacc)) { |
||||
| 1375 | $connect = $stripeacc . '/'; |
||||
| 1376 | } |
||||
| 1377 | //$url='https://dashboard.stripe.com/'.$connect.'test/sources/'.$src->id; |
||||
| 1378 | $url = 'https://dashboard.stripe.com/' . $connect . 'test/search?query=' . $src->id; |
||||
| 1379 | if ($servicestatus) { |
||||
| 1380 | //$url='https://dashboard.stripe.com/'.$connect.'sources/'.$src->id; |
||||
| 1381 | $url = 'https://dashboard.stripe.com/' . $connect . 'search?query=' . $src->id; |
||||
| 1382 | } |
||||
| 1383 | print "<a href='" . $url . "' target='_stripe'>" . img_picto($langs->trans('ShowInStripe'), 'globe') . "</a> "; |
||||
| 1384 | print $src->id; |
||||
| 1385 | print '</td>'; |
||||
| 1386 | // Img |
||||
| 1387 | print '<td>'; |
||||
| 1388 | print $imgline; |
||||
| 1389 | print'</td>'; |
||||
| 1390 | // Information |
||||
| 1391 | print '<td valign="middle">'; |
||||
| 1392 | if ($src->object == 'card') { |
||||
| 1393 | print '....' . $src->last4 . ' - ' . $src->exp_month . '/' . $src->exp_year; |
||||
| 1394 | print '</td><td>'; |
||||
| 1395 | if ($src->country) { |
||||
| 1396 | $img = picto_from_langcode($src->country); |
||||
| 1397 | print $img ? $img . ' ' : ''; |
||||
| 1398 | print getCountry($src->country, 1); |
||||
| 1399 | } else { |
||||
| 1400 | print img_warning() . ' <span class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")) . '</span>'; |
||||
| 1401 | } |
||||
| 1402 | } elseif ($src->object == 'source' && $src->type == 'card') { |
||||
| 1403 | print '<span class="opacitymedium">' . $src->owner->name . '</span><br>....' . $src->card->last4 . ' - ' . $src->card->exp_month . '/' . $src->card->exp_year; |
||||
| 1404 | print '</td><td>'; |
||||
| 1405 | |||||
| 1406 | if ($src->card->country) { |
||||
| 1407 | $img = picto_from_langcode($src->card->country); |
||||
| 1408 | print $img ? $img . ' ' : ''; |
||||
| 1409 | print getCountry($src->card->country, 1); |
||||
| 1410 | } else { |
||||
| 1411 | print img_warning() . ' <span class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")) . '</span>'; |
||||
| 1412 | } |
||||
| 1413 | } elseif ($src->object == 'source' && $src->type == 'sepa_debit') { |
||||
| 1414 | print '<span class="opacitymedium">' . $src->billing_details->name . '</span><br>....' . $src->sepa_debit->last4; |
||||
| 1415 | print '</td><td>'; |
||||
| 1416 | if ($src->sepa_debit->country) { |
||||
| 1417 | $img = picto_from_langcode($src->sepa_debit->country); |
||||
| 1418 | print $img ? $img . ' ' : ''; |
||||
| 1419 | print getCountry($src->sepa_debit->country, 1); |
||||
| 1420 | } else { |
||||
| 1421 | print img_warning() . ' <span class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")) . '</span>'; |
||||
| 1422 | } |
||||
| 1423 | } elseif ($src->object == 'payment_method' && $src->type == 'card') { |
||||
| 1424 | print '<span class="opacitymedium">' . $src->billing_details->name . '</span><br>....' . $src->card->last4 . ' - ' . $src->card->exp_month . '/' . $src->card->exp_year; |
||||
| 1425 | print '</td><td>'; |
||||
| 1426 | |||||
| 1427 | if ($src->card->country) { |
||||
| 1428 | $img = picto_from_langcode($src->card->country); |
||||
| 1429 | print $img ? $img . ' ' : ''; |
||||
| 1430 | print getCountry($src->card->country, 1); |
||||
| 1431 | } else { |
||||
| 1432 | print img_warning() . ' <span class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")) . '</span>'; |
||||
| 1433 | } |
||||
| 1434 | } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit') { |
||||
| 1435 | print '<span class="opacitymedium">' . $src->billing_details->name . '</span><br>....' . $src->sepa_debit->last4; |
||||
| 1436 | print '</td><td>'; |
||||
| 1437 | if ($src->sepa_debit->country) { |
||||
| 1438 | $img = picto_from_langcode($src->sepa_debit->country); |
||||
| 1439 | print $img ? $img . ' ' : ''; |
||||
| 1440 | print getCountry($src->sepa_debit->country, 1); |
||||
| 1441 | } else { |
||||
| 1442 | print img_warning() . ' <span class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")) . '</span>'; |
||||
| 1443 | } |
||||
| 1444 | } else { |
||||
| 1445 | print '</td><td>'; |
||||
| 1446 | } |
||||
| 1447 | print '</td>'; |
||||
| 1448 | // Default |
||||
| 1449 | print '<td class="center" width="50">'; |
||||
| 1450 | if ( |
||||
| 1451 | (empty($customerstripe->invoice_settings) && $customerstripe->default_source != $src->id) || |
||||
| 1452 | (!empty($customerstripe->invoice_settings) && $customerstripe->invoice_settings->default_payment_method != $src->id) |
||||
| 1453 | ) { |
||||
| 1454 | print '<a href="' . constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id . '&source=' . $src->id . '&action=setassourcedefault&token=' . newToken() . '">'; |
||||
| 1455 | print img_picto($langs->trans("Default"), 'off'); |
||||
| 1456 | print '</a>'; |
||||
| 1457 | } else { |
||||
| 1458 | print img_picto($langs->trans("Default"), 'on'); |
||||
| 1459 | } |
||||
| 1460 | print '</td>'; |
||||
| 1461 | print '<td>'; |
||||
| 1462 | print $langs->trans("Remote"); |
||||
| 1463 | //if ($src->cvc_check == 'fail') print ' - CVC check fail'; |
||||
| 1464 | print '</td>'; |
||||
| 1465 | |||||
| 1466 | print '<td>'; |
||||
| 1467 | //var_dump($src); |
||||
| 1468 | print '</td>'; |
||||
| 1469 | |||||
| 1470 | // Fields from hook |
||||
| 1471 | $parameters = array('arrayfields' => array(), 'stripesource' => $src, 'linetype' => 'stripecardremoteonly'); |
||||
| 1472 | $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook |
||||
| 1473 | print $hookmanager->resPrint; |
||||
| 1474 | |||||
| 1475 | // Action column |
||||
| 1476 | print '<td class="right nowraponall">'; |
||||
| 1477 | if ($permissiontoaddupdatepaymentinformation) { |
||||
| 1478 | print '<a class="marginleftonly marginrightonly" href="' . constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id . '&source=' . $src->id . '&action=deletecard&token=' . newToken() . '">'; |
||||
| 1479 | print img_picto($langs->trans("Delete"), 'delete'); |
||||
| 1480 | print '</a>'; |
||||
| 1481 | } |
||||
| 1482 | print '</td>'; |
||||
| 1483 | |||||
| 1484 | print '</tr>'; |
||||
| 1485 | } |
||||
| 1486 | } |
||||
| 1487 | |||||
| 1488 | if ($nbremote == 0 && $nblocal == 0) { |
||||
| 1489 | $colspan = (getDolGlobalString('STRIPE_ALLOW_LOCAL_CARD') ? 10 : 9); |
||||
| 1490 | print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>'; |
||||
| 1491 | } |
||||
| 1492 | print "</table>"; |
||||
| 1493 | print "</div>"; |
||||
| 1494 | print '<br>'; |
||||
| 1495 | } |
||||
| 1496 | |||||
| 1497 | // List of Stripe connect accounts |
||||
| 1498 | if (isModEnabled('stripe') && !empty($conf->stripeconnect->enabled) && !empty($stripesupplieracc)) { |
||||
| 1499 | print load_fiche_titre($langs->trans('StripeBalance') . ($stripesupplieracc ? ' (Stripe connection with StripeConnect account ' . $stripesupplieracc . ')' : ' (Stripe connection with keys from Stripe module setup)'), $morehtmlright, 'stripe-s'); |
||||
| 1500 | $balance = \Stripe\Balance::retrieve(array("stripe_account" => $stripesupplieracc)); |
||||
| 1501 | print '<table class="liste centpercent">' . "\n"; |
||||
| 1502 | print '<tr class="liste_titre">'; |
||||
| 1503 | print '<td>' . $langs->trans('Currency') . '</td>'; |
||||
| 1504 | print '<td>' . $langs->trans('Available') . '</td>'; |
||||
| 1505 | print '<td>' . $langs->trans('Pending') . '</td>'; |
||||
| 1506 | print '<td>' . $langs->trans('Total') . '</td>'; |
||||
| 1507 | print '</tr>'; |
||||
| 1508 | |||||
| 1509 | $currencybalance = array(); |
||||
| 1510 | if (is_array($balance->available) && count($balance->available)) { |
||||
| 1511 | foreach ($balance->available as $cpt) { |
||||
| 1512 | $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'); |
||||
| 1513 | if (!in_array($cpt->currency, $arrayzerounitcurrency)) { |
||||
| 1514 | $currencybalance[$cpt->currency]['available'] = $cpt->amount / 100; |
||||
| 1515 | } else { |
||||
| 1516 | $currencybalance[$cpt->currency]['available'] = $cpt->amount; |
||||
| 1517 | } |
||||
| 1518 | $currencybalance[$cpt->currency]['currency'] = $cpt->currency; |
||||
| 1519 | } |
||||
| 1520 | } |
||||
| 1521 | |||||
| 1522 | if (is_array($balance->pending) && count($balance->pending)) { |
||||
| 1523 | foreach ($balance->pending as $cpt) { |
||||
| 1524 | $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'); |
||||
| 1525 | if (!in_array($cpt->currency, $arrayzerounitcurrency)) { |
||||
| 1526 | $currencybalance[$cpt->currency]['pending'] = $currencybalance[$cpt->currency]['available'] + $cpt->amount / 100; |
||||
| 1527 | } else { |
||||
| 1528 | $currencybalance[$cpt->currency]['pending'] = $currencybalance[$cpt->currency]['available'] + $cpt->amount; |
||||
| 1529 | } |
||||
| 1530 | } |
||||
| 1531 | } |
||||
| 1532 | |||||
| 1533 | if (is_array($currencybalance)) { |
||||
| 1534 | foreach ($currencybalance as $cpt) { |
||||
| 1535 | print '<tr><td>' . $langs->trans("Currency" . strtoupper($cpt['currency'])) . '</td><td>' . price($cpt['available'], 0, '', 1, -1, -1, strtoupper($cpt['currency'])) . '</td><td>' . price(isset($cpt->pending) ? $cpt->pending : 0, 0, '', 1, -1, -1, strtoupper($cpt['currency'])) . '</td><td>' . price($cpt['available'] + (isset($cpt->pending) ? $cpt->pending : 0), 0, '', 1, -1, -1, strtoupper($cpt['currency'])) . '</td></tr>'; |
||||
| 1536 | } |
||||
| 1537 | } |
||||
| 1538 | |||||
| 1539 | print '</table>'; |
||||
| 1540 | print '<br>'; |
||||
| 1541 | } |
||||
| 1542 | |||||
| 1543 | // List of bank accounts |
||||
| 1544 | if ($permissiontoaddupdatepaymentinformation) { |
||||
| 1545 | $morehtmlright = dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&action=create'); |
||||
| 1546 | } |
||||
| 1547 | |||||
| 1548 | print load_fiche_titre($langs->trans("BankAccounts"), $morehtmlright, 'bank'); |
||||
| 1549 | |||||
| 1550 | $nblocal = 0; |
||||
| 1551 | $nbremote = 0; |
||||
| 1552 | $arrayofremoteban = array(); |
||||
| 1553 | |||||
| 1554 | $rib_list = $object->get_all_rib(); |
||||
| 1555 | |||||
| 1556 | if (is_array($rib_list)) { |
||||
| 1557 | print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table |
||||
| 1558 | print '<table class="liste centpercent">'; |
||||
| 1559 | |||||
| 1560 | print '<tr class="liste_titre">'; |
||||
| 1561 | print_liste_field_titre("Label"); |
||||
| 1562 | print_liste_field_titre($form->textwithpicto($langs->trans('ExternalSystemID'), $langs->trans("IDOfPaymentInAnExternalSystem"))); // external system ID |
||||
| 1563 | print_liste_field_titre("Bank"); |
||||
| 1564 | print_liste_field_titre("RIB"); |
||||
| 1565 | print_liste_field_titre("IBAN"); |
||||
| 1566 | print_liste_field_titre("BIC"); |
||||
| 1567 | if (isModEnabled('prelevement')) { |
||||
| 1568 | print_liste_field_titre("RUM"); |
||||
| 1569 | print_liste_field_titre("DateRUM"); |
||||
| 1570 | print_liste_field_titre("WithdrawMode"); |
||||
| 1571 | } |
||||
| 1572 | print_liste_field_titre("Default", '', '', '', '', '', '', '', 'center '); |
||||
| 1573 | if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT') && getDolGlobalInt("SOCIETE_RIB_ALLOW_ONLINESIGN")) { |
||||
| 1574 | print_liste_field_titre('', '', '', '', '', '', '', '', 'center '); |
||||
| 1575 | } |
||||
| 1576 | print_liste_field_titre('', '', '', '', '', '', '', '', 'center '); |
||||
| 1577 | // Fields from hook |
||||
| 1578 | $parameters = array('arrayfields' => array(), 'linetype' => 'stripebantitle'); |
||||
| 1579 | $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook |
||||
| 1580 | print $hookmanager->resPrint; |
||||
| 1581 | print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch '); |
||||
| 1582 | print "</tr>\n"; |
||||
| 1583 | |||||
| 1584 | // List of local BAN |
||||
| 1585 | foreach ($rib_list as $rib) { |
||||
| 1586 | $arrayofremoteban[$rib->stripe_card_ref] = $rib->stripe_card_ref; |
||||
| 1587 | |||||
| 1588 | $nblocal++; |
||||
| 1589 | |||||
| 1590 | print '<tr class="oddeven">'; |
||||
| 1591 | // Label |
||||
| 1592 | print '<td class="tdoverflowmax150" title="' . dol_escape_htmltag($rib->label) . '">' . dol_escape_htmltag($rib->label) . '</td>'; |
||||
| 1593 | // External system ID |
||||
| 1594 | print '<td class="tdoverflowmax150" title="' . dol_escape_htmltag($rib->stripe_card_ref . (empty($rib->stripe_account) ? '' : ' - ' . $rib->stripe_account)) . '">'; |
||||
| 1595 | if (!empty($rib->stripe_card_ref) && !empty($rib->ext_payment_site)) { |
||||
| 1596 | if (isModEnabled('stripe') && in_array($rib->ext_payment_site, array('StripeTest', 'StripeLive'))) { |
||||
| 1597 | $connect = ''; |
||||
| 1598 | if (!empty($stripeacc)) { |
||||
| 1599 | $connect = $stripeacc . '/'; |
||||
| 1600 | } |
||||
| 1601 | if ($rib->ext_payment_site == 'StripeLive') { |
||||
| 1602 | $url = 'https://dashboard.stripe.com/' . $connect . 'search?query=' . $rib->stripe_card_ref; |
||||
| 1603 | } else { |
||||
| 1604 | $url = 'https://dashboard.stripe.com/' . $connect . 'test/search?query=' . $rib->stripe_card_ref; |
||||
| 1605 | } |
||||
| 1606 | print "<a href='" . $url . "' target='_stripe'>" . img_picto($langs->trans('ShowInStripe'), 'globe') . "</a> "; |
||||
| 1607 | } |
||||
| 1608 | // TODO Add hook here for other payment services |
||||
| 1609 | } |
||||
| 1610 | print dol_escape_htmltag($rib->stripe_card_ref); |
||||
| 1611 | print '</td>'; |
||||
| 1612 | // Bank name |
||||
| 1613 | print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($rib->bank) . '">' . dol_escape_htmltag($rib->bank) . '</td>'; |
||||
| 1614 | // Account number |
||||
| 1615 | $string = ''; |
||||
| 1616 | foreach ($rib->getFieldsToShow() as $val) { |
||||
| 1617 | if ($val == 'BankCode') { |
||||
| 1618 | $string .= $rib->code_banque . ' '; |
||||
| 1619 | } elseif ($val == 'BankAccountNumber') { |
||||
| 1620 | $string .= $rib->number . ' '; |
||||
| 1621 | } elseif ($val == 'DeskCode') { |
||||
| 1622 | $string .= $rib->code_guichet . ' '; |
||||
| 1623 | } elseif ($val == 'BankAccountNumberKey') { |
||||
| 1624 | $string .= $rib->cle_rib . ' '; |
||||
| 1625 | } |
||||
| 1626 | // Already output after |
||||
| 1627 | // } elseif ($val == 'BIC') { |
||||
| 1628 | // $string .= $rib->bic.' '; |
||||
| 1629 | // } elseif ($val == 'IBAN') { |
||||
| 1630 | // $string .= $rib->iban.' ';*/ |
||||
| 1631 | //} |
||||
| 1632 | } |
||||
| 1633 | if (!empty($rib->label) && $rib->number) { |
||||
| 1634 | if (!checkBanForAccount($rib)) { |
||||
| 1635 | $string .= ' ' . img_picto($langs->trans("ValueIsNotValid"), 'warning'); |
||||
| 1636 | } else { |
||||
| 1637 | $string .= ' ' . img_picto($langs->trans("ValueIsValid"), 'info'); |
||||
| 1638 | } |
||||
| 1639 | } |
||||
| 1640 | print '<td class="tdoverflowmax150" title="' . dol_escape_htmltag($string) . '">'; |
||||
| 1641 | print $string; |
||||
| 1642 | print '</td>'; |
||||
| 1643 | // IBAN |
||||
| 1644 | print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($rib->iban) . '">'; |
||||
| 1645 | if (!empty($rib->iban)) { |
||||
| 1646 | if (!checkIbanForAccount($rib)) { |
||||
| 1647 | print img_picto($langs->trans("IbanNotValid"), 'warning') . ' '; |
||||
| 1648 | } |
||||
| 1649 | } |
||||
| 1650 | print dol_escape_htmltag($rib->iban); |
||||
| 1651 | print '</td>'; |
||||
| 1652 | // BIC |
||||
| 1653 | print '<td>'; |
||||
| 1654 | if (!empty($rib->bic)) { |
||||
| 1655 | if (!checkSwiftForAccount($rib)) { |
||||
| 1656 | print img_picto($langs->trans("SwiftNotValid"), 'warning') . ' '; |
||||
| 1657 | } |
||||
| 1658 | } |
||||
| 1659 | print dol_escape_htmltag($rib->bic); |
||||
| 1660 | print '</td>'; |
||||
| 1661 | |||||
| 1662 | if (isModEnabled('prelevement')) { |
||||
| 1663 | // RUM |
||||
| 1664 | //print '<td>'.$prelevement->buildRumNumber($object->code_client, $rib->datec, $rib->id).'</td>'; |
||||
| 1665 | print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($rib->rum) . '">' . dol_escape_htmltag($rib->rum) . '</td>'; |
||||
| 1666 | |||||
| 1667 | print '<td>' . dol_print_date($rib->date_rum, 'day') . '</td>'; |
||||
| 1668 | |||||
| 1669 | // FRST or RCUR |
||||
| 1670 | print '<td>' . dol_escape_htmltag($rib->frstrecur) . '</td>'; |
||||
| 1671 | } |
||||
| 1672 | |||||
| 1673 | // Default |
||||
| 1674 | print '<td class="center" width="70">'; |
||||
| 1675 | if (!$rib->default_rib) { |
||||
| 1676 | print '<a href="' . $_SERVER["PHP_SELF"] . '?socid=' . ((int)$object->id) . '&ribid=' . ((int)$rib->id) . '&action=setasbankdefault&token=' . newToken() . '">'; |
||||
| 1677 | print img_picto($langs->trans("Disabled"), 'off'); |
||||
| 1678 | print '</a>'; |
||||
| 1679 | } else { |
||||
| 1680 | print img_picto($langs->trans("Enabled"), 'on'); |
||||
| 1681 | } |
||||
| 1682 | print '</td>'; |
||||
| 1683 | |||||
| 1684 | // Generate doc |
||||
| 1685 | print '<td class="center">'; |
||||
| 1686 | |||||
| 1687 | $buttonlabel = $langs->trans("BuildDoc"); |
||||
| 1688 | $forname = 'builddocrib' . $rib->id; |
||||
| 1689 | |||||
| 1690 | include_once DOL_DOCUMENT_ROOT . '/core/modules/bank/modules_bank.php'; |
||||
| 1691 | $modellist = ModeleBankAccountDoc::liste_modeles($db); |
||||
| 1692 | |||||
| 1693 | $out = ''; |
||||
| 1694 | if (is_array($modellist) && count($modellist)) { |
||||
| 1695 | $out .= '<form action="' . $_SERVER["PHP_SELF"] . (!getDolGlobalString('MAIN_JUMP_TAG') ? '' : '#builddoc') . '" name="' . $forname . '" id="' . $forname . '_form" method="post">'; |
||||
| 1696 | $out .= '<input type="hidden" name="action" value="builddocrib">'; |
||||
| 1697 | $out .= '<input type="hidden" name="token" value="' . newToken() . '">'; |
||||
| 1698 | $out .= '<input type="hidden" name="socid" value="' . $object->id . '">'; |
||||
| 1699 | $out .= '<input type="hidden" name="companybankid" value="' . $rib->id . '">'; |
||||
| 1700 | |||||
| 1701 | $modelselected = ''; |
||||
| 1702 | if (count($modellist) == 1) { // If there is only one element |
||||
| 1703 | $arraykeys = array_keys($modellist); |
||||
| 1704 | $modelselected = $arraykeys[0]; |
||||
| 1705 | } |
||||
| 1706 | if (getDolGlobalString('BANKADDON_PDF')) { |
||||
| 1707 | $modelselected = getDolGlobalString('BANKADDON_PDF'); |
||||
| 1708 | } |
||||
| 1709 | |||||
| 1710 | $out .= $form->selectarray('modelrib' . $rib->id, $modellist, $modelselected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth125'); |
||||
| 1711 | $out .= ajax_combobox('modelrib' . $rib->id); |
||||
| 1712 | |||||
| 1713 | // Language code (if multilang) |
||||
| 1714 | if (getDolGlobalInt('MAIN_MULTILANGS')) { |
||||
| 1715 | include_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php'; |
||||
| 1716 | $formadmin = new FormAdmin($db); |
||||
| 1717 | $defaultlang = $langs->getDefaultLang(); |
||||
| 1718 | $morecss = 'maxwidth150'; |
||||
| 1719 | if ($conf->browser->layout == 'phone') { |
||||
| 1720 | $morecss = 'maxwidth100'; |
||||
| 1721 | } |
||||
| 1722 | $out .= FormAdmin::selectLanguage($defaultlang, 'lang_idrib' . $rib->id, 0, 0, 0, 0, 0, $morecss); |
||||
| 1723 | } |
||||
| 1724 | // Button |
||||
| 1725 | $out .= '<input class="button buttongen reposition nomargintop nomarginbottom" id="' . $forname . '_generatebutton" name="' . $forname . '_generatebutton"'; |
||||
| 1726 | $out .= ' type="submit" value="' . $buttonlabel . '"'; |
||||
| 1727 | $out .= '>'; |
||||
| 1728 | $out .= '</form>'; |
||||
| 1729 | } |
||||
| 1730 | print $out; |
||||
| 1731 | print '</td>'; |
||||
| 1732 | |||||
| 1733 | // Fields from hook |
||||
| 1734 | $parameters = array('arrayfields' => array(), 'stripe_card_ref' => $rib->stripe_card_ref, 'stripe_account' => $rib->stripe_account, 'linetype' => 'stripeban'); |
||||
| 1735 | $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook |
||||
| 1736 | print $hookmanager->resPrint; |
||||
| 1737 | |||||
| 1738 | if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT') && getDolGlobalInt("SOCIETE_RIB_ALLOW_ONLINESIGN")) { |
||||
| 1739 | // Show online signature link |
||||
| 1740 | print '<td class="width200">'; |
||||
| 1741 | $useonlinesignature = 1; |
||||
| 1742 | if ($useonlinesignature) { |
||||
| 1743 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/signature.lib.php'; |
||||
| 1744 | print showOnlineSignatureUrl($companybankaccount->element, $rib->id, $rib, 'short'); |
||||
| 1745 | } |
||||
| 1746 | print '</td>'; |
||||
| 1747 | } |
||||
| 1748 | |||||
| 1749 | // Edit/Delete |
||||
| 1750 | print '<td class="right nowraponall">'; |
||||
| 1751 | if ($permissiontoaddupdatepaymentinformation) { |
||||
| 1752 | if (isModEnabled('stripe')) { |
||||
| 1753 | if (empty($rib->stripe_card_ref)) { |
||||
| 1754 | if ($object->client) { |
||||
| 1755 | // Add link to create BAN on Stripe |
||||
| 1756 | print '<a class="editfielda marginrightonly marginleftonly" href="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&id=' . $rib->id . '&action=syncsepatostripe&token=' . newToken() . '">'; |
||||
| 1757 | print img_picto($langs->trans("CreateBANOnStripe"), 'stripe'); |
||||
| 1758 | print '</a>'; |
||||
| 1759 | } else { |
||||
| 1760 | print '<span class="opacitymedium marginrightonly marginleftonly">'; |
||||
| 1761 | print img_picto($langs->trans("ThirdPartyMustBeACustomerToCreateBANOnStripe"), 'stripe'); |
||||
| 1762 | print '</span>'; |
||||
| 1763 | } |
||||
| 1764 | } |
||||
| 1765 | } |
||||
| 1766 | |||||
| 1767 | print '<a class="editfielda marginrightonly marginleftonly" href="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&id=' . $rib->id . '&action=edit">'; |
||||
| 1768 | print img_picto($langs->trans("Modify"), 'edit'); |
||||
| 1769 | print '</a>'; |
||||
| 1770 | |||||
| 1771 | print '<a class="marginrightonly marginleftonly reposition" href="' . $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&id=' . $rib->id . '&action=deletebank&token=' . newToken() . '">'; |
||||
| 1772 | print img_picto($langs->trans("Delete"), 'delete'); |
||||
| 1773 | print '</a>'; |
||||
| 1774 | } |
||||
| 1775 | print '</td>'; |
||||
| 1776 | |||||
| 1777 | print '</tr>'; |
||||
| 1778 | } |
||||
| 1779 | |||||
| 1780 | |||||
| 1781 | // List of remote BAN (if not already added as local) |
||||
| 1782 | foreach ($listofsources as $src) { |
||||
| 1783 | if (!empty($arrayofremoteban[$src->id])) { |
||||
| 1784 | continue; // Already in previous list |
||||
| 1785 | } |
||||
| 1786 | |||||
| 1787 | $imgline = ''; |
||||
| 1788 | if ($src->object == 'source' && $src->type == 'sepa_debit') { |
||||
| 1789 | $imgline = '<span class="fa fa-university fa-2x fa-fw"></span>'; |
||||
| 1790 | } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit') { |
||||
| 1791 | $imgline = '<span class="fa fa-university fa-2x fa-fw"></span>'; |
||||
| 1792 | } else { |
||||
| 1793 | continue; |
||||
| 1794 | } |
||||
| 1795 | |||||
| 1796 | $nbremote++; |
||||
| 1797 | |||||
| 1798 | print '<tr class="oddeven">'; |
||||
| 1799 | print '<td>'; |
||||
| 1800 | print '</td>'; |
||||
| 1801 | // Src ID |
||||
| 1802 | print '<td class="tdoverflowmax150">'; |
||||
| 1803 | $connect = ''; |
||||
| 1804 | if (!empty($stripeacc)) { |
||||
| 1805 | $connect = $stripeacc . '/'; |
||||
| 1806 | } |
||||
| 1807 | //$url='https://dashboard.stripe.com/'.$connect.'test/sources/'.$src->id; |
||||
| 1808 | $url = 'https://dashboard.stripe.com/' . $connect . 'test/search?query=' . $src->id; |
||||
| 1809 | if ($servicestatus) { |
||||
| 1810 | //$url='https://dashboard.stripe.com/'.$connect.'sources/'.$src->id; |
||||
| 1811 | $url = 'https://dashboard.stripe.com/' . $connect . 'search?query=' . $src->id; |
||||
| 1812 | } |
||||
| 1813 | print "<a href='" . $url . "' target='_stripe'>" . img_picto($langs->trans('ShowInStripe'), 'globe') . "</a> "; |
||||
| 1814 | print $src->id; |
||||
| 1815 | print '</td>'; |
||||
| 1816 | // Bank |
||||
| 1817 | print '<td>'; |
||||
| 1818 | print'</td>'; |
||||
| 1819 | // Account number |
||||
| 1820 | print '<td valign="middle">'; |
||||
| 1821 | print '</td>'; |
||||
| 1822 | // IBAN |
||||
| 1823 | print '<td valign="middle">'; |
||||
| 1824 | //var_dump($src); |
||||
| 1825 | print '</td>'; |
||||
| 1826 | // BIC |
||||
| 1827 | print '<td valign="middle">'; |
||||
| 1828 | //var_dump($src); |
||||
| 1829 | print '</td>'; |
||||
| 1830 | |||||
| 1831 | if (isModEnabled('prelevement')) { |
||||
| 1832 | // RUM |
||||
| 1833 | print '<td valign="middle">'; |
||||
| 1834 | //var_dump($src); |
||||
| 1835 | print '</td>'; |
||||
| 1836 | // Date |
||||
| 1837 | print '<td valign="middle">'; |
||||
| 1838 | //var_dump($src); |
||||
| 1839 | print '</td>'; |
||||
| 1840 | // Mode mandate |
||||
| 1841 | print '<td valign="middle">'; |
||||
| 1842 | //var_dump($src); |
||||
| 1843 | print '</td>'; |
||||
| 1844 | } |
||||
| 1845 | |||||
| 1846 | // Default |
||||
| 1847 | print '<td class="center" width="50">'; |
||||
| 1848 | if ( |
||||
| 1849 | (empty($customerstripe->invoice_settings) && $customerstripe->default_source != $src->id) || |
||||
| 1850 | (!empty($customerstripe->invoice_settings) && $customerstripe->invoice_settings->default_payment_method != $src->id) |
||||
| 1851 | ) { |
||||
| 1852 | print '<a href="' . constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id . '&source=' . $src->id . '&action=setassourcedefault&token=' . newToken() . '">'; |
||||
| 1853 | print img_picto($langs->trans("Default"), 'off'); |
||||
| 1854 | print '</a>'; |
||||
| 1855 | } else { |
||||
| 1856 | print img_picto($langs->trans("Default"), 'on'); |
||||
| 1857 | } |
||||
| 1858 | print '</td>'; |
||||
| 1859 | /* |
||||
| 1860 | print '<td>'; |
||||
| 1861 | print $langs->trans("Remote"); |
||||
| 1862 | //if ($src->cvc_check == 'fail') print ' - CVC check fail'; |
||||
| 1863 | print '</td>'; |
||||
| 1864 | */ |
||||
| 1865 | |||||
| 1866 | print '<td>'; |
||||
| 1867 | print '</td>'; |
||||
| 1868 | |||||
| 1869 | // Fields from hook |
||||
| 1870 | $parameters = array('arrayfields' => array(), 'stripe_card_ref' => $rib->stripe_card_ref, 'stripe_account' => $rib->stripe_account, 'linetype' => 'stripebanremoteonly'); |
||||
| 1871 | $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook |
||||
| 1872 | print $hookmanager->resPrint; |
||||
| 1873 | |||||
| 1874 | // Action column |
||||
| 1875 | print '<td class="right nowraponall">'; |
||||
| 1876 | if ($permissiontoaddupdatepaymentinformation) { |
||||
| 1877 | print '<a class="marginleftonly marginrightonly reposition" href="' . constant('BASE_URL') . '/societe/paymentmodes.php?socid=' . $object->id . '&source=' . $src->id . '&action=deletebank&token=' . newToken() . '">'; |
||||
| 1878 | print img_picto($langs->trans("Delete"), 'delete'); |
||||
| 1879 | print '</a>'; |
||||
| 1880 | } |
||||
| 1881 | print '</td>'; |
||||
| 1882 | |||||
| 1883 | print '</tr>'; |
||||
| 1884 | } |
||||
| 1885 | |||||
| 1886 | if ($nbremote == 0 && $nblocal == 0) { |
||||
| 1887 | $colspan = 10; |
||||
| 1888 | if (isModEnabled('prelevement')) { |
||||
| 1889 | $colspan += 3; |
||||
| 1890 | } |
||||
| 1891 | print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoBANRecord") . '</span></td></tr>'; |
||||
| 1892 | } |
||||
| 1893 | |||||
| 1894 | print '</table>'; |
||||
| 1895 | print '</div>'; |
||||
| 1896 | } else { |
||||
| 1897 | dol_print_error($db); |
||||
| 1898 | } |
||||
| 1899 | |||||
| 1900 | //Hook to display your print listing (list of CB card from Stancer Plugin for example) |
||||
| 1901 | $parameters = array('arrayfields' => array(), 'param' => '', 'sortfield' => '', 'sortorder' => '', 'linetype' => ''); |
||||
| 1902 | $reshook = $hookmanager->executeHooks('printNewTable', $parameters, $object); |
||||
| 1903 | print $hookmanager->resPrint; |
||||
| 1904 | |||||
| 1905 | if (!getDolGlobalString('SOCIETE_DISABLE_BUILDDOC')) { |
||||
| 1906 | print '<br>'; |
||||
| 1907 | |||||
| 1908 | print '<div class="fichecenter"><div class="fichehalfleft">'; |
||||
| 1909 | print '<a name="builddoc"></a>'; // ancre |
||||
| 1910 | |||||
| 1911 | /* |
||||
| 1912 | * Generated documents |
||||
| 1913 | */ |
||||
| 1914 | $filedir = $conf->societe->multidir_output[$object->entity] . '/' . $object->id; |
||||
| 1915 | $urlsource = $_SERVER["PHP_SELF"] . "?socid=" . $object->id; |
||||
| 1916 | |||||
| 1917 | print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $permissiontoread, $permissiontoaddupdatepaymentinformation, $object->model_pdf, 0, 0, 0, 28, 0, 'entity=' . $object->entity, 0, '', $object->default_lang); |
||||
| 1918 | |||||
| 1919 | // Show direct download link |
||||
| 1920 | if (getDolGlobalString('BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD')) { |
||||
| 1921 | $companybankaccounttemp = new CompanyBankAccount($db); |
||||
| 1922 | $companypaymentmodetemp = new CompanyPaymentMode($db); |
||||
| 1923 | // @phan-suppress-next-line PhanPluginSuspiciousParamPosition |
||||
| 1924 | $result = $companypaymentmodetemp->fetch(0, null, $object->id, 'ban'); |
||||
| 1925 | |||||
| 1926 | $ecmfile = new EcmFiles($db); |
||||
| 1927 | // @phan-suppress-next-line PhanPluginSuspiciousParamPosition |
||||
| 1928 | $result = $ecmfile->fetch(0, '', '', '', '', $companybankaccounttemp->table_element, $companypaymentmodetemp->id); |
||||
| 1929 | if ($result > 0) { |
||||
| 1930 | $companybankaccounttemp->last_main_doc = $ecmfile->filepath . '/' . $ecmfile->filename; |
||||
| 1931 | print '<br><!-- Link to download main doc -->' . "\n"; |
||||
| 1932 | print showDirectDownloadLink($companybankaccounttemp) . '<br>'; |
||||
| 1933 | } |
||||
| 1934 | } |
||||
| 1935 | |||||
| 1936 | print '</div><div class="fichehalfright">'; |
||||
| 1937 | |||||
| 1938 | |||||
| 1939 | print '</div></div>'; |
||||
| 1940 | |||||
| 1941 | print '<br>'; |
||||
| 1942 | } |
||||
| 1943 | /* |
||||
| 1944 | include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php'; |
||||
| 1945 | $modellist=ModeleBankAccountDoc::liste_modeles($db); |
||||
| 1946 | //print '<td>'; |
||||
| 1947 | if (is_array($modellist) && count($modellist) == 1) // If there is only one element |
||||
| 1948 | { |
||||
| 1949 | $arraykeys=array_keys($modellist); |
||||
| 1950 | $modelselected=$arraykeys[0]; |
||||
| 1951 | } |
||||
| 1952 | $out.= $form->selectarray('model', $modellist, $modelselected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100'); |
||||
| 1953 | $out.= ajax_combobox('model'); |
||||
| 1954 | //print $out; |
||||
| 1955 | $buttonlabel=$langs->trans("Generate"); |
||||
| 1956 | $genbutton = '<input class="button buttongen reposition nomargintop nomarginbottom" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"'; |
||||
| 1957 | $genbutton.= ' type="submit" value="'.$buttonlabel.'"'; |
||||
| 1958 | $genbutton.= '>'; |
||||
| 1959 | print $genbutton; |
||||
| 1960 | //print '</td>'; // TODO Add link to generate doc |
||||
| 1961 | */ |
||||
| 1962 | } |
||||
| 1963 | |||||
| 1964 | // Edit BAN |
||||
| 1965 | if ($socid && $action == 'edit' && $permissiontoaddupdatepaymentinformation) { |
||||
| 1966 | print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company'); |
||||
| 1967 | |||||
| 1968 | $linkback = '<a href="' . constant('BASE_URL') . '/societe/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>'; |
||||
| 1969 | |||||
| 1970 | dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); |
||||
| 1971 | |||||
| 1972 | print '<div class="underbanner clearboth"></div>'; |
||||
| 1973 | |||||
| 1974 | print '<br>'; |
||||
| 1975 | |||||
| 1976 | print '<div class="div-table-responsive-no-min">'; |
||||
| 1977 | print '<table class="border centpercent">'; |
||||
| 1978 | |||||
| 1979 | print '<tr><td class="titlefield fieldrequired">' . $langs->trans("Label") . '</td>'; |
||||
| 1980 | print '<td><input class="minwidth300" type="text" name="label" value="' . $companybankaccount->label . '"></td></tr>'; |
||||
| 1981 | |||||
| 1982 | print '<tr><td class="fieldrequired">' . $langs->trans("BankName") . '</td>'; |
||||
| 1983 | print '<td><input class="minwidth200" type="text" name="bank" value="' . $companybankaccount->bank . '"></td></tr>'; |
||||
| 1984 | |||||
| 1985 | // Show fields of bank account |
||||
| 1986 | $bankaccount = $companybankaccount; |
||||
| 1987 | // Code here is similar as in bank.php for users |
||||
| 1988 | foreach ($bankaccount->getFieldsToShow(1) as $val) { |
||||
| 1989 | $require = false; |
||||
| 1990 | $tooltip = ''; |
||||
| 1991 | if ($val == 'BankCode') { |
||||
| 1992 | $name = 'code_banque'; |
||||
| 1993 | $size = 8; |
||||
| 1994 | $content = $bankaccount->code_banque; |
||||
| 1995 | } elseif ($val == 'DeskCode') { |
||||
| 1996 | $name = 'code_guichet'; |
||||
| 1997 | $size = 8; |
||||
| 1998 | $content = $bankaccount->code_guichet; |
||||
| 1999 | } elseif ($val == 'BankAccountNumber') { |
||||
| 2000 | $name = 'number'; |
||||
| 2001 | $size = 18; |
||||
| 2002 | $content = $bankaccount->number; |
||||
| 2003 | } elseif ($val == 'BankAccountNumberKey') { |
||||
| 2004 | $name = 'cle_rib'; |
||||
| 2005 | $size = 3; |
||||
| 2006 | $content = $bankaccount->cle_rib; |
||||
| 2007 | } elseif ($val == 'IBAN') { |
||||
| 2008 | $name = 'iban'; |
||||
| 2009 | $size = 30; |
||||
| 2010 | $content = $bankaccount->iban; |
||||
| 2011 | if ($bankaccount->needIBAN()) { |
||||
| 2012 | $require = true; |
||||
| 2013 | } |
||||
| 2014 | $tooltip = $langs->trans("Example") . ':<br>CH93 0076 2011 6238 5295 7<br>LT12 1000 0111 0100 1000<br>FR14 2004 1010 0505 0001 3M02 606<br>LU28 0019 4006 4475 0000<br>DE89 3704 0044 0532 0130 00'; |
||||
| 2015 | } elseif ($val == 'BIC') { |
||||
| 2016 | $name = 'bic'; |
||||
| 2017 | $size = 12; |
||||
| 2018 | $content = $bankaccount->bic; |
||||
| 2019 | if ($bankaccount->needIBAN()) { |
||||
| 2020 | $require = true; |
||||
| 2021 | } |
||||
| 2022 | $tooltip = $langs->trans("Example") . ': LIABLT2XXXX'; |
||||
| 2023 | } |
||||
| 2024 | |||||
| 2025 | print '<tr>'; |
||||
| 2026 | print '<td' . ($require ? ' class="fieldrequired" ' : '') . '>'; |
||||
| 2027 | if ($tooltip) { |
||||
| 2028 | print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name); |
||||
| 2029 | } else { |
||||
| 2030 | print $langs->trans($val); |
||||
| 2031 | } |
||||
| 2032 | print '</td>'; |
||||
| 2033 | print '<td><input size="' . $size . '" type="text" class="flat" name="' . $name . '" value="' . $content . '"></td>'; |
||||
| 2034 | print '</tr>'; |
||||
| 2035 | } |
||||
| 2036 | |||||
| 2037 | print '<tr><td class="tdtop">' . $langs->trans("BankAccountDomiciliation") . '</td><td>'; |
||||
| 2038 | print '<textarea name="address" rows="4" cols="40" maxlength="255">'; |
||||
| 2039 | print $companybankaccount->address; |
||||
| 2040 | print "</textarea></td></tr>"; |
||||
| 2041 | |||||
| 2042 | print '<tr><td>' . $langs->trans("BankAccountOwner") . '</td>'; |
||||
| 2043 | print '<td><input class="minwidth300" type="text" name="proprio" value="' . $companybankaccount->owner_name . '"></td></tr>'; |
||||
| 2044 | print "</td></tr>\n"; |
||||
| 2045 | |||||
| 2046 | print '<tr><td class="tdtop">' . $langs->trans("BankAccountOwnerAddress") . '</td><td>'; |
||||
| 2047 | print '<textarea name="owner_address" rows="' . ROWS_4 . '" cols="40" maxlength="255">'; |
||||
| 2048 | print $companybankaccount->owner_address; |
||||
| 2049 | print "</textarea></td></tr>"; |
||||
| 2050 | |||||
| 2051 | print '</table>'; |
||||
| 2052 | print '</div>'; |
||||
| 2053 | |||||
| 2054 | if (isModEnabled('prelevement')) { |
||||
| 2055 | print '<br>'; |
||||
| 2056 | |||||
| 2057 | print '<div class="div-table-responsive-no-min">'; |
||||
| 2058 | print '<table class="border centpercent">'; |
||||
| 2059 | |||||
| 2060 | if (empty($companybankaccount->rum)) { |
||||
| 2061 | $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id); |
||||
| 2062 | } |
||||
| 2063 | |||||
| 2064 | // RUM |
||||
| 2065 | print '<tr><td class="titlefield">' . $langs->trans("RUM") . '</td>'; |
||||
| 2066 | print '<td><input class="minwidth300" type="text" name="rum" value="' . dol_escape_htmltag($companybankaccount->rum) . '"></td></tr>'; |
||||
| 2067 | |||||
| 2068 | $date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth'), GETPOST('date_rumday'), GETPOST('date_rumyear')); |
||||
| 2069 | |||||
| 2070 | print '<tr><td class="titlefield">' . $langs->trans("DateRUM") . '</td>'; |
||||
| 2071 | print '<td>' . $form->selectDate($date_rum ? $date_rum : $companybankaccount->date_rum, 'date_rum', 0, 0, 1, 'date_rum', 1, 1) . '</td></tr>'; |
||||
| 2072 | |||||
| 2073 | print '<tr><td>' . $langs->trans("WithdrawMode") . '</td><td>'; |
||||
| 2074 | $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RCUR" => $langs->trans("RECUR")); |
||||
| 2075 | print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur', 'alpha') ? GETPOST('frstrecur', 'alpha') : $companybankaccount->frstrecur), 0); |
||||
| 2076 | print '</td></tr>'; |
||||
| 2077 | |||||
| 2078 | print '<tr><td>' . $langs->trans("ExternalSystemID") . " ('pm_...' or 'src_...')</td>"; |
||||
| 2079 | print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="' . $companypaymentmode->stripe_card_ref . '"></td></tr>'; |
||||
| 2080 | |||||
| 2081 | print '</table>'; |
||||
| 2082 | print '</div>'; |
||||
| 2083 | } |
||||
| 2084 | |||||
| 2085 | |||||
| 2086 | print dol_get_fiche_end(); |
||||
| 2087 | |||||
| 2088 | print $form->buttonsSaveCancel("Modify"); |
||||
| 2089 | } |
||||
| 2090 | |||||
| 2091 | // Edit Card |
||||
| 2092 | if ($socid && $action == 'editcard' && $permissiontoaddupdatepaymentinformation) { |
||||
| 2093 | print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company'); |
||||
| 2094 | |||||
| 2095 | $linkback = '<a href="' . constant('BASE_URL') . '/societe/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>'; |
||||
| 2096 | |||||
| 2097 | dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); |
||||
| 2098 | |||||
| 2099 | print '<div class="nofichecenter">'; |
||||
| 2100 | |||||
| 2101 | print '<div class="underbanner clearboth"></div>'; |
||||
| 2102 | |||||
| 2103 | print '<br>'; |
||||
| 2104 | |||||
| 2105 | print '<table class="border centpercent">'; |
||||
| 2106 | |||||
| 2107 | print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans("Label") . '</td>'; |
||||
| 2108 | print '<td><input class="minwidth300" type="text" id="label" name="label" value="' . $companypaymentmode->label . '"></td></tr>'; |
||||
| 2109 | |||||
| 2110 | print '<tr><td class="fieldrequired">' . $langs->trans("NameOnCard") . '</td>'; |
||||
| 2111 | print '<td><input class="minwidth200" type="text" name="proprio" value="' . $companypaymentmode->proprio . '"></td></tr>'; |
||||
| 2112 | |||||
| 2113 | print '<tr><td>' . $langs->trans("CardNumber") . '</td>'; |
||||
| 2114 | print '<td><input class="minwidth200" type="text" name="cardnumber" value="' . $companypaymentmode->number . '"></td></tr>'; |
||||
| 2115 | |||||
| 2116 | print '<tr><td class="fieldrequired">' . $langs->trans("ExpiryDate") . '</td>'; |
||||
| 2117 | print '<td>'; |
||||
| 2118 | print $formother->select_month($companypaymentmode->exp_date_month, 'exp_date_month', 1); |
||||
| 2119 | print $formother->selectyear($companypaymentmode->exp_date_year, 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly'); |
||||
| 2120 | print '</td></tr>'; |
||||
| 2121 | |||||
| 2122 | print '<tr><td>' . $langs->trans("CVN") . '</td>'; |
||||
| 2123 | print '<td><input size="8" type="text" name="cvn" value="' . $companypaymentmode->cvn . '"></td></tr>'; |
||||
| 2124 | |||||
| 2125 | print '<tr><td>' . $langs->trans("ExternalSystemID") . " ('pm_... " . $langs->trans("or") . " card_....')</td>"; |
||||
| 2126 | print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="' . $companypaymentmode->stripe_card_ref . '"></td></tr>'; |
||||
| 2127 | |||||
| 2128 | print '</table>'; |
||||
| 2129 | print '</div>'; |
||||
| 2130 | |||||
| 2131 | print dol_get_fiche_end(); |
||||
| 2132 | |||||
| 2133 | print $form->buttonsSaveCancel("Modify"); |
||||
| 2134 | } |
||||
| 2135 | |||||
| 2136 | |||||
| 2137 | // Create BAN |
||||
| 2138 | if ($socid && $action == 'create' && $permissiontoaddupdatepaymentinformation) { |
||||
| 2139 | print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company'); |
||||
| 2140 | |||||
| 2141 | $linkback = '<a href="' . constant('BASE_URL') . '/societe/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>'; |
||||
| 2142 | |||||
| 2143 | dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); |
||||
| 2144 | |||||
| 2145 | print '<div class="nofichecenter">'; |
||||
| 2146 | |||||
| 2147 | print '<div class="underbanner clearboth"></div>'; |
||||
| 2148 | |||||
| 2149 | print '<br>'; |
||||
| 2150 | |||||
| 2151 | print '<table class="border centpercent">'; |
||||
| 2152 | |||||
| 2153 | print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans("Label") . '</td>'; |
||||
| 2154 | print '<td><input class="minwidth200" type="text" id="label" name="label" value="' . (GETPOSTISSET('label') ? GETPOST('label') : $object->name) . '"></td></tr>'; |
||||
| 2155 | |||||
| 2156 | print '<tr><td>' . $langs->trans("Bank") . '</td>'; |
||||
| 2157 | print '<td><input class="minwidth200" type="text" id="bank" name="bank" value="' . GETPOST('bank') . '"></td></tr>'; |
||||
| 2158 | |||||
| 2159 | // Show fields of bank account |
||||
| 2160 | foreach ($companybankaccount->getFieldsToShow(1) as $val) { |
||||
| 2161 | $require = false; |
||||
| 2162 | $tooltip = ''; |
||||
| 2163 | if ($val == 'BankCode') { |
||||
| 2164 | $name = 'code_banque'; |
||||
| 2165 | $size = 8; |
||||
| 2166 | $content = $companybankaccount->code_banque; |
||||
| 2167 | } elseif ($val == 'DeskCode') { |
||||
| 2168 | $name = 'code_guichet'; |
||||
| 2169 | $size = 8; |
||||
| 2170 | $content = $companybankaccount->code_guichet; |
||||
| 2171 | } elseif ($val == 'BankAccountNumber') { |
||||
| 2172 | $name = 'number'; |
||||
| 2173 | $size = 18; |
||||
| 2174 | $content = $companybankaccount->number; |
||||
| 2175 | } elseif ($val == 'BankAccountNumberKey') { |
||||
| 2176 | $name = 'cle_rib'; |
||||
| 2177 | $size = 3; |
||||
| 2178 | $content = $companybankaccount->cle_rib; |
||||
| 2179 | } elseif ($val == 'IBAN') { |
||||
| 2180 | $name = 'iban'; |
||||
| 2181 | $size = 30; |
||||
| 2182 | $content = $companybankaccount->iban; |
||||
| 2183 | if ($companybankaccount->needIBAN()) { |
||||
| 2184 | $require = true; |
||||
| 2185 | } |
||||
| 2186 | $tooltip = $langs->trans("Example") . ':<br>CH93 0076 2011 6238 5295 7<br>LT12 1000 0111 0100 1000<br>FR14 2004 1010 0505 0001 3M02 606<br>LU28 0019 4006 4475 0000<br>DE89 3704 0044 0532 0130 00'; |
||||
| 2187 | } elseif ($val == 'BIC') { |
||||
| 2188 | $name = 'bic'; |
||||
| 2189 | $size = 12; |
||||
| 2190 | $content = $companybankaccount->bic; |
||||
| 2191 | if ($companybankaccount->needIBAN()) { |
||||
| 2192 | $require = true; |
||||
| 2193 | } |
||||
| 2194 | $tooltip = $langs->trans("Example") . ': LIABLT2XXXX'; |
||||
| 2195 | } |
||||
| 2196 | |||||
| 2197 | print '<tr><td' . ($require ? ' class="fieldrequired" ' : '') . '>'; |
||||
| 2198 | if ($tooltip) { |
||||
| 2199 | print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name); |
||||
| 2200 | } else { |
||||
| 2201 | print $langs->trans($val); |
||||
| 2202 | } |
||||
| 2203 | print '</td>'; |
||||
| 2204 | print '<td><input size="' . $size . '" type="text" class="flat" name="' . $name . '" value="' . GETPOST($name) . '"></td>'; |
||||
| 2205 | print '</tr>'; |
||||
| 2206 | } |
||||
| 2207 | |||||
| 2208 | print '<tr><td class="tdtop">' . $langs->trans("BankAccountDomiciliation") . '</td><td>'; |
||||
| 2209 | print '<textarea name="address" rows="' . ROWS_4 . '" class="quatrevingtpercent" maxlength="255">'; |
||||
| 2210 | print GETPOST('address'); |
||||
| 2211 | print "</textarea></td></tr>"; |
||||
| 2212 | |||||
| 2213 | print '<tr><td>' . $langs->trans("BankAccountOwner") . '</td>'; |
||||
| 2214 | print '<td><input class="minwidth200" type="text" name="proprio" value="' . GETPOST('proprio') . '"></td></tr>'; |
||||
| 2215 | print "</td></tr>\n"; |
||||
| 2216 | |||||
| 2217 | print '<tr><td class="tdtop">' . $langs->trans("BankAccountOwnerAddress") . '</td><td>'; |
||||
| 2218 | print '<textarea name="owner_address" rows="' . ROWS_4 . '" class="quatrevingtpercent" maxlength="255">'; |
||||
| 2219 | print GETPOST('owner_address'); |
||||
| 2220 | print "</textarea></td></tr>"; |
||||
| 2221 | |||||
| 2222 | print '</table>'; |
||||
| 2223 | |||||
| 2224 | if (isModEnabled('prelevement')) { |
||||
| 2225 | print '<br>'; |
||||
| 2226 | |||||
| 2227 | print '<table class="border centpercent">'; |
||||
| 2228 | |||||
| 2229 | // RUM |
||||
| 2230 | print '<tr><td class="titlefieldcreate">' . $form->textwithpicto($langs->trans("RUM"), $langs->trans("RUMLong") . '<br>' . $langs->trans("RUMWillBeGenerated")) . '</td>'; |
||||
| 2231 | print '<td colspan="4"><input type="text" class="minwidth300" name="rum" value="' . GETPOST('rum', 'alpha') . '"></td></tr>'; |
||||
| 2232 | |||||
| 2233 | $date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth'), GETPOST('date_rumday'), GETPOST('date_rumyear')); |
||||
| 2234 | |||||
| 2235 | print '<tr><td class="titlefieldcreate">' . $langs->trans("DateRUM") . '</td>'; |
||||
| 2236 | print '<td colspan="4">' . $form->selectDate($date_rum, 'date_rum', 0, 0, 1, 'date_rum', 1, 1) . '</td></tr>'; |
||||
| 2237 | |||||
| 2238 | print '<tr><td>' . $langs->trans("WithdrawMode") . '</td><td>'; |
||||
| 2239 | $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RCUR" => $langs->trans("RECUR")); |
||||
| 2240 | print $form->selectarray("frstrecur", $tblArraychoice, (GETPOSTISSET('frstrecur') ? GETPOST('frstrecur') : 'FRST'), 0); |
||||
| 2241 | print '</td></tr>'; |
||||
| 2242 | |||||
| 2243 | print '<tr><td>' . $langs->trans("ExternalSystemID") . " ('src_....')</td>"; |
||||
| 2244 | print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="' . GETPOST('stripe_card_ref', 'alpha') . '"></td></tr>'; |
||||
| 2245 | |||||
| 2246 | print '</table>'; |
||||
| 2247 | } |
||||
| 2248 | |||||
| 2249 | print '</div>'; |
||||
| 2250 | |||||
| 2251 | print dol_get_fiche_end(); |
||||
| 2252 | |||||
| 2253 | dol_set_focus('#bank'); |
||||
| 2254 | |||||
| 2255 | print $form->buttonsSaveCancel("Add"); |
||||
| 2256 | } |
||||
| 2257 | |||||
| 2258 | // Create Card |
||||
| 2259 | if ($socid && $action == 'createcard' && $permissiontoaddupdatepaymentinformation) { |
||||
| 2260 | print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company'); |
||||
| 2261 | |||||
| 2262 | $linkback = '<a href="' . constant('BASE_URL') . '/societe/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>'; |
||||
| 2263 | |||||
| 2264 | dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); |
||||
| 2265 | |||||
| 2266 | print '<div class="nofichecenter">'; |
||||
| 2267 | |||||
| 2268 | print '<div class="underbanner clearboth"></div>'; |
||||
| 2269 | |||||
| 2270 | print '<br>'; |
||||
| 2271 | |||||
| 2272 | print '<table class="border centpercent">'; |
||||
| 2273 | |||||
| 2274 | print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans("Label") . '</td>'; |
||||
| 2275 | print '<td><input class="minwidth200" type="text" id="label" name="label" value="' . GETPOST('label', 'alpha') . '"></td></tr>'; |
||||
| 2276 | |||||
| 2277 | print '<tr><td class="fieldrequired">' . $langs->trans("NameOnCard") . '</td>'; |
||||
| 2278 | print '<td><input class="minwidth200" type="text" name="proprio" value="' . GETPOST('proprio', 'alpha') . '"></td></tr>'; |
||||
| 2279 | |||||
| 2280 | print '<tr><td>' . $langs->trans("CardNumber") . '</td>'; |
||||
| 2281 | print '<td><input class="minwidth200" type="text" name="cardnumber" value="' . GETPOST('cardnumber', 'alpha') . '"></td></tr>'; |
||||
| 2282 | |||||
| 2283 | print '<tr><td class="fieldrequired">' . $langs->trans("ExpiryDate") . '</td>'; |
||||
| 2284 | print '<td>'; |
||||
| 2285 | print $formother->select_month(GETPOSTINT('exp_date_month'), 'exp_date_month', 1); |
||||
| 2286 | print $formother->selectyear(GETPOSTINT('exp_date_year'), 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly'); |
||||
| 2287 | print '</td></tr>'; |
||||
| 2288 | |||||
| 2289 | print '<tr><td>' . $langs->trans("CVN") . '</td>'; |
||||
| 2290 | print '<td><input class="width50" type="text" name="cvn" value="' . GETPOST('cvn', 'alpha') . '"></td></tr>'; |
||||
| 2291 | |||||
| 2292 | print '<tr><td>' . $langs->trans("ExternalSystemID") . " ('card_....')</td>"; |
||||
| 2293 | print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="' . GETPOST('stripe_card_ref', 'alpha') . '"></td></tr>'; |
||||
| 2294 | |||||
| 2295 | print '</table>'; |
||||
| 2296 | |||||
| 2297 | print '</div>'; |
||||
| 2298 | |||||
| 2299 | print dol_get_fiche_end(); |
||||
| 2300 | |||||
| 2301 | dol_set_focus('#label'); |
||||
| 2302 | |||||
| 2303 | print $form->buttonsSaveCancel("Add"); |
||||
| 2304 | } |
||||
| 2305 | |||||
| 2306 | if ($socid && ($action == 'edit' || $action == 'editcard') && $permissiontoaddupdatepaymentinformation) { |
||||
| 2307 | print '</form>'; |
||||
| 2308 | } |
||||
| 2309 | if ($socid && ($action == 'create' || $action == 'createcard') && $permissiontoaddupdatepaymentinformation) { |
||||
| 2310 | print '</form>'; |
||||
| 2311 | } |
||||
| 2312 | |||||
| 2313 | // End of page |
||||
| 2314 | ViewMain::llxFooter(); |
||||
| 2315 | $db->close(); |
||||
| 2316 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.