@@ -26,7 +26,7 @@ export class PdRebateCardComponent implements OnInit {
2626 public card_comment : string ;
2727 public rebate_status : string ;
2828 private numToMonth : string [ ] = [ "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec" ] ;
29-
29+ public p_total_rebate_days : string = "0" ;
3030 constructor (
3131 private data_service : StudentdataService ,
3232 private dialog : MatDialog ,
@@ -43,6 +43,7 @@ export class PdRebateCardComponent implements OnInit {
4343 this . p_rebate_reason = this . rebate_request . reason ;
4444 this . card_comment = "" ;
4545 this . p_rebate_days = this . noOfDays ( this . rebate_request . start , this . rebate_request . end ) ;
46+ this . calculateTotalRebateDays ( ) ;
4647 }
4748
4849 acceptRebate ( ) {
@@ -91,7 +92,7 @@ export class PdRebateCardComponent implements OnInit {
9192 }
9293
9394 isAdmin ( ) : boolean {
94- return ! this . auth . isStudent ( ) ;
95+ return this . auth . isRebate ( ) ;
9596 }
9697
9798 updateRebateData ( ) {
@@ -165,4 +166,21 @@ export class PdRebateCardComponent implements OnInit {
165166 return "0" ;
166167 }
167168}
169+
170+ private async calculateTotalRebateDays ( ) : Promise < void > {
171+ try {
172+ const res : any = await this . data_service . getAdminRebatesRoll ( this . rebate_request . roll ) ;
173+ const acceptedRebates = res . accepted_rebate || [ ] ;
174+
175+ let totalDays = 0 ;
176+ acceptedRebates . forEach ( ( rebate : any ) => {
177+ totalDays += parseInt ( this . noOfDays ( rebate . start , rebate . end ) ) ;
178+ } ) ;
179+
180+ this . p_total_rebate_days = totalDays . toString ( ) ;
181+ } catch ( error ) {
182+ console . error ( 'Error calculating total rebate days:' , error ) ;
183+ this . p_total_rebate_days = "0" ;
184+ }
185+ }
168186}
0 commit comments