@@ -62,26 +62,34 @@ export class SavingComponent implements OnInit {
6262
6363 calculateStats ( ) {
6464 this . totalSavedAmount = this . savings . reduce ( ( sum , s ) => sum + Number ( s . amount || 0 ) , 0 ) ;
65- this . goalTarget = Number ( this . currentGoal ?. target_amount || 0 ) ;
65+ this . goalTarget = this . goalTargetFunction ( ) ;
6666
67- const progress = this . goalTarget > 0 ? ( this . totalSavedAmount / this . goalTarget ) * 100 : 0 ;
67+ const totalSavedBetweenGoalRange = this . savingsService . gettotalSavingsBetweenDates ( this . currentGoal ?. start_date || null , this . currentGoal ?. target_date || null ) ;
68+
69+ const progress = this . goalTarget > 0 ? ( totalSavedBetweenGoalRange / this . goalTarget ) * 100 : 0 ;
6870 this . progressPercentage = Math . min ( Math . max ( progress , 0 ) , 100 ) ;
6971 this . remainingPercentage = Math . max ( 100 - this . progressPercentage , 0 ) ;
72+ this . goalRemaining = ( this . goalTarget - totalSavedBetweenGoalRange ) > 0 ? this . goalTarget - totalSavedBetweenGoalRange : 0 ;
7073
71- this . goalRemaining = ( this . goalTarget - this . totalSavedAmount ) > 0 ? this . goalTarget - this . totalSavedAmount : 0 ;
72-
73- if ( this . currentGoal ?. start_date && this . totalSavedAmount > 0 ) {
74+ if ( this . currentGoal ?. start_date && totalSavedBetweenGoalRange > 0 ) {
7475 const start = new Date ( this . currentGoal . start_date ) . getTime ( ) ;
7576 const today = new Date ( ) . getTime ( ) ;
7677 let days = Math . ceil ( ( today - start ) / ( 1000 * 3600 * 24 ) ) ;
77- this . averageSavedPerDay = this . totalSavedAmount / ( days <= 0 ? 1 : days ) ;
78+ this . averageSavedPerDay = totalSavedBetweenGoalRange / ( days <= 0 ? 1 : days ) ;
7879 } else {
7980 this . averageSavedPerDay = 0 ;
8081 }
8182 this . allowedPerDay = this . allowedPerDayFunction ( ) ;
8283 this . suggestedPerDay = this . suggestedPerDayFunction ( ) ;
8384 }
8485
86+
87+ goalTargetFunction ( ) : number {
88+ if ( this . currentGoal ) {
89+ return Number ( this . currentGoal . target_amount ) ;
90+ }
91+ return 0 ;
92+ }
8593 allowedPerDayFunction ( ) : number {
8694 if ( this . currentGoal ) {
8795 const days = this . utilService . calculateDaysBetween ( this . currentGoal . start_date , this . currentGoal . target_date ) ;
0 commit comments