agoalofalife/reports

UI for created and download reports in Laravel

v0.3.0 2019-04-11 07:26 UTC

This package is auto-updated.

Last update: 2024-04-29 03:32:46 UTC


README

68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f61676f616c6f66616c6966652f7265706f7274732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572 68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f61676f616c6f66616c6966652f7265706f7274732f6261646765732f636f7665726167652e706e673f623d6d6173746572 68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f61676f616c6f66616c6966652f7265706f7274732f6261646765732f6275696c642e706e673f623d6d6173746572

base.jpg

Requirements : PHP verison >= 7.1.0 Laravel version >= 5.5

not support Laravel version 5.8 & >

What is it?

This is package offers ready UI and some code, for reports.

Reports will be with extensions: pdf, xlxs, xls, csv .

In the paradigm Laravel, we make reprots and write code. It's just!

Install

composer require agoalofalife/reports
php artisan reports:install

Locale

In file config/app.php select your language.

The package provides two languages:

  • ru
  • en

Blade and UI

In your template, you need to paste the code

  <body>
    @include('reports::app')
    ...

Cron

You have to add cron, how separete process.

// App\Console\Kernel
use agoalofalife\Reports\Console\ParseReportsCommand;

  $schedule->command(ParseReportsCommand::class)->everyMinute();

The development process

You create new file report:

php artisan make:report NameReport

Insert in config config/reports.php :

  'reports' => [
          \App\Reports\TestReport::class
    ],

Fill the class:

<?php
declare(strict_types=1);
namespace App\Reports;

use agoalofalife\Reports\Contracts\HandlerReport;
use agoalofalife\Reports\Report;

class TestReport extends Report implements HandlerReport
{
    /**
     * Disk for filesystem
     * @var string
     */
    public $disk = 'public';

  /**
     * Format export : xls, xlsx, pdf, csv
     * @var string
     */
    public $extension = 'xlsx';

     /**
     * Get file name
     * @return string
     */
    public function getFilename() : string
    {
        return 'TestReport';
    }

    /**
     * Get title report
     * @return string
     */
    public function getTitle() : string
    {
        return 'Test';
    }

    /**
     * Get description report
     * @return string
     */
    public function getDescription() : string
    {
        return 'Description test report';
    }

    /**
     * @param $excel
     * @return bool
     */
    public function handler($excel) : bool
    {
      $excel->sheet('Sheetname', function ($sheet) {
            $sheet->rows(array(
                array('test1', 'test2'),
                array('test3', 'test4')
            ));
        });
      return true;
    }
}

Property $disk, name disk in filesystem.

Property $extension, type extension your file.

Method getFilename accordingly return name file.

Method getTitle return name title in UI.

Method getDescription return description in UI.

Method handler is base method. Package use external package.

Method is a small wrapper.

Notification

Once the report is ready, you can send notification.

For this you need to implement interface agoalofalife\Reports\Contracts\NotificationReport.

Method getNotifiable return notifiable, which has a method routeNotificationFor.

And method getNotification, return Notification type.

    // implements agoalofalife\Reports\Contracts\NotificationReport
    public function getNotifiable()
    {
        return User::where('email', 'test@gmail.com')->get()->first();
    }

    public function getNotification(): Notification
    {
        return new InvoicePaid();
    }
// app/User.php

    public function routeNotificationForSlack($notification)
    {
        return 'hook';
    }