# degdigital/magento2-customreports

> A Magento 2 module that allows an administrator to create reports in the admin panel.  This is modeled after the Clean Reports module for Magento 1.

`composer require degdigital/magento2-customreports`

Canonical URL: https://packagento.com/degdigital/magento2-customreports

## At a glance

- **Vendor**: degdigital (https://packagento.com/degdigital.md)
- **Latest version**: 3.1.4 — released 2023-04-27
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/degdigital/magento2-customreports and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require degdigital/magento2-customreports:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

A Magento 2 module that allows an administrator to create reports in the admin panel.  This is modeled after the Clean Reports module for Magento 1.

## README

This module was inspired by the Magento 1 extension for custom reports (https://github.com/kalenjordan/custom-reports).
Thank you to Kalen Jordan and all who contributed to that project.

### Description

Easily create reports with custom SQL queries and display them using the Magento admin grid.

### Disclaimer
This module has the potential to make irreversible changes to your database if set up incorrectly.  Use at your own risk.

### Features
* Report result table
* Usage of a read-only database connection
* Column filtering
* Column sorting
* CSV, TSV, TXT (pipe-delimited), and Excel XML exports
* Automated exports

### Custom Reports

From the admin panel > Reports > Custom Reports > Custom Reports interface, reports can be created with arbitrary queries.

#### Performance

Report queries can be very slow, even enough to trigger an unavoidable gateway timeout (depending on architecture) or browser timeout and thus be unusable. This is exacerbated by (often unnecessary) queries to retrieve columns and queries to retrieve the total record count.

The query to retrieve columns now reuses the same query used to get the full result set (when filters and sorting are not applied). When filters/sorting are applied, the columns query must use its own query for the reasons outlined in `\DEG\CustomReports\Block\Adminhtml\Report\Grid::_prepareLayout`.

A flag on the custom reports called 'Allow Count Query' can be set to 'No', which will prevent the typical 'select count(*) from (original query)' query used to determine the total number of records and the total number of pages, because this data may be unnecessary on report grids for the following reasons:
* some reports may always return results far below the page size.
* some reports might only render useful data on the first page, so the total record count and the total page count are unnecessary.
* some report grids might only be used to gain access to the Export button, so all information on the grid is unnecessary.

In such cases, if the query is slow, this flag can be set to 'No' to improve the performance of the report query.

With no filters applied and 'Allow Count Query' set to 'No', the report query will only run once.

### Automated Exports

From the admin panel > Reports > Custom Reports > Automated Exports interface, jobs can be created to export one or more custom reports. Currently, two types of exports are supported:
1. Local file drops, in which a file is created on the server in which the Magento cron runs from in a configurable location, with var/export being the suggested location.
2. Remote file drops, in which a file is created the same as a local file drop and then uploaded to an SFTP server with the provided credentials.
3. Email, in which a file is sent as an attachment to the email recipient(s). If "Send as one combined email" is set to 'No' (the default), N*M emails will be sent with one attachment each, where N is the number of custom reports and M is the number of file types. If it is set to 'Yes', then only one email will be sent with N*M attachments.

If both types are selected, the system will run the query and generate the local file only once. This is useful for especially heavy queries.

A cron job will be created with the name "automated_export_<automated_export_id_here>". The configuration for the cron job resides in the core_config_data table with a path like `crontab/default/jobs/automated_export_<automated_export_id_here>`. E.g.:

```
crontab/default/jobs/automated_export_1/schedule/cron_expr = 0 0 0 0 0
crontab/default/jobs/automated_export_1/run/model = DEG\CustomReports\Model\AutomatedExport\Cron::execute
crontab/default/jobs/automated_export_1/name = automated_export_1
```

The popular third-party Magento tool, n98-magerun, can be used to run the automated exports manually from the command line using the above name, e.g. `n98-magerun sys:cron:run automated_export_1`.

## Recent Versions

| Version | Released |
|---|---|
| 3.1.4 | 2023-04-27 |
| 3.1.3 | 2023-03-03 |
| 3.1.2 | 2023-03-03 |
| 3.1.1 | 2023-03-03 |
| 3.1.0 | 2023-03-03 |
| 3.0.0 | 2023-02-13 |
| 2.0.6 | 2022-10-04 |
| 2.0.5 | 2022-09-15 |
| 2.0.4 | 2022-08-11 |
| 2.0.3 | 2022-02-09 |

Showing 10 of 21 versions. Full release history on https://packagento.com/degdigital/magento2-customreports.

## Quality

Latest release (3.1.4) fails the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | not tested | Pass | – | – |
| 2.4.8 | – | Pass | 1 | – |
| 2.4.9 | – | – | 1 | 1 |


### Code Quality

Advisory checks against the module's source. Never affect the Compatibility verdict — a phpcs finding can't make a module incompatible.

#### Static Analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Fail | 138 | 7 errors, 131 warnings (ruleset: Magento2) — 50 auto-fixable with phpcbf |
| PHPMD | Warning | 10 | 10 rule violations (IfStatementAssignment:7, MissingImport:1, CyclomaticComplexity:1, NPathComplexity:1) |
| Cpd | Warning | 12 | 12 duplicated chunks spanning 767 total lines (min-lines=5, min-tokens=70) |
| Composer validate | Pass | 0 |  |

#### PHPStan

Type-checks the module against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | 59 | 59 | – | – |
| 2.4.8 | – | 62 | 69 | – |
| 2.4.9 | – | – | 65 | 65 |


### Tests

Unit and integration suites run per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |

#### Integration Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Security

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["degdigital/magento2-customreports"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

degdigital is a Magento 2 vendor on Packagento. See https://packagento.com/degdigital.md for their full catalogue.

