KoolReport's Forum

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

Multiple reports into a "book" #1514

Open Richb201 opened this topic on on Jul 6, 2020 - 12 comments

Richb201 commented on Jul 6, 2020

I need to generate multiple "reports" and output them all into a single pdf file. There will be approx 12 of these reports and they will get their data from numerous tables. I will also need a table of contents. Is there any suggestion on how to create a "book" (term from jaspereports)? Some will include images (jpg).

Richb201 commented on Jul 6, 2020

I also need to "build" this thing to a blank window, not the window with my menu's on it. I'd like to put a header at the top each "page" and a footer at the bottom of each. I am worried that if i use export to a pdf that the menus will show. Can you give me some guidance?

David Winterburn commented on Jul 7, 2020

Hi,

The pdf export function can use a separate view file from the web one, for example: MyReportPDF.view.php vs MyReport.view.php. Thus you won't need to worry about the menu on the pdf, just don't include your menu in the pdf view file.

We have two pdf export solution, the Export and CloudExport packages, both of which support header, footer and page break. And our export function allows users to either download the pdf file or show it on browser:

$report->run()->export("MyReportPDF")
->pdf($pdfOption)
->toBrowser("MyReport.pdf", $openOnBrowser); //set $openOnBrowser=true or false 

To open the pdf file on a new blank window you could use either a target="_blank" link or an iframe.

Let us know if you have any question. Thanks!

David Winterburn commented on Jul 7, 2020

Regarding the number of pages in your pdf file, you asked whether to use multiple reports or one big report to render.

Even though a single big report could have better performance (not much) than multiple small reports, I would suggest using multiple small reports to render each parts of your pdf. I will keep your code clearly separated and much better for maintenance.

Richb201 commented on Jul 7, 2020

I see that CloudExport uses another site to render the PDF. In my case the information in each report is confidential and I'd prefer to keep it all on my server. So Export might work better for me, all other things being equal. Here is an example of my first report. I hope to clean it up and add some charts to it (once I bring in some "joined data"). Having the black banner would be fine since you are saying that it won't be rendered on the "pdf version". What I am concerned about is that if I have 18 different small reports, I'll have to keep them all (ie in S3) and offer the user a separate way to download them all at once. This is why making one big report would make the dowloading of the pdf much easier for me. I am guessing I could append reports by running $report->run()->export("MyReport1") and then $report->run()->export("MyReportPDF2") and then $report->run()->export("MyReportPDF3"), etc?

Richb201 commented on Jul 7, 2020

Thanks David. As you can see from the attached image I have 4 Business Components listed, iPod, MAC, IOS and Goldmine. These all appear in the Business Component "report". Now for each one of these want to generate

iPod description, names of employees who worked on it, bar chart showing how many $ each employee's work represents

MAC description, names of employees who worked on it, bar chart showing how many $ each employee's work represents

IOS description, names of employees who worked on it, bar chart showing how many $ each employee's work represents

David, as you can see, each "subreport" is the same except for the data. Is there a way to create a "subreport" template within koolreport? Can I directly access the data that is in the pipe?

Richb201 commented on Jul 7, 2020

One more quick question for you. I have a "report cover" and some boilerplate text that I need to include at the start of the report. How do you recommend that I do that with Koolreport? Should I create an image that includes the text and then just have it appear using <body>

<img src="<?php echo base_url();  ?>/business_image/your_image.jpg" />

</body>

or is there a more "cultured" way to do this? In your example you have hard coded the location of the image. In my situation I have the location of the image in a mySQL column.

David Winterburn commented on Jul 8, 2020

Hi Richard,

If you have multiple views with the same structure, only different data it's a good idea to separate the structure into a separated template file. Then in each view set the your data to the same variable name, then include the template. For a simple example:

//viewTemplate.php
<div>
    <h1><?php echo $viewTitle; ?></h1>
    <div>
        <?php print_r($viewData); ?>
    </div>
</div>

