KoolReport's Forum

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

How to run a report with json data coming from json column in MySQL #840

Open paulo opened this topic on on Apr 29, 2019 - 15 comments

paulo commented on Apr 29, 2019

Hi,

I am storing data as a JSON column in MySQL. Is it possible to run this report against this data? If I select a bunch of rows from mysql table and have the json column with the fields, how can I run a report? I looked at the datasource documentation and couldn't find anything about json.

thanks Paulo

David Winterburn commented on Apr 30, 2019

Hi Paulo,

Please try using the Map process to turn the json column to multiple fields:

->pipe(new Map([
    "{value}" => function($row) {
        $jsonData = $row["jsonColumn"];
        $jsonData = json_decode($jsonData, true);
        $row["field1"] = $jsonData["field1"];
        $row["fieldN"] = $jsonData["fieldN"];

        return $row;
    }
]))

Let us know if this is what you want. Thanks!

paulo commented on Apr 30, 2019

thank you. I will try this. Paulo

Afluens commented on Oct 10, 2019

I am getting a PHP notice when using json column with MariaDB. Can you fix this ? Thanks, Christophe Notice: Undefined index: native_type in /Users/cney/dev/testjson/vendor/koolreport/core/src/datasources/PdoDataSource.php on line 461

The answer at #1121

paulo commented on Dec 10, 2020

H there, I was looking at this example, combined with the API example posted at https://www.koolreport.com/forum/topics/234

here is the code:

function settings()
{
    return array(
        "dataSources"=>array(
            "apiarray"=>array(
                "class"=>'\koolreport\datasources\ArrayDataSource',
                "dataFormat"=>"associate",
            )
        )
    );
}

function setup()

