Skip to content

Commit c264a04

Browse files
committed
add is_from_income in saving form
1 parent c37be9c commit c264a04

5 files changed

Lines changed: 44 additions & 5 deletions

File tree

src/app/component/income-components/saving/saving.component.html

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,18 @@ <h3 class="text-xl font-semibold">Recent Savings</h3>
150150
<i class="fa-solid fa-arrow-down"></i>
151151
</div>
152152
<div>
153-
<p class="font-bold text-sm md:text-base truncate max-w-[140px] md:max-w-[250px]">
154-
{{ s.note || 'Savings Addition' }}
155-
</p>
153+
<div class="flex items-center gap-2">
154+
<p class="font-bold text-sm md:text-base truncate max-w-[140px] md:max-w-[250px]">
155+
{{ s.note || 'Savings Addition' }}
156+
</p>
157+
<!-- Income Indication Badge -->
158+
@if (s.is_from_income) {
159+
<span
160+
class="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-bold bg-indigo-500/10 text-indigo-500 border border-indigo-500/20 whitespace-nowrap">
161+
<i class="fa-solid fa-briefcase mr-1 text-[9px]"></i> Income
162+
</span>
163+
}
164+
</div>
156165
<p class="text-[10px] md:text-xs opacity-60 font-medium mt-0.5">
157166
{{ s.date | date:'MMMM yyyy' }}
158167
</p>
@@ -249,6 +258,26 @@ <h3 class="text-xl font-bold">
249258
class="fa-solid fa-circle-exclamation mr-1"></i>{{ savingNoteError }}</p>
250259
}
251260
</div>
261+
262+
<!-- New Toggle Field for Income Source -->
263+
<div>
264+
<label
265+
class="flex items-center justify-between p-4 transition-colors border rounded-xl cursor-pointer hover:opacity-80"
266+
style="background-color: var(--color-bg-500); border-color: var(--color-bg-600);">
267+
<div class="flex flex-col">
268+
<span class="text-sm font-medium"><i class="fa-solid fa-briefcase mr-2 opacity-60"></i>From
269+
Regular Income</span>
270+
<span class="text-xs opacity-50 mt-1">Is this amount part of your income?</span>
271+
</div>
272+
<div class="relative inline-flex items-center ml-4">
273+
<input type="checkbox" [(ngModel)]="savingForm.is_from_income" class="sr-only peer">
274+
<div
275+
class="w-11 h-6 bg-gray-400/50 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-500">
276+
</div>
277+
</div>
278+
</label>
279+
</div>
280+
252281
</div>
253282

254283
<div class="flex gap-3">

src/app/component/income-components/saving/saving.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ export class SavingComponent implements OnInit {
146146
saving_id: this.editingSavingId || 'sav_' + Date.now(),
147147
amount: Number(this.savingForm.amount),
148148
date: this.savingForm.date!,
149-
note: this.savingForm.note || ''
149+
note: this.savingForm.note || '',
150+
is_from_income: this.savingForm.is_from_income || false
150151
};
151152

152153
if (this.editingSavingId) {

src/app/features/salary/salary.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class SalaryComponent implements OnInit {
130130
) {
131131
this.userCurrancy = this.userService.getValue<string>('currency') || '';
132132
this.viewMode = this.userService.getValue<'salary' | 'budget' | 'saving'>('salary_view_mode') || 'salary';
133-
this.totalSavings = this.savingsService.getTotalSavings() > 0 ? this.savingsService.getTotalSavings() : 0;
133+
134134
}
135135

136136
/**
@@ -177,6 +177,7 @@ export class SalaryComponent implements OnInit {
177177
this.totalExpense = this.totalExpenseFunction();
178178
this.totalIncome = this.filteredTransactions.reduce((acc, t) => acc + (t.amount || 0), 0);
179179
this.totalBudget = this.filteredTransactions.reduce((acc, t) => acc + (t.budget || 0), 0);
180+
this.totalSavings = this.savingsService.getTotalSavings() > 0 ? this.savingsService.getTotalSavings() : 0;
180181
this.salaryGrowth = this.salaryGrowthFunction(allTransactions);
181182
this.dateMetrics = this.dateMetricsFunction();
182183
this.dailyAllowed = this.dailyAllowedFunction();
@@ -228,6 +229,12 @@ export class SalaryComponent implements OnInit {
228229
return (balance / this.totalIncome) * 100;
229230
}
230231

232+
totalSavingsFunction(): number {
233+
const savingsAmount = this.savingsService.getTotalSavings();
234+
return savingsAmount > 0 ? savingsAmount : 0;;
235+
}
236+
237+
231238
/**
232239
* Aggregates total expenses based on whether the user is viewing all time or the current month's budget.
233240
* @returns Total expense amount

src/app/service/localStorage/savings.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface Saving {
99
amount: number;
1010
date: string;
1111
note: string;
12+
is_from_income?: boolean;
1213
}
1314

1415
/**

src/app/service/localStorage/storage.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export class StorageService {
128128
amount: 0,
129129
date: "",
130130
note: "",
131+
is_from_income: false
131132
};
132133

133134
/**

0 commit comments

Comments
 (0)