Hi Engene,
Our developer has done a test and I can assure that our Group is working very well. Here is the test to compare CSV and DB. Your data is like above.
Report.php
<?php
class Report extends \koolreport\KoolReport
{
use \koolreport\clients\Bootstrap;
protected function settings()
{
return array(
"dataSources"=>array(
"db"=>array(
"connectionString"=>"mysql:host=localhost;dbname=eugene",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
),
"csv"=>array(
"class"=>'\koolreport\datasources\CSVDataSource',
"filePath"=>dirname(__FILE__)."/data.csv"
)
)
);
}
}
Report.view.php
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\processes\CalculatedColumn;
use \koolreport\processes\Group;
use \koolreport\processes\Filter;
use \koolreport\processes\CopyColumn;
use \koolreport\processes\DateTimeFormat;
?>
<html>
<head>
<title>Test Grouping</title>
</head>
<body>
<div class="container">
<h1 class="text-center">CSV Group By Date</h1>
<?php
Table::create(array(
"dataSource"=>(
$this->src("csv")
->pipe(new CopyColumn(array(
"date"=>"datetime"
)))
->pipe(new DateTimeFormat(array(
"date"=>"Y-m-d"
)))
->pipe(new Filter(array(
array("date","<=","2019-02-20"),
array("date",">=","2019-02-20")
)))
->pipe(new Group(array(
"by"=>"date",
"max"=>"datetime"
)))
),
"columns"=>array("code","datetime","in_out")
));
?>
<h1 class="text-center">DB Group By Date</h1>
<?php
Table::create(array(
"dataSource"=>(
$this->src("db")->query("
SELECT code, MAX(datetime),in_out
FROM att_test
WHERE
DATE(datetime) BETWEEN '2019-02-20' AND '2019-02-20'
GROUP BY DATE(datetime);
")
)
));
?>
<br/>
<br/>
<br/>
<br/>
<br/>
<h1 class="text-center">CSV Group By Code, Date, In_out</h1>
<?php
Table::create(array(
"dataSource"=>(
$this->src("csv")
->pipe(new CopyColumn(array(
"date"=>"datetime"
)))
->pipe(new DateTimeFormat(array(
"date"=>"Y-m-d"
)))
->pipe(new Filter(array(
array("date","<=","2019-02-20"),
array("date",">=","2019-02-20")
)))
->pipe(new Group(array(
"by"=>array("code","date","in_out"),
"max"=>"datetime"
)))
),
"columns"=>array("code","datetime","in_out")
));
?>
<h1 class="text-center">DB Group By Code, Date, In_out</h1>
<?php
Table::create(array(
"dataSource"=>(
$this->src("db")->query("
SELECT code, MAX(datetime),in_out
FROM att_test
WHERE
DATE(datetime) BETWEEN '2019-02-20' AND '2019-02-20'
GROUP BY code, DATE(datetime), in_out;
")
)
));
?>
</div>
</body>
</html>
The result coming from both case are the same.
When group by date only, we have this output:
From CSV
code | datetime | in_out |
10019 | 2019-02-20 15:02:51 | 0 |
From DB
code | MAX(datetime) | in_out |
10,019 | 2019-02-20 15:02:51 | 0 |
__When group by code, date, in_out we have this output:__
From CSV
code | datetime | in_out |
10019 | 2019-02-20 15:02:47 | 0 |
10019 | 2019-02-20 15:02:51 | 1 |
From DB
code | MAX(datetime) | in_out |
10,019 | 2019-02-20 15:02:47 | 0 |
10,019 | 2019-02-20 15:02:51 | 1 |
You can test yourself with above code. If something could go wrong, I think it could be the definition of BETWEEN in SQL. When we translate to Filter
process, it should <=
and >=
. It may go wrong if we use <
and >
operator.