Skip to content

Commit

Permalink
increase the fiscal year availability (#367)
Browse files Browse the repository at this point in the history
Signed-off-by: David <daveclaveau@gmail.com>
  • Loading branch information
davidclaveau authored Aug 27, 2024
1 parent c811d77 commit c4f5b6f
Showing 1 changed file with 61 additions and 40 deletions.
101 changes: 61 additions & 40 deletions src/app/export-reports/export-reports.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ChangeDetectorRef, Component, OnDestroy } from '@angular/core';
import { ChangeDetectorRef, Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { DataService } from '../services/data.service';
import { ExportService } from '../services/export.service';
import { Constants } from '../shared/utils/constants';
import { DateTime, Duration } from 'luxon'
import { DateTime, Duration } from 'luxon';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';

@Component({
Expand Down Expand Up @@ -44,12 +44,12 @@ export class ExportReportsComponent implements OnDestroy {
public tz = Constants.timezone;
public maxDate = DateTime.now().setZone(this.tz);
// negate duration so we can pick the end date first
public duration = Duration.fromObject({years: 1}).negate();
public duration = Duration.fromObject({ years: 1 }).negate();
public dateFormat = 'yyyy-LL';

public form = new UntypedFormGroup({
year: new UntypedFormControl(null)
})
year: new UntypedFormControl(null),
});

public exportMessage = 'Last export: -';

Expand All @@ -58,44 +58,52 @@ export class ExportReportsComponent implements OnDestroy {
constructor(
private exportService: ExportService,
private dataService: DataService,
private cd: ChangeDetectorRef
private cd: ChangeDetectorRef,
) {
this.subscriptions.add(
this.dataService.watchItem(Constants.dataIds.EXPORT_VARIANCE_POLLING_DATA)
.subscribe((res) => {
this.jobUpdate(res);
})
)
this.dataService
.watchItem(Constants.dataIds.EXPORT_VARIANCE_POLLING_DATA)
.subscribe((res) => {
this.jobUpdate(res);
}),
);
this.subscriptions.add(
this.form.controls['year'].valueChanges.subscribe((changes) => {
const startDate = DateTime.fromFormat(changes[1], this.dateFormat).plus({months: 2});
const endDate = DateTime.fromFormat(changes[0], this.dateFormat).plus({months: 3});
this.form.controls['year'].setValue([
const startDate = DateTime.fromFormat(changes[1], this.dateFormat).plus(
{ months: 2 },
);
const endDate = DateTime.fromFormat(changes[0], this.dateFormat).plus({
months: 3,
});
this.form.controls['year'].setValue(
[
startDate.toFormat(this.dateFormat),
endDate.toFormat(this.dateFormat),
],
{
emitEvent: false
})
})
)
emitEvent: false,
},
);
}),
);
this.subscriptions.add(
this.dataService.watchItem(Constants.dataIds.EXPORT_ALL_POLLING_DATA)
this.dataService
.watchItem(Constants.dataIds.EXPORT_ALL_POLLING_DATA)
.subscribe((res) => {
this.jobUpdate(res);
}
));
}),
);
}

// setMaxDate() {
// // get current fiscal year
// const currentDT = DateTime.now();
// let year = currentDT.year;
// if (currentDT.month > 3){
// year += 1;
// }
// this.maxDate = new Date(year, 2, 31);
// }
setMaxDate() {
// get current fiscal year
const currentDT = DateTime.now();
let year = currentDT.year;
if (currentDT.month > 3) {
year += 1;
}
this.maxDate = DateTime.local(year);
}

jobUpdate(res) {
if (res) {
Expand All @@ -121,9 +129,7 @@ export class ExportReportsComponent implements OnDestroy {
this.setExportMessage(res);
}

this.signedURL = res?.['signedURL']
? res?.['signedURL']
: undefined;
this.signedURL = res?.['signedURL'] ? res?.['signedURL'] : undefined;
}
}

Expand All @@ -145,13 +151,16 @@ export class ExportReportsComponent implements OnDestroy {
this.setState(this.stateDictionary.GENERATING);
this.setExportMessage(null);
if (this.activeTab === 'variance') {
const year = this.form.controls['year'].value[1].slice(0,4);
const year = this.form.controls['year'].value[1].slice(0, 4);
this.exportService.generateReport(
Constants.dataIds.EXPORT_VARIANCE_POLLING_DATA, 'variance', { fiscalYearEnd: year }
Constants.dataIds.EXPORT_VARIANCE_POLLING_DATA,
'variance',
{ fiscalYearEnd: year },
);
} else {
this.exportService.generateReport(
Constants.dataIds.EXPORT_ALL_POLLING_DATA, 'standard'
Constants.dataIds.EXPORT_ALL_POLLING_DATA,
'standard',
);
}
this.cd.detectChanges();
Expand Down Expand Up @@ -225,11 +234,18 @@ export class ExportReportsComponent implements OnDestroy {
this.setExportMessage(null);
if (this.activeTab === 'variance') {
if (this.modelDate) {
this.exportService.checkForReports(Constants.dataIds.EXPORT_VARIANCE_POLLING_DATA, 'variance', { fiscalYearEnd: this.modelDate });
this.exportService.checkForReports(
Constants.dataIds.EXPORT_VARIANCE_POLLING_DATA,
'variance',
{ fiscalYearEnd: this.modelDate },
);
}
return;
} else {
this.exportService.checkForReports(Constants.dataIds.EXPORT_ALL_POLLING_DATA, 'standard');
this.exportService.checkForReports(
Constants.dataIds.EXPORT_ALL_POLLING_DATA,
'standard',
);
}
this.cd.detectChanges();
return;
Expand All @@ -244,7 +260,8 @@ export class ExportReportsComponent implements OnDestroy {
) {
if (res?.jobObj?.dateGenerated) {
if (res.jobObj.progressState === 'error') {
this.dateGenerated = new Date(res.jobObj.lastSuccessfulJob?.dateGenerated) || undefined;
this.dateGenerated =
new Date(res.jobObj.lastSuccessfulJob?.dateGenerated) || undefined;
} else {
this.dateGenerated = new Date(res.jobObj.dateGenerated);
}
Expand Down Expand Up @@ -272,7 +289,11 @@ export class ExportReportsComponent implements OnDestroy {
return true;
}
return false;
} s
}

ngOnInit() {
this.setMaxDate();
}

ngOnDestroy() {
this.subscriptions.unsubscribe();
Expand Down

0 comments on commit c4f5b6f

Please sign in to comment.