{
    Log::debug("PaymentAPIReport init");

    $this->login();
    $QueryPayments = $this->paymentRunQuery(
        array(
            "SortBy" => "paymentDate",
            "payType" => "2",
            "paymentGroup" => "15-20"
        )
    );

    if(isset($QueryPayments['Payment']) && !empty($QueryPayments['Payment'])){
        Log::debug("PaymentAPIReport GOOD");

    }
    $this->logout();
   //dd($QueryPayments);
    $this->src("apiarray")->load($QueryPayments)
        ->pipe(new Map([
            "{value}" => function($row) {
                $jsonData = $row["Payment"];
                $jsonData = json_decode($jsonData, true);
                $row["paymentNo"] = $jsonData["paymentNo"];
                $row["amount"] = $jsonData["amount"];

                return $row;
            }
        ]))
    ->pipe($this->dataStore("result"));

I am getting: "Undefined offset: 0"

C:\dev\ellison-travel\vendor\koolreport\core\src\datasources\ArrayDataSource.php

        case "table":
            $columnNames = $data[0];
            $metaData = array("columns"=>array());
            for ($i=0;$i<count($columnNames);$i++) {
                $metaData["columns"][$columnNames[$i]] = array(
                    "type"=>(isset($data[1]))
                        ?$this->guessType($data[1][$i]):"unknown",
                );;
            }
            $this->sendMeta($metaData, $this);
            $this->startInput(null);
            $rowNum = count($data);
            for ($i=1;$i<$rowNum;$i++) {
                $this->next(array_combine($columnNames, $data[$i]), $this);
            }
            break;
        case "associate":
        default:
            $metaData = array("columns"=>array());
            foreach ($data[0] as $key=>$value) {
                $metaData["columns"][$key]=array(

API is returning JSON with data, I can see in the browser when dd, Here is the return:

"Payment": [

                {
                    "paymentNo": 207416,
                    "paymentDate": "2018-08-28T00:00:00.000Z",
                    "ckCCNo": "MC 54-X",
                    "amount": 120000,
                    "bank_LinkNo": "4",
                    "payType_LinkNo": "1",
                    "payMethod_LinkNo": "5",
                    "profile_LinkNo": 635,
                    "JERecord_LinkNo": null,
                    "submitTo_LinkCode": null,
                    "name": "NAMEie",
                    "profileType_LinkCode": "I",
                    "remarks": "text",
                    "paymentGroup": "1955",
                    "dateCleared": "2018-08-29T00:00:00.000Z",
                    "currencyCode": "",
                    "code": "",
                    "payeeName": "name",
                    "branch_LinkNo": 2,
                    "deposit_LinkNo": null,
                    "invoiceRef": null,
                    "attachmentCount": 0
                },
                {
                    "paymentNo": 207417,
                    "paymentDate": "2018-08-28T00:00:00.000Z",
                    "ckCCNo": "VI 45-X",
                    "amount": 120000,
                    "bank_LinkNo": "4",
                    "payType_LinkNo": "1",
                    "payMethod_LinkNo": "5",
                    "profile_LinkNo": 63975,
                    "JERecord_LinkNo": null,
                    "submitTo_LinkCode": null,
                    "name": "name of the cliente",
                    "profileType_LinkCode": "I",
                    "remarks":ffff",
                    "paymentGroup": "1955 - ",
                    "dateCleared": "2018-08-29T00:00:00.000Z",
                    "currencyCode": "",
                    "code": "",
                    "payeeName": "name of the lcient",
                    "branch_LinkNo": 2,
                    "deposit_LinkNo": null,
                    "invoiceRef": null,
                    "attachmentCount": 0
                },

thank you very much

David Winterburn commented on Dec 10, 2020

Hi Paulo,

Would you please post the full error message including stack tracing? There could have been some array structure error. Thanks!

paulo commented on Dec 10, 2020

ok, I will try to paste here everything that I see. From the Log files: Undefined offset: 0 {"userId":3,"exception":"[object] (ErrorException(code: 0): Undefined offset: 0 at C:\dev\ellison-travel\vendor\koolreport\core\src\datasources\ArrayDataSource.php:136) [stacktrace] #0 C:\dev\ellison-travel\vendor\koolreport\core\src\datasources\ArrayDataSource.php(136): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined offse...', 'C:\\dev\\ellison-...', 136, Array) #1 C:\dev\ellison-travel\vendor\koolreport\core\src\KoolReport.php(315): koolreport\datasources\ArrayDataSource->start() #2 C:\dev\ellison-travel\app\Http\Controllers\Admin\AdminReportController.php(1288): koolreport\KoolReport->run() #3 [internal function]: App\Http\Controllers\Admin\AdminReportController->executeReport('Reporting:TRAMS...') #4 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(54): call_user_func_array(Array, Array) #5 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('executeReport', Array) #6 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Route.php(219): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\Admin\AdminReportController), 'executeReport') #7 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Route.php(176): Illuminate\Routing\Route->runController() #8 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php(680): Illuminate\Routing\Route->run() #9 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #10 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #11 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure)) #12 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #13 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php(75): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #14 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure)) #15 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #16 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #17 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure)) #18 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #19 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(56): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #20 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure)) #21 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #22 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #23 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure)) #24 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #25 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(66): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #26 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure)) #27 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #28 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #29 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php(682): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #30 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php(657): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request)) #31 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php(623): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route)) #32 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php(612): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) #33 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(176): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) #34 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request)) #35 C:\dev\ellison-travel\vendor\fideloper\proxy\src\TrustProxies.php(57): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #36 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure)) #37 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #38 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #39 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure)) #40 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #41 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #42 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure)) #43 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #44 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php(27): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #45 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure)) #46 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #47 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(62): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #48 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(163): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure)) #49 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #50 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #51 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #52 C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request)) #53 C:\dev\ellison-travel\public\index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) #54 C:\dev\ellison-travel\server.php(21): require_once('C:\\dev\\ellison-...') #55 {main} "}

paulo commented on Dec 10, 2020

from the browser screen: C:\dev\ellison-travel\vendor\koolreport\core\src\datasources\ArrayDataSource.php

        case "table":
            $columnNames = $data[0];
            $metaData = array("columns"=>array());
            for ($i=0;$i<count($columnNames);$i++) {
                $metaData["columns"][$columnNames[$i]] = array(
                    "type"=>(isset($data[1]))
                        ?$this->guessType($data[1][$i]):"unknown",
                );;
            }
            $this->sendMeta($metaData, $this);
            $this->startInput(null);
            $rowNum = count($data);
            for ($i=1;$i<$rowNum;$i++) {
                $this->next(array_combine($columnNames, $data[$i]), $this);
            }
            break;
        case "associate":
        default:
            $metaData = array("columns"=>array());
            foreach ($data[0] as $key=>$value) {
                $metaData["columns"][$key]=array(
                    "type"=>$this->guessType($value),
                );
            }
            $this->sendMeta($metaData, $this);
            $this->startInput(null);
            foreach ($data as $row) {
                $this->next($row);
            }
            break;
        }
    }
    $this->endInput(null);
}

} Arguments "Undefined offset: 0"

