KoolReport's Forum

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

Unable to run the example code provided by you #1866

Closed Abhishek opened this topic on on Jan 25, 2021 - 4 comments

Abhishek commented on Jan 25, 2021

Hi, My name is Abhishek actually I am looking for a tool that can make my work easy to produce the report but I am unable to execute the example code provided on your site. And I am running the code on windows, not on the mac so could you please help me to run the code. And thanks in advance. code

index.php

<?php
require_once "SalesByCustomer.php";
$salesbycustomer = new SalesByCustomer;
$salesbycustomer->run()->render();
?>

SalesBycustomer.php

<?php
require_once "../vendor/koolreport/core/autoload.php";
require_once "../vendor/koolreport/core/src/KoolReport.php";

use \Users\Ashwin\XAMPP\htdocs\Reports\processes\Group;
use \Users\Ashwin\XAMPP\htdocs\Reports\processes\Sort;
use \Users\Ashwin\XAMPP\htdocs\Reports\processes\Limit;

class SalesByCustomer
{
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "sales"=>array(
                    "connectionString"=>"mysql:host=localhost;dbname=db_sales",
                    "username"=>"root",
                    "password"=>"",
                    "charset"=>"utf8"
                )
            )
        );
    }

    public function setup()
    {
        $this->src('sales')
        ->query("SELECT customerName,dollar_sales FROM customer_product_dollarsales")
        ->pipe(new Group(array(
            "by"=>"customerName",
            "sum"=>"dollar_sales"
        )))
        ->pipe(new Sort(array(
            "dollar_sales"=>"desc"
        )))
        ->pipe(new Limit(array(10)))
        ->pipe($this->dataStore('sales_by_customer'));
    }
}
?>

SalesBycustomer.view.php

<?php 
    use \Users\Ashwin\XAMPP\htdocs\Reports\widgets\koolphp\Table;
    use \Users\Ashwin\XAMPP\htdocs\Reports\widgets\google\BarChart;
?>

<div class="text-center">
    <h1>Sales Report</h1>
    <h4>This report shows top 10 sales by customer</h4>
</div>
<hr/>

<?php
    BarChart::create(array(
        "dataStore"=>$this->dataStore('sales_by_customer'),
        "width"=>"100%",
        "height"=>"500px",
        "columns"=>array(
            "customerName"=>array(
                "label"=>"Customer"
            ),
            "dollar_sales"=>array(
                "type"=>"number",
                "label"=>"Amount",
                "prefix"=>"$",
            )
        ),
        "options"=>array(
            "title"=>"Sales By Customer"
        )
    ));
?>
<?php
Table::create(array(
    "dataStore"=>$this->dataStore('sales_by_customer'),
        "columns"=>array(
            "customerName"=>array(
                "label"=>"Customer"
            ),
            "dollar_sales"=>array(
                "type"=>"number",
                "label"=>"Amount",
                "prefix"=>"$",
            )
        ),
    "cssClass"=>array(
        "table"=>"table table-hover table-bordered"
    )
));
?>

error

PHP Warnin
Warning: require_once(../vendor/koolreport/core/autoload.php): Failed to open stream: No such file or directory in C:\Users\Ashwin\XAMPP\htdocs\Reports\salesreport\SalesByCustomer.php on line 2
g:  require_once(../vendor/koolreport/core/autoload.php): Failed to open stream: No such file or directory in C:\Users\Ashwin\XAMPP\htdocs\Reports\salesreport\SalesByCustomer.php on line 2
PHP Fatal error:  Uncaught Error: Failed opening required '../vendor/koolreport/core/autoload.php' (include_path='C:\Users\Ashwin\XAMPP\php\PEAR') in C:\Users\Ashwin\XAMPP\htdocs\Reports\salesreport\SalesByCustomer.php:2
Stack trace:
#0 C:\Users\Ashwin\XAMPP\htdocs\Reports\salesreport\index.php(2): require_once()
#1 {main}
  thrown in C:\Users\Ashwin\XAMPP\htdocs\Reports\salesreport\SalesByCustomer.php on line 2
Fatal error: Uncaught Error: Failed opening required '../vendor/koolreport/core/autoload.php' (include_path='C:\Users\Ashwin\XAMPP\php\PEAR') in C:\Users\Ashwin\XAMPP\htdocs\Reports\salesreport\SalesByCustomer.php:2
Stack trace:
#0 C:\Users\Ashwin\XAMPP\htdocs\Reports\salesreport\index.php(2): require_once()
#1 {main}
  thrown in C:\Users\Ashwin\XAMPP\htdocs\Reports\salesreport\SalesByCustomer.php on line 2
KoolReport commented on Jan 25, 2021

Base on error generated, please make sure that you have correct path to "../vendor/koolreport/core/autoload.php", please check that path.

Beside:

  1. You do not need to require the "../vendor/koolreport/core/src/KoolReport.php"
  2. You use the wrong class name, for example: use \Users\Ashwin\XAMPP\htdocs\Reports\processes\Group; it should be use \koolreport\processes\Group;. Please use the same like in our example.
use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\Limit;

in the view as well, it should be:

<?php 
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\BarChart;
?>

Please try to read the error message, it will guide you how to fix the issue.

KoolReport commented on Jan 25, 2021

Further more, your SaleByCustomer does not extends from our KoolReport, it should be:

class SaleByCustomer extends \koolreport\Koolreport
{
//...
}
Abhishek commented on Jan 25, 2021

Respected Sir/Madam, Thanks for your soon reply, and now I am able to get the exact output in the example after following your instructions.

KoolReport commented on Jan 25, 2021

Awesome :)

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
help needed

None