@@ -4,6 +4,7 @@ import { FormsModule } from '@angular/forms';
44import { GoalService , Goal } from '../../../service/localStorage/goal.service' ;
55import { SavingsService , Saving } from '../../../service/localStorage/savings.service' ;
66import { ConfigService } from '../../../service/config/config.service' ;
7+ import { UtilService } from '../../../service/utils/util.service' ;
78
89@Component ( {
910 selector : 'app-saving' ,
@@ -34,13 +35,17 @@ export class SavingComponent implements OnInit {
3435 goalTarget = 0 ;
3536 progressPercentage = 0 ;
3637 remainingPercentage = 0 ;
37- currentMonthAdded = 0 ;
38+ goalRemaining = 0 ;
3839 averageSavedPerDay = 0 ;
40+ suggestedPerDay = 0 ;
41+ allowedPerDay = 0 ;
42+
3943
4044 constructor (
4145 private goalService : GoalService ,
4246 private savingsService : SavingsService ,
43- private configService : ConfigService
47+ private configService : ConfigService ,
48+ private utilService : UtilService
4449 ) {
4550 this . todayDateStr = this . configService . getLocalTime ( ) . split ( 'T' ) [ 0 ] ;
4651 }
@@ -63,8 +68,7 @@ export class SavingComponent implements OnInit {
6368 this . progressPercentage = Math . min ( Math . max ( progress , 0 ) , 100 ) ;
6469 this . remainingPercentage = Math . max ( 100 - this . progressPercentage , 0 ) ;
6570
66- const now = new Date ( ) ;
67- this . currentMonthAdded = ( this . goalTarget - this . totalSavedAmount ) > 0 ? this . goalTarget - this . totalSavedAmount : 0 ;
71+ this . goalRemaining = ( this . goalTarget - this . totalSavedAmount ) > 0 ? this . goalTarget - this . totalSavedAmount : 0 ;
6872
6973 if ( this . currentGoal ?. start_date && this . totalSavedAmount > 0 ) {
7074 const start = new Date ( this . currentGoal . start_date ) . getTime ( ) ;
@@ -74,6 +78,28 @@ export class SavingComponent implements OnInit {
7478 } else {
7579 this . averageSavedPerDay = 0 ;
7680 }
81+ this . allowedPerDay = this . allowedPerDayFunction ( ) ;
82+ this . suggestedPerDay = this . suggestedPerDayFunction ( ) ;
83+ }
84+
85+ allowedPerDayFunction ( ) : number {
86+ if ( this . currentGoal ) {
87+ const days = this . utilService . calculateDaysBetween ( this . currentGoal . start_date , this . currentGoal . target_date ) ;
88+ if ( days <= 0 ) return 0 ;
89+ this . allowedPerDay = this . goalTarget / days ;
90+ return this . allowedPerDay ;
91+ }
92+ return 0 ;
93+ }
94+
95+ suggestedPerDayFunction ( ) : number {
96+ if ( this . currentGoal ) {
97+ const days = this . utilService . calculateDaysBetween ( this . todayDateStr , this . currentGoal . target_date ) ;
98+ if ( days <= 0 ) return 0 ;
99+ this . suggestedPerDay = this . goalRemaining / days ;
100+ return this . suggestedPerDay ;
101+ }
102+ return 0 ;
77103 }
78104
79105 /* ---------- Saving Form Validation Getters ---------- */
0 commit comments