paulo commented on Dec 10, 2020

ErrorException thrown with message "Undefined offset: 0"

Stacktrace: #55 ErrorException in C:\dev\ellison-travel\vendor\koolreport\core\src\datasources\ArrayDataSource.php:136 #54 Illuminate\Foundation\Bootstrap\HandleExceptions:handleError in C:\dev\ellison-travel\vendor\koolreport\core\src\datasources\ArrayDataSource.php:136 #53 koolreport\datasources\ArrayDataSource:start in C:\dev\ellison-travel\vendor\koolreport\core\src\KoolReport.php:315 #52 koolreport\KoolReport:run in C:\dev\ellison-travel\app\Http\Controllers\Admin\AdminReportController.php:1288 #51 App\Http\Controllers\Admin\AdminReportController:executeReport in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54 #50 call_user_func_array in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54 #49 Illuminate\Routing\Controller:callAction in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php:45 #48 Illuminate\Routing\ControllerDispatcher:dispatch in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Route.php:219 #47 Illuminate\Routing\Route:runController in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Route.php:176 #46 Illuminate\Routing\Route:run in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php:680 #45 Illuminate\Routing\Router:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30 #44 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php:41 #43 Illuminate\Routing\Middleware\SubstituteBindings:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #42 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #41 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php:75 #40 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #39 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #38 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php:49 #37 Illuminate\View\Middleware\ShareErrorsFromSession:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #36 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #35 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php:56 #34 Illuminate\Session\Middleware\StartSession:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #33 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #32 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php:37 #31 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #30 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #29 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php:66 #28 Illuminate\Cookie\Middleware\EncryptCookies:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #27 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #26 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:104 #25 Illuminate\Pipeline\Pipeline:then in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php:682 #24 Illuminate\Routing\Router:runRouteWithinStack in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php:657 #23 Illuminate\Routing\Router:runRoute in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php:623 #22 Illuminate\Routing\Router:dispatchToRoute in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php:612 #21 Illuminate\Routing\Router:dispatch in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:176 #20 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30 #19 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\fideloper\proxy\src\TrustProxies.php:57 #18 Fideloper\Proxy\TrustProxies:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #17 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #16 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:21 #15 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #14 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #13 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:21 #12 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #11 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #10 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php:27 #9 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #8 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #7 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php:62 #6 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #5 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #4 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:104 #3 Illuminate\Pipeline\Pipeline:then in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:151 #2 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:116 #1 Illuminate\Foundation\Http\Kernel:handle in C:\dev\ellison-travel\public\index.php:55 #0 require_once in C:\dev\ellison-travel\server.php:21

paulo commented on Dec 11, 2020

Hi, is there any other info that you need from me ? thank you

David Winterburn commented on Dec 14, 2020

Hi Paulo,

Just before this statement:

     $this->src("apiarray")->load($QueryPayments)

please add the following line and let us know the result:

     echo "QueryPayments = "; var_dump($QueryPayments);
     $this->src("apiarray")->load($QueryPayments)

Thanks!

paulo commented on Dec 14, 2020

this doesn't make a lot of sense to me, but you guys are the experts, I got similar error after placing the above in place.

ErrorException thrown with message "Undefined offset: 0"

