Giter Club home page Giter Club logo

report's Introduction

Agile Data - Reportig Add-on

This extension for Agile Data implements advanced reporting capabilities:

  • Aggregate models. Provite grouping of existing model.
  • Union models. Combine one or multiple models.

Installation and Usage

This repository is now public and available under MIT license, so to install:

composer require atk4/report

You may need to adjust your minimum-stability setting.

UnionModel

Create a new model that combines data from scopes of several nested models. Will help you map fields properly so that resulting model have the columns you want. In next example you would need to define Purchase and Sale models yourself. See https://github.com/atk4/data):

$m = new \atk4\report\UnionModel($db);
$m->addNestedModel(new Purchase(), [
    'ref_no'        => '[ref_no]',          // mapping fields is optional
    'date'          => '[purchase_date]',   // you can alias like this
    'contact'       => 'concat("From: ", [contractor_from])',
]);                                         // use expressions
$m->addNestedModel(new Sale(), [
    'date'          => '[sale_date]',       // this way we have one column for dates
    'contact'       => 'concat("To: ", [contractor_to])',
]);
$m->setOrder(['date']);                     // sorts resulting union model

$m->addField('date', ['caption' => 'Date', 'type' => 'date']);
     // now add union-based models here.

$m->addField('contact', ['caption' => 'Supplier/Payee']);
$m->addField('ref_no', ['caption' => 'Document No']);
$m->addField('amount', ['caption' => 'Net Amount', 'type' => 'money']);
     // if association in nested model is not explicitly defined, will
     // use field. If no field is found, will use expression: "null"

$m->join('country', 'country_id')
    ->addField('country', 'name');
     // Union Model extends \atk4\data\Model so you can use addField and addExpression


// $m->groupBy('country', ['amount'=>'sum([]')])
// groupBy works like in GroupModel, next example for usage.

$table->setModel($m);

GroupModel

Creates a new model containing aggregate data from your existing model. Note that you can combine UnionModel and GroupModel recursively.

$m = new \smbo\GroupModel(new Sale($db));
$m->groupBy(['contractor_to', 'type'], [      // groups by 2 columns
    'c'                     => 'count(*)',    // defines aggregate formulas for fields
    'qty'                   => 'sum([])',     // [] refers back to qty
    'total'                 => 'sum([amount])', // can specify any field here
]);

$m->addFields(['vat_registered', ['vat_no', 'caption' => 'VAT No']]);
    // add 2 more fields which will bypass aggregation.

$m->getElement('total')->type = 'money';
    // change the type

Documentation

https://github.com/atk4/report/blob/develop/docs/index.md

Current Status

Implementation is complete, but a better documentation and more examples needed. Also some cleanups in the code are welcome!

License: MIT

report's People

Contributors

romaninsh avatar darkside666 avatar alexlvcom avatar

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.