Fix: add entity field in llx_societe_remise_except, useful when
third-sharing is used with multicompany
This commit is contained in:
parent
63ad970a27
commit
ee02ff43d7
@ -248,7 +248,8 @@ if ($socid > 0)
|
||||
$remise_all=$remise_user=0;
|
||||
$sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
||||
$sql.= " WHERE rc.fk_soc =". $object->id;
|
||||
$sql.= " WHERE rc.fk_soc = " . $object->id;
|
||||
$sql.= " AND rc.entity = " . $conf->entity;
|
||||
$sql.= " AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
|
||||
$sql.= " GROUP BY rc.fk_user";
|
||||
$resql=$db->query($sql);
|
||||
@ -318,7 +319,8 @@ if ($socid > 0)
|
||||
$sql.= " fa.facnumber as ref, fa.type as type";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
|
||||
$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";
|
||||
$sql.= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
|
||||
$sql.= " ORDER BY rc.datec DESC";
|
||||
|
||||
@ -66,6 +66,8 @@ class DiscountAbsolute
|
||||
*/
|
||||
function fetch($rowid,$fk_facture_source=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Check parameters
|
||||
if (! $rowid && ! $fk_facture_source)
|
||||
{
|
||||
@ -81,9 +83,9 @@ class DiscountAbsolute
|
||||
$sql.= " f.facnumber as ref_facture_source";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid";
|
||||
$sql.= " WHERE";
|
||||
if ($rowid) $sql.= " sr.rowid=".$rowid;
|
||||
if ($fk_facture_source) $sql.= " sr.fk_facture_source=".$fk_facture_source;
|
||||
$sql.= " WHERE sr.entity = " . $conf->entity;
|
||||
if ($rowid) $sql.= " AND sr.rowid=".$rowid;
|
||||
if ($fk_facture_source) $sql.= " AND sr.fk_facture_source=".$fk_facture_source;
|
||||
|
||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
@ -150,11 +152,11 @@ class DiscountAbsolute
|
||||
|
||||
// Insert request
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";
|
||||
$sql.= " (datec, fk_soc, fk_user, description,";
|
||||
$sql.= " (entity, datec, fk_soc, fk_user, description,";
|
||||
$sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,";
|
||||
$sql.= " fk_facture_source";
|
||||
$sql.= ")";
|
||||
$sql.= " VALUES ('".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',";
|
||||
$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',";
|
||||
$sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.",";
|
||||
$sql.= " ".($this->fk_facture_source?"'".$this->fk_facture_source."'":"null");
|
||||
$sql.= ")";
|
||||
@ -343,10 +345,13 @@ class DiscountAbsolute
|
||||
*/
|
||||
function getAvailableDiscounts($company='', $user='',$filter='', $maxvalue=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT SUM(rc.amount_ttc) as amount";
|
||||
// $sql = "SELECT rc.amount_ttc as amount";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
||||
$sql.= " WHERE (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available
|
||||
$sql.= " WHERE rc.entity = " . $conf->entity;
|
||||
$sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available
|
||||
if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id;
|
||||
if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id;
|
||||
if ($filter) $sql.=' AND ('.$filter.')';
|
||||
|
||||
@ -1117,7 +1117,8 @@ class Form
|
||||
$sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
|
||||
$sql.= " re.description, re.fk_facture_source";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
|
||||
$sql.= " WHERE fk_soc = ".(int) $socid;
|
||||
$sql.= " WHERE re.fk_soc = ".(int) $socid;
|
||||
$sql.= " AND re.entity = " . $conf->entity;
|
||||
if ($filter) $sql.= " AND ".$filter;
|
||||
$sql.= " ORDER BY re.description ASC";
|
||||
|
||||
|
||||
@ -327,6 +327,7 @@ 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_facturefourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
|
||||
|
||||
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_tva double(24,8) DEFAULT 0 NOT NULL;
|
||||
ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_ttc double(24,8) DEFAULT 0 NOT NULL;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -402,6 +402,9 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
|
||||
$beforeversionarray=explode('.','4.0.9');
|
||||
if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0)
|
||||
{
|
||||
// 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)
|
||||
@ -3658,6 +3661,118 @@ function migrate_event_assignement($db,$langs,$conf)
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 '<tr><td colspan="4">';
|
||||
|
||||
print '<br>';
|
||||
print '<b>'.$langs->trans('MigrationRemiseExceptEntity')."</b><br>\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')."<br>\n";
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$db->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
$db->rollback();
|
||||
}
|
||||
|
||||
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration directory
|
||||
*
|
||||
|
||||
@ -184,6 +184,7 @@ 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
|
||||
MigrationRemiseExceptEntity=Update entity field value of llx_societe_remise_except
|
||||
MigrationReloadModule=Reload module %s
|
||||
ShowNotAvailableOptions=Show not available options
|
||||
HideNotAvailableOptions=Hide not available options
|
||||
|
||||
Loading…
Reference in New Issue
Block a user