law-common 11.3.16 → 11.3.18

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.
Files changed (51) hide show
  1. package/dist/src/api/index.d.ts +4 -0
  2. package/dist/src/api/index.js +4 -0
  3. package/dist/src/api/interface/vendor_tds_challan.create.dto.interface.d.ts +5 -0
  4. package/dist/src/api/interface/vendor_tds_challan.create.dto.interface.js +2 -0
  5. package/dist/src/api/interface/vendor_tds_challan.update.dto.interface.d.ts +17 -0
  6. package/dist/src/api/interface/vendor_tds_challan.update.dto.interface.js +17 -0
  7. package/dist/src/api/interface/vendor_tds_liability.create.dto.interface.d.ts +5 -0
  8. package/dist/src/api/interface/vendor_tds_liability.create.dto.interface.js +2 -0
  9. package/dist/src/api/interface/vendor_tds_liability.update.dto.interface.d.ts +22 -0
  10. package/dist/src/api/interface/vendor_tds_liability.update.dto.interface.js +14 -0
  11. package/dist/src/entities/enums/configuration-key.enum.d.ts +4 -0
  12. package/dist/src/entities/enums/configuration-key.enum.js +7 -0
  13. package/dist/src/entities/enums/cron-jobs-name.enum.d.ts +3 -0
  14. package/dist/src/entities/enums/cron-jobs-name.enum.js +3 -0
  15. package/dist/src/entities/enums/vendor_tds_challan_status_enum.d.ts +5 -0
  16. package/dist/src/entities/enums/vendor_tds_challan_status_enum.js +9 -0
  17. package/dist/src/entities/enums/vendor_tds_liability_paid_status_enum.d.ts +4 -0
  18. package/dist/src/entities/enums/vendor_tds_liability_paid_status_enum.js +8 -0
  19. package/dist/src/entities/enums/vendor_tds_liability_status_enum.d.ts +5 -0
  20. package/dist/src/entities/enums/vendor_tds_liability_status_enum.js +9 -0
  21. package/dist/src/entities/flow-configs/vendor_tds_challan_flow.config.d.ts +6 -0
  22. package/dist/src/entities/flow-configs/vendor_tds_challan_flow.config.js +70 -0
  23. package/dist/src/entities/flow-configs/vendor_tds_liability_flow.config.d.ts +13 -0
  24. package/dist/src/entities/flow-configs/vendor_tds_liability_flow.config.js +125 -0
  25. package/dist/src/entities/index.d.ts +9 -0
  26. package/dist/src/entities/index.js +9 -0
  27. package/dist/src/entities/interface/entity.utils.interface.d.ts +9 -3
  28. package/dist/src/entities/interface/entity.utils.interface.js +2 -0
  29. package/dist/src/entities/interface/vendor_tds_challan.entity.interface.d.ts +15 -0
  30. package/dist/src/entities/interface/vendor_tds_challan.entity.interface.js +2 -0
  31. package/dist/src/entities/interface/vendor_tds_liability.entity.interface.d.ts +15 -0
  32. package/dist/src/entities/interface/vendor_tds_liability.entity.interface.js +2 -0
  33. package/dist/src/entities/model/billing.entity.model.d.ts +2 -0
  34. package/dist/src/entities/model/billing.entity.model.js +10 -0
  35. package/dist/src/entities/model/entity.model.interface.js +4 -0
  36. package/dist/src/entities/model/reimbursement-expense.entity.model.d.ts +5 -1
  37. package/dist/src/entities/model/reimbursement-expense.entity.model.js +18 -0
  38. package/dist/src/entities/model/tds_rate.entity.model.autocode.js +225 -1
  39. package/dist/src/entities/model/tds_rate.entity.model.d.ts +7 -1
  40. package/dist/src/entities/model/tds_rate.entity.model.js +18 -0
  41. package/dist/src/entities/model/timesheet.entity.model.d.ts +1 -0
  42. package/dist/src/entities/model/timesheet.entity.model.js +5 -1
  43. package/dist/src/entities/model/vendor_invoice.entity.model.d.ts +8 -1
  44. package/dist/src/entities/model/vendor_invoice.entity.model.js +9 -0
  45. package/dist/src/entities/model/vendor_tds_challan.entity.model.d.ts +69 -0
  46. package/dist/src/entities/model/vendor_tds_challan.entity.model.js +257 -0
  47. package/dist/src/entities/model/vendor_tds_liability.entity.model.d.ts +66 -0
  48. package/dist/src/entities/model/vendor_tds_liability.entity.model.js +222 -0
  49. package/dist/src/enums/error.key.enum.d.ts +2 -1
  50. package/dist/src/enums/error.key.enum.js +1 -0
  51. package/package.json +4 -1
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VendorTdsChallanEntityModel = void 0;
4
+ const date_fns_1 = require("date-fns");
5
+ const entity_utils_interface_1 = require("../interface/entity.utils.interface");
6
+ const base_entity_model_1 = require("./base.entity.model");
7
+ const relation_type_enum_1 = require("../enums/relation-type.enum");
8
+ const exceptions_1 = require("../../exceptions");
9
+ const error_key_enum_1 = require("../../enums/error.key.enum");
10
+ const utils_1 = require("../../utils");
11
+ const vendor_tds_challan_status_enum_1 = require("../enums/vendor_tds_challan_status_enum");
12
+ const vendor_tds_challan_flow_config_1 = require("../flow-configs/vendor_tds_challan_flow.config");
13
+ class VendorTdsChallanEntityModel extends base_entity_model_1.BaseEntityModel {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.id = 0;
17
+ this.challanDate = 0;
18
+ this.period = 0;
19
+ this.tdsRateId = 0;
20
+ this.challanNo = "";
21
+ this.bankId = 0;
22
+ this.amount = 0;
23
+ this.status = vendor_tds_challan_status_enum_1.VendorTdsChallanStatusEnum.APPROVED;
24
+ this.createdOn = 0;
25
+ this.updatedOn = 0;
26
+ this.createdBy = 0;
27
+ this.updatedBy = 0;
28
+ }
29
+ static fromEntity(entity) {
30
+ const result = new VendorTdsChallanEntityModel(entity_utils_interface_1.EntityEnum.VENDOR_TDS_CHALLAN);
31
+ Object.assign(result, entity);
32
+ return result;
33
+ }
34
+ getRelationConfigs() {
35
+ return this.constructor.prototype.constructor.relationConfigs || [];
36
+ }
37
+ get organizationTypes() {
38
+ // many_to_many -> many_to_many verified
39
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many'}
40
+ // ['vendor_tds_challan', 'tds_rate'] -> many_to_one
41
+ // ['tds_rate', 'organization_type'] -> many_to_many
42
+ var _a;
43
+ return (_a = this.tdsRate) === null || _a === void 0 ? void 0 : _a.organizationTypes;
44
+ }
45
+ get vendors() {
46
+ // many_to_many -> many_to_many verified
47
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many', 'organization_type->vendor': 'one_to_many'}
48
+ // ['tds_rate', 'organization_type'] -> many_to_many
49
+ // ['organization_type', 'vendor'] -> one_to_many
50
+ var _a;
51
+ return (_a = this.organizationTypes) === null || _a === void 0 ? void 0 : _a.flatMap((organizationType) => organizationType.vendors).filter((vendor) => !!vendor).reduce((accumulator, current) => {
52
+ if (!accumulator.some((vendor) => vendor.id === current.id)) {
53
+ accumulator.push(current);
54
+ }
55
+ return accumulator;
56
+ }, []);
57
+ }
58
+ get states() {
59
+ // many_to_many -> many_to_many verified
60
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many', 'organization_type->vendor': 'one_to_many', 'vendor->state': 'many_to_one'}
61
+ // ['organization_type', 'vendor'] -> one_to_many
62
+ // ['vendor', 'state'] -> many_to_one
63
+ var _a;
64
+ return (_a = this.vendors) === null || _a === void 0 ? void 0 : _a.flatMap((vendor) => vendor.stateModel).filter((state) => !!state).reduce((accumulator, current) => {
65
+ if (!accumulator.some((state) => state.id === current.id)) {
66
+ accumulator.push(current);
67
+ }
68
+ return accumulator;
69
+ }, []);
70
+ }
71
+ get countrys() {
72
+ // many_to_many -> many_to_many verified
73
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many', 'organization_type->vendor': 'one_to_many', 'vendor->country': 'many_to_one'}
74
+ // ['organization_type', 'vendor'] -> one_to_many
75
+ // ['vendor', 'country'] -> many_to_one
76
+ var _a;
77
+ return (_a = this.vendors) === null || _a === void 0 ? void 0 : _a.flatMap((vendor) => vendor.countryModel).filter((country) => !!country).reduce((accumulator, current) => {
78
+ if (!accumulator.some((country) => country.id === current.id)) {
79
+ accumulator.push(current);
80
+ }
81
+ return accumulator;
82
+ }, []);
83
+ }
84
+ get vendorInvoices() {
85
+ // one_to_many -> many_to_many mismatch
86
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many', 'organization_type->vendor': 'one_to_many', 'vendor->vendor_invoice': 'one_to_many'}
87
+ // ['organization_type', 'vendor'] -> one_to_many
88
+ // ['vendor', 'vendor_invoice'] -> one_to_many
89
+ var _a;
90
+ return (_a = this.vendors) === null || _a === void 0 ? void 0 : _a.flatMap((vendor) => vendor.vendorInvoices).filter((vendorInvoice) => !!vendorInvoice).reduce((accumulator, current) => {
91
+ if (!accumulator.some((vendorInvoice) => vendorInvoice.id === current.id)) {
92
+ accumulator.push(current);
93
+ }
94
+ return accumulator;
95
+ }, []);
96
+ }
97
+ get officeLocations() {
98
+ // many_to_many -> many_to_many verified
99
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many', 'organization_type->vendor': 'one_to_many', 'vendor->vendor_invoice': 'one_to_many', 'vendor_invoice->office_location': 'many_to_one'}
100
+ // ['vendor', 'vendor_invoice'] -> one_to_many
101
+ // ['vendor_invoice', 'office_location'] -> many_to_one
102
+ var _a;
103
+ return (_a = this.vendorInvoices) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoice) => vendorInvoice.officeLocation).filter((officeLocation) => !!officeLocation).reduce((accumulator, current) => {
104
+ if (!accumulator.some((officeLocation) => officeLocation.id === current.id)) {
105
+ accumulator.push(current);
106
+ }
107
+ return accumulator;
108
+ }, []);
109
+ }
110
+ get vendorInvoiceItems() {
111
+ // many_to_many -> many_to_many verified
112
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->vendor_invoice_item': 'one_to_many'}
113
+ // ['vendor_tds_challan', 'tds_rate'] -> many_to_one
114
+ // ['tds_rate', 'vendor_invoice_item'] -> one_to_many
115
+ var _a;
116
+ return (_a = this.tdsRate) === null || _a === void 0 ? void 0 : _a.vendorInvoiceItems;
117
+ }
118
+ get voucherTypes() {
119
+ // many_to_many -> many_to_many verified
120
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->voucher_type': 'many_to_many'}
121
+ // ['vendor_tds_challan', 'tds_rate'] -> many_to_one
122
+ // ['tds_rate', 'voucher_type'] -> many_to_many
123
+ var _a;
124
+ return (_a = this.tdsRate) === null || _a === void 0 ? void 0 : _a.voucherTypes;
125
+ }
126
+ get expenseHeads() {
127
+ // many_to_many -> many_to_many verified
128
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->voucher_type': 'many_to_many', 'voucher_type->expense_head': 'one_to_many'}
129
+ // ['tds_rate', 'voucher_type'] -> many_to_many
130
+ // ['voucher_type', 'expense_head'] -> one_to_many
131
+ var _a;
132
+ return (_a = this.voucherTypes) === null || _a === void 0 ? void 0 : _a.flatMap((voucherType) => voucherType.expenseHeads).filter((expenseHead) => !!expenseHead).reduce((accumulator, current) => {
133
+ if (!accumulator.some((expenseHead) => expenseHead.id === current.id)) {
134
+ accumulator.push(current);
135
+ }
136
+ return accumulator;
137
+ }, []);
138
+ }
139
+ get gstRates() {
140
+ // many_to_many -> many_to_many verified
141
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->vendor_invoice_item': 'one_to_many', 'vendor_invoice_item->gst_rate': 'many_to_one'}
142
+ // ['tds_rate', 'vendor_invoice_item'] -> one_to_many
143
+ // ['vendor_invoice_item', 'gst_rate'] -> many_to_one
144
+ var _a;
145
+ return (_a = this.vendorInvoiceItems) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoiceItem) => vendorInvoiceItem.gstRate).filter((gstRate) => !!gstRate).reduce((accumulator, current) => {
146
+ if (!accumulator.some((gstRate) => gstRate.id === current.id)) {
147
+ accumulator.push(current);
148
+ }
149
+ return accumulator;
150
+ }, []);
151
+ }
152
+ get vendorInvoicePayments() {
153
+ // one_to_many -> many_to_many mismatch
154
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many', 'organization_type->vendor': 'one_to_many', 'vendor->vendor_invoice': 'one_to_many', 'vendor_invoice->vendor_invoice_payment': 'one_to_many'}
155
+ // ['vendor', 'vendor_invoice'] -> one_to_many
156
+ // ['vendor_invoice', 'vendor_invoice_payment'] -> one_to_many
157
+ var _a;
158
+ return (_a = this.vendorInvoices) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoice) => vendorInvoice.vendorInvoicePayments).filter((vendorInvoicePayment) => !!vendorInvoicePayment).reduce((accumulator, current) => {
159
+ if (!accumulator.some((vendorInvoicePayment) => vendorInvoicePayment.id === current.id)) {
160
+ accumulator.push(current);
161
+ }
162
+ return accumulator;
163
+ }, []);
164
+ }
165
+ get vendorTdsLiabilitys() {
166
+ // many_to_many -> many_to_many verified
167
+ // {'vendor_tds_challan->tds_rate': 'many_to_one', 'tds_rate->vendor_tds_liability': 'one_to_many'}
168
+ // ['vendor_tds_challan', 'tds_rate'] -> many_to_one
169
+ // ['tds_rate', 'vendor_tds_liability'] -> one_to_many
170
+ var _a;
171
+ return (_a = this.tdsRate) === null || _a === void 0 ? void 0 : _a.vendorTdsLiabilitys;
172
+ }
173
+ getNextStatus(currentUser, action, vendorTdsChallanFlowConfigContextData) {
174
+ if (!this.status) {
175
+ throw new exceptions_1.AppBadRequestException({
176
+ key: error_key_enum_1.ErrorKeyEnum.STATUS,
177
+ message: [`Status not found: ${this.status}`],
178
+ });
179
+ }
180
+ const flowForStatus = vendor_tds_challan_flow_config_1.vendorTdsChallanFlowConfig[this.status];
181
+ if (!flowForStatus) {
182
+ throw new exceptions_1.AppBadRequestException({
183
+ key: error_key_enum_1.ErrorKeyEnum.STATUS,
184
+ message: [`No flow configuration found for status: ${this.status}`],
185
+ });
186
+ }
187
+ if (!action) {
188
+ throw new exceptions_1.AppBadRequestException({
189
+ key: error_key_enum_1.ErrorKeyEnum.ACTION_DATA,
190
+ message: ["actionData is required"],
191
+ });
192
+ }
193
+ const matchingPermissionConfig = flowForStatus.actions[action];
194
+ if (!matchingPermissionConfig) {
195
+ throw new exceptions_1.AppBadRequestException({
196
+ key: error_key_enum_1.ErrorKeyEnum.ACTION,
197
+ message: [`Action '${action}' is not valid for the current status.`],
198
+ });
199
+ }
200
+ if (!currentUser.permissions || currentUser.permissions.length === 0) {
201
+ throw new exceptions_1.AppBadRequestException({
202
+ key: error_key_enum_1.ErrorKeyEnum.PERMISSIONS,
203
+ message: ["Permission not available for currentUser"],
204
+ });
205
+ }
206
+ const hasPermission = matchingPermissionConfig.permissions.some((permission) => currentUser.permissions.includes(permission));
207
+ if (!hasPermission) {
208
+ throw new exceptions_1.AppBadRequestException({
209
+ key: error_key_enum_1.ErrorKeyEnum.PERMISSION,
210
+ message: [`Current user does not have permission to ${action} vendorTdsChallan`],
211
+ });
212
+ }
213
+ const nextStatus = matchingPermissionConfig.next(vendorTdsChallanFlowConfigContextData);
214
+ return nextStatus;
215
+ }
216
+ getAvailableActions(currentUser, config) {
217
+ var _a;
218
+ const params = {
219
+ flowConfig: vendor_tds_challan_flow_config_1.vendorTdsChallanFlowConfig,
220
+ currentStatus: this.status,
221
+ userPermissions: (_a = currentUser.permissions) !== null && _a !== void 0 ? _a : [],
222
+ visibilityData: this.getUpdateActionVisibility.bind(this, currentUser),
223
+ combinedActions: config === null || config === void 0 ? void 0 : config.combinedActions,
224
+ customLabels: config === null || config === void 0 ? void 0 : config.customLabels,
225
+ };
226
+ return utils_1.EntityActionFlowResolverV2.getAvailableActionsData(params);
227
+ }
228
+ getUpdateActionVisibility(currentUser) {
229
+ return {};
230
+ }
231
+ formatPeriod(formatStr = "MMM-yyyy") {
232
+ const year = Math.floor(this.period / 100);
233
+ const month = this.period % 100;
234
+ return (0, date_fns_1.format)(new Date(year, month - 1), formatStr);
235
+ }
236
+ }
237
+ exports.VendorTdsChallanEntityModel = VendorTdsChallanEntityModel;
238
+ VendorTdsChallanEntityModel.relationConfigs = [
239
+ {
240
+ name: entity_utils_interface_1.EntityEnum.BANK,
241
+ relation: relation_type_enum_1.RelationType.ONE,
242
+ key: "bank",
243
+ mapKeyConfig: {
244
+ relationKey: "id",
245
+ key: "bankId",
246
+ },
247
+ },
248
+ {
249
+ name: entity_utils_interface_1.EntityEnum.TDS_RATE,
250
+ relation: relation_type_enum_1.RelationType.ONE,
251
+ key: "tdsRate",
252
+ mapKeyConfig: {
253
+ relationKey: "id",
254
+ key: "tdsRateId",
255
+ },
256
+ },
257
+ ];
@@ -0,0 +1,66 @@
1
+ import { EntityEnum } from "../interface/entity.utils.interface";
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 { IVendorTdsLiabilityEntity } from "../interface/vendor_tds_liability.entity.interface";
8
+ import { VendorTdsLiabilityPaidStatusEnum } from "../enums/vendor_tds_liability_paid_status_enum";
9
+ import { VendorTdsLiabilityStatusEnum } from "../enums/vendor_tds_liability_status_enum";
10
+ import { TdsRateEntityModel } from "./tds_rate.entity.model";
11
+ import { OrganizationTypeEntityModel } from "./organization_type.entity.model";
12
+ import { VendorEntityModel } from "./vendor.entity.model";
13
+ import { StateEntityModel } from "./state.entity.model";
14
+ import { CountryEntityModel } from "./country.entity.model";
15
+ import { VendorInvoiceEntityModel } from "./vendor_invoice.entity.model";
16
+ import { VendorInvoiceItemEntityModel } from "./vendor_invoice_item.entity.model";
17
+ import { VoucherTypeEntityModel } from "./voucher_type.entity.model";
18
+ import { GstRateEntityModel } from "./gst_rate.entity.model";
19
+ import { VendorTdsLiabilityActionEnum } from "../../api";
20
+ import { IVendorTdsLiabilityFlowConfigContextData } from "../flow-configs/vendor_tds_liability_flow.config";
21
+ export declare class VendorTdsLiabilityEntityModel extends BaseEntityModel<EntityEnum.VENDOR_TDS_LIABILITY> implements IVendorTdsLiabilityEntity {
22
+ id: number;
23
+ period: number;
24
+ tdsRateId: number;
25
+ tdsDeducted: number;
26
+ tdsPaid?: number;
27
+ paidStatus: VendorTdsLiabilityPaidStatusEnum;
28
+ status: VendorTdsLiabilityStatusEnum;
29
+ dueDate: number;
30
+ pendingAmount?: number;
31
+ createdOn: number;
32
+ updatedOn: number;
33
+ createdBy: number;
34
+ updatedBy: number;
35
+ tdsRate?: TdsRateEntityModel;
36
+ static relationConfigs: RelationConfigs<[EntityEnum.TDS_RATE], EntityEnum.VENDOR_TDS_LIABILITY>;
37
+ static fromEntity(entity: IVendorTdsLiabilityEntity): VendorTdsLiabilityEntityModel;
38
+ getRelationConfigs(): any[];
39
+ get organizationTypes(): OrganizationTypeEntityModel[] | undefined;
40
+ get vendors(): VendorEntityModel[] | undefined;
41
+ get states(): StateEntityModel[] | undefined;
42
+ get countrys(): CountryEntityModel[] | undefined;
43
+ get vendorInvoiceItems(): VendorInvoiceItemEntityModel[] | undefined;
44
+ get vendorInvoices(): VendorInvoiceEntityModel[] | undefined;
45
+ get voucherTypes(): VoucherTypeEntityModel[] | undefined;
46
+ get gstRates(): GstRateEntityModel[] | undefined;
47
+ getNextStatus(currentUser: IUserEntity, action: VendorTdsLiabilityActionEnum, vendorTdsLiabilityFlowConfigContextData: IVendorTdsLiabilityFlowConfigContextData): VendorTdsLiabilityStatusEnum;
48
+ getAvailableActions(currentUser: UserEntityModel, config?: {
49
+ combinedActions?: Record<string, {
50
+ combineActions: VendorTdsLiabilityActionEnum[];
51
+ label: string;
52
+ }>;
53
+ customLabels?: Partial<Record<VendorTdsLiabilityActionEnum, string>>;
54
+ }): IRowActions<EntityEnum.VENDOR_TDS_LIABILITY>[];
55
+ getUpdateActionVisibility(currentUser: UserEntityModel): {
56
+ [key: string]: () => boolean;
57
+ };
58
+ formatPeriod(formatStr: string): string;
59
+ static derivePeriodFromDateCode({ dateCode }: {
60
+ dateCode: number;
61
+ }): number;
62
+ static deriveDueDateFromPeriod({ period }: {
63
+ period: number;
64
+ }): number;
65
+ static filterByPeriodTdsRateId(period: number, tdsRateId: number, vendorTdsLiabilityEntities: VendorTdsLiabilityEntityModel[]): VendorTdsLiabilityEntityModel | undefined;
66
+ }
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VendorTdsLiabilityEntityModel = void 0;
4
+ const date_fns_1 = require("date-fns");
5
+ const entity_utils_interface_1 = require("../interface/entity.utils.interface");
6
+ const base_entity_model_1 = require("./base.entity.model");
7
+ const relation_type_enum_1 = require("../enums/relation-type.enum");
8
+ const exceptions_1 = require("../../exceptions");
9
+ const error_key_enum_1 = require("../../enums/error.key.enum");
10
+ const utils_1 = require("../../utils");
11
+ const vendor_tds_liability_paid_status_enum_1 = require("../enums/vendor_tds_liability_paid_status_enum");
12
+ const vendor_tds_liability_status_enum_1 = require("../enums/vendor_tds_liability_status_enum");
13
+ // import { IVendorTdsLiabilityFlowConfigContextData } from "../flow-configs/vendor_tds_liability_flow.config";
14
+ const vendor_tds_liability_flow_config_1 = require("../flow-configs/vendor_tds_liability_flow.config");
15
+ class VendorTdsLiabilityEntityModel extends base_entity_model_1.BaseEntityModel {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.id = 0;
19
+ this.period = 0;
20
+ this.tdsRateId = 0;
21
+ this.tdsDeducted = 0;
22
+ this.paidStatus = vendor_tds_liability_paid_status_enum_1.VendorTdsLiabilityPaidStatusEnum.PAID;
23
+ this.status = vendor_tds_liability_status_enum_1.VendorTdsLiabilityStatusEnum.APPROVED;
24
+ this.dueDate = 0;
25
+ this.createdOn = 0;
26
+ this.updatedOn = 0;
27
+ this.createdBy = 0;
28
+ this.updatedBy = 0;
29
+ }
30
+ static fromEntity(entity) {
31
+ const result = new VendorTdsLiabilityEntityModel(entity_utils_interface_1.EntityEnum.VENDOR_TDS_LIABILITY);
32
+ Object.assign(result, entity);
33
+ return result;
34
+ }
35
+ getRelationConfigs() {
36
+ return this.constructor.prototype.constructor.relationConfigs || [];
37
+ }
38
+ get organizationTypes() {
39
+ // many_to_many -> many_to_many verified
40
+ // {'vendor_tds_liability->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many'}
41
+ // ['vendor_tds_liability', 'tds_rate'] -> many_to_one
42
+ // ['tds_rate', 'organization_type'] -> many_to_many
43
+ var _a;
44
+ return (_a = this.tdsRate) === null || _a === void 0 ? void 0 : _a.organizationTypes.filter((organizationType) => !!organizationType).reduce((accumulator, current) => {
45
+ if (!accumulator.some((organizationType) => organizationType.id === current.id)) {
46
+ accumulator.push(current);
47
+ }
48
+ return accumulator;
49
+ }, []);
50
+ }
51
+ get vendors() {
52
+ // many_to_many -> many_to_many verified
53
+ // {'vendor_tds_liability->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many', 'organization_type->vendor': 'one_to_many'}
54
+ // ['tds_rate', 'organization_type'] -> many_to_many
55
+ // ['organization_type', 'vendor'] -> one_to_many
56
+ var _a;
57
+ return (_a = this.organizationTypes) === null || _a === void 0 ? void 0 : _a.flatMap((organizationType) => organizationType.vendors).filter((vendor) => !!vendor).reduce((accumulator, current) => {
58
+ if (!accumulator.some((vendor) => vendor.id === current.id)) {
59
+ accumulator.push(current);
60
+ }
61
+ return accumulator;
62
+ }, []);
63
+ }
64
+ get states() {
65
+ // many_to_many -> many_to_many verified
66
+ // {'vendor_tds_liability->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many', 'organization_type->vendor': 'one_to_many', 'vendor->state': 'many_to_one'}
67
+ // ['organization_type', 'vendor'] -> one_to_many
68
+ // ['vendor', 'state'] -> many_to_one
69
+ var _a;
70
+ return (_a = this.vendors) === null || _a === void 0 ? void 0 : _a.flatMap((vendor) => vendor.stateModel).filter((state) => !!state).reduce((accumulator, current) => {
71
+ if (!accumulator.some((state) => state.id === current.id)) {
72
+ accumulator.push(current);
73
+ }
74
+ return accumulator;
75
+ }, []);
76
+ }
77
+ get countrys() {
78
+ // many_to_many -> many_to_many verified
79
+ // {'vendor_tds_liability->tds_rate': 'many_to_one', 'tds_rate->organization_type': 'many_to_many', 'organization_type->vendor': 'one_to_many', 'vendor->country': 'many_to_one'}
80
+ // ['organization_type', 'vendor'] -> one_to_many
81
+ // ['vendor', 'country'] -> many_to_one
82
+ var _a;
83
+ return (_a = this.vendors) === null || _a === void 0 ? void 0 : _a.flatMap((vendor) => vendor.countryModel).filter((country) => !!country).reduce((accumulator, current) => {
84
+ if (!accumulator.some((country) => country.id === current.id)) {
85
+ accumulator.push(current);
86
+ }
87
+ return accumulator;
88
+ }, []);
89
+ }
90
+ get vendorInvoiceItems() {
91
+ var _a;
92
+ return (_a = this.tdsRate) === null || _a === void 0 ? void 0 : _a.vendorInvoiceItems;
93
+ }
94
+ get vendorInvoices() {
95
+ // many_to_many -> many_to_many verified
96
+ // {'vendor_tds_liability->tds_rate': 'many_to_one', 'tds_rate->vendor_invoice_item': 'one_to_many', 'vendor_invoice_item->vendor_invoice': 'many_to_one'}
97
+ // ['tds_rate', 'vendor_invoice_item'] -> one_to_many
98
+ // ['vendor_invoice_item', 'vendor_invoice'] -> many_to_one
99
+ var _a;
100
+ return (_a = this.vendorInvoiceItems) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoiceItem) => vendorInvoiceItem.vendorInvoice).filter((vendorInvoice) => !!vendorInvoice).reduce((accumulator, current) => {
101
+ if (!accumulator.some((vendorInvoice) => vendorInvoice.id === current.id)) {
102
+ accumulator.push(current);
103
+ }
104
+ return accumulator;
105
+ }, []);
106
+ }
107
+ get voucherTypes() {
108
+ // many_to_many -> many_to_many verified
109
+ // {'vendor_tds_liability->tds_rate': 'many_to_one', 'tds_rate->vendor_invoice_item': 'one_to_many', 'vendor_invoice_item->voucher_type': 'many_to_one'}
110
+ // ['tds_rate', 'vendor_invoice_item'] -> one_to_many
111
+ // ['vendor_invoice_item', 'voucher_type'] -> many_to_one
112
+ var _a;
113
+ return (_a = this.vendorInvoiceItems) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoiceItem) => vendorInvoiceItem.voucherType).filter((voucherType) => !!voucherType).reduce((accumulator, current) => {
114
+ if (!accumulator.some((voucherType) => voucherType.id === current.id)) {
115
+ accumulator.push(current);
116
+ }
117
+ return accumulator;
118
+ }, []);
119
+ }
120
+ get gstRates() {
121
+ // many_to_many -> many_to_many verified
122
+ // {'vendor_tds_liability->tds_rate': 'many_to_one', 'tds_rate->vendor_invoice_item': 'one_to_many', 'vendor_invoice_item->gst_rate': 'many_to_one'}
123
+ // ['tds_rate', 'vendor_invoice_item'] -> one_to_many
124
+ // ['vendor_invoice_item', 'gst_rate'] -> many_to_one
125
+ var _a;
126
+ return (_a = this.vendorInvoiceItems) === null || _a === void 0 ? void 0 : _a.flatMap((vendorInvoiceItem) => vendorInvoiceItem.gstRate).filter((gstRate) => !!gstRate).reduce((accumulator, current) => {
127
+ if (!accumulator.some((gstRate) => gstRate.id === current.id)) {
128
+ accumulator.push(current);
129
+ }
130
+ return accumulator;
131
+ }, []);
132
+ }
133
+ getNextStatus(currentUser, action, vendorTdsLiabilityFlowConfigContextData) {
134
+ if (!this.status) {
135
+ throw new exceptions_1.AppBadRequestException({
136
+ key: error_key_enum_1.ErrorKeyEnum.STATUS,
137
+ message: [`Status not found: ${this.status}`],
138
+ });
139
+ }
140
+ const flowForStatus = vendor_tds_liability_flow_config_1.vendorTdsLiabilityFlowConfig[this.status];
141
+ if (!flowForStatus) {
142
+ throw new exceptions_1.AppBadRequestException({
143
+ key: error_key_enum_1.ErrorKeyEnum.STATUS,
144
+ message: [`No flow configuration found for status: ${this.status}`],
145
+ });
146
+ }
147
+ if (!action) {
148
+ throw new exceptions_1.AppBadRequestException({
149
+ key: error_key_enum_1.ErrorKeyEnum.ACTION_DATA,
150
+ message: ["actionData is required"],
151
+ });
152
+ }
153
+ const matchingPermissionConfig = flowForStatus.actions[action];
154
+ if (!matchingPermissionConfig) {
155
+ throw new exceptions_1.AppBadRequestException({
156
+ key: error_key_enum_1.ErrorKeyEnum.ACTION,
157
+ message: [`Action '${action}' is not valid for the current status.`],
158
+ });
159
+ }
160
+ if (!currentUser.permissions || currentUser.permissions.length === 0) {
161
+ throw new exceptions_1.AppBadRequestException({
162
+ key: error_key_enum_1.ErrorKeyEnum.PERMISSIONS,
163
+ message: ["Permission not available for currentUser"],
164
+ });
165
+ }
166
+ const hasPermission = matchingPermissionConfig.permissions.some((permission) => currentUser.permissions.includes(permission));
167
+ if (!hasPermission) {
168
+ throw new exceptions_1.AppBadRequestException({
169
+ key: error_key_enum_1.ErrorKeyEnum.PERMISSION,
170
+ message: [`Current user does not have permission to ${action} vendorTdsLiability`],
171
+ });
172
+ }
173
+ const nextStatus = matchingPermissionConfig.next(vendorTdsLiabilityFlowConfigContextData);
174
+ return nextStatus;
175
+ }
176
+ getAvailableActions(currentUser, config) {
177
+ var _a;
178
+ const params = {
179
+ flowConfig: vendor_tds_liability_flow_config_1.vendorTdsLiabilityFlowConfig,
180
+ currentStatus: this.status,
181
+ userPermissions: (_a = currentUser.permissions) !== null && _a !== void 0 ? _a : [],
182
+ visibilityData: this.getUpdateActionVisibility.bind(this, currentUser),
183
+ combinedActions: config === null || config === void 0 ? void 0 : config.combinedActions,
184
+ customLabels: config === null || config === void 0 ? void 0 : config.customLabels,
185
+ };
186
+ return utils_1.EntityActionFlowResolverV2.getAvailableActionsData(params);
187
+ }
188
+ getUpdateActionVisibility(currentUser) {
189
+ return {};
190
+ }
191
+ formatPeriod(formatStr) {
192
+ const year = Math.floor(this.period / 100);
193
+ const month = this.period % 100;
194
+ return (0, date_fns_1.format)(new Date(year, month - 1), formatStr);
195
+ }
196
+ static derivePeriodFromDateCode({ dateCode }) {
197
+ return parseInt(dateCode.toString().slice(0, 6));
198
+ }
199
+ static deriveDueDateFromPeriod({ period }) {
200
+ // YYYYMM -> YYYY(MM + 1)07
201
+ const year = Math.floor(period / 100);
202
+ const month = period % 100;
203
+ const nextMonth = month === 12 ? 1 : month + 1;
204
+ const nextYear = month === 12 ? year + 1 : year;
205
+ return nextYear * 10000 + nextMonth * 100 + 7;
206
+ }
207
+ static filterByPeriodTdsRateId(period, tdsRateId, vendorTdsLiabilityEntities) {
208
+ return vendorTdsLiabilityEntities.find((entity) => entity.period === period && entity.tdsRateId === tdsRateId);
209
+ }
210
+ }
211
+ exports.VendorTdsLiabilityEntityModel = VendorTdsLiabilityEntityModel;
212
+ VendorTdsLiabilityEntityModel.relationConfigs = [
213
+ {
214
+ name: entity_utils_interface_1.EntityEnum.TDS_RATE,
215
+ relation: relation_type_enum_1.RelationType.ONE,
216
+ key: "tdsRate",
217
+ mapKeyConfig: {
218
+ relationKey: "id",
219
+ key: "tdsRateId",
220
+ },
221
+ },
222
+ ];
@@ -35,5 +35,6 @@ export declare enum ErrorKeyEnum {
35
35
  VENDOR_INVOICE_ITEMS = "VENDOR_INVOICE_ITEMS",
36
36
  PROJECT_USER_MAPPING = "PROJECT_USER_MAPPING",
37
37
  CONFIGURATION_KEY = "CONFIGURATION_KEY",
38
- VENDOR_INVOICE_FLOW_CONTEXT_DATA = "VENDOR_INVOICE_FLOW_CONTEXT_DATA"
38
+ VENDOR_INVOICE_FLOW_CONTEXT_DATA = "VENDOR_INVOICE_FLOW_CONTEXT_DATA",
39
+ VENDOR_TDS_LIABILITY_FLOW_CONTEXT_DATA = "VENDOR_TDS_LIABILITY_FLOW_CONTEXT_DATA"
39
40
  }
