@etsoo/smarterp-core 1.1.59 → 1.1.61

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 (62) hide show
  1. package/__tests__/OrgApi.ts +48 -7
  2. package/__tests__/tsconfig.json +1 -1
  3. package/lib/cjs/CoreApp.d.ts +43 -0
  4. package/lib/cjs/CoreApp.js +34 -0
  5. package/lib/cjs/OrgApi.d.ts +9 -0
  6. package/lib/cjs/OrgApi.js +9 -0
  7. package/lib/cjs/PublicApi.d.ts +9 -0
  8. package/lib/cjs/PublicApi.js +10 -1
  9. package/lib/cjs/components/index.d.ts +1 -0
  10. package/lib/cjs/components/index.js +1 -0
  11. package/lib/cjs/components/public/TimeZoneList.d.ts +33 -0
  12. package/lib/cjs/components/public/TimeZoneList.js +27 -0
  13. package/lib/cjs/dto/org/OrgReportData.d.ts +38 -0
  14. package/lib/cjs/dto/org/OrgReportData.js +2 -0
  15. package/lib/cjs/dto/public/TimeZoneItem.d.ts +22 -0
  16. package/lib/cjs/dto/public/TimeZoneItem.js +2 -0
  17. package/lib/cjs/i18n/en.json +5 -1
  18. package/lib/cjs/i18n/zh-Hans.json +5 -1
  19. package/lib/cjs/i18n/zh-Hant.json +5 -1
  20. package/lib/cjs/index.d.ts +4 -0
  21. package/lib/cjs/index.js +4 -0
  22. package/lib/cjs/rq/org/OrgUsageReportRQ.d.ts +21 -0
  23. package/lib/cjs/rq/org/OrgUsageReportRQ.js +2 -0
  24. package/lib/cjs/rq/public/TimeZoneRQ.d.ts +14 -0
  25. package/lib/cjs/rq/public/TimeZoneRQ.js +2 -0
  26. package/lib/mjs/CoreApp.d.ts +43 -0
  27. package/lib/mjs/CoreApp.js +36 -2
  28. package/lib/mjs/OrgApi.d.ts +9 -0
  29. package/lib/mjs/OrgApi.js +9 -0
  30. package/lib/mjs/PublicApi.d.ts +9 -0
  31. package/lib/mjs/PublicApi.js +10 -1
  32. package/lib/mjs/components/index.d.ts +1 -0
  33. package/lib/mjs/components/index.js +1 -0
  34. package/lib/mjs/components/public/TimeZoneList.d.ts +33 -0
  35. package/lib/mjs/components/public/TimeZoneList.js +24 -0
  36. package/lib/mjs/dto/org/OrgReportData.d.ts +38 -0
  37. package/lib/mjs/dto/org/OrgReportData.js +1 -0
  38. package/lib/mjs/dto/public/TimeZoneItem.d.ts +22 -0
  39. package/lib/mjs/dto/public/TimeZoneItem.js +1 -0
  40. package/lib/mjs/i18n/en.json +5 -1
  41. package/lib/mjs/i18n/zh-Hans.json +5 -1
  42. package/lib/mjs/i18n/zh-Hant.json +5 -1
  43. package/lib/mjs/index.d.ts +4 -0
  44. package/lib/mjs/index.js +4 -0
  45. package/lib/mjs/rq/org/OrgUsageReportRQ.d.ts +21 -0
  46. package/lib/mjs/rq/org/OrgUsageReportRQ.js +1 -0
  47. package/lib/mjs/rq/public/TimeZoneRQ.d.ts +14 -0
  48. package/lib/mjs/rq/public/TimeZoneRQ.js +1 -0
  49. package/package.json +8 -8
  50. package/src/CoreApp.ts +78 -1
  51. package/src/OrgApi.ts +12 -0
  52. package/src/PublicApi.ts +15 -3
  53. package/src/components/index.ts +1 -0
  54. package/src/components/public/TimeZoneList.tsx +82 -0
  55. package/src/dto/org/OrgReportData.ts +41 -0
  56. package/src/dto/public/TimeZoneItem.ts +25 -0
  57. package/src/i18n/en.json +5 -1
  58. package/src/i18n/zh-Hans.json +5 -1
  59. package/src/i18n/zh-Hant.json +5 -1
  60. package/src/index.ts +4 -0
  61. package/src/rq/org/OrgUsageReportRQ.ts +23 -0
  62. package/src/rq/public/TimeZoneRQ.ts +16 -0
