Skip to content

Commit

Permalink
fix: improve loger transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusantguerrero committed Oct 28, 2023
1 parent 080ecaf commit c113ce9
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace App\Domains\LogerProfile\Http\Controllers;

use App\Domains\LogerProfile\Data\LogerProfileData;
use App\Domains\LogerProfile\Services\LogerProfileService;
use App\Models\Setting;
use App\Http\Controllers\Controller;
use App\Domains\LogerProfile\Data\LogerProfileData;
use App\Http\Controllers\Traits\HasEnrichedRequest;
use App\Domains\LogerProfile\Services\LogerProfileService;

class LogerProfileController extends Controller
{
Expand All @@ -28,7 +29,6 @@ public function store(LogerProfileService $profileService)

public function show(LogerProfileService $profileService, int $profileId)
{

return inertia('LogerProfile/ProfileView', [
'profiles' => $profileService->list(auth()->user()->current_team_id),
'profile' => $profileService->getById($profileId),
Expand All @@ -37,4 +37,14 @@ public function show(LogerProfileService $profileService, int $profileId)
},
]);
}

public function transactions(int $profileId, LogerProfileService $profileService)
{
$queryParams = request()->query();

$filters = isset($queryParams['filter']) ? $queryParams['filter'] : [];
[$startDate, $endDate] = $this->getFilterDates($filters);

return $profileService->getTransactionsByProfileId($profileId, $startDate, $endDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Domains\LogerProfile\Http\Controllers;

use App\Domains\LogerProfile\Data\ProfileEntityData;
use App\Domains\LogerProfile\Services\LogerProfileService;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\HasEnrichedRequest;
use App\Domains\LogerProfile\Data\ProfileEntityData;
use App\Domains\LogerProfile\Services\LogerProfileService;

class LogerProfileEntityController extends Controller
{
Expand Down
29 changes: 28 additions & 1 deletion app/Domains/LogerProfile/Services/LogerProfileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace App\Domains\LogerProfile\Services;

use App\Domains\AppCore\Models\Category;
use App\Domains\LogerProfile\Models\LogerProfile;
use App\Domains\LogerProfile\Data\LogerProfileData;
use App\Domains\Transaction\Models\TransactionLine;
use App\Domains\LogerProfile\Data\ProfileEntityData;
use App\Domains\LogerProfile\Models\LogerProfile;
use App\Domains\LogerProfile\Models\LogerProfileEntity;
use App\Domains\Transaction\Services\TransactionService;

class LogerProfileService
{
Expand Down Expand Up @@ -40,4 +43,28 @@ public function getEntitiesByProfileId(int $profileId)
'profile_id' => $profileId,
])->get());
}

public function getTransactionsByProfileId(int $profileId, $startDate, $endDate)
{
$entities = LogerProfileEntity::where([
'profile_id' => $profileId,
'entity_type' => Category::class
])->get();

$categories = $entities->map(fn ($entity) => $entity->entity->id)->all();

$teamId = $entities[0]->team_id;

$transactions = TransactionLine::byTeam($teamId)
->inDateFrame($startDate, $endDate)
->expenseCategories($categories)
->verified()
->orderByDesc('transactions.date')
->get();

return [
"data" => $transactions,
"total" => $transactions->sum('total'),
];
}
}
3 changes: 2 additions & 1 deletion app/Domains/LogerProfile/routes.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