//view1.php
$viewTitle = "My view 1";
$viewData = $this->dataStore("users"); //$this refers to this report
include "viewTemplate.php";

//view2.php
$viewTitle = "My view 2";
$viewData = $this->dataStore("customers"); //$this refers to this report
include "viewTemplate.php";

Regarding your quick question, if your image location is in database just retrieve the location data and put it to the src property of the img tag and put it at the beginning of your report view (or pdf view). Again, if you intend to use the boilerplate text in multiple views, it's advisable to separate it into a separated file and include the boilerplate file in each view.

Let us know if we misunderstood your questions. Thanks!

Richb201 commented on Jul 8, 2020

Thanks David. Sorry I am so easily confused! I have three files that deal with koolreport. First I have a function in the controller that calls it:

public function report_generator2()
{
    $report= new MyReport;
    $report->run()->render();
}

Then I have two files in the assets directory, MyReport.php and MyReport.view.php. MyReport has: 2 functions, settings and setup. Here is setup:

function setup()
{
    $this->src('substantiator')
       ->query("SELECT bus_comp FROM business_components WHERE campaign='Apple' AND email='richb201@gmail.com'")

->pipe(new ColumnRename(array(

        "bus_comp"=>"Business Component")))
        ->pipe($this->dataStore("business_components"));
}

MyReport.view.php has lots of HTML, but the important thing (from the Koolreport perspective) is <?php Table::create(array(

"dataStore"=>$this->dataStore("business_components"),
"class"=>array(
    "table"=>"table table-hover"
)

));

This part appears in the Business Components part of the report. I also have other "sections" such as the Employees section and the Cost Centers section. Each of these sections will have different reports based on different tables and will have different graphs.

So how I read your response above, in the MyReport.view.php I will have <h2>Business Components</h2> <?php Table::create(array(

"BusinessComponents"=>$this->dataStore("business_components"),
"class"=>array(
    "table"=>"table table-hover"
)

)); <h2>Employees</h2> <?php Table::create(array(

"Employees"=>$this->dataStore("employees"),
"class"=>array(
    "table"=>"table table-hover"
)

));

How should I modify the MyReport.php to have a different Query and pipe? Right now they are ONLY for business components. Do I just need to change the "DataStore" string to "BusinessComponentsStore" and create another one in MyReport.php that has ->pipe($this->dataStore("BusinessComponentsStore")); ?

There seems to be two moving parts here, MyReport.php and MyReport.view.php and I am not sure how they interact.

David Winterburn commented on Jul 10, 2020

Hi Richard,

In a report's setup, you could start multipe "src" and pipe to multiple datastores as well. For example:

$this->src('substantiator')
       ->query("SELECT bus_comp FROM business_components WHERE campaign='Apple' AND email='richb201@gmail.com'")
->pipe(new ColumnRename(array(

        "bus_comp"=>"Business Component")))
        ->pipe($this->dataStore("business_components"));

$this->src($otherDataSrc)
       ->query($otherQuery)
        ...
        ->pipe($this->dataStore($otherDataStore));

Then in your report view, you could create multiple widgets using these datastores.

Richb201 commented on Jul 10, 2020

Ok, so before I redo my report to meet your suggestion, I can open 20 different data sources and each with its own data store? Memory issue? Now some of these need to be joined. Can they only be joined on "indexed" fields?

David Winterburn commented on Jul 13, 2020

Regarding join, you could join data either in your sql queries or by koolreport's datastore join:

https://www.koolreport.com/examples/reports/datastores/join/

I would suggest trying join in sql first, which is really optimized in databases. If there're some reasons you can't join by sql then try the latter option.

Richb201 commented on Jul 14, 2020

Thanks. I will get into the details of the data once I can get koolreport working in a reasonable fashion. This is the error I see in the console: Uncaught ReferenceError: KoolReport is not defined

at report_generator2:32

KoolReport.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)

which is followed by: GET http://localhost/index.php/Configure/assets/4078463670/KoolReport.js net::ERR_ABORTED 404 (Not Found)

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

None