Stacktrace: #55 ErrorException in C:\dev\ellison-travel\vendor\koolreport\core\src\datasources\ArrayDataSource.php:136 #54 Illuminate\Foundation\Bootstrap\HandleExceptions:handleError in C:\dev\ellison-travel\vendor\koolreport\core\src\datasources\ArrayDataSource.php:136 #53 koolreport\datasources\ArrayDataSource:start in C:\dev\ellison-travel\vendor\koolreport\core\src\KoolReport.php:315 #52 koolreport\KoolReport:run in C:\dev\ellison-travel\app\Http\Controllers\Admin\AdminReportController.php:1288 #51 App\Http\Controllers\Admin\AdminReportController:executeReport in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54 #50 call_user_func_array in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54 #49 Illuminate\Routing\Controller:callAction in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php:45 #48 Illuminate\Routing\ControllerDispatcher:dispatch in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Route.php:219 #47 Illuminate\Routing\Route:runController in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Route.php:176 #46 Illuminate\Routing\Route:run in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php:680 #45 Illuminate\Routing\Router:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30 #44 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php:41 #43 Illuminate\Routing\Middleware\SubstituteBindings:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #42 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #41 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php:75 #40 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #39 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #38 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php:49 #37 Illuminate\View\Middleware\ShareErrorsFromSession:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #36 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #35 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php:56 #34 Illuminate\Session\Middleware\StartSession:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #33 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #32 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php:37 #31 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #30 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #29 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php:66 #28 Illuminate\Cookie\Middleware\EncryptCookies:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #27 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #26 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:104 #25 Illuminate\Pipeline\Pipeline:then in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php:682 #24 Illuminate\Routing\Router:runRouteWithinStack in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php:657 #23 Illuminate\Routing\Router:runRoute in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php:623 #22 Illuminate\Routing\Router:dispatchToRoute in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Router.php:612 #21 Illuminate\Routing\Router:dispatch in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:176 #20 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30 #19 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\fideloper\proxy\src\TrustProxies.php:57 #18 Fideloper\Proxy\TrustProxies:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #17 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #16 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:21 #15 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #14 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #13 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:21 #12 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #11 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #10 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php:27 #9 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #8 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #7 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php:62 #6 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163 #5 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 #4 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:104 #3 Illuminate\Pipeline\Pipeline:then in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:151 #2 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in C:\dev\ellison-travel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:116 #1 Illuminate\Foundation\Http\Kernel:handle in C:\dev\ellison-travel\public\index.php:55 #0 require_once in C:\dev\ellison-travel\server.php:21

paulo commented on Dec 14, 2020

after testing the above, I also printed out the logs to see the variable:

  Log::debug("TRAMSPaymentAPIReport ok here");
   //echo "QueryPayments = ";
   //var_dump($QueryPayments);
    Log::debug("TRAMSPaymentAPIReport passed above =", $QueryPayments);
    $this->src("apiarray")->load($QueryPayments)

Log printed something starting like this: TRAMSPaymentAPIReport passed above = {"Payment":[{"paymentNo":267357,"paymentDate":"2020-01-22T00:00:00.000Z","ckCCNo":"","amount":-185000,"

paulo commented on Dec 14, 2020

Also, to clarify, after I call the API, the trait class already does some 'stuff':

$json = json_decode($response->getBody()->getContents(), true);

         if (isset($json['result']['dataset']['data'])) {
        return $json['result']['dataset']['data'];
    }
     return [];

The above is inside of the trait which is called by the report setup function when I do this: $QueryPayments = $this->paymentRunQuery(

    array(
        "SortBy" => "paymentDate",
        "payType" => "2",
        "paymentGroup" => "15-20"
    )
);

if(isset($QueryPayments['Payment']) && !empty($QueryPayments['Payment'])){
    Log::debug("PaymentAPIReport GOOD");

}
paulo commented on Dec 14, 2020

I think I solve my problem. I have to do some testing still. The part that I am not getting is how it process the result into the report without any mapping. Is it because I am decoding above already and the report uses the name of the JSON map to fill up the report ?

After returning the API, I modified the following: $QueryPayments = $QueryPayments['Payment'];

 $this->src("apiarray")->load($QueryPayments)
        ->pipe(new Map([
            "{value}" => function($row) {
             //   $jsonData = $row["Payment"];
              //  $jsonData = json_decode($jsonData, true);
                $jsonData = $row;
            //    $row["paymentNo"] = $jsonData["paymentNo"];
           //     $row["amount"] = $jsonData["amount"];

                return $row;
            }
        ]))
daniel commented on Nov 29, 2021

Since 2019 they have been asking for integration with the JSON API and they still have not been able to put anything in the documentation

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