Fix bug on margin calculation (column price no more use) use subprice
instead.
This commit is contained in:
parent
fc0d5abd14
commit
97192510e2
@ -45,7 +45,7 @@ if (! $sortfield)
|
|||||||
if ($agentid > 0)
|
if ($agentid > 0)
|
||||||
$sortfield="s.nom";
|
$sortfield="s.nom";
|
||||||
else
|
else
|
||||||
$sortfield="u.name";
|
$sortfield="u.lastname";
|
||||||
}
|
}
|
||||||
$page = GETPOST("page",'int');
|
$page = GETPOST("page",'int');
|
||||||
if ($page == -1) { $page = 0; }
|
if ($page == -1) { $page = 0; }
|
||||||
@ -125,10 +125,10 @@ print "</table>";
|
|||||||
print '</form>';
|
print '</form>';
|
||||||
|
|
||||||
$sql = "SELECT s.nom, s.rowid as socid, s.code_client, s.client, u.rowid as agent,";
|
$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.= " 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.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.subprice + d.buy_price_ht) * d.qty)','sum((d.subprice - d.buy_price_ht) * d.qty)')." as marge" ;
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
$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);
|
$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)
|
if ($agentid > 0)
|
||||||
$sql.= " GROUP BY s.rowid";
|
$sql.= " GROUP BY s.rowid";
|
||||||
else
|
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 ";
|
$sql.= " ORDER BY $sortfield $sortorder ";
|
||||||
// TODO: calculate total to display then restore pagination
|
// TODO: calculate total to display then restore pagination
|
||||||
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
||||||
|
|
||||||
|
dol_syslog('margin::agentMargins.php sql='.$sql,LOG_DEBUG);
|
||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
@ -180,7 +181,7 @@ if ($result)
|
|||||||
if ($agentid > 0)
|
if ($agentid > 0)
|
||||||
print_liste_field_titre($langs->trans("Customer"),$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'align="center"',$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("Customer"),$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'align="center"',$sortfield,$sortorder);
|
||||||
else
|
else
|
||||||
print_liste_field_titre($langs->trans("CommercialAgent"),$_SERVER["PHP_SELF"],"u.name","","&agentid=".$agentid,'align="center"',$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("CommercialAgent"),$_SERVER["PHP_SELF"],"u.lastname","","&agentid=".$agentid,'align="center"',$sortfield,$sortorder);
|
||||||
|
|
||||||
print_liste_field_titre($langs->trans("SellingPrice"),$_SERVER["PHP_SELF"],"selling_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("SellingPrice"),$_SERVER["PHP_SELF"],"selling_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder);
|
||||||
print_liste_field_titre($langs->trans("BuyingPrice"),$_SERVER["PHP_SELF"],"buying_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("BuyingPrice"),$_SERVER["PHP_SELF"],"buying_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder);
|
||||||
|
|||||||
@ -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.= " f.facnumber, f.total as total_ht,";
|
||||||
$sql.= " sum(d.total_ht) as selling_price,";
|
$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.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.subprice + d.buy_price_ht) * d.qty)','sum((d.subprice - d.buy_price_ht) * d.qty)')." as marge," ;
|
||||||
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
|
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
||||||
@ -178,7 +178,7 @@ if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPr
|
|||||||
if ($client)
|
if ($client)
|
||||||
$sql.= " GROUP BY f.rowid";
|
$sql.= " GROUP BY f.rowid";
|
||||||
else
|
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 ";
|
$sql.= " ORDER BY $sortfield $sortorder ";
|
||||||
// TODO: calculate total to display then restore pagination
|
// TODO: calculate total to display then restore pagination
|
||||||
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
||||||
|
|||||||
@ -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.= " f.facnumber, f.total as total_ht,";
|
||||||
$sql.= " sum(d.total_ht) as selling_price,";
|
$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.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.subprice + d.buy_price_ht) * d.qty)','sum((d.subprice - d.buy_price_ht) * d.qty)')." as marge," ;
|
||||||
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
|
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."product as p";
|
$sql.= ", ".MAIN_DB_PREFIX."product as p";
|
||||||
@ -186,7 +186,7 @@ else
|
|||||||
$sql.= " ORDER BY $sortfield $sortorder ";
|
$sql.= " ORDER BY $sortfield $sortorder ";
|
||||||
// TODO: calculate total to display then restore pagination
|
// TODO: calculate total to display then restore pagination
|
||||||
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
//$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);
|
$result = $db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -133,7 +133,7 @@ if ($id > 0 || ! empty($ref))
|
|||||||
$sql.= " d.total_ht as selling_price,";
|
$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.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.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.subprice + d.buy_price_ht) * d.qty)','((d.subprice - d.buy_price_ht) * d.qty)')." as marge," ;
|
||||||
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
|
$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 ";
|
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||||
@ -153,7 +153,7 @@ if ($id > 0 || ! empty($ref))
|
|||||||
$sql.= " ORDER BY $sortfield $sortorder ";
|
$sql.= " ORDER BY $sortfield $sortorder ";
|
||||||
// TODO: calculate total to display then restore pagination
|
// TODO: calculate total to display then restore pagination
|
||||||
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
||||||
|
dol_syslog('margin:tabs:productMargins.php sql='.$sql,LOG_DEBUG);
|
||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -131,7 +131,7 @@ if ($socid > 0)
|
|||||||
$sql.= " sum(d.total_ht) as selling_price,";
|
$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.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.subprice + d.buy_price_ht) * d.qty)','sum((d.subprice - d.buy_price_ht) * d.qty)')." as marge," ;
|
||||||
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
|
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
||||||
@ -149,6 +149,7 @@ if ($socid > 0)
|
|||||||
// TODO: calculate total to display then restore pagination
|
// TODO: calculate total to display then restore pagination
|
||||||
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
|
||||||
|
|
||||||
|
dol_syslog('margin:tabs:thirdpartyMargins.php sql='.$sql,LOG_DEBUG);
|
||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user