Skip to content

Commit

Permalink
Merge pull request #319 from jesusantguerrero/fix/profiles
Browse files Browse the repository at this point in the history
Fix/profiles
  • Loading branch information
jesusantguerrero authored Nov 18, 2023
2 parents 4dd5e44 + 3436206 commit d911056
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 114 deletions.
28 changes: 18 additions & 10 deletions app/Domains/Budget/Services/BudgetCategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,31 @@ public function getBudgetInfo($category, string $month)
->toFloat();
} else {
$monthBalance = (float) $category->getMonthBalance($yearMonth)->balance;
$available = Money::of($budgeted, 'USD')->plus($monthBudget?->left_from_last_month ?? 0)->plus($monthBalance)->getAmount()->toFloat();

$available = Money::of($budgeted, 'USD')
->plus($monthBudget?->left_from_last_month ?? 0)
->plus($monthBalance)
->getAmount()
->toFloat();

if ($category->display_id == 'ready_to_assign') {
$available = $monthBudget?->available;
$monthBalance = $monthBudget?->activity;
// dd($monthBalance, $available, $monthBalance, $monthBudget);
}
}

$data = [
'budgeted' => $budgeted,
'budgeted' => $monthBudget?->budgeted,
'activity' => $monthBalance,
'available' => $available,
'payments' => $monthBudget?->payments ?? 0,
'left_from_last_month' => $monthBudget?->left_from_last_month ?? 0,
'funded_spending_previous_month' => $monthBudget?->funded_spending_previous_month ?? 0,
'funded_spending_previous_month' => 0,
'funded_spending' => $monthBudget?->funded_spending ?? 0,
'name' => $category->name,
'month' => $yearMonth,
];

// if ($category->id == 733) {
// // dd($data);
// // dd($prevMonthLeftOver);
// }

return $data;
}

Expand Down Expand Up @@ -282,15 +287,18 @@ public function updateFundedSpending(Category $category, string $month)
$transactions = $category->account->getMonthFundedSpending($yearMonth)->balance;
$payments = $category->account->getMonthPayments($yearMonth)->balance;

$fundedSpending = ($transactions * -1) ?? 0;

BudgetMonth::updateOrCreate([
'category_id' => $category->id,
'team_id' => $category->team_id,
'month' => $month,
'name' => $month,
], [
'user_id' => $category->user_id,
'funded_spending' => ($transactions * -1) ?? 0,
'funded_spending' => $fundedSpending,
'payments' => $payments ?? 0,
'available' => DB::raw("$fundedSpending + available - $payments"),
]);

echo "{$category->name} updated to {$activity}".PHP_EOL;
Expand Down
30 changes: 8 additions & 22 deletions app/Domains/Budget/Services/BudgetRolloverService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

namespace App\Domains\Budget\Services;

use App\Domains\Budget\Data\BudgetReservedNames;
use App\Domains\Budget\Models\BudgetMonth;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Insane\Journal\Models\Core\Category;
use App\Domains\Budget\Models\BudgetMonth;
use App\Domains\Budget\Data\BudgetReservedNames;

