Giter VIP home page Giter VIP logo

yii2-report's Introduction

Krajee Logo
yii2-report
Donate

Latest Stable Version Latest Unstable Version License Total Downloads Monthly Downloads Daily Downloads

A Yii2 component to generate beautiful formatted reports using Microsoft Word Document Templates in PDF/DOC/DOCX format. The component uses the PHP reports library API to generate reports. PHP-Reports is a cloud based, interactive report engine which helps in generating well formatted PDF reports from Word / DOCX templates.

How to contribute via a pull request?

Refer this git workflow for contributors.

Installation

The preferred way to install this extension is through composer.

Pre-requisites

Note: Check the composer.json for this extension's requirements and dependencies. You must set the minimum-stability to dev in the composer.json file in your application root folder before installation of this extension OR if your minimum-stability is set to any other value other than dev, then set the following in the require section of your composer.json file

kartik-v/yii2-report: "@dev"

Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

Install

Either run

$ php composer.phar require kartik-v/yii2-report "@dev"

or add

"kartik-v/yii2-report": "@dev"

to the require section of your composer.json file.

Usage

Step 1: Getting API Key

Create free account at https://www.php-reports.com and get your free API Key.

Step 2: Creating Your First Template

To accelerate the process of creating your reports and applications, PHP Reports takes advantage of Microsoft Word's design capabilites. Simply create a Microsoft Word file and design your report.

Step 3: Using Template Variables

You can use template variables in your Microsoft Word template. Template variables take their name from the contents of their double curly braces and they can later be replaced with a concrete value.

All template variable names within a template string must be unique. Template variable names are case-insensitive.

Word Template Screenshot

Step 4: Upload Your Template

Save and upload your template at "Template Manager" section in https://www.php-reports.com. Remember the template identifier (templateId).

Step 5: Setting up the yii2-report global component

Setup the following component in the components section of your Yii2 application configuration file.

use kartik\report\Report;

// ...
'components' => [
    // setup Krajee Yii2 Report component
    'report' => [
        'class' => Report::classname(),
        'apiKey' => 'YOUR_PHP_REPORTS_API_KEY',
        // the following variables can be set to globally default your settings
        'templateId' => 1, // optional: the numeric identifier for your default global template 
        'outputAction' => Report::ACTION_FORCE_DOWNLOAD, // or Report::ACTION_GET_DOWNLOAD_URL 
        'outputFileType' => Report::OUTPUT_PDF, // or Report::OUTPUT_DOCX
        'outputFileName' => 'KrajeeReport.pdf', // a default file name if 
        'defaultTemplateVariables' => [ // any default data you desire to always default
            'companyName' => 'Krajee.com'
        ]
    ]
]

Step 6: Generating the report from the component

use kartik\report\Report;

$report = Yii::$app->report;

// set your template identifier (override global defaults)
$report->templateId = 2;

// If you want to override the output file name, uncomment line below
// $report->outputFileName = 'My_Generated_Report.pdf';

// If you want to override the output file type, uncomment line below
// $report->outputFileType = Report::OUTPUT_DOCX;

// If you want to override the output file action, uncomment line below
// $report->outputFileAction = Report::ACTION_GET_DOWNLOAD_URL;

// Configure your report data. Each of the keys must match the template 
// variables set in your MS Word template and each value will be the
// evaluated to replace the Word template variable. If the value is an 
// array, it will treated as tabular data.
$report->templateVariables = [
    'client_name' => 'Murat Cileli', 
    'address' => 'Kadikoy, Istanbul / Turkey', 
    'date' => '10-Apr-2018', 
    'phone' => '+1-800-3399622', 
    'email' => '[email protected]', 
    'notes' => 'Thank you for your purchase.', 
    'quantities' => ['6', '3', '4'], 
    'products' => ['Apple iPhone 5S', 'Samsung Galaxy S5', 'Office 365 License'], 
    'prices' => ['490 USD', '399 USD', '199 USD'], 
];

// lastly in your controller action download the generated report
return $report->generateReport();

Step 7: Check your output report document

Your output should look something like below:

Output Document Screenshot

License

yii2-report is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.

yii2-report's People

Contributors

kartik-v avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yii2-report's Issues

The var of the template not working

Hi...
I already uploaded my word template to the cloud https://www.php-reports.com and configure the yii extension but when I try to make it work only a couple of vars works the others do not...

here is the code of my template.docx

Navn: {{participants}}
{{itinerary_day}} - {{product}}
{{itinerary_descript}}
Vår referanse: {{id}}

this is in my web config

'components' => [
 .....
      'report' => [
            'class' => Report::classname(),
            'apiKey' => 'my apikey',
            'templateId' => 1634,
            'outputAction' => Report::ACTION_FORCE_DOWNLOAD, 
            'outputFileType' => Report::OUTPUT_DOCX,
            'outputFileName' => 'Export.docx',
            'defaultTemplateVariables' => [ 
                'companyName' => 'NORWEGIAN ADVENTURES',
            ]
        ],
........
]

and this is the action function

public function actionExportInfo($idItinerary, $idProduct)
    {
        $report = Yii::$app->report;
        $report->templateId = 1634;
        $ItineraryProduct = ItineraryProduct::findOne(['idItinerary' => $idItinerary, 'idProduct' => $idProduct]);
        $p = '';
        foreach ($ItineraryProduct->participants as $t) :
            $p .= $t->firstName . ' ' . $t->lastName . ', ';
        endforeach;
        $report->templateVariables = [
            'participants' => trim($p, ', '),
            'itinerary_day' => date('l jS F Y', strtotime($ItineraryProduct->itinerary->project->dateStart . ' +' . $ItineraryProduct->itinerary->day . ' day')),
            'product' => $ItineraryProduct->product->productName,
            'itinerary_descipt' => $ItineraryProduct->itinerary->description,
            'id' => $idItinerary,
        ];
        return $report->generateReport();
    }

the vars in the work just fine because a make a print_r($report->templateVariables) and got this

Array
(
    [participants] => raciel brito,  ascac
    [itinerary_day] => Tuesday 2nd April 2019
    [product] => bbbb
    [itinerary_descipt] => 44444
    [id] => 138
)

and this is what i got from the word exported

Navn: participants
Tuesday 2nd April 2019 - product
itinerary_descript
Vår referanse: id

How you can see only one var take the value expected...
So i'm not realy shure what i'm doing wrong
Need some hepl because i think this is an extension issue...
thanks

template offline

hello guys

it is possible to use a template from file system ?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.