Skip to content

Commit

Permalink
Merge pull request #916 from FHenry/3.3
Browse files Browse the repository at this point in the history
Fix margin calculation problem
  • Loading branch information
Juanjo Menent committed May 6, 2013
2 parents 1c9caeb + 0bb9ee1 commit 934657c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 15 deletions.
4 changes: 3 additions & 1 deletion htdocs/core/modules/DolibarrModules.class.php
Expand Up @@ -906,7 +906,9 @@ function insert_permissions($reinitadminperms=0, $force_entity=null)
dol_syslog(get_class($this)."::insert_permissions Add permission to user id=".$obj2->rowid);
$tmpuser=new User($this->db);
$tmpuser->fetch($obj2->rowid);
$tmpuser->addrights($r_id);
if (!empty($tmpuser->id)) {
$tmpuser->addrights($r_id);
}
$i++;
}
if (! empty($user->admin)) // Reload permission for current user if defined
Expand Down
4 changes: 3 additions & 1 deletion htdocs/fichinter/class/fichinter.class.php
Expand Up @@ -167,7 +167,9 @@ function create()
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('FICHINTER_CREATE',$this,$user,$langs,$conf);
$tmpuser=new User($this->db);
$tmpuser->fetch($this->author);
$result=$interface->run_triggers('FICHINTER_CREATE',$this,$tmpuser,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
Expand Down
4 changes: 2 additions & 2 deletions htdocs/langs/fr_FR/dict.lang
Expand Up @@ -274,8 +274,8 @@ CurrencyMAD=Dirham
CurrencySingMAD=Dirham
CurrencyMGA=Ariary
CurrencySingMGA=Ariary
CurrencyMUR=Roupies mauritiennes
CurrencySingMUR=Roupie mauritienne
CurrencyMUR=Roupies mauriciennes
CurrencySingMUR=Roupie mauriciennes
CurrencyNOK=Couronnes norvégiennes
CurrencySingNOK=Couronne norvégienne
CurrencySUR=Roubles
Expand Down
5 changes: 3 additions & 2 deletions htdocs/margin/agentMargins.php
Expand Up @@ -128,7 +128,7 @@
$sql.= " u.login, u.name, u.firstname,";
$sql.= " sum(d.total_ht) as selling_price,";
$sql.= $db->ifsql('f.type =2','sum(d.buy_price_ht * d.qty *-1)','sum(d.buy_price_ht * d.qty)')." as buying_price, ";
$sql.= $db->ifsql('f.type =2','sum((d.price + d.buy_price_ht) * d.qty)','sum((d.price - d.buy_price_ht) * d.qty)')." as marge" ;
$sql.= $db->ifsql('f.type =2','sum(d.total_ht + (d.buy_price_ht * d.qty))','sum(d.total_ht - (d.buy_price_ht * d.qty))')." as marge" ;
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact e ON e.element_id = f.rowid and e.statut = 4 and e.fk_c_type_contact = ".(empty($conf->global->AGENT_CONTACT_TYPE)?-1:$conf->global->AGENT_CONTACT_TYPE);
Expand Down Expand Up @@ -160,11 +160,12 @@
if ($agentid > 0)
$sql.= " GROUP BY s.rowid";
else
$sql.= " GROUP BY u.rowid";
$sql.= " GROUP BY u.rowid, s.nom, s.rowid, s.code_client, s.client, u.login, u.name, u.firstname, f.type ";
$sql.= " ORDER BY $sortfield $sortorder ";
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);

dol_syslog('margin::agentMargins.php sql='.$sql,LOG_DEBUG);
$result = $db->query($sql);
if ($result)
{
Expand Down
5 changes: 3 additions & 2 deletions htdocs/margin/customerMargins.php
Expand Up @@ -157,7 +157,7 @@
$sql.= " f.facnumber, f.total as total_ht,";
$sql.= " sum(d.total_ht) as selling_price,";
$sql.= $db->ifsql('f.type =2','sum(d.buy_price_ht * d.qty *-1)','sum(d.buy_price_ht * d.qty)')." as buying_price, ";
$sql.= $db->ifsql('f.type =2','sum((d.price + d.buy_price_ht) * d.qty)','sum((d.price - d.buy_price_ht) * d.qty)')." as marge," ;
$sql.= $db->ifsql('f.type =2','sum(d.total_ht + (d.buy_price_ht * d.qty))','sum(d.total_ht - (d.buy_price_ht * d.qty))')." as marge," ;
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
Expand All @@ -178,11 +178,12 @@
if ($client)
$sql.= " GROUP BY f.rowid";
else
$sql.= " GROUP BY s.rowid";
$sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.facnumber, f.total, f.datef, f.paye, f.fk_statut, f.rowid ";
$sql.= " ORDER BY $sortfield $sortorder ";
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);

dol_syslog('margin::customerMargins.php sql='.$sql,LOG_DEBUG);
$result = $db->query($sql);
if ($result)
{
Expand Down
6 changes: 3 additions & 3 deletions htdocs/margin/productMargins.php
Expand Up @@ -159,7 +159,7 @@
$sql.= " f.facnumber, f.total as total_ht,";
$sql.= " sum(d.total_ht) as selling_price,";
$sql.= $db->ifsql('f.type =2','sum(d.buy_price_ht * d.qty *-1)','sum(d.buy_price_ht * d.qty)')." as buying_price, ";
$sql.= $db->ifsql('f.type =2','sum((d.price + d.buy_price_ht) * d.qty)','sum((d.price - d.buy_price_ht) * d.qty)')." as marge," ;
$sql.= $db->ifsql('f.type =2','sum(d.total_ht + (d.buy_price_ht * d.qty))','sum(d.total_ht - (d.buy_price_ht * d.qty))')." as marge," ;
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."product as p";
Expand All @@ -182,11 +182,11 @@
if ($id > 0)
$sql.= " GROUP BY f.rowid";
else
$sql.= " GROUP BY d.fk_product";
$sql.= " GROUP BY d.fk_product, p.label, p.rowid, p.fk_product_type, p.ref, f.facnumber, f.total, f.datef, f.paye, f.fk_statut, f.rowid";
$sql.= " ORDER BY $sortfield $sortorder ";
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);

dol_syslog('margin::productMargins.php sql='.$sql,LOG_DEBUG);
$result = $db->query($sql);
if ($result)
{
Expand Down
5 changes: 3 additions & 2 deletions htdocs/margin/tabs/productMargins.php
Expand Up @@ -133,7 +133,7 @@
$sql.= " d.total_ht as selling_price,";
$sql.= $db->ifsql('f.type =2','(d.buy_price_ht * d.qty *-1)','(d.buy_price_ht * d.qty)')." as buying_price, ";
$sql.= $db->ifsql('f.type =2','d.qty *-1','d.qty')." as qty,";
$sql.= $db->ifsql('f.type =2','((d.price + d.buy_price_ht) * d.qty)','((d.price - d.buy_price_ht) * d.qty)')." as marge," ;
$sql.= $db->ifsql('f.type =2','d.total_ht + (d.buy_price_ht * d.qty)','d.total_ht - (d.buy_price_ht * d.qty)')." as marge," ;
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
Expand All @@ -153,7 +153,8 @@
$sql.= " ORDER BY $sortfield $sortorder ";
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);


dol_syslog('margin:tabs:productMargins.php sql='.$sql,LOG_DEBUG);
$result = $db->query($sql);
if ($result)
{
Expand Down
5 changes: 3 additions & 2 deletions htdocs/margin/tabs/thirdpartyMargins.php
Expand Up @@ -131,7 +131,7 @@
$sql.= " sum(d.total_ht) as selling_price,";

$sql.= $db->ifsql('f.type =2','sum(d.buy_price_ht * d.qty *-1)','sum(d.buy_price_ht * d.qty)')." as buying_price, ";
$sql.= $db->ifsql('f.type =2','sum((d.price + d.buy_price_ht) * d.qty)','sum((d.price - d.buy_price_ht) * d.qty)')." as marge," ;
$sql.= $db->ifsql('f.type =2','sum(d.total_ht + (d.buy_price_ht * d.qty))','sum(d.total_ht - (d.buy_price_ht * d.qty))')." as marge," ;
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
Expand All @@ -144,11 +144,12 @@
$sql .= " AND d.buy_price_ht IS NOT NULL";
if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)
$sql .= " AND d.buy_price_ht <> 0";
$sql.= " GROUP BY f.rowid";
$sql.= " GROUP BY f.rowid, s.nom, s.rowid, s.code_client, f.facnumber, f.total, f.datef, f.paye, f.fk_statut";
$sql.= " ORDER BY $sortfield $sortorder ";
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);

dol_syslog('margin:tabs:thirdpartyMargins.php sql='.$sql,LOG_DEBUG);
$result = $db->query($sql);
if ($result)
{
Expand Down

0 comments on commit 934657c

Please sign in to comment.