Clean code
This commit is contained in:
parent
cc6b9269f9
commit
be70232bfe
@ -42,6 +42,9 @@ class ExpenseReportStats extends Stats
|
|||||||
public $field;
|
public $field;
|
||||||
public $where;
|
public $where;
|
||||||
|
|
||||||
|
private $datetouse = 'date_valid';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -91,7 +94,7 @@ class ExpenseReportStats extends Stats
|
|||||||
*/
|
*/
|
||||||
public function getNbByYear()
|
public function getNbByYear()
|
||||||
{
|
{
|
||||||
$sql = "SELECT YEAR(".$this->db->ifsql('e.date_valid IS NULL', 'e.date_create', 'e.date_valid').") as dm, count(*)";
|
$sql = "SELECT YEAR(".$this->db->ifsql('e.'.$this->datetouse.' IS NULL', 'e.date_create', 'e.'.$this->datetouse).") as dm, count(*)";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
$sql.= " GROUP BY dm DESC";
|
$sql.= " GROUP BY dm DESC";
|
||||||
$sql.= " WHERE ".$this->where;
|
$sql.= " WHERE ".$this->where;
|
||||||
@ -109,9 +112,9 @@ class ExpenseReportStats extends Stats
|
|||||||
*/
|
*/
|
||||||
public function getNbByMonth($year, $format = 0)
|
public function getNbByMonth($year, $format = 0)
|
||||||
{
|
{
|
||||||
$sql = "SELECT MONTH(".$this->db->ifsql('e.date_valid IS NULL', 'e.date_create', 'e.date_valid').") as dm, count(*)";
|
$sql = "SELECT MONTH(".$this->db->ifsql('e.'.$this->datetouse.' IS NULL', 'e.date_create', 'e.'.$this->datetouse).") as dm, count(*)";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
$sql.= " WHERE YEAR(e.date_valid) = ".$year;
|
$sql.= " WHERE YEAR(e.".$this->datetouse.") = ".$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,9 +134,9 @@ class ExpenseReportStats extends Stats
|
|||||||
*/
|
*/
|
||||||
public function getAmountByMonth($year, $format = 0)
|
public function getAmountByMonth($year, $format = 0)
|
||||||
{
|
{
|
||||||
$sql = "SELECT date_format(".$this->db->ifsql('e.date_valid IS NULL', 'e.date_create', 'e.date_valid').",'%m') as dm, sum(".$this->field.")";
|
$sql = "SELECT date_format(".$this->db->ifsql('e.'.$this->datetouse.' IS NULL', 'e.date_create', 'e.'.$this->datetouse).",'%m') as dm, sum(".$this->field.")";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
$sql.= " WHERE date_format(".$this->db->ifsql('e.date_valid IS NULL', 'e.date_create', 'e.date_valid').",'%Y') = '".$year."'";
|
$sql.= " WHERE date_format(".$this->db->ifsql('e.'.$this->datetouse.' IS NULL', 'e.date_create', 'e.'.$this->datetouse).",'%Y') = '".$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');
|
||||||
@ -151,9 +154,9 @@ class ExpenseReportStats extends Stats
|
|||||||
*/
|
*/
|
||||||
public function getAverageByMonth($year)
|
public function getAverageByMonth($year)
|
||||||
{
|
{
|
||||||
$sql = "SELECT date_format(".$this->db->ifsql('e.date_valid IS NULL', 'e.date_create', 'e.date_valid').",'%m') as dm, avg(".$this->field.")";
|
$sql = "SELECT date_format(".$this->db->ifsql('e.'.$this->datetouse.' IS NULL', 'e.date_create', 'e.'.$this->datetouse).",'%m') as dm, avg(".$this->field.")";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
$sql.= " WHERE date_format(".$this->db->ifsql('e.date_valid IS NULL', 'e.date_create', 'e.date_valid').",'%Y') = '".$year."'";
|
$sql.= " WHERE date_format(".$this->db->ifsql('e.'.$this->datetouse.' IS NULL', 'e.date_create', 'e.'.$this->datetouse).",'%Y') = '".$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');
|
||||||
@ -168,7 +171,7 @@ class ExpenseReportStats extends Stats
|
|||||||
*/
|
*/
|
||||||
public function getAllByYear()
|
public function getAllByYear()
|
||||||
{
|
{
|
||||||
$sql = "SELECT date_format(".$this->db->ifsql('e.date_valid IS NULL', 'e.date_create', 'e.date_valid').",'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
|
$sql = "SELECT date_format(".$this->db->ifsql('e.'.$this->datetouse.' IS NULL', 'e.date_create', 'e.'.$this->datetouse).",'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
|
||||||
$sql.= " FROM ".$this->from;
|
$sql.= " FROM ".$this->from;
|
||||||
$sql.= " WHERE ".$this->where;
|
$sql.= " WHERE ".$this->where;
|
||||||
$sql.= " GROUP BY year";
|
$sql.= " GROUP BY year";
|
||||||
|
|||||||
@ -232,7 +232,9 @@ $liststatus = $tmpexpensereport->statuts;
|
|||||||
print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'int'), -4, 0, 0, '', 1);
|
print $form->selectarray('object_status', $liststatus, GETPOST('object_status', 'int'), -4, 0, 0, '', 1);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
// Year
|
// Year
|
||||||
print '<tr><td>'.$langs->trans("Year").'</td><td>';
|
print '<tr><td>';
|
||||||
|
print $form->textwithpicto($langs->trans("Year"), $langs->trans("DateValidation"));
|
||||||
|
print '</td><td>';
|
||||||
if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
|
if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
|
||||||
arsort($arrayyears);
|
arsort($arrayyears);
|
||||||
print $form->selectarray('year', $arrayyears, $year, 0);
|
print $form->selectarray('year', $arrayyears, $year, 0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user