repzo-sap-absjo 1.0.20 → 1.0.22

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 (90) hide show
  1. package/changelog.md +1 -0
  2. package/lib/actions/create_invoice.d.ts +19 -13
  3. package/lib/actions/create_invoice.js +359 -210
  4. package/lib/actions/create_payment.d.ts +4 -1
  5. package/lib/actions/create_payment.js +195 -107
  6. package/lib/actions/create_proforma.d.ts +4 -1
  7. package/lib/actions/create_proforma.js +288 -147
  8. package/lib/actions/create_return_invoice.d.ts +4 -1
  9. package/lib/actions/create_return_invoice.js +312 -158
  10. package/lib/actions/create_transfer.d.ts +4 -1
  11. package/lib/actions/create_transfer.js +223 -126
  12. package/lib/actions/index.js +23 -15
  13. package/lib/commands/adjust_inventory.d.ts +4 -2
  14. package/lib/commands/adjust_inventory.js +290 -160
  15. package/lib/commands/bank.d.ts +4 -2
  16. package/lib/commands/bank.js +279 -157
  17. package/lib/commands/basic.js +68 -48
  18. package/lib/commands/brand.d.ts +3 -1
  19. package/lib/commands/brand.js +174 -100
  20. package/lib/commands/category.d.ts +3 -1
  21. package/lib/commands/category.js +178 -104
  22. package/lib/commands/channel.d.ts +3 -1
  23. package/lib/commands/channel.js +198 -117
  24. package/lib/commands/client.d.ts +34 -32
  25. package/lib/commands/client.js +404 -244
  26. package/lib/commands/client_disabled.d.ts +3 -1
  27. package/lib/commands/client_disabled.js +163 -94
  28. package/lib/commands/index.d.ts +24 -11
  29. package/lib/commands/index.js +65 -62
  30. package/lib/commands/join.js +192 -66
  31. package/lib/commands/measureunit.d.ts +19 -14
  32. package/lib/commands/measureunit.js +289 -191
  33. package/lib/commands/measureunit_family.d.ts +10 -8
  34. package/lib/commands/measureunit_family.js +250 -138
  35. package/lib/commands/payment_term.d.ts +3 -1
  36. package/lib/commands/payment_term.js +202 -123
  37. package/lib/commands/price_list.d.ts +15 -15
  38. package/lib/commands/price_list.js +617 -326
  39. package/lib/commands/price_list_disabled.d.ts +12 -0
  40. package/lib/commands/price_list_disabled.js +216 -0
  41. package/lib/commands/product.d.ts +32 -30
  42. package/lib/commands/product.js +485 -263
  43. package/lib/commands/product_disabled.d.ts +3 -1
  44. package/lib/commands/product_disabled.js +160 -94
  45. package/lib/commands/rep.js +221 -141
  46. package/lib/commands/tag.js +174 -109
  47. package/lib/commands/tax.js +177 -112
  48. package/lib/commands/warehouse.d.ts +3 -1
  49. package/lib/commands/warehouse.js +207 -119
  50. package/lib/index.d.ts +30 -12
  51. package/lib/test/actions/create_invoice.js +193 -188
  52. package/lib/test/actions/create_payment.js +112 -107
  53. package/lib/test/actions/create_proforma.js +220 -216
  54. package/lib/test/actions/create_return_invoice.js +205 -200
  55. package/lib/test/actions/create_transfer.js +120 -115
  56. package/lib/test/commands/adjust_inventory.js +90 -90
  57. package/lib/test/commands/bank.js +90 -90
  58. package/lib/test/commands/basic.js +335 -327
  59. package/lib/test/commands/brand.js +90 -90
  60. package/lib/test/commands/category.js +90 -90
  61. package/lib/test/commands/channel.js +90 -90
  62. package/lib/test/commands/client.js +355 -353
  63. package/lib/test/commands/client_disabled.js +90 -90
  64. package/lib/test/commands/join.js +328 -327
  65. package/lib/test/commands/measureunit.js +90 -90
  66. package/lib/test/commands/measureunit_family.js +90 -90
  67. package/lib/test/commands/payment_term.js +90 -90
  68. package/lib/test/commands/price_list.js +337 -334
  69. package/lib/test/commands/price_list_disabled.d.ts +1 -0
  70. package/lib/test/commands/price_list_disabled.js +359 -0
  71. package/lib/test/commands/product.js +90 -90
  72. package/lib/test/commands/product_disabled.js +90 -90
  73. package/lib/test/commands/rep.js +346 -344
  74. package/lib/test/commands/tag.js +90 -90
  75. package/lib/test/commands/tax.js +90 -90
  76. package/lib/test/commands/warehouse.js +90 -90
  77. package/lib/types.d.ts +78 -53
  78. package/lib/util.d.ts +76 -19
  79. package/lib/util.js +179 -144
  80. package/package.json +1 -1
  81. package/src/actions/create_invoice.ts +7 -18
  82. package/src/actions/create_proforma.ts +11 -1
  83. package/src/commands/basic.ts +1 -0
  84. package/src/commands/index.ts +3 -0
  85. package/src/commands/price_list.ts +7 -2
  86. package/src/commands/price_list_disabled.ts +194 -0
  87. package/src/test/commands/basic.ts +7 -0
  88. package/src/test/commands/price_list_disabled.ts +362 -0
  89. package/src/types.ts +1 -0
  90. package/src/util.ts +18 -1
