Use code of societeaccount
This commit is contained in:
parent
944ba69cd8
commit
2566170c68
@ -178,6 +178,8 @@ function societe_prepare_head(Societe $object)
|
|||||||
// Bank accounts
|
// Bank accounts
|
||||||
if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT))
|
if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT))
|
||||||
{
|
{
|
||||||
|
$nbBankAccount=0;
|
||||||
|
$foundonexternalonlinesystem=0;
|
||||||
$langs->load("banks");
|
$langs->load("banks");
|
||||||
|
|
||||||
$title = $langs->trans("BankAccounts");
|
$title = $langs->trans("BankAccounts");
|
||||||
@ -185,11 +187,16 @@ function societe_prepare_head(Societe $object)
|
|||||||
{
|
{
|
||||||
$langs->load("stripe");
|
$langs->load("stripe");
|
||||||
$title = $langs->trans("BankAccountsAndGateways");
|
$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 = "SELECT COUNT(n.rowid) as nb";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib as n";
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib as n";
|
||||||
$sql.= " WHERE fk_soc = ".$object->id;
|
$sql.= " WHERE fk_soc = ".$object->id;
|
||||||
@ -211,7 +218,10 @@ function societe_prepare_head(Societe $object)
|
|||||||
|
|
||||||
//if (! empty($conf->stripe->enabled) && $nbBankAccount > 0) $nbBankAccount = '...'; // No way to know exact number
|
//if (! empty($conf->stripe->enabled) && $nbBankAccount > 0) $nbBankAccount = '...'; // No way to know exact number
|
||||||
|
|
||||||
if ($nbBankAccount > 0) $head[$h][1].= ' <span class="badge">'.$nbBankAccount.'</span>';
|
$head[$h][0] = DOL_URL_ROOT .'/societe/paymentmodes.php?socid='.$object->id;
|
||||||
|
$head[$h][1] = $title;
|
||||||
|
if ($foundonexternalonlinesystem) $head[$h][1].= ' <span class="badge">...</span>';
|
||||||
|
elseif ($nbBankAccount > 0) $head[$h][1].= ' <span class="badge">'.$nbBankAccount.'</span>';
|
||||||
$head[$h][2] = 'rib';
|
$head[$h][2] = 'rib';
|
||||||
$h++;
|
$h++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -246,6 +246,40 @@ class SocieteAccount extends CommonObject
|
|||||||
return count($this->lines)?1:0;
|
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
|
* Update object into database
|
||||||
*
|
*
|
||||||
|
|||||||
@ -94,32 +94,15 @@ class Stripe extends CommonObject
|
|||||||
*
|
*
|
||||||
* @param int $id Id of third party
|
* @param int $id Id of third party
|
||||||
* @param int $status Status
|
* @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)
|
public function getStripeCustomerAccount($id, $status=0)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$sql = "SELECT sa.key_account as key_account, sa.entity";
|
include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
|
||||||
$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
|
$societeaccount = new SocieteAccount($this->db);
|
||||||
$sql.= " WHERE sa.fk_soc = " . $id;
|
return $societeaccount->getCustomerAccount($object->id, 'stripe', $status); // Get thirdparty cu_...
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user