@@ -3,9 +3,9 @@ import { OrgApi } from "./OrgApi";
3
3
  import { AppApi } from "./AppApi";
4
4
  import { PublicApi } from "./PublicApi";
5
5
  import { UserApi } from "./UserApi";
6
- import { AuthApi, IdentityType, IdentityTypeFlags, UserIdentifierType } from "@etsoo/appscript";
6
+ import { AuthApi, BusinessUtils, IdentityType, IdentityTypeFlags, UserIdentifierType } from "@etsoo/appscript";
7
7
  import { AuthCodeApi } from "./AuthCodeApi";
8
- import { DataTypes } from "@etsoo/shared";
8
+ import { DataTypes, NumberUtils } from "@etsoo/shared";
9
9
  import { CoreApiService } from "./dto/org/CoreApiService";
10
10
  import { DocumentApi } from "./DocumentApi";
11
11
  import { DocumentKind } from "./dto/document/DocumentKind";
@@ -217,4 +217,38 @@ export class CoreApp {
217
217
  return id;
218
218
  });
219
219
  }
220
+ /**
221
+ * Get report data
222
+ * 获取报告数据
223
+ * @param data Input data
224
+ * @param year Year to calculate
225
+ * @returns Result
226
+ */
227
+ getReportData(data, year) {
228
+ const [start, end] = NumberUtils.getMonthPeriodRange(year);
229
+ const items = [];
230
+ for (let i = start; i <= end; i++) {
231
+ const item = data.find((d) => d.period === i);
232
+ items.push(item ? ("qty" in item ? item.qty : item.amount) : 0);
233
+ }
234
+ return items;
235
+ }
236
+ /**
237
+ * Transform report data for chart
238
+ * 转换报告数据用于图表
239
+ * @param data Input data
240
+ * @param hasLastYear Has last year data
241
+ * @param year Year to calculate, default is current year
242
+ * @returns Transformed report data
243
+ */
244
+ transformReportData(data, hasLastYear, year) {
245
+ year ??= new Date().getFullYear();
246
+ const months = BusinessUtils.getMonths(this.app.get("months") ?? []);
247
+ const labels = months.map((m) => m.label);
248
+ const currentYearData = this.getReportData(data, year);
249
+ const lastYearData = hasLastYear == null || hasLastYear
250
+ ? this.getReportData(data, year - 1)
251
+ : [];
252
+ return { labels, currentYearData, lastYearData };
253
+ }
220
254
  }
@@ -26,6 +26,8 @@ import { OrgQueryApiData } from "./dto/org/OrgQueryApiData";
26
26
  import { CoreApiService } from "./dto/org/CoreApiService";
27
27
  import { UploadFilesResult } from "./dto/org/UploadFilesResult";
28
28
  import { OrgOwnsRQ } from "./rq/org/OrgOwnsRQ";
29
+ import { OrgUsageReportRQ } from "./rq/org/OrgUsageReportRQ";
30
+ import { OrgReportData } from "./dto/org/OrgReportData";
29
31
  /**
30
32
  * Organization API
31
33
  * 机构接口
@@ -247,4 +249,11 @@ export declare class OrgApi extends EntityApi {
247
249
  * @returns Result
248
250
  */
249
251
  updateResourceRead(id: number, payload?: IApiPayload<OrgUpdateResourceReadData>): Promise<OrgUpdateResourceReadData | undefined>;
