import { formatDate } from '@angular/common';
import { Component, OnInit, ChangeDetectionStrategy, Input, OnChanges, SimpleChanges } from '@angular/core';
import { DailyRegisterPaymentTotalService } from 'src/app/core/service/report/daily-register/daily-register-payment-total.service';
import { DailyRegisterPaymentService } from 'src/app/core/service/report/daily-register/daily-register-payment.service';
import { PeriodRegisterPaymentService } from 'src/app/core/service/report/period-register/period-register-payment.service';

@Component({
  selector: 'period-summary-list',
  templateUrl: './period-summary-list.component.html',
  styleUrls: ['./period-summary-list.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class PeriodSummaryListComponent implements OnInit,OnChanges {
  @Input() periodSummary: any = [];
  price1000 = 0;
  price500 = 0;
  price100 = 0;
  price50 = 0;
  price20 = 0;
  price10 = 0;
  price5 = 0;
  price2 = 0;
  price1 = 0;
  price050 = 0;
  price025 = 0;
  column = ['1','2','3','4','5','6','7']
  // periodSummaryList$ : any = [];
  sumPrice;
  constructor(
    private periodRegisterPaymentSV: PeriodRegisterPaymentService,
    private dailyRegisterSV: DailyRegisterPaymentService,
    private dailyRegisterTotalSV: DailyRegisterPaymentTotalService
  ) { }

  ngOnInit(): void {
  }

  ngOnChanges(changes: SimpleChanges): void {
    if(this.periodSummary){
      this.sumPrice = this.periodSummary.reduce((acc,cur) => {
        return acc + +cur.total_amount
      },0)
    }
  }

  print(){
    const obj = {
      start_date : formatDate(this.periodSummary[0].payment_date, 'yyyy-MM-dd', 'en-US'),
      end_date : formatDate(new Date() ,'yyyy-MM-dd', 'en-US')
    }
    window.open(this.periodRegisterPaymentSV.etest103(obj))
  }

  sum(){
    let sum;
    sum =
    (this.price1000 * 1000) +
    (this.price500 * 500) +
    (this.price100 * 100) +
    (this.price50 * 50) +
    (this.price20 * 20) +
    (this.price10 * 10) +
    (this.price5 * 5) +
    (this.price2 * 2) +
    (this.price1 * 1) +
    (this.price050 * 0.5) +
    (this.price025 * 0.25)
    return sum;
  }

  reportEtest(type:string){
    const data = {...this.periodSummary[0]}
    const query = {
      period: data.period,
      counter_no: data.counter_no,
      date : data.payment_date
    }
    if(type == '101'){
      window.open(this.dailyRegisterSV.etest101(query))
    }else{
      window.open(this.dailyRegisterTotalSV.etest102(query))
    }
  }


  printScreen(){
    window.print()
  }

}
