diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 70274040fd35e..4d26361139000 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -81,9 +81,10 @@ public function __construct($db) * @param string $moreparam More param to add on a href URL. * @param int $fieldrequired 1 if we want to show field as mandatory using the "fieldrequired" CSS. * @param int $notabletag 1=Do not output table tags but output a ':', 2=Do not output table tags and no ':', 3=Do not output table tags but output a ' ' + * @param string $paramid Key of parameter for id ('id', 'socid') * @return string HTML edit field */ - function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata='string', $moreparam='', $fieldrequired=0, $notabletag=0) + function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata='string', $moreparam='', $fieldrequired=0, $notabletag=0, $paramid='id') { global $conf,$langs; @@ -117,7 +118,7 @@ function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdat if (! empty($notabletag)) $ret.=' '; if (empty($notabletag) && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.=''; if (empty($notabletag) && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.=''; - if ($htmlname && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.='id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).''; + if ($htmlname && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.='id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).''; if (! empty($notabletag) && $notabletag == 1) $ret.=' : '; if (! empty($notabletag) && $notabletag == 3) $ret.=' '; if (empty($notabletag) && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.=''; @@ -142,9 +143,10 @@ function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdat * @param string $moreparam More param to add on a href URL * @param int $notabletag Do no output table tags * @param string $formatfunc Call a specific function to output field + * @param string $paramid Key of parameter for id ('id', 'socid') * @return string HTML edit field */ - function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='string', $editvalue='', $extObject=null, $custommsg=null, $moreparam='', $notabletag=0, $formatfunc='') + function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='string', $editvalue='', $extObject=null, $custommsg=null, $moreparam='', $notabletag=0, $formatfunc='', $paramid='id') { global $conf,$langs,$db; @@ -166,7 +168,7 @@ function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='str $ret.='
'; $ret.=''; $ret.=''; - $ret.=''; + $ret.=''; if (empty($notabletag)) $ret.=''; if (empty($notabletag)) $ret.=''; - } print '
'; if (preg_match('/^(string|email)/',$typeofdata)) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 023729e680dfc..3a295f7a941b9 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -178,6 +178,8 @@ function societe_prepare_head(Societe $object) // Bank accounts if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT)) { + $nbBankAccount=0; + $foundonexternalonlinesystem=0; $langs->load("banks"); $title = $langs->trans("BankAccounts"); @@ -185,11 +187,16 @@ function societe_prepare_head(Societe $object) { $langs->load("stripe"); $title = $langs->trans("BankAccountsAndGateways"); + + $servicestatus = 0; + if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha')) $servicestatus = 1; + + include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; + $societeaccount = new SocieteAccount($db); + $stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_... + if ($stripecu) $foundonexternalonlinesystem++; } - $nbBankAccount=0; - $head[$h][0] = DOL_URL_ROOT .'/societe/paymentmodes.php?socid='.$object->id; - $head[$h][1] = $title; $sql = "SELECT COUNT(n.rowid) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib as n"; $sql.= " WHERE fk_soc = ".$object->id; @@ -208,7 +215,13 @@ function societe_prepare_head(Societe $object) else { dol_print_error($db); } - if ($nbBankAccount > 0) $head[$h][1].= ' '.$nbBankAccount.''; + + //if (! empty($conf->stripe->enabled) && $nbBankAccount > 0) $nbBankAccount = '...'; // No way to know exact number + + $head[$h][0] = DOL_URL_ROOT .'/societe/paymentmodes.php?socid='.$object->id; + $head[$h][1] = $title; + if ($foundonexternalonlinesystem) $head[$h][1].= ' ...'; + elseif ($nbBankAccount > 0) $head[$h][1].= ' '.$nbBankAccount.''; $head[$h][2] = 'rib'; $h++; } diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index 9c65b4442d26c..6f36d760c18a1 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -260,7 +260,7 @@ CREATE TABLE llx_societe_account( entity integer DEFAULT 1, key_account varchar(128), login varchar(128) NOT NULL, - pass_encoding varchar(24) NOT NULL, + pass_encoding varchar(24), pass_crypted varchar(128), pass_temp varchar(128), -- temporary password when asked for forget password fk_soc integer, @@ -278,6 +278,7 @@ CREATE TABLE llx_societe_account( -- END MODULEBUILDER FIELDS ) ENGINE=innodb; +-- VMYSQL4.3 ALTER TABLE llx_societe_account MODIFY COLUMN pass_encoding varchar(24) NULL; ALTER TABLE llx_societe_account ADD COLUMN key_account varchar(128); @@ -288,6 +289,7 @@ ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_fk_website (fk_web ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_fk_soc (fk_soc); ALTER TABLE llx_societe_account ADD UNIQUE INDEX uk_societe_account_login_website_soc(entity, fk_soc, login, site, fk_website); +ALTER TABLE llx_societe_account ADD UNIQUE INDEX uk_societe_account_key_account_soc(entity, fk_soc, key_account, site, fk_website); ALTER TABLE llx_societe_account ADD CONSTRAINT llx_societe_account_fk_website FOREIGN KEY (fk_website) REFERENCES llx_website(rowid); ALTER TABLE llx_societe_account ADD CONSTRAINT llx_societe_account_fk_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid); diff --git a/htdocs/install/mysql/tables/llx_societe_account.key.sql b/htdocs/install/mysql/tables/llx_societe_account.key.sql index ece860300c1c0..3e0dc13055447 100644 --- a/htdocs/install/mysql/tables/llx_societe_account.key.sql +++ b/htdocs/install/mysql/tables/llx_societe_account.key.sql @@ -23,6 +23,7 @@ ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_fk_soc (fk_soc); -- END MODULEBUILDER INDEXES ALTER TABLE llx_societe_account ADD UNIQUE INDEX uk_societe_account_login_website_soc(entity, fk_soc, login, site, fk_website); +ALTER TABLE llx_societe_account ADD UNIQUE INDEX uk_societe_account_key_account_soc(entity, fk_soc, key_account, site, fk_website); ALTER TABLE llx_societe_account ADD CONSTRAINT llx_societe_account_fk_website FOREIGN KEY (fk_website) REFERENCES llx_website(rowid); ALTER TABLE llx_societe_account ADD CONSTRAINT llx_societe_account_fk_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid); diff --git a/htdocs/install/mysql/tables/llx_societe_account.sql b/htdocs/install/mysql/tables/llx_societe_account.sql index 4dd17f441ed92..7a0f87cbe5d6a 100644 --- a/htdocs/install/mysql/tables/llx_societe_account.sql +++ b/htdocs/install/mysql/tables/llx_societe_account.sql @@ -21,7 +21,7 @@ CREATE TABLE llx_societe_account( entity integer DEFAULT 1, key_account varchar(128), login varchar(128) NOT NULL, - pass_encoding varchar(24) NOT NULL, + pass_encoding varchar(24), pass_crypted varchar(128), pass_temp varchar(128), -- temporary password when asked for forget password fk_soc integer, diff --git a/htdocs/website/class/websiteaccount.class.php b/htdocs/societe/class/societeaccount.class.php similarity index 85% rename from htdocs/website/class/websiteaccount.class.php rename to htdocs/societe/class/societeaccount.class.php index f24847a4601d3..08b3617e5400a 100644 --- a/htdocs/website/class/websiteaccount.class.php +++ b/htdocs/societe/class/societeaccount.class.php @@ -20,9 +20,9 @@ */ /** - * \file class/websiteaccount.class.php - * \ingroup website - * \brief This file is a CRUD class file for WebsiteAccount (Create/Read/Update/Delete) + * \file class/societeaccount.class.php + * \ingroup societe + * \brief This file is a CRUD class file for SocieteAccount (Create/Read/Update/Delete) */ // Put here all includes required by your class file @@ -31,24 +31,24 @@ //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; /** - * Class for WebsiteAccount + * Class for SocieteAccount */ -class WebsiteAccount extends CommonObject +class SocieteAccount extends CommonObject { /** * @var string ID to identify managed object */ - public $element = 'websiteaccount'; + public $element = 'societeaccount'; /** * @var string Name of table without prefix where object is stored */ - public $table_element = 'website_account'; + public $table_element = 'societe_account'; /** - * @var array Does websiteaccount support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + * @var array Does societeaccount support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe */ public $ismultientitymanaged = 0; /** - * @var string String with name of icon for websiteaccount. Must be the part after the 'object_' into object_myobject.png + * @var string String with name of icon for societeaccount. Must be the part after the 'object_' into object_myobject.png */ public $picto = 'lock'; @@ -76,12 +76,15 @@ class WebsiteAccount extends CommonObject */ public $fields=array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',), - 'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Login',), + 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'default'=>1), + 'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>-1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Key account',), + 'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'position'=>10), 'pass_encoding' => array('type'=>'varchar(24)', 'label'=>'PassEncoding', 'visible'=>0, 'enabled'=>1, 'position'=>30), 'pass_crypted' => array('type'=>'varchar(128)', 'label'=>'Password', 'visible'=>1, 'enabled'=>1, 'position'=>31, 'notnull'=>1), 'pass_temp' => array('type'=>'varchar(128)', 'label'=>'Temp', 'visible'=>0, 'enabled'=>0, 'position'=>32, 'notnull'=>-1,), 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1, 'index'=>1), - 'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>1, 'enabled'=>1, 'position'=>41, 'notnull'=>1, 'index'=>1), + 'site' => array('type'=>'varchar(128)', 'label'=>'Site', 'visible'=>-1, 'enabled'=>1, 'position'=>41), + 'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>1, 'enabled'=>1, 'position'=>42, 'notnull'=>1, 'index'=>1), 'date_last_login' => array('type'=>'datetime', 'label'=>'LastConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>50, 'notnull'=>0,), 'date_previous_login' => array('type'=>'datetime', 'label'=>'PreviousConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>51, 'notnull'=>0,), //'note_public' => array('type'=>'text', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,), @@ -94,9 +97,13 @@ class WebsiteAccount extends CommonObject 'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'default'=>1, 'arrayofkeyval'=>array('1'=>'Active','0'=>'Disabled')), ); public $rowid; - public $login; + public $entity; + public $key_account; public $pass_encoding; public $pass_crypted; + public $pass_temp; + public $fk_soc; + public $site; public $date_last_login; public $date_previous_login; public $note_private; @@ -106,7 +113,6 @@ class WebsiteAccount extends CommonObject public $fk_user_modif; public $import_key; public $status; - public $fk_soc; // END MODULEBUILDER PROPERTIES @@ -117,21 +123,21 @@ class WebsiteAccount extends CommonObject /** * @var int Name of subtable line */ - //public $table_element_line = 'website_accountdet'; + //public $table_element_line = 'societe_accountdet'; /** * @var int Field with ID of parent key if this field has a parent */ - //public $fk_element = 'fk_website_account'; + //public $fk_element = 'fk_societe_account'; /** * @var int Name of subtable class that manage subtable lines */ - //public $class_element_line = 'WebsiteAccountline'; + //public $class_element_line = 'societeAccountline'; /** * @var array Array of child tables (child tables to delete before deleting a record) */ - //protected $childtables=array('website_accountdet'); + //protected $childtables=array('societe_accountdet'); /** - * @var WebsiteAccountLine[] Array of subtable lines + * @var societeAccountLine[] Array of subtable lines */ //public $lines = array(); @@ -235,11 +241,45 @@ public function fetchLines() { $this->lines=array(); - // Load lines with object WebsiteAccountLine + // Load lines with object societeAccountLine return count($this->lines)?1:0; } + /** + * Try to find the external customer id of a thirdparty for an another site/system. + * + * @param int $id Id of third party + * @param string $site Site (example: 'stripe', '...') + * @param int $status Status (0=test, 1=live) + * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or '' + */ + public function getCustomerAccount($id, $site, $status=0) + { + global $conf; + + $sql = "SELECT sa.key_account as key_account, sa.entity"; + $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; + $sql.= " WHERE sa.fk_soc = " . $id; + $sql.= " AND sa.entity IN (".getEntity('societe').")"; + $sql.= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status); + + dol_syslog(get_class($this) . "::getCustomerAccount Try to find the system customer id of thirdparty id=".$id." (exemple: cu_.... for stripe)", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) { + if ($this->db->num_rows($result)) { + $obj = $this->db->fetch_object($result); + $key = $obj->key_account; + } else { + $key = ''; + } + } else { + $key = ''; + } + + return $key; + } + /** * Update object into database * @@ -287,12 +327,12 @@ function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_la $this->ref = $this->login; - $label = '' . $langs->trans("WebsiteAccount") . ''; + $label = '' . $langs->trans("SocieteAccount") . ''; $label.= '
'; $label.= '' . $langs->trans('Login') . ': ' . $this->ref; //$label.= '' . $langs->trans('WebSite') . ': ' . $this->ref; - $url = dol_buildpath('/website/websiteaccount_card.php',1).'?id='.$this->id; + $url = dol_buildpath('/societe/societeaccount_card.php',1).'?id='.$this->id; if ($option != 'nolink') { @@ -307,7 +347,7 @@ function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_la { if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { - $label=$langs->trans("ShowWebsiteAccount"); + $label=$langs->trans("ShowsocieteAccount"); $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"'; @@ -486,10 +526,10 @@ public function doScheduledJob() } /** - * Class WebsiteAccountLine. You can also remove this and generate a CRUD class for lines objects. + * Class societeAccountLine. You can also remove this and generate a CRUD class for lines objects. */ /* -class WebsiteAccountLine +class societeAccountLine { // @var int ID public $id; diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index abaaf0e694d16..898c442b75552 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -33,13 +33,11 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; -$langs->load("companies"); -$langs->load("commercial"); -$langs->load("banks"); -$langs->load("bills"); +$langs->loadLangs(array("companies","commercial","banks","bills")); // Security check $socid = GETPOST("socid","int"); @@ -50,6 +48,7 @@ $source=GETPOST("source","alpha"); $ribid=GETPOST("ribid","int"); $action=GETPOST("action", 'alpha', 3); +$cancel=GETPOST('cancel', 'alpha'); $object = new Societe($db); $object->fetch($socid); @@ -90,6 +89,11 @@ * Actions */ +if ($cancel) +{ + $action=''; +} + $parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -344,35 +348,88 @@ include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; $id = $savid; -} -// Action for stripe -if (! empty($conf->stripe->enabled) && class_exists('Stripe')) -{ - if ($action == 'setassourcedefault') + // Action for stripe + if (! empty($conf->stripe->enabled) && class_exists('Stripe')) { - $cu = \Stripe\Customer::retrieve($stripecu); + if ($action == 'setkey_account') + { + $error = 0; - $cu->default_source = "$source"; // obtained with Stripe.js - $cu->save(); + $newcu = GETPOST('key_account', 'alpha'); - $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; - header('Location: '.$url); - exit; - } - elseif ($action == 'delete') - { - $cu = \Stripe\Customer::retrieve($stripecu); + $db->begin(); - $cu->sources->retrieve("$source")->detach(); + $sql = 'UPDATE '.MAIN_DB_PREFIX."societe_account"; + $sql.= " SET key_account = '".$db->escape(GETPOST('key_account', 'alpha'))."'"; + $sql.= " WHERE site = 'stripe' AND fk_soc = ".$object->id." AND status = ".$servicestatus." AND entity = ".$conf->entity; // Keep = here for entity. Only 1 record must be modified ! - $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; - header('Location: '.$url); - exit; + $resql = $db->query($sql); + $num = $db->num_rows($resql); + if (empty($num)) + { + $societeaccount = new SocieteAccount($db); + $societeaccount->fk_soc = $object->id; + $societeaccount->login = ''; + $societeaccount->pass_encoding = ''; + $societeaccount->site = 'stripe'; + $societeaccount->status = $servicestatus; + $societeaccount->key_account = $newcu; + $result = $societeaccount->create($user); + if ($result < 0) + { + $error++; + } + } + + if (! $error) + { + $stripecu = $newcu; + $db->commit(); + } + else + { + $db->rollback(); + } + } + + if ($action == 'setassourcedefault') + { + try { + $cu = \Stripe\Customer::retrieve($stripecu); + $cu->default_source = (string) $source; + $result = $cu->save(); + + $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; + header('Location: '.$url); + exit; + } + catch(Exception $e) + { + + } + } + elseif ($action == 'delete') + { + try { + $cu = \Stripe\Customer::retrieve($stripecu); + + $cu->sources->retrieve("$source")->detach(); + + $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; + header('Location: '.$url); + exit; + } + catch(Exception $e) + { + + } + } } } + /* * View */ @@ -459,13 +516,15 @@ if (! empty($conf->stripe->enabled)) { - - + $permissiontowrite = $user->rights->societe->creer; // Stripe customer key 'cu_....' stored into llx_societe_account - print '
'.$langs->trans('StripeCustomerId').''; - print $stripecu; + print '
'; + //print $langs->trans('StripeCustomerId'); + print $form->editfieldkey("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', 0, 1, 'socid'); + print ''; + //print $stripecu; + print $form->editfieldval("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', null, null, '', 1, '', 'socid'); print '
'; @@ -475,24 +534,30 @@ if (! (empty($conf->stripe->enabled))) { - print load_fiche_titre($langs->trans('StripeGateways').($stripeacc ? ' ('.$stripeacc.')':''), '', ''); + print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc ? ' ('.$stripeacc.')':''), '', ''); $listofsources = array(); if (is_object($stripe) && $stripeacc) { - $customerstripe=$stripe->customerStripe($object->id, $stripeacc, $servicestatus); - - if ($customerstripe->id) { - $listofsources=$customerstripe->sources->data; + try { + $customerstripe=$stripe->customerStripe($object->id, $stripeacc, $servicestatus); + if ($customerstripe->id) { + $listofsources=$customerstripe->sources->data; + } + } + catch(Exception $e) + { + dol_syslog("Failed to get strip customer for thirdparty id =".$object->id); } } print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''."\n"; print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; print ''; print "\n"; @@ -500,7 +565,10 @@ { foreach ($listofsources as $src) { - print ''; + print ''; + print ''; print ''; // Default print ''; print ''; @@ -603,8 +671,9 @@ // List of bank accounts + print '
'; - $morehtmlright=''.$langs->trans("Add").''; + $morehtmlright=''.$langs->trans("Add").''; print load_fiche_titre($langs->trans("AllRIB"), $morehtmlright, ''); diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index dfecc56a1722d..5f86c45f6965e 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -94,32 +94,15 @@ public function getStripeAccount($mode='StripeTest') * * @param int $id Id of third party * @param int $status Status - * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' + * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or '' */ public function getStripeCustomerAccount($id, $status=0) { global $conf; - $sql = "SELECT sa.key_account as key_account, sa.entity"; - $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; - $sql.= " WHERE sa.fk_soc = " . $id; - $sql.= " AND sa.entity IN (".getEntity('societe').")"; - $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status); - - dol_syslog(get_class($this) . "::getStripeCustomerAccount Try to find the cu_.... of thirdparty id=".$id, LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { - if ($this->db->num_rows($result)) { - $obj = $this->db->fetch_object($result); - $key = $obj->key_account; - } else { - $key = NULL; - } - } else { - $key = NULL; - } - - return $key; + include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; + $societeaccount = new SocieteAccount($this->db); + return $societeaccount->getCustomerAccount($id, 'stripe', $status); // Get thirdparty cu_... }
'.$langs->trans('Type').''.$langs->trans('Informations').''.$langs->trans('ID').''.$langs->trans('Type').''.$langs->trans('Informations').''.$langs->trans('Default').'
'; + print $src->id; + print ''; if ($src->object=='card') { @@ -511,7 +579,7 @@ elseif ($src->brand == 'JCB') {$brand='cc-jcb';} elseif ($src->brand == 'Diners Club') {$brand='cc-diners-club';} else {$brand='credit-card';} - print ''; + print ''; } elseif ($src->object=='source' && $src->type=='card') { @@ -522,11 +590,11 @@ elseif ($src->card->brand == 'JCB') {$brand='cc-jcb';} elseif ($src->card->brand == 'Diners Club') {$brand='cc-diners-club';} else {$brand='credit-card';} - print ''; + print ''; } elseif ($src->object=='source' && $src->type=='sepa_debit') { - print ''; + print ''; } print''; @@ -570,13 +638,13 @@ print ''; - if (($customerstripe->default_source!=$src->id)) + if (($customerstripe->default_source != $src->id)) { print ''; - print ""; + print img_picto($langs->trans("Default"),'off'); print ''; } else { - print ""; + print img_picto($langs->trans("Default"),'on'); } print ''; @@ -587,7 +655,7 @@ // print ''; // print ' '; print ''; - print ""; + print img_delete($langs->trans("Delete")); print ''; } print '