Skip to content

Commit

Permalink
import name with code from sage 300 cre mapping (#890)
Browse files Browse the repository at this point in the history
import name with code from sage 300 cre
  • Loading branch information
DhaaraniCIT authored Aug 22, 2024
1 parent 0550917 commit 3a2b763
Show file tree
Hide file tree
Showing 28 changed files with 424 additions and 90 deletions.
23 changes: 18 additions & 5 deletions src/app/core/models/common/import-settings.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { Sage300ImportSettingGet } from "../sage300/sage300-configuration/sage30
export type ImportDefaultField = {
destination_field: string,
source_field: string,
formController: string
formController: string,
import_code?: string
}

export type ExpenseField = {
Expand All @@ -30,7 +31,8 @@ export type ImportSettingMappingRow = {
import_to_fyle: boolean,
is_custom: boolean,
source_field: string,
source_placeholder: string | null
source_placeholder: string | null,
import_code?: boolean
}

export type ImportSettingsCustomFieldRow = {
Expand All @@ -40,6 +42,10 @@ export type ImportSettingsCustomFieldRow = {
is_dependent: boolean
}

export type ImportCodeFieldConfigType = {
[key: string]: boolean;
};

export class ImportSettingsModel {

static getCustomFieldOption(): ExpenseField[] {
Expand All @@ -52,11 +58,16 @@ export class ImportSettingsModel {
destination_field: new FormControl(data.destination_field || '', RxwebValidators.unique()),
import_to_fyle: new FormControl(data.import_to_fyle || false),
is_custom: new FormControl(data.is_custom || false),
source_placeholder: new FormControl(data.source_placeholder || null)
source_placeholder: new FormControl(data.source_placeholder || null),
import_code: new FormControl(data.import_code)
});
}

static constructFormArray(importSettingsMappingSettings: ImportSettingMappingRow[] | [], accountingAppFields: IntegrationField[], isDestinationFixedImport: boolean = true): FormGroup[] {
static getImportCodeField(importCodeFields: string[], destinationField: string): boolean {
return importCodeFields.includes(destinationField);
}

static constructFormArray(importSettingsMappingSettings: ImportSettingMappingRow[], accountingAppFields: IntegrationField[], isDestinationFixedImport: boolean = true, importCodeFields: string[] | [] = []): FormGroup[] {
const expenseFieldFormArray: FormGroup[] = [];
const mappedFieldMap = new Map<string, any>();
const unmappedFieldMap = new Map<string, any>();
Expand All @@ -72,9 +83,11 @@ export class ImportSettingsModel {
import_to_fyle: false,
is_custom: false,
source_field: '',
source_placeholder: null
source_placeholder: null,
import_code: null
};
if (mappingSetting) {
fieldData.import_code = fieldData.import_to_fyle ? this.getImportCodeField(importCodeFields, accountingAppField.attribute_type) : null;
mappedFieldMap.set(accountingAppField.attribute_type, fieldData);
} else {
unmappedFieldMap.set(accountingAppField.attribute_type, fieldData);
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/models/common/select-form-option.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type SelectFormOption = {
label: string;
value: string | null | number;
value: string | null | number | boolean;
subLabel?: string;
}

export type SelectFormLabel = {
Expand Down
1 change: 1 addition & 0 deletions src/app/core/models/db/destination-attribute.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type DestinationAttribute = {
value: string;
destination_id: string;
active: boolean;
code?: string;
created_at: Date;
updated_at: Date;
workspace: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { IntegrationField } from "../../db/mapping.model";
export type Sage300DefaultFields = {
destination_field: string,
source_field: string,
formController: string
formController: string,
import_code: string
}

export type Sage300DependentImportFields = {
Expand All @@ -27,7 +28,8 @@ export type Sage300ImportSetting = {
import_settings: {
import_categories: boolean,
import_vendors_as_merchants: boolean,
add_commitment_details: boolean
add_commitment_details: boolean,
import_code_fields: string[] | [],
},
mapping_settings: ImportSettingMappingRow[] | [],
dependent_field_settings: Sage300ImportSettingsDependentFieldSetting | null,
Expand All @@ -51,10 +53,14 @@ export class Sage300ImportSettingModel extends ImportSettingsModel {
}

static mapAPIResponseToFormGroup(importSettings: Sage300ImportSettingGet | null, sage300Fields: IntegrationField[]): FormGroup {
const expenseFieldsArray = importSettings?.mapping_settings ? this.constructFormArray(importSettings.mapping_settings, sage300Fields, false) : [] ;
const importCode = importSettings?.import_settings?.import_code_fields ? importSettings?.import_settings?.import_code_fields : [];
const expenseFieldsArray = importSettings?.mapping_settings ? this.constructFormArray(importSettings.mapping_settings, sage300Fields, false, importCode) : [] ;
return new FormGroup({
importCodeFields: new FormControl(importSettings?.import_settings?.import_code_fields ? importSettings?.import_settings.import_code_fields : []),
importCategories: new FormControl(importSettings?.import_settings?.import_categories ?? false),
importCategoryCode: new FormControl(importSettings?.import_settings?.import_categories ? this.getImportCodeField(importCode, 'ACCOUNT') : null),
importVendorAsMerchant: new FormControl(importSettings?.import_settings?.import_vendors_as_merchants ?? false),
importVendorCode: new FormControl(importSettings?.import_settings?.import_vendors_as_merchants ? this.getImportCodeField(importCode, 'VENDOR') : null),
expenseFields: new FormArray(expenseFieldsArray),
isDependentImportEnabled: new FormControl(importSettings?.dependent_field_settings?.is_import_enabled ? importSettings.dependent_field_settings.is_import_enabled : false),
costCodes: new FormControl(importSettings?.dependent_field_settings?.cost_code_field_name ? this.generateDependentFieldValue(importSettings.dependent_field_settings.cost_code_field_name, importSettings.dependent_field_settings.cost_code_placeholder) : null),
Expand All @@ -72,10 +78,11 @@ export class Sage300ImportSettingModel extends ImportSettingsModel {
import_settings: {
import_categories: importSettingsForm.get('importCategories')?.value,
import_vendors_as_merchants: importSettingsForm.get('importVendorAsMerchant')?.value,
add_commitment_details: importSettingsForm.get('addCommitmentDetails')?.value
add_commitment_details: importSettingsForm.get('addCommitmentDetails')?.value,
import_code_fields: importSettingsForm.get('importCodeFields')?.value
},
mapping_settings: mappingSettings,
dependent_field_settings: importSettingsForm.get('isDependentImportEnabled')?.value ? {
dependent_field_settings: importSettingsForm.get('isDependentImportEnabled')?.value && (importSettingsForm.get('costCodes')?.value && importSettingsForm.get('costCategory')?.value) ? {
cost_code_field_name: importSettingsForm.get('costCodes')?.value ? importSettingsForm.get('costCodes')?.value.attribute_type : (importSettings?.dependent_field_settings?.cost_code_field_name ? importSettings.dependent_field_settings?.cost_code_field_name : null),
cost_code_placeholder: importSettingsForm.get('costCodes')?.value ? importSettingsForm.get('costCodes')?.value.source_placeholder : (importSettings?.dependent_field_settings?.cost_code_placeholder ? importSettings.dependent_field_settings?.cost_code_placeholder : null),
cost_category_field_name: importSettingsForm.get('costCategory')?.value ? importSettingsForm.get('costCategory')?.value.attribute_type : (importSettings?.dependent_field_settings?.cost_category_field_name ? importSettings.dependent_field_settings?.cost_category_field_name : null),
Expand Down
1 change: 1 addition & 0 deletions src/app/core/services/common/helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export class HelperService {
}

sentenseCaseConversion(content: string) {
content = new SnakeCaseToSpaceCasePipe().transform(content);
return brandingConfig.brandId === 'co' ? new SentenceCasePipe().transform(content) : content;
}

Expand Down
14 changes: 11 additions & 3 deletions src/app/core/services/common/mapping.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export class MappingService {
return this.apiService.get(`/workspaces/${this.workspaceId}/export_settings/`, {});
}

getImportSettings(): Observable<any> {
return this.apiService.get(`/workspaces/${this.workspaceId}/import_settings/`, {});
}

getDestinationAttributes(attributeTypes: string | string[], version: 'v1' | 'v2', apiPath?: string, accountType?: string, active?: boolean, displayName?: string): Observable<any> {
const params: {attribute_type__in: string | string[], account_type?: string, active?: boolean, display_name__in?: string} = {
attribute_type__in: attributeTypes
Expand Down Expand Up @@ -166,17 +170,21 @@ export class MappingService {
return this.apiService.post(`/workspaces/${this.workspaceService.getWorkspaceId()}/mappings/`, mapping);
}

getPaginatedDestinationAttributes(attributeType: string, value?: string, display_name?: string): Observable<PaginatedDestinationAttribute> {
getPaginatedDestinationAttributes(attributeType: string, value?: string, display_name?: string, appName?: string): Observable<PaginatedDestinationAttribute> {
const workspaceId = this.workspaceService.getWorkspaceId();
const params: {limit: number, offset: number, attribute_type: string, active?: boolean, value__icontains?: string, display_name__in?: string} = {
const params: {limit: number, offset: number, attribute_type: string, active?: boolean, value__icontains?: string, value?: string, display_name__in?: string} = {
limit: 100,
offset: 0,
attribute_type: attributeType,
active: true
};

if (value) {
params.value__icontains = value;
if (appName === AppName.SAGE300) {
params.value = value;
} else {
params.value__icontains = value;
}
}

if (display_name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ export class Sage300ImportSettingsService {
postImportSettings(importSettingsPayload: Sage300ImportSettingPost): Observable<Sage300ImportSettingGet> {
return this.apiService.put(`/workspaces/${this.workspaceService.getWorkspaceId()}/import_settings/`, importSettingsPayload);
}

getImportCodeFieldConfig() {
const workspaceId = this.workspaceService.getWorkspaceId();
return this.apiService.get(`/workspaces/${workspaceId}/import_settings/import_code_fields_config/`, {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
[groupedErrorStat]="groupedErrorStat"
[destinationFieldMap]="destinationFieldMap"
[exportKey]="'accounting_export'"
>
[importCodeFields]="importCodeFields">
</app-dashboard-error-section>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Sage300AccountingExportResponse, Sage300AccountingExport } from 'src/ap
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';
import { Sage300ImportSettingsService } from 'src/app/core/services/sage300/sage300-configuration/sage300-import-settings.service';

@Component({
selector: 'app-sage300-dashboard',
Expand Down Expand Up @@ -67,11 +68,14 @@ export class Sage300DashboardComponent implements OnInit {

readonly isGradientAllowed: boolean = brandingFeatureConfig.isGradientAllowed;

importCodeFields: any;

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

private pollExportStatus(exportableAccountingExportIds: number[] = []): void {
Expand Down Expand Up @@ -128,7 +132,8 @@ export class Sage300DashboardComponent implements OnInit {
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.sage300ExportSettingService.getSage300ExportSettings()
this.sage300ExportSettingService.getSage300ExportSettings(),
this.sage300ImportSettingService.getSage300ImportSettings()
]).subscribe((responses) => {
this.errors = DashboardModel.parseAPIResponseToGroupedError(responses[0].results);
this.accountingExportSummary = responses[1];
Expand All @@ -140,6 +145,8 @@ export class Sage300DashboardComponent implements OnInit {
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;

this.importCodeFields = responses[5].import_settings.import_code_fields ? responses[5].import_settings.import_code_fields : [];

this.isLoading = false;

if (queuedTasks.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
[destinationField]="destinationField"
[showAutoMapEmployee]="showAutoMapEmployee"
[appName]="AppName.SAGE300"
[isMultiLineOption]="isMultiLineOption"
(triggerAutoMapEmployee)="triggerAutoMapEmployees()"
></app-generic-mapping-v2>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class Sage300BaseMappingComponent implements OnInit {

AppName = AppName;

isMultiLineOption: boolean = false;

constructor(
private route: ActivatedRoute,
private mappingService: MappingService,
Expand Down Expand Up @@ -63,12 +65,14 @@ export class Sage300BaseMappingComponent implements OnInit {
this.sourceField = decodeURIComponent(this.route.snapshot.params.source_field.toUpperCase());
forkJoin(
this.mappingService.getExportSettings(),
this.mappingService.getImportSettings(),
this.mappingService.getMappingSettings()
).subscribe(([exportSettingsResponse, mappingSettingsResponse]) => {
).subscribe(([exportSettingsResponse, importSettingsResponse, mappingSettingsResponse]) => {
this.reimbursableExpenseObject = exportSettingsResponse.reimbursable_expenses_object;
this.cccExpenseObject = exportSettingsResponse.corporate_credit_card_expenses_object;
this.showAutoMapEmployee = exportSettingsResponse.auto_map_employees ? true : false;
this.destinationField = this.getSourceType(mappingSettingsResponse.results);
this.isMultiLineOption = this.destinationField !== FyleField.VENDOR ? importSettingsResponse.import_settings.import_code_fields?.includes(this.destinationField) : false;
this.mappingService.getPaginatedDestinationAttributes(this.destinationField).subscribe((response: any) => {
this.destinationOptions = response.results;
this.isLoading = false;
Expand Down
3 changes: 2 additions & 1 deletion src/app/integrations/sage300/sage300-shared/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const importSettingsResponse: Sage300ImportSettingGet = {
"import_settings": {
"import_categories": false,
"import_vendors_as_merchants": false,
"add_commitment_details": false
"add_commitment_details": false,
"import_code_fields": []
},
"mapping_settings": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
[iconPath]="'list'"
[placeholder]="'Select default Job'"
[appName]="appName"
[isMultiLineOption]="sage300ImportCodeFields.includes(sage300Field.JOB)"
[formControllerName]="'defaultJobName'">
</app-configuration-select-field>
</div>
Expand All @@ -109,6 +110,7 @@
[iconPath]="'list'"
[placeholder]="'Select A/P account'"
[appName]="appName"
[isMultiLineOption]="sage300ImportCodeFields.includes(sage300Field.ACCOUNT)"
[formControllerName]="'defaultReimbursableAP'"></app-configuration-select-field>
</div>
<div *ngIf="exportSettingForm.get('reimbursableExportType')?.value" class="tw-mt-16-px tw-bg-white tw-border tw-border-solid tw-border-separator tw-rounded-12-px">
Expand Down Expand Up @@ -229,6 +231,7 @@
[showClearIcon]="true"
[iconPath]="'list'"
[placeholder]="'Select Default Job'"
[isMultiLineOption]="sage300ImportCodeFields.includes(sage300Field.JOB)"
[appName]="appName"
[formControllerName]="'defaultJobName'">
</app-configuration-select-field>
Expand All @@ -250,6 +253,7 @@
[iconPath]="'list'"
[placeholder]="'Select A/P account'"
[appName]="appName"
[isMultiLineOption]="sage300ImportCodeFields.includes(sage300Field.ACCOUNT)"
[formControllerName]="'defaultCCCAP'"></app-configuration-select-field>
</div>
<div *ngIf="exportSettingForm.get('cccExportType')?.value" class="tw-mt-16-px tw-bg-white tw-border tw-border-solid tw-border-separator tw-rounded-12-px">
Expand All @@ -268,6 +272,7 @@
[iconPath]="'list'"
[placeholder]="'Select default vendor'"
[appName]="appName"
[isMultiLineOption]="sage300ImportCodeFields.includes(Sage300ExportSettingDestinationOptionKey.VENDOR)"
[formControllerName]="'defaultVendorName'">
</app-configuration-select-field>
</div>
Expand Down
Loading

0 comments on commit 3a2b763

Please sign in to comment.