ts-glitter 20.8.7 → 20.9.1

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 (180) hide show
  1. package/lowcode/Entry.js +1 -1
  2. package/lowcode/Entry.ts +1 -1
  3. package/lowcode/backend-manager/bg-product.js +1 -1
  4. package/lowcode/backend-manager/bg-product.ts +1 -1
  5. package/lowcode/backend-manager/bg-recommend.js +1 -1
  6. package/lowcode/backend-manager/bg-recommend.ts +2 -2
  7. package/lowcode/backend-manager/bg-shopping.js +2 -5
  8. package/lowcode/backend-manager/bg-shopping.ts +2 -5
  9. package/lowcode/cms-plugin/POS-setting.js +58 -34
  10. package/lowcode/cms-plugin/POS-setting.ts +69 -33
  11. package/lowcode/cms-plugin/data-analyze-orders.js +0 -1
  12. package/lowcode/cms-plugin/data-analyze-orders.ts +1 -1
  13. package/lowcode/cms-plugin/data-analyze.js +1 -21
  14. package/lowcode/cms-plugin/data-analyze.ts +25 -25
  15. package/lowcode/cms-plugin/filter-options.js +1 -1
  16. package/lowcode/cms-plugin/filter-options.ts +1 -2
  17. package/lowcode/cms-plugin/information/information-module.js +275 -0
  18. package/lowcode/cms-plugin/information/information-module.ts +308 -0
  19. package/lowcode/cms-plugin/pos-pages/models.ts +3 -1
  20. package/lowcode/cms-plugin/pos-pages/payment-page.js +3 -11
  21. package/lowcode/cms-plugin/pos-pages/payment-page.ts +3 -11
  22. package/lowcode/cms-plugin/pos-pages/pos-function.js +1 -0
  23. package/lowcode/cms-plugin/pos-pages/pos-function.ts +1 -0
  24. package/lowcode/cms-plugin/pos-pages/products-page.js +1 -1
  25. package/lowcode/cms-plugin/pos-pages/products-page.ts +1 -1
  26. package/lowcode/cms-plugin/product-service.js +4 -9
  27. package/lowcode/cms-plugin/product-service.ts +4 -13
  28. package/lowcode/cms-plugin/shopping-discount-setting.js +76 -27
  29. package/lowcode/cms-plugin/shopping-discount-setting.ts +123 -63
  30. package/lowcode/cms-plugin/shopping-information.js +21 -167
  31. package/lowcode/cms-plugin/shopping-information.ts +35 -191
  32. package/lowcode/cms-plugin/shopping-order-return.js +212 -360
  33. package/lowcode/cms-plugin/shopping-order-return.ts +349 -482
  34. package/lowcode/cms-plugin/shopping-product-setting.js +8 -0
  35. package/lowcode/cms-plugin/shopping-product-setting.ts +12 -4
  36. package/lowcode/form-view/e-commerce/product-select.js +59 -51
  37. package/lowcode/form-view/e-commerce/product-select.ts +279 -266
  38. package/lowcode/glitter-base/global/language.js +2 -1
  39. package/lowcode/glitter-base/global/language.ts +2 -1
  40. package/lowcode/public-components/checkout/index.ts +2078 -2078
  41. package/lowcode/public-components/headers/sy-02.js +190 -179
  42. package/lowcode/public-components/headers/sy-02.ts +397 -370
  43. package/lowcode/public-components/headers/sy-03.js +133 -107
  44. package/lowcode/public-components/headers/sy-03.ts +276 -244
  45. package/lowcode/public-components/headers/sy-04.js +181 -146
  46. package/lowcode/public-components/headers/sy-04.ts +289 -247
  47. package/lowcode/public-components/product/pd-class.js +31 -23
  48. package/lowcode/public-components/product/pd-class.ts +51 -29
  49. package/lowcode/public-components/user-manager/um-voucher.js +1 -0
  50. package/lowcode/public-components/user-manager/um-voucher.ts +1 -0
  51. package/package.json +1 -1
  52. package/src/Language.js +1 -1
  53. package/src/Language.js.map +1 -1
  54. package/src/Language.ts +1 -1
  55. package/src/api-public/controllers/ai-chat.js.map +1 -1
  56. package/src/api-public/controllers/chat.js.map +1 -1
  57. package/src/api-public/controllers/customer-sessions.js.map +1 -1
  58. package/src/api-public/controllers/fb-message.js.map +1 -1
  59. package/src/api-public/controllers/fb-service.js.map +1 -1
  60. package/src/api-public/controllers/invoice.js.map +1 -1
  61. package/src/api-public/controllers/line-message.js.map +1 -1
  62. package/src/api-public/controllers/oauth.js.map +1 -1
  63. package/src/api-public/controllers/progress.js.map +1 -1
  64. package/src/api-public/controllers/rebate.js.map +1 -1
  65. package/src/api-public/controllers/recommend.js.map +1 -1
  66. package/src/api-public/controllers/reconciliation.js.map +1 -1
  67. package/src/api-public/controllers/shop.js +5 -2
  68. package/src/api-public/controllers/shop.js.map +1 -1
  69. package/src/api-public/controllers/shop.ts +7 -3
  70. package/src/api-public/controllers/shopee.js.map +1 -1
  71. package/src/api-public/controllers/sms.js.map +1 -1
  72. package/src/api-public/controllers/smtp.js.map +1 -1
  73. package/src/api-public/controllers/stock.js.map +1 -1
  74. package/src/api-public/controllers/track.js.map +1 -1
  75. package/src/api-public/controllers/voucher.js.map +1 -1
  76. package/src/api-public/models/glitter-finance.js +1 -2
  77. package/src/api-public/models/glitter-finance.js.map +1 -1
  78. package/src/api-public/services/EcInvoice.js.map +1 -1
  79. package/src/api-public/services/article.js.map +1 -1
  80. package/src/api-public/services/auto-send-email.js.map +1 -1
  81. package/src/api-public/services/chat.js.map +1 -1
  82. package/src/api-public/services/checkout-event.d.ts +1 -0
  83. package/src/api-public/services/checkout-event.js +17 -7
  84. package/src/api-public/services/checkout-event.js.map +1 -1
  85. package/src/api-public/services/checkout-event.ts +21 -9
  86. package/src/api-public/services/checkout.js.map +1 -1
  87. package/src/api-public/services/custom-code.js.map +1 -1
  88. package/src/api-public/services/customer-sessions.js.map +1 -1
  89. package/src/api-public/services/data-analyze.js +209 -196
  90. package/src/api-public/services/data-analyze.js.map +1 -1
  91. package/src/api-public/services/data-analyze.ts +219 -205
  92. package/src/api-public/services/delivery.js.map +1 -1
  93. package/src/api-public/services/ezpay/tool.d.ts +0 -1
  94. package/src/api-public/services/ezpay/tool.js.map +1 -1
  95. package/src/api-public/services/fake-data-model/fake-order.js.map +1 -1
  96. package/src/api-public/services/fake-data-model/fake-product.js.map +1 -1
  97. package/src/api-public/services/fake-data-model/fake-user.js.map +1 -1
  98. package/src/api-public/services/fb-api.js.map +1 -1
  99. package/src/api-public/services/filter-protect-data.js.map +1 -1
  100. package/src/api-public/services/financial-service.js +0 -1
  101. package/src/api-public/services/financial-service.js.map +1 -1
  102. package/src/api-public/services/form-check.js.map +1 -1
  103. package/src/api-public/services/graph-api.js.map +1 -1
  104. package/src/api-public/services/initial-fake-data.js.map +1 -1
  105. package/src/api-public/services/invoice.d.ts +3 -9
  106. package/src/api-public/services/invoice.js +66 -85
  107. package/src/api-public/services/invoice.js.map +1 -1
  108. package/src/api-public/services/invoice.ts +287 -293
  109. package/src/api-public/services/language-setting.js.map +1 -1
  110. package/src/api-public/services/mail.js.map +1 -1
  111. package/src/api-public/services/manager.js.map +1 -1
  112. package/src/api-public/services/paynow-logistics.js.map +1 -1
  113. package/src/api-public/services/phone-verify.js.map +1 -1
  114. package/src/api-public/services/pos.js.map +1 -1
  115. package/src/api-public/services/post.js.map +1 -1
  116. package/src/api-public/services/product-initial.js.map +1 -1
  117. package/src/api-public/services/rebate.js.map +1 -1
  118. package/src/api-public/services/reconciliation.js.map +1 -1
  119. package/src/api-public/services/schedule.d.ts +1 -0
  120. package/src/api-public/services/schedule.js +27 -0
  121. package/src/api-public/services/schedule.js.map +1 -1
  122. package/src/api-public/services/schedule.ts +30 -0
  123. package/src/api-public/services/shopping.d.ts +4 -3
  124. package/src/api-public/services/shopping.js +40 -20
  125. package/src/api-public/services/shopping.js.map +1 -1
  126. package/src/api-public/services/shopping.ts +52 -28
  127. package/src/api-public/services/stock.js.map +1 -1
  128. package/src/api-public/services/terms-check.js.map +1 -1
  129. package/src/api-public/services/updated-table-checked.js.map +1 -1
  130. package/src/api-public/services/user-update.js.map +1 -1
  131. package/src/api-public/services/user.d.ts +10 -0
  132. package/src/api-public/services/user.js +35 -8
  133. package/src/api-public/services/user.js.map +1 -1
  134. package/src/api-public/services/user.ts +50 -7
  135. package/src/api-public/services/voucher.js.map +1 -1
  136. package/src/api-public/utils/ut-database.js.map +1 -1
  137. package/src/app-project/android/app/src/main/res/xml/network_security_config.xml +3 -3
  138. package/src/app-project/android/app/src/main/res/xml/s.xml +5 -5
  139. package/src/app-project/android/gradlew.bat +94 -94
  140. package/src/app-project/serverless/src/controllers/index.js.map +1 -1
  141. package/src/app-project/serverless/src/controllers/sample.js.map +1 -1
  142. package/src/app-project/serverless/src/modules/database.d.ts +1 -2
  143. package/src/app-project/serverless/src/modules/database.js.map +1 -1
  144. package/src/app-project/serverless/src/modules/exception.js.map +1 -1
  145. package/src/app-project/serverless/src/modules/hooks.js.map +1 -1
  146. package/src/app-project/serverless/src/modules/logger.js.map +1 -1
  147. package/src/app-project/serverless/src/modules/redis.d.ts +1 -1
  148. package/src/app-project/serverless/src/modules/redis.js.map +1 -1
  149. package/src/app-project/serverless/src/modules/response.js.map +1 -1
  150. package/src/app-project/serverless/src/modules/ssh.js.map +1 -1
  151. package/src/controllers/ai.js.map +1 -1
  152. package/src/controllers/global-event.js.map +1 -1
  153. package/src/controllers/page.js.map +1 -1
  154. package/src/controllers/private_config.js.map +1 -1
  155. package/src/export/export-test.js.map +1 -1
  156. package/src/firebase/message.js +1 -2
  157. package/src/firebase/message.js.map +1 -1
  158. package/src/helper/app_creater.js +1 -2
  159. package/src/helper/app_creater.js.map +1 -1
  160. package/src/helper/glitter-util.d.ts +0 -1
  161. package/src/helper/glitter-util.js.map +1 -1
  162. package/src/lambda/interface.d.ts +1 -1
  163. package/src/lambda/interface.js +2 -2
  164. package/src/lambda/interface.js.map +1 -1
  165. package/src/modules/database.js +4 -3
  166. package/src/modules/database.js.map +1 -1
  167. package/src/modules/database.ts +4 -4
  168. package/src/modules/exception.js.map +1 -1
  169. package/src/modules/hooks.js.map +1 -1
  170. package/src/modules/response.js.map +1 -1
  171. package/src/modules/ssh.js.map +1 -1
  172. package/src/public-config-initial/auto-fcm.js.map +1 -1
  173. package/src/run.js.map +1 -1
  174. package/src/run.ts +12 -12
  175. package/src/services/ai.js.map +1 -1
  176. package/src/services/ses.js +1 -2
  177. package/src/services/ses.js.map +1 -1
  178. package/src/services/system-schedule.js.map +1 -1
  179. package/src/update-progress-track.js.map +1 -1
  180. package/src/update-script.js.map +1 -1
@@ -1,36 +1,75 @@
1
1
  import app from '../../app.js';
2
- import response from '../../modules/response.js';
3
- import { EzInvoice } from './ezpay/invoice.js';
4
2
  import exception from '../../modules/exception.js';
5
3
  import db from '../../modules/database.js';
4
+ import Tool from '../../modules/tool.js';
5
+ import { EzInvoice } from './ezpay/invoice.js';
6
6
  import { EcInvoice, EcInvoiceInterface } from './EcInvoice.js';
7
- import { EcPay } from './financial-service.js';
8
7
  import { Shopping } from './shopping.js';
9
- import Tool from '../../modules/tool.js';
8
+
9
+ type InvoiceOrder = {
10
+ user_info: {
11
+ name: string;
12
+ note: string;
13
+ email: string;
14
+ phone: string;
15
+ address: string;
16
+ gui_number?: string;
17
+ company?: string;
18
+ invoice_type: 'company' | 'me' | 'donate';
19
+ send_type: 'email' | 'carrier';
20
+ carrier_num: string;
21
+ };
22
+ total: number;
23
+ lineItems: [
24
+ {
25
+ id: number;
26
+ spec: string[];
27
+ count: number;
28
+ title: string;
29
+ collection: string[];
30
+ sale_price: number;
31
+ preview_image: string;
32
+ discount_price: number;
33
+ },
34
+ ];
35
+ use_wallet: number;
36
+ use_rebate: number;
37
+ shipment_fee: number;
38
+ discount: number;
39
+ orderID: number;
40
+ };
10
41
 
