@datarailsshared/datarailsshared 1.4.98 → 1.4.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3501,6 +3501,7 @@ class DrDatePickerService {
3501
3501
  quarter: DateFromats.QUARTER_FORMAT,
3502
3502
  week: DateFromats.WEEK_FORMAT
3503
3503
  };
3504
+ this.fiscalYearMonthsModifier = 0;
3504
3505
  }
3505
3506
  getDisplayPrefix() {
3506
3507
  const formatCached = this.format$.getValue();
@@ -3527,6 +3528,93 @@ class DrDatePickerService {
3527
3528
  normalizeValue(value) {
3528
3529
  return value.replace(/d/g, 'D');
3529
3530
  }
3531
+ /**
3532
+ * Get quarter number for date according to fiscal year
3533
+ *
3534
+ * @param date
3535
+ */
3536
+ getQuarterAccordingToFiscalYear(date) {
3537
+ let fiscalMonth = this.fiscalYearMonthsModifier;
3538
+ const dateMonth = date.month();
3539
+ if (dateMonth < fiscalMonth) {
3540
+ fiscalMonth -= 12;
3541
+ }
3542
+ return Math.trunc((date.month() - fiscalMonth) / 3) + 1;
3543
+ }
3544
+ /**
3545
+ * Sets date to end of quarter in FY by passed quarter number
3546
+ *
3547
+ * @param date
3548
+ * @param quarterNumber
3549
+ */
3550
+ setEndOfQuarter(date, quarterNumber) {
3551
+ date
3552
+ .subtract(this.fiscalYearMonthsModifier, 'M')
3553
+ .startOf('year')
3554
+ .add(this.fiscalYearMonthsModifier + quarterNumber * 3 - 1, 'M')
3555
+ .endOf('month');
3556
+ }
3557
+ /**
3558
+ * Sets date to start of quarter in FY by passed quarter number
3559
+ *
3560
+ * @param date
3561
+ * @param quarterNumber
3562
+ */
3563
+ setStartOfQuarter(date, quarterNumber) {
3564
+ date
3565
+ .subtract(this.fiscalYearMonthsModifier, 'M')
3566
+ .startOf('year')
3567
+ .add(this.fiscalYearMonthsModifier + (quarterNumber - 1) * 3, 'M');
3568
+ }
3569
+ /**
3570
+ * Sets date to end of current quarter (in which date is located) according to FY
3571
+ *
3572
+ * @param date
3573
+ */
3574
+ setEndOfCurrentQuarter(date) {
3575
+ this.setEndOfQuarter(date, this.getQuarterAccordingToFiscalYear(date));
3576
+ }
3577
+ /**
3578
+ * Sets date to start of current quarter (in which date is located) according to FY
3579
+ *
3580
+ * @param date
3581
+ */
3582
+ setStartOfCurrentQuarter(date) {
3583
+ this.setStartOfQuarter(date, this.getQuarterAccordingToFiscalYear(date));
3584
+ }
3585
+ /**
3586
+ * If date selection on this timeframe depends on Fiscal Year
3587
+ *
3588
+ * @param timeframe
3589
+ */
3590
+ isTimeframeDependingOnFY(timeframe) {
3591
+ return _.includes([TimeframeOption.QUARTER, TimeframeOption.YEAR], timeframe);
3592
+ }
3593
+ /**
3594
+ * Subtract from date fiscal year shift months count
3595
+ *
3596
+ * @param date
3597
+ */
3598
+ subtractFiscalYearMonthsFromDate(date) {
3599
+ return this.getDateModifiedByFiscalMonths(date, true);
3600
+ }
3601
+ /**
3602
+ * Add to date fiscal year shift months count
3603
+ *
3604
+ * @param date
3605
+ */
3606
+ addFiscalYearMonthsToDate(date) {
3607
+ return this.getDateModifiedByFiscalMonths(date);
3608
+ }
3609
+ /**
3610
+ * Add or subtract depending on isRevert paremeter Fiscal year month shift
3611
+ *
3612
+ * @param date
3613
+ * @param isSubtract
3614
+ */
3615
+ getDateModifiedByFiscalMonths(date, isSubtract = false) {
3616
+ return date ? _.cloneDeep(date)[isSubtract ? 'subtract' : 'add'](this.fiscalYearMonthsModifier, 'month') : date;
3617
+ }
3530
3618
  }
3531
3619
  DrDatePickerService.decorators = [
3532
3620
  { type: Injectable }
@@ -3560,20 +3648,20 @@ class DrDatePickerCustomHeaderComponent {
3560
3648
  title: 'Month',
3561
3649
  value: CalendarView.FOR_MONTHS,
3562
3650
  format: this.datePickerService.formatConfig.month,
3563
- periodLabel: () => String(moment$1(this._calendar.activeDate).year())
3651
+ periodLabel: () => String(moment$1(this._calendar.activeDate).utc().year())
3564
3652
  }, {
3565
3653
  timeframe: TimeframeOption.QUARTER,
3566
3654
  title: 'Quarter',
3567
3655
  value: CalendarView.FOR_QUARTERS,
3568
3656
  format: this.datePickerService.formatConfig.quarter,
3569
- periodLabel: () => String(moment$1(this._calendar.activeDate).year())
3657
+ periodLabel: () => String(moment$1(this.datePickerService.subtractFiscalYearMonthsFromDate(this._calendar.activeDate)).utc().year())
3570
3658
  }, {
3571
3659
  timeframe: TimeframeOption.YEAR,
3572
3660
  title: 'Year',
3573
3661
  value: CalendarView.FOR_YEARS,
3574
3662
  format: this.datePickerService.formatConfig.year,
3575
3663
  periodLabel: () => {
3576
- const currentYear = moment$1(this._calendar.activeDate).year();
3664
+ const currentYear = moment$1(this.datePickerService.subtractFiscalYearMonthsFromDate(this._calendar.activeDate)).utc().year();
3577
3665
  const startPeriod = Math.floor(currentYear / 24) * 24;
3578
3666
  return startPeriod + '-' + (startPeriod + 23);
3579
3667
  }
@@ -3595,12 +3683,24 @@ class DrDatePickerCustomHeaderComponent {
3595
3683
  _calendar.currentView = this.selectedTimeframe;
3596
3684
  this.setPeriodLabels();
3597
3685
  if (this.selectedTimeframe === CalendarView.FOR_QUARTERS) {
3598
- this.selectedQuarter = moment$1(this._calendar.activeDate).quarter();
3686
+ this.selectedQuarter = this.datePickerService.getQuarterAccordingToFiscalYear(this._calendar.activeDate);
3687
+ }
3688
+ });
3689
+ _calendar.viewChanged.pipe(takeUntil(this._destroyed)).subscribe(() => {
3690
+ this.setPeriodLabels();
3691
+ if (_calendar.multiYearView) {
3692
+ this.transformDateInMultiyearViewAccordingToFY();
3599
3693
  }
3600
3694
  });
3601
- _calendar.viewChanged.pipe(takeUntil(this._destroyed)).subscribe(() => this.setPeriodLabels());
3602
3695
  this.datePickerService.calendarInstance = _calendar;
3603
3696
  }
3697
+ ngOnInit() {
3698
+ setTimeout(() => {
3699
+ if (this._calendar.multiYearView) {
3700
+ this.transformDateInMultiyearViewAccordingToFY();
3701
+ }
3702
+ });
3703
+ }
3604
3704
  ngOnDestroy() {
3605
3705
  this._destroyed.next();
3606
3706
  this._destroyed.complete();
@@ -3624,7 +3724,7 @@ class DrDatePickerCustomHeaderComponent {
3624
3724
  const chosenTimeframeOption = this.timeframeOptions.filter(option => option.value === this.selectedTimeframe)[0];
3625
3725
  this.datePickerService.updateTimeframeAndFormat(chosenTimeframeOption.format);
3626
3726
  if (this.selectedTimeframe === CalendarView.FOR_QUARTERS) {
3627
- this.selectedQuarter = moment$1(this._calendar.activeDate).quarter();
3727
+ this.selectedQuarter = this.datePickerService.getQuarterAccordingToFiscalYear(this._calendar.activeDate);
3628
3728
  }
3629
3729
  }
3630
3730
  get currentViewIsQuarter() {
@@ -3634,11 +3734,9 @@ class DrDatePickerCustomHeaderComponent {
3634
3734
  this._calendar.currentView = view;
3635
3735
  }
3636
3736
  onSelectQuarter(quarterNumber) {
3637
- const monthsInQuarter = 3;
3638
- this.selectedQuarter = moment$1(this._calendar.activeDate).quarter();
3639
- const unadaptedDate = this._dateAdapter.addCalendarMonths(this._calendar.activeDate, monthsInQuarter * (quarterNumber - this.selectedQuarter));
3640
- this._calendar.activeDate = unadaptedDate;
3641
- this.datePickerService.updatedQuarter$.next(moment$1(unadaptedDate));
3737
+ this.selectedQuarter = quarterNumber;
3738
+ this.datePickerService.setEndOfQuarter(this._calendar.activeDate, quarterNumber);
3739
+ this.datePickerService.updatedQuarter$.next(this._calendar.activeDate);
3642
3740
  this.datePickerService.datePickerInstance.close();
3643
3741
  }
3644
3742
  pagingClicked(forward) {
@@ -3650,11 +3748,17 @@ class DrDatePickerCustomHeaderComponent {
3650
3748
  this._calendar.activeDate = this._dateAdapter[actionCall](this._calendar.activeDate, forward ? amount : -amount);
3651
3749
  this.setPeriodLabels();
3652
3750
  }
3751
+ transformDateInMultiyearViewAccordingToFY() {
3752
+ const multuYearView = this._calendar.multiYearView;
3753
+ multuYearView._activeDate = this.datePickerService.subtractFiscalYearMonthsFromDate(multuYearView._activeDate);
3754
+ multuYearView._selectedYear = multuYearView._activeDate.year();
3755
+ multuYearView._init();
3756
+ }
3653
3757
  }
3654
3758
  DrDatePickerCustomHeaderComponent.decorators = [
3655
3759
  { type: Component, args: [{
3656
3760
  selector: 'dr-date-picker_custom-header.component',
3657
- template: "<div *ngIf=\"datePickerService.isTimeframeSelectionEnabled\" class=\"dr-datepicker__timeframe-select__wrapper\">\n <dr-select\n class=\"dr-datepicker__timeframe-select\"\n [(ngModel)]=\"selectedTimeframe\"\n [items]=\"timeframeOptions | drShowTimeframePipe: datePickerService.availableTimeframes\"\n bindLabel=\"title\"\n bindValue=\"value\"\n (ngModelChange)=\"setTimeframe()\">\n </dr-select>\n</div>\n\n<div class=\"dr-date-paging\">\n <div class=\"dr-date-paging flip-page-button\"\n (click)=\"pagingClicked(false)\">\n <i class=\"dr-icon-arrow-left presentation_buttons-navigate_input\"></i>\n </div>\n <span class=\"example-header-label\">\n <span (click)=\"switchViewOnClickOnPeriodLabel(calendarView.FOR_MONTHS)\">{{periodMonthLabel + ' '}}</span>\n <span (click)=\"switchViewOnClickOnPeriodLabel(calendarView.FOR_YEARS)\">{{periodYearLabel}}</span>\n </span>\n <div class=\"dr-date-paging flip-page-button\"\n (click)=\"pagingClicked(true)\">\n <i class=\"dr-icon-arrow-right presentation_buttons-navigate_input\"></i>\n </div>\n</div>\n<div #quarterlyDatePicker class=\"dr-quarterly-datepicker\" *ngIf=\"currentViewIsQuarter\">\n <div *ngFor=\"let quarter of quarters\"\n class=\"quarter-selector\" (click)=\"onSelectQuarter(quarter)\"\n [class]=\"quarter === selectedQuarter ? 'selected' : ''\"\n >Q{{quarter}}</div>\n</div>\n\n",
3761
+ template: "<div *ngIf=\"datePickerService.isTimeframeSelectionEnabled\" class=\"dr-datepicker__timeframe-select__wrapper\">\n <dr-select\n class=\"dr-datepicker__timeframe-select\"\n [(ngModel)]=\"selectedTimeframe\"\n [items]=\"timeframeOptions | drShowTimeframePipe: datePickerService.availableTimeframes\"\n bindLabel=\"title\"\n bindValue=\"value\"\n (ngModelChange)=\"setTimeframe()\">\n </dr-select>\n</div>\n\n<div class=\"dr-date-paging\">\n <div class=\"dr-date-paging flip-page-button\"\n (click)=\"pagingClicked(false)\">\n <i class=\"dr-icon-arrow-left presentation_buttons-navigate_input\"></i>\n </div>\n <span class=\"example-header-label\">\n <span (click)=\"switchViewOnClickOnPeriodLabel(calendarView.FOR_MONTHS)\">{{ periodMonthLabel + ' ' }}</span>\n <span (click)=\"switchViewOnClickOnPeriodLabel(calendarView.FOR_YEARS)\">{{ periodYearLabel }}</span>\n </span>\n <div class=\"dr-date-paging flip-page-button\"\n (click)=\"pagingClicked(true)\">\n <i class=\"dr-icon-arrow-right presentation_buttons-navigate_input\"></i>\n </div>\n</div>\n<div #quarterlyDatePicker class=\"dr-quarterly-datepicker\" *ngIf=\"currentViewIsQuarter\">\n <div *ngFor=\"let quarter of quarters\"\n class=\"quarter-selector\" (click)=\"onSelectQuarter(quarter)\"\n [class]=\"quarter === selectedQuarter ? 'selected' : ''\"\n >Q{{quarter}}</div>\n</div>\n\n",
3658
3762
  changeDetection: ChangeDetectionStrategy.OnPush,
3659
3763
  styles: [":host{height:54px;align-items:center;font-family:\"Poppins\";font-style:normal;font-weight:600;font-size:14px;line-height:22px}.dr-datepicker__timeframe-select__wrapper{background-color:#f9faff;padding:16px 32px;border-radius:18px 18px 0 0}.dr-date-paging{display:flex;flex-direction:row;justify-content:space-between;align-items:center;padding:16px 8px;grid-gap:4px;gap:4px}.dr-date-paging.flip-page-button{width:20px;height:20px;padding:0;color:#4e566c}.dr-date-paging.flip-page-button:hover{border-radius:50%;background:#f2f2fb;color:#4646ce}.example-header-label{cursor:pointer}.dr-quarterly-datepicker{display:flex;justify-content:space-between;padding:10px}.dr-quarterly-datepicker .quarter-selector{display:block;width:74px;height:40px;text-align:center;border-radius:40px;font-weight:400;padding-top:9px}.dr-quarterly-datepicker .quarter-selector:hover{background:#f2f2fb;color:#4646ce;font-weight:600;cursor:pointer}.dr-quarterly-datepicker .quarter-selector.selected{background-color:#4646ce;color:#f3f7ff;font-weight:600}\n"]
3660
3764
  },] }
@@ -3679,6 +3783,7 @@ class DrDatePickerComponent {
3679
3783
  // Whether to transform date, taking end, start, middle of preiod (i.e. set middle of month if timeframe='month')
3680
3784
  this.periodPosition = DatePickerPeriodPosition.DEFAULT;
3681
3785
  this.placeholder = 'Select';
3786
+ this.fiscalYearMonthsModifier = 0;
3682
3787
  this.calendarViewsTimeframeMapping = {
3683
3788
  year: 'multi-year',
3684
3789
  month: 'year',
@@ -3715,6 +3820,7 @@ class DrDatePickerComponent {
3715
3820
  this.cdr.markForCheck();
3716
3821
  }
3717
3822
  ngAfterViewInit() {
3823
+ this.datePickerService.fiscalYearMonthsModifier = this.fiscalYearMonthsModifier;
3718
3824
  this.datePickerService.datePickerInstance = this.datePicker;
3719
3825
  this.datePicker.startView = this.calendarViewsTimeframeMapping[this.datePickerService.timeframe];
3720
3826
  }
@@ -3730,14 +3836,43 @@ class DrDatePickerComponent {
3730
3836
  const timeframe = this.datePickerService.timeframe;
3731
3837
  switch (this.periodPosition) {
3732
3838
  case DatePickerPeriodPosition.START_OF_PERIOD:
3733
- this.innerValue.startOf(timeframe);
3839
+ if (this.datePickerService.timeframe === TimeframeOption.QUARTER) {
3840
+ this.datePickerService.setStartOfCurrentQuarter(this.innerValue);
3841
+ }
3842
+ else if (this.datePickerService.timeframe === TimeframeOption.YEAR) {
3843
+ this.datePickerService.setStartOfQuarter(this.innerValue, 1);
3844
+ }
3845
+ else {
3846
+ this.innerValue.startOf(timeframe);
3847
+ }
3734
3848
  break;
3735
3849
  case DatePickerPeriodPosition.END_OF_PERIOD:
3736
- this.innerValue.endOf(timeframe);
3850
+ if (this.datePickerService.timeframe === TimeframeOption.QUARTER) {
3851
+ this.datePickerService.setEndOfCurrentQuarter(this.innerValue);
3852
+ }
3853
+ else if (this.datePickerService.timeframe === TimeframeOption.YEAR) {
3854
+ this.datePickerService.setEndOfQuarter(this.innerValue, 4);
3855
+ }
3856
+ else {
3857
+ this.innerValue.endOf(timeframe);
3858
+ }
3737
3859
  break;
3738
3860
  case DatePickerPeriodPosition.MIDDLE_OF_PERIOD:
3739
- this.innerValue.startOf(timeframe);
3740
- const endOfPeriod = this.innerValue.clone().endOf(timeframe);
3861
+ let endOfPeriod;
3862
+ if (this.datePickerService.timeframe === TimeframeOption.QUARTER) {
3863
+ endOfPeriod = this.innerValue.clone();
3864
+ this.datePickerService.setStartOfCurrentQuarter(this.innerValue);
3865
+ this.datePickerService.setEndOfCurrentQuarter(endOfPeriod);
3866
+ }
3867
+ else if (this.datePickerService.timeframe === TimeframeOption.YEAR) {
3868
+ endOfPeriod = this.innerValue.clone();
3869
+ this.datePickerService.setStartOfQuarter(this.innerValue, 1);
3870
+ this.datePickerService.setEndOfQuarter(endOfPeriod, 4);
3871
+ }
3872
+ else {
3873
+ this.innerValue.startOf(timeframe);
3874
+ endOfPeriod = this.innerValue.clone().endOf(timeframe);
3875
+ }
3741
3876
  const diff = endOfPeriod.diff(this.innerValue, 'seconds');
3742
3877
  this.innerValue.add(diff / 2 + 1, 'seconds');
3743
3878
  break;
@@ -3747,6 +3882,9 @@ class DrDatePickerComponent {
3747
3882
  }
3748
3883
  }
3749
3884
  chosenPeriodHandler(chosenDate, timeframe) {
3885
+ if (timeframe === TimeframeOption.YEAR) {
3886
+ chosenDate = this.datePickerService.addFiscalYearMonthsToDate(chosenDate);
3887
+ }
3750
3888
  if (this.datePickerService.timeframe === TimeframeOption.QUARTER && timeframe === TimeframeOption.YEAR) {
3751
3889
  this.datePickerService.calendarInstance.currentView = CalendarView.FOR_QUARTERS;
3752
3890
  this.datePickerService.calendarInstance.activeDate = chosenDate;
@@ -3814,6 +3952,7 @@ DrDatePickerComponent.propDecorators = {
3814
3952
  max: [{ type: Input }],
3815
3953
  periodPosition: [{ type: Input }],
3816
3954
  placeholder: [{ type: Input }],
3955
+ fiscalYearMonthsModifier: [{ type: Input }],
3817
3956
  datePicker: [{ type: ViewChild, args: ['datePicker',] }]
3818
3957
  };
3819
3958
 
@@ -3858,8 +3997,12 @@ class DrDatePickerWithTimeframeComponent extends DrDatePickerComponent {
3858
3997
  if (!this.value) {
3859
3998
  return this.placeholder;
3860
3999
  }
4000
+ let displayValue = _.cloneDeep(this.value);
4001
+ if (this.datePickerService.isTimeframeDependingOnFY(this.datePickerService.timeframe)) {
4002
+ displayValue = this.datePickerService.subtractFiscalYearMonthsFromDate(displayValue);
4003
+ }
3861
4004
  const formatCached = this.datePickerService.format$.getValue();
3862
- return this.datePickerService.getDisplayPrefix() + this.value.format(formatCached);
4005
+ return this.datePickerService.getDisplayPrefix() + displayValue.format(formatCached);
3863
4006
  }
3864
4007
  ngOnInit() {
3865
4008
  this.datePickerService.isTimeframeSelectionEnabled = this.canSelectTimeframe;