diff --git a/app/Domains/LogerProfile/Http/Controllers/LogerProfileController.php b/app/Domains/LogerProfile/Http/Controllers/LogerProfileController.php index 85483e46..7968faae 100644 --- a/app/Domains/LogerProfile/Http/Controllers/LogerProfileController.php +++ b/app/Domains/LogerProfile/Http/Controllers/LogerProfileController.php @@ -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 { @@ -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), @@ -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); + } } diff --git a/app/Domains/LogerProfile/Http/Controllers/LogerProfileEntityController.php b/app/Domains/LogerProfile/Http/Controllers/LogerProfileEntityController.php index 89aef381..3be1692c 100644 --- a/app/Domains/LogerProfile/Http/Controllers/LogerProfileEntityController.php +++ b/app/Domains/LogerProfile/Http/Controllers/LogerProfileEntityController.php @@ -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 { diff --git a/app/Domains/LogerProfile/Services/LogerProfileService.php b/app/Domains/LogerProfile/Services/LogerProfileService.php index 5d6032bc..edb0bf5c 100644 --- a/app/Domains/LogerProfile/Services/LogerProfileService.php +++ b/app/Domains/LogerProfile/Services/LogerProfileService.php @@ -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 { @@ -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'), + ]; + } } diff --git a/app/Domains/LogerProfile/routes.php b/app/Domains/LogerProfile/routes.php index 2309cc30..f266f3f3 100644 --- a/app/Domains/LogerProfile/routes.php +++ b/app/Domains/LogerProfile/routes.php @@ -1,11 +1,12 @@ 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']); }); diff --git a/resources/js/Components/molecules/SectionNav.vue b/resources/js/Components/molecules/SectionNav.vue index 056d5c4a..9366aad1 100644 --- a/resources/js/Components/molecules/SectionNav.vue +++ b/resources/js/Components/molecules/SectionNav.vue @@ -8,6 +8,7 @@ import { NDropdown } from 'naive-ui'; interface NavSection { url?: string; + action?: string; value: string; label: string; } @@ -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 @@ -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) } diff --git a/resources/js/Components/templates/ProfileSectionNav.vue b/resources/js/Components/templates/ProfileSectionNav.vue index 8d2fc73d..2ba40f53 100644 --- a/resources/js/Components/templates/ProfileSectionNav.vue +++ b/resources/js/Components/templates/ProfileSectionNav.vue @@ -9,6 +9,7 @@ const props = defineProps<{ }>(); + const sections = computed(() => { return [ ...(props.logerProfile?.map((profile: Record) => ({ @@ -21,7 +22,7 @@ const sections = computed(() => { icon: 'plus', name: 'add', label: 'Add', - url: '/trends' + action: 'add' } ] }) @@ -29,7 +30,7 @@ const sections = computed(() => {