Skip to content

Commit

Permalink
Export section content to be updated based on config (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin1111 authored Jan 25, 2024
1 parent 08849e1 commit b90a12a
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 22 deletions.
18 changes: 16 additions & 2 deletions src/app/core/models/db/dashboard.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountingErrorType, DefaultImportFields, ExportErrorSourceType, FyleField } from "../enum/enum.model";
import { AccountingErrorType, CCCExpenseState, CCCImportState, DefaultImportFields, ExpenseState, ExportErrorSourceType, FyleField, ReimbursableImportState } from "../enum/enum.model";
import { AccountingGroupedErrors, Error } from "./error.model";

export class DashboardModel {
Expand All @@ -15,7 +15,21 @@ export class DashboardModel {
[AccountingErrorType.CATEGORY_MAPPING]: [],
[AccountingErrorType.ACCOUNTING_ERROR]: []
});
}
}

static getReimbursableExpenseImportStateMap() {
return {
[ExpenseState.PAID]: ReimbursableImportState.PAID,
[ExpenseState.PAYMENT_PROCESSING]: ReimbursableImportState.PROCESSING
};
}

static getCCCExpenseImportStateMap() {
return {
[CCCExpenseState.PAID]: CCCImportState.PAID,
[CCCExpenseState.APPROVED]: CCCImportState.APPROVED
};
}
}

