Fix: Several bugs into filter on statistics pages.
This commit is contained in:
parent
71e14df62f
commit
6db07ac2d8
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php';
|
include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php';
|
||||||
include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
|
include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
|
||||||
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,14 +50,14 @@ class PropaleStats extends Stats
|
|||||||
*
|
*
|
||||||
* @param DoliDB $db Database handler
|
* @param DoliDB $db Database handler
|
||||||
* @param int $socid Id third party
|
* @param int $socid Id third party
|
||||||
* @param int $userid Id user for filter
|
* @param int $userid Id user for filter (creation user)
|
||||||
*/
|
*/
|
||||||
function __construct($db, $socid=0, $userid=0)
|
function __construct($db, $socid=0, $userid=0)
|
||||||
{
|
{
|
||||||
global $user, $conf;
|
global $user, $conf;
|
||||||
|
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->socid = $socid;
|
$this->socid = ($socid > 0 ? $socid : 0);
|
||||||
$this->userid = $userid;
|
$this->userid = $userid;
|
||||||
|
|
||||||
$object=new Propal($this->db);
|
$object=new Propal($this->db);
|
||||||
@ -66,7 +67,7 @@ class PropaleStats extends Stats
|
|||||||
|
|
||||||
$this->field='total_ht';
|
$this->field='total_ht';
|
||||||
|
|
||||||
$this->where.= " fk_statut > 0";
|
$this->where.= " p.fk_statut > 0";
|
||||||
$this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity;
|
$this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity;
|
||||||
if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||||
if($this->socid)
|
if($this->socid)
|
||||||
@ -90,7 +91,7 @@ class PropaleStats extends Stats
|
|||||||
$sql = "SELECT date_format(p.datep,'%m') as dm, count(*)";
|
$sql = "SELECT date_format(p.datep,'%m') as dm, count(*)";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
$sql.= " WHERE date_format(p.datep,'%Y') = '".$year."'";
|
$sql.= " WHERE p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||||
$sql.= " AND ".$this->where;
|
$sql.= " AND ".$this->where;
|
||||||
$sql.= " GROUP BY dm";
|
$sql.= " GROUP BY dm";
|
||||||
$sql.= $this->db->order('dm','DESC');
|
$sql.= $this->db->order('dm','DESC');
|
||||||
@ -131,7 +132,7 @@ class PropaleStats extends Stats
|
|||||||
$sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.".$this->field.")";
|
$sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.".$this->field.")";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
$sql.= " WHERE date_format(p.datep,'%Y') = '".$year."'";
|
$sql.= " WHERE p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||||
$sql.= " AND ".$this->where;
|
$sql.= " AND ".$this->where;
|
||||||
$sql.= " GROUP BY dm";
|
$sql.= " GROUP BY dm";
|
||||||
$sql.= $this->db->order('dm','DESC');
|
$sql.= $this->db->order('dm','DESC');
|
||||||
@ -152,7 +153,7 @@ class PropaleStats extends Stats
|
|||||||
$sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.".$this->field.")";
|
$sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.".$this->field.")";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
$sql.= " WHERE date_format(p.datep,'%Y') = '".$year."'";
|
$sql.= " WHERE p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||||
$sql.= " AND ".$this->where;
|
$sql.= " AND ".$this->where;
|
||||||
$sql.= " GROUP BY dm";
|
$sql.= " GROUP BY dm";
|
||||||
$sql.= $this->db->order('dm','DESC');
|
$sql.= $this->db->order('dm','DESC');
|
||||||
|
|||||||
@ -31,8 +31,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
|
|||||||
$WIDTH=DolGraph::getDefaultGraphSizeForStats('width');
|
$WIDTH=DolGraph::getDefaultGraphSizeForStats('width');
|
||||||
$HEIGHT=DolGraph::getDefaultGraphSizeForStats('height');
|
$HEIGHT=DolGraph::getDefaultGraphSizeForStats('height');
|
||||||
|
|
||||||
$userid=GETPOST('userid','int'); if ($userid < 0) $userid=0;
|
$userid=GETPOST('userid','int');
|
||||||
$socid=GETPOST('socid','int'); if ($socid < 0) $socid=0;
|
$socid=GETPOST('socid','int');
|
||||||
// Security check
|
// Security check
|
||||||
if ($user->societe_id > 0)
|
if ($user->societe_id > 0)
|
||||||
{
|
{
|
||||||
@ -63,7 +63,7 @@ $dir=$conf->propal->dir_temp;
|
|||||||
|
|
||||||
dol_mkdir($dir);
|
dol_mkdir($dir);
|
||||||
|
|
||||||
$stats = new PropaleStats($db, $socid, $userid);
|
$stats = new PropaleStats($db, $socid, ($userid>0?$userid:0));
|
||||||
|
|
||||||
// Build graphic number of object
|
// Build graphic number of object
|
||||||
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
|
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
|
||||||
@ -233,12 +233,13 @@ print '<div class="fichecenter"><div class="fichethirdleft">';
|
|||||||
print $form->select_company($socid,'socid',$filter,1);
|
print $form->select_company($socid,'socid',$filter,1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
// User
|
// User
|
||||||
print '<tr><td align="left">'.$langs->trans("User").'/'.$langs->trans("SalesRepresentative").'</td><td align="left">';
|
print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
|
||||||
print $form->select_users($userid,'userid',1);
|
print $form->select_users($userid,'userid',1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
// Year
|
// Year
|
||||||
print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
|
print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
|
||||||
if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
|
if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
|
||||||
|
if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
|
||||||
arsort($arrayyears);
|
arsort($arrayyears);
|
||||||
print $form->selectarray('year',$arrayyears,$year,0);
|
print $form->selectarray('year',$arrayyears,$year,0);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php';
|
include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php';
|
||||||
include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
|
include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
|
||||||
include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
|
include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
|
||||||
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +50,7 @@ class CommandeStats extends Stats
|
|||||||
* @param DoliDB $db Database handler
|
* @param DoliDB $db Database handler
|
||||||
* @param int $socid Id third party for filter
|
* @param int $socid Id third party for filter
|
||||||
* @param string $mode Option
|
* @param string $mode Option
|
||||||
* @param int $userid Id user for filter
|
* @param int $userid Id user for filter (creation user)
|
||||||
*/
|
*/
|
||||||
function __construct($db, $socid, $mode, $userid=0)
|
function __construct($db, $socid, $mode, $userid=0)
|
||||||
{
|
{
|
||||||
@ -57,7 +58,7 @@ class CommandeStats extends Stats
|
|||||||
|
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
|
|
||||||
$this->socid = $socid;
|
$this->socid = ($socid > 0 ? $socid : 0);
|
||||||
$this->userid = $userid;
|
$this->userid = $userid;
|
||||||
|
|
||||||
if ($mode == 'customer')
|
if ($mode == 'customer')
|
||||||
@ -100,7 +101,7 @@ class CommandeStats extends Stats
|
|||||||
$sql = "SELECT date_format(c.date_commande,'%m') as dm, count(*) nb";
|
$sql = "SELECT date_format(c.date_commande,'%m') as dm, count(*) nb";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
$sql.= " WHERE date_format(c.date_commande,'%Y') = '".$year."'";
|
$sql.= " WHERE c.date_commande BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||||
$sql.= " AND ".$this->where;
|
$sql.= " AND ".$this->where;
|
||||||
$sql.= " GROUP BY dm";
|
$sql.= " GROUP BY dm";
|
||||||
$sql.= $this->db->order('dm','DESC');
|
$sql.= $this->db->order('dm','DESC');
|
||||||
@ -143,7 +144,7 @@ class CommandeStats extends Stats
|
|||||||
$sql = "SELECT date_format(c.date_commande,'%m') as dm, sum(c.".$this->field.")";
|
$sql = "SELECT date_format(c.date_commande,'%m') as dm, sum(c.".$this->field.")";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
$sql.= " WHERE date_format(c.date_commande,'%Y') = '".$year."'";
|
$sql.= " WHERE c.date_commande BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||||
$sql.= " AND ".$this->where;
|
$sql.= " AND ".$this->where;
|
||||||
$sql.= " GROUP BY dm";
|
$sql.= " GROUP BY dm";
|
||||||
$sql.= $this->db->order('dm','DESC');
|
$sql.= $this->db->order('dm','DESC');
|
||||||
@ -165,7 +166,7 @@ class CommandeStats extends Stats
|
|||||||
$sql = "SELECT date_format(c.date_commande,'%m') as dm, avg(c.".$this->field.")";
|
$sql = "SELECT date_format(c.date_commande,'%m') as dm, avg(c.".$this->field.")";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
$sql.= " WHERE date_format(c.date_commande,'%Y') = '".$year."'";
|
$sql.= " WHERE c.date_commande BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||||
$sql.= " AND ".$this->where;
|
$sql.= " AND ".$this->where;
|
||||||
$sql.= " GROUP BY dm";
|
$sql.= " GROUP BY dm";
|
||||||
$sql.= $this->db->order('dm','DESC');
|
$sql.= $this->db->order('dm','DESC');
|
||||||
|
|||||||
@ -36,8 +36,8 @@ $mode=GETPOST("mode")?GETPOST("mode"):'customer';
|
|||||||
if ($mode == 'customer' && ! $user->rights->commande->lire) accessforbidden();
|
if ($mode == 'customer' && ! $user->rights->commande->lire) accessforbidden();
|
||||||
if ($mode == 'supplier' && ! $user->rights->fournisseur->commande->lire) accessforbidden();
|
if ($mode == 'supplier' && ! $user->rights->fournisseur->commande->lire) accessforbidden();
|
||||||
|
|
||||||
$userid=GETPOST('userid','int'); if ($userid < 0) $userid=0;
|
$userid=GETPOST('userid','int');
|
||||||
$socid=GETPOST('socid','int'); if ($socid < 0) $socid=0;
|
$socid=GETPOST('socid','int');
|
||||||
// Security check
|
// Security check
|
||||||
if ($user->societe_id > 0)
|
if ($user->societe_id > 0)
|
||||||
{
|
{
|
||||||
@ -77,7 +77,7 @@ print_fiche_titre($title);
|
|||||||
|
|
||||||
dol_mkdir($dir);
|
dol_mkdir($dir);
|
||||||
|
|
||||||
$stats = new CommandeStats($db, $socid, $mode, $userid);
|
$stats = new CommandeStats($db, $socid, $mode, ($userid>0?$userid:0));
|
||||||
|
|
||||||
// Build graphic number of object
|
// Build graphic number of object
|
||||||
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
|
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
|
||||||
@ -255,12 +255,13 @@ print '<div class="fichecenter"><div class="fichethirdleft">';
|
|||||||
print $form->select_company($socid,'socid',$filter,1);
|
print $form->select_company($socid,'socid',$filter,1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
// User
|
// User
|
||||||
print '<tr><td align="left">'.$langs->trans("User").'/'.$langs->trans("SalesRepresentative").'</td><td align="left">';
|
print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
|
||||||
print $form->select_users($userid,'userid',1);
|
print $form->select_users($userid,'userid',1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
// Year
|
// Year
|
||||||
print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
|
print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
|
||||||
if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
|
if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
|
||||||
|
if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
|
||||||
arsort($arrayyears);
|
arsort($arrayyears);
|
||||||
print $form->selectarray('year',$arrayyears,$year,0);
|
print $form->selectarray('year',$arrayyears,$year,0);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|||||||
@ -48,12 +48,12 @@ class FactureStats extends Stats
|
|||||||
* @param DoliDB $db Database handler
|
* @param DoliDB $db Database handler
|
||||||
* @param int $socid Id third party
|
* @param int $socid Id third party
|
||||||
* @param string $mode Option
|
* @param string $mode Option
|
||||||
* @param int $userid Id user for filter
|
* @param int $userid Id user for filter (creation user)
|
||||||
* @return FactureStats
|
* @return FactureStats
|
||||||
*/
|
*/
|
||||||
function __construct($db, $socid, $mode, $userid=0)
|
function __construct($db, $socid, $mode, $userid=0)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $user, $conf;
|
||||||
|
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->socid = ($socid > 0 ? $socid : 0);
|
$this->socid = ($socid > 0 ? $socid : 0);
|
||||||
@ -62,41 +62,25 @@ class FactureStats extends Stats
|
|||||||
if ($mode == 'customer')
|
if ($mode == 'customer')
|
||||||
{
|
{
|
||||||
$object=new Facture($this->db);
|
$object=new Facture($this->db);
|
||||||
$this->from = MAIN_DB_PREFIX.$object->table_element;
|
$this->from = MAIN_DB_PREFIX.$object->table_element." as f";
|
||||||
$this->field='total';
|
$this->field='total';
|
||||||
}
|
}
|
||||||
if ($mode == 'supplier')
|
if ($mode == 'supplier')
|
||||||
{
|
{
|
||||||
$object=new FactureFournisseur($this->db);
|
$object=new FactureFournisseur($this->db);
|
||||||
$this->from = MAIN_DB_PREFIX.$object->table_element;
|
$this->from = MAIN_DB_PREFIX.$object->table_element." as f";
|
||||||
$this->field='total_ht';
|
$this->field='total_ht';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->where = " fk_statut > 0";
|
$this->where = " f.fk_statut > 0";
|
||||||
$this->where.= " AND entity = ".$conf->entity;
|
$this->where.= " AND f.entity = ".$conf->entity;
|
||||||
if ($mode == 'customer') $this->where.=" AND (fk_statut <> 3 OR close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons)
|
if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||||
|
if ($mode == 'customer') $this->where.=" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons)
|
||||||
if ($this->socid)
|
if ($this->socid)
|
||||||
{
|
{
|
||||||
$this->where.=" AND fk_soc = ".$this->socid;
|
$this->where.=" AND f.fk_soc = ".$this->socid;
|
||||||
}
|
}
|
||||||
if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid;
|
if ($this->userid > 0) $this->where.=' AND f.fk_user_author = '.$this->userid;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renvoie le nombre de facture par annee
|
|
||||||
*
|
|
||||||
* @return array Array of values
|
|
||||||
*/
|
|
||||||
function getNbByYear()
|
|
||||||
{
|
|
||||||
$sql = "SELECT YEAR(datef) as dm, COUNT(*)";
|
|
||||||
$sql.= " FROM ".$this->from;
|
|
||||||
$sql.= " WHERE ".$this->where;
|
|
||||||
$sql.= " GROUP BY dm";
|
|
||||||
$sql.= $this->db->order('dm','DESC');
|
|
||||||
|
|
||||||
return $this->_getNbByYear($sql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -108,9 +92,10 @@ class FactureStats extends Stats
|
|||||||
*/
|
*/
|
||||||
function getNbByMonth($year)
|
function getNbByMonth($year)
|
||||||
{
|
{
|
||||||
$sql = "SELECT MONTH(datef) as dm, COUNT(*)";
|
$sql = "SELECT MONTH(f.datef) as dm, COUNT(*)";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
$sql.= " WHERE datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
|
$sql.= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||||
$sql.= " AND ".$this->where;
|
$sql.= " AND ".$this->where;
|
||||||
$sql.= " GROUP BY dm";
|
$sql.= " GROUP BY dm";
|
||||||
$sql.= $this->db->order('dm','DESC');
|
$sql.= $this->db->order('dm','DESC');
|
||||||
@ -121,6 +106,24 @@ class FactureStats extends Stats
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renvoie le nombre de facture par annee
|
||||||
|
*
|
||||||
|
* @return array Array of values
|
||||||
|
*/
|
||||||
|
function getNbByYear()
|
||||||
|
{
|
||||||
|
$sql = "SELECT YEAR(f.datef) as dm, COUNT(*)";
|
||||||
|
$sql.= " FROM ".$this->from;
|
||||||
|
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
|
$sql.= " WHERE ".$this->where;
|
||||||
|
$sql.= " GROUP BY dm";
|
||||||
|
$sql.= $this->db->order('dm','DESC');
|
||||||
|
|
||||||
|
return $this->_getNbByYear($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renvoie le montant de facture par mois pour une annee donnee
|
* Renvoie le montant de facture par mois pour une annee donnee
|
||||||
*
|
*
|
||||||
@ -129,9 +132,10 @@ class FactureStats extends Stats
|
|||||||
*/
|
*/
|
||||||
function getAmountByMonth($year)
|
function getAmountByMonth($year)
|
||||||
{
|
{
|
||||||
$sql = "SELECT date_format(datef,'%m') as dm, SUM(".$this->field.")";
|
$sql = "SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.")";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
$sql.= " WHERE date_format(datef,'%Y') = '".$year."'";
|
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
|
$sql.= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||||
$sql.= " AND ".$this->where;
|
$sql.= " AND ".$this->where;
|
||||||
$sql.= " GROUP BY dm";
|
$sql.= " GROUP BY dm";
|
||||||
$sql.= $this->db->order('dm','DESC');
|
$sql.= $this->db->order('dm','DESC');
|
||||||
@ -149,9 +153,10 @@ class FactureStats extends Stats
|
|||||||
*/
|
*/
|
||||||
function getAverageByMonth($year)
|
function getAverageByMonth($year)
|
||||||
{
|
{
|
||||||
$sql = "SELECT date_format(datef,'%m') as dm, AVG(".$this->field.")";
|
$sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
$sql.= " WHERE datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
|
$sql.= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||||
$sql.= " AND ".$this->where;
|
$sql.= " AND ".$this->where;
|
||||||
$sql.= " GROUP BY dm";
|
$sql.= " GROUP BY dm";
|
||||||
$sql.= $this->db->order('dm','DESC');
|
$sql.= $this->db->order('dm','DESC');
|
||||||
@ -166,8 +171,9 @@ class FactureStats extends Stats
|
|||||||
*/
|
*/
|
||||||
function getAllByYear()
|
function getAllByYear()
|
||||||
{
|
{
|
||||||
$sql = "SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(".$this->field.") as total, AVG(".$this->field.") as avg";
|
$sql = "SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->field.") as total, AVG(f.".$this->field.") as avg";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
|
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
$sql.= " WHERE ".$this->where;
|
$sql.= " WHERE ".$this->where;
|
||||||
$sql.= " GROUP BY year";
|
$sql.= " GROUP BY year";
|
||||||
$sql.= $this->db->order('year','DESC');
|
$sql.= $this->db->order('year','DESC');
|
||||||
|
|||||||
@ -233,12 +233,13 @@ print '<div class="fichecenter"><div class="fichethirdleft">';
|
|||||||
print $form->select_company($socid,'socid',$filter,1);
|
print $form->select_company($socid,'socid',$filter,1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
// User
|
// User
|
||||||
print '<tr><td>'.$langs->trans("User").'/'.$langs->trans("SalesRepresentative").'</td><td>';
|
print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
|
||||||
print $form->select_users($userid,'userid',1);
|
print $form->select_users($userid,'userid',1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
// Year
|
// Year
|
||||||
print '<tr><td>'.$langs->trans("Year").'</td><td>';
|
print '<tr><td>'.$langs->trans("Year").'</td><td>';
|
||||||
if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
|
if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
|
||||||
|
if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
|
||||||
arsort($arrayyears);
|
arsort($arrayyears);
|
||||||
print $form->selectarray('year',$arrayyears,$year,0);
|
print $form->selectarray('year',$arrayyears,$year,0);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user