diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index a7e92bc463c..70239a1257c 100755 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -49,6 +49,7 @@ abstract class CommonDocGenerator return array( 'myuser_lastname'=>$user->lastname, 'myuser_firstname'=>$user->firstname, + 'myuser_fullname'=>$user->getFullName($outputlangs,1), 'myuser_login'=>$user->login, 'myuser_phone'=>$user->office_phone, 'myuser_address'=>$user->address, @@ -61,6 +62,7 @@ abstract class CommonDocGenerator 'myuser_fax'=>$user->office_fax, 'myuser_mobile'=>$user->user_mobile, 'myuser_email'=>$user->email, + 'myuser_logo'=>$logotouse, 'myuser_web'=>'' // url not exist in $user object ); } diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index 0e953422ef2..3b5b2d46ec5 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -128,7 +128,7 @@ $sql = "SELECT s.nom, s.rowid as socid, s.code_client, s.client, u.rowid as agen $sql.= " u.login, u.lastname, 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.total_ht/d.qty) + d.buy_price_ht) * d.qty)','sum(((d.total_ht/d.qty) - 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); diff --git a/htdocs/margin/customerMargins.php b/htdocs/margin/customerMargins.php index 5fb491ea5c3..6af526492fe 100644 --- a/htdocs/margin/customerMargins.php +++ b/htdocs/margin/customerMargins.php @@ -157,7 +157,7 @@ $sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client, s.client,"; $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.total_ht/d.qty) + d.buy_price_ht) * d.qty)','sum(((d.total_ht/d.qty) - 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"; diff --git a/htdocs/margin/productMargins.php b/htdocs/margin/productMargins.php index d2e3198b5ee..26aaa953d78 100644 --- a/htdocs/margin/productMargins.php +++ b/htdocs/margin/productMargins.php @@ -159,7 +159,7 @@ $sql = "SELECT DISTINCT d.fk_product, p.label, p.rowid, p.fk_product_type, p.ref $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.total_ht/d.qty) + d.buy_price_ht) * d.qty)','sum(((d.total_ht/d.qty) - 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"; diff --git a/htdocs/margin/tabs/productMargins.php b/htdocs/margin/tabs/productMargins.php index 8eee225b42d..6fc92f94860 100644 --- a/htdocs/margin/tabs/productMargins.php +++ b/htdocs/margin/tabs/productMargins.php @@ -133,7 +133,7 @@ if ($id > 0 || ! empty($ref)) $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.total_ht/d.qty) + d.buy_price_ht) * d.qty)','(((d.total_ht/d.qty) - 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"; diff --git a/htdocs/margin/tabs/thirdpartyMargins.php b/htdocs/margin/tabs/thirdpartyMargins.php index fc319b17054..04ac4d65d64 100644 --- a/htdocs/margin/tabs/thirdpartyMargins.php +++ b/htdocs/margin/tabs/thirdpartyMargins.php @@ -131,7 +131,7 @@ if ($socid > 0) $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.total_ht/d.qty) + d.buy_price_ht) * d.qty)','sum(((d.total_ht/d.qty) - 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";