gm-mcp 2.0.12 → 2.0.14
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/index.js +2 -2
- package/dist/tools/constants/customer-ewa.d.ts +5 -0
- package/dist/tools/constants/customer-ewa.js +17 -0
- package/dist/tools/constants/dda.d.ts +8 -0
- package/dist/tools/constants/dda.js +32 -0
- package/dist/tools/constants/employee.d.ts +13 -0
- package/dist/tools/constants/employee.js +64 -0
- package/dist/tools/eligibility-tools_v2.d.ts +7 -0
- package/dist/tools/eligibility-tools_v2.js +279 -0
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/tools/constants/customer-ewa.ts +15 -0
- package/src/tools/constants/dda.ts +30 -0
- package/src/tools/constants/employee.ts +61 -0
- package/src/tools/eligibility-tools_v2.ts +315 -0
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ const tools_1 = require("./tools");
|
|
|
20
20
|
const zod_1 = __importDefault(require("zod"));
|
|
21
21
|
const env_1 = require("./env");
|
|
22
22
|
const lark_tool_1 = require("./tools/lark-tool");
|
|
23
|
-
const
|
|
23
|
+
const eligibility_tools_v2_1 = require("./tools/eligibility-tools_v2");
|
|
24
24
|
exports.server = new mcp_js_1.McpServer({
|
|
25
25
|
name: "mcp-server",
|
|
26
26
|
version: "1.0.0",
|
|
@@ -85,7 +85,7 @@ exports.server.tool("check_eligibility", "Check customer's eligibility for salar
|
|
|
85
85
|
phone_number: zod_1.default.string({ description: "Customer's phone number" }),
|
|
86
86
|
}, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
87
|
const { phone_number } = args;
|
|
88
|
-
return (0,
|
|
88
|
+
return (0, eligibility_tools_v2_1.elgibilityToolV2)(phone_number);
|
|
89
89
|
}));
|
|
90
90
|
function bootstap() {
|
|
91
91
|
(0, env_1.ensureEnvVariables)();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CUSTOMER_EWA_STATUS_MAPS = exports.CustomerEwaStatus = void 0;
|
|
4
|
+
exports.CustomerEwaStatus = {
|
|
5
|
+
DEACTIVATE: "DEACTIVATE",
|
|
6
|
+
ACTIVE: "ACTIVE",
|
|
7
|
+
};
|
|
8
|
+
exports.CUSTOMER_EWA_STATUS_MAPS = {
|
|
9
|
+
DEACTIVATE: {
|
|
10
|
+
id: exports.CustomerEwaStatus.DEACTIVATE,
|
|
11
|
+
label: "Tạm ngưng",
|
|
12
|
+
},
|
|
13
|
+
ACTIVE: {
|
|
14
|
+
id: exports.CustomerEwaStatus.ACTIVE,
|
|
15
|
+
label: "Hoạt động",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const DdaStatus: {
|
|
2
|
+
readonly UNREGISTERED: "UNREGISTERED";
|
|
3
|
+
readonly REGISTERED: "REGISTERED";
|
|
4
|
+
readonly CANCEL: "CANCEL";
|
|
5
|
+
readonly WAITING_BANK_APPROVE: "WAITING_BANK_APPROVE";
|
|
6
|
+
readonly REJECTED: "REJECTED";
|
|
7
|
+
};
|
|
8
|
+
export declare const DDA_STATUS_MAPS: Record<string, any>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DDA_STATUS_MAPS = exports.DdaStatus = void 0;
|
|
4
|
+
exports.DdaStatus = {
|
|
5
|
+
UNREGISTERED: "UNREGISTERED",
|
|
6
|
+
REGISTERED: "REGISTERED",
|
|
7
|
+
CANCEL: "CANCEL",
|
|
8
|
+
WAITING_BANK_APPROVE: "WAITING_BANK_APPROVE",
|
|
9
|
+
REJECTED: "REJECTED",
|
|
10
|
+
};
|
|
11
|
+
exports.DDA_STATUS_MAPS = {
|
|
12
|
+
UNREGISTERED: {
|
|
13
|
+
id: exports.DdaStatus.UNREGISTERED,
|
|
14
|
+
label: "Chưa đăng ký",
|
|
15
|
+
},
|
|
16
|
+
REGISTERED: {
|
|
17
|
+
id: exports.DdaStatus.REGISTERED,
|
|
18
|
+
label: "Đã đăng ký",
|
|
19
|
+
},
|
|
20
|
+
CANCEL: {
|
|
21
|
+
id: exports.DdaStatus.CANCEL,
|
|
22
|
+
label: "Đã huỷ",
|
|
23
|
+
},
|
|
24
|
+
WAITING_BANK_APPROVE: {
|
|
25
|
+
id: exports.DdaStatus.WAITING_BANK_APPROVE,
|
|
26
|
+
label: "Chờ bank xác nhận",
|
|
27
|
+
},
|
|
28
|
+
REJECTED: {
|
|
29
|
+
id: exports.DdaStatus.REJECTED,
|
|
30
|
+
label: "Bị tử chối",
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum EmployeeStatus {
|
|
2
|
+
ACTIVE = "ACTIVE",
|
|
3
|
+
SUSPEND__WAITING_TO_APPROVE = "SUSPEND__WAITING_TO_APPROVE",
|
|
4
|
+
SUSPEND__MATERNITY_LEAVE = "SUSPEND__MATERNITY_LEAVE",
|
|
5
|
+
SUSPEND__UNPAID_LEAVE = "SUSPEND__UNPAID_LEAVE",
|
|
6
|
+
SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT = "SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT",
|
|
7
|
+
SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT = "SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT",
|
|
8
|
+
SUSPEND__WAITING_FOR_DEBT_PAYMENT = "SUSPEND__WAITING_FOR_DEBT_PAYMENT",
|
|
9
|
+
SUSPEND__DEFAULT = "SUSPEND__DEFAULT",
|
|
10
|
+
SUSPEND__DDA_REACH_LIMIT = "SUSPEND__DDA_REACH_LIMIT",
|
|
11
|
+
INACTIVE = "INACTIVE"
|
|
12
|
+
}
|
|
13
|
+
export declare const EMPLOYEE_STATUS_MAPS: Record<string, any>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EMPLOYEE_STATUS_MAPS = exports.EmployeeStatus = void 0;
|
|
4
|
+
var EmployeeStatus;
|
|
5
|
+
(function (EmployeeStatus) {
|
|
6
|
+
EmployeeStatus["ACTIVE"] = "ACTIVE";
|
|
7
|
+
EmployeeStatus["SUSPEND__WAITING_TO_APPROVE"] = "SUSPEND__WAITING_TO_APPROVE";
|
|
8
|
+
EmployeeStatus["SUSPEND__MATERNITY_LEAVE"] = "SUSPEND__MATERNITY_LEAVE";
|
|
9
|
+
EmployeeStatus["SUSPEND__UNPAID_LEAVE"] = "SUSPEND__UNPAID_LEAVE";
|
|
10
|
+
EmployeeStatus["SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT"] = "SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT";
|
|
11
|
+
EmployeeStatus["SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT"] = "SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT";
|
|
12
|
+
EmployeeStatus["SUSPEND__WAITING_FOR_DEBT_PAYMENT"] = "SUSPEND__WAITING_FOR_DEBT_PAYMENT";
|
|
13
|
+
EmployeeStatus["SUSPEND__DEFAULT"] = "SUSPEND__DEFAULT";
|
|
14
|
+
EmployeeStatus["SUSPEND__DDA_REACH_LIMIT"] = "SUSPEND__DDA_REACH_LIMIT";
|
|
15
|
+
EmployeeStatus["INACTIVE"] = "INACTIVE";
|
|
16
|
+
})(EmployeeStatus || (exports.EmployeeStatus = EmployeeStatus = {}));
|
|
17
|
+
exports.EMPLOYEE_STATUS_MAPS = {
|
|
18
|
+
ACTIVE: {
|
|
19
|
+
id: EmployeeStatus.ACTIVE,
|
|
20
|
+
label: "Đang làm việc",
|
|
21
|
+
},
|
|
22
|
+
SUSPEND__WAITING_TO_APPROVE: {
|
|
23
|
+
id: EmployeeStatus.SUSPEND__WAITING_TO_APPROVE,
|
|
24
|
+
label: "Chờ công đoàn phê duyệt",
|
|
25
|
+
},
|
|
26
|
+
SUSPEND__MATERNITY_LEAVE: {
|
|
27
|
+
id: EmployeeStatus.SUSPEND__MATERNITY_LEAVE,
|
|
28
|
+
label: "Nhân sự nghỉ thai sản",
|
|
29
|
+
},
|
|
30
|
+
SUSPEND__UNPAID_LEAVE: {
|
|
31
|
+
id: EmployeeStatus.SUSPEND__UNPAID_LEAVE,
|
|
32
|
+
label: "Nhân sự nghỉ không lương",
|
|
33
|
+
},
|
|
34
|
+
SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT: {
|
|
35
|
+
id: EmployeeStatus.SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT,
|
|
36
|
+
label: "Chờ cập nhật chứng minh thu nhập",
|
|
37
|
+
},
|
|
38
|
+
SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT: {
|
|
39
|
+
id: EmployeeStatus.SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT,
|
|
40
|
+
label: "Chờ phê duyệt chứng minh thu nhập",
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated
|
|
44
|
+
*/
|
|
45
|
+
SUSPEND__WAITING_FOR_DEBT_PAYMENT: {
|
|
46
|
+
id: EmployeeStatus.SUSPEND__WAITING_FOR_DEBT_PAYMENT,
|
|
47
|
+
label: "Chờ thanh toán công nợ",
|
|
48
|
+
},
|
|
49
|
+
SUSPEND__DEFAULT: {
|
|
50
|
+
id: EmployeeStatus.SUSPEND__DEFAULT,
|
|
51
|
+
label: "Tạm nghỉ",
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated
|
|
55
|
+
*/
|
|
56
|
+
SUSPEND__DDA_REACH_LIMIT: {
|
|
57
|
+
id: EmployeeStatus.SUSPEND__DDA_REACH_LIMIT,
|
|
58
|
+
label: "Huỷ DDA quá số lần",
|
|
59
|
+
},
|
|
60
|
+
INACTIVE: {
|
|
61
|
+
id: EmployeeStatus.INACTIVE,
|
|
62
|
+
label: "Nghỉ việc",
|
|
63
|
+
},
|
|
64
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
|
|
2
|
+
export declare const DEBT_COLLECTION_TYPE: {
|
|
3
|
+
readonly PARTNER_IN_CHARGE: "PARTNER_IN_CHARGE";
|
|
4
|
+
readonly DIRECT_FROM_CUSTOMER_ACCOUNT: "DIRECT_FROM_CUSTOMER_ACCOUNT";
|
|
5
|
+
};
|
|
6
|
+
export declare const EMPLOYEE_STATUS_MAPS_2: Record<string, any>;
|
|
7
|
+
export declare function elgibilityToolV2(phoneNumber: string): Promise<CallToolResult>;
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EMPLOYEE_STATUS_MAPS_2 = exports.DEBT_COLLECTION_TYPE = void 0;
|
|
13
|
+
exports.elgibilityToolV2 = elgibilityToolV2;
|
|
14
|
+
const gimo_service_1 = require("../services/gimo.service");
|
|
15
|
+
const customer_ewa_1 = require("./constants/customer-ewa");
|
|
16
|
+
const employee_1 = require("./constants/employee");
|
|
17
|
+
const dda_1 = require("./constants/dda");
|
|
18
|
+
const FIELD_LABELS = {
|
|
19
|
+
ewa_status: "Trạng thái EWA",
|
|
20
|
+
dda: "Trạng thái DDA",
|
|
21
|
+
seniority: "Thâm niên làm việc",
|
|
22
|
+
working_status: "Trạng thái làm việc",
|
|
23
|
+
longest_overdue_bill: "Bill quá hạn lâu nhất",
|
|
24
|
+
outstanding_balance: "Số dư nợ",
|
|
25
|
+
parnter_contract_expirity: "Hạn hợp đồng đối tác",
|
|
26
|
+
time_sheet: "Công ca",
|
|
27
|
+
product_type: "Loại sản phẩm",
|
|
28
|
+
opreation_note: "Ghi chú vận hành",
|
|
29
|
+
employee_status: "Trạng thái nhân sự",
|
|
30
|
+
available_balance: "Số dư khả dụng",
|
|
31
|
+
wage: "Mức lương",
|
|
32
|
+
};
|
|
33
|
+
const PRODUCT_TYPE = {
|
|
34
|
+
EWA_01: "EWA_01",
|
|
35
|
+
EWA_02: "EWA_02",
|
|
36
|
+
EWA_03: "EWA_03",
|
|
37
|
+
EWA_04: "EWA_04",
|
|
38
|
+
};
|
|
39
|
+
const PARTNER_ONBOARD_METHOD = {
|
|
40
|
+
/// truyen thong
|
|
41
|
+
TRADITIONAL: "TRADITIONAL",
|
|
42
|
+
/// cong doan
|
|
43
|
+
UNION: "UNION",
|
|
44
|
+
/// chung minh thu nhap
|
|
45
|
+
EARNING_PROVE: "EARNING_PROVE",
|
|
46
|
+
};
|
|
47
|
+
exports.DEBT_COLLECTION_TYPE = {
|
|
48
|
+
PARTNER_IN_CHARGE: "PARTNER_IN_CHARGE",
|
|
49
|
+
DIRECT_FROM_CUSTOMER_ACCOUNT: "DIRECT_FROM_CUSTOMER_ACCOUNT",
|
|
50
|
+
};
|
|
51
|
+
function getProductType(options) {
|
|
52
|
+
const { partner_onboard_method, debt_collection_type } = options;
|
|
53
|
+
if (debt_collection_type === exports.DEBT_COLLECTION_TYPE.PARTNER_IN_CHARGE) {
|
|
54
|
+
return PRODUCT_TYPE.EWA_01;
|
|
55
|
+
}
|
|
56
|
+
if (debt_collection_type === exports.DEBT_COLLECTION_TYPE.DIRECT_FROM_CUSTOMER_ACCOUNT) {
|
|
57
|
+
if (partner_onboard_method === PARTNER_ONBOARD_METHOD.EARNING_PROVE) {
|
|
58
|
+
return PRODUCT_TYPE.EWA_03;
|
|
59
|
+
}
|
|
60
|
+
if (partner_onboard_method === PARTNER_ONBOARD_METHOD.UNION) {
|
|
61
|
+
return PRODUCT_TYPE.EWA_02;
|
|
62
|
+
}
|
|
63
|
+
// if (partner_onboard_method === PARTNER_ONBOARD_METHOD.TRADITIONAL) {
|
|
64
|
+
// return PRODUCT_TYPE.EWA_02;
|
|
65
|
+
// }
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
exports.EMPLOYEE_STATUS_MAPS_2 = {
|
|
70
|
+
ACTIVE: "Đang làm việc",
|
|
71
|
+
SUSPEND__WAITING_TO_APPROVE: "Chờ công đoàn phê duyệt",
|
|
72
|
+
SUSPEND__MATERNITY_LEAVE: "Nhân sự nghỉ thai sản",
|
|
73
|
+
SUSPEND__UNPAID_LEAVE: "Nhân sự nghỉ không lương",
|
|
74
|
+
SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT: "Chờ cập nhật chứng minh thu nhập",
|
|
75
|
+
SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT: "Chờ phê duyệt chứng minh thu nhập",
|
|
76
|
+
SUSPEND__DEFAULT: "Tạm nghỉ",
|
|
77
|
+
INACTIVE: "Nghỉ việc",
|
|
78
|
+
};
|
|
79
|
+
const CUSTOMER_EWA_STATUS = {
|
|
80
|
+
ACTIVE: "Hoạt động",
|
|
81
|
+
DEACTIVATE: "Tạm ngưng",
|
|
82
|
+
};
|
|
83
|
+
const BASE_REQUIRED_CRITERIA = {
|
|
84
|
+
ewa_status: CUSTOMER_EWA_STATUS.ACTIVE,
|
|
85
|
+
seniority: ">= 0.3 year",
|
|
86
|
+
working_status: exports.EMPLOYEE_STATUS_MAPS_2.ACTIVE,
|
|
87
|
+
longest_overdue_bill: "<=10 days",
|
|
88
|
+
outstanding_balance: "0",
|
|
89
|
+
parnter_contract_expirity: "Not yet expired",
|
|
90
|
+
time_sheet: "The data exists",
|
|
91
|
+
available_balance: ">0",
|
|
92
|
+
wage: ">0",
|
|
93
|
+
};
|
|
94
|
+
const EWA_02_CRITERIA = Object.assign(Object.assign({}, BASE_REQUIRED_CRITERIA), { dda: "REGISTERED" });
|
|
95
|
+
const EWA_03_CRITERIA = Object.assign(Object.assign({}, BASE_REQUIRED_CRITERIA), { dda: "REGISTERED" });
|
|
96
|
+
const formatter = (record) => {
|
|
97
|
+
return Object.keys(record)
|
|
98
|
+
.map((key) => `${key}: ${record[key]}`)
|
|
99
|
+
.join(",");
|
|
100
|
+
};
|
|
101
|
+
function elgibilityToolV2(phoneNumber) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
104
|
+
try {
|
|
105
|
+
const accessToken = yield (0, gimo_service_1.getAccessToken)();
|
|
106
|
+
const customer = yield (0, gimo_service_1.findCustomerEWAByPhonenumber)(phoneNumber, { accessToken });
|
|
107
|
+
if (!customer) {
|
|
108
|
+
throw "Customer not found";
|
|
109
|
+
}
|
|
110
|
+
const { employee, partner } = yield (0, gimo_service_1.getEmployeeByCustomerId)(customer.customer_id, { accessToken });
|
|
111
|
+
let periods = [];
|
|
112
|
+
let timeSheets = [];
|
|
113
|
+
let ewaDeactiveReason = "";
|
|
114
|
+
let currentPayperiodInfo = null;
|
|
115
|
+
if (employee) {
|
|
116
|
+
const payPeriods = yield (0, gimo_service_1.getPayPeriods)({ orgId: employee === null || employee === void 0 ? void 0 : employee.organization_id, parnterId: employee.partner_id }, { accessToken });
|
|
117
|
+
if (payPeriods === null || payPeriods === void 0 ? void 0 : payPeriods.length) {
|
|
118
|
+
periods = payPeriods;
|
|
119
|
+
timeSheets = yield (0, gimo_service_1.getTimeSheets)({ payPeriodId: payPeriods[0].id, employeeId: employee.id }, { accessToken });
|
|
120
|
+
currentPayperiodInfo = yield (0, gimo_service_1.getCurrentPayperiodInfo)(employee.id, { accessToken });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (customer.ewa_status === "DEACTIVATE") {
|
|
124
|
+
ewaDeactiveReason =
|
|
125
|
+
((_b = (_a = (yield (0, gimo_service_1.getCustomerStatusChange)(customer.customer_id, { accessToken }))) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.log_description) || "";
|
|
126
|
+
}
|
|
127
|
+
const { debt_collection, onboard_method } = partner || {};
|
|
128
|
+
const productType = getProductType({
|
|
129
|
+
debt_collection_type: debt_collection || "",
|
|
130
|
+
partner_onboard_method: onboard_method || "",
|
|
131
|
+
});
|
|
132
|
+
const currentInformation = {
|
|
133
|
+
ewa_status: (_d = CUSTOMER_EWA_STATUS[(_c = customer === null || customer === void 0 ? void 0 : customer.ewa_status) !== null && _c !== void 0 ? _c : ""]) !== null && _d !== void 0 ? _d : "",
|
|
134
|
+
dda: customer === null || customer === void 0 ? void 0 : customer.dda_status,
|
|
135
|
+
seniority: employee === null || employee === void 0 ? void 0 : employee.seniority,
|
|
136
|
+
working_status: exports.EMPLOYEE_STATUS_MAPS_2[(employee === null || employee === void 0 ? void 0 : employee.status) || "ACTIVE"],
|
|
137
|
+
product_type: productType,
|
|
138
|
+
time_sheet: (timeSheets === null || timeSheets === void 0 ? void 0 : timeSheets.length) ? "The data exists" : "The data does't exists",
|
|
139
|
+
longest_overdue_bill: customer.ewa_longest_over_due_day,
|
|
140
|
+
opreation_note: employee === null || employee === void 0 ? void 0 : employee.reason,
|
|
141
|
+
available_balance: currentPayperiodInfo === null || currentPayperiodInfo === void 0 ? void 0 : currentPayperiodInfo.accessible_amount,
|
|
142
|
+
wage: (employee === null || employee === void 0 ? void 0 : employee.wage) || 0,
|
|
143
|
+
};
|
|
144
|
+
const getRequriedCriteria = (productType) => {
|
|
145
|
+
if (productType === PRODUCT_TYPE.EWA_01) {
|
|
146
|
+
return BASE_REQUIRED_CRITERIA;
|
|
147
|
+
}
|
|
148
|
+
if (productType === PRODUCT_TYPE.EWA_02) {
|
|
149
|
+
return EWA_02_CRITERIA;
|
|
150
|
+
}
|
|
151
|
+
if (productType === PRODUCT_TYPE.EWA_03) {
|
|
152
|
+
return EWA_03_CRITERIA;
|
|
153
|
+
}
|
|
154
|
+
return BASE_REQUIRED_CRITERIA;
|
|
155
|
+
};
|
|
156
|
+
const requiredCriteria = getRequriedCriteria(productType);
|
|
157
|
+
const compare = (a, b) => {
|
|
158
|
+
return a.toLowerCase().trim() === b.toLowerCase().trim();
|
|
159
|
+
};
|
|
160
|
+
const formatter2 = (criteria) => {
|
|
161
|
+
var _a;
|
|
162
|
+
let mess = "";
|
|
163
|
+
const name = (_a = FIELD_LABELS[criteria.key]) !== null && _a !== void 0 ? _a : criteria.key;
|
|
164
|
+
mess = `tiêu chí ${name} có giá trị: ${criteria.currentLabel}, yêu cầu: ${criteria.requiredLabel}, trạng thái kiểm tra: ${criteria.pass ? "thoà mãn" : "không thoả mãn"}`;
|
|
165
|
+
if (criteria.reason) {
|
|
166
|
+
mess = mess + `lý do: ${criteria.reason}`;
|
|
167
|
+
}
|
|
168
|
+
return mess;
|
|
169
|
+
};
|
|
170
|
+
const compareResult = [
|
|
171
|
+
{
|
|
172
|
+
key: "ewa_status",
|
|
173
|
+
current: customer.ewa_status,
|
|
174
|
+
currentLabel: (_f = (_e = customer_ewa_1.CUSTOMER_EWA_STATUS_MAPS[customer.ewa_status]) === null || _e === void 0 ? void 0 : _e.label) !== null && _f !== void 0 ? _f : "",
|
|
175
|
+
required: "active",
|
|
176
|
+
requiredLabel: customer_ewa_1.CUSTOMER_EWA_STATUS_MAPS.ACTIVE.LABEL,
|
|
177
|
+
pass: compare(customer.ewa_status, customer_ewa_1.CustomerEwaStatus.ACTIVE),
|
|
178
|
+
reason: ewaDeactiveReason,
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
key: "seniority",
|
|
182
|
+
current: employee === null || employee === void 0 ? void 0 : employee.seniority,
|
|
183
|
+
currentLabel: `${employee === null || employee === void 0 ? void 0 : employee.seniority} năm`,
|
|
184
|
+
required: "active",
|
|
185
|
+
requiredLabel: `>= 0.3 năm`,
|
|
186
|
+
pass: !!(employee === null || employee === void 0 ? void 0 : employee.seniority) && employee.seniority >= 0.3,
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
key: "seniority",
|
|
190
|
+
current: employee === null || employee === void 0 ? void 0 : employee.seniority,
|
|
191
|
+
currentLabel: `${employee === null || employee === void 0 ? void 0 : employee.seniority} năm`,
|
|
192
|
+
required: ">= 0.3",
|
|
193
|
+
requiredLabel: `>= 0.3 năm`,
|
|
194
|
+
pass: !!(employee === null || employee === void 0 ? void 0 : employee.seniority) && employee.seniority >= 0.3,
|
|
195
|
+
reason: ewaDeactiveReason,
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
key: "employee_status",
|
|
199
|
+
current: employee === null || employee === void 0 ? void 0 : employee.status,
|
|
200
|
+
currentLabel: ((_g = employee_1.EMPLOYEE_STATUS_MAPS[(employee === null || employee === void 0 ? void 0 : employee.status) || ""]) === null || _g === void 0 ? void 0 : _g.label) || "",
|
|
201
|
+
required: employee_1.EmployeeStatus.ACTIVE,
|
|
202
|
+
requiredLabel: employee_1.EMPLOYEE_STATUS_MAPS.ACTIVE.label,
|
|
203
|
+
pass: ((_h = employee === null || employee === void 0 ? void 0 : employee.status) === null || _h === void 0 ? void 0 : _h.toLowerCase()) === employee_1.EmployeeStatus.ACTIVE,
|
|
204
|
+
reason: employee === null || employee === void 0 ? void 0 : employee.reason,
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
key: "time_sheet",
|
|
208
|
+
current: timeSheets.length > 0 ? "exists" : "not_exists_yet",
|
|
209
|
+
currentLabel: timeSheets.length > 0 ? "tồn tại" : "chưa tồn tại",
|
|
210
|
+
required: "exists",
|
|
211
|
+
requiredLabel: "tồn tại",
|
|
212
|
+
pass: timeSheets.length > 0,
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
key: "longest_overdue_bill",
|
|
216
|
+
current: customer.ewa_longest_over_due_day,
|
|
217
|
+
currentLabel: `${customer.ewa_longest_over_due_day} ngày`,
|
|
218
|
+
required: "< 11",
|
|
219
|
+
requiredLabel: "< 11 ngày",
|
|
220
|
+
pass: (customer.ewa_longest_over_due_day || 0) < 11,
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
key: "available_balance",
|
|
224
|
+
current: currentPayperiodInfo === null || currentPayperiodInfo === void 0 ? void 0 : currentPayperiodInfo.accessible_amount,
|
|
225
|
+
currentLabel: `${currentPayperiodInfo === null || currentPayperiodInfo === void 0 ? void 0 : currentPayperiodInfo.accessible_amount} VNĐ`,
|
|
226
|
+
required: "> 0",
|
|
227
|
+
requiredLabel: "> 0 VNĐ",
|
|
228
|
+
pass: !!(currentPayperiodInfo === null || currentPayperiodInfo === void 0 ? void 0 : currentPayperiodInfo.accessible_amount) && currentPayperiodInfo.accessible_amount > 0,
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
key: "wage",
|
|
232
|
+
current: employee === null || employee === void 0 ? void 0 : employee.wage,
|
|
233
|
+
currentLabel: `${employee === null || employee === void 0 ? void 0 : employee.wage} VNĐ`,
|
|
234
|
+
required: "> 0",
|
|
235
|
+
requiredLabel: "> 0 VNĐ",
|
|
236
|
+
pass: !!(employee === null || employee === void 0 ? void 0 : employee.wage) && employee.wage > 0,
|
|
237
|
+
},
|
|
238
|
+
/// @TODO update late
|
|
239
|
+
// {
|
|
240
|
+
// key: "outstanding_balance",
|
|
241
|
+
// current: ,
|
|
242
|
+
// currentLabel: `${employee?.wage} VNĐ`,
|
|
243
|
+
// required: "> 0",
|
|
244
|
+
// requiredLabel: "> 0 VNĐ",
|
|
245
|
+
// pass: !!employee?.wage && employee.wage > 0,
|
|
246
|
+
// },
|
|
247
|
+
];
|
|
248
|
+
if (productType === "EWA_02" || productType === "EWA_03") {
|
|
249
|
+
compareResult.push({
|
|
250
|
+
key: "dda",
|
|
251
|
+
current: customer === null || customer === void 0 ? void 0 : customer.dda_status,
|
|
252
|
+
currentLabel: ((_k = dda_1.DDA_STATUS_MAPS[(_j = customer === null || customer === void 0 ? void 0 : customer.dda_status) !== null && _j !== void 0 ? _j : ""]) === null || _k === void 0 ? void 0 : _k.label) || "",
|
|
253
|
+
required: dda_1.DdaStatus.REGISTERED,
|
|
254
|
+
requiredLabel: dda_1.DDA_STATUS_MAPS["REGISTERED"].label,
|
|
255
|
+
pass: (customer === null || customer === void 0 ? void 0 : customer.dda_status) === dda_1.DdaStatus.REGISTERED,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
const reasons = [];
|
|
259
|
+
if (ewaDeactiveReason) {
|
|
260
|
+
reasons.push(`Reason for ewa status: ${ewaDeactiveReason}`);
|
|
261
|
+
}
|
|
262
|
+
const criteriaText = compareResult.map(formatter2).join("\n");
|
|
263
|
+
const result = `
|
|
264
|
+
Customer ${customer.customer_full_name}, partner name ${customer.partner_name}, product type: ${productType} has criteria: ${criteriaText}
|
|
265
|
+
`;
|
|
266
|
+
return { content: [{ type: "text", text: result }] };
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
return {
|
|
270
|
+
content: [
|
|
271
|
+
{
|
|
272
|
+
type: "text",
|
|
273
|
+
text: "Oh no,có rồi, thử lại nhé " + JSON.stringify(error),
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import z from "zod";
|
|
|
14
14
|
import { ensureEnvVariables, getEnv } from "./env";
|
|
15
15
|
import { debtCollectionRateTool } from "./tools/lark-tool";
|
|
16
16
|
import { elgibilityTool } from "./tools/eligibility-tools";
|
|
17
|
+
import { elgibilityToolV2 } from "./tools/eligibility-tools_v2";
|
|
17
18
|
|
|
18
19
|
export const server = new McpServer(
|
|
19
20
|
{
|
|
@@ -115,7 +116,7 @@ server.tool(
|
|
|
115
116
|
},
|
|
116
117
|
async (args) => {
|
|
117
118
|
const { phone_number } = args;
|
|
118
|
-
return
|
|
119
|
+
return elgibilityToolV2(phone_number);
|
|
119
120
|
}
|
|
120
121
|
);
|
|
121
122
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const CustomerEwaStatus = {
|
|
2
|
+
DEACTIVATE: "DEACTIVATE",
|
|
3
|
+
ACTIVE: "ACTIVE",
|
|
4
|
+
} as const;
|
|
5
|
+
|
|
6
|
+
export const CUSTOMER_EWA_STATUS_MAPS: Record<string, any> = {
|
|
7
|
+
DEACTIVATE: {
|
|
8
|
+
id: CustomerEwaStatus.DEACTIVATE,
|
|
9
|
+
label: "Tạm ngưng",
|
|
10
|
+
},
|
|
11
|
+
ACTIVE: {
|
|
12
|
+
id: CustomerEwaStatus.ACTIVE,
|
|
13
|
+
label: "Hoạt động",
|
|
14
|
+
},
|
|
15
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const DdaStatus = {
|
|
2
|
+
UNREGISTERED: "UNREGISTERED",
|
|
3
|
+
REGISTERED: "REGISTERED",
|
|
4
|
+
CANCEL: "CANCEL",
|
|
5
|
+
WAITING_BANK_APPROVE: "WAITING_BANK_APPROVE",
|
|
6
|
+
REJECTED: "REJECTED",
|
|
7
|
+
} as const;
|
|
8
|
+
|
|
9
|
+
export const DDA_STATUS_MAPS: Record<string, any> = {
|
|
10
|
+
UNREGISTERED: {
|
|
11
|
+
id: DdaStatus.UNREGISTERED,
|
|
12
|
+
label: "Chưa đăng ký",
|
|
13
|
+
},
|
|
14
|
+
REGISTERED: {
|
|
15
|
+
id: DdaStatus.REGISTERED,
|
|
16
|
+
label: "Đã đăng ký",
|
|
17
|
+
},
|
|
18
|
+
CANCEL: {
|
|
19
|
+
id: DdaStatus.CANCEL,
|
|
20
|
+
label: "Đã huỷ",
|
|
21
|
+
},
|
|
22
|
+
WAITING_BANK_APPROVE: {
|
|
23
|
+
id: DdaStatus.WAITING_BANK_APPROVE,
|
|
24
|
+
label: "Chờ bank xác nhận",
|
|
25
|
+
},
|
|
26
|
+
REJECTED: {
|
|
27
|
+
id: DdaStatus.REJECTED,
|
|
28
|
+
label: "Bị tử chối",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export enum EmployeeStatus {
|
|
2
|
+
ACTIVE = "ACTIVE",
|
|
3
|
+
SUSPEND__WAITING_TO_APPROVE = "SUSPEND__WAITING_TO_APPROVE",
|
|
4
|
+
SUSPEND__MATERNITY_LEAVE = "SUSPEND__MATERNITY_LEAVE",
|
|
5
|
+
SUSPEND__UNPAID_LEAVE = "SUSPEND__UNPAID_LEAVE",
|
|
6
|
+
SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT = "SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT",
|
|
7
|
+
SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT = "SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT",
|
|
8
|
+
SUSPEND__WAITING_FOR_DEBT_PAYMENT = "SUSPEND__WAITING_FOR_DEBT_PAYMENT",
|
|
9
|
+
SUSPEND__DEFAULT = "SUSPEND__DEFAULT",
|
|
10
|
+
SUSPEND__DDA_REACH_LIMIT = "SUSPEND__DDA_REACH_LIMIT",
|
|
11
|
+
INACTIVE = "INACTIVE",
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const EMPLOYEE_STATUS_MAPS: Record<string, any> = {
|
|
15
|
+
ACTIVE: {
|
|
16
|
+
id: EmployeeStatus.ACTIVE,
|
|
17
|
+
label: "Đang làm việc",
|
|
18
|
+
},
|
|
19
|
+
SUSPEND__WAITING_TO_APPROVE: {
|
|
20
|
+
id: EmployeeStatus.SUSPEND__WAITING_TO_APPROVE,
|
|
21
|
+
label: "Chờ công đoàn phê duyệt",
|
|
22
|
+
},
|
|
23
|
+
SUSPEND__MATERNITY_LEAVE: {
|
|
24
|
+
id: EmployeeStatus.SUSPEND__MATERNITY_LEAVE,
|
|
25
|
+
label: "Nhân sự nghỉ thai sản",
|
|
26
|
+
},
|
|
27
|
+
SUSPEND__UNPAID_LEAVE: {
|
|
28
|
+
id: EmployeeStatus.SUSPEND__UNPAID_LEAVE,
|
|
29
|
+
label: "Nhân sự nghỉ không lương",
|
|
30
|
+
},
|
|
31
|
+
SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT: {
|
|
32
|
+
id: EmployeeStatus.SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT,
|
|
33
|
+
label: "Chờ cập nhật chứng minh thu nhập",
|
|
34
|
+
},
|
|
35
|
+
SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT: {
|
|
36
|
+
id: EmployeeStatus.SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT,
|
|
37
|
+
label: "Chờ phê duyệt chứng minh thu nhập",
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated
|
|
41
|
+
*/
|
|
42
|
+
SUSPEND__WAITING_FOR_DEBT_PAYMENT: {
|
|
43
|
+
id: EmployeeStatus.SUSPEND__WAITING_FOR_DEBT_PAYMENT,
|
|
44
|
+
label: "Chờ thanh toán công nợ",
|
|
45
|
+
},
|
|
46
|
+
SUSPEND__DEFAULT: {
|
|
47
|
+
id: EmployeeStatus.SUSPEND__DEFAULT,
|
|
48
|
+
label: "Tạm nghỉ",
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated
|
|
52
|
+
*/
|
|
53
|
+
SUSPEND__DDA_REACH_LIMIT: {
|
|
54
|
+
id: EmployeeStatus.SUSPEND__DDA_REACH_LIMIT,
|
|
55
|
+
label: "Huỷ DDA quá số lần",
|
|
56
|
+
},
|
|
57
|
+
INACTIVE: {
|
|
58
|
+
id: EmployeeStatus.INACTIVE,
|
|
59
|
+
label: "Nghỉ việc",
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
|
|
2
|
+
import {
|
|
3
|
+
findCustomerEWAByPhonenumber,
|
|
4
|
+
getAccessToken,
|
|
5
|
+
getCurrentPayperiodInfo,
|
|
6
|
+
getCustomerStatusChange,
|
|
7
|
+
getEmployeeByCustomerId,
|
|
8
|
+
getPayPeriods,
|
|
9
|
+
getTimeSheets,
|
|
10
|
+
} from "../services/gimo.service";
|
|
11
|
+
import { PayPeriod, PayperiodInfo } from "../services/types/pay-period";
|
|
12
|
+
import { TimeSheet } from "../services/types/time-keeper";
|
|
13
|
+
import { CUSTOMER_EWA_STATUS_MAPS, CustomerEwaStatus } from "./constants/customer-ewa";
|
|
14
|
+
import { EMPLOYEE_STATUS_MAPS, EmployeeStatus } from "./constants/employee";
|
|
15
|
+
import { DDA_STATUS_MAPS, DdaStatus } from "./constants/dda";
|
|
16
|
+
|
|
17
|
+
const FIELD_LABELS: Record<string, string> = {
|
|
18
|
+
ewa_status: "Trạng thái EWA",
|
|
19
|
+
dda: "Trạng thái DDA",
|
|
20
|
+
seniority: "Thâm niên làm việc",
|
|
21
|
+
working_status: "Trạng thái làm việc",
|
|
22
|
+
longest_overdue_bill: "Bill quá hạn lâu nhất",
|
|
23
|
+
outstanding_balance: "Số dư nợ",
|
|
24
|
+
parnter_contract_expirity: "Hạn hợp đồng đối tác",
|
|
25
|
+
time_sheet: "Công ca",
|
|
26
|
+
product_type: "Loại sản phẩm",
|
|
27
|
+
opreation_note: "Ghi chú vận hành",
|
|
28
|
+
employee_status: "Trạng thái nhân sự",
|
|
29
|
+
available_balance: "Số dư khả dụng",
|
|
30
|
+
wage: "Mức lương",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const PRODUCT_TYPE = {
|
|
34
|
+
EWA_01: "EWA_01",
|
|
35
|
+
EWA_02: "EWA_02",
|
|
36
|
+
EWA_03: "EWA_03",
|
|
37
|
+
EWA_04: "EWA_04",
|
|
38
|
+
} as const;
|
|
39
|
+
|
|
40
|
+
const PARTNER_ONBOARD_METHOD = {
|
|
41
|
+
/// truyen thong
|
|
42
|
+
TRADITIONAL: "TRADITIONAL",
|
|
43
|
+
/// cong doan
|
|
44
|
+
UNION: "UNION",
|
|
45
|
+
/// chung minh thu nhap
|
|
46
|
+
EARNING_PROVE: "EARNING_PROVE",
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
export const DEBT_COLLECTION_TYPE = {
|
|
50
|
+
PARTNER_IN_CHARGE: "PARTNER_IN_CHARGE",
|
|
51
|
+
DIRECT_FROM_CUSTOMER_ACCOUNT: "DIRECT_FROM_CUSTOMER_ACCOUNT",
|
|
52
|
+
} as const;
|
|
53
|
+
|
|
54
|
+
function getProductType(options: { partner_onboard_method: string; debt_collection_type: string }) {
|
|
55
|
+
const { partner_onboard_method, debt_collection_type } = options;
|
|
56
|
+
if (debt_collection_type === DEBT_COLLECTION_TYPE.PARTNER_IN_CHARGE) {
|
|
57
|
+
return PRODUCT_TYPE.EWA_01;
|
|
58
|
+
}
|
|
59
|
+
if (debt_collection_type === DEBT_COLLECTION_TYPE.DIRECT_FROM_CUSTOMER_ACCOUNT) {
|
|
60
|
+
if (partner_onboard_method === PARTNER_ONBOARD_METHOD.EARNING_PROVE) {
|
|
61
|
+
return PRODUCT_TYPE.EWA_03;
|
|
62
|
+
}
|
|
63
|
+
if (partner_onboard_method === PARTNER_ONBOARD_METHOD.UNION) {
|
|
64
|
+
return PRODUCT_TYPE.EWA_02;
|
|
65
|
+
}
|
|
66
|
+
// if (partner_onboard_method === PARTNER_ONBOARD_METHOD.TRADITIONAL) {
|
|
67
|
+
// return PRODUCT_TYPE.EWA_02;
|
|
68
|
+
// }
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const EMPLOYEE_STATUS_MAPS_2: Record<string, any> = {
|
|
74
|
+
ACTIVE: "Đang làm việc",
|
|
75
|
+
SUSPEND__WAITING_TO_APPROVE: "Chờ công đoàn phê duyệt",
|
|
76
|
+
SUSPEND__MATERNITY_LEAVE: "Nhân sự nghỉ thai sản",
|
|
77
|
+
SUSPEND__UNPAID_LEAVE: "Nhân sự nghỉ không lương",
|
|
78
|
+
SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT: "Chờ cập nhật chứng minh thu nhập",
|
|
79
|
+
SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT: "Chờ phê duyệt chứng minh thu nhập",
|
|
80
|
+
SUSPEND__DEFAULT: "Tạm nghỉ",
|
|
81
|
+
INACTIVE: "Nghỉ việc",
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const CUSTOMER_EWA_STATUS: Record<string, any> = {
|
|
85
|
+
ACTIVE: "Hoạt động",
|
|
86
|
+
DEACTIVATE: "Tạm ngưng",
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const BASE_REQUIRED_CRITERIA = {
|
|
90
|
+
ewa_status: CUSTOMER_EWA_STATUS.ACTIVE,
|
|
91
|
+
seniority: ">= 0.3 year",
|
|
92
|
+
working_status: EMPLOYEE_STATUS_MAPS_2.ACTIVE,
|
|
93
|
+
longest_overdue_bill: "<=10 days",
|
|
94
|
+
outstanding_balance: "0",
|
|
95
|
+
parnter_contract_expirity: "Not yet expired",
|
|
96
|
+
time_sheet: "The data exists",
|
|
97
|
+
available_balance: ">0",
|
|
98
|
+
wage: ">0",
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const EWA_02_CRITERIA = {
|
|
102
|
+
...BASE_REQUIRED_CRITERIA,
|
|
103
|
+
dda: "REGISTERED",
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const EWA_03_CRITERIA = {
|
|
107
|
+
...BASE_REQUIRED_CRITERIA,
|
|
108
|
+
dda: "REGISTERED",
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
interface CompareResult {
|
|
112
|
+
key: string;
|
|
113
|
+
current: any;
|
|
114
|
+
currentLabel: string;
|
|
115
|
+
required: any;
|
|
116
|
+
requiredLabel: string;
|
|
117
|
+
pass: boolean;
|
|
118
|
+
reason?: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const formatter = (record: Record<string, any>) => {
|
|
122
|
+
return Object.keys(record)
|
|
123
|
+
.map((key) => `${key}: ${record[key]}`)
|
|
124
|
+
.join(",");
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export async function elgibilityToolV2(phoneNumber: string): Promise<CallToolResult> {
|
|
128
|
+
try {
|
|
129
|
+
const accessToken = await getAccessToken();
|
|
130
|
+
const customer = await findCustomerEWAByPhonenumber(phoneNumber, { accessToken });
|
|
131
|
+
if (!customer) {
|
|
132
|
+
throw "Customer not found";
|
|
133
|
+
}
|
|
134
|
+
const { employee, partner } = await getEmployeeByCustomerId(customer.customer_id, { accessToken });
|
|
135
|
+
let periods: PayPeriod[] = [];
|
|
136
|
+
let timeSheets: TimeSheet[] = [];
|
|
137
|
+
let ewaDeactiveReason = "";
|
|
138
|
+
let currentPayperiodInfo: PayperiodInfo | null = null;
|
|
139
|
+
if (employee) {
|
|
140
|
+
const payPeriods = await getPayPeriods(
|
|
141
|
+
{ orgId: employee?.organization_id, parnterId: employee.partner_id },
|
|
142
|
+
{ accessToken },
|
|
143
|
+
);
|
|
144
|
+
if (payPeriods?.length) {
|
|
145
|
+
periods = payPeriods;
|
|
146
|
+
timeSheets = await getTimeSheets({ payPeriodId: payPeriods[0].id, employeeId: employee.id }, { accessToken });
|
|
147
|
+
currentPayperiodInfo = await getCurrentPayperiodInfo(employee.id, { accessToken });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (customer.ewa_status === "DEACTIVATE") {
|
|
151
|
+
ewaDeactiveReason =
|
|
152
|
+
(await getCustomerStatusChange(customer.customer_id, { accessToken }))?.[0]?.log_description || "";
|
|
153
|
+
}
|
|
154
|
+
const { debt_collection, onboard_method } = partner || {};
|
|
155
|
+
|
|
156
|
+
const productType = getProductType({
|
|
157
|
+
debt_collection_type: debt_collection || "",
|
|
158
|
+
partner_onboard_method: onboard_method || "",
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const currentInformation = {
|
|
162
|
+
ewa_status: CUSTOMER_EWA_STATUS[customer?.ewa_status ?? ""] ?? "",
|
|
163
|
+
dda: customer?.dda_status,
|
|
164
|
+
seniority: employee?.seniority,
|
|
165
|
+
working_status: EMPLOYEE_STATUS_MAPS_2[employee?.status || "ACTIVE"],
|
|
166
|
+
product_type: productType,
|
|
167
|
+
time_sheet: timeSheets?.length ? "The data exists" : "The data does't exists",
|
|
168
|
+
longest_overdue_bill: customer.ewa_longest_over_due_day,
|
|
169
|
+
opreation_note: employee?.reason,
|
|
170
|
+
available_balance: currentPayperiodInfo?.accessible_amount,
|
|
171
|
+
wage: employee?.wage || 0,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const getRequriedCriteria = (productType: keyof typeof PRODUCT_TYPE | null) => {
|
|
175
|
+
if (productType === PRODUCT_TYPE.EWA_01) {
|
|
176
|
+
return BASE_REQUIRED_CRITERIA;
|
|
177
|
+
}
|
|
178
|
+
if (productType === PRODUCT_TYPE.EWA_02) {
|
|
179
|
+
return EWA_02_CRITERIA;
|
|
180
|
+
}
|
|
181
|
+
if (productType === PRODUCT_TYPE.EWA_03) {
|
|
182
|
+
return EWA_03_CRITERIA;
|
|
183
|
+
}
|
|
184
|
+
return BASE_REQUIRED_CRITERIA;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const requiredCriteria: Record<string, any> = getRequriedCriteria(productType);
|
|
188
|
+
|
|
189
|
+
const compare = (a: string, b: string) => {
|
|
190
|
+
return a.toLowerCase().trim() === b.toLowerCase().trim();
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const formatter2 = (criteria: CompareResult) => {
|
|
194
|
+
let mess = "";
|
|
195
|
+
const name = FIELD_LABELS[criteria.key] ?? criteria.key;
|
|
196
|
+
mess = `tiêu chí ${name} có giá trị: ${criteria.currentLabel}, yêu cầu: ${criteria.requiredLabel}, trạng thái kiểm tra: ${criteria.pass ? "thoà mãn" : "không thoả mãn"}`;
|
|
197
|
+
if (criteria.reason) {
|
|
198
|
+
mess = mess + `lý do: ${criteria.reason}`;
|
|
199
|
+
}
|
|
200
|
+
return mess;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const compareResult: CompareResult[] = [
|
|
204
|
+
{
|
|
205
|
+
key: "ewa_status",
|
|
206
|
+
current: customer.ewa_status,
|
|
207
|
+
currentLabel: CUSTOMER_EWA_STATUS_MAPS[customer.ewa_status]?.label ?? "",
|
|
208
|
+
required: "active",
|
|
209
|
+
requiredLabel: CUSTOMER_EWA_STATUS_MAPS.ACTIVE.LABEL,
|
|
210
|
+
pass: compare(customer.ewa_status, CustomerEwaStatus.ACTIVE),
|
|
211
|
+
reason: ewaDeactiveReason,
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
key: "seniority",
|
|
215
|
+
current: employee?.seniority,
|
|
216
|
+
currentLabel: `${employee?.seniority} năm`,
|
|
217
|
+
required: "active",
|
|
218
|
+
requiredLabel: `>= 0.3 năm`,
|
|
219
|
+
pass: !!employee?.seniority && employee.seniority >= 0.3,
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
key: "seniority",
|
|
223
|
+
current: employee?.seniority,
|
|
224
|
+
currentLabel: `${employee?.seniority} năm`,
|
|
225
|
+
required: ">= 0.3",
|
|
226
|
+
requiredLabel: `>= 0.3 năm`,
|
|
227
|
+
pass: !!employee?.seniority && employee.seniority >= 0.3,
|
|
228
|
+
reason: ewaDeactiveReason,
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
key: "employee_status",
|
|
232
|
+
current: employee?.status,
|
|
233
|
+
currentLabel: EMPLOYEE_STATUS_MAPS[employee?.status || ""]?.label || "",
|
|
234
|
+
required: EmployeeStatus.ACTIVE,
|
|
235
|
+
requiredLabel: EMPLOYEE_STATUS_MAPS.ACTIVE.label,
|
|
236
|
+
pass: employee?.status?.toLowerCase() === EmployeeStatus.ACTIVE,
|
|
237
|
+
reason: employee?.reason,
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
key: "time_sheet",
|
|
241
|
+
current: timeSheets.length > 0 ? "exists" : "not_exists_yet",
|
|
242
|
+
currentLabel: timeSheets.length > 0 ? "tồn tại" : "chưa tồn tại",
|
|
243
|
+
required: "exists",
|
|
244
|
+
requiredLabel: "tồn tại",
|
|
245
|
+
pass: timeSheets.length > 0,
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
key: "longest_overdue_bill",
|
|
249
|
+
current: customer.ewa_longest_over_due_day,
|
|
250
|
+
currentLabel: `${customer.ewa_longest_over_due_day} ngày`,
|
|
251
|
+
required: "< 11",
|
|
252
|
+
requiredLabel: "< 11 ngày",
|
|
253
|
+
pass: (customer.ewa_longest_over_due_day || 0) < 11,
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
key: "available_balance",
|
|
257
|
+
current: currentPayperiodInfo?.accessible_amount,
|
|
258
|
+
currentLabel: `${currentPayperiodInfo?.accessible_amount} VNĐ`,
|
|
259
|
+
required: "> 0",
|
|
260
|
+
requiredLabel: "> 0 VNĐ",
|
|
261
|
+
pass: !!currentPayperiodInfo?.accessible_amount && currentPayperiodInfo.accessible_amount > 0,
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
key: "wage",
|
|
265
|
+
current: employee?.wage,
|
|
266
|
+
currentLabel: `${employee?.wage} VNĐ`,
|
|
267
|
+
required: "> 0",
|
|
268
|
+
requiredLabel: "> 0 VNĐ",
|
|
269
|
+
pass: !!employee?.wage && employee.wage > 0,
|
|
270
|
+
},
|
|
271
|
+
/// @TODO update late
|
|
272
|
+
// {
|
|
273
|
+
// key: "outstanding_balance",
|
|
274
|
+
// current: ,
|
|
275
|
+
// currentLabel: `${employee?.wage} VNĐ`,
|
|
276
|
+
// required: "> 0",
|
|
277
|
+
// requiredLabel: "> 0 VNĐ",
|
|
278
|
+
// pass: !!employee?.wage && employee.wage > 0,
|
|
279
|
+
// },
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
if (productType === "EWA_02" || productType === "EWA_03") {
|
|
283
|
+
compareResult.push({
|
|
284
|
+
key: "dda",
|
|
285
|
+
current: customer?.dda_status,
|
|
286
|
+
currentLabel: DDA_STATUS_MAPS[customer?.dda_status ?? ""]?.label || "",
|
|
287
|
+
required: DdaStatus.REGISTERED,
|
|
288
|
+
requiredLabel: DDA_STATUS_MAPS["REGISTERED"].label,
|
|
289
|
+
pass: customer?.dda_status === DdaStatus.REGISTERED,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const reasons: string[] = [];
|
|
294
|
+
if (ewaDeactiveReason) {
|
|
295
|
+
reasons.push(`Reason for ewa status: ${ewaDeactiveReason}`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const criteriaText = compareResult.map(formatter2).join("\n");
|
|
299
|
+
|
|
300
|
+
const result = `
|
|
301
|
+
Customer ${customer.customer_full_name}, partner name ${customer.partner_name}, product type: ${productType} has criteria: ${criteriaText}
|
|
302
|
+
`;
|
|
303
|
+
|
|
304
|
+
return { content: [{ type: "text", text: result }] };
|
|
305
|
+
} catch (error) {
|
|
306
|
+
return {
|
|
307
|
+
content: [
|
|
308
|
+
{
|
|
309
|
+
type: "text",
|
|
310
|
+
text: "Oh no,có rồi, thử lại nhé " + JSON.stringify(error),
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|