mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
🤖 Auto commit for release 'develop' on 2025-09-29
This commit is contained in:
@@ -30,6 +30,7 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Override;
|
||||
|
||||
class PeriodStatisticRepository implements PeriodStatisticRepositoryInterface, UserGroupInterface
|
||||
{
|
||||
@@ -38,24 +39,26 @@ class PeriodStatisticRepository implements PeriodStatisticRepositoryInterface, U
|
||||
public function findPeriodStatistics(Model $model, Carbon $start, Carbon $end, array $types): Collection
|
||||
{
|
||||
return $model->primaryPeriodStatistics()
|
||||
->where('start', $start)
|
||||
->where('end', $end)
|
||||
->whereIn('type', $types)
|
||||
->get();
|
||||
->where('start', $start)
|
||||
->where('end', $end)
|
||||
->whereIn('type', $types)
|
||||
->get()
|
||||
;
|
||||
}
|
||||
|
||||
public function findPeriodStatistic(Model $model, Carbon $start, Carbon $end, string $type): Collection
|
||||
{
|
||||
return $model->primaryPeriodStatistics()
|
||||
->where('start', $start)
|
||||
->where('end', $end)
|
||||
->where('type', $type)
|
||||
->get();
|
||||
->where('start', $start)
|
||||
->where('end', $end)
|
||||
->where('type', $type)
|
||||
->get()
|
||||
;
|
||||
}
|
||||
|
||||
public function saveStatistic(Model $model, int $currencyId, Carbon $start, Carbon $end, string $type, int $count, string $amount): PeriodStatistic
|
||||
{
|
||||
$stat = new PeriodStatistic();
|
||||
$stat = new PeriodStatistic();
|
||||
$stat->primaryStatable()->associate($model);
|
||||
$stat->transaction_currency_id = $currencyId;
|
||||
$stat->user_group_id = $this->getUserGroup()->id;
|
||||
@@ -69,16 +72,16 @@ class PeriodStatisticRepository implements PeriodStatisticRepositoryInterface, U
|
||||
$stat->save();
|
||||
|
||||
Log::debug(sprintf(
|
||||
'Saved #%d [currency #%d, Model %s #%d, %s to %s, %d, %s] as new statistic.',
|
||||
$stat->id,
|
||||
$model::class,
|
||||
$model->id,
|
||||
$stat->transaction_currency_id,
|
||||
$stat->start->toW3cString(),
|
||||
$stat->end->toW3cString(),
|
||||
$count,
|
||||
$amount
|
||||
));
|
||||
'Saved #%d [currency #%d, Model %s #%d, %s to %s, %d, %s] as new statistic.',
|
||||
$stat->id,
|
||||
$model::class,
|
||||
$model->id,
|
||||
$stat->transaction_currency_id,
|
||||
$stat->start->toW3cString(),
|
||||
$stat->end->toW3cString(),
|
||||
$count,
|
||||
$amount
|
||||
));
|
||||
|
||||
return $stat;
|
||||
}
|
||||
@@ -93,18 +96,19 @@ class PeriodStatisticRepository implements PeriodStatisticRepositoryInterface, U
|
||||
$model->primaryPeriodStatistics()->where('start', '<=', $date)->where('end', '>=', $date)->delete();
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
#[Override]
|
||||
public function allInRangeForPrefix(string $prefix, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
return $this->userGroup->periodStatistics()
|
||||
->where('type', 'LIKE', sprintf('%s%%', $prefix))
|
||||
->where('start', '>=', $start)->where('end', '<=', $end)->get();
|
||||
->where('type', 'LIKE', sprintf('%s%%', $prefix))
|
||||
->where('start', '>=', $start)->where('end', '<=', $end)->get()
|
||||
;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
#[Override]
|
||||
public function savePrefixedStatistic(string $prefix, int $currencyId, Carbon $start, Carbon $end, string $type, int $count, string $amount): PeriodStatistic
|
||||
{
|
||||
$stat = new PeriodStatistic();
|
||||
$stat = new PeriodStatistic();
|
||||
$stat->transaction_currency_id = $currencyId;
|
||||
$stat->user_group_id = $this->getUserGroup()->id;
|
||||
$stat->start = $start;
|
||||
@@ -113,19 +117,19 @@ class PeriodStatisticRepository implements PeriodStatisticRepositoryInterface, U
|
||||
$stat->end_tz = $end->format('e');
|
||||
$stat->amount = $amount;
|
||||
$stat->count = $count;
|
||||
$stat->type = sprintf('%s_%s',$prefix, $type);
|
||||
$stat->type = sprintf('%s_%s', $prefix, $type);
|
||||
$stat->save();
|
||||
|
||||
Log::debug(sprintf(
|
||||
'Saved #%d [currency #%d, type "%s", %s to %s, %d, %s] as new statistic.',
|
||||
$stat->id,
|
||||
$stat->transaction_currency_id,
|
||||
$stat->type,
|
||||
$stat->start->toW3cString(),
|
||||
$stat->end->toW3cString(),
|
||||
$count,
|
||||
$amount
|
||||
));
|
||||
'Saved #%d [currency #%d, type "%s", %s to %s, %d, %s] as new statistic.',
|
||||
$stat->id,
|
||||
$stat->transaction_currency_id,
|
||||
$stat->type,
|
||||
$stat->start->toW3cString(),
|
||||
$stat->end->toW3cString(),
|
||||
$count,
|
||||
$amount
|
||||
));
|
||||
|
||||
return $stat;
|
||||
}
|
||||
|
@@ -35,9 +35,11 @@ interface PeriodStatisticRepositoryInterface
|
||||
public function findPeriodStatistic(Model $model, Carbon $start, Carbon $end, string $type): Collection;
|
||||
|
||||
public function saveStatistic(Model $model, int $currencyId, Carbon $start, Carbon $end, string $type, int $count, string $amount): PeriodStatistic;
|
||||
|
||||
public function savePrefixedStatistic(string $prefix, int $currencyId, Carbon $start, Carbon $end, string $type, int $count, string $amount): PeriodStatistic;
|
||||
|
||||
public function allInRangeForModel(Model $model, Carbon $start, Carbon $end): Collection;
|
||||
|
||||
public function allInRangeForPrefix(string $prefix, Carbon $start, Carbon $end): Collection;
|
||||
|
||||
public function deleteStatisticsForModel(Model $model, Carbon $date): void;
|
||||
|
Reference in New Issue
Block a user