Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Land major header/indent rst to md changes #1109

Merged
merged 6 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
881 changes: 470 additions & 411 deletions docs/advanced.md

Large diffs are not rendered by default.

64 changes: 33 additions & 31 deletions docs/aggregates.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@

.. _Aggregates:

================
Model Aggregates
================
# Model Aggregates

.. php:namespace:: Atk4\Data\Model

.. php:class:: AggregateModel

In order to create model aggregates the AggregateModel model needs to be used:

Grouping
--------
### Grouping

AggregateModel model can be used for grouping::
AggregateModel model can be used for grouping:

$aggregate = new AggregateModel($orders)->setGroupBy(['country_id']);
```
$aggregate = new AggregateModel($orders)->setGroupBy(['country_id']);
```

`$aggregate` above is a new object that is most appropriate for the model's persistence and which can be manipulated
in various ways to fine-tune aggregation. Below is one sample use::

$aggregate = new AggregateModel($orders);
$aggregate->addField('country');
$aggregate->setGroupBy(['country_id'], [
'count' => ['expr' => 'count(*)', 'type' => 'integer'],
'total_amount' => ['expr' => 'sum([amount])', 'type' => 'atk4_money'],
],
);

// $aggregate will have following rows:
// ['country' => 'UK', 'count' => 20, 'total_amount' => 123.2];
// ..

Below is how opening balance can be built::

$ledger = new GeneralLedger($db);
$ledger->addCondition('date', '<', $from);

// we actually need grouping by nominal
$ledger->setGroupBy(['nominal_id'], [
'opening_balance' => ['expr' => 'sum([amount])', 'type' => 'atk4_money'],
]);
in various ways to fine-tune aggregation. Below is one sample use:

```
$aggregate = new AggregateModel($orders);
$aggregate->addField('country');
$aggregate->setGroupBy(['country_id'], [
'count' => ['expr' => 'count(*)', 'type' => 'integer'],
'total_amount' => ['expr' => 'sum([amount])', 'type' => 'atk4_money'],
],
);

// $aggregate will have following rows:
// ['country' => 'UK', 'count' => 20, 'total_amount' => 123.2];
// ..
```

Below is how opening balance can be built:

```
$ledger = new GeneralLedger($db);
$ledger->addCondition('date', '<', $from);

// we actually need grouping by nominal
$ledger->setGroupBy(['nominal_id'], [
'opening_balance' => ['expr' => 'sum([amount])', 'type' => 'atk4_money'],
]);
```

Loading