@@ -1,131 +1,210 @@
1
1
  import Repzo from "repzo";
2
- import { _create, update_bench_time, date_formatting, set_error, } from "../util.js";
2
+ import {
3
+ _create,
4
+ update_bench_time,
5
+ date_formatting,
6
+ set_error,
7
+ } from "../util.js";
3
8
  export const sync_payment_term = async (commandEvent) => {
4
- var _a, _b, _c, _d;
5
- const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
6
- env: commandEvent.env,
7
- });
8
- const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
9
- try {
10
- // console.log("sync_payment_term");
11
- const new_bench_time = new Date().toISOString();
12
- const bench_time_key = "bench_time_payment_term";
13
- await commandLog.load(commandEvent.sync_id);
14
- await commandLog
15
- .addDetail("Repzo SAP: Started Syncing Payments Term")
16
- .commit();
17
- const nameSpace = commandEvent.nameSpace.join("_");
18
- const result = {
19
- sap_total: 0,
20
- repzo_total: 0,
21
- created: 0,
22
- updated: 0,
23
- failed: 0,
24
- };
25
- const failed_docs_report = [];
26
- const sap_clients = await get_sap_clients(commandEvent.app.formData.sapHostUrl, {
27
- updateAt: commandEvent.app.options_formData[bench_time_key],
28
- GroupCode: commandEvent.app.formData.GroupCode,
29
- });
30
- const sap_unique_payment_terms = {};
31
- sap_clients === null || sap_clients === void 0 ? void 0 : sap_clients.forEach((client) => {
32
- const paymentTerm = client.PAYMENTTERM;
33
- sap_unique_payment_terms[paymentTerm] = true;
34
- });
35
- const sap_payment_terms = Object.keys(sap_unique_payment_terms);
36
- result.sap_total = sap_payment_terms === null || sap_payment_terms === void 0 ? void 0 : sap_payment_terms.length;
37
- await commandLog
38
- .addDetail(`${result.sap_total} Payments Term in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
39
- .commit();
40
- const repzo_payment_terms = await repzo.paymentTerm.find({
41
- per_page: 50000,
9
+ var _a, _b, _c, _d;
10
+ const repzo = new Repzo(
11
+ (_a = commandEvent.app.formData) === null || _a === void 0
12
+ ? void 0
13
+ : _a.repzoApiKey,
14
+ {
15
+ env: commandEvent.env,
16
+ }
17
+ );
18
+ const commandLog = new Repzo.CommandLog(
19
+ repzo,
20
+ commandEvent.app,
21
+ commandEvent.command
22
+ );
23
+ try {
24
+ // console.log("sync_payment_term");
25
+ const new_bench_time = new Date().toISOString();
26
+ const bench_time_key = "bench_time_payment_term";
27
+ await commandLog.load(commandEvent.sync_id);
28
+ await commandLog
29
+ .addDetail("Repzo SAP: Started Syncing Payments Term")
30
+ .commit();
31
+ const nameSpace = commandEvent.nameSpace.join("_");
32
+ const result = {
33
+ sap_total: 0,
34
+ repzo_total: 0,
35
+ created: 0,
36
+ updated: 0,
37
+ failed: 0,
38
+ };
39
+ const failed_docs_report = [];
40
+ const sap_clients = await get_sap_clients(
41
+ commandEvent.app.formData.sapHostUrl,
42
+ {
43
+ updateAt: commandEvent.app.options_formData[bench_time_key],
44
+ GroupCode: commandEvent.app.formData.GroupCode,
45
+ }
46
+ );
47
+ const sap_unique_payment_terms = {};
48
+ sap_clients === null || sap_clients === void 0
49
+ ? void 0
50
+ : sap_clients.forEach((client) => {
51
+ const paymentTerm = client.PAYMENTTERM;
52
+ sap_unique_payment_terms[paymentTerm] = true;
42
53
  });
43
- result.repzo_total = (_b = repzo_payment_terms === null || repzo_payment_terms === void 0 ? void 0 : repzo_payment_terms.data) === null || _b === void 0 ? void 0 : _b.length;
44
- await commandLog
45
- .addDetail(`${(_c = repzo_payment_terms === null || repzo_payment_terms === void 0 ? void 0 : repzo_payment_terms.data) === null || _c === void 0 ? void 0 : _c.length} Payments Term in Repzo`)
46
- .commit();
47
- for (let i = 0; i < (sap_payment_terms === null || sap_payment_terms === void 0 ? void 0 : sap_payment_terms.length); i++) {
48
- const sap_payment_term = sap_payment_terms[i];
49
- const repzo_payment_term = repzo_payment_terms.data.find((r_payment_term) => {
50
- var _a;
51
- return ((_a = r_payment_term.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
52
- `${nameSpace}_${sap_payment_term}`;
53
- });
54
- const body = {
55
- name: sap_payment_term.toString(),
56
- due_days: Number(sap_payment_term),
57
- integration_meta: {
58
- id: `${nameSpace}_${sap_payment_term}`,
59
- },
60
- company_namespace: [nameSpace],
61
- };
62
- if (!repzo_payment_term) {
63
- // Create
64
- try {
65
- const created_payment_term = await repzo.paymentTerm.create(body);
66
- result.created++;
67
- }
68
- catch (e) {
69
- // console.log("Create Payment Term Failed >> ", e?.response, body);
70
- failed_docs_report.push({
71
- method: "create",
72
- doc: body,
73
- error_message: set_error(e),
74
- });
75
- result.failed++;
76
- }
77
- }
78
- else {
79
- if ((repzo_payment_term === null || repzo_payment_term === void 0 ? void 0 : repzo_payment_term.name) == (body === null || body === void 0 ? void 0 : body.name) &&
80
- (repzo_payment_term === null || repzo_payment_term === void 0 ? void 0 : repzo_payment_term.due_days) == (body === null || body === void 0 ? void 0 : body.due_days))
81
- continue;
82
- // Update
83
- try {
84
- const updated_payment_term = await repzo.paymentTerm.update(repzo_payment_term._id, body);
85
- result.updated++;
86
- }
87
- catch (e) {
88
- // console.log(
89
- // "Update Payment Term Failed >> ",
90
- // e?.response?.data,
91
- // body
92
- // );
93
- failed_docs_report.push({
94
- method: "update",
95
- doc_id: repzo_payment_term === null || repzo_payment_term === void 0 ? void 0 : repzo_payment_term._id,
96
- doc: body,
97
- error_message: set_error(e),
98
- });
99
- result.failed++;
100
- }
101
- }
54
+ const sap_payment_terms = Object.keys(sap_unique_payment_terms);
55
+ result.sap_total =
56
+ sap_payment_terms === null || sap_payment_terms === void 0
57
+ ? void 0
58
+ : sap_payment_terms.length;
59
+ await commandLog
60
+ .addDetail(
61
+ `${result.sap_total} Payments Term in SAP changed since ${
62
+ commandEvent.app.options_formData[bench_time_key] || "ever"
63
+ }`
64
+ )
65
+ .commit();
66
+ const repzo_payment_terms = await repzo.paymentTerm.find({
67
+ per_page: 50000,
68
+ });
69
+ result.repzo_total =
70
+ (_b =
71
+ repzo_payment_terms === null || repzo_payment_terms === void 0
72
+ ? void 0
73
+ : repzo_payment_terms.data) === null || _b === void 0
74
+ ? void 0
75
+ : _b.length;
76
+ await commandLog
77
+ .addDetail(
78
+ `${
79
+ (_c =
80
+ repzo_payment_terms === null || repzo_payment_terms === void 0
81
+ ? void 0
82
+ : repzo_payment_terms.data) === null || _c === void 0
83
+ ? void 0
84
+ : _c.length
85
+ } Payments Term in Repzo`
86
+ )
87
+ .commit();
88
+ for (
89
+ let i = 0;
90
+ i <
91
+ (sap_payment_terms === null || sap_payment_terms === void 0
92
+ ? void 0
93
+ : sap_payment_terms.length);
94
+ i++
95
+ ) {
96
+ const sap_payment_term = sap_payment_terms[i];
97
+ const repzo_payment_term = repzo_payment_terms.data.find(
98
+ (r_payment_term) => {
99
+ var _a;
100
+ return (
101
+ ((_a = r_payment_term.integration_meta) === null || _a === void 0
102
+ ? void 0
103
+ : _a.id) == `${nameSpace}_${sap_payment_term}`
104
+ );
102
105
  }
103
- // console.log(result);
104
- await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
105
- await commandLog
106
- .setStatus("success", failed_docs_report.length ? failed_docs_report : null)
107
- .setBody(result)
108
- .commit();
109
- return result;
110
- }
111
- catch (e) {
112
- //@ts-ignore
113
- console.error(((_d = e === null || e === void 0 ? void 0 : e.response) === null || _d === void 0 ? void 0 : _d.data) || e);
114
- await commandLog.setStatus("fail", e).commit();
115
- throw e;
106
+ );
107
+ const body = {
108
+ name: sap_payment_term.toString(),
109
+ due_days: Number(sap_payment_term),
110
+ integration_meta: {
111
+ id: `${nameSpace}_${sap_payment_term}`,
112
+ },
113
+ company_namespace: [nameSpace],
114
+ };
115
+ if (!repzo_payment_term) {
116
+ // Create
117
+ try {
118
+ const created_payment_term = await repzo.paymentTerm.create(body);
119
+ result.created++;
120
+ } catch (e) {
121
+ // console.log("Create Payment Term Failed >> ", e?.response, body);
122
+ failed_docs_report.push({
123
+ method: "create",
124
+ doc: body,
125
+ error_message: set_error(e),
126
+ });
127
+ result.failed++;
128
+ }
129
+ } else {
130
+ if (
131
+ (repzo_payment_term === null || repzo_payment_term === void 0
132
+ ? void 0
133
+ : repzo_payment_term.name) ==
134
+ (body === null || body === void 0 ? void 0 : body.name) &&
135
+ (repzo_payment_term === null || repzo_payment_term === void 0
136
+ ? void 0
137
+ : repzo_payment_term.due_days) ==
138
+ (body === null || body === void 0 ? void 0 : body.due_days)
139
+ )
140
+ continue;
141
+ // Update
142
+ try {
143
+ const updated_payment_term = await repzo.paymentTerm.update(
144
+ repzo_payment_term._id,
145
+ body
146
+ );
147
+ result.updated++;
148
+ } catch (e) {
149
+ // console.log(
150
+ // "Update Payment Term Failed >> ",
151
+ // e?.response?.data,
152
+ // body
153
+ // );
154
+ failed_docs_report.push({
155
+ method: "update",
156
+ doc_id:
157
+ repzo_payment_term === null || repzo_payment_term === void 0
158
+ ? void 0
159
+ : repzo_payment_term._id,
160
+ doc: body,
161
+ error_message: set_error(e),
162
+ });
163
+ result.failed++;
164
+ }
165
+ }
116
166
  }
167
+ // console.log(result);
168
+ await update_bench_time(
169
+ repzo,
170
+ commandEvent.app._id,
171
+ bench_time_key,
172
+ new_bench_time
173
+ );
174
+ await commandLog
175
+ .setStatus(
176
+ "success",
177
+ failed_docs_report.length ? failed_docs_report : null
178
+ )
179
+ .setBody(result)
180
+ .commit();
181
+ return result;
182
+ } catch (e) {
183
+ //@ts-ignore
184
+ console.error(
185
+ ((_d = e === null || e === void 0 ? void 0 : e.response) === null ||
186
+ _d === void 0
187
+ ? void 0
188
+ : _d.data) || e
189
+ );
190
+ await commandLog.setStatus("fail", e).commit();
191
+ throw e;
192
+ }
117
193
  };
118
194
  const get_sap_clients = async (serviceEndPoint, query) => {
119
- try {
120
- const sap_clients = await _create(serviceEndPoint, "/Customers", {
121
- Active: "Y",
122
- Frozen: "N",
123
- UpdateAt: date_formatting(query === null || query === void 0 ? void 0 : query.updateAt, "YYYYMMDD:HHmmss"),
124
- GroupCode: (query === null || query === void 0 ? void 0 : query.GroupCode) || "",
125
- });
126
- return sap_clients.Customers;
127
- }
128
- catch (e) {
129
- throw e;
130
- }
195
+ try {
196
+ const sap_clients = await _create(serviceEndPoint, "/Customers", {
197
+ Active: "Y",
198
+ Frozen: "N",
199
+ UpdateAt: date_formatting(
200
+ query === null || query === void 0 ? void 0 : query.updateAt,
201
+ "YYYYMMDD:HHmmss"
202
+ ),
203
+ GroupCode:
204
+ (query === null || query === void 0 ? void 0 : query.GroupCode) || "",
205
+ });
206
+ return sap_clients.Customers;
207
+ } catch (e) {
208
+ throw e;
209
+ }
131
210
  };
@@ -1,18 +1,18 @@
1
1
  import { CommandEvent } from "../types";
2
2
  export declare const sync_price_list: (commandEvent: CommandEvent) => Promise<{
3
- PL: {
4
- created: number;
5
- updated: number;
6
- failed: number;
7
- };
8
- PL_items: {
9
- created: number;
10
- updated: number;
11
- failed: number;
12
- };
13
- sap_total: number;
14
- repzo_total: number;
15
- repzo_PL_items: number;
16
- sap_UoMs_total: number;
17
- repzo_products_total: number;
3
+ PL: {
4
+ created: number;
5
+ updated: number;
6
+ failed: number;
7
+ };
8
+ PL_items: {
9
+ created: number;
10
+ updated: number;
11
+ failed: number;
12
+ };
13
+ sap_total: number;
14
+ repzo_total: number;
15
+ repzo_PL_items: number;
16
+ sap_UoMs_total: number;
17
+ repzo_products_total: number;
18
18
  }>;