KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Metrics widget controlled with Date Range selector #2315

Open Mathieu Viennet opened this topic on on Sep 2 - 5 comments

Mathieu Viennet commented on Sep 2

Hi!

Is it possible to control the Metrics widget with a date range selector and also remove the date selector of the metric? I basically just want to keep the functionality of showing the current data VS last period...

Or do i need to create a custom text panel?

Here's a screenshot of what i want to do :

Thanks!

KoolReport commented on Sep 2

Instread of using metrics, You may use the SimpleCard via KWidget like following:

<?php

class OrderNetMetric extends \koolreport\dashboard\widgets\KWidget
{
    protected function onCreated()
    {
        $this->use(\koolreport\amazing\SimpleCard::class);
    }

    protected function onRendering()
    {
        $range = $this->sibling("DateRange")->value();
        $value = Incognito::rawSQL("
            SELECT
                orderTotal - orderTax - orderShipping - orderShippingTax - cartDiscount - cartDiscountTax - refundAmount AS orderNet
            FROM 
                viuInvoicesRefundsByDate
            WHERE 
                transactionDateTimestamp between '" . $range[0] . "' and '" . $range[1] . "'	
        ")
        ->run()
        ->getScalar(); //Query to get value only

        $this->settings([
            "title"=>"Order Net"
            "value"=>$value
        ]);
        
        return true;
    }
}

Let us know if you need further assistance.

Mathieu Viennet commented on Sep 2

Thank you i'll look into it and get back to you if questions

Mathieu Viennet commented on Sep 9

post edited Found the error :

We need a coma after "title"=>"Order Net"

Mathieu Viennet commented on Sep 9

Is there a way in the dashboard where i can just right some PHP and SQL and echo the values? Kinda like a VIEW in the normal KoolReport? Where you can write PHP and HTML...

Sorry i don't know if i'm clear

KoolReport commented on Sep 10

Yes, it is possible, you can use the CustomBoard in which you have full control of the view, you can use HTML or PHP or any KoolReport widget there. It is designed following MVC pattern. The CustomBoard is the closest to the normal KoolReport.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

Dashboard