use Illuminate\Support\Facades\Route;
use App\Domains\LogerProfile\Http\Controllers\LogerProfileController;
use App\Domains\LogerProfile\Http\Controllers\LogerProfileEntityController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth:sanctum', 'atmosphere.teamed', 'verified'])->group(function () {
// Route::resource('/loger-profiles', [LogerProfileController::class, 'index'])->name('profiles.index');
Route::resource('/loger-profiles', LogerProfileController::class);
Route::resource('/loger-profiles/{profileId}/entities', LogerProfileEntityController::class);
Route::get('/loger-profiles/{profileId}/transactions', [LogerProfileController::class, 'transactions']);
});
5 changes: 4 additions & 1 deletion resources/js/Components/molecules/SectionNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { NDropdown } from 'naive-ui';
interface NavSection {
url?: string;
action?: string;
value: string;
label: string;
}
Expand All @@ -17,7 +18,7 @@ const props = defineProps<{
modelValue?: string;
}>();
const emit = defineEmits(['update:modelValue']);
const emit = defineEmits(['update:modelValue', 'action']);
const currentPath = computed(() => {
return document?.location?.pathname
Expand All @@ -32,6 +33,8 @@ const isSelected = (section: NavSection) => {
const handleClick = (section: NavSection) => {
if (section?.url) {
router.visit(section.url)
} else if (section?.action) {
emit('action', section.action)
} else {
emit('update:modelValue', section?.value)
}
Expand Down
5 changes: 3 additions & 2 deletions resources/js/Components/templates/ProfileSectionNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const props = defineProps<{
}>();
const sections = computed(() => {
return [
...(props.logerProfile?.map((profile: Record<string, string>) => ({
Expand All @@ -21,15 +22,15 @@ const sections = computed(() => {
icon: 'plus',
name: 'add',
label: 'Add',
url: '/trends'
action: 'add'
}
]
})
</script>


<template>
<SectionNav :sections="sections">
<SectionNav :sections="sections" @action="$emit('action', $event)">
<template #actions>
<slot name="actions" />
</template>
Expand Down
4 changes: 2 additions & 2 deletions resources/js/Pages/LogerProfile/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ const onSaved = () => {
<template>
<AppLayout title="Home Projects">
<template #header>
<ProfileSectionNav :loger-profile="profiles" />
<ProfileSectionNav :loger-profile="profiles" @action="isModalOpen = true" />
</template>

<LogerProfileTemplate title="Loger Profiles" ref="profileTemplateRef">
<WelcomeCard class="mt-5" message="Loger profiles">
<WelcomeCard message="Loger profiles">
<section class="flex flex-col items-center pb-12 mx-auto">
<img src="./empty-box.svg" class="opacity-50" />
<h4 class="text-lg font-bold text-body-1"> There are not profiles created</h4>
Expand Down
32 changes: 17 additions & 15 deletions resources/js/Pages/LogerProfile/ProfileView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import BudgetDetailForm from '@/domains/budget/components/BudgetDetailForm.vue';
import { IOccurrenceCheck } from '@/Components/Modules/occurrence/models';
import { ITransaction } from '@/domains/transactions/models';
import { transactionDBToTransaction } from '@/domains/transactions';
import axios from 'axios';
const { entities } = defineProps<{
Expand All @@ -38,10 +39,6 @@ const onSaved = () => {
const isProfileEntityModalOpen = ref(false);
const profileEntity = ref({});
const onProfileSaved = () => {
router.reload()
}
const areEntitiesLoading = ref(true)
function fetchProfileEntities() {
router.reload({
Expand All @@ -52,7 +49,19 @@ function fetchProfileEntities() {
})
}
onMounted(() => {
const transactions = ref<ITransaction[]>([]);
const isLoading = ref(false);
const fetchTransactions = (params = location.toString()) => {
return axios.get(`${location.pathname}/transactions`).then(({ data }: { data : {
data: ITransaction[]
}}) => {
transactions.value = data.data;
isLoading.value = false
})
}
onMounted(async () => {
fetchTransactions()
fetchProfileEntities()
})
Expand All @@ -64,14 +73,7 @@ const occurrenceChecks = computed(() => {
return checks;
}, []);
})
const transactions = computed(() => {
return entities.reduce((checks: ITransaction[], entity: any) => {
if (entity.entity?.transactions && entity.entity) {
checks.push(...entity.entity.transactions);
}
return checks;
}, []);
})
const budgets = computed(() => {
return entities.reduce((checks: any, entity: any) => {
if (entity.entity?.budget) {
Expand All @@ -83,6 +85,7 @@ const budgets = computed(() => {
return checks;
}, []);
})
</script>


Expand Down Expand Up @@ -143,7 +146,7 @@ const budgets = computed(() => {
<section v-else class="w-full">
<OccurrenceCard :checks="occurrenceChecks" class="mx-auto mt-4" />
<BudgetDetailForm
v-for="budget in budgets"
v-for="budget in budgets"
class="mt-5"
full
:category="budget.category"
Expand All @@ -169,4 +172,3 @@ const budgets = computed(() => {
</LogerProfileTemplate>
</AppLayout>
</template>
@/domains/transactions/models/transactions
7 changes: 4 additions & 3 deletions resources/js/Pages/Trends/Overview.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, toRefs } from "vue";
import { computed, toRefs, ref, onMounted } from "vue";
import { Link, router } from "@inertiajs/vue3";
// @ts-ignore
import { AtDatePager } from "atmosphere-ui";
Expand All @@ -14,10 +14,11 @@ import ChartComparison from "@/Components/widgets/ChartComparison.vue";
import WidgetTitleCard from "@/Components/molecules/WidgetTitleCard.vue";
import Collapse from "@/Components/molecules/Collapse.vue";
import YearSummary from "@/domains/transactions/components/YearSummary.vue";
import ExpenseChartWidget from "@/domains/transactions/components/ExpenseChartWidget.vue";
import { useServerSearch } from "@/composables/useServerSearch";
import { ITransaction } from "@/domains/transactions/models";
import axios from "axios";
const props = defineProps({
user: {
Expand Down Expand Up @@ -113,7 +114,7 @@ const cashflowEntities = {
value: '/trends/payees'
}
}
const isFilterSelected = (filterValue) => {
const isFilterSelected = (filterValue: string) => {
const currentStatus = location.pathname;
return currentStatus.includes(filterValue);
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const PANEL_SIZES = {
small: 'md:w-3/12',
small: "md:w-5/12 lg:w-3/12",
large: 'md:w-5/12'
}

Expand Down

0 comments on commit c113ce9

Please sign in to comment.