{success.fa-video} If you are a visual learner, please watch this video instead.
hisabi comes with many built-in reports(metrics) to generate useful financial data and understand the distribution and trends of expenses vs income.
Any report must be registered in the config file config/hisabi.php
under reports
.
return [
...
'reports' => [
new TotalIncome,
new TotalExpenses,
new IncomePerCategory,
new ExpensesPerCategory,
new TotalIncomeTrend,
new TotalExpensesTrend,
new TotalPerCategoryTrend,
new TotalPerBrandTrend,
new TotalPerBrand,
],
]
A report simply is a GraphQL query represented as a PHP class. you can find all the reports under namespace App\GraphQL\Queries
.
Total Income
Total Expenses
Income Per Category
Expenses Per Category
Total Income Trend
Total Expenses Trend
Total Per Category Trend
Total Per Brand Trend
Total Per Brand
To write a custom report, you need to create a class that extends one of the available metrics (you can build a new metric type too):
ValueMetric
: displays a single value and, if desired, its change compared to a previous time interval.PartitionMetric
: displays a pie chart of values. For example, a partition metric might display the total amount for each expenses category.TrendMetric
: displays values over time via a line chart<?php
namespace App\GraphQL\Queries;
use App\Models\Transaction;
use App\Domain\Metrics\ValueMetric;
class TotalIncome extends ValueMetric // <-- Required
{
public function __invoke($_, array $args) // <-- Executed by GraphQL query
{
$rangeData = app('findRangeByKey', ["key" => $args['range']]);
$query = Transaction::query()->income();
if($rangeData) {
$query->whereBetween('created_at', [$rangeData->start(), $rangeData->end()]);
}
return ['value' => $query->sum('amount')];
}
}
Once you created the report, add the reference to it in the config file:
// config/hisabi.php
return [
...
'reports' => [
new TotalIncome,
...
],
]
Finally, register the GraphQL query in the graphql/schema.graphql
:
{info} Note the name of the query is the same as the class name written in camelCase.
type Query {
..
totalExpenses(range: String!): Json
..
}