export interface DestinationFieldMap {
Expand Down
1 change: 1 addition & 0 deletions src/app/core/models/db/expense-group.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type SkipExportParam = {
limit: number;
offset: number;
org_id: string;
is_skipped: boolean;
updated_at__gte?: string;
updated_at__lte?: string;
}
11 changes: 10 additions & 1 deletion src/app/core/models/enum/enum.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ export enum ExpenseState {
}

export enum CCCExpenseState {
PAYMENT_PROCESSING = 'PAYMENT_PROCESSING',
PAID = 'PAID',
APPROVED = 'APPROVED'
}
Expand Down Expand Up @@ -633,3 +632,13 @@ export enum TrackingApp {
TRAVELPERK = 'TP',
GUSTO = 'GUSTO'
}

export enum ReimbursableImportState {
PROCESSING = 'processed for payments',
PAID = 'closed'
}

export enum CCCImportState {
APPROVED = 'approved',
PAID = 'closed'
}
3 changes: 2 additions & 1 deletion src/app/core/services/common/export-log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export class ExportLogService {
const params: SkipExportParam = {
limit,
offset,
org_id: this.userService.getUserProfile().org_id
org_id: this.userService.getUserProfile().org_id,
is_skipped: true
};
params.org_id = this.userService.getUserProfile().org_id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
[failedExpenseGroupCount]="failedExpenseGroupCount"
[exportProgressPercentage]="exportProgressPercentage"
[accountingExportSummary]="accountingExportSummary"
[processedCount]="processedCount">
[processedCount]="processedCount"
[reimbursableImportState]="reimbursableImportState"
[cccImportState]="cccImportState">
</app-dashboard-export-section>

<app-zero-state *ngIf="!accountingExportSummary && !exportableAccountingExportIds.length"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BusinessCentralAccountingExport, BusinessCentralAccountingExportRespons
import { AccountingExportSummary } from 'src/app/core/models/db/accounting-export-summary.model';
import { DashboardModel, DestinationFieldMap } from 'src/app/core/models/db/dashboard.model';
import { Error, AccountingGroupedErrorStat, AccountingGroupedErrors, ErrorResponse } from 'src/app/core/models/db/error.model';
import { AccountingErrorType, AccountingExportStatus, AccountingExportType, AppName, BusinessCentralExportType, RefinerSurveyType } from 'src/app/core/models/enum/enum.model';
import { AccountingErrorType, AccountingExportStatus, AccountingExportType, AppName, BusinessCentralExportType, CCCImportState, RefinerSurveyType, ReimbursableImportState } from 'src/app/core/models/enum/enum.model';
import { BusinessCentralExportSettingsService } from 'src/app/core/services/business-central/business-central-configuration/business-central-export-settings.service';
import { AccountingExportService } from 'src/app/core/services/common/accounting-export.service';
import { DashboardService } from 'src/app/core/services/common/dashboard.service';
Expand Down Expand Up @@ -54,6 +54,14 @@ export class BusinessCentralDashboardComponent implements OnInit {

isGradientAllowed: boolean = brandingFeatureConfig.isGradientAllowed;

reimbursableImportState: ReimbursableImportState | null;

private readonly reimbursableExpenseImportStateMap = DashboardModel.getReimbursableExpenseImportStateMap();

cccImportState: CCCImportState | null;

private readonly cccExpenseImportStateMap = DashboardModel.getCCCExpenseImportStateMap();

constructor(
private refinerService: RefinerService,
private dashboardService: DashboardService,
Expand Down Expand Up @@ -129,6 +137,9 @@ export class BusinessCentralDashboardComponent implements OnInit {
'CATEGORY': 'ACCOUNT'
};

this.reimbursableImportState = responses[4].reimbursable_expenses_export_type ? this.reimbursableExpenseImportStateMap[responses[4].reimbursable_expense_state] : null;
this.cccImportState = responses[4].credit_card_expense_export_type ? this.cccExpenseImportStateMap[responses[4].credit_card_expense_state] : null;

if (queuedTasks.length) {
this.isImportInProgress = false;
this.isExportInProgress = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const exportSettingsResponse: BusinessCentralExportSettingGet = {
"reimbursable_expense_date": ExportDateType.LAST_SPENT_AT,
"reimbursable_expense_grouped_by": ExpenseGroupedBy.EXPENSE,
"credit_card_expense_export_type": BusinessCentralExportType.JOURNAL_ENTRY,
"credit_card_expense_state": CCCExpenseState.PAYMENT_PROCESSING,
"credit_card_expense_state": CCCExpenseState.APPROVED,
"credit_card_expense_grouped_by": ExpenseGroupedBy.EXPENSE,
"credit_card_expense_date": ExportDateType.LAST_SPENT_AT,
"updated_at": new Date("2023-10-09T08:18:29.080160Z"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
[failedExpenseGroupCount]="failedExpenseGroupCount"
[exportProgressPercentage]="exportProgressPercentage"
[accountingExportSummary]="accountingExportSummary"
[processedCount]="processedCount">
[processedCount]="processedCount"
[reimbursableImportState]="reimbursableImportState"
[cccImportState]="cccImportState">
</app-dashboard-export-section>

<app-zero-state *ngIf="!accountingExportSummary && !exportableAccountingExportIds.length"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { brandingFeatureConfig } from 'src/app/branding/branding-config';
import { AccountingExportSummary, AccountingExportSummaryModel } from 'src/app/core/models/db/accounting-export-summary.model';
import { DashboardModel, DestinationFieldMap } from 'src/app/core/models/db/dashboard.model';
import { AccountingGroupedErrorStat, AccountingGroupedErrors, Error, ErrorResponse } from 'src/app/core/models/db/error.model';
import { AccountingErrorType, AppName, AppUrl, QBOTaskLogType, TaskLogState } from 'src/app/core/models/enum/enum.model';
import { AccountingErrorType, AppName, AppUrl, CCCExpenseState, CCCImportState, ExpenseState, QBOTaskLogType, ReimbursableImportState, TaskLogState } from 'src/app/core/models/enum/enum.model';
import { QBOTaskLog, QBOTaskResponse } from 'src/app/core/models/qbo/db/qbo-task-log.model';
import { AccountingExportService } from 'src/app/core/services/common/accounting-export.service';
import { DashboardService } from 'src/app/core/services/common/dashboard.service';
import { WorkspaceService } from 'src/app/core/services/common/workspace.service';
import { QboExportSettingsService } from 'src/app/core/services/qbo/qbo-configuration/qbo-export-settings.service';

@Component({
selector: 'app-qbo-dashboard',
Expand Down Expand Up @@ -52,13 +53,22 @@ export class QboDashboardComponent implements OnInit {

isImportItemsEnabled: boolean;

reimbursableImportState: ReimbursableImportState | null;

private readonly reimbursableExpenseImportStateMap = DashboardModel.getReimbursableExpenseImportStateMap();

cccImportState: CCCImportState | null;

private readonly cccExpenseImportStateMap = DashboardModel.getCCCExpenseImportStateMap();

AppUrl = AppUrl;

readonly isGradientAllowed: boolean = brandingFeatureConfig.isGradientAllowed;

constructor(
private accountingExportService: AccountingExportService,
private dashboardService: DashboardService,
private qboExportSettingsService: QboExportSettingsService,
private workspaceService: WorkspaceService
) { }

Expand Down Expand Up @@ -111,7 +121,8 @@ export class QboDashboardComponent implements OnInit {
this.getAccountingExportSummary$.pipe(catchError(() => of(null))),
this.dashboardService.getAllTasks([TaskLogState.ENQUEUED, TaskLogState.IN_PROGRESS, TaskLogState.FAILED], undefined, this.accountingExportType),
this.workspaceService.getWorkspaceGeneralSettings(),
this.dashboardService.getExportableAccountingExportIds('v1')
this.dashboardService.getExportableAccountingExportIds('v1'),
this.qboExportSettingsService.getExportSettings()
]).subscribe((responses) => {
this.errors = DashboardModel.parseAPIResponseToGroupedError(responses[0]);
this.isImportItemsEnabled = responses[3].import_items;
Expand All @@ -130,6 +141,9 @@ export class QboDashboardComponent implements OnInit {

this.exportableAccountingExportIds = responses[4].exportable_expense_group_ids;

this.reimbursableImportState = responses[5].workspace_general_settings.reimbursable_expenses_object ? this.reimbursableExpenseImportStateMap[responses[5].expense_group_settings.expense_state] : null;
this.cccImportState = responses[5].workspace_general_settings.corporate_credit_card_expenses_object ? this.cccExpenseImportStateMap[responses[5].expense_group_settings.ccc_expense_state] : null;

if (queuedTasks.length) {
this.isImportInProgress = false;
this.isExportInProgress = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
[failedExpenseGroupCount]="failedExpenseGroupCount"
[exportProgressPercentage]="exportProgressPercentage"
[accountingExportSummary]="accountingExportSummary"
[processedCount]="processedCount">
[processedCount]="processedCount"
[reimbursableImportState]="reimbursableImportState"
[cccImportState]="cccImportState">
</app-dashboard-export-section>

<app-zero-state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Observable, catchError, forkJoin, from, interval, map, of, switchMap, takeWhile } from 'rxjs';
import { Error, AccountingGroupedErrorStat, AccountingGroupedErrors, ErrorResponse } from 'src/app/core/models/db/error.model';
import { AccountingErrorType, AccountingExportStatus, AccountingExportType, AppName, FyleField, LoaderType, RefinerSurveyType } from 'src/app/core/models/enum/enum.model';
import { AccountingErrorType, AccountingExportStatus, AccountingExportType, AppName, CCCImportState, FyleField, LoaderType, RefinerSurveyType, ReimbursableImportState } from 'src/app/core/models/enum/enum.model';
import { DashboardService } from 'src/app/core/services/common/dashboard.service';
import { RefinerService } from 'src/app/core/services/integration/refiner.service';
import { environment } from 'src/environments/environment';
Expand All @@ -10,6 +10,7 @@ import { DashboardModel, DestinationFieldMap } from 'src/app/core/models/db/dash
import { Sage300AccountingExportResponse, Sage300AccountingExport } from 'src/app/core/models/sage300/db/sage300-accounting-export.model';
import { AccountingExportService } from 'src/app/core/services/common/accounting-export.service';
import { brandingFeatureConfig } from 'src/app/branding/branding-config';
import { Sage300ExportSettingService } from 'src/app/core/services/sage300/sage300-configuration/sage300-export-setting.service';

@Component({
selector: 'app-sage300-dashboard',
Expand Down Expand Up @@ -56,12 +57,21 @@ export class Sage300DashboardComponent implements OnInit {

LoaderType = LoaderType;

reimbursableImportState: ReimbursableImportState | null;

private readonly reimbursableExpenseImportStateMap = DashboardModel.getReimbursableExpenseImportStateMap();

cccImportState: CCCImportState | null;

private readonly cccExpenseImportStateMap = DashboardModel.getCCCExpenseImportStateMap();

readonly isGradientAllowed: boolean = brandingFeatureConfig.isGradientAllowed;

constructor(
private refinerService: RefinerService,
private accountingExportService: AccountingExportService,
private dashboardService: DashboardService,
private accountingExportService: AccountingExportService
private refinerService: RefinerService,
private sage300ExportSettingService: Sage300ExportSettingService
) { }

private pollExportStatus(exportableAccountingExportIds: number[] = []): void {
Expand Down Expand Up @@ -118,13 +128,19 @@ export class Sage300DashboardComponent implements OnInit {
this.getExportErrors$,
this.getAccountingExportSummary$.pipe(catchError(() => of(null))),
this.accountingExportService.getAccountingExports(this.accountingExportType, [AccountingExportStatus.ENQUEUED, AccountingExportStatus.IN_PROGRESS, AccountingExportStatus.EXPORT_QUEUED, AccountingExportStatus.FAILED, AccountingExportStatus.FATAL], [], 500, 0),
this.dashboardService.getExportableAccountingExportIds()
this.dashboardService.getExportableAccountingExportIds(),
this.sage300ExportSettingService.getSage300ExportSettings()
]).subscribe((responses) => {
this.errors = DashboardModel.parseAPIResponseToGroupedError(responses[0].results);
this.accountingExportSummary = responses[1];
this.exportableAccountingExportIds = responses[3].exportable_accounting_export_ids;

const queuedTasks: Sage300AccountingExport[] = responses[2].results.filter((accountingExport: Sage300AccountingExport) => accountingExport.status === AccountingExportStatus.ENQUEUED || accountingExport.status === AccountingExportStatus.IN_PROGRESS || accountingExport.status === AccountingExportStatus.EXPORT_QUEUED);
this.failedExpenseGroupCount = responses[2].results.filter((accountingExport: Sage300AccountingExport) => accountingExport.status === AccountingExportStatus.FAILED || accountingExport.status === AccountingExportStatus.FATAL).length;

this.reimbursableImportState = responses[4].reimbursable_expenses_export_type ? this.reimbursableExpenseImportStateMap[responses[4].reimbursable_expense_state] : null;
this.cccImportState = responses[4].credit_card_expense_export_type ? this.cccExpenseImportStateMap[responses[4].credit_card_expense_state] : null;

if (queuedTasks.length) {
this.isImportInProgress = false;
this.isExportInProgress = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ <h3 class="tw-text-20-px tw-font-500 tw-text-slightly-normal-text-color" *ngIf="
<h3 class="tw-text-20-px tw-font-500 tw-text-slightly-normal-text-color" *ngIf="!isExportInProgress && !exportableAccountingExportIds.length && accountingExportSummary?.successful_accounting_export_count">You are all caught up!</h3>
<svg-icon-sprite src="info" width="16px" height="16px" class="tw-text-info tw-ml-4-px" pTooltip="All expenses that have reached your export state in {{brandingConfig.brandName}} will be automatically imported and kept ready for export."></svg-icon-sprite>
</div>
<h5 class="tw-text-14-px tw-font-400 tw-text-slightly-normal-text-color tw-pl-34-px tw-pt-8-px" *ngIf="!isExportInProgress && !exportableAccountingExportIds.length && !accountingExportSummary">No new expenses to export in the configured state of export in {{brandingConfig.brandName}}. Once you start processing payments or closing your expenses, they will be automatically available here.</h5>
<h5 class="tw-text-14-px tw-font-400 tw-text-slightly-normal-text-color tw-pl-34-px tw-pt-8-px" *ngIf="!isExportInProgress && !exportableAccountingExportIds.length && !accountingExportSummary">
No new expenses to export right now
<br>
Once expenses are {{ importStates }}, they'll automatically be available here for export
</h5>
<h5 class="tw-text-14-px tw-font-400 tw-text-slightly-normal-text-color tw-pl-34-px tw-pt-8-px" *ngIf="isExportInProgress">This may take a few minutes...</h5>
<h5 class="tw-text-14-px tw-font-400 tw-text-slightly-normal-text-color tw-pl-34-px tw-pt-8-px" *ngIf="!isExportInProgress && !exportableAccountingExportIds.length && accountingExportSummary?.successful_accounting_export_count">No new expenses to export from the payment processing state in {{brandingConfig.brandName}}.<br>Once you start processing payment for the expenses, they will be automatically available here to export.</h5>
<h5 class="tw-text-14-px tw-font-400 tw-text-slightly-normal-text-color tw-pl-34-px tw-pt-8-px" *ngIf="!isExportInProgress && !exportableAccountingExportIds.length && accountingExportSummary?.successful_accounting_export_count">
No new expenses to export right now
<br>
Once expenses are {{ importStates }}, they'll automatically be available here for export
</h5>
<div *ngIf="!isExportInProgress && failedExpenseGroupCount !== null && failedExpenseGroupCount > 0" fxLayout="row" fxFlex="4" class="tw-text-14-px tw-font-500 tw-text-slightly-normal-text-color tw-pl-34-px tw-pt-8-px tw-flex">
<h5>{{ exportableAccountingExportIds.length - failedExpenseGroupCount > 0 ? exportableAccountingExportIds.length - failedExpenseGroupCount : 0 }} new expense{{(exportableAccountingExportIds.length - failedExpenseGroupCount) > 1 ? 's' : ''}}, {{ failedExpenseGroupCount }} previously failed expense{{failedExpenseGroupCount > 1 ? 's' : ''}}</h5>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { brandingConfig } from 'src/app/branding/branding-config';
import { AccountingExportSummary } from 'src/app/core/models/db/accounting-export-summary.model';
import { AppName, LoaderType } from 'src/app/core/models/enum/enum.model';
import { AppName, CCCImportState, LoaderType, ReimbursableImportState } from 'src/app/core/models/enum/enum.model';

@Component({
selector: 'app-dashboard-export-section',
Expand All @@ -28,17 +28,38 @@ export class DashboardExportSectionComponent implements OnInit {

@Input() loaderType: LoaderType = LoaderType.DETERMINATE;

@Input() reimbursableImportState: ReimbursableImportState | null;

@Input() cccImportState: CCCImportState | null;

@Output() export = new EventEmitter<boolean>();

readonly brandingConfig = brandingConfig;

importStates: string;

constructor() { }

triggerExport() {
this.export.emit(true);
}

private constructImportStates() {
if (this.reimbursableImportState === ReimbursableImportState.PAID && this.cccImportState === CCCImportState.PAID) {
this.importStates = ReimbursableImportState.PAID;
} else {
if (this.reimbursableImportState && this.cccImportState) {
this.importStates = this.reimbursableImportState + ' or ' + this.cccImportState;
} else if (this.reimbursableImportState) {
this.importStates = this.reimbursableImportState;
} else if (this.cccImportState) {
this.importStates = this.cccImportState;
}
}
}

ngOnInit(): void {
this.constructImportStates();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ export class ExportSettingComponent implements OnInit {
private setUpExpenseStates(): void {
this.cccExpenseStateOptions = [
{
label: this.is_simplify_report_closure_enabled ? 'Approved' : 'Payment Processing',
value: this.is_simplify_report_closure_enabled ? CCCExpenseState.APPROVED: CCCExpenseState.PAYMENT_PROCESSING
label: 'Approved',
value: CCCExpenseState.APPROVED
},
{
label: this.is_simplify_report_closure_enabled ? 'Closed' : 'Paid',
Expand Down
Loading

0 comments on commit b90a12a

Please sign in to comment.