Skip to content

Commit

Permalink
Merge branch 'develop' into patch-17
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 13, 2018
2 parents 1ff13cf + 0a642a2 commit 43c8309
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 100 deletions.
10 changes: 6 additions & 4 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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.='</td>';
if (empty($notabletag) && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.='<td align="right">';
if ($htmlname && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.='<a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;id='.$object->id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).'</a>';
if ($htmlname && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.='<a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;'.$paramid.'='.$object->id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).'</a>';
if (! empty($notabletag) && $notabletag == 1) $ret.=' : ';
if (! empty($notabletag) && $notabletag == 3) $ret.=' ';
if (empty($notabletag) && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.='</td>';
Expand All @@ -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;

Expand All @@ -166,7 +168,7 @@ function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='str
$ret.='<form method="post" action="'.$_SERVER["PHP_SELF"].($moreparam?'?'.$moreparam:'').'">';
$ret.='<input type="hidden" name="action" value="set'.$htmlname.'">';
$ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$ret.='<input type="hidden" name="id" value="'.$object->id.'">';
$ret.='<input type="hidden" name="'.$paramid.'" value="'.$object->id.'">';
if (empty($notabletag)) $ret.='<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
if (empty($notabletag)) $ret.='<tr><td>';
if (preg_match('/^(string|email)/',$typeofdata))
Expand Down
21 changes: 17 additions & 4 deletions htdocs/core/lib/company.lib.php
Expand Up @@ -178,18 +178,25 @@ 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");
if (! empty($conf->stripe->enabled))
{
$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;
Expand All @@ -208,7 +215,13 @@ function societe_prepare_head(Societe $object)
else {
dol_print_error($db);
}
if ($nbBankAccount > 0) $head[$h][1].= ' <span class="badge">'.$nbBankAccount.'</span>';

//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].= ' <span class="badge">...</span>';
elseif ($nbBankAccount > 0) $head[$h][1].= ' <span class="badge">'.$nbBankAccount.'</span>';
$head[$h][2] = 'rib';
$h++;
}
Expand Down
4 changes: 3 additions & 1 deletion htdocs/install/mysql/migration/7.0.0-8.0.0.sql
Expand Up @@ -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,
Expand All @@ -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);

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions htdocs/install/mysql/tables/llx_societe_account.key.sql
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/install/mysql/tables/llx_societe_account.sql
Expand Up @@ -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,
Expand Down
Expand Up @@ -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
Expand All @@ -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';

Expand Down Expand Up @@ -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,),
Expand All @@ -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;
Expand All @@ -106,7 +113,6 @@ class WebsiteAccount extends CommonObject
public $fk_user_modif;
public $import_key;
public $status;
public $fk_soc;
// END MODULEBUILDER PROPERTIES


Expand All @@ -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();

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -287,12 +327,12 @@ function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_la

$this->ref = $this->login;

$label = '<u>' . $langs->trans("WebsiteAccount") . '</u>';
$label = '<u>' . $langs->trans("SocieteAccount") . '</u>';
$label.= '<br>';
$label.= '<b>' . $langs->trans('Login') . ':</b> ' . $this->ref;
//$label.= '<b>' . $langs->trans('WebSite') . ':</b> ' . $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')
{
Expand All @@ -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).'"';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 43c8309

Please sign in to comment.