252
+ /**
253
+ * Get usage report
254
+ * @param rq Request data
255
+ * @param payload Payload
256
+ * @returns Result
257
+ */
258
+ usageReport(rq: OrgUsageReportRQ, payload?: IApiPayload<OrgReportData[]>): Promise<OrgReportData[] | undefined>;
250
259
  }
package/lib/mjs/OrgApi.js CHANGED
@@ -302,4 +302,13 @@ export class OrgApi extends EntityApi {
302
302
  updateResourceRead(id, payload) {
303
303
  return this.api.get(`${this.flag}/UpdateResourceRead/${id}`, undefined, payload);
304
304
  }
305
+ /**
306
+ * Get usage report
307
+ * @param rq Request data
308
+ * @param payload Payload
309
+ * @returns Result
310
+ */
311
+ usageReport(rq, payload) {
312
+ return this.api.post(`${this.flag}/UsageReport`, rq, payload);
313
+ }
305
314
  }
@@ -12,6 +12,8 @@ import { AcceptInvitationRQ } from "./rq/public/AcceptInvitationRQ";
12
12
  import { ChinaPinData } from "./dto/public/ChinaPinData";
13
13
  import { ParseNameRQ } from "./rq/public/ParseNameRQ";
14
14
  import { NameData } from "./dto/public/NameData";
15
+ import { TimeZoneItem } from "./dto/public/TimeZoneItem";
16
+ import { TimeZoneRQ } from "./rq/public/TimeZoneRQ";
15
17
  /**
16
18
  * Public API
17
19
  * 公共接口
@@ -78,6 +80,13 @@ export declare class PublicApi extends BaseApi {
78
80
  * @returns Result
79
81
  */
80
82
  getRegions(ids?: string[], payload?: IApiPayload<RegionData[]>): Promise<RegionData[] | undefined>;
