Skip to content

Commit

Permalink
Merge branch 'master' into FYLE-86cwm1x6h
Browse files Browse the repository at this point in the history
  • Loading branch information
sumrender authored Nov 26, 2024
2 parents 1a0c337 + f104c5a commit 8705c89
Show file tree
Hide file tree
Showing 48 changed files with 1,197 additions and 1,000 deletions.
372 changes: 264 additions & 108 deletions README.md

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/app/core/mock-data/org-settings.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ export const orgSettingsRes: OrgSettings = deepFreeze({
enabled: true,
enable_individual_per_diem_rates: false,
},
advanced_per_diems_settings: {
allowed: true,
enabled: true,
enable_employee_restriction: false,
},
payment_mode_settings: {
allowed: true,
enabled: true,
Expand Down Expand Up @@ -458,6 +463,11 @@ export const orgSettingsParams2: OrgSettings = deepFreeze({
enabled: true,
enable_individual_projects: true,
},
advanced_per_diems_settings: {
allowed: true,
enabled: true,
enable_employee_restriction: false,
},
advance_requests: {
allowed: false,
enabled: false,
Expand Down Expand Up @@ -931,6 +941,11 @@ export const orgSettingsParamWoCCC: OrgSettings = deepFreeze({
enabled: true,
enable_individual_per_diem_rates: false,
},
advanced_per_diems_settings: {
allowed: true,
enabled: true,
enable_employee_restriction: false,
},
payment_mode_settings: {
allowed: true,
enabled: true,
Expand Down
39 changes: 39 additions & 0 deletions src/app/core/mock-data/transaction.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Transaction } from '../models/v1/transaction.model';
import { optionsData15, optionsData33 } from './merge-expenses-options-data.data';
import { expectedTxnCustomProperties, txnCustomPropertiesData } from './txn-custom-properties.data';
import { ExpenseTransactionStatus } from '../enums/platform/v1/expense-transaction-status.enum';
import { Expense } from '../models/platform/v1/expense.model';
import { MileageUnitEnum } from '../models/platform/platform-mileage-rates.model';
import deepFreezeStrict from 'deep-freeze-strict';

export const txnList: Transaction[] = deepFreeze([
{
Expand Down Expand Up @@ -2583,6 +2586,42 @@ export const txnAmount1: Transaction = deepFreeze({
categoryDisplayName: 'Bus',
});

export const transformedExpensePayload: Partial<Expense> = deepFreezeStrict({
id: txnAmount1.id,
spent_at: txnAmount1.txn_dt,
category_id: txnAmount1.org_category_id,
purpose: txnAmount1.purpose,
source_account_id: txnAmount1.source_account_id,
claim_amount: txnAmount1.amount,
merchant: txnAmount1.vendor,
project_id: txnAmount1.project_id,
cost_center_id: txnAmount1.cost_center_id,
foreign_currency: txnAmount1.orig_currency,
foreign_amount: txnAmount1.orig_amount,
source: txnAmount1.source,
is_reimbursable: !txnAmount1.skip_reimbursement,
tax_amount: txnAmount1.tax_amount,
tax_group_id: txnAmount1.tax_group_id,
is_billable: txnAmount1.billable,
distance: txnAmount1.distance,
distance_unit: txnAmount1.distance_unit as MileageUnitEnum,
started_at: txnAmount1.from_dt,
ended_at: txnAmount1.to_dt,
custom_fields: txnAmount1.custom_properties,
per_diem_rate_id: txnAmount1.per_diem_rate_id,
per_diem_num_days: 0,
mileage_rate_id: txnAmount1.mileage_rate_id,
advance_wallet_id: txnAmount1.advance_wallet_id,
report_id: txnAmount1.report_id,
travel_classes: [],
locations: [],
commute_deduction: undefined,
mileage_is_round_trip: null,
commute_details_id: undefined,
hotel_is_breakfast_provided: null,
file_ids: undefined,
});

export const splitExpenseTxn2: Transaction = deepFreeze({
skip_reimbursement: false,
source: 'MOBILE',
Expand Down
8 changes: 4 additions & 4 deletions src/app/core/mock-data/txn-custom-properties.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export const txnCustomPropertiesData4: TxnCustomProperties[] = deepFreeze([
id: 210281,
prefix: '',
name: 'test',
value: '',
value: [],
placeholder: '123test',
type: 'MULTI_SELECT',
mandatory: false,
Expand All @@ -328,7 +328,7 @@ export const txnCustomPropertiesData4: TxnCustomProperties[] = deepFreeze([
id: 212819,
prefix: '',
name: 'category2',
value: '',
value: [],
placeholder: 'category2',
type: 'MULTI_SELECT',
mandatory: false,
Expand All @@ -339,7 +339,7 @@ export const txnCustomPropertiesData4: TxnCustomProperties[] = deepFreeze([
id: 206206,
prefix: '',
name: 'pub create hola 1',
value: null,
value: {},
placeholder: 'pub create hola 1',
type: 'LOCATION',
mandatory: false,
Expand All @@ -350,7 +350,7 @@ export const txnCustomPropertiesData4: TxnCustomProperties[] = deepFreeze([
id: 211321,
prefix: '',
name: 'test 112',
value: null,
value: {},
placeholder: 'placeholder',
type: 'LOCATION',
mandatory: false,
Expand Down
16 changes: 9 additions & 7 deletions src/app/core/mock-data/unflattened-txn.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ export const newExpFromFg: Partial<UnflattenedTransaction> = deepFreeze({
report_id: null,
reported_at: null,
state: 'COMPLETE',
num_files: 0,
num_files: 1,
invoice_number: null,
purpose: 'purpose',
source: 'MOBILE',
Expand Down Expand Up @@ -2095,8 +2095,8 @@ export const newExpFromFg2: Partial<UnflattenedTransaction> = deepFreeze({
vendor_id: 28860,
platform_vendor: null,
platform_vendor_id: null,
org_category: 'TRAVEL',
sub_category: 'TAXI',
org_category: 'Software',
sub_category: 'Software',
fyle_category: 'Groceries',
org_category_code: '117',
org_category_id: 215481,
Expand Down Expand Up @@ -2220,7 +2220,7 @@ export const newExpFromFg3: Partial<UnflattenedTransaction> = deepFreeze({
report_id: null,
reported_at: null,
state: 'DRAFT',
num_files: 0,
num_files: 1,
invoice_number: null,
purpose: 'purpose',
source: 'MOBILE',
Expand Down Expand Up @@ -2356,7 +2356,7 @@ export const newExpFromFg4: Partial<UnflattenedTransaction> = deepFreeze({
report_id: null,
reported_at: null,
state: 'DRAFT',
num_files: 0,
num_files: 1,
invoice_number: null,
purpose: 'purpose',
source: 'MOBILE',
Expand Down Expand Up @@ -3236,7 +3236,8 @@ export const newMileageExpFromForm: Partial<UnflattenedTransaction> = deepFreeze
num_days: null,
mileage_calculated_distance: 10,
mileage_calculated_amount: 100,
mileage_vehicle_type: 'bicycle',
mileage_vehicle_type: null,
mileage_rate_id: 57035,
mileage_rate: null,
mileage_is_round_trip: true,
hotel_is_breakfast_provided: null,
Expand Down Expand Up @@ -3382,7 +3383,8 @@ export const newMileageExpFromForm2: Partial<UnflattenedTransaction> = deepFreez
user_can_delete: true,
billable: undefined,
user_reason_for_duplicate_expenses: null,
mileage_vehicle_type: undefined,
mileage_vehicle_type: null,
mileage_rate_id: undefined,
txn_dt: new Date('2023-02-13T01:00:00.000Z'),
category: null,
amount: 100,
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/models/custom-input-options.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface CustomInputOptions {
label: string;
value: string | string[] | boolean | Date | number | { display: string };
value: string | string[] | boolean | Date | number | { display?: string };
}
2 changes: 1 addition & 1 deletion src/app/core/models/custom-input.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface CustomInput {
placeholder: string;
prefix: string;
type: string;
value: string | string[] | boolean | Date | number | { display: string };
value: string | string[] | boolean | Date | number | { display?: string };
parent_field_id: number;
displayValue: string;
areSameValues?: boolean;
Expand Down
11 changes: 11 additions & 0 deletions src/app/core/models/custom-inputs-option.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface CustomInputsOption {
id?: number;
mandatory?: boolean;
name?: string;
options?: string[];
placeholder?: string;
prefix?: string;
type?: string;
label: string;
value: string;
}
4 changes: 2 additions & 2 deletions src/app/core/models/custom_field.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { AbstractControl } from '@angular/forms';
export interface CustomField {
id?: number;
name: string;
value: string | boolean | number | Date | string[] | { display: string };
value: string | boolean | number | Date | string[] | { display?: string };
type?: string;
displayValue?: string | boolean | number | Date | string[] | { display: string };
displayValue?: string | boolean | number | Date | string[] | { display?: string };
mandatory?: boolean;
control?: AbstractControl;
}
7 changes: 6 additions & 1 deletion src/app/core/models/org-settings.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export interface PerDiemSettings extends CommonOrgSettings {
enable_individual_per_diem_rates?: boolean;
}

export interface AdvancedPerDiemsSettings extends CommonOrgSettings {
enable_employee_restriction?: boolean;
}

export interface ReceiptSettings extends CommonOrgSettings {
enable_magnifier?: boolean;
}
Expand Down Expand Up @@ -378,7 +382,7 @@ export interface OrgSettingsResponse {
org_personal_cards_settings?: CommonOrgSettings;
bank_data_aggregation_settings?: OrgBankDataAggregationSettings;
per_diem_settings?: PerDiemSettings;
advanced_per_diems_settings?: CommonOrgSettings;
advanced_per_diems_settings?: AdvancedPerDiemsSettings;
accounting_export_settings?: AccountingExportSettings;
activity_settings?: ActivitySettings;
tax_settings?: TaxSettings;
Expand Down Expand Up @@ -499,6 +503,7 @@ export interface OrgSettings {
advances?: AdvancesSettings;
projects?: CommonOrgSettings;
advanced_projects?: AdvancedProjectSettings;
advanced_per_diems_settings?: AdvancedPerDiemsSettings;
advance_requests?: CommonOrgSettings;
cost_centers?: CommonOrgSettings;
policies?: UiPolicySettings;
Expand Down
5 changes: 5 additions & 0 deletions src/app/core/models/receipt-detail.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type ReceiptDetail = {
dataUrl: string;
type: string;
actionSource: string;
};
15 changes: 2 additions & 13 deletions src/app/core/models/txn-custom-properties.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AbstractControl } from '@angular/forms';
import { CustomInputsOption } from './custom-inputs-option.model';

export interface TxnCustomProperties {
id?: number;
Expand All @@ -8,21 +9,9 @@ export interface TxnCustomProperties {
placeholder?: string;
prefix?: string;
type?: string;
value: string | string[] | boolean | Date | number | { display: string };
value: string | string[] | boolean | Date | number | { display?: string };
parent_field_id?: number;
label?: string;
control?: AbstractControl;
is_enabled?: boolean;
}

export interface CustomInputsOption {
id?: number;
mandatory?: boolean;
name?: string;
options?: string[];
placeholder?: string;
prefix?: string;
type?: string;
label: string;
value: string;
}
1 change: 1 addition & 0 deletions src/app/core/models/v1/transaction.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ export interface Transaction {
status: ExpenseTransactionStatus;
corporate_card_nickname?: string;
}[];
file_ids?: string[];
}
12 changes: 3 additions & 9 deletions src/app/core/services/custom-fields.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,13 @@ describe('CustomFieldsService', () => {
expect(result.value).toBeFalse();
});

it('should set default value to empty string for select type', () => {
const mockTxnCustomProperties = cloneDeep(txnCustomPropertiesData3[1]);
const result = customFieldsService.setDefaultValue(mockTxnCustomProperties, 'SELECT');
expect(result.value).toBe('');
});

it('should set default value to empty string for multi select type', () => {
it('should set default value to empty array for multi select type', () => {
const mockTxnCustomProperties = cloneDeep(txnCustomPropertiesData3[2]);
const result = customFieldsService.setDefaultValue(mockTxnCustomProperties, 'MULTI_SELECT');
expect(result.value).toBe('');
expect(result.value).toEqual([]);
});

it('should set default value to empty string for user select type', () => {
it('should set default value to empty array for user select type', () => {
const mockTxnCustomProperties = cloneDeep(txnCustomPropertiesData[0]);
const result = customFieldsService.setDefaultValue(mockTxnCustomProperties, 'USER_LIST');
expect(result.value).toEqual([]);
Expand Down
13 changes: 7 additions & 6 deletions src/app/core/services/custom-fields.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Injectable } from '@angular/core';
import { CustomProperty } from '../models/custom-properties.model';
import { CustomInputsOption, TxnCustomProperties } from '../models/txn-custom-properties.model';
import { TxnCustomProperties } from '../models/txn-custom-properties.model';
import { ExpenseField } from '../models/v1/expense-field.model';
import { CustomInputsOption } from '../models/custom-inputs-option.model';

@Injectable({
providedIn: 'root',
})
export class CustomFieldsService {
constructor() {}

sortcustomFieldsByType(customField1: TxnCustomProperties, customField2: TxnCustomProperties): 1 | -1 | 0 {
if (customField1.type > customField2.type) {
return -1;
Expand All @@ -23,15 +22,16 @@ export class CustomFieldsService {
setDefaultValue(property: TxnCustomProperties, inputValue: string): TxnCustomProperties {
if (inputValue === 'BOOLEAN') {
property.value = false;
} else if (inputValue === 'SELECT' || inputValue === 'MULTI_SELECT') {
property.value = '';
} else if (inputValue === 'USER_LIST') {
} else if (inputValue === 'USER_LIST' || inputValue === 'MULTI_SELECT') {
property.value = [];
} else if (inputValue === 'LOCATION') {
property.value = {};
}

return property;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
setProperty(prefix: string, customInput: ExpenseField, customProperties: CustomProperty<any>[]): TxnCustomProperties {
/* Setting the name and mandatory based on the custom input key
* Reason: Same method is used for expense custom fields and transport/advance request custom fields
Expand Down Expand Up @@ -83,6 +83,7 @@ export class CustomFieldsService {
}

standardizeCustomFields(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
customProperties: CustomProperty<any>[],
customInputs: ExpenseField[]
): TxnCustomProperties[] {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/services/custom-inputs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe('CustomInputsService', () => {
options: null,
};

const expectedProperty = 'some,location';
const expectedProperty = '-';

const result = customInputsService.getCustomPropertyDisplayValue(testProperty);
expect(result).toEqual(expectedProperty);
Expand Down
2 changes: 0 additions & 2 deletions src/app/core/services/custom-inputs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ export class CustomInputsService {
if (customProperty.value) {
if (customProperty.value.hasOwnProperty('display')) {
displayValue = (<{ display: string }>customProperty.value).display || '-';
} else {
displayValue = customProperty.value.toString();
}
}
return displayValue;
Expand Down
6 changes: 6 additions & 0 deletions src/app/core/services/org-settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ export class OrgSettingsService {
enable_category_restriction:
incoming.advanced_project_settings && incoming.advanced_project_settings.enable_category_restriction,
},
advanced_per_diems_settings: {
allowed: incoming.advanced_per_diems_settings?.allowed,
enabled: incoming.advanced_per_diems_settings?.enabled,
enable_employee_restriction: incoming.advanced_per_diems_settings?.enable_employee_restriction,
},
advance_requests: {
allowed: incoming.advances_settings && incoming.advances_settings.allowed,
enabled: incoming.advances_settings && incoming.advances_settings.advance_requests_enabled,
Expand Down Expand Up @@ -447,6 +452,7 @@ export class OrgSettingsService {
enable_individual_projects: outgoing.advanced_projects.enable_individual_projects,
enable_category_restriction: outgoing.advanced_projects.enable_category_restriction,
},
advanced_per_diems_settings: outgoing.advanced_per_diems_settings,
org_cost_center_settings: {
allowed: outgoing.cost_centers.allowed,
enabled: outgoing.cost_centers.enabled,
Expand Down
Loading

0 comments on commit 8705c89

Please sign in to comment.