Fix: add entity field in llx_societe_remise, useful when third-sharing

is used with multicompany
This commit is contained in:
Regis Houssin 2016-07-07 12:43:02 +02:00
parent ee02ff43d7
commit 08725003b9
6 changed files with 120 additions and 25 deletions

View File

@ -162,6 +162,7 @@ if ($socid > 0)
$sql.= " u.login, u.rowid as user_id"; $sql.= " u.login, u.rowid as user_id";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE rc.fk_soc = " . $object->id; $sql.= " WHERE rc.fk_soc = " . $object->id;
$sql.= " AND rc.entity = " . $conf->entity;
$sql.= " AND u.rowid = rc.fk_user_author"; $sql.= " AND u.rowid = rc.fk_user_author";
$sql.= " ORDER BY rc.datec DESC"; $sql.= " ORDER BY rc.datec DESC";

View File

@ -327,6 +327,8 @@ ALTER TABLE llx_paiement_facture ADD COLUMN multicurrency_amount double(24,8) DE
ALTER TABLE llx_paiementfourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0; ALTER TABLE llx_paiementfourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
ALTER TABLE llx_paiementfourn_facturefourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0; ALTER TABLE llx_paiementfourn_facturefourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
ALTER TABLE llx_societe_remise ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid;
ALTER TABLE llx_societe_remise_except ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid; ALTER TABLE llx_societe_remise_except ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid;
ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_ht double(24,8) DEFAULT 0 NOT NULL; ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_ht double(24,8) DEFAULT 0 NOT NULL;
ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_tva double(24,8) DEFAULT 0 NOT NULL; ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_tva double(24,8) DEFAULT 0 NOT NULL;

View File

@ -1,6 +1,6 @@
-- ======================================================================== -- ========================================================================
-- Copyright (C) 2000-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> -- Copyright (C) 2000-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2011 Regis Houssin <regis.houssin@capnetworks.com> -- Copyright (C) 2011-2016 Regis Houssin <regis.houssin@capnetworks.com>
-- --
-- This program is free software; you can redistribute it and/or modify -- 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 -- it under the terms of the GNU General Public License as published by
@ -22,6 +22,7 @@
create table llx_societe_remise create table llx_societe_remise
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
entity integer DEFAULT 1 NOT NULL, -- multi company id
fk_soc integer NOT NULL, fk_soc integer NOT NULL,
tms timestamp, tms timestamp,
datec datetime, -- creation date datec datetime, -- creation date

View File

@ -402,6 +402,9 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
$beforeversionarray=explode('.','4.0.9'); $beforeversionarray=explode('.','4.0.9');
if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) 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 to add entity value into llx_societe_remise_except
migrate_remise_except_entity($db,$langs,$conf); migrate_remise_except_entity($db,$langs,$conf);
@ -3661,6 +3664,84 @@ function migrate_event_assignement($db,$langs,$conf)
print '</td></tr>'; print '</td></tr>';
} }
/**
* 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 '<tr><td colspan="4">';
print '<br>';
print '<b>'.$langs->trans('MigrationRemiseEntity')."</b><br>\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')."<br>\n";
}
if (! $error)
{
$db->commit();
}
else
{
$db->rollback();
}
}
else
{
dol_print_error($db);
$db->rollback();
}
print '</td></tr>';
}
/** /**
* Migrate to add entity value into llx_societe_remise_except * Migrate to add entity value into llx_societe_remise_except
* *

View File

@ -184,6 +184,7 @@ MigrationActioncommElement=Update data on actions
MigrationPaymentMode=Data migration for payment mode MigrationPaymentMode=Data migration for payment mode
MigrationCategorieAssociation=Migration of categories MigrationCategorieAssociation=Migration of categories
MigrationEvents=Migration of events to add event owner into assignement table 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 MigrationRemiseExceptEntity=Update entity field value of llx_societe_remise_except
MigrationReloadModule=Reload module %s MigrationReloadModule=Reload module %s
ShowNotAvailableOptions=Show not available options ShowNotAvailableOptions=Show not available options

View File

@ -1424,6 +1424,18 @@ class Societe extends CommonObject
// Remove societe_remise_except // Remove societe_remise_except
if (! $error) 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)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except";
$sql.= " WHERE fk_soc = " . $id; $sql.= " WHERE fk_soc = " . $id;
@ -1533,7 +1545,7 @@ class Societe extends CommonObject
*/ */
function set_remise_client($remise, $note, User $user) function set_remise_client($remise, $note, User $user)
{ {
global $langs; global $conf, $langs;
// Nettoyage parametres // Nettoyage parametres
$note=trim($note); $note=trim($note);
@ -1565,8 +1577,8 @@ class Societe extends CommonObject
// Ecrit trace dans historique des remises // Ecrit trace dans historique des remises
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise";
$sql.= " (datec, fk_soc, remise_client, note, fk_user_author)"; $sql.= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
$sql.= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',"; $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
$sql.= " '".$this->db->escape($note)."',"; $sql.= " '".$this->db->escape($note)."',";
$sql.= " ".$user->id; $sql.= " ".$user->id;
$sql.= ")"; $sql.= ")";
@ -3478,13 +3490,10 @@ class Societe extends CommonObject
* Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some * Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some
* Because this function is meant to be executed within a transaction, we won't take care of it. * Because this function is meant to be executed within a transaction, we won't take care of it.
*/ */
$sql = 'SELECT rowid $sql = 'SELECT rowid';
FROM '.MAIN_DB_PREFIX.'societe_commerciaux $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux';
WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( $sql.= ' WHERE fk_soc = ' . (int) $dest_id;
SELECT fk_user $sql.= ' AND fk_user IN (SELECT fk_user FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE fk_soc = '.(int) $origin_id.');';
FROM '.MAIN_DB_PREFIX.'societe_commerciaux
WHERE fk_soc = '.(int) $origin_id.'
);';
$query = $db->query($sql); $query = $db->query($sql);