KoolReport's Forum

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

KoolReport\Utility not found #1133

Open Jesse opened this topic on on Oct 22, 2019 - 7 comments

Jesse commented on Oct 22, 2019

I'm using the instructions at https://www.koolreport.com/examples/reports/datasources/csv_report/ to build a website with a csv file. I've taken some liberties as to what the CSV is and what it contains, but as far as I know that's not where the error is coming from. When loading the website, i get the error

Fatal error: Class 'koolreport\core\Utility' not found in [projectpath]/koolreport/core/src/KoolReport.php on line 140

I'm not sure if its because of my project structure or something in my code, but I haven't found anything that has made this problem any clearer. My php file includes the following:

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

    use \koolreport\core\src\KoolReport;
    use \koolreport\core\src\processes\Filter;
    use \koolreport\core\src\processes\TimeBucket;
    use \koolreport\core\src\processes\Group;
    use \koolreport\core\src\processes\Limit;
    use \koolreport\core\src\core\Utility;

    class PaymentReports extends \koolreport\KoolReport{
      public function settings(){
        return array(
          "dataSources"=>array(
            "payment_reports"=>array(
              "class"=>'\koolreport\core\src\datasources\CSVDataSource.php',
              'filePath'=>dirname(__FILE__)."/AgentPaymentReports.csv",
            )
          )
        );
      }
      protected function setup(){
        $this->src('AgentPaymentReports')
        ->pipe(new TimeBucket(array(
          "payment_date"=>"month"
        )))
        ->pipe(new Group(array(
          "by"=>"payment_date",
          "sum"=>"amount"
        )))
        ->pipe($this->dataStore('sale_by_month'));
      }
    }

?>

If you'd like to see my CSV file or how my project is structured, I would be more than happy to send it. Thanks in advance!

KoolReport commented on Oct 23, 2019

You should do:

require_once "koolreport/core/autoload.php";

Let me know if it works.

Jesse commented on Oct 23, 2019

It seems to have worked, but now I get the error

Fatal error: Uncaught exception 'Exception' with message 'Datasource not found 'AgentPaymentReport'' in /var/www/projects/ugadisplay/koolreport/core/src/KoolReport.php:255 Stack trace: #0 /var/www/projects/ugadisplay/PaymentReports.php(24): koolreport\KoolReport->src('AgentPaymentRep...') #1 /var/www/projects/ugadisplay/koolreport/core/src/KoolReport.php(100): PaymentReports->setup() #2 /var/www/projects/ugadisplay/index.php(6): koolreport\KoolReport->__construct() #3 {main} thrown in /var/www/projects/ugadisplay/koolreport/core/src/KoolReport.php on line 255

where AgentPaymentReport is my .CSV file and PaymentReports.php is where the code I gave is. I'm guessing the way I referenced my KoolReport.php file may be the cause of this? Thanks for the help; if you have any ideas about this one (or just want me to make a separate thread) go right ahead.

KoolReport commented on Oct 23, 2019

The class name of CSVDataSource should be

"class"=>'\koolreport\datasources\CSVDataSource',

Please follow our documentation or example to get started.

Jesse commented on Oct 23, 2019

Fixing the class line didn't appear to have changed the error I get now. I am following the code at https://www.koolreport.com/examples/reports/datasources/csv_report/, but there are several discrepancies between directories and how they are called (like how datasources is not an actual folder in my koolreport folder).

KoolReport commented on Oct 23, 2019

It seems you register datasource name as "payment_reports" but in the src() function you use "AgentPaymentReports", please change to:

$this->src("payment_reports")->...
Jesse commented on Oct 23, 2019

Since the last comment I've changed the naming issues regarding the csv file and how its called, at least I think I have. Now i'm getting issues regarding variable names and how I call/create them.

Notice: Undefined index: amount in [projectdirectory]/koolreport/core/src/processes/TimeBucket.php on line 100

Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (500) at position 0 (5): Unexpected character' in [projectname]/koolreport/core/src/processes/TimeBucket.php:135 Stack trace: #0 /[projectdirectory]/koolreport/core/src/processes/TimeBucket.php(135): DateTime->__construct('500') #1 [projectdirectory]/koolreport/core/src/core/Node.php(244): koolreport\processes\TimeBucket->onInput(Array) #2 [projectdirectory]/koolreport/core/src/core/Node.php(201): koolreport\core\Node->input(Array, Object(koolreport\datasources\CSVDataSource)) #3 [projectdirectory]/koolreport/core/src/datasources/CSVDataSource.php(175): koolreport\core\Node->next(Array, Object(koolreport\datasources\CSVDataSource)) #4 [projectdirectory]/koolreport/core/src/KoolReport.php(315): koolreport\datasources\CSVDataSource->start() #5 /[projectdirectory]/index.php(7): koolreport\KoolReport->run() #6 {main} thrown in [projectdirectory]/koolreport/core/src/processes/TimeBucket.php on line 135

It's heftier to say the least. Normally I would be able to parse this error and figure out where its coming from but I'm at a lost here. I appreciate the fast responses; hope to get this fixed soon. I'm almost certain its coming from my array dictation with

protected function setup(){
        $this->src('AgentPaymentsReport')
        ->pipe(new TimeBucket(array(
          "Payment Amount"=>"amount"
        )))
        ->pipe(new Group(array(
          "sum"=>"Payment Amount",
          "time"=>"Days Past Due"
        )))
        ->pipe($this->dataStore('overdue_payments'));
      }

Once I get the authorization for sharing the CSV file, I'm sure the problem solving will go a lot smoother.

KoolReport commented on Oct 23, 2019

This settings of TimeBucket is not correct:

"Payment Amount"=>"amount"

Here is our documentation of TimeBucket

The timebucket works on datetime column only to separate datetime into day, week, month ... only.

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