Skip to content
Snippets Groups Projects
Commit 8a6adb8a authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Merge pull request #756 from cbattarel/3.3

various fixes on margin :
parents d2d0f83f f8291a9e
No related branches found
No related tags found
No related merge requests found
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -40,7 +40,13 @@ $mesg = '';
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="s.nom";
if (! $sortfield)
{
if ($agentid > 0)
$sortfield="s.nom";
else
$sortfield="u.name";
}
$page = GETPOST("page",'int');
if ($page == -1) { $page = 0; }
$offset = $conf->liste_limit * $page;
......@@ -75,7 +81,7 @@ $titre=$langs->trans("Margins");
$picto='margin';
dol_fiche_head($head, 'agentMargins', $titre, 0, $picto);
print '<form method="post" name="sel">';
print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">';
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans('CommercialAgent').'</td>';
......@@ -118,10 +124,11 @@ if (! empty($conf->global->DISPLAY_MARK_RATES)) {
print "</table>";
print '</form>';
$sql = "SELECT s.nom, s.rowid as socid, s.code_client, s.client, sc.fk_user as agent,";
$sql.= " u.login,";
$sql.= " sum(d.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price,";
$sql.= " sum(d.buy_price_ht * d.qty) as buying_price, sum(((d.subprice * (1 - d.remise_percent / 100)) - d.buy_price_ht) * d.qty) as marge" ;
$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.= " 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.= " 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);
......@@ -155,7 +162,8 @@ if ($agentid > 0)
else
$sql.= " GROUP BY u.rowid";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
$result = $db->query($sql);
if ($result)
......@@ -163,7 +171,7 @@ if ($result)
$num = $db->num_rows($result);
print '<br>';
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"",$sortfield,$sortorder,'',$num,0,'');
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"",$sortfield,$sortorder,'',0,0,'');
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
......@@ -172,7 +180,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.login","","&amp;agentid=".$agentid,'align="center"',$sortfield,$sortorder);
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("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);
......@@ -191,7 +199,7 @@ if ($result)
if ($num > 0)
{
$var=true;
while ($i < $num && $i < $conf->liste_limit)
while ($i < $num /*&& $i < $conf->liste_limit*/)
{
$objp = $db->fetch_object($result);
......@@ -208,9 +216,8 @@ if ($result)
print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n";
}
else {
$userstatic->id=$objp->agent;
$userstatic->login=$objp->login;
print "<td>".$userstatic->getLoginUrl(1)."</td>\n";
$userstatic->fetch($objp->agent);
print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n";
}
print "<td align=\"right\">".price($objp->selling_price)."</td>\n";
print "<td align=\"right\">".price($objp->buying_price)."</td>\n";
......
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -40,10 +40,6 @@ $result = restrictedArea($user, 'societe','','');
$mesg = '';
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="s.nom";
$page = GETPOST("page",'int');
if ($page == -1) { $page = 0; }
$offset = $conf->liste_limit * $page;
......@@ -77,7 +73,7 @@ $titre=$langs->trans("Margins");
$picto='margin';
dol_fiche_head($head, 'customerMargins', $titre, 0, $picto);
print '<form method="post" name="sel">';
print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">';
print '<table class="border" width="100%">';
$client = false;
......@@ -105,6 +101,23 @@ else {
print '</td></tr>';
}
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
if (! $sortorder) $sortorder="ASC";
if (! $sortfield)
{
if ($client)
{
$sortfield="f.datef";
$sortorder="DESC";
}
else
{
$sortfield="s.nom";
$sortorder="ASC";
}
}
// Start date
print '<td>'.$langs->trans('StartDate').'</td>';
print '<td width="20%">';
......@@ -142,8 +155,9 @@ print '</form>';
$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.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price,";
$sql.= " sum(d.buy_price_ht * d.qty) as buying_price, sum(((d.subprice * (1 - d.remise_percent / 100)) - d.buy_price_ht) * d.qty) as marge," ;
$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.= " 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";
......@@ -166,7 +180,8 @@ if ($client)
else
$sql.= " GROUP BY s.rowid";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
$result = $db->query($sql);
if ($result)
......@@ -174,7 +189,7 @@ if ($result)
$num = $db->num_rows($result);
print '<br>';
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"",$sortfield,$sortorder,'',$num,0,'');
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"",$sortfield,$sortorder,'',0,0,'');
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
......@@ -203,7 +218,7 @@ if ($result)
if ($num > 0)
{
$var=True;
while ($i < $num && $i < $conf->liste_limit)
while ($i < $num /*&& $i < $conf->liste_limit*/)
{
$objp = $db->fetch_object($result);
......
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -48,7 +48,20 @@ $mesg = '';
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="p.ref";
if (! $sortfield)
{
if ($id > 0)
{
$sortfield="f.datef";
$sortorder="DESC";
}
else
{
$sortfield="p.ref";
$sortorder="ASC";
}
}
$page = GETPOST("page",'int');
if ($page == -1) { $page = 0; }
$offset = $conf->liste_limit * $page;
......@@ -83,7 +96,7 @@ $titre=$langs->trans("Margins");
$picto='margin';
dol_fiche_head($head, 'productMargins', $titre, 0, $picto);
print '<form method="post" name="sel">';
print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">';
print '<table class="border" width="100%">';
if ($id > 0) {
......@@ -144,8 +157,9 @@ print '</form>';
$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.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price,";
$sql.= " sum(d.buy_price_ht * d.qty) as buying_price, sum(((d.subprice * (1 - d.remise_percent / 100)) - d.buy_price_ht) * d.qty) as marge," ;
$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.= " 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";
......@@ -170,7 +184,8 @@ if ($id > 0)
else
$sql.= " GROUP BY d.fk_product";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
$result = $db->query($sql);
if ($result)
......@@ -178,7 +193,7 @@ if ($result)
$num = $db->num_rows($result);
print '<br>';
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;id=".$id,$sortfield,$sortorder,'',$num,0,'');
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;id=".$id,$sortfield,$sortorder,'',0,0,'');
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
......@@ -207,7 +222,7 @@ if ($result)
if ($num > 0)
{
$var=True;
while ($i < $num && $i < $conf->liste_limit)
while ($i < $num /*&& $i < $conf->liste_limit*/)
{
$objp = $db->fetch_object($result);
......
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -130,7 +130,10 @@ if ($id > 0 || ! empty($ref))
$sql = "SELECT DISTINCT s.nom, s.rowid as socid, s.code_client,";
$sql.= " f.facnumber, f.total as total_ht,";
$sql.= " (d.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price, (d.buy_price_ht * d.qty) as buying_price, d.qty, ((d.subprice - d.buy_price_ht) * d.qty) as marge," ;
$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.= " 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";
......@@ -148,14 +151,15 @@ if ($id > 0 || ! empty($ref))
if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)
$sql .= " AND d.buy_price_ht <> 0";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;id=$object->id",$sortfield,$sortorder,'',$num,0,'');
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;id=$object->id",$sortfield,$sortorder,'',0,0,'');
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
......@@ -184,7 +188,7 @@ if ($id > 0 || ! empty($ref))
if ($num > 0)
{
$var=True;
while ($i < $num && $i < $conf->liste_limit)
while ($i < $num /*&& $i < $conf->liste_limit*/)
{
$objp = $db->fetch_object($result);
$var=!$var;
......
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -128,7 +128,10 @@ if ($socid > 0)
$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,";
$sql.= " f.facnumber, f.total as total_ht,";
$sql.= " sum(d.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price, sum(d.buy_price_ht * d.qty) as buying_price, sum(((d.subprice * (1 - d.remise_percent / 100)) - d.buy_price_ht) * d.qty) as marge," ;
$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.= " 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";
......@@ -143,14 +146,15 @@ if ($socid > 0)
$sql .= " AND d.buy_price_ht <> 0";
$sql.= " GROUP BY f.rowid";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;socid=$societe->id",$sortfield,$sortorder,'',$num,0,'');
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;socid=$societe->id",$sortfield,$sortorder,'',0,0,'');
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
......@@ -176,7 +180,7 @@ if ($socid > 0)
if ($num > 0)
{
$var=True;
while ($i < $num && $i < $conf->liste_limit)
while ($i < $num /*&& $i < $conf->liste_limit*/)
{
$objp = $db->fetch_object($result);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment