law-common 10.72.14-beta.3 → 10.72.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/api/interface/state.create.dto.interface.autocode.js +3 -1
- package/dist/src/api/interface/state.create.dto.interface.d.ts +2 -1
- package/dist/src/api/interface/state.update.dto.interface.autocode.d.ts +0 -0
- package/dist/src/api/interface/state.update.dto.interface.autocode.js +10 -0
- package/dist/src/api/interface/state.update.dto.interface.d.ts +13 -1
- package/dist/src/api/interface/state.update.dto.interface.js +8 -0
- package/dist/src/entities/flow-configs/state_flow.config.d.ts +6 -0
- package/dist/src/entities/flow-configs/state_flow.config.js +90 -0
- package/dist/src/entities/index.d.ts +1 -0
- package/dist/src/entities/index.js +1 -0
- package/dist/src/entities/interface/state.entity.interface.autocode.js +3 -1
- package/dist/src/entities/interface/state.entity.interface.d.ts +1 -1
- package/dist/src/entities/model/state.entity.model.d.ts +40 -3
- package/dist/src/entities/model/state.entity.model.js +204 -2
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// import { IEntityCreateDto } from "../../entities";
|
|
2
|
+
// import { IEntityCreateDto, Nullable } from "../../entities";
|
|
3
|
+
// import { IAppFileConfig, IFilePayload, MulterFileWithUrl } from "../../misc";
|
|
4
|
+
// import { IStateEntity } from "../../entities/interface/state.entity.interface";
|
|
3
5
|
// export type IStateCreateExclude = "status";
|
|
4
6
|
// export interface IStateCreateDto extends Omit<IEntityCreateDto<IStateEntity>, IStateCreateExclude> {}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { IEntityCreateDto
|
|
1
|
+
import { IEntityCreateDto } from "../../entities";
|
|
2
|
+
import { IStateEntity } from "../../entities/interface/state.entity.interface";
|
|
2
3
|
export type IStateCreateExclude = "status";
|
|
3
4
|
export interface IStateCreateDto extends Omit<IEntityCreateDto<IStateEntity>, IStateCreateExclude> {
|
|
4
5
|
}
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { DeepPartialButRequired } from "./api.utils.interface";
|
|
3
|
+
// import { IDeleteDocumentDetails } from "../../misc";
|
|
4
|
+
// import { EntityEnum, EnumEntityType } from "../../entities";
|
|
5
|
+
// import { IStateCreateDto } from "./state.create.dto.interface";
|
|
6
|
+
// export type IStateUpdateDto = DeepPartialButRequired<IStateCreateDto, never> & { actionData: IStateActionDataDto };
|
|
7
|
+
// export interface IStateActionDataDto {
|
|
8
|
+
// action: StateActionEnum;
|
|
9
|
+
// remark?: string;
|
|
10
|
+
// }
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import { DeepPartialButRequired } from "./api.utils.interface";
|
|
2
2
|
import { IStateCreateDto } from "./state.create.dto.interface";
|
|
3
|
-
export type IStateUpdateDto = DeepPartialButRequired<IStateCreateDto, never
|
|
3
|
+
export type IStateUpdateDto = DeepPartialButRequired<IStateCreateDto, never> & {
|
|
4
|
+
actionData: IStateActionDataDto;
|
|
5
|
+
};
|
|
6
|
+
export interface IStateActionDataDto {
|
|
7
|
+
action: StateActionEnum;
|
|
8
|
+
remark?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare enum StateActionEnum {
|
|
11
|
+
VIEW = "view",
|
|
12
|
+
EDIT = "edit",
|
|
13
|
+
DELETE = "delete",
|
|
14
|
+
CREATE = "create"
|
|
15
|
+
}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateActionEnum = void 0;
|
|
4
|
+
var StateActionEnum;
|
|
5
|
+
(function (StateActionEnum) {
|
|
6
|
+
StateActionEnum["VIEW"] = "view";
|
|
7
|
+
StateActionEnum["EDIT"] = "edit";
|
|
8
|
+
StateActionEnum["DELETE"] = "delete";
|
|
9
|
+
StateActionEnum["CREATE"] = "create";
|
|
10
|
+
})(StateActionEnum || (exports.StateActionEnum = StateActionEnum = {}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { StateActionEnum } from "../../api";
|
|
2
|
+
import { StateStatusEnum } from "../enums/state_status_enum";
|
|
3
|
+
import { FlowConfig } from "./flow-config.type";
|
|
4
|
+
export interface IStateFlowConfigContextData {
|
|
5
|
+
}
|
|
6
|
+
export declare const stateFlowConfig: FlowConfig<StateStatusEnum, StateActionEnum, IStateFlowConfigContextData>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stateFlowConfig = void 0;
|
|
4
|
+
const api_1 = require("../../api");
|
|
5
|
+
const state_status_enum_1 = require("../enums/state_status_enum");
|
|
6
|
+
/**
|
|
7
|
+
* State Flow Configuration - Status transition rules for state master.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Simple transition (fixed target status)
|
|
11
|
+
* createActionConfig(StateStatusEnum.INACTIVE, StateActionEnum.DELETE)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Function-based transition (choose one of possible statuses via context data)
|
|
15
|
+
* // Note: this example uses an extended context shape for illustration.
|
|
16
|
+
* type IExtendedContext = IStateFlowConfigContextData & { nextStatus?: StateStatusEnum };
|
|
17
|
+
* const transitionWithContext = (context: IExtendedContext) =>
|
|
18
|
+
* context.nextStatus === StateStatusEnum.DEACTIVE ? StateStatusEnum.DEACTIVE : StateStatusEnum.ACTIVE;
|
|
19
|
+
* createActionConfig(transitionWithContext, StateActionEnum.EDIT)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Subset transition — restricts the valid next statuses for a specific (currentStatus, action) pair.
|
|
23
|
+
* //
|
|
24
|
+
* // StateActionStatusMap says EDIT can go to: ACTIVE | DEACTIVE | INACTIVE (globally).
|
|
25
|
+
* // But from ACTIVE status, EDIT should only allow ACTIVE or DEACTIVE (not INACTIVE).
|
|
26
|
+
* // The Subset type parameter enforces this narrowing at compile time.
|
|
27
|
+
* //
|
|
28
|
+
* // TypeScript will reject any value outside the declared Subset:
|
|
29
|
+
* // createActionConfig<StateActionEnum.EDIT, StateStatusEnum.ACTIVE | StateStatusEnum.DEACTIVE>(
|
|
30
|
+
* // StateStatusEnum.INACTIVE, // ❌ compile error — INACTIVE not in Subset
|
|
31
|
+
* // StateActionEnum.EDIT
|
|
32
|
+
* // )
|
|
33
|
+
* //
|
|
34
|
+
* // Correct usage with a fixed subset value:
|
|
35
|
+
* createActionConfig<StateActionEnum.EDIT, StateStatusEnum.ACTIVE | StateStatusEnum.DEACTIVE>(
|
|
36
|
+
* StateStatusEnum.ACTIVE,
|
|
37
|
+
* StateActionEnum.EDIT
|
|
38
|
+
* )
|
|
39
|
+
* //
|
|
40
|
+
* // Correct usage with a context-driven subset function:
|
|
41
|
+
* type IExtendedContext2 = IStateFlowConfigContextData & { deactivate?: boolean };
|
|
42
|
+
* createActionConfig<StateActionEnum.EDIT, StateStatusEnum.ACTIVE | StateStatusEnum.DEACTIVE>(
|
|
43
|
+
* (context: IExtendedContext2) =>
|
|
44
|
+
* context.deactivate ? StateStatusEnum.DEACTIVE : StateStatusEnum.ACTIVE,
|
|
45
|
+
* StateActionEnum.EDIT
|
|
46
|
+
* )
|
|
47
|
+
*/
|
|
48
|
+
const STATE_CREATE_PERMISSION = ["STATE_CREATE"];
|
|
49
|
+
const STATE_UPDATE_PERMISSION = ["STATE_UPDATE"];
|
|
50
|
+
const STATE_DELETE_PERMISSION = ["STATE_DELETE"];
|
|
51
|
+
const STATE_VIEW_PERMISSION = ["STATE_VIEW"];
|
|
52
|
+
const createTransition = (transition) => (context) => {
|
|
53
|
+
if (typeof transition === "function") {
|
|
54
|
+
return transition(context);
|
|
55
|
+
}
|
|
56
|
+
return transition;
|
|
57
|
+
};
|
|
58
|
+
const actionPermissionMap = {
|
|
59
|
+
[api_1.StateActionEnum.CREATE]: STATE_CREATE_PERMISSION,
|
|
60
|
+
[api_1.StateActionEnum.EDIT]: STATE_UPDATE_PERMISSION,
|
|
61
|
+
[api_1.StateActionEnum.DELETE]: STATE_DELETE_PERMISSION,
|
|
62
|
+
[api_1.StateActionEnum.VIEW]: STATE_VIEW_PERMISSION,
|
|
63
|
+
};
|
|
64
|
+
const createActionConfig = (nextStatus, action, overridePermissions) => ({
|
|
65
|
+
permissions: overridePermissions !== null && overridePermissions !== void 0 ? overridePermissions : actionPermissionMap[action],
|
|
66
|
+
next: createTransition(nextStatus),
|
|
67
|
+
});
|
|
68
|
+
const transitionActiveStatusEditAction = (context) => state_status_enum_1.StateStatusEnum.DEACTIVE;
|
|
69
|
+
exports.stateFlowConfig = {
|
|
70
|
+
[state_status_enum_1.StateStatusEnum.ACTIVE]: {
|
|
71
|
+
actions: {
|
|
72
|
+
[api_1.StateActionEnum.VIEW]: createActionConfig(state_status_enum_1.StateStatusEnum.ACTIVE, api_1.StateActionEnum.VIEW),
|
|
73
|
+
[api_1.StateActionEnum.EDIT]: createActionConfig(transitionActiveStatusEditAction, api_1.StateActionEnum.EDIT),
|
|
74
|
+
[api_1.StateActionEnum.DELETE]: createActionConfig(state_status_enum_1.StateStatusEnum.INACTIVE, api_1.StateActionEnum.DELETE),
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
[state_status_enum_1.StateStatusEnum.DEACTIVE]: {
|
|
78
|
+
actions: {
|
|
79
|
+
[api_1.StateActionEnum.VIEW]: createActionConfig(state_status_enum_1.StateStatusEnum.DEACTIVE, api_1.StateActionEnum.VIEW),
|
|
80
|
+
[api_1.StateActionEnum.EDIT]: createActionConfig(state_status_enum_1.StateStatusEnum.ACTIVE, api_1.StateActionEnum.EDIT),
|
|
81
|
+
[api_1.StateActionEnum.DELETE]: createActionConfig(state_status_enum_1.StateStatusEnum.INACTIVE, api_1.StateActionEnum.DELETE),
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
[state_status_enum_1.StateStatusEnum.INACTIVE]: {
|
|
85
|
+
actions: {
|
|
86
|
+
[api_1.StateActionEnum.VIEW]: createActionConfig(state_status_enum_1.StateStatusEnum.INACTIVE, api_1.StateActionEnum.VIEW),
|
|
87
|
+
[api_1.StateActionEnum.CREATE]: createActionConfig(state_status_enum_1.StateStatusEnum.ACTIVE, api_1.StateActionEnum.CREATE),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
@@ -105,6 +105,7 @@ export * from "./interface/address-book.entity.interface";
|
|
|
105
105
|
export * from "./enums/state_status_enum";
|
|
106
106
|
export * from "./interface/state.entity.interface";
|
|
107
107
|
export * from "./model/state.entity.model";
|
|
108
|
+
export * from "./flow-configs/state_flow.config";
|
|
108
109
|
export * from "./enums/gst_rate_status_enum";
|
|
109
110
|
export * from "./interface/gst_rate.entity.interface";
|
|
110
111
|
export * from "./model/gst_rate.entity.model";
|
|
@@ -121,6 +121,7 @@ __exportStar(require("./interface/address-book.entity.interface"), exports);
|
|
|
121
121
|
__exportStar(require("./enums/state_status_enum"), exports);
|
|
122
122
|
__exportStar(require("./interface/state.entity.interface"), exports);
|
|
123
123
|
__exportStar(require("./model/state.entity.model"), exports);
|
|
124
|
+
__exportStar(require("./flow-configs/state_flow.config"), exports);
|
|
124
125
|
__exportStar(require("./enums/gst_rate_status_enum"), exports);
|
|
125
126
|
__exportStar(require("./interface/gst_rate.entity.interface"), exports);
|
|
126
127
|
__exportStar(require("./model/gst_rate.entity.model"), exports);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// import { IEntityAuditColumn } from "./entity-audit-columns.interface";
|
|
3
|
+
// import { Nullable } from "./entity.utils.interface";
|
|
4
|
+
// import { StateStatusEnum } from "../enums/state_status_enum";
|
|
3
5
|
// export interface IStateEntity extends IEntityAuditColumn {
|
|
4
6
|
// id: number;
|
|
5
7
|
// name: string;
|
|
6
|
-
// status: StateStatusEnum;
|
|
7
8
|
// code: string;
|
|
9
|
+
// status: StateStatusEnum;
|
|
8
10
|
// }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { StateStatusEnum } from "../enums/state_status_enum";
|
|
2
1
|
import { IEntityAuditColumn } from "./entity-audit-columns.interface";
|
|
2
|
+
import { StateStatusEnum } from "../enums/state_status_enum";
|
|
3
3
|
export interface IStateEntity extends IEntityAuditColumn {
|
|
4
4
|
id: number;
|
|
5
5
|
name: string;
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
import { StateStatusEnum } from "../enums/state_status_enum";
|
|
2
1
|
import { EntityEnum } from "../interface/entity.utils.interface";
|
|
3
|
-
import { IStateEntity } from "../interface/state.entity.interface";
|
|
4
2
|
import { BaseEntityModel } from "./base.entity.model";
|
|
3
|
+
import { RelationConfigs } from "../interface/relation-config.interface";
|
|
4
|
+
import { IUserEntity } from "../interface/user.entity.interface";
|
|
5
|
+
import { UserEntityModel } from "./user.entity.model";
|
|
6
|
+
import { IRowActions } from "./interface/row-actions.interface";
|
|
7
|
+
import { IStateEntity } from "../interface/state.entity.interface";
|
|
8
|
+
import { StateStatusEnum } from "../enums/state_status_enum";
|
|
9
|
+
import { VendorEntityModel } from "./vendor.entity.model";
|
|
10
|
+
import { CountryEntityModel } from "./country.entity.model";
|
|
11
|
+
import { VendorInvoiceEntityModel } from "./vendor_invoice.entity.model";
|
|
12
|
+
import { OfficeLocationEntityModel } from "./office_location.entity.model";
|
|
13
|
+
import { VendorInvoiceItemEntityModel } from "./vendor_invoice_item.entity.model";
|
|
14
|
+
import { VoucherTypeEntityModel } from "./voucher_type.entity.model";
|
|
15
|
+
import { TdsRateEntityModel } from "./tds_rate.entity.model";
|
|
16
|
+
import { OrganizationTypeEntityModel } from "./organization_type.entity.model";
|
|
17
|
+
import { ExpenseHeadEntityModel } from "./expense_head.entity.model";
|
|
18
|
+
import { GstRateEntityModel } from "./gst_rate.entity.model";
|
|
19
|
+
import { StateActionEnum } from "../../api";
|
|
20
|
+
import { IStateFlowConfigContextData } from "../flow-configs/state_flow.config";
|
|
5
21
|
export declare class StateEntityModel extends BaseEntityModel<EntityEnum.STATE> implements IStateEntity {
|
|
6
22
|
id: number;
|
|
7
23
|
name: string;
|
|
@@ -11,7 +27,28 @@ export declare class StateEntityModel extends BaseEntityModel<EntityEnum.STATE>
|
|
|
11
27
|
updatedOn: number;
|
|
12
28
|
createdBy: number;
|
|
13
29
|
updatedBy: number;
|
|
30
|
+
vendors?: VendorEntityModel[];
|
|
31
|
+
static relationConfigs: RelationConfigs<[EntityEnum.VENDOR], EntityEnum.STATE>;
|
|
14
32
|
static fromEntity(entity: IStateEntity): StateEntityModel;
|
|
15
|
-
static relationConfigs: never[];
|
|
16
33
|
getRelationConfigs(): any[];
|
|
34
|
+
get countrys(): CountryEntityModel[] | undefined;
|
|
35
|
+
get vendorInvoices(): VendorInvoiceEntityModel[] | undefined;
|
|
36
|
+
get officeLocations(): OfficeLocationEntityModel[] | undefined;
|
|
37
|
+
get vendorInvoiceItems(): VendorInvoiceItemEntityModel[] | undefined;
|
|
38
|
+
get voucherTypes(): VoucherTypeEntityModel[] | undefined;
|
|
39
|
+
get tdsRates(): TdsRateEntityModel[] | undefined;
|
|
40
|
+
get organizationTypes(): OrganizationTypeEntityModel[] | undefined;
|
|
41
|
+
get expenseHeads(): ExpenseHeadEntityModel[] | undefined;
|
|
42
|
+
get gstRates(): GstRateEntityModel[] | undefined;
|
|
43
|
+
getNextStatus(currentUser: IUserEntity, action: StateActionEnum, stateFlowConfigContextData: IStateFlowConfigContextData): StateStatusEnum;
|
|
44
|
+
getAvailableActions(currentUser: UserEntityModel, config?: {
|
|
45
|
+
combinedActions?: Record<string, {
|
|
46
|
+
combineActions: StateActionEnum[];
|
|
47
|
+
label: string;
|
|
48
|
+
}>;
|
|
49
|
+
customLabels?: Partial<Record<StateActionEnum, string>>;
|
|
50
|
+
}): IRowActions<EntityEnum.STATE>[];
|
|
51
|
+
getUpdateActionVisibility(currentUser: UserEntityModel): {
|
|
52
|
+
[key: string]: () => boolean;
|
|
53
|
+
};
|
|
17
54
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StateEntityModel = void 0;
|
|
4
|
-
const state_status_enum_1 = require("../enums/state_status_enum");
|
|
5
4
|
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
6
5
|
const base_entity_model_1 = require("./base.entity.model");
|
|
6
|
+
const relation_type_enum_1 = require("../enums/relation-type.enum");
|
|
7
|
+
const exceptions_1 = require("../../exceptions");
|
|
8
|
+
const error_key_enum_1 = require("../../enums/error.key.enum");
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
10
|
+
const state_status_enum_1 = require("../enums/state_status_enum");
|
|
11
|
+
const state_flow_config_1 = require("../flow-configs/state_flow.config");
|
|
7
12
|
class StateEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
8
13
|
constructor() {
|
|
9
14
|
super(...arguments);
|
|
@@ -24,6 +29,203 @@ class StateEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
|
24
29
|
getRelationConfigs() {
|
|
25
30
|
return this.constructor.prototype.constructor.relationConfigs || [];
|
|
26
31
|
}
|
|
32
|
+
get countrys() {
|
|
33
|
+
// many_to_many -> many_to_many verified
|
|
34
|
+
// {'state->vendor': 'one_to_many', 'vendor->country': 'many_to_one'}
|
|
35
|
+
// ['state', 'vendor'] -> one_to_many
|
|
36
|
+
// ['vendor', 'country'] -> many_to_one
|
|
37
|
+
var _a;
|
|
38
|
+
return (_a = this.vendors) === null || _a === void 0 ? void 0 : _a.flatMap((vendor) => vendor.countryModel).filter((country) => !!country).reduce((accumulator, current) => {
|
|
39
|
+
if (!accumulator.some((country) => country.id === current.id)) {
|
|
40
|
+
accumulator.push(current);
|
|
41
|
+
}
|
|
42
|
+
return accumulator;
|
|
43
|
+
}, []);
|
|
44
|
+
}
|
|
45
|
+
get vendorInvoices() {
|
|
46
|
+
// one_to_many -> one_to_many verified
|
|
47
|
+
// {'state->vendor': 'one_to_many', 'vendor->vendor_invoice': 'one_to_many'}
|
|
48
|
+
// ['state', 'vendor'] -> one_to_many
|
|
49
|
+
// ['vendor', 'vendor_invoice'] -> one_to_many
|
|
50
|
+
var _a;
|
|
51
|
+
return (_a = this.vendors) === null || _a === void 0 ? void 0 : _a.flatMap((vendor) => vendor.vendorInvoices).filter((vendorInvoice) => !!vendorInvoice).reduce((accumulator, current) => {
|
|
52
|
+
if (!accumulator.some((vendorInvoice) => vendorInvoice.id === current.id)) {
|
|
53
|
+
accumulator.push(current);
|
|
54
|
+
}
|
|
55
|
+
return accumulator;
|
|
56
|
+
}, []);
|
|
57
|
+
}
|
|
58
|
+
get officeLocations() {
|
|
59
|
+
// many_to_many -> many_to_many verified
|
|
60
|
+
// {'state->vendor': 'one_to_many', 'vendor->vendor_invoice': 'one_to_many', 'vendor_invoice->office_location': 'many_to_one'}
|
|
61
|
+
// ['vendor', 'vendor_invoice'] -> one_to_many
|
|
62
|
+
// ['vendor_invoice', 'office_location'] -> many_to_one
|
|
63
|
+
var _a;
|
|
64
|
+
return (_a = this.vendorInvoices) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoice) => vendorInvoice.officeLocation).filter((officeLocation) => !!officeLocation).reduce((accumulator, current) => {
|
|
65
|
+
if (!accumulator.some((officeLocation) => officeLocation.id === current.id)) {
|
|
66
|
+
accumulator.push(current);
|
|
67
|
+
}
|
|
68
|
+
return accumulator;
|
|
69
|
+
}, []);
|
|
70
|
+
}
|
|
71
|
+
get vendorInvoiceItems() {
|
|
72
|
+
// one_to_many -> one_to_many verified
|
|
73
|
+
// {'state->vendor': 'one_to_many', 'vendor->vendor_invoice': 'one_to_many', 'vendor_invoice->vendor_invoice_item': 'one_to_many'}
|
|
74
|
+
// ['vendor', 'vendor_invoice'] -> one_to_many
|
|
75
|
+
// ['vendor_invoice', 'vendor_invoice_item'] -> one_to_many
|
|
76
|
+
var _a;
|
|
77
|
+
return (_a = this.vendorInvoices) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoice) => vendorInvoice.vendorInvoiceItems).filter((vendorInvoiceItem) => !!vendorInvoiceItem).reduce((accumulator, current) => {
|
|
78
|
+
if (!accumulator.some((vendorInvoiceItem) => vendorInvoiceItem.id === current.id)) {
|
|
79
|
+
accumulator.push(current);
|
|
80
|
+
}
|
|
81
|
+
return accumulator;
|
|
82
|
+
}, []);
|
|
83
|
+
}
|
|
84
|
+
get voucherTypes() {
|
|
85
|
+
// many_to_many -> many_to_many verified
|
|
86
|
+
// {'state->vendor': 'one_to_many', 'vendor->vendor_invoice': 'one_to_many', 'vendor_invoice->vendor_invoice_item': 'one_to_many', 'vendor_invoice_item->voucher_type': 'many_to_one'}
|
|
87
|
+
// ['vendor_invoice', 'vendor_invoice_item'] -> one_to_many
|
|
88
|
+
// ['vendor_invoice_item', 'voucher_type'] -> many_to_one
|
|
89
|
+
var _a;
|
|
90
|
+
return (_a = this.vendorInvoiceItems) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoiceItem) => vendorInvoiceItem.voucherType).filter((voucherType) => !!voucherType).reduce((accumulator, current) => {
|
|
91
|
+
if (!accumulator.some((voucherType) => voucherType.id === current.id)) {
|
|
92
|
+
accumulator.push(current);
|
|
93
|
+
}
|
|
94
|
+
return accumulator;
|
|
95
|
+
}, []);
|
|
96
|
+
}
|
|
97
|
+
get tdsRates() {
|
|
98
|
+
// many_to_many -> many_to_many verified
|
|
99
|
+
// {'state->vendor': 'one_to_many', 'vendor->vendor_invoice': 'one_to_many', 'vendor_invoice->vendor_invoice_item': 'one_to_many', 'vendor_invoice_item->tds_rate': 'many_to_one'}
|
|
100
|
+
// ['vendor_invoice', 'vendor_invoice_item'] -> one_to_many
|
|
101
|
+
// ['vendor_invoice_item', 'tds_rate'] -> many_to_one
|
|
102
|
+
var _a;
|
|
103
|
+
return (_a = this.vendorInvoiceItems) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoiceItem) => vendorInvoiceItem.tdsRate).filter((tdsRate) => !!tdsRate).reduce((accumulator, current) => {
|
|
104
|
+
if (!accumulator.some((tdsRate) => tdsRate.id === current.id)) {
|
|
105
|
+
accumulator.push(current);
|
|
106
|
+
}
|
|
107
|
+
return accumulator;
|
|
108
|
+
}, []);
|
|
109
|
+
}
|
|
110
|
+
get organizationTypes() {
|
|
111
|
+
// many_to_many -> many_to_many verified
|
|
112
|
+
// {'state->vendor': 'one_to_many', 'vendor->organization_type': 'many_to_one'}
|
|
113
|
+
// ['state', 'vendor'] -> one_to_many
|
|
114
|
+
// ['vendor', 'organization_type'] -> many_to_one
|
|
115
|
+
var _a;
|
|
116
|
+
return (_a = this.vendors) === null || _a === void 0 ? void 0 : _a.flatMap((vendor) => vendor.organizationType).filter((organizationType) => !!organizationType).reduce((accumulator, current) => {
|
|
117
|
+
if (!accumulator.some((organizationType) => organizationType.id === current.id)) {
|
|
118
|
+
accumulator.push(current);
|
|
119
|
+
}
|
|
120
|
+
return accumulator;
|
|
121
|
+
}, []);
|
|
122
|
+
}
|
|
123
|
+
get expenseHeads() {
|
|
124
|
+
// many_to_many -> many_to_many verified
|
|
125
|
+
// {'state->vendor': 'one_to_many', 'vendor->vendor_invoice': 'one_to_many', 'vendor_invoice->vendor_invoice_item': 'one_to_many', 'vendor_invoice_item->expense_head': 'many_to_one'}
|
|
126
|
+
// ['vendor_invoice', 'vendor_invoice_item'] -> one_to_many
|
|
127
|
+
// ['vendor_invoice_item', 'expense_head'] -> many_to_one
|
|
128
|
+
var _a;
|
|
129
|
+
return (_a = this.vendorInvoiceItems) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoiceItem) => vendorInvoiceItem.expenseHead).filter((expenseHead) => !!expenseHead).reduce((accumulator, current) => {
|
|
130
|
+
if (!accumulator.some((expenseHead) => expenseHead.id === current.id)) {
|
|
131
|
+
accumulator.push(current);
|
|
132
|
+
}
|
|
133
|
+
return accumulator;
|
|
134
|
+
}, []);
|
|
135
|
+
}
|
|
136
|
+
get gstRates() {
|
|
137
|
+
// many_to_many -> many_to_many verified
|
|
138
|
+
// {'state->vendor': 'one_to_many', 'vendor->vendor_invoice': 'one_to_many', 'vendor_invoice->vendor_invoice_item': 'one_to_many', 'vendor_invoice_item->gst_rate': 'many_to_one'}
|
|
139
|
+
// ['vendor_invoice', 'vendor_invoice_item'] -> one_to_many
|
|
140
|
+
// ['vendor_invoice_item', 'gst_rate'] -> many_to_one
|
|
141
|
+
var _a;
|
|
142
|
+
return (_a = this.vendorInvoiceItems) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoiceItem) => vendorInvoiceItem.gstRate).filter((gstRate) => !!gstRate).reduce((accumulator, current) => {
|
|
143
|
+
if (!accumulator.some((gstRate) => gstRate.id === current.id)) {
|
|
144
|
+
accumulator.push(current);
|
|
145
|
+
}
|
|
146
|
+
return accumulator;
|
|
147
|
+
}, []);
|
|
148
|
+
}
|
|
149
|
+
getNextStatus(currentUser, action, stateFlowConfigContextData) {
|
|
150
|
+
if (!this.status) {
|
|
151
|
+
throw new exceptions_1.AppBadRequestException({
|
|
152
|
+
key: error_key_enum_1.ErrorKeyEnum.STATUS,
|
|
153
|
+
message: [`Status not found: ${this.status}`],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const flowForStatus = state_flow_config_1.stateFlowConfig[this.status];
|
|
157
|
+
if (!flowForStatus) {
|
|
158
|
+
throw new exceptions_1.AppBadRequestException({
|
|
159
|
+
key: error_key_enum_1.ErrorKeyEnum.STATUS,
|
|
160
|
+
message: [`No flow configuration found for status: ${this.status}`],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (!action) {
|
|
164
|
+
throw new exceptions_1.AppBadRequestException({
|
|
165
|
+
key: error_key_enum_1.ErrorKeyEnum.ACTION_DATA,
|
|
166
|
+
message: ["actionData is required"],
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const matchingPermissionConfig = flowForStatus.actions[action];
|
|
170
|
+
if (!matchingPermissionConfig) {
|
|
171
|
+
throw new exceptions_1.AppBadRequestException({
|
|
172
|
+
key: error_key_enum_1.ErrorKeyEnum.ACTION,
|
|
173
|
+
message: [`Action '${action}' is not valid for the current status.`],
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
if (!currentUser.permissions || currentUser.permissions.length === 0) {
|
|
177
|
+
throw new exceptions_1.AppBadRequestException({
|
|
178
|
+
key: error_key_enum_1.ErrorKeyEnum.PERMISSIONS,
|
|
179
|
+
message: ["Permission not available for currentUser"],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const hasPermission = matchingPermissionConfig.permissions.some((permission) => currentUser.permissions.includes(permission));
|
|
183
|
+
if (!hasPermission) {
|
|
184
|
+
throw new exceptions_1.AppBadRequestException({
|
|
185
|
+
key: error_key_enum_1.ErrorKeyEnum.PERMISSION,
|
|
186
|
+
message: [`Current user does not have permission to ${action} state`],
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const nextStatus = matchingPermissionConfig.next(stateFlowConfigContextData);
|
|
190
|
+
return nextStatus;
|
|
191
|
+
}
|
|
192
|
+
// .getAvailableActions(this.currentUserModel, {
|
|
193
|
+
// combinedActions: {
|
|
194
|
+
// approveOrReject: {
|
|
195
|
+
// combineActions: [VendorActionEnum.APPROVE, VendorActionEnum.REJECT],
|
|
196
|
+
// label: "Approve or Reject",
|
|
197
|
+
// },
|
|
198
|
+
// },
|
|
199
|
+
// customLabels: {
|
|
200
|
+
// [VendorActionEnum.APPROVE]: "Approve",
|
|
201
|
+
// [VendorActionEnum.REJECT]: "Reject",
|
|
202
|
+
// },
|
|
203
|
+
// })
|
|
204
|
+
getAvailableActions(currentUser, config) {
|
|
205
|
+
var _a;
|
|
206
|
+
const params = {
|
|
207
|
+
flowConfig: state_flow_config_1.stateFlowConfig,
|
|
208
|
+
currentStatus: this.status,
|
|
209
|
+
userPermissions: (_a = currentUser.permissions) !== null && _a !== void 0 ? _a : [],
|
|
210
|
+
visibilityData: this.getUpdateActionVisibility.bind(this, currentUser),
|
|
211
|
+
combinedActions: config === null || config === void 0 ? void 0 : config.combinedActions,
|
|
212
|
+
customLabels: config === null || config === void 0 ? void 0 : config.customLabels,
|
|
213
|
+
};
|
|
214
|
+
return utils_1.EntityActionFlowResolverV2.getAvailableActionsData(params);
|
|
215
|
+
}
|
|
216
|
+
getUpdateActionVisibility(currentUser) {
|
|
217
|
+
return {};
|
|
218
|
+
}
|
|
27
219
|
}
|
|
28
220
|
exports.StateEntityModel = StateEntityModel;
|
|
29
|
-
StateEntityModel.relationConfigs = [
|
|
221
|
+
StateEntityModel.relationConfigs = [
|
|
222
|
+
{
|
|
223
|
+
name: entity_utils_interface_1.EntityEnum.VENDOR,
|
|
224
|
+
relation: relation_type_enum_1.RelationType.MANY,
|
|
225
|
+
key: "vendors",
|
|
226
|
+
mapKeyConfig: {
|
|
227
|
+
relationKey: "state",
|
|
228
|
+
key: "name",
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
];
|