83
+ /**
84
+ * Get time zones
85
+ * @param rq Request data
86
+ * @param payload Payload
87
+ * @returns Result
88
+ */
89
+ getTimeZones(rq?: TimeZoneRQ, payload?: IApiPayload<TimeZoneItem[]>): Promise<TimeZoneItem[] | undefined>;
81
90
  /**
82
91
  * Get product unit's label
83
92
  * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
@@ -95,6 +95,15 @@ export class PublicApi extends BaseApi {
95
95
  contentType: "application/json"
96
96
  });
97
97
  }
98
+ /**
99
+ * Get time zones
100
+ * @param rq Request data
101
+ * @param payload Payload
102
+ * @returns Result
103
+ */
104
+ getTimeZones(rq, payload) {
105
+ return this.api.post("Public/GetTimeZones", rq, payload);
106
+ }
98
107
  /**
99
108
  * Get product unit's label
100
109
  * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
@@ -113,7 +122,7 @@ export class PublicApi extends BaseApi {
113
122
  }
114
123
  getUnitJoin(isJoined) {
115
124
  return typeof isJoined === "string"
116
- ? this.app.get(isJoined) ?? isJoined
125
+ ? (this.app.get(isJoined) ?? isJoined)
117
126
  : isJoined
118
127
  ? this.app.get("unitJoin")
119
128
  : undefined;
@@ -18,4 +18,5 @@ export * from "./public/ButtonRadioRegions";
18
18
  export * from "./public/ButtonRegions";
19
19
  export * from "./public/CultureList";
20
20
  export * from "./public/ProductBaseUnits";
21
+ export * from "./public/TimeZoneList";
21
22
  export * from "./user/UserTiplist";
@@ -23,5 +23,6 @@ export * from "./public/ButtonRadioRegions";
23
23
  export * from "./public/ButtonRegions";
24
24
  export * from "./public/CultureList";
25
25
  export * from "./public/ProductBaseUnits";
26
+ export * from "./public/TimeZoneList";
26
27
  // user
27
28
  export * from "./user/UserTiplist";
@@ -0,0 +1,33 @@
1
+ import { TiplistProps } from "@etsoo/materialui";
2
+ import { TimeZoneItem } from "../../dto/public/TimeZoneItem";
3
+ import { TimeZoneRQ } from "../../rq/public/TimeZoneRQ";
4
+ /**
5
+ * Time zone tiplist properties
6
+ * 时区提示列表属性
7
+ */
8
+ export type TimeZoneTiplistProps = Omit<TiplistProps<TimeZoneItem, "id">, "loadData" | "label" | "name"> & {
9
+ /**
10
+ * Label
11
+ */
12
+ label?: string;
13
+ /**
14
+ * Name
15
+ */
16
+ name?: string;
17
+ /**
18
+ * Default request data
19
+ */
20
+ rq?: Partial<TimeZoneRQ>;
21
+ /**
22
+ * Load data handler
23
+ * @param rq Request data
24
+ */
25
+ onLoadData?: (rq: TimeZoneRQ) => TimeZoneRQ;
26
+ };
27
+ /**
28
+ * Time zone tiplist
29
+ * 时区提示列表
30
+ * @param props Properties
31
+ * @returns Component
32
+ */
33
+ export declare function TimeZoneTiplist(props: TimeZoneTiplistProps): import("react").JSX.Element;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Tiplist } from "@etsoo/materialui";
3
+ import { useRequiredAppContext } from "../../ICoreServiceApp";
4
+ /**
5
+ * Time zone tiplist
6
+ * 时区提示列表
7
+ * @param props Properties
8
+ * @returns Component
9
+ */
10
+ export function TimeZoneTiplist(props) {
11
+ // App
12
+ const app = useRequiredAppContext();
13
+ // Destruct
14
+ const { fullWidth = true, label = app.get("timeZone"), maxItems = 10, getOptionLabel = (data) => data.displayName, onLoadData = (rq) => rq, name = "timeZone", rq = { enabled: true }, ...rest } = props;
15
+ // Layout
16
+ return (_jsx(Tiplist, { label: label, getOptionLabel: getOptionLabel, name: name, fullWidth: fullWidth, maxItems: maxItems, loadData: (keyword, id, maxItems) => app.core.publicApi.getTimeZones(onLoadData({
17
+ ...rq,
18
+ keyword,
19
+ id,
20
+ queryPaging: {
21
+ batchSize: maxItems
22
+ }
23
+ }), { showLoading: false, defaultValue: [] }), ...rest }));
24
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Organization usage report data
3
+ * 机构使用报告数据
4
+ */
5
+ type OrgUsageReportData = {
6
+ /**
7
+ * Period
8
+ * 周期
9
+ */
10
+ period: number;
11
+ /**
12
+ * Qty.
13
+ * 数量
14
+ */
15
+ qty: number;
16
+ };
17
+ /**
18
+ * Organization amount report data
19
+ * 机构金额报告数据
20
+ */
21
+ type OrgAmountReportData = {
22
+ /**
23
+ * Period
24
+ * 周期
25
+ */
26
+ period: number;
27
+ /**
28
+ * Amount
29
+ * 金额
30
+ */
31
+ amount: number;
32
+ };
33
+ /**
34
+ * Organization report data
35
+ * 机构报告数据
36
+ */
37
+ export type OrgReportData = OrgUsageReportData | OrgAmountReportData;
38
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ export type TimeZoneItem = {
2
+ /**
3
+ * IANA Id
4
+ * IANA 编号
5
+ */
6
+ id: string;
7
+ /**
8
+ * Display name
9
+ * 显示名称
10
+ */
11
+ displayName: string;
12
+ /**
13
+ * Standard name
14
+ * 标准名称
15
+ */
16
+ standardName: string;
17
+ /**
18
+ * UTC offset
19
+ * UTC偏移
20
+ */
21
+ utcOffset: string;
22
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -106,6 +106,7 @@
106
106
  "roleOperator": "Operator",
107
107
  "rolePartner": "Channel Partner",
108
108
  "roleUser": "User",
109
+ "samePeriodLastYear": "Same period last year",
109
110
  "slogan": "Slogan",
110
111
  "smarterp": "SmartERP Cloud",
111
112
  "signin": "Sign in",
@@ -132,6 +133,7 @@
132
133
  "templateCMSPODATA": "CMS PO data",
133
134
  "templateCMSSTOCKDATA": "CMS stock data",
134
135
  "templateKind": "Template kind",
136
+ "timeZone": "Time zone",
135
137
  "years5": ["1 year", "2 years", "3 years", "4 years", "5 years"],
136
138
  "uiTypeEmail": "Email",
137
139
  "uiTypeMobile": "Mobile",
@@ -139,5 +141,7 @@
139
141
  "uiTypeAlipay": "Alipay",
140
142
  "uiTypeGoogle": "Google",
141
143
  "uiTypeMicrosoft": "Microsoft",
142
- "updatedAt": "Updated at"
144
+ "updatedAt": "Updated at",
145
+ "usage": "Usage",
146
+ "usageReport": "Usage report"
143
147
  }
@@ -106,6 +106,7 @@
106
106
  "roleOperator": "操作员",
107
107
  "rolePartner": "渠道伙伴",
108
108
  "roleUser": "用户",
109
+ "samePeriodLastYear": "去年同期",
109
110
  "slogan": "标语",
110
111
  "smarterp": "司友®云ERP",
111
112
  "signin": "登录",
@@ -132,6 +133,7 @@
132
133
  "templateCMSPODATA": "CMS采购数据",
133
134
  "templateCMSSTOCKDATA": "CMS库存数据",
134
135
  "templateKind": "模板类型",
136
+ "timeZone": "时区",
135
137
  "years5": ["1年", "2年", "3年", "4年", "5年"],
136
138
  "uiTypeEmail": "电子邮箱",
137
139
  "uiTypeMobile": "手机号",
@@ -139,5 +141,7 @@
139
141
  "uiTypeAlipay": "支付宝",
140
142
  "uiTypeGoogle": "谷歌",
141
143
  "uiTypeMicrosoft": "微软",
142
- "updatedAt": "更新时间"
144
+ "updatedAt": "更新时间",
145
+ "usage": "使用量",
146
+ "usageReport": "使用情况报告"
143
147
  }
