--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@@ -21,13 +21,14 @@
create table llx_societe_remise
(
- rowid integer AUTO_INCREMENT PRIMARY KEY,
- fk_soc integer NOT NULL,
- tms timestamp,
- datec datetime, -- creation date
- fk_user_author integer, -- creation user
- remise_client double(6,3) DEFAULT 0 NOT NULL, -- discount
- note text
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ entity integer DEFAULT 1 NOT NULL, -- multi company id
+ fk_soc integer NOT NULL,
+ tms timestamp,
+ datec datetime, -- creation date
+ fk_user_author integer, -- creation user
+ remise_client double(6,3) DEFAULT 0 NOT NULL, -- discount
+ note text
)ENGINE=innodb;
diff --git a/htdocs/install/mysql/tables/llx_societe_remise_except.sql b/htdocs/install/mysql/tables/llx_societe_remise_except.sql
index f17d17670d2..4c55e34425c 100644
--- a/htdocs/install/mysql/tables/llx_societe_remise_except.sql
+++ b/htdocs/install/mysql/tables/llx_societe_remise_except.sql
@@ -21,18 +21,19 @@
create table llx_societe_remise_except
(
- rowid integer AUTO_INCREMENT PRIMARY KEY,
- fk_soc integer NOT NULL, -- client
- datec datetime,
- amount_ht double(24,8) NOT NULL,
- amount_tva double(24,8) DEFAULT 0 NOT NULL,
- amount_ttc double(24,8) DEFAULT 0 NOT NULL,
- tva_tx double(6,3) DEFAULT 0 NOT NULL,
- fk_user integer NOT NULL,
- fk_facture_line integer,
- fk_facture integer,
- fk_facture_source integer,
- description text NOT NULL,
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ entity integer DEFAULT 1 NOT NULL, -- multi company id
+ fk_soc integer NOT NULL, -- client
+ datec datetime,
+ amount_ht double(24,8) NOT NULL,
+ amount_tva double(24,8) DEFAULT 0 NOT NULL,
+ amount_ttc double(24,8) DEFAULT 0 NOT NULL,
+ tva_tx double(6,3) DEFAULT 0 NOT NULL,
+ fk_user integer NOT NULL,
+ fk_facture_line integer,
+ fk_facture integer,
+ fk_facture_source integer,
+ description text NOT NULL,
multicurrency_amount_ht double(24,8) DEFAULT 0 NOT NULL,
multicurrency_amount_tva double(24,8) DEFAULT 0 NOT NULL,
multicurrency_amount_ttc double(24,8) DEFAULT 0 NOT NULL
diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php
index 74e3af98249..6167510e527 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -397,14 +397,20 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
// Reload menus (this must be always and only into last targeted version)
migrate_reload_menu($db,$langs,$conf,$versionto);
}
-
+
// Scripts for last version
$afterversionarray=explode('.','3.9.9');
$beforeversionarray=explode('.','4.0.9');
if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0)
{
+ // Migrate to add entity value into llx_societe_remise
+ migrate_remise_entity($db,$langs,$conf);
+
+ // Migrate to add entity value into llx_societe_remise_except
+ migrate_remise_except_entity($db,$langs,$conf);
+
migrate_directories($db,$langs,$conf,'/fckeditor','/medias');
-
+
// Reload modules (this must be always and only into last targeted version)
$listofmodule=array(
'MAIN_MODULE_BARCODE'=>'newboxdefonly',
@@ -413,12 +419,12 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
'MAIN_MODULE_PRINTING'=>'newboxdefonly',
);
migrate_reload_modules($db,$langs,$conf,$listofmodule);
-
+
// Reload menus (this must be always and only into last targeted version)
migrate_reload_menu($db,$langs,$conf,$versionto);
}
-
+
// Can force activation of some module during migration with third paramater = MAIN_MODULE_XXX,MAIN_MODULE_YYY,...
if ($enablemodules)
{
@@ -431,8 +437,8 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
}
migrate_reload_modules($db,$langs,$conf,$listofmodules,1);
}
-
-
+
+
print ' '.$langs->trans("MigrationFinished").' |
';
// On commit dans tous les cas.
@@ -1329,10 +1335,10 @@ function migrate_paiementfourn_facturefourn($db,$langs,$conf)
function migrate_price_facture($db,$langs,$conf)
{
$err=0;
-
+
$tmpmysoc=new Societe($db);
$tmpmysoc->setMysoc($conf);
-
+
$db->begin();
print '| ';
@@ -1449,7 +1455,7 @@ function migrate_price_propal($db,$langs,$conf)
{
$tmpmysoc=new Societe($db);
$tmpmysoc->setMysoc($conf);
-
+
$db->begin();
print ' |
| ';
@@ -1648,7 +1654,7 @@ function migrate_price_commande($db,$langs,$conf)
$tmpmysoc=new Societe($db);
$tmpmysoc->setMysoc($conf);
-
+
print ' |
';
print ' ';
@@ -1762,10 +1768,10 @@ function migrate_price_commande($db,$langs,$conf)
function migrate_price_commande_fournisseur($db,$langs,$conf)
{
$db->begin();
-
+
$tmpmysoc=new Societe($db);
$tmpmysoc->setMysoc($conf);
-
+
print ' |
';
print ' ';
@@ -3659,6 +3665,196 @@ function migrate_event_assignement($db,$langs,$conf)
print ' |
';
}
+/**
+ * Migrate to add entity value into llx_societe_remise
+ *
+ * @param DoliDB $db Database handler
+ * @param Translate $langs Object langs
+ * @param Conf $conf Object conf
+ * @return void
+ */
+function migrate_remise_entity($db,$langs,$conf)
+{
+ print '';
+
+ print ' ';
+ print ''.$langs->trans('MigrationRemiseEntity')." \n";
+
+ $error = 0;
+
+ dolibarr_install_syslog("upgrade2::migrate_remise_entity");
+
+ $db->begin();
+
+ $sqlSelect = "SELECT sr.rowid, s.entity";
+ $sqlSelect.= " FROM ".MAIN_DB_PREFIX."societe_remise as sr, ".MAIN_DB_PREFIX."societe as s";
+ $sqlSelect.= " WHERE sr.fk_soc = s.rowid";
+
+ //print $sqlSelect;
+
+ $resql = $db->query($sqlSelect);
+ if ($resql)
+ {
+ $i = 0;
+ $num = $db->num_rows($resql);
+
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+
+ $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise SET";
+ $sqlUpdate.= " entity = " . $obj->entity;
+ $sqlUpdate.= " WHERE rowid = " . $obj->rowid;
+
+ $result=$db->query($sqlUpdate);
+ if (! $result)
+ {
+ $error++;
+ dol_print_error($db);
+ }
+
+ print ". ";
+ $i++;
+ }
+ }
+ else
+ {
+ print $langs->trans('AlreadyDone')." \n";
+ }
+
+ if (! $error)
+ {
+ $db->commit();
+ }
+ else
+ {
+ $db->rollback();
+ }
+ }
+ else
+ {
+ dol_print_error($db);
+ $db->rollback();
+ }
+
+
+ print ' |
';
+}
+
+/**
+ * Migrate to add entity value into llx_societe_remise_except
+ *
+ * @param DoliDB $db Database handler
+ * @param Translate $langs Object langs
+ * @param Conf $conf Object conf
+ * @return void
+ */
+function migrate_remise_except_entity($db,$langs,$conf)
+{
+ print '';
+
+ print ' ';
+ print ''.$langs->trans('MigrationRemiseExceptEntity')." \n";
+
+ $error = 0;
+
+ dolibarr_install_syslog("upgrade2::migrate_remise_except_entity");
+
+ $db->begin();
+
+ $sqlSelect = "SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
+ $sqlSelect.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
+ //print $sqlSelect;
+
+ $resql = $db->query($sqlSelect);
+ if ($resql)
+ {
+ $i = 0;
+ $num = $db->num_rows($resql);
+
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+
+ if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture))
+ {
+ $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
+
+ $sqlSelect2 = "SELECT f.entity";
+ $sqlSelect2.= " FROM ".MAIN_DB_PREFIX."facture as f";
+ $sqlSelect2.= " WHERE f.rowid = " . $fk_facture;
+ }
+ else if (!empty($obj->fk_facture_line))
+ {
+ $sqlSelect2 = "SELECT f.entity";
+ $sqlSelect2.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd";
+ $sqlSelect2.= " WHERE fd.rowid = " . $obj->fk_facture_line;
+ $sqlSelect2.= " AND fd.fk_facture = f.rowid";
+ }
+ else
+ {
+ $sqlSelect2 = "SELECT s.entity";
+ $sqlSelect2.= " FROM ".MAIN_DB_PREFIX."societe as s";
+ $sqlSelect2.= " WHERE s.rowid = " . $obj->fk_soc;
+ }
+
+ $resql2 = $db->query($sqlSelect2);
+ if ($resql2)
+ {
+ if ($db->num_rows($resql2) > 0)
+ {
+ $obj2 = $db->fetch_object($resql2);
+
+ $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except SET";
+ $sqlUpdate.= " entity = " . $obj2->entity;
+ $sqlUpdate.= " WHERE rowid = " . $obj->rowid;
+
+ $result=$db->query($sqlUpdate);
+ if (! $result)
+ {
+ $error++;
+ dol_print_error($db);
+ }
+ }
+ }
+ else
+ {
+ $error++;
+ dol_print_error($db);
+ }
+
+ print ". ";
+ $i++;
+ }
+ }
+ else
+ {
+ print $langs->trans('AlreadyDone')." \n";
+ }
+
+ if (! $error)
+ {
+ $db->commit();
+ }
+ else
+ {
+ $db->rollback();
+ }
+ }
+ else
+ {
+ dol_print_error($db);
+ $db->rollback();
+ }
+
+
+ print ' |
';
+}
+
/**
* Migration directory
*
@@ -3826,7 +4022,7 @@ function migrate_reload_modules($db,$langs,$conf,$listofmodule=array(),$force=0)
if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && ! $force)) continue; // Discard reload if module not enabled
$mod=null;
-
+
if ($moduletoreload == 'MAIN_MODULE_AGENDA')
{
dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate Agenda module");
@@ -3999,7 +4195,7 @@ function migrate_reload_modules($db,$langs,$conf,$listofmodule=array(),$force=0)
}
if (! empty($mod) && is_object($mod))
- {
+ {
print '| ';
print ''.$langs->trans('Upgrade').': ';
print $langs->trans('MigrationReloadModule').' '.$mod->getName(); // We keep getName outside of trans because getName is already encoded/translated
@@ -4031,7 +4227,7 @@ function migrate_reload_menu($db,$langs,$conf,$versionto)
$versiontoarray=explode('.',$versionto);
- // Migration required when target version is between
+ // Migration required when target version is between
$afterversionarray=explode('.','2.8.9');
$beforeversionarray=explode('.','2.9.9');
if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0)
@@ -4039,7 +4235,7 @@ function migrate_reload_menu($db,$langs,$conf,$versionto)
$listofmenuhandler['auguria']=1; // We set here only dynamic menu handlers
}
- // Migration required when target version is between
+ // Migration required when target version is between
$afterversionarray=explode('.','3.1.9');
$beforeversionarray=explode('.','3.2.9');
if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0)
@@ -4054,7 +4250,7 @@ function migrate_reload_menu($db,$langs,$conf,$versionto)
{
$listofmenuhandler['auguria']=1; // We set here only dynamic menu handlers
}
-
+
foreach ($listofmenuhandler as $key => $val)
{
print ' |
| ';
diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang
index 69711cb77cc..cbe453ef245 100644
--- a/htdocs/langs/en_US/install.lang
+++ b/htdocs/langs/en_US/install.lang
@@ -191,6 +191,8 @@ MigrationActioncommElement=Update data on actions
MigrationPaymentMode=Data migration for payment mode
MigrationCategorieAssociation=Migration of categories
MigrationEvents=Migration of events to add event owner into assignement table
+MigrationRemiseEntity=Update entity field value of llx_societe_remise
+MigrationRemiseExceptEntity=Update entity field value of llx_societe_remise_except
MigrationReloadModule=Reload module %s
ShowNotAvailableOptions=Show not available options
HideNotAvailableOptions=Hide not available options
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 61b3ccae469..3bd03e0673e 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -1166,7 +1166,7 @@ class Societe extends CommonObject
$this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
$this->shipping_method_id = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
$this->fk_account = $obj->fk_account;
-
+
$this->client = $obj->client;
$this->fournisseur = $obj->fournisseur;
@@ -1431,6 +1431,18 @@ class Societe extends CommonObject
}
}
+ // Remove societe_remise
+ if (! $error)
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise";
+ $sql.= " WHERE fk_soc = " . $id;
+ if (! $this->db->query($sql))
+ {
+ $error++;
+ $this->error = $this->db->lasterror();
+ }
+ }
+
// Remove societe_remise_except
if (! $error)
{
@@ -1542,7 +1554,7 @@ class Societe extends CommonObject
*/
function set_remise_client($remise, $note, User $user)
{
- global $langs;
+ global $conf, $langs;
// Nettoyage parametres
$note=trim($note);
@@ -1574,8 +1586,8 @@ class Societe extends CommonObject
// Ecrit trace dans historique des remises
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise";
- $sql.= " (datec, fk_soc, remise_client, note, fk_user_author)";
- $sql.= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
+ $sql.= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
+ $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
$sql.= " '".$this->db->escape($note)."',";
$sql.= " ".$user->id;
$sql.= ")";
@@ -1922,7 +1934,7 @@ class Societe extends CommonObject
}
$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose.=' class="classfortooltip"';
-
+
if (! is_object($hookmanager))
{
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
@@ -2760,7 +2772,7 @@ class Societe extends CommonObject
$url='';
$action = '';
-
+
$hookmanager->initHooks(array('idprofurl'));
$parameters=array('idprof'=>$idprof, 'company'=>$thirdparty);
$reshook=$hookmanager->executeHooks('getIdProfUrl',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
@@ -2773,14 +2785,14 @@ class Societe extends CommonObject
//if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/'; // Link no more valid
if ($idprof == 1 && $thirdparty->country_code == 'ES') $url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$thirdparty->idprof1;
if ($idprof == 1 && $thirdparty->country_code == 'IN') $url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$thirdparty->idprof1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
-
+
if ($url) return ''.$langs->trans("Check").'';
}
else
{
return $hookmanager->resPrint;
}
-
+
return '';
}
@@ -3508,9 +3520,9 @@ class Societe extends CommonObject
*/
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
$sql .= ' WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( ';
- $sql = ' SELECT fk_user ';
- $sql = ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
- $sql = ' WHERE fk_soc = '.(int) $origin_id.') ';
+ $sql .= ' SELECT fk_user ';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
+ $sql .= ' WHERE fk_soc = '.(int) $origin_id.') ';
$query = $db->query($sql);
|