diff --git a/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts index 30cf658d3..23d20b594 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts @@ -21,12 +21,6 @@ export class LicenseChartComponent { readonly lineChartSeries$ = this.#licenseChartSeries$; barChart = []; - constructor( - private readonly _translateService: TranslateService, - private readonly _licenseService: LicenseService, - private readonly _loadingService: LoadingService, - ) {} - get #licenseChartSeries$(): Observable { return this._licenseService.selectedLicense$.pipe( tap(() => this._loadingService.start()), @@ -35,9 +29,16 @@ export class LicenseChartComponent { ); } + constructor( + private readonly _translateService: TranslateService, + private readonly _licenseService: LicenseService, + private readonly _loadingService: LoadingService, + ) {} + async #getLicenseData(license: ILicense): Promise { const startDate = dayjs(license.validFrom); const endDate = dayjs(license.validUntil); + const startDay: number = startDate.date(); const startMonth: number = startDate.month(); const startYear: number = startDate.year(); @@ -48,6 +49,9 @@ export class LicenseChartComponent { dateRanges.push({ startMonth: dt.month(), startYear: dt.year(), endMonth: end.month(), endYear: end.year() }); } + if (dateRanges.length > 0) { + dateRanges[0].startDay = startDay; + } const reports = await this.#getReports(dateRanges, license.id); return this.#mapRangesToReports(startMonth, startYear, dateRanges, reports); @@ -111,7 +115,7 @@ export class LicenseChartComponent { return existingReport; } - const startDate = toDate(startMonth, range.startYear); + const startDate = toDate(startMonth, range.startYear, range.startDay); const endDate = toDate(endMonth, range.endYear); const requestedReport = this._licenseService.getReport({ startDate, endDate }); return requestedReport.then(report => this.#storeReportIfNotCurrentMonth(range, report, key)); diff --git a/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts b/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts index 1c29ba8b2..0dd196237 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts @@ -1,8 +1,8 @@ import dayjs from 'dayjs'; import { IDateRange } from '@red/domain'; -export function toDate(month: number, year: number) { - return dayjs(`01-${month}-${year}`, 'D-M-YYYY').toDate(); +export function toDate(month: number, year: number, day: number = 1) { + return dayjs(`${day}-${month}-${year}`, 'D-M-YYYY').toDate(); } export function isCurrentMonth(month: number, year: number) { diff --git a/apps/red-ui/src/app/services/license.service.ts b/apps/red-ui/src/app/services/license.service.ts index 1d6402870..1ee38480a 100644 --- a/apps/red-ui/src/app/services/license.service.ts +++ b/apps/red-ui/src/app/services/license.service.ts @@ -58,15 +58,6 @@ export class LicenseService extends GenericService { readonly #licenseData$ = new BehaviorSubject(undefined); readonly #selectedLicense$ = new BehaviorSubject(undefined); - constructor(private readonly _logger: NGXLogger) { - super(); - this.selectedLicense$ = this.#selectedLicense$.pipe(filter(license => !!license)); - this.licenseData$ = this.#licenseData$.pipe( - filter(licenses => !!licenses), - tap(data => (this.activeLicenseId = data.activeLicense)), - ); - } - get selectedLicense() { return this.#selectedLicense$.value; } @@ -84,6 +75,15 @@ export class LicenseService extends GenericService { return this.activeLicense.features.find(f => f.name === 'pdftron').value; } + constructor(private readonly _logger: NGXLogger) { + super(); + this.selectedLicense$ = this.#selectedLicense$.pipe(filter(license => !!license)); + this.licenseData$ = this.#licenseData$.pipe( + filter(licenses => !!licenses), + tap(data => (this.activeLicenseId = data.activeLicense)), + ); + } + wipeStoredReportsAndReloadSelectedLicenseData() { this._logger.info('[LICENSE] Wiping stored reports and reloading license data'); this.storedReports = {}; diff --git a/libs/red-domain/src/lib/license/date-range.ts b/libs/red-domain/src/lib/license/date-range.ts index c18962cd6..7a8de5a86 100644 --- a/libs/red-domain/src/lib/license/date-range.ts +++ b/libs/red-domain/src/lib/license/date-range.ts @@ -1,6 +1,8 @@ export interface IDateRange { + readonly startDay: number; readonly startMonth: number; readonly startYear: number; readonly endMonth: number; readonly endYear: number; + readonly endDay: number; }