gm-mcp 2.0.7 → 2.0.8

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.
@@ -1,6 +1,7 @@
1
1
  import { Gimo } from "./types";
2
- import { PayPeriod } from "./types/pay-period";
2
+ import { PayPeriod, PayperiodInfo } from "./types/pay-period";
3
3
  import { TimeSheet } from "./types/time-keeper";
4
+ import { CustomerEwaStatusChangeLogs } from "./types/status-change";
4
5
  export declare function getAccessToken(): Promise<string>;
5
6
  export declare function findCustomerEWAByPhonenumber(phoneNumber: string, options?: {
6
7
  accessToken?: string;
@@ -21,3 +22,9 @@ export declare function getEmployeeByCustomerId(customerId: number, options?: {
21
22
  accessToken?: string;
22
23
  }): Promise<Gimo.EmployeeInfo>;
23
24
  export declare function findCustomerEWAById(id: number): Promise<Gimo.CustomerEWA>;
25
+ export declare function getCustomerStatusChange(ewaCustomerId: number, options?: {
26
+ accessToken?: string;
27
+ }): Promise<CustomerEwaStatusChangeLogs[]>;
28
+ export declare function getCurrentPayperiodInfo(payPeriodId: number, options?: {
29
+ accessToken?: string;
30
+ }): Promise<PayperiodInfo>;
@@ -18,6 +18,8 @@ exports.getPayPeriods = getPayPeriods;
18
18
  exports.getTimeSheets = getTimeSheets;
19
19
  exports.getEmployeeByCustomerId = getEmployeeByCustomerId;
20
20
  exports.findCustomerEWAById = findCustomerEWAById;
21
+ exports.getCustomerStatusChange = getCustomerStatusChange;
22
+ exports.getCurrentPayperiodInfo = getCurrentPayperiodInfo;
21
23
  const axios_1 = __importDefault(require("axios"));
22
24
  const env_1 = require("../env");
23
25
  function getAccessToken() {
@@ -142,3 +144,41 @@ function findCustomerEWAById(id) {
142
144
  return customer || null;
143
145
  });
144
146
  }
147
+ function getCustomerStatusChange(ewaCustomerId, options) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ const { accessToken } = options || {};
150
+ let access_token = accessToken;
151
+ if (!access_token) {
152
+ access_token = yield getAccessToken();
153
+ }
154
+ const url = `${(0, env_1.getEnv)().DASH_URL}/api/v1/admin/customers/ewa/${ewaCustomerId}/status/changes`;
155
+ const res = yield axios_1.default
156
+ .get(url, {
157
+ headers: {
158
+ Authorization: "Bearer " + access_token,
159
+ },
160
+ })
161
+ .then((res) => res.data);
162
+ // Select first customer
163
+ return res;
164
+ });
165
+ }
166
+ function getCurrentPayperiodInfo(payPeriodId, options) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ const { accessToken } = options || {};
169
+ let access_token = accessToken;
170
+ if (!access_token) {
171
+ access_token = yield getAccessToken();
172
+ }
173
+ const url = `${(0, env_1.getEnv)().DASH_URL}/api/v1/admin/employees/${payPeriodId}/current-pay-period-info`;
174
+ const res = yield axios_1.default
175
+ .get(url, {
176
+ headers: {
177
+ Authorization: "Bearer " + access_token,
178
+ },
179
+ })
180
+ .then((res) => res.data);
181
+ // Select first customer
182
+ return res;
183
+ });
184
+ }
@@ -39,3 +39,14 @@ export interface Config {
39
39
  version_number: number;
40
40
  previous_config_id: any;
41
41
  }