@@ -106,6 +106,7 @@
106
106
  "roleOperator": "操作員",
107
107
  "rolePartner": "渠道夥伴",
108
108
  "roleUser": "用戶",
109
+ "samePeriodLastYear": "去年同期",
109
110
  "signin": "登入",
110
111
  "signout": "登出",
111
112
  "slogan": "標語",
@@ -132,6 +133,7 @@
132
133
  "templateCMSPODATA": "CMS採購數據",
133
134
  "templateCMSSTOCKDATA": "CMS庫存數據",
134
135
  "templateKind": "模板類型",
136
+ "timeZone": "時區",
135
137
  "years5": ["1年", "2年", "3年", "4年", "5年"],
136
138
  "uiTypeEmail": "電子郵件",
137
139
  "uiTypeMobile": "手機號碼",
@@ -139,5 +141,7 @@
139
141
  "uiTypeAlipay": "支付寶",
140
142
  "uiTypeGoogle": "谷歌",
141
143
  "uiTypeMicrosoft": "微軟",
142
- "updatedAt": "更新時間"
144
+ "updatedAt": "更新時間",
145
+ "usage": "使用量",
146
+ "usageReport": "使用情況報告"
143
147
  }
@@ -22,6 +22,7 @@ export * from "./dto/org/OrgQueryApiData";
22
22
  export * from "./dto/org/OrgQueryDto";
23
23
  export * from "./dto/org/OrgQueryResourceData";
24
24
  export * from "./dto/org/OrgReadDto";
25
+ export * from "./dto/org/OrgReportData";
25
26
  export * from "./dto/org/OrgResourceItem";
26
27
  export * from "./dto/org/OrgUpdateApiReadDto";
