atk4 / report
此软件包已被废弃,不再维护。未建议替代软件包。
敏捷数据 - 报告扩展
1.0.4
2020-10-16 12:39 UTC
Requires
- php: >=7.3.0
- atk4/data: ~2.2.0
Requires (Dev)
- atk4/schema: ~2.2.0
- friendsofphp/php-cs-fixer: ^2.16
- phpunit/phpcov: *
- phpunit/phpunit: >=9.0
This package is not auto-updated.
Last update: 2022-04-27 10:09:19 UTC
README
敏捷数据 - 报告插件
此插件为敏捷数据实现了高级报告功能
- 聚合模型。提供现有模型的分组。
- 并集模型。合并一个或多个模型。
重要 - 从版本2.3.0开始,此仓库已停止维护,聚合和并集模型的功能将移至https://github.com/atk4/data
安装和用法
此仓库现在是公共的,并受MIT许可证的保护,因此要安装
composer require atk4/report
您可能需要调整您的minimum-stability
设置。
UnionModel
创建一个新的模型,它结合了几个嵌套模型的作用域中的数据。这将帮助您正确地映射字段,以便结果模型具有您想要的列。在下一个示例中,您需要自己定义采购和销售模型。请参阅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
创建一个包含您现有模型聚合数据的新的模型。请注意,您可以递归地组合UnionModel和GroupModel。
$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
文档
https://github.com/atk4/report/blob/develop/docs/index.md
当前状态
实现已完成,但需要更好的文档和更多示例。还欢迎对代码进行一些清理!