42
+ export interface PayperiodInfo {
43
+ month: number;
44
+ year: number;
45
+ worked_days: number;
46
+ standard_work_days: number;
47
+ work_days: number;
48
+ earned_amount: number;
49
+ advanced_amount: number;
50
+ accessible_amount: number;
51
+ has_income_from_attendance: boolean;
52
+ }
@@ -0,0 +1,10 @@
1
+ export interface CustomerEwaStatusChangeLogs {
2
+ log_created_at: string;
3
+ log_description?: string;
4
+ log_ewa_status?: "DEACTIVATE" | "ACTIVE";
5
+ log_id: string;
6
+ log_type?: string;
7
+ log_user_id?: string;
8
+ log_username?: string;
9
+ [key: string]: any;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -12,6 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EMPLOYEE_STATUS_MAPS = exports.DEBT_COLLECTION_TYPE = void 0;
13
13
  exports.elgibilityTool = elgibilityTool;
14
14
  const gimo_service_1 = require("../services/gimo.service");
15
+ const FIELD_LABELS = {
16
+ ewa_status: "Trạng thái EWA",
17
+ dda: "Trạng thái DDA",
18
+ seniority: "Thâm niên làm việc",
19
+ working_status: "Trạng thái làm việc",
20
+ longest_overdue_bill: "Số ngày quá hạn thanh toán dài nhất",
21
+ outstanding_balance: "Số dư nợ",
22
+ parnter_contract_expirity: "Hạn hợp đồng đối tác",
23
+ time_sheet: "Dữ liệu chấm công",
24
+ product_type: "Loại sản phẩm",
25
+ opreation_note: "Ghi chú vận hành",
26
+ };
15
27
  const PRODUCT_TYPE = {
16
28
  EWA_01: "EWA_01",
17
29
  EWA_02: "EWA_02",
@@ -58,6 +70,10 @@ exports.EMPLOYEE_STATUS_MAPS = {
58
70
  SUSPEND__DEFAULT: "Tạm nghỉ",
59
71
  INACTIVE: "Nghỉ việc",
60
72
  };
73
+ const CUSTOMER_EWA_STATUSP_MAPS = {
74
+ ACTIVE: "Hoạt động",
75
+ DEACTIVATE: "Tạm ngưng",
76
+ };
61
77
  const BASE_REQUIRED_CRITERIA = {
62
78
  ewa_status: "ACTIVE",
63
79
  seniority: ">= 0.3 year",
@@ -66,6 +82,7 @@ const BASE_REQUIRED_CRITERIA = {
66
82
  outstanding_balance: "0",
67
83
  parnter_contract_expirity: "Not yet expired",
68
84
  time_sheet: "The data exists",
85
+ available_balance: ">0",
69
86
  };
70
87
  const EWA_02_CRITERIA = Object.assign(Object.assign({}, BASE_REQUIRED_CRITERIA), { dda: "REGISTERED" });
71
88
  const EWA_03_CRITERIA = Object.assign(Object.assign({}, BASE_REQUIRED_CRITERIA), { dda: "REGISTERED" });
@@ -76,6 +93,7 @@ const formatter = (record) => {
76
93
  };
77
94
  function elgibilityTool(phoneNumber) {
78
95
  return __awaiter(this, void 0, void 0, function* () {
96
+ var _a, _b;
79
97
  try {
80
98
  const accessToken = yield (0, gimo_service_1.getAccessToken)();
81
99
  const customer = yield (0, gimo_service_1.findCustomerEWAByPhonenumber)(phoneNumber, { accessToken });
@@ -85,13 +103,20 @@ function elgibilityTool(phoneNumber) {
85
103
  const { employee, partner } = yield (0, gimo_service_1.getEmployeeByCustomerId)(customer.customer_id, { accessToken });
86
104
  let periods = [];
87
105
  let timeSheets = [];
106
+ let ewaDeactiveReason = "";
107
+ let currentPayperiodInfo = null;
88
108
  if (employee) {
89
109
  const payPeriods = yield (0, gimo_service_1.getPayPeriods)({ orgId: employee === null || employee === void 0 ? void 0 : employee.organization_id, parnterId: employee.partner_id }, { accessToken });
90
110
  if (payPeriods === null || payPeriods === void 0 ? void 0 : payPeriods.length) {
91
111
  periods = payPeriods;
92
112
  timeSheets = yield (0, gimo_service_1.getTimeSheets)({ payPeriodId: payPeriods[0].id, employeeId: employee.id }, { accessToken });
113
+ currentPayperiodInfo = yield (0, gimo_service_1.getCurrentPayperiodInfo)(payPeriods[0].id, { accessToken });
93
114
  }
94
115
  }
116
+ if (customer.ewa_status === "DEACTIVATE") {
117
+ ewaDeactiveReason =
118
+ ((_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) || "";
119
+ }
95
120
  const { debt_collection, onboard_method } = partner || {};
96
121
  const productType = getProductType({
97
122
  debt_collection_type: debt_collection || "",
@@ -106,6 +131,7 @@ function elgibilityTool(phoneNumber) {
106
131
  time_sheet: (timeSheets === null || timeSheets === void 0 ? void 0 : timeSheets.length) ? "The data exists" : "The data does't exists",
107
132
  longest_overdue_bill: customer.ewa_longest_over_due_day,
108
133
  opreation_note: employee === null || employee === void 0 ? void 0 : employee.reason,
134
+ available_balance: currentPayperiodInfo === null || currentPayperiodInfo === void 0 ? void 0 : currentPayperiodInfo.accessible_amount,
109
135
  };
110
136
  const getRequriedCriteria = (productType) => {
111
137
  if (productType === PRODUCT_TYPE.EWA_01) {
@@ -120,9 +146,11 @@ function elgibilityTool(phoneNumber) {
120
146
  return BASE_REQUIRED_CRITERIA;
121
147
  };
122
148
  const requiredCriteria = getRequriedCriteria(productType);
149
+ const reasons = [ewaDeactiveReason];
123
150
  const result = `
124
- Customer ${customer.customer_full_name}, partner name ${customer.partner_name} has these informations: ${formatter(currentInformation)}
125
- Eligibility Criteria for Salary Advances: ${formatter(requiredCriteria)}
151
+ Customer ${customer.customer_full_name}, partner name ${customer.partner_name} has these information: ${formatter(currentInformation)}
152
+ Eligibility Criteria for Salary Advance: ${formatter(requiredCriteria)}
153
+ Reasons: ${reasons.filter(Boolean).join("")}
126
154
  `;
127
155
  return { content: [{ type: "text", text: result }] };
128
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-mcp",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "description": "Mcp server for Gm",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,8 +1,9 @@
1
1
  import axios from "axios";
2
2
  import { Gimo } from "./types";
3
3
  import { getEnv } from "../env";
4
- import { PayPeriod } from "./types/pay-period";
4
+ import { PayPeriod, PayperiodInfo } from "./types/pay-period";
5
5
  import { TimeSheet } from "./types/time-keeper";
6
+ import { CustomerEwaStatusChangeLogs } from "./types/status-change";
6
7
 
7
8
  export async function getAccessToken() {
8
9
  const url = `${getEnv().DASH_URL}/api/v1/auth/admin/login`;
@@ -123,3 +124,39 @@ export async function findCustomerEWAById(id: number) {
123
124
  // Select first customer
124
125
  return customer || null;
125
126
  }
127
+
128
+ export async function getCustomerStatusChange(ewaCustomerId: number, options?: { accessToken?: string }) {
129
+ const { accessToken } = options || {};
130
+ let access_token = accessToken;
131
+ if (!access_token) {
132
+ access_token = await getAccessToken();
133
+ }
134
+ const url = `${getEnv().DASH_URL}/api/v1/admin/customers/ewa/${ewaCustomerId}/status/changes`;
135
+ const res = await axios
136
+ .get<CustomerEwaStatusChangeLogs[]>(url, {
137
+ headers: {
138
+ Authorization: "Bearer " + access_token,
139
+ },
140
+ })
141
+ .then((res) => res.data);
142
+ // Select first customer
143
+ return res;
144
+ }
145
+
146
+ export async function getCurrentPayperiodInfo(payPeriodId: number, options?: { accessToken?: string }) {
147
+ const { accessToken } = options || {};
148
+ let access_token = accessToken;
149
+ if (!access_token) {
150
+ access_token = await getAccessToken();
151
+ }
152
+ const url = `${getEnv().DASH_URL}/api/v1/admin/employees/${payPeriodId}/current-pay-period-info`;
153
+ const res = await axios
154
+ .get<PayperiodInfo>(url, {
155
+ headers: {
156
+ Authorization: "Bearer " + access_token,
157
+ },
158
+ })
159
+ .then((res) => res.data);
160
+ // Select first customer
161
+ return res;
162
+ }
@@ -40,3 +40,15 @@ export interface Config {
40
40
  version_number: number;
41
41
  previous_config_id: any;
42
42
  }
43
+
44
+ export interface PayperiodInfo {
45
+ month: number;
46
+ year: number;
47
+ worked_days: number;
48
+ standard_work_days: number;
49
+ work_days: number;
50
+ earned_amount: number;
51
+ advanced_amount: number;
52
+ accessible_amount: number;
53
+ has_income_from_attendance: boolean;
54
+ }
@@ -0,0 +1,11 @@
1
+ export interface CustomerEwaStatusChangeLogs {
2
+ log_created_at: string;
3
+ log_description?: string;
4
+ log_ewa_status?: "DEACTIVATE" | "ACTIVE";
5
+ log_id: string;
6
+ log_type?: string;
7
+ log_user_id?: string;
8
+ log_username?: string;
9
+
10
+ [key: string]: any;
11
+ }
@@ -2,13 +2,28 @@ import { CallToolResult } from "@modelcontextprotocol/sdk/types";
2
2
  import {
3
3
  findCustomerEWAByPhonenumber,
4
4
  getAccessToken,
5
+ getCurrentPayperiodInfo,
6
+ getCustomerStatusChange,
5
7
  getEmployeeByCustomerId,
6
8
  getPayPeriods,
7
9
  getTimeSheets,
8
10
  } from "../services/gimo.service";
9
- import { PayPeriod } from "../services/types/pay-period";
11
+ import { PayPeriod, PayperiodInfo } from "../services/types/pay-period";
10
12
  import { TimeSheet } from "../services/types/time-keeper";
11
13
 
14
+ const FIELD_LABELS: Record<string, string> = {
15
+ ewa_status: "Trạng thái EWA",
16
+ dda: "Trạng thái DDA",
17
+ seniority: "Thâm niên làm việc",
18
+ working_status: "Trạng thái làm việc",
19
+ longest_overdue_bill: "Số ngày quá hạn thanh toán dài nhất",
20
+ outstanding_balance: "Số dư nợ",
21
+ parnter_contract_expirity: "Hạn hợp đồng đối tác",
22
+ time_sheet: "Dữ liệu chấm công",
23
+ product_type: "Loại sản phẩm",
24
+ opreation_note: "Ghi chú vận hành",
25
+ };
26
+
12
27
  const PRODUCT_TYPE = {
13
28
  EWA_01: "EWA_01",
14
29
  EWA_02: "EWA_02",
@@ -60,6 +75,11 @@ export const EMPLOYEE_STATUS_MAPS: Record<string, any> = {
60
75
  INACTIVE: "Nghỉ việc",
61
76
  };
62
77
 
78
+ const CUSTOMER_EWA_STATUSP_MAPS = {
79
+ ACTIVE: "Hoạt động",
80
+ DEACTIVATE: "Tạm ngưng",
81
+ };
82
+
63
83
  const BASE_REQUIRED_CRITERIA = {
64
84
  ewa_status: "ACTIVE",
65
85
  seniority: ">= 0.3 year",
@@ -68,6 +88,7 @@ const BASE_REQUIRED_CRITERIA = {
68
88
  outstanding_balance: "0",
69
89
  parnter_contract_expirity: "Not yet expired",
70
90
  time_sheet: "The data exists",
91
+ available_balance: ">0",
71
92
  };
72
93
 
73
94
  const EWA_02_CRITERIA = {
@@ -96,6 +117,8 @@ export async function elgibilityTool(phoneNumber: string): Promise<CallToolResul
96
117
  const { employee, partner } = await getEmployeeByCustomerId(customer.customer_id, { accessToken });
97
118
  let periods: PayPeriod[] = [];
98
119
  let timeSheets: TimeSheet[] = [];
120
+ let ewaDeactiveReason = "";
121
+ let currentPayperiodInfo: PayperiodInfo | null = null;
99
122
  if (employee) {
100
123
  const payPeriods = await getPayPeriods(
101
124
  { orgId: employee?.organization_id, parnterId: employee.partner_id },
@@ -104,8 +127,13 @@ export async function elgibilityTool(phoneNumber: string): Promise<CallToolResul
104
127
  if (payPeriods?.length) {
105
128
  periods = payPeriods;
106
129
  timeSheets = await getTimeSheets({ payPeriodId: payPeriods[0].id, employeeId: employee.id }, { accessToken });
130
+ currentPayperiodInfo = await getCurrentPayperiodInfo(payPeriods[0].id, { accessToken });
107
131
  }
108
132
  }
133
+ if (customer.ewa_status === "DEACTIVATE") {
134
+ ewaDeactiveReason =
135
+ (await getCustomerStatusChange(customer.customer_id, { accessToken }))?.[0]?.log_description || "";
136
+ }
109
137
  const { debt_collection, onboard_method } = partner || {};
110
138
 
111
139
  const productType = getProductType({
@@ -122,6 +150,7 @@ export async function elgibilityTool(phoneNumber: string): Promise<CallToolResul
122
150
  time_sheet: timeSheets?.length ? "The data exists" : "The data does't exists",
123
151
  longest_overdue_bill: customer.ewa_longest_over_due_day,
124
152
  opreation_note: employee?.reason,
153
+ available_balance: currentPayperiodInfo?.accessible_amount,
125
154
  };
126
155
 
127
156
  const getRequriedCriteria = (productType: keyof typeof PRODUCT_TYPE | null) => {
@@ -139,9 +168,12 @@ export async function elgibilityTool(phoneNumber: string): Promise<CallToolResul
139
168
 
140
169
  const requiredCriteria: Record<string, any> = getRequriedCriteria(productType);
141
170
 
171
+ const reasons = [ewaDeactiveReason];
172
+
142
173
  const result = `
143
- Customer ${customer.customer_full_name}, partner name ${customer.partner_name} has these informations: ${formatter(currentInformation)}
144
- Eligibility Criteria for Salary Advances: ${formatter(requiredCriteria)}
174
+ Customer ${customer.customer_full_name}, partner name ${customer.partner_name} has these information: ${formatter(currentInformation)}
175
+ Eligibility Criteria for Salary Advance: ${formatter(requiredCriteria)}
176
+ Reasons: ${reasons.filter(Boolean).join("")}
145
177
  `;
146
178
 
147
179
  return { content: [{ type: "text", text: result }] };