2
0
forked from Wavyzz/dolibarr

Merge pull request #914 from FHenry/3.4

fix margin calculation problem
This commit is contained in:
Laurent Destailleur
2013-05-03 04:18:15 -07:00
6 changed files with 15 additions and 13 deletions

View File

@@ -38,7 +38,7 @@ create table llx_facturedet
remise real DEFAULT 0, -- Montant calcule de la remise % sur PU HT (exemple 20)
fk_remise_except integer NULL, -- Lien vers table des remises fixes
subprice double(24,8), -- P.U. HT (exemple 100)
price double(24,8), -- P.U. HT apres remise % de ligne
price double(24,8), -- Deprecated (Do not use)
total_ht double(24,8), -- Total HT de la ligne toute quantite et incluant remise ligne et globale
total_tva double(24,8), -- Total TVA de la ligne toute quantite et incluant remise ligne et globale
total_localtax1 double(24,8) DEFAULT 0, -- Total LocalTax1 for total quantity of line

View File

@@ -45,7 +45,7 @@ if (! $sortfield)
if ($agentid > 0)
$sortfield="s.nom";
else
$sortfield="u.name";
$sortfield="u.lastname";
}
$page = GETPOST("page",'int');
if ($page == -1) { $page = 0; }
@@ -125,10 +125,10 @@ print "</table>";
print '</form>';
$sql = "SELECT s.nom, s.rowid as socid, s.code_client, s.client, u.rowid as agent,";
$sql.= " u.login, u.name, u.firstname,";
$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.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.qty) + d.buy_price_ht) * d.qty)','sum(((d.total_ht/d.qty) - 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);
@@ -160,11 +160,12 @@ if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPr
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.lastname, 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)
{
@@ -180,7 +181,7 @@ if ($result)
if ($agentid > 0)
print_liste_field_titre($langs->trans("Customer"),$_SERVER["PHP_SELF"],"s.nom","","&amp;agentid=".$agentid,'align="center"',$sortfield,$sortorder);
else
print_liste_field_titre($langs->trans("CommercialAgent"),$_SERVER["PHP_SELF"],"u.name","","&amp;agentid=".$agentid,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CommercialAgent"),$_SERVER["PHP_SELF"],"u.lastname","","&amp;agentid=".$agentid,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("SellingPrice"),$_SERVER["PHP_SELF"],"selling_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("BuyingPrice"),$_SERVER["PHP_SELF"],"buying_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);

View File

@@ -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.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.qty) + d.buy_price_ht) * d.qty)','sum(((d.total_ht/d.qty) - 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";
@@ -178,7 +178,7 @@ if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPr
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);

View File

@@ -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.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.qty) + d.buy_price_ht) * d.qty)','sum(((d.total_ht/d.qty) - 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";
@@ -186,7 +186,7 @@ else
$sql.= " ORDER BY $sortfield $sortorder ";
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
dol_syslog('margin::productMargin.php sql='.$sql,LOG_DEBUG);
dol_syslog('margin::productMargins.php sql='.$sql,LOG_DEBUG);
$result = $db->query($sql);
if ($result)
{

View File

@@ -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.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.qty) + d.buy_price_ht) * d.qty)','(((d.total_ht/d.qty) - 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";
@@ -153,7 +153,7 @@ if ($id > 0 || ! empty($ref))
$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)
{

View File

@@ -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.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.qty) + d.buy_price_ht) * d.qty)','sum(((d.total_ht/d.qty) - 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";
@@ -149,6 +149,7 @@ if ($socid > 0)
// 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)
{