diff --git a/htdocs/telephonie/stats/graph/gain.class.php b/htdocs/telephonie/stats/graph/gain.class.php index 553a648495f0569f3c7a13a1428e87806560bccb..df4a50462f1523a11894cfb8c677eff504f73fa6 100644 --- a/htdocs/telephonie/stats/graph/gain.class.php +++ b/htdocs/telephonie/stats/graph/gain.class.php @@ -32,6 +32,7 @@ class GraphGain extends GraphBrouzouf{ $this->client = 0; $this->contrat = 0; + $this->ligne = 0; $this->titre = "Gain (euros HT)"; $this->barcolor = "blue"; @@ -41,34 +42,39 @@ class GraphGain extends GraphBrouzouf{ Function GraphDraw() { $num = 0; + + $sql = "SELECT tf.date, sum(tf.gain)"; + $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as tf"; - if ($this->client == 0 && $this->contrat == 0) + if ($this->client == 0 && $this->contrat == 0 && $this->ligne == 0) { - $sql = "SELECT date, sum(gain)"; - $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture"; - $sql .= " WHERE fk_facture is not null"; - $sql .= " GROUP BY date ASC"; + $sql .= " WHERE tf.fk_facture is not null"; + $sql .= " GROUP BY tf.date ASC"; } - elseif ($this->client > 0 && $this->contrat == 0) + elseif ($this->client > 0 && $this->contrat == 0 && $this->ligne == 0) { - $sql = "SELECT date, sum(gain)"; - $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture"; $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as s"; - $sql .= " WHERE fk_facture is not null"; - $sql .= " AND s.rowid = fk_ligne"; + $sql .= " WHERE tf.fk_facture is not null"; + $sql .= " AND s.rowid = tf.fk_ligne"; $sql .= " AND s.fk_client_comm = ".$this->client; - $sql .= " GROUP BY date ASC"; + $sql .= " GROUP BY tf.date ASC"; } - elseif ($this->client == 0 && $this->contrat > 0) + elseif ($this->client == 0 && $this->contrat > 0 && $this->ligne == 0) { - $sql = "SELECT tf.date, sum(tf.gain)"; - $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as tf"; $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as s"; $sql .= " WHERE tf.fk_facture is not null"; $sql .= " AND s.rowid = tf.fk_ligne"; $sql .= " AND s.fk_contrat = ".$this->contrat; $sql .= " GROUP BY tf.date ASC"; } + elseif ($this->client == 0 && $this->contrat == 0 && $this->ligne > 0) + { + $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as s"; + $sql .= " WHERE tf.fk_facture is not null"; + $sql .= " AND s.rowid = tf.fk_ligne"; + $sql .= " AND s.rowid = ".$this->ligne; + $sql .= " GROUP BY tf.date ASC"; + } $result = $this->db->query($sql);