Order Number | Customer Name | Order Date | Status |
---|---|---|---|
This example shows the status of ordering. By using metrics widget, it shows the status of order quantity, order amount as well as the distribution of order status. It will help us to have an overview of business. The table in example shows the list of all orders with their full information. We can navigate the orders page by page, sorting them by their status or order date.
<?php
namespace demo\orders;
use \koolreport\dashboard\metrics\Trend;
use \demo\AutoMaker;
use \koolreport\dashboard\fields\Date;
use \koolreport\dashboard\fields\Currency;
class OrderAmount extends Trend
{
protected function onInit()
{
$this->defaultRange("This Month");
}
protected function dataSource()
{
return AutoMaker::rawSQL("
SELECT
orderDate,
orderdetails.priceEach*orderdetails.quantityOrdered AS total
FROM
orders
JOIN
orderdetails
ON
orders.orderNumber = orderdetails.orderNumber
");
}
protected function ranges()
{
return [
"This Week"=>$this::thisWeek(),
"Last 7 Days"=>$this::last7days(),
"Last 30 Days"=>$this::last30days(),
"This Month"=>$this::thisMonth(),
"This Quarter"=>$this::thisQuarter(),
"This Year"=>$this::thisYear(),
];
}
protected function fields()
{
return [
$this->group(Date::create("orderDate")),
$this->sum(
Currency::create("total")
->USD()
->symbol()
->decimals(0)
)
];
}
}
<?php
namespace demo\orders;
use \koolreport\dashboard\Dashboard;
use \koolreport\dashboard\containers\Row;
use \koolreport\dashboard\containers\Panel;
use \koolreport\dashboard\containers\Html;
class OrderBoard extends Dashboard
{
protected function content()
{
return [
Row::create()->sub([
OrderQuantity::create()->type("primary")->width(1/3)->lazyLoading(true),
OrderAmount::create()->type("warning")->width(1/3)->lazyLoading(true),
OrderStatus::create()->type("success")->width(1/3)->lazyLoading(true),
]),
OrderTable::create()->lazyLoading(true),
\demo\CodeDemo::create("
This example shows the status of ordering. By using metrics widget, it shows the status of
order quantity, order amount as well as the distribution of order status. It will help us
to have an overview of business. The table in example shows the list of all orders
with their full information. We can navigate the orders page by page,
sorting them by their status or order date.
")
];
}
}
<?php
namespace demo\orders;
use \koolreport\dashboard\metrics\Value;
use \demo\AutoMaker;
use \koolreport\dashboard\fields\Date;
use \koolreport\dashboard\fields\Text;
class OrderQuantity extends Value
{
protected function onInit()
{
$this->defaultRange("This Month");
}
protected function dataSource()
{
return AutoMaker::table("orders")
->select("orderDate");
}
protected function ranges()
{
return [
"This Week"=>$this::thisWeek(),
"Last 7 Days"=>$this::last7days(),
"Last 30 Days"=>$this::last30days(),
"This Month"=>$this::thisMonth(),
"This Quarter"=>$this::thisQuarter(),
"This Year"=>$this::thisYear(),
];
}
protected function fields()
{
return [
Date::create("orderDate"),
$this->count(
Text::create("orderDate")
)
];
}
}
<?php
namespace demo\orders;
use \koolreport\dashboard\metrics\Category;
use \demo\AutoMaker;
use \koolreport\dashboard\fields\Text;
class OrderStatus extends Category
{
protected function dataSource()
{
return AutoMaker::table("orders")
->select("status");
}
protected function fields()
{
return [
$this->group(Text::create("status"))->showTop(3)->andShowOthers(),
$this->count(Text::create("status"))
];
}
}
<?php
namespace demo\orders;
use \koolreport\dashboard\widgets\Table;
use \koolreport\dashboard\fields\Number;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Date;
use \koolreport\dashboard\fields\Badge;
use \demo\AutoMaker;
class OrderTable extends Table
{
protected function onInit()
{
$this->pageSize(10);
}
protected function dataSource()
{
return AutoMaker::table("orders")
->join("customers","customers.customerNumber","=","orders.customerNumber")
->select("orders.orderNumber","customerName","orderDate","status");
}
protected function fields()
{
return [
Number::create("orderNumber")
->useRaw(true),
Text::create("customerName"),
Date::create("orderDate")
->displayFormat("F j, Y")
->sortable(true)
->sort("desc")
,
Badge::create("status")->type(function($status){
switch($status){
case "Shipped":
case "Resolved":
return "success";
case "Cancelled":
case "Disputed":
return "danger";
case "On Hold":
return "warning";
case "In Process":
return "info";
default:
return "default";
}
})
->sortable(true),
];
}
}