11
42
  export class Invoice {
12
- public appName: string;
43
+ appName: string;
13
44
 
14
45
  constructor(appName: string) {
15
46
  this.appName = appName;
16
47
  }
17
48
 
18
- //判斷發票類型開立
19
- public async postInvoice(cf: { invoice_data: any; print: boolean; order_id: string; orderData: any }) {
49
+ static checkWhiteList(config: any, invoice_data: any) {
50
+ if (config.point === 'beta' && invoice_data.BuyerEmail && config.whiteList && config.whiteList.length > 0) {
51
+ return config.whiteList.find((dd: any) => dd.email === invoice_data.BuyerEmail);
52
+ }
53
+ return true;
54
+ }
55
+
56
+ // 判斷發票類型開立
57
+ async postInvoice(cf: { invoice_data: any; print: boolean; order_id: string; orderData: any }) {
20
58
  try {
21
59
  const config = await app.getAdConfig(this.appName, 'invoice_setting');
60
+ let invoiceResult = {};
61
+
22
62
  switch (config.fincial) {
23
63
  case 'ezpay':
24
- return await EzInvoice.postInvoice({
64
+ invoiceResult = await EzInvoice.postInvoice({
25
65
  hashKey: config.hashkey,
26
66
  hash_IV: config.hashiv,
27
67
  merchNO: config.merchNO,
28
68
  invoice_data: cf.invoice_data,
29
69
  beta: config.point === 'beta',
30
70
  });
31
- // ecpay跟
32
71
  case 'ecpay':
33
- return await EcInvoice.postInvoice({
72
+ invoiceResult = await EcInvoice.postInvoice({
34
73
  hashKey: config.hashkey,
35
74
  hash_IV: config.hashiv,
36
75
  merchNO: config.merchNO,
@@ -42,70 +81,51 @@ export class Invoice {
42
81
  print: cf.print,
43
82
  });
44
83
  }
84
+
85
+ // 更新排程開立發票資料
86
+ await db.query(
87
+ `
88
+ UPDATE \`${this.appName}\`.t_triggers SET status = 1
89
+ WHERE tag = 'triggerInvoice' AND content->>'$.cart_token' = ?;
90
+ `,
91
+ [cf.order_id]
92
+ );
93
+
94
+ return invoiceResult;
45
95
  } catch (e: any) {
46
- throw exception.BadRequestError('BAD_REQUEST', e.message, null);
96
+ throw exception.BadRequestError('BAD_REQUEST', 'postInvoice Error: ' + e.message, null);
47
97
  }
48
98
  }
49
99
 
50
- //訂單開發票
51
- public async postCheckoutInvoice(orderID: string | any, print: boolean, obj?: { offlineInvoice?: boolean }) {
52
- const order: {
53
- user_info: {
54
- name: string;
55
- note: string;
56
- email: string;
57
- phone: string;
58
- address: string;
59
- gui_number?: string;
60
- company?: string;
61
- invoice_type: 'company' | 'me' | 'donate';
62
- send_type: 'email' | 'carrier';
63
- carrier_num: string;
64
- };
65
- total: number;
66
- lineItems: [
67
- {
68
- id: number;
69
- spec: string[];
70
- count: number;
71
- title: string;
72
- collection: string[];
73
- sale_price: number;
74
- preview_image: string;
75
- discount_price: number;
76
- },
77
- ];
78
- use_wallet: number;
79
- use_rebate: number;
80
- shipment_fee: number;
81
- discount: number;
82
- orderID: number;
83
- } =
100
+ // 訂單開立發票
101
+ async postCheckoutInvoice(orderID: string | any, print: boolean, obj?: { offlineInvoice?: boolean }) {
102
+ const order: InvoiceOrder =
84
103
  typeof orderID === 'string'
85
104
  ? (
86
105
  await db.query(
87
- `SELECT *
88
- FROM \`${this.appName}\`.t_checkout
89
- where cart_token = ?`,
106
+ `SELECT * FROM \`${this.appName}\`.t_checkout WHERE cart_token = ?
107
+ `,
90
108
  [orderID]
91
109
  )
92
110
  )[0]['orderData']
93
111
  : orderID;
112
+
94
113
  const count_invoice = (
95
114
  await db.query(
96
- `SELECT count(1)
97
- from \`${this.appName}\`.t_invoice_memory
98
- where order_id = ?
99
- and status = 1`,
115
+ `SELECT count(1) FROM \`${this.appName}\`.t_invoice_memory WHERE order_id = ? AND status = 1
116
+ `,
100
117
  [order.orderID]
101
118
  )
102
119
  )[0]['count(1)'];
120
+
103
121
  if (count_invoice) {
104
122
  return false;
105
123
  }
106
- const config = await app.getAdConfig(this.appName, 'invoice_setting');
124
+
107
125
  let can_discount_tax_5 = 0;
108
126
  let can_discount_tax_0 = 0;
127
+ const config = await app.getAdConfig(this.appName, 'invoice_setting');
128
+
109
129
  const line_item = await Promise.all(
110
130
  order.lineItems.map(async dd => {
111
131
  const product = await new Shopping(this.appName).getProduct({
@@ -129,10 +149,12 @@ export class Invoice {
129
149
  };
130
150
  })
131
151
  );
152
+
132
153
  order.use_rebate = parseInt(`${order.use_rebate || '0'}`, 10);
133
154
  order.discount = parseInt(`${order.discount || '0'}`, 10);
134
155
  order.shipment_fee = parseInt(`${order.shipment_fee || '0'}`, 10);
135
- //所有折扣扣除應稅折扣
156
+
157
+ // 所有折扣扣除應稅折扣
136
158
  let all_discount = order.use_rebate + order.discount;
137
159
  if (order.shipment_fee) {
138
160
  can_discount_tax_5 = can_discount_tax_5 + order.shipment_fee;
@@ -153,12 +175,9 @@ export class Invoice {
153
175
  ItemAmt: (all_discount <= can_discount_tax_5 ? all_discount : can_discount_tax_5) * -1,
154
176
  ItemTaxType: 1,
155
177
  });
156
- //所有折扣扣除應稅折扣
157
- if (
158
- line_item.find(dd => {
159
- return dd.ItemTaxType === 3;
160
- })
161
- ) {
178
+
179
+ // 所有折扣扣除應稅折扣
180
+ if (line_item.find(dd => dd.ItemTaxType === 3)) {
162
181
  let free_tax_discount = all_discount - can_discount_tax_5;
163
182
  line_item.push({
164
183
  ItemName: '免稅折扣',
@@ -226,11 +245,7 @@ export class Invoice {
226
245
  : undefined,
227
246
  Donation: order.user_info.invoice_type === 'donate' ? '1' : '0',
228
247
  LoveCode: order.user_info.invoice_type === 'donate' ? (order.user_info as any).love_code : undefined,
229
- TaxType: line_item.find(dd => {
230
- return dd.ItemTaxType === 3;
231
- })
232
- ? '9'
233
- : '1',
248
+ TaxType: line_item.find(dd => dd.ItemTaxType === 3) ? '9' : '1',
234
249
  SalesAmount: order.total,
235
250
  InvType: '07',
236
251
  Items: line_item.map((dd, index) => {
@@ -246,8 +261,8 @@ export class Invoice {
246
261
  };
247
262
  }),
248
263
  };
249
- if(order.user_info.invoice_type === 'company'){
250
- json={
264
+ if (order.user_info.invoice_type === 'company') {
265
+ json = {
251
266
  ...json,
252
267
  ClearanceMark: '1',
253
268
  Print: '1',
@@ -255,7 +270,7 @@ export class Invoice {
255
270
  LoveCode: '',
256
271
  CarrierType: '',
257
272
  CarrierNum: '',
258
- }
273
+ };
259
274
  }
260
275
  if (print) {
261
276
  const cover = {
@@ -293,26 +308,217 @@ export class Invoice {
293
308
  }
294
309
  }
295
310
 
296
- public async updateInvoice(obj: { orderID: string; invoice_data: any }) {
297
- let data = await db.query(
298
- `SELECT *
299
- FROM \`${this.appName}\`.t_invoice_memory
300
- where order_id = ?`,
301
- [obj.orderID]
302
- );
303
- data = data[0];
311
+ // 更新發票
312
+ async updateInvoice(obj: { orderID: string; invoice_data: any }) {
313
+ const data = (
314
+ await db.query(
315
+ `SELECT * FROM \`${this.appName}\`.t_invoice_memory WHERE order_id = ?
316
+ `,
317
+ [obj.orderID]
318
+ )
319
+ )[0];
304
320
  data.invoice_data.remark = obj.invoice_data;
321
+
305
322
  await db.query(
306
323
  `UPDATE \`${this.appName}\`.t_invoice_memory
307
- set invoice_data = ?
308
- WHERE order_id = ?`,
324
+ SET invoice_data = ? WHERE order_id = ?`,
309
325
  [JSON.stringify(data.invoice_data), obj.orderID]
310
326
  );
311
- // console.log("data -- " , data.invoice_data)
312
327
  }
313
328
 
314
- //儲值開立發票
315
- // public async postCheckoutInvoice(orderID: string|any ,print:boolean) {
329
+ // 取得發票
330
+ async getInvoice(query: {
331
+ page: number;
332
+ limit: number;
333
+ search?: string;
334
+ searchType?: string;
335
+ orderString?: string;
336
+ created_time?: string;
337
+ invoice_type?: string;
338
+ issue_method?: string;
339
+ status?: string;
340
+ filter?: any;
341
+ }) {
342
+ try {
343
+ const querySql = [`1=1`];
344
+
345
+ if (query.search) {
346
+ switch (query.searchType) {
347
+ case 'invoice_number':
348
+ querySql.push(`invoice_no LIKE '%${query.search}%'`);
349
+ break;
350
+ case 'name':
351
+ querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.CustomerName') LIKE '%${query.search}%'`);
352
+ break;
353
+ case 'business_number':
354
+ querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.CustomerIdentifier') LIKE '%${query.search}%'`);
355
+ break;
356
+ case 'phone':
357
+ querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.CustomerPhone') LIKE '%${query.search}%'`);
358
+ break;
359
+ case 'product_name':
360
+ querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.Items[*].ItemName') LIKE '%${query.search}%'`);
361
+ break;
362
+ case 'product_number':
363
+ querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.Items[*].ItemNumber') LIKE '%${query.search}%'`);
364
+ break;
365
+ case 'order_number':
366
+ default:
367
+ querySql.push(`order_id LIKE '%${query.search}%'`);
368
+ break;
369
+ }
370
+ }
371
+
372
+ if (query.created_time) {
373
+ const created_time = query.created_time.split(',');
374
+ if (created_time.length > 1) {
375
+ querySql.push(`
376
+ (create_date BETWEEN ${db.escape(`${created_time[0]} 00:00:00`)}
377
+ AND ${db.escape(`${created_time[1]} 23:59:59`)})
378
+ `);
379
+ }
380
+ }
381
+ // 發票種類: B2B,B2C 發票開立方式: 自動,手動
382
+ if (query.invoice_type) {
383
+ const data = query.invoice_type;
384
+ if (data == 'B2B') {
385
+ querySql.push(`
386
+ JSON_EXTRACT(invoice_data, '$.original_data.CustomerIdentifier') IS NULL
387
+ OR CHAR_LENGTH(JSON_EXTRACT(invoice_data, '$.original_data.CustomerIdentifier')) = 0
388
+ `);
389
+ } else {
390
+ querySql.push(`
391
+ JSON_EXTRACT(invoice_data, '$.original_data.CustomerIdentifier') IS NOT NULL
392
+ AND CHAR_LENGTH(JSON_EXTRACT(invoice_data, '$.original_data.CustomerIdentifier')) > 0
393
+ `);
394
+ }
395
+ }
396
+ if (query.issue_method) {
397
+ if (query.issue_method == 'manual') {
398
+ querySql.push(`
399
+ JSON_EXTRACT(invoice_data, '$.remark.issueType') IS NOT NULL
400
+ AND CHAR_LENGTH(JSON_EXTRACT(invoice_data, '$.remark.issueType')) > 0
401
+ `);
402
+ } else {
403
+ querySql.push(`
404
+ JSON_EXTRACT(invoice_data, '$.remark.issueType') IS NULL
405
+ OR CHAR_LENGTH(JSON_EXTRACT(invoice_data, '$.remark.issueType')) = 0
406
+ `);
407
+ }
408
+ }
409
+ query.status && querySql.push(`status IN (${query.status})`);
410
+ query.orderString = (() => {
411
+ switch (query.orderString) {
412
+ case 'created_time_desc':
413
+ return `order by create_date desc`;
414
+ case 'created_time_asc':
415
+ return `order by create_date ASC`;
416
+ case 'order_total_desc':
417
+ return `ORDER BY JSON_EXTRACT(invoice_data, '$.original_data.SalesAmount') DESC`;
418
+ case 'order_total_asc':
419
+ return `ORDER BY JSON_EXTRACT(invoice_data, '$.original_data.SalesAmount') ASC`;
420
+ case 'default':
421
+ default:
422
+ return `order by id desc`;
423
+ }
424
+ })();
425
+ const sql = `
426
+ SELECT *
427
+ FROM \`${this.appName}\`.t_invoice_memory
428
+ WHERE ${querySql.join(' and ')} ${query.orderString || `order by id desc`}
429
+ `;
430
+ return {
431
+ data: await db.query(
432
+ `SELECT * FROM (${sql}) as subqyery limit ${query.page * query.limit}, ${query.limit}
433
+ `,
434
+ []
435
+ ),
436
+ total: (
437
+ await db.query(
438
+ `SELECT count(1) FROM (${sql}) as subqyery
439
+ `,
440
+ []
441
+ )
442
+ )[0]['count(1)'],
443
+ };
444
+ } catch (e) {
445
+ console.error(e);
446
+ throw exception.BadRequestError('BAD_REQUEST', 'getInvoice Error:' + e, null);
447
+ }
448
+ }
449
+
450
+ // 取得折讓單
451
+ async getAllowance(query: {
452
+ page: number;
453
+ limit: number;
454
+ search?: string;
455
+ searchType?: string;
456
+ orderString?: string;
457
+ created_time?: string;
458
+ invoice_type?: string;
459
+ issue_method?: string;
460
+ status?: string;
461
+ filter?: string;
462
+ }) {
463
+ try {
464
+ let querySql = [`1=1`];
465
+
466
+ if (query.search) {
467
+ querySql.push(`${query.searchType} LIKE '%${query.search}%'`);
468
+ }
469
+
470
+ if (query.created_time) {
471
+ const created_time = query.created_time.split(',');
472
+ if (created_time.length > 1) {
473
+ querySql.push(`
474
+ (create_date BETWEEN ${db.escape(`${created_time[0]} 00:00:00`)}
475
+ AND ${db.escape(`${created_time[1]} 23:59:59`)})
476
+ `);
477
+ }
478
+ }
479
+ query.status && querySql.push(`status IN (${query.status})`);
480
+ query.orderString = (() => {
481
+ switch (query.orderString) {
482
+ case 'created_time_desc':
483
+ return `order by create_date desc`;
484
+ case 'created_time_asc':
485
+ return `order by create_date ASC`;
486
+ case 'order_total_desc':
487
+ return `ORDER BY JSON_EXTRACT(invoice_data, '$.original_data.SalesAmount') DESC`;
488
+ case 'order_total_asc':
489
+ return `ORDER BY JSON_EXTRACT(invoice_data, '$.original_data.SalesAmount') ASC`;
490
+ case 'default':
491
+ default:
492
+ return `order by id desc`;
493
+ }
494
+ })();
495
+ let sql = `
496
+ SELECT *
497
+ FROM \`${this.appName}\`.t_allowance_memory
498
+ WHERE ${querySql.join(' and ')} ${query.orderString || `order by id desc`}
499
+ `;
500
+ return {
501
+ data: await db.query(
502
+ `SELECT * FROM (${sql}) as subqyery limit ${query.page * query.limit}, ${query.limit}
503
+ `,
504
+ []
505
+ ),
506
+ total: (
507
+ await db.query(
508
+ `SELECT count(1) FROM (${sql}) as subqyery
509
+ `,
510
+ []
511
+ )
512
+ )[0]['count(1)'],
513
+ };
514
+ } catch (e) {
515
+ console.error(e);
516
+ throw exception.BadRequestError('BAD_REQUEST', 'getAllowance Error:' + e, null);
517
+ }
518
+ }
519
+
520
+ // 儲值開立發票
521
+ // async postCheckoutInvoice(orderID: string|any ,print:boolean) {
316
522
  // const order: {
317
523
  // user_info: {
318
524
  // name: string;
@@ -466,7 +672,6 @@ export class Invoice {
466
672
  // "TaxType": "1",
467
673
  // "InvType": "07"
468
674
  // }
469
- // console.log(`cover.CustomerEmail==>`,cover.CustomerEmail)
470
675
  // if(order.user_info.invoice_type==='company'){
471
676
  // cover.CustomerName=await EcInvoice.getCompanyName({
472
677
  // company_id:order.user_info.gui_number as any,
@@ -485,215 +690,4 @@ export class Invoice {
485
690
  // return 'no_need'
486
691
  // }
487
692
  // }
488
-
489
- public static checkWhiteList(config: any, invoice_data: any) {
490
- if (config.point === 'beta' && invoice_data.BuyerEmail && config.whiteList && config.whiteList.length > 0) {
491
- return config.whiteList.find((dd: any) => {
492
- return dd.email === invoice_data.BuyerEmail;
493
- });
494
- } else {
495
- return true;
496
- }
497
- }
498
-
499
- public async getInvoice(query: {
500
- page: number;
501
- limit: number;
502
- search?: string;
503
- searchType?: string;
504
- orderString?: string;
505
- created_time?: string;
506
- invoice_type?: string;
507
- issue_method?: string;
508
- status?: string;
509
- filter?: any;
510
- }) {
511
- try {
512
- let querySql = [`1=1`];
513
- if (query.search) {
514
- switch (query.searchType) {
515
- case 'invoice_number':
516
- querySql.push(`invoice_no LIKE '%${query.search}%'`);
517
- break;
518
- case 'name':
519
- querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.CustomerName') LIKE '%${query.search}%'`);
520
- break;
521
- case 'business_number':
522
- querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.CustomerIdentifier') LIKE '%${query.search}%'`);
523
- break;
524
- case 'phone':
525
- querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.CustomerPhone') LIKE '%${query.search}%'`);
526
- break;
527
- case 'product_name':
528
- querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.Items[*].ItemName') LIKE '%${query.search}%'`);
529
- break;
530
- case 'product_number':
531
- querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.Items[*].ItemNumber') LIKE '%${query.search}%'`);
532
- break;
533
- case 'order_number':
534
- default:
535
- querySql.push(`order_id LIKE '%${query.search}%'`);
536
-
537
- break;
538
- }
539
- }
540
-
541
- if (query.invoice_type) {
542
- const invoice_type = query.invoice_type;
543
- }
544
-
545
- if (query.created_time) {
546
- const created_time = query.created_time.split(',');
547
- if (created_time.length > 1) {
548
- querySql.push(`
549
- (create_date BETWEEN ${db.escape(`${created_time[0]} 00:00:00`)}
550
- AND ${db.escape(`${created_time[1]} 23:59:59`)})
551
- `);
552
- }
553
- }
554
- // 發票種類 B2B B2C , 發票開立方式 自動 手動
555
- if (query.invoice_type) {
556
- const data = query.invoice_type;
557
- if (data == 'B2B') {
558
- querySql.push(`
559
- JSON_EXTRACT(invoice_data, '$.original_data.CustomerIdentifier') IS NULL
560
- OR CHAR_LENGTH(JSON_EXTRACT(invoice_data, '$.original_data.CustomerIdentifier')) = 0`);
561
- } else {
562
- querySql.push(`JSON_EXTRACT(invoice_data, '$.original_data.CustomerIdentifier') IS NOT NULL
563
- AND CHAR_LENGTH(JSON_EXTRACT(invoice_data, '$.original_data.CustomerIdentifier')) > 0`);
564
- }
565
- }
566
- if (query.issue_method) {
567
- if (query.issue_method == 'manual') {
568
- console.log('query.issue_method -- ', query.issue_method);
569
- querySql.push(`JSON_EXTRACT(invoice_data, '$.remark.issueType') IS NOT NULL
570
- AND CHAR_LENGTH(JSON_EXTRACT(invoice_data, '$.remark.issueType')) > 0`);
571
- } else {
572
- querySql.push(`
573
- JSON_EXTRACT(invoice_data, '$.remark.issueType') IS NULL
574
- OR CHAR_LENGTH(JSON_EXTRACT(invoice_data, '$.remark.issueType')) = 0`);
575
- }
576
- }
577
- // query.invoice_type && querySql.push(`JSON_UNQUOTE(JSON_EXTRACT(invoice_data, '$.orderStatus')) IN (${query.invoice_type})`);
578
- // query.issue_method && querySql.push(`JSON_UNQUOTE(JSON_EXTRACT(invoice_data, '$.orderStatus')) IN (${query.issue_method})`);
579
- query.status && querySql.push(`status IN (${query.status})`);
580
- query.orderString = (() => {
581
- switch (query.orderString) {
582
- case 'created_time_desc':
583
- return `order by create_date desc`;
584
- case 'created_time_asc':
585
- return `order by create_date ASC`;
586
- case 'order_total_desc':
587
- return `ORDER BY JSON_EXTRACT(invoice_data, '$.original_data.SalesAmount') DESC`;
588
- case 'order_total_asc':
589
- return `ORDER BY JSON_EXTRACT(invoice_data, '$.original_data.SalesAmount') ASC`;
590
- case 'default':
591
- default:
592
- return `order by id desc`;
593
- }
594
- })();
595
- let sql = `SELECT *
596
- FROM \`${this.appName}\`.t_invoice_memory
597
- WHERE ${querySql.join(' and ')} ${query.orderString || `order by id desc`}
598
- `;
599
- return {
600
- data: await db.query(
601
- `SELECT *
602
- FROM (${sql}) as subqyery limit ${query.page * query.limit}, ${query.limit}`,
603
- []
604
- ),
605
- total: (
606
- await db.query(
607
- `SELECT count(1)
608
- FROM (${sql}) as subqyery`,
609
- []
610
- )
611
- )[0]['count(1)'],
612
- };
613
- } catch (e) {
614
- console.error(e);
615
- throw exception.BadRequestError('BAD_REQUEST', 'GetProduct Error:' + e, null);
616
- }
617
- }
618
-
619
- public async getAllowance(query: {
620
- page: number;
621
- limit: number;
622
- search?: string;
623
- searchType?: string;
624
- orderString?: string;
625
- created_time?: string;
626
- invoice_type?: string;
627
- issue_method?: string;
628
- status?: string;
629
- filter?: string;
630
- }) {
631
- try {
632
- let querySql = [`1=1`];
633
- console.log('searchType -- ', query.searchType);
634
- if (query.search) {
635
- querySql.push(`${query.searchType} LIKE '%${query.search}%'`);
636
- }
637
-
638
- if (query.created_time) {
639
- const created_time = query.created_time.split(',');
640
- if (created_time.length > 1) {
641
- querySql.push(`
642
- (create_date BETWEEN ${db.escape(`${created_time[0]} 00:00:00`)}
643
- AND ${db.escape(`${created_time[1]} 23:59:59`)})
644
- `);
645
- }
646
- }
647
- query.status && querySql.push(`status IN (${query.status})`);
648
- query.orderString = (() => {
649
- switch (query.orderString) {
650
- case 'created_time_desc':
651
- return `order by create_date desc`;
652
- case 'created_time_asc':
653
- return `order by create_date ASC`;
654
- case 'order_total_desc':
655
- return `ORDER BY JSON_EXTRACT(invoice_data, '$.original_data.SalesAmount') DESC`;
656
- case 'order_total_asc':
657
- return `ORDER BY JSON_EXTRACT(invoice_data, '$.original_data.SalesAmount') ASC`;
658
- case 'default':
659
- default:
660
- return `order by id desc`;
661
- }
662
- })();
663
- let sql = `SELECT *
664
- FROM \`${this.appName}\`.t_allowance_memory
665
- WHERE ${querySql.join(' and ')} ${query.orderString || `order by id desc`}
666
- `;
667
- return {
668
- data: await db.query(
669
- `SELECT *
670
- FROM (${sql}) as subqyery limit ${query.page * query.limit}, ${query.limit}`,
671
- []
672
- ),
673
- total: (
674
- await db.query(
675
- `SELECT count(1)
676
- FROM (${sql}) as subqyery`,
677
- []
678
- )
679
- )[0]['count(1)'],
680
- };
681
- } catch (e) {
682
- console.error(e);
683
- throw exception.BadRequestError('BAD_REQUEST', 'GetProduct Error:' + e, null);
684
- }
685
- }
686
-
687
- public async querySql(querySql: string[], query: { page: number; limit: number; id?: string; order_by?: string }) {
688
- let sql = `SELECT *
689
- FROM \`${this.appName}\`.t_invoice_memory
690
- WHERE ${querySql.join(' and ')} ${query.order_by || `order by id desc`}
691
- `;
692
-
693
- try {
694
- return await db.query(sql, []);
695
- } catch (e) {
696
- console.log('get invoice failed:', e);
697
- }
698
- }
699
693
  }
@@ -1 +1 @@
1
- {"version":3,"file":"language-setting.js","sourceRoot":"","sources":["language-setting.ts"],"names":[],"mappings":";;;AAAA,uCAA+B;AAE/B,MAAa,eAAe;IAClB,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAa,EAAC,OAAc;QACxD,IAAI,UAAU,GAAG,MAAM,IAAI,cAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC;YACjD,GAAG,EAAE,mBAAmB;YACxB,OAAO,EAAE,SAAS;SACrB,CAAC,CAAC;QACH,IAAG,UAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAC;YACpD,OAAO,MAAM,CAAA;SAChB;aAAI;YACD,OAAO,UAAU,CAAC,gBAAgB,CAAC,GAAG,CAAC;SAC1C;IACL,CAAC;CACH;AAZD,0CAYC"}
1
+ {"version":3,"file":"language-setting.js","sourceRoot":"","sources":["language-setting.ts"],"names":[],"mappings":";;;AAAA,uCAA+B;AAE/B,MAAa,eAAe;IAClB,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAa,EAAC,OAAc;QACxD,IAAI,UAAU,GAAG,MAAM,IAAI,cAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC;YACjD,GAAG,EAAE,mBAAmB;YACxB,OAAO,EAAE,SAAS;SACrB,CAAC,CAAC;QACH,IAAG,UAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAC,CAAC;YACrD,OAAO,MAAM,CAAA;QACjB,CAAC;aAAI,CAAC;YACF,OAAO,UAAU,CAAC,gBAAgB,CAAC,GAAG,CAAC;QAC3C,CAAC;IACL,CAAC;CACH;AAZD,0CAYC"}