Skip to content

Commit

Permalink
fix: improve report assigned in year
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusantguerrero committed Aug 2, 2024
1 parent 81260ab commit 15cbcc9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/Domains/Transaction/Services/ReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public static function generateExpensesByPeriodInDate($teamId, $startDate, $endD
}, $resultGroup)->sortBy('date');
}

public static function getAssignedByPeriod($teamId, $startDate, $timeUnitDiff = 2, $timeUnit = 'month', $categories = null)
public static function getAssignedByPeriod($teamId, $startDate, $endDate, $categories = null)
{
$rangeEndAt = Carbon::createFromFormat('Y-m-d', $startDate)->endOfMonth()->format('Y-m-d');
$rangeStartAt = Carbon::now()->subMonth($timeUnitDiff)->startOfMonth()->format('Y-m-d');
$rangeStartAt = Carbon::createFromFormat('Y-m-d', $startDate)->startOfMonth()->format('Y-m-d');
$rangeEndAt = Carbon::createFromFormat('Y-m-d', $endDate)->endOfMonth()->format('Y-m-d');

$results = self::getAssignedByCategoriesInPeriod($teamId, $rangeStartAt, $rangeEndAt, $categories);
$resultGroup = $results->groupBy('date');
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/Finance/FinanceTrendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,19 @@ public function assignedInYear()
$excludedAccounts = collect(explode(',', $filters['category']))->map(fn ($id) => "-$id")->all();
}

$endDate = Carbon::createFromFormat('Y-m-d', $startDate)->endOfYear()->format('Y-m-d');
$startDate = Carbon::createFromFormat('Y-m-d', $startDate)->startOfYear()->format('Y-m-d');

$assignedInYear = ReportService::getAssignedByPeriod($teamId, $startDate, $endDate, $excludedAccounts);

return [
'data' => ReportService::getAssignedByPeriod($teamId, $startDate, 12, 'month', $excludedAccounts),
'data' => $assignedInYear,
'metaData' => [
'name' => 'assignedYear',
'title' => 'Assigned in year',
'props' => [
'headerTemplate' => 'grid',
'total' => $assignedInYear->sum('total'),
],
],
];
Expand Down
8 changes: 4 additions & 4 deletions resources/js/Pages/Trends/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const components = {
incomeExpenses: IncomeExpenses,
incomeExpensesGraph: ChartNetWorth,
spendingYear: WidgetYearSpending,
assignedYear: ChartComparison,
assignedYear: WidgetYearSpending,
}
const trendComponent = computed(() => {
Expand All @@ -76,8 +76,8 @@ const isCategoryTrend = computed(() => {
})
const isYearSpending = computed(() => {
return ['spendingYear'].includes(props.metaData.name)
const isYearReport = computed(() => {
return ['spendingYear', 'assignedYear'].includes(props.metaData.name)
})
const cashflowEntities = {
Expand Down Expand Up @@ -121,7 +121,7 @@ const isFilterSelected = (filterValue: string) => {
<TrendTemplate title="Finance" ref="financeTemplateRef" :hide-panel="!isCategoryTrend">
<component
class="mt-5"
v-if="isYearSpending"
v-if="isYearReport"
:is="trendComponent"
style="background: white; width: 100%"
:type="section"
Expand Down

0 comments on commit 15cbcc9

Please sign in to comment.