2017 © Pedro Peláez
 

yii2-extension yii2-report

A Yii2 component to generate beautiful formatted reports using MS Word Templates in PDF/DOC/DOCX format

image

kartik-v/yii2-report

A Yii2 component to generate beautiful formatted reports using MS Word Templates in PDF/DOC/DOCX format

  • Monday, June 25, 2018
  • by kartik-v
  • Repository
  • 1 Watchers
  • 5 Stars
  • 58 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 1 Versions
  • 152 % Grown

The README.md

Krajee Logo
yii2-report
Donate

Latest Stable Version Latest Unstable Version License Total Downloads Monthly Downloads Daily Downloads, (*1)

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., (*2)

How to contribute via a pull request?

Refer this git workflow for contributors., (*3)

Installation

The preferred way to install this extension is through composer., (*4)

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, (*5)

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

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

Install

Either run, (*7)

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

or add, (*8)

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

to the require section of your composer.json file., (*9)

Usage

Step 1: Getting API Key

Create free account at https://www.php-reports.com and get your free API Key., (*10)

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., (*11)

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., (*12)

All template variable names within a template string must be unique. Template variable names are case-insensitive., (*13)

Word Template Screenshot, (*14)

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)., (*15)

Step 5: Setting up the yii2-report global component

Setup the following component in the components section of your Yii2 application configuration file., (*16)

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' => 'admin@gmail.com', 
    '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:, (*17)

Output Document Screenshot, (*18)

License

yii2-report is released under the BSD-3-Clause License. See the bundled LICENSE.md for details., (*19)

The Versions

25/06 2018

dev-master

9999999-dev https://github.com/kartik-v/yii2-report

A Yii2 component to generate beautiful formatted reports using MS Word Templates in PDF/DOC/DOCX format

  Sources   Download

BSD-3-Clause

template extension yii2 pdf report doc docx