class BudgetRolloverService {
public function __construct(private BudgetCategoryService $budgetCategoryService) {
public function __construct(private BudgetCategoryService $budgetCategoryService) {}

}
public function rollMonth($teamId, $month, $categories = null) {
if (!$categories) {
$categories = Category::where([
Expand Down Expand Up @@ -40,19 +39,11 @@ private function setNewMonthBudget($category, $month) {
'name' => $month,
])->first();
$available = ($budgetMonth?->budgeted ?? 0) + ($budgetMonth->left_from_last_month ?? 0) + $activity;
$leftFunded = 0;
if ($category->account_id) {
$leftFunded = ($budgetMonth?->funded_spending ?? 0) + ($budgetMonth?->funded_spending_previous_month ?? 0) - ($budgetMonth?->payments ?? 0);
}
$this->movePositiveAmounts($category, $month, $available, $leftFunded);
// If your category had been overspent in cash (negative red Available), that amount will be deducted from Ready to Assign in the new month.
$this->movePositiveAmounts($category, $month, $available);

// If your category had been overspent in credit (negative yellow Available), the amount you overspent will be represented as an Underfunded alert ↗️ in your Credit Card Payment category. If you can't cover this overspending in the month it happens, you'll need to assign funds directly to the Credit Card Payment category to pay back the debt.

// Not seeing an Underfunded Alert in your Credit Card Payment category? We're testing this new feature in stages and releasing it to everyone soon.
}

private function movePositiveAmounts($category, $oldMonth, $available, $leftFunded = 0) {
private function movePositiveAmounts($category, $oldMonth, $available) {
$nextMonth = Carbon::createFromFormat("Y-m-d", $oldMonth)->addMonthsWithNoOverflow(1)->format('Y-m-d');
BudgetMonth::updateOrCreate([
'category_id' => $category->id,
Expand All @@ -62,7 +53,7 @@ private function movePositiveAmounts($category, $oldMonth, $available, $leftFund
], [
'user_id' => $category->user_id,
'left_from_last_month' => $available ?? 0,
'funded_spending_previous_month' => $leftFunded
'funded_spending_previous_month' => 0
]);
}

Expand Down Expand Up @@ -94,8 +85,7 @@ private function moveReadyToAssign($teamId, $month) {

$activity = (new BudgetCategoryService($readyToAssignCategory))->getCategoryActivity($readyToAssignCategory, $month);
$activityPlusLeft = $activity + $budgetMonth->left_from_last_month;
$available = $activityPlusLeft - ($results?->budgeted ?? 0);
$leftFunded = ($results?->funded_spending ?? 0) + ($results?->funded_spending_previous_month ?? 0) - ($results?->payments ?? 0);
$available = $activityPlusLeft - ($results?->budgeted ?? 0) ;

$nextMonth = Carbon::createFromFormat("Y-m-d", $month)->addMonthsWithNoOverflow(1)->format('Y-m-d');

Expand Down Expand Up @@ -123,7 +113,7 @@ private function moveReadyToAssign($teamId, $month) {
], [
'user_id' => $readyToAssignCategory->user_id,
'left_from_last_month' => $available ?? 0,
'funded_spending_previous_month' => $leftFunded ?? 0,
'funded_spending_previous_month' => 0,
]);
}

Expand All @@ -136,9 +126,5 @@ private function reduceOverspent() {
// Not seeing an Underfunded Alert in your Credit Card Payment category? We're testing this new feature in stages and releasing it to everyone soon.
}

private function setReadyToAssign() {

}

// transactions with more than 3 days prior to the las recinciled transaction are not imported
}
6 changes: 6 additions & 0 deletions resources/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
.multiselect__input {
@apply bg-base-lvl-2;
}

.aside-content {
width: -webkit-fill-available;
height: 100%;
overflow: auto;
}
61 changes: 31 additions & 30 deletions resources/js/Components/AppUserMenu.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
<script setup lang="ts">
import JetDropdown from '@/Components/atoms/Dropdown.vue'
import JetDropdownLink from '@/Components/atoms/DropdownLink.vue'
import AppUserMenuButton from './AppUserMenuButton.vue';
import { useAppContextStore } from '@/store';
import { AtDropdownLink } from 'atmosphere-ui';
import { useImportModal } from '@/domains/transactions/useImportModal';
defineProps({
hasImage: {
type: Boolean
},
hasApiFeatures: {
type: Boolean
},
imageUrl: {
type: String
},
user: {
type: Object
}
})
const context = useAppContextStore()
const { toggleModal: toggleImportModal } = useImportModal();
</script>


<template>
<JetDropdown align="right" width="48" v-if="!context.isMobile">
<template #trigger>
Expand Down Expand Up @@ -60,33 +91,3 @@
@click="context.toggleOptionsModal()"
/>
</template>

<script setup lang="ts">
import JetDropdown from '@/Components/atoms/Dropdown.vue'
import JetDropdownLink from '@/Components/atoms/DropdownLink.vue'
import AppUserMenuButton from './AppUserMenuButton.vue';
import { useAppContextStore } from '@/store';
import { AtDropdownLink } from 'atmosphere-ui';
import { useImportModal } from '@/domains/transactions/useImportModal';
defineProps({
hasImage: {
type: Boolean
},
hasApiFeatures: {
type: Boolean
},
imageUrl: {
type: String
},
user: {
type: Object
}
})
const context = useAppContextStore()
const { toggleModal: toggleImportModal } = useImportModal();
</script>
5 changes: 4 additions & 1 deletion resources/js/Components/templates/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import { useTransactionModal } from '@/domains/transactions'
import { useOnMessage } from '@/composables/useFirebase'
import AppProvider from './AppProvider.vue'
import { useAppContextStore } from '@/store'
// import LogerAssistant from '../organisms/logerAssistant.vue'
const props = defineProps({
Expand All @@ -39,6 +40,8 @@
},
})
const context = useAppContextStore()
const { appMenu, headerMenu, mobileMenu } = useAppMenu(t)
const serverMenu = computed(() => {
return pageProps.menu
Expand Down Expand Up @@ -145,7 +148,7 @@
/>
<!-- <LogerAssistant /> -->
<AtTeamSelect
v-if="$page.props.user.all_teams.length"
v-if="$page.props.user.all_teams.length && !context.isMobile"
:has-team-features="$page.props.jetstream.hasTeamFeatures"
:can-create-teams="$page.props.jetstream.canCreateTeams"
:current-team="$page.props.user.current_team"
Expand Down
8 changes: 0 additions & 8 deletions resources/js/Components/templates/LogerProfileTemplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,3 @@
</aside>
</article>
</template>


<style lang="scss" scoped>
.aside-content {
width: -webkit-fill-available;
}
</style>
17 changes: 8 additions & 9 deletions resources/js/Pages/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,33 @@
<AppIcon size="medium" class="ml-2" />
</template>

<div class="px-5 mx-auto mt-5 space-y-10 md:space-y-0 md:space-x-10 md:flex max-w-screen-2xl sm:px-6 lg:px-8">
<div class="px-5 mx-auto mt-5 mb-10 md:space-y-0 md:space-x-10 md:flex max-w-screen-2xl sm:px-6 lg:px-8">
<div class="mt-6 md:w-9/12">
<section class="flex space-x-4">
<section class="flex flex-col md:flex-row md:space-x-4">
<BudgetTracker
class="w-8/12 "
class="md:w-8/12 w-full order-1 mt-2 md:mt-0"
ref="budgetTrackerRef"
:budget="budgetTotal"
:expenses="transactionTotal.total_amount"
:message="t('dashboard.welcome')"
:message="$t('dashboard.welcome')"
:username="user.name"
@section-click="selected=$event"
>
<ChartCurrentVsPrevious
v-if="selected=='expenses'"
class="w-full mt-4 mb-10 overflow-hidden bg-white rounded-lg"
class="w-full mt-4 md:mb-10 overflow-hidden bg-white rounded-lg"
:class="[cardShadow]"
:title="t('This month vs last month')"
ref="ComparisonRevenue"
:data="expenses"
/>
</BudgetTracker>
<WeatherWidget class="w-4/12" />
<WeatherWidget class="md:w-4/12 md:order-1" />
</section>

<section class="flex space-x-4">
<ChartComparison
class="w-full mt-4 mb-10 overflow-hidden bg-white rounded-lg"
class="w-full mt-4 md:mb-10 overflow-hidden bg-white rounded-lg"
:class="[cardShadow]"
:title="$t('Spending summary')"
ref="ComparisonRevenue"
Expand All @@ -154,9 +154,8 @@
@action="router.visit('/trends/income-expenses-graph')"
/>
</section>

</div>
<div class="py-6 space-y-4 md:w-3/12">
<div class="py-6 space-y-4 md:w-3/12">
<OccurrenceCard :checks="checks" />
<OnboardingSteps
v-if="onboarding.steps"
Expand Down
4 changes: 2 additions & 2 deletions resources/js/Pages/Finance/Index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<script setup lang="ts">
import { computed, toRefs, watch, ref } from "vue";
import { computed, toRefs, ref } from "vue";
import { router, useForm } from "@inertiajs/vue3";
import { format, subMonths } from "date-fns";
// @ts-ignore
Expand Down Expand Up @@ -215,7 +215,7 @@ const deleteBulkTransactions = () => {
</div>
</WidgetTitleCard>

<section class="grid grid-cols-2 gap-2">
<section class="grid md:grid-cols-2 gap-2">
<WidgetTitleCard title="Planned Transactions" class="hidden md:block">
<TransactionsList
class="w-full"
Expand Down
9 changes: 0 additions & 9 deletions resources/js/Pages/Finance/Partials/FinanceTemplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,3 @@
</aside>
</article>
</template>




<style lang="scss" scoped>
.aside-content {
width: -webkit-fill-available;
}
</style>
9 changes: 0 additions & 9 deletions resources/js/Pages/Trends/Partials/TrendTemplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,3 @@
</aside>
</article>
</template>




<style lang="scss" scoped>
.aside-content {
width: -webkit-fill-available;
}
</style>
14 changes: 7 additions & 7 deletions resources/js/domains/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ export const useAppMenu = t => {
return /finance|budgets/.test(currentPath)
}
},
{
icon: 'fas fa-heart',
label: t('Relationship'),
to: '/relationships/partner',
as: Link
},
{
icon: 'fas fa-home',
label: t('Housing'),
Expand All @@ -47,6 +41,12 @@ export const useAppMenu = t => {
return /housing/.test(currentPath)
}
},
{
icon: 'fas fa-heart',
label: t('Relationship'),
to: '/relationships/partner',
as: Link
},
{
icon: 'fas fa-users',
label: t('Profiles'),
Expand All @@ -67,7 +67,7 @@ export const useAppMenu = t => {
}
].filter(item => !item.hidden);

let mobileMenu = cloneDeep(appMenu)
let mobileMenu = cloneDeep(appMenu).splice(0, 4)
mobileMenu.splice(2, null, {
name: 'add',
label: 'Add',
Expand Down
Loading

0 comments on commit d911056

Please sign in to comment.