Hi everyone!
I'm new to KoolReport and i'm using the KoolReport Dashboard.
I'm following the example of Payments (in the Dashboard demo)
I'm building a simple widget of sales amount by date.
I want the data to be grouped by day. But, since since the date is stored in MySQL as DATETIME (0000-00-00 00:00:00) it doesn't add up the sales amount in a day, everything is separated...
How can i convert the date so the sales are grouped by day?
Here's my code (based on the PAYMENTS example in the dashboard demo):
<?php
use \koolreport\dashboard\widgets\google\ColumnChart;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\DateTime;
use \koolreport\dashboard\fields\Currency;
use \koolreport\processes\Limit;
use \koolreport\processes\DateTimeFormat;
class TransactionsByDate extends ColumnChart
{
protected function onInit()
{
$this
->title("Payment By Date")
//->updateEffect("none")
->height("240px");
}
protected function dataSource()
{
//Get value from the date range picker
$range = $this->sibling("TransactionsDateRange")->value();
//Apply to query
return Incognito::table("wp_wc_order_stats")
->whereBetween("date_created",$range)
->groupBy("date_created")
->sum("net_total")->alias("dayAmount")
->select("date_created");
}
protected function fields()
{
return [
DateTime::create("date_created")->displayFormat("Y-m-d")->sort("asc"),
Currency::create("dayAmount")->CAD()->symbol()->decimals(2)
];
}
}
Thanks for your help!