@@ -40,4 +40,5 @@ var ErrorKeyEnum;
40
40
  ErrorKeyEnum["PROJECT_USER_MAPPING"] = "PROJECT_USER_MAPPING";
41
41
  ErrorKeyEnum["CONFIGURATION_KEY"] = "CONFIGURATION_KEY";
42
42
  ErrorKeyEnum["VENDOR_INVOICE_FLOW_CONTEXT_DATA"] = "VENDOR_INVOICE_FLOW_CONTEXT_DATA";
43
+ ErrorKeyEnum["VENDOR_TDS_LIABILITY_FLOW_CONTEXT_DATA"] = "VENDOR_TDS_LIABILITY_FLOW_CONTEXT_DATA";
43
44
  })(ErrorKeyEnum || (exports.ErrorKeyEnum = ErrorKeyEnum = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "law-common",
3
- "version": "11.3.16",
3
+ "version": "11.3.18",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -15,6 +15,9 @@
15
15
  "publish:minor": "npm version minor && git push && npm run build && npm publish",
16
16
  "publish:major": "npm verYsion major && git push && npm run build && npm publish",
17
17
  "link": "npm run build && npm link",
18
+ "link:backend": "npm run build && npm link && cd ../law-backend && npm link law-common && cd ../law-common",
19
+ "link:frontend": "npm run build && npm link && cd ../law-admin-web && npm link law-common && cd ../law-common",
20
+ "link:both": "npm run build && npm link && cd ../law-backend && npm link law-common && cd ../law-admin-web && npm link law-common && cd ../law-common",
18
21
  "test": "jest",
19
22
  "format": "prettier --write .",
20
23
  "check-format": "prettier --check .",