Customers
118
Customers
295
Shipped Orders
$8,853,839
Received Payments
Customer Number | Customer Name | Country | Credit Limit | ||
---|---|---|---|---|---|
103 | Omkarms5 | Singapore | $10,012.00 | ||
112 | Shubham Mhase | Switzerland | $2,000.00 | ||
114 | Australian Collectors, Co. | Canada | $117,300.00 | ||
119 | La Rochelle Gifts | France | $118,200.00 | ||
121 | ddd | Singapore | $667,773.00 | ||
124 | Mini changos | USA | $210,500.00 | ||
128 | Blauer See Auto, Co. | Germany | $59,800.00 | ||
129 | Mini Wheels Co. | New Zealand | $64,600.00 | ||
131 | Land of Toys Inc. | USA | $114,900.00 | ||
141 | Euro+ Shopping Channel | Portugal | $227,601.00 |
Admin Panel is a new feature of Dashboard Framework which can help to contruct beautiful dashboard admin panel. Setting up different views of your data, applying data search & filter, adding custom actions on your data are all possible.
This example demonstrates creating Customer
resource to manage your customers table.
<?php
namespace demo\admin\customer;
use demo\AdminAutoMaker;
use koolreport\dashboard\admin\filters\MultiSelect2Filter;
class CountryFilter extends MultiSelect2Filter
{
protected function apply($query, $countries)
{
$query->whereIn("country",$countries);
return $query;
}
protected function options()
{
return AdminAutoMaker::table("customers")
->select("country")
->distinct();
}
}
<?php
namespace demo\admin\customer;
use demo\admin\order\Order;
use demo\AdminAutoMaker;
use koolreport\dashboard\admin\actions\ExportAction;
use koolreport\dashboard\admin\actions\DeleteAction;
use koolreport\dashboard\admin\actions\DetailAction;
use koolreport\dashboard\admin\actions\InlineEditAction;
use koolreport\dashboard\admin\actions\UpdateAction;
use koolreport\dashboard\admin\relations\HasMany;
use koolreport\dashboard\admin\Resource;
use koolreport\dashboard\fields\Currency;
use koolreport\dashboard\fields\ID;
use koolreport\dashboard\fields\Text;
use koolreport\dashboard\inputs\Select;
use koolreport\dashboard\validators\NumericValidator;
use koolreport\dashboard\validators\RequiredFieldValidator;
class Customer extends Resource
{
protected function onCreated()
{
$this->manageTable("customers")->inSource(AdminAutoMaker::class);
//Allow searchBox
$this->listScreen()->searchBox()
->enabled(true)
->placeHolder("Search customers");
$this->listScreen()->adminTable()
->tableStriped(true);
}
protected function relations()
{
return [
HasMany::resource(Order::class)->link(["customerNumber"=>"customerNumber"])->title("Orders")
];
}
protected function filters()
{
return [
CountryFilter::create()->title("Countries"),
HighCreditFilter::create()->title("Credit Limit > $120k")
];
}
protected function glasses()
{
return [
MostValuedCustomers::create()
];
}
protected function actions()
{
return [
ExportAction::create()
->formatOptions(["csv","xlsx","pdf"]) // Other options include "png" and "jpg"
->rangeOptions(["selected-rows","current-page","all-pages"])
->csv([
"delimiter"=>";",
]),
EmailAction::create()->showOnDetail(true),
DetailAction::create(),
UpdateAction::create()->showOnTable(false),
InlineEditAction::create(),
DeleteAction::create(),
];
}
protected function fields()
{
return [
ID::create("customerNumber")
->searchable(true)
->sortable(true)
->validators([
RequiredFieldValidator::create(),
NumericValidator::create(),
]),
Text::create("customerName")
->searchable(true)
->sortable(true),
Text::create("country")
->searchable(true)
->sortable(true)
->inputWidget(
Select::create()
->dataSource(function(){
return AdminAutoMaker::table("customers")->select("country")->distinct()->orderBy("country");
})
->fields(function(){
return [
Text::create("country")
];
})
),
Text::create("city")
->showOnIndex(false),
Text::create("addressLine1")->label("Address")
->showOnIndex(false),
Text::create("phone")
->showOnIndex(false),
Currency::create("creditLimit")
->USD()->symbol()
->sortable(true),
];
}
protected function highlights()
{
return [
TotalCustomers::create()->width(1/3),
TotalShippedOrders::create()->width(1/3),
TotalPayments::create()->width(1/3),
];
}
/**
* The bottom is where you can put extra widgets,
* Here we just put the CodeDemo to show our demo code
* which is not important in your real application.
* @return array
*/
protected function bottom()
{
return [
\demo\CodeDemo::create("
Admin Panel is a new feature of Dashboard Framework which can help to contruct beautiful dashboard
admin panel. Setting up different views of your data, applying data search & filter, adding custom
actions on your data are all possible.
<p>
This example demonstrates creating <code>Customer</code> resource to manage your customers table.
</p>
")->raw(true)
];
}
}
<?php
namespace demo\admin\customer;
use koolreport\dashboard\admin\actions\Action;
use koolreport\dashboard\inputs\TextArea;
use koolreport\dashboard\inputs\TextBox;
use koolreport\dashboard\notifications\Note;
use koolreport\dashboard\validators\RequiredFieldValidator;
class EmailAction extends Action
{
protected function onCreated()
{
$this->title("Email")
->type("warning")
->icon("far fa-envelope");
}
protected function handle($form, $models)
{
$subject = $form->input("subject")->value();
$content = $form->input("content")->value();
// In real applications, we will send email here
// We fake sending email and show notification
$numberOfPersons = $models->count();
if($numberOfPersons==1) {
return Note::success("The email has been sent to <b>".$models->get(0,"customerName")."</b>","Email sent!");
}
return Note::success("Has emailed to $numberOfPersons persons","Email sent!");
}
protected function form()
{
return Action::modalForm([
"Subject"=>TextBox::create("subject")->placeHolder("Subject"),
"Content"=>TextArea::create("content")->placeHolder("Content"),
])
->validators([
//Subject required validation
RequiredFieldValidator::create()
->inputToValidate("subject")
->errorMessage("* Subject is required"),
//Content required validation
RequiredFieldValidator::create()
->inputToValidate("content")
->errorMessage("* Content can not be empty"),
])
->confirmButtonText("Send");
}
}
<?php
namespace demo\admin\customer;
use koolreport\dashboard\admin\filters\ToggleFilter;
class HighCreditFilter extends ToggleFilter
{
protected function apply($query, $bool)
{
$query->where("creditLimit",">",120000);
return $query;
}
}
<?php
namespace demo\admin\customer;
use koolreport\dashboard\admin\glasses\Glass;
use koolreport\dashboard\fields\Currency;
use koolreport\dashboard\fields\ID;
use koolreport\dashboard\fields\Text;
class MostValuedCustomers extends Glass
{
protected function onCreated()
{
$this->type("warning")
->icon("fa fa-users");
}
protected function query($query)
{
$query->join("payments","customers.customerNumber","=","payments.customerNumber")
->groupBy("customers.customerNumber")
->sum("amount")->alias("totalPayment")
->select("customers.customerNumber","customerName","country")
->orderBy("totalPayment","desc");
return $query;
}
protected function fields()
{
return [
ID::create("customerNumber")
->searchable(true)
->sortable(true),
Text::create("customerName")
->searchable(true)
->sortable(true),
Text::create("country")
->searchable(true)
->sortable(true),
Currency::create("totalPayment")
->USD()->symbol()
];
}
}
<?php
namespace demo\admin\customer;
use demo\AdminAutoMaker;
use koolreport\dashboard\widgets\SimpleCard;
class TotalCustomers extends SimpleCard
{
protected function onCreated()
{
$this
->type("primary")
->text("Customers")
->icon("fas fa-users");
}
protected function value()
{
return AdminAutoMaker::table("customers")->count()->run()->getScalar();
}
}
<?php
namespace demo\admin\customer;
use demo\AdminAutoMaker;
use koolreport\dashboard\widgets\SimpleCard;
class TotalPayments extends SimpleCard
{
protected function onCreated()
{
$this
->type("warning")
->text("Received Payments")
->icon("fas fa-dollar-sign")
->prefix("$");
}
protected function value()
{
return AdminAutoMaker::table("payments")->sum("amount")->run()->getScalar();
}
}
<?php
namespace demo\admin\customer;
use demo\AdminAutoMaker;
use koolreport\dashboard\widgets\SimpleCard;
class TotalShippedOrders extends SimpleCard
{
protected function onCreated()
{
$this
->type("danger")
->text("Shipped Orders")
->icon("far fa-copy");
}
protected function value()
{
return AdminAutoMaker::table("orders")->where("status","Shipped")->count()->run()->getScalar();
}
}