From dfde884e62b93b962224082ec94423188bb8c5f0 Mon Sep 17 00:00:00 2001 From: anishfyle Date: Tue, 26 Nov 2024 16:04:41 +0530 Subject: [PATCH] handle export settings and app name --- .../models/common/advanced-settings.model.ts | 20 +++++++++++++++++++ .../netsuite-advanced-settings.model.ts | 15 +++++++++++++- .../netsuite-advanced-settings.component.ts | 16 ++++++++++----- .../qbo-clone-settings.component.ts | 2 ++ .../qbo-advanced-settings.component.ts | 11 ++++++---- 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/app/core/models/common/advanced-settings.model.ts b/src/app/core/models/common/advanced-settings.model.ts index 3c9764c78..302304005 100644 --- a/src/app/core/models/common/advanced-settings.model.ts +++ b/src/app/core/models/common/advanced-settings.model.ts @@ -1,6 +1,9 @@ import { FormControl, FormGroup } from "@angular/forms"; import { JoinOption, Operator } from "../enum/enum.model"; import { environment } from "src/environments/environment"; +import { ExportSettingGet } from "../intacct/intacct-configuration/export-settings.model"; +import { QBOExportSettingGet } from "../qbo/qbo-configuration/qbo-export-setting.model"; +import { NetSuiteExportSettingGet } from "../netsuite/netsuite-configuration/netsuite-export-setting.model"; export type EmailOption = { email: string; @@ -72,6 +75,23 @@ export class AdvancedSettingsModel { return ['employee_email', 'employee_name', 'merchant', 'purpose', 'category', 'spent_on', 'report_number', 'expense_link', 'card_number']; } + static getMemoOptions(exportSettings: ExportSettingGet | NetSuiteExportSettingGet | QBOExportSettingGet, appName: string): string[] { + const defaultOptions = this.getDefaultMemoOptions(); + let cccExportType: string | undefined; + + // Extract cccExportType based on the type of exportSettings + if ('configurations' in exportSettings) { + cccExportType = exportSettings.configurations.corporate_credit_card_expenses_object ?? undefined; + } + + // Filter out options based on cccExportType and appName + if (cccExportType && ['netsuite', 'qbo', 'sage intacct'].includes(appName.toLowerCase())) { + return defaultOptions; // Allow all options including 'card_number' + } else { + return defaultOptions.filter(option => option !== 'card_number'); // Omit 'card_number' for other apps + } + } + static formatMemoPreview(memoStructure: string[], defaultMemoOptions: string[]): [string, string[]] { const time = Date.now(); const today = new Date(time); diff --git a/src/app/core/models/netsuite/netsuite-configuration/netsuite-advanced-settings.model.ts b/src/app/core/models/netsuite/netsuite-configuration/netsuite-advanced-settings.model.ts index 5bbb15784..e9c620e94 100644 --- a/src/app/core/models/netsuite/netsuite-configuration/netsuite-advanced-settings.model.ts +++ b/src/app/core/models/netsuite/netsuite-configuration/netsuite-advanced-settings.model.ts @@ -1,11 +1,12 @@ import { FormControl, FormGroup } from "@angular/forms"; import { EmailOption, SelectFormOption } from "../../common/select-form-option.model"; import { DefaultDestinationAttribute } from "../../db/destination-attribute.model"; -import { NetsuiteDefaultLevelOptions, NetsuitePaymentSyncDirection, PaymentSyncDirection } from "../../enum/enum.model"; +import { AppName, NetsuiteDefaultLevelOptions, NetsuitePaymentSyncDirection, PaymentSyncDirection } from "../../enum/enum.model"; import { AdvancedSettingValidatorRule, AdvancedSettingsModel } from "../../common/advanced-settings.model"; import { HelperUtility } from "../../common/helper.model"; import { brandingConfig } from "src/app/branding/branding-config"; import { environment } from "src/environments/environment"; +import { NetSuiteExportSettingGet } from "./netsuite-export-setting.model"; export type NetsuiteAdvancedSettingConfiguration = { @@ -70,6 +71,18 @@ export class NetsuiteAdvancedSettingModel extends HelperUtility { return ['employee_email', 'employee_name', 'merchant', 'purpose', 'category', 'spent_on', 'report_number', 'card_number']; } + static getMemoOptions(exportSettings: NetSuiteExportSettingGet, appName: AppName): string[] { + const defaultOptions = this.getDefaultMemoOptions(); + const cccExportType = exportSettings.configuration.corporate_credit_card_expenses_object; + + // Filter out options based on cccExportType and appName + if (cccExportType && [AppName.NETSUITE, AppName.QBO, AppName.INTACCT].includes(appName as AppName)) { + return defaultOptions; // Allow all options including 'card_number' + } else { + return defaultOptions.filter(option => option !== 'card_number'); // Omit 'card_number' for other apps + } + } + static getPaymentSyncOptions(): SelectFormOption[] { return [ { diff --git a/src/app/integrations/netsuite/netsuite-shared/netsuite-advanced-settings/netsuite-advanced-settings.component.ts b/src/app/integrations/netsuite/netsuite-shared/netsuite-advanced-settings/netsuite-advanced-settings.component.ts index 09227cbcb..1224b984b 100644 --- a/src/app/integrations/netsuite/netsuite-shared/netsuite-advanced-settings/netsuite-advanced-settings.component.ts +++ b/src/app/integrations/netsuite/netsuite-shared/netsuite-advanced-settings/netsuite-advanced-settings.component.ts @@ -10,7 +10,7 @@ import { DefaultDestinationAttribute, DestinationAttribute } from 'src/app/core/ import { AppName, AutoMapEmployeeOptions, ConfigurationCta, EmployeeFieldMapping, NameInJournalEntry, NetSuiteCorporateCreditCardExpensesObject, NetsuiteOnboardingState, NetsuiteReimbursableExpensesObject, ToastSeverity } from 'src/app/core/models/enum/enum.model'; import { NetsuiteConfiguration } from 'src/app/core/models/netsuite/db/netsuite-workspace-general-settings.model'; import { NetsuiteAdvancedSettingGet, NetsuiteAdvancedSettingModel } from 'src/app/core/models/netsuite/netsuite-configuration/netsuite-advanced-settings.model'; -import { NetSuiteExportSettingModel } from 'src/app/core/models/netsuite/netsuite-configuration/netsuite-export-setting.model'; +import { NetSuiteExportSettingGet, NetSuiteExportSettingModel } from 'src/app/core/models/netsuite/netsuite-configuration/netsuite-export-setting.model'; import { Org } from 'src/app/core/models/org/org.model'; import { ConfigurationService } from 'src/app/core/services/common/configuration.service'; import { HelperService } from 'src/app/core/services/common/helper.service'; @@ -19,6 +19,7 @@ import { MappingService } from 'src/app/core/services/common/mapping.service'; import { SkipExportService } from 'src/app/core/services/common/skip-export.service'; import { WorkspaceService } from 'src/app/core/services/common/workspace.service'; import { NetsuiteAdvancedSettingsService } from 'src/app/core/services/netsuite/netsuite-configuration/netsuite-advanced-settings.service'; +import { NetsuiteExportSettingsService } from 'src/app/core/services/netsuite/netsuite-configuration/netsuite-export-settings.service'; import { NetsuiteConnectorService } from 'src/app/core/services/netsuite/netsuite-core/netsuite-connector.service'; import { NetsuiteHelperService } from 'src/app/core/services/netsuite/netsuite-core/netsuite-helper.service'; import { OrgService } from 'src/app/core/services/org/org.service'; @@ -52,6 +53,8 @@ export class NetsuiteAdvancedSettingsComponent implements OnInit { advancedSetting: NetsuiteAdvancedSettingGet; + exportSettings: NetSuiteExportSettingGet; + expenseFilters: ExpenseFilterResponse; conditionFieldOptions: ConditionField[]; @@ -111,7 +114,8 @@ export class NetsuiteAdvancedSettingsComponent implements OnInit { private skipExportService: SkipExportService, private toastService: IntegrationsToastService, private workspaceService: WorkspaceService, - private orgService: OrgService + private orgService: OrgService, + private exportSettingsService: NetsuiteExportSettingsService ) { } isOptional(): string { @@ -261,12 +265,14 @@ export class NetsuiteAdvancedSettingsComponent implements OnInit { this.mappingService.getGroupedDestinationAttributes(['LOCATION', 'DEPARTMENT', 'CLASS', 'VENDOR_PAYMENT_ACCOUNT'], 'v2', 'netsuite'), this.configurationService.getAdditionalEmails(), this.workspaceService.getConfiguration(), - this.netsuiteConnectorService.getSubsidiaryMapping() - ]).subscribe(([netsuiteAdvancedSetting, expenseFiltersGet, expenseFilterCondition, netsuiteAttributes, adminEmails, workspaceGeneralSettings, subsidiaryMapping]) => { + this.netsuiteConnectorService.getSubsidiaryMapping(), + this.exportSettingsService.getExportSettings() + ]).subscribe(([netsuiteAdvancedSetting, expenseFiltersGet, expenseFilterCondition, netsuiteAttributes, adminEmails, workspaceGeneralSettings, subsidiaryMapping, exportSettings]) => { this.advancedSetting = netsuiteAdvancedSetting; this.expenseFilters = expenseFiltersGet; this.conditionFieldOptions = expenseFilterCondition; - + this.exportSettings = exportSettings; + this.defaultMemoOptions = NetsuiteAdvancedSettingModel.getMemoOptions(this.exportSettings, this.appName); this.adminEmails = adminEmails; if (this.advancedSetting.workspace_schedules?.additional_email_options && this.advancedSetting.workspace_schedules?.additional_email_options.length > 0) { this.adminEmails = this.adminEmails.concat(this.advancedSetting.workspace_schedules?.additional_email_options); diff --git a/src/app/integrations/qbo/qbo-onboarding/qbo-clone-settings/qbo-clone-settings.component.ts b/src/app/integrations/qbo/qbo-onboarding/qbo-clone-settings/qbo-clone-settings.component.ts index 84063f6b8..3bc0aa6e0 100644 --- a/src/app/integrations/qbo/qbo-onboarding/qbo-clone-settings/qbo-clone-settings.component.ts +++ b/src/app/integrations/qbo/qbo-onboarding/qbo-clone-settings/qbo-clone-settings.component.ts @@ -511,6 +511,8 @@ export class QboCloneSettingsComponent implements OnInit { this.setupAdvancedSettingFormWatcher(); + this.defaultMemoOptions = AdvancedSettingsModel.getMemoOptions(this.cloneSetting.export_settings, AppName.QBO); + this.isLoading = false; }); }); diff --git a/src/app/integrations/qbo/qbo-shared/qbo-advanced-settings/qbo-advanced-settings.component.ts b/src/app/integrations/qbo/qbo-shared/qbo-advanced-settings/qbo-advanced-settings.component.ts index f8d5248b4..9fc4364df 100644 --- a/src/app/integrations/qbo/qbo-shared/qbo-advanced-settings/qbo-advanced-settings.component.ts +++ b/src/app/integrations/qbo/qbo-shared/qbo-advanced-settings/qbo-advanced-settings.component.ts @@ -19,6 +19,7 @@ import { SkipExportService } from 'src/app/core/services/common/skip-export.serv import { WorkspaceService } from 'src/app/core/services/common/workspace.service'; import { OrgService } from 'src/app/core/services/org/org.service'; import { QboAdvancedSettingsService } from 'src/app/core/services/qbo/qbo-configuration/qbo-advanced-settings.service'; +import { QboExportSettingsService } from 'src/app/core/services/qbo/qbo-configuration/qbo-export-settings.service'; import { QboHelperService } from 'src/app/core/services/qbo/qbo-core/qbo-helper.service'; @Component({ @@ -93,7 +94,8 @@ export class QboAdvancedSettingsComponent implements OnInit { private skipExportService: SkipExportService, private toastService: IntegrationsToastService, private workspaceService: WorkspaceService, - private orgService: OrgService + private orgService: OrgService, + private exportSettingsService: QboExportSettingsService ) { } @@ -229,8 +231,9 @@ export class QboAdvancedSettingsComponent implements OnInit { this.skipExportService.getExpenseFields('v1'), this.mappingService.getGroupedDestinationAttributes(['BANK_ACCOUNT'], 'v1', 'qbo'), this.configurationService.getAdditionalEmails(), - this.workspaceService.getWorkspaceGeneralSettings() - ]).subscribe(([sage300AdvancedSettingResponse, expenseFiltersGet, expenseFilterCondition, billPaymentAccounts, adminEmails, workspaceGeneralSettings]) => { + this.workspaceService.getWorkspaceGeneralSettings(), + this.exportSettingsService.getExportSettings() + ]).subscribe(([sage300AdvancedSettingResponse, expenseFiltersGet, expenseFilterCondition, billPaymentAccounts, adminEmails, workspaceGeneralSettings, exportSettings]) => { this.advancedSetting = sage300AdvancedSettingResponse; this.expenseFilters = expenseFiltersGet; this.conditionFieldOptions = expenseFilterCondition; @@ -248,7 +251,7 @@ export class QboAdvancedSettingsComponent implements OnInit { this.advancedSettingForm = QBOAdvancedSettingModel.mapAPIResponseToFormGroup(this.advancedSetting, isSkipExportEnabled, this.adminEmails, this.helper.shouldAutoEnableAccountingPeriod(this.org.created_at)); this.skipExportForm = SkipExportModel.setupSkipExportForm(this.expenseFilters, [], this.conditionFieldOptions); - + this.defaultMemoOptions = AdvancedSettingsModel.getMemoOptions(exportSettings, AppName.QBO); this.setupFormWatchers(); this.isLoading = false; });