27
28
  export * from "./dto/org/OrgUpdateReadDto";
@@ -33,6 +34,7 @@ export * from "./dto/public/MemberInvitationDto";
33
34
  export * from "./dto/public/NameData";
34
35
  export * from "./dto/public/PlaceCommon";
35
36
  export * from "./dto/public/RegionData";
37
+ export * from "./dto/public/TimeZoneItem";
36
38
  export * from "./dto/user/AuditHistoryDto";
37
39
  export * from "./dto/user/DeviceListDto";
38
40
  export * from "./dto/user/UserIdentifierData";
@@ -68,6 +70,7 @@ export * from "./rq/org/OrgQueryApiRQ";
68
70
  export * from "./rq/org/OrgQueryResourceRQ";
69
71
  export * from "./rq/org/OrgQueryRQ";
70
72
  export * from "./rq/org/OrgUpdateApiRQ";
73
+ export * from "./rq/org/OrgUsageReportRQ";
71
74
  export * from "./rq/org/OrgUpdateRQ";
72
75
  export * from "./rq/org/SendEmailMessage";
73
76
  export * from "./rq/org/SendProfileEmailRQ";
@@ -77,6 +80,7 @@ export * from "./rq/public/CreateBarcodeRQ";
77
80
  export * from "./rq/public/ParseNameRQ";
78
81
  export * from "./rq/public/PinyinRQ";
79
82
  export * from "./rq/public/PlaceQueryRQ";
83
+ export * from "./rq/public/TimeZoneRQ";
80
84
  export * from "./rq/user/AuditHistoryRQ";
81
85
  export * from "./rq/user/UserUpdateRQ";
82
86
  export * from "./AppApi";
package/lib/mjs/index.js CHANGED
@@ -23,6 +23,7 @@ export * from "./dto/org/OrgQueryApiData";
23
23
  export * from "./dto/org/OrgQueryDto";
24
24
  export * from "./dto/org/OrgQueryResourceData";
25
25
  export * from "./dto/org/OrgReadDto";
26
+ export * from "./dto/org/OrgReportData";
26
27
  export * from "./dto/org/OrgResourceItem";
27
28
  export * from "./dto/org/OrgUpdateApiReadDto";
28
29
  export * from "./dto/org/OrgUpdateReadDto";
@@ -34,6 +35,7 @@ export * from "./dto/public/MemberInvitationDto";
34
35
  export * from "./dto/public/NameData";
35
36
  export * from "./dto/public/PlaceCommon";
36
37
  export * from "./dto/public/RegionData";
38
+ export * from "./dto/public/TimeZoneItem";
37
39
  export * from "./dto/user/AuditHistoryDto";
38
40
  export * from "./dto/user/DeviceListDto";
39
41
  export * from "./dto/user/UserIdentifierData";
@@ -71,6 +73,7 @@ export * from "./rq/org/OrgQueryApiRQ";
71
73
  export * from "./rq/org/OrgQueryResourceRQ";
72
74
  export * from "./rq/org/OrgQueryRQ";
73
75
  export * from "./rq/org/OrgUpdateApiRQ";
76
+ export * from "./rq/org/OrgUsageReportRQ";
74
77
  export * from "./rq/org/OrgUpdateRQ";
75
78
  export * from "./rq/org/SendEmailMessage";
76
79
  export * from "./rq/org/SendProfileEmailRQ";
@@ -80,6 +83,7 @@ export * from "./rq/public/CreateBarcodeRQ";
80
83
  export * from "./rq/public/ParseNameRQ";
81
84
  export * from "./rq/public/PinyinRQ";
82
85
  export * from "./rq/public/PlaceQueryRQ";
86
+ export * from "./rq/public/TimeZoneRQ";
83
87
  export * from "./rq/user/AuditHistoryRQ";
84
88
  export * from "./rq/user/UserUpdateRQ";
85
89
  // APIs
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Organization usage report request data
3
+ * 机构使用报告请求数据
4
+ */
5
+ export type OrgUsageReportRQ = {
6
+ /**
7
+ * Organization id
8
+ * 机构编号
9
+ */
10
+ orgId?: number;
11
+ /**
12
+ * Year
13
+ * 年
14
+ */
15
+ year?: number;
16
+ /**
17
+ * Whether to include last year data
18
+ * 是否包含去年数据
19
+ */
20
+ hasLastYear?: boolean;
21
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { QueryRQ } from "@etsoo/appscript";
2
+ export type TimeZoneRQ = QueryRQ<string> & {
3
+ /**
4
+ * Culture, like "en-US", "zh-CN", etc.
5
+ * If not specified, the current culture will be used.
6
+ * 文化
7
+ */
8
+ culture?: string;
9
+ /**
10
+ * All system timezones
11
+ * 所有系统时区
12
+ */
13
+ all?: boolean;
14
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/smarterp-core",
3
- "version": "1.1.59",
3
+ "version": "1.1.61",
4
4
  "description": "TypeScript APIs for SmartERP Core",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -40,16 +40,16 @@
40
40
  "license": "MIT",
41
41
  "homepage": "https://github.com/ETSOO/smarterp-core#readme",
42
42
  "devDependencies": {
43
- "@babel/core": "^7.29.7",
44
- "@babel/plugin-transform-runtime": "^7.29.7",
45
- "@babel/preset-env": "^7.29.7",
46
- "@babel/runtime-corejs3": "^7.29.7",
43
+ "@babel/core": "^8.0.1",
44
+ "@babel/plugin-transform-runtime": "^8.0.1",
45
+ "@babel/preset-env": "^8.0.1",
46
+ "@babel/runtime-corejs3": "^8.0.0",
47
47
  "@types/react": "^19.2.17",
48
48
  "@types/react-dom": "^19.2.3",
49
49
  "@vitejs/plugin-react": "^6.0.2",
50
50
  "jsdom": "^29.1.1",
51
51
  "typescript": "^6.0.3",
52
- "vitest": "^4.1.8"
52
+ "vitest": "^4.1.9"
53
53
  },
54
54
  "overrides": {
55
55
  "react": "$react",
@@ -57,9 +57,9 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@etsoo/appscript": "^1.6.66",
60
- "@etsoo/materialui": "^1.6.70",
60
+ "@etsoo/materialui": "^1.6.71",
61
61
  "@etsoo/react": "^1.8.91",
62
- "@etsoo/shared": "^1.2.84",
62
+ "@etsoo/shared": "^1.2.86",
63
63
  "@etsoo/toolpad": "^1.0.50",
64
64
  "@mui/material": "^9.1.1",
65
65
  "ajv": "^8.20.0",
package/src/CoreApp.ts CHANGED
@@ -6,16 +6,18 @@ import { PublicApi } from "./PublicApi";
6
6
  import { UserApi } from "./UserApi";
7
7
  import {
8
8
  AuthApi,
9
+ BusinessUtils,
9
10
  IApp,
10
11
  IdentityType,
11
12
  IdentityTypeFlags,
12
13
  UserIdentifierType
13
14
  } from "@etsoo/appscript";
14
15
  import { AuthCodeApi } from "./AuthCodeApi";
15
- import { DataTypes, ListType, ListType1 } from "@etsoo/shared";
16
+ import { DataTypes, ListType, ListType1, NumberUtils } from "@etsoo/shared";
16
17
  import { CoreApiService } from "./dto/org/CoreApiService";
17
18
  import { DocumentApi } from "./DocumentApi";
18
19
  import { DocumentKind } from "./dto/document/DocumentKind";
20
+ import { OrgReportData } from "./dto/org/OrgReportData";
19
21
 
20
22
  type AppData = { id: number; appId?: number; name: string; localName?: string };
21
23
 
@@ -149,6 +151,33 @@ export interface ICoreApp {
149
151
  * @returns List
150
152
  */
151
153
  getIdentityFlags(identity?: number | true): ListType[];
154
+
155
+ /**
156
+ * Get report data
157
+ * 获取报告数据
158
+ * @param data Input data
159
+ * @param year Year to calculate
160
+ * @returns Result
161
+ */
162
+ getReportData(data: OrgReportData[], year: number): number[];
163
+
164
+ /**
165
+ * Transform report data for chart
166
+ * 转换报告数据用于图表
167
+ * @param data Input data
168
+ * @param hasLastYear Has last year data
169
+ * @param year Year to calculate, default is current year
170
+ * @returns Transformed report data
171
+ */
172
+ transformReportData(
173
+ data: OrgReportData[],
174
+ hasLastYear?: boolean,
175
+ year?: number
176
+ ): {
177
+ labels: string[];
178
+ currentYearData: number[];
179
+ lastYearData: number[];
180
+ };
152
181
  }
153
182
 
154
183
  /**
@@ -383,4 +412,52 @@ export class CoreApp implements ICoreApp {
383
412
  if (id === 0 || (id & identity) > 0) return id;
384
413
  });
385
414
  }
415
+
416
+ /**
417
+ * Get report data
418
+ * 获取报告数据
419
+ * @param data Input data
420
+ * @param year Year to calculate
421
+ * @returns Result
422
+ */
423
+ getReportData(data: OrgReportData[], year: number) {
424
+ const [start, end] = NumberUtils.getMonthPeriodRange(year);
425
+ const items: number[] = [];
426
+
427
+ for (let i = start; i <= end; i++) {
428
+ const item = data.find((d) => d.period === i);
429
+ items.push(item ? ("qty" in item ? item.qty : item.amount) : 0);
430
+ }
431
+
432
+ return items;
433
+ }
434
+
435
+ /**
436
+ * Transform report data for chart
437
+ * 转换报告数据用于图表
438
+ * @param data Input data
439
+ * @param hasLastYear Has last year data
440
+ * @param year Year to calculate, default is current year
441
+ * @returns Transformed report data
442
+ */
443
+ transformReportData(
444
+ data: OrgReportData[],
445
+ hasLastYear?: boolean,
446
+ year?: number
447
+ ) {
448
+ year ??= new Date().getFullYear();
449
+
450
+ const months = BusinessUtils.getMonths(
451
+ this.app.get<string[]>("months") ?? []
452
+ );
453
+ const labels = months.map((m) => m.label);
454
+
455
+ const currentYearData = this.getReportData(data, year);
456
+ const lastYearData =
457
+ hasLastYear == null || hasLastYear
458
+ ? this.getReportData(data, year - 1)
459
+ : [];
460
+
461
+ return { labels, currentYearData, lastYearData };
462
+ }
386
463
  }
package/src/OrgApi.ts CHANGED
@@ -36,6 +36,8 @@ import { OrgQueryApiData } from "./dto/org/OrgQueryApiData";
36
36
  import { CoreApiService } from "./dto/org/CoreApiService";
37
37
  import { UploadFilesResult } from "./dto/org/UploadFilesResult";
38
38
  import { OrgOwnsRQ } from "./rq/org/OrgOwnsRQ";
39
+ import { OrgUsageReportRQ } from "./rq/org/OrgUsageReportRQ";
40
+ import { OrgReportData } from "./dto/org/OrgReportData";
39
41
 
40
42
  /**
41
43
  * Organization API
@@ -412,4 +414,14 @@ export class OrgApi extends EntityApi {
412
414
  payload
413
415
  );
414
416
  }
417
+
418
+ /**
419
+ * Get usage report
420
+ * @param rq Request data
421
+ * @param payload Payload
422
+ * @returns Result
423
+ */
424
+ usageReport(rq: OrgUsageReportRQ, payload?: IApiPayload<OrgReportData[]>) {
425
+ return this.api.post(`${this.flag}/UsageReport`, rq, payload);
426
+ }
415
427
  }