KoolReport's Forum

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

Pass data to view #1124

Closed paulo opened this topic on on Oct 10, 2019 - 9 comments

paulo commented on Oct 10, 2019

How can I do some php calculation in laravel report class and then pass them to the view and display them ? For instance, I will use Laravel-php to calculate the number of business dates taking into account weekends and stat holidays based on the employee province. I'd like to pass this info to the view. The view will show a report showing the hours worked <- this part is straight forward.

thank you!

KoolReport commented on Oct 11, 2019

Could you please share some of your code. I a little confuse with view of report with view of laravel. Those are different.

paulo commented on Oct 15, 2019

I have a function like the one below to give me the number of working days. I want to send this information to the view, so I can display there on the top. After this, I will show a simple report. Showing this report is not an issue. The issue is to pass the information from the function below to the view. thanks

function number_of_working_dates($from, $days) {
    $workingDays = [1, 2, 3, 4, 5]; # date format = N (1 = Monday, ...)
    $holidayDays = ['*-12-25', '*-01-01', '2013-12-24', '2013-12-25']; # variable and fixed holidays

    $from = new DateTime($from);
    $dates = [];
    $dates[] = $from->format('Y-m-d');
    while ($days) {
        $from->modify('+1 day');

        if (!in_array($from->format('N'), $workingDays)) continue;
        if (in_array($from->format('Y-m-d'), $holidayDays)) continue;
        if (in_array($from->format('*-m-d'), $holidayDays)) continue;

        $dates[] = $from->format('Y-m-d');
        $days--;
    }
    return $dates;
}
print_r( number_of_working_dates('2013-12-23', 3) );
paulo commented on Oct 17, 2019

Hi, did you have a chance to take a look at this? How can I pass data from the report class file to the report view ? thank you

KoolReport commented on Oct 17, 2019

You can pass any parameters to report, please follow this topics. In the view of your report, you still can use $this->params["your-param-name"]

paulo commented on Oct 18, 2019

thank you. I have been using this for sending to the report. Now, how can I access this param from the view? Can I just use {{$this->params["year"]}}

(using Laravel) thank you!

KoolReport commented on Oct 19, 2019

Please do not confuse between view of KoolReport and the view of laravel. The view of KoolReport is the file with .view.php located near the report class. The parameter $this->params["year"] is used inside the view of KoolReport. For the view of Laravel, please refer to laravel documentation to know how to pass param to the view.

paulo commented on Oct 30, 2019

Hi, I'be tried all this. My controller sends an id to the extends \koolreport\KoolReport class, but HOW can I send information from the class to the view?

The following works fine. I get the id of the user.

 function setup()
    {
        $id = $this->params["userId"]; //Auth::user()->id;
.....
}

Now, under the view "staffTimeLogManager.view.php' How can I display this amount? I've tried the following, nothing works: Staff id= <?php $this->params['userId'] ?>

staff 2=<?php $this->userID  ?>

staff 3= {{ userID }}

Thank you very much

KoolReport commented on Oct 30, 2019

In the view you should do:

staff id = <?php echo $this->params["userId"];  ?>
paulo commented on Oct 31, 2019

PERFECT! thank you!

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