repzo-sap-absjo 1.0.6 → 1.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.
Files changed (80) hide show
  1. package/changelog.md +4 -0
  2. package/lib/actions/create_invoice.d.ts +13 -19
  3. package/lib/actions/create_invoice.js +216 -336
  4. package/lib/actions/create_payment.d.ts +1 -4
  5. package/lib/actions/create_payment.js +125 -171
  6. package/lib/actions/create_proforma.d.ts +1 -4
  7. package/lib/actions/create_proforma.js +165 -268
  8. package/lib/actions/create_return_invoice.d.ts +1 -4
  9. package/lib/actions/create_return_invoice.js +177 -295
  10. package/lib/actions/create_transfer.d.ts +1 -4
  11. package/lib/actions/create_transfer.js +143 -198
  12. package/lib/actions/index.js +15 -23
  13. package/lib/commands/adjust_inventory.d.ts +2 -4
  14. package/lib/commands/adjust_inventory.js +160 -290
  15. package/lib/commands/bank.d.ts +2 -4
  16. package/lib/commands/bank.js +157 -279
  17. package/lib/commands/basic.js +47 -66
  18. package/lib/commands/category.d.ts +1 -3
  19. package/lib/commands/category.js +104 -178
  20. package/lib/commands/channel.d.ts +1 -3
  21. package/lib/commands/channel.js +117 -198
  22. package/lib/commands/client.d.ts +32 -34
  23. package/lib/commands/client.js +244 -404
  24. package/lib/commands/client_disabled.d.ts +1 -3
  25. package/lib/commands/client_disabled.js +94 -163
  26. package/lib/commands/index.d.ts +11 -15
  27. package/lib/commands/index.js +60 -60
  28. package/lib/commands/join.js +66 -192
  29. package/lib/commands/measureunit.d.ts +14 -19
  30. package/lib/commands/measureunit.js +191 -289
  31. package/lib/commands/measureunit_family.d.ts +8 -10
  32. package/lib/commands/measureunit_family.js +138 -250
  33. package/lib/commands/payment_term.d.ts +1 -3
  34. package/lib/commands/payment_term.js +123 -202
  35. package/lib/commands/price_list.d.ts +15 -15
  36. package/lib/commands/price_list.js +327 -571
  37. package/lib/commands/product.d.ts +30 -32
  38. package/lib/commands/product.js +243 -425
  39. package/lib/commands/product_disabled.d.ts +1 -3
  40. package/lib/commands/product_disabled.js +94 -164
  41. package/lib/commands/rep.js +141 -221
  42. package/lib/commands/tag.js +109 -174
  43. package/lib/commands/tax.js +112 -177
  44. package/lib/commands/warehouse.d.ts +1 -3
  45. package/lib/commands/warehouse.js +119 -207
  46. package/lib/index.d.ts +12 -21
  47. package/lib/test/actions/create_invoice.js +188 -193
  48. package/lib/test/actions/create_payment.js +107 -112
  49. package/lib/test/actions/create_proforma.js +216 -220
  50. package/lib/test/actions/create_return_invoice.js +200 -205
  51. package/lib/test/actions/create_transfer.js +115 -120
  52. package/lib/test/commands/adjust_inventory.js +90 -90
  53. package/lib/test/commands/bank.js +90 -90
  54. package/lib/test/commands/basic.js +327 -328
  55. package/lib/test/commands/category.js +90 -90
  56. package/lib/test/commands/channel.js +90 -90
  57. package/lib/test/commands/client.js +353 -355
  58. package/lib/test/commands/client_disabled.js +90 -90
  59. package/lib/test/commands/join.js +327 -328
  60. package/lib/test/commands/measureunit.js +90 -90
  61. package/lib/test/commands/measureunit_family.js +90 -90
  62. package/lib/test/commands/payment_term.js +90 -90
  63. package/lib/test/commands/price_list.js +337 -90
  64. package/lib/test/commands/product.js +90 -90
  65. package/lib/test/commands/product_disabled.js +90 -90
  66. package/lib/test/commands/rep.js +344 -346
  67. package/lib/test/commands/tag.js +90 -90
  68. package/lib/test/commands/tax.js +90 -90
  69. package/lib/test/commands/warehouse.js +90 -90
  70. package/lib/types.d.ts +60 -83
  71. package/lib/util.d.ts +19 -70
  72. package/lib/util.js +144 -170
  73. package/package.json +1 -1
  74. package/src/actions/create_invoice.ts +35 -0
  75. package/src/actions/create_payment.ts +35 -0
  76. package/src/actions/create_proforma.ts +35 -0
  77. package/src/actions/create_return_invoice.ts +35 -0
  78. package/src/actions/create_transfer.ts +34 -0
  79. package/src/commands/price_list.ts +40 -4
  80. package/src/test/commands/price_list.ts +263 -13
@@ -1,260 +1,148 @@
1
1
  import Repzo from "repzo";
2
2
  import _ from "lodash";
3
- import { update_bench_time, set_error } from "../util.js";
3
+ import { update_bench_time, set_error, } from "../util.js";
4
4
  import { get_sap_UoMs } from "./measureunit.js";
5
5
  export const sync_measureunit_family = async (commandEvent) => {
6
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
7
- const repzo = new Repzo(
8
- (_a = commandEvent.app.formData) === null || _a === void 0
9
- ? void 0
10
- : _a.repzoApiKey,
11
- {
12
- env: commandEvent.env,
13
- }
14
- );
15
- const commandLog = new Repzo.CommandLog(
16
- repzo,
17
- commandEvent.app,
18
- commandEvent.command
19
- );
20
- try {
21
- // console.log("sync_measureunit_family");
22
- const new_bench_time = new Date().toISOString();
23
- const bench_time_key = "bench_time_measureunit_family";
24
- await commandLog.load(commandEvent.sync_id);
25
- await commandLog
26
- .addDetail("Repzo SAP: Started Syncing Measure Units Family")
27
- .commit();
28
- const nameSpace = commandEvent.nameSpace.join("_");
29
- const result = {
30
- sap_total: 0,
31
- repzo_total: 0,
32
- sap_UoM_total: 0,
33
- repzo_UoM_total: 0,
34
- created: 0,
35
- updated: 0,
36
- failed: 0,
37
- };
38
- const failed_docs_report = [];
39
- const sap_UoMs = await get_sap_UoMs(
40
- commandEvent.app.formData.sapHostUrl,
41
- {}
42
- );
43
- result.sap_UoM_total =
44
- sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length;
45
- await commandLog
46
- .addDetail(`${result.sap_UoM_total} Unit of Measures in SAP`)
47
- .commit();
48
- let repzo_UoMs = await repzo.measureunit.find({
49
- disabled: false,
50
- per_page: 50000,
51
- });
52
- result.repzo_UoM_total =
53
- (_b =
54
- repzo_UoMs === null || repzo_UoMs === void 0
55
- ? void 0
56
- : repzo_UoMs.data) === null || _b === void 0
57
- ? void 0
58
- : _b.length;
59
- await commandLog
60
- .addDetail(
61
- `${
62
- (_c =
63
- repzo_UoMs === null || repzo_UoMs === void 0
64
- ? void 0
65
- : repzo_UoMs.data) === null || _c === void 0
66
- ? void 0
67
- : _c.length
68
- } Measure Units in Repzo`
69
- )
70
- .commit();
71
- if (
72
- !((_d =
73
- repzo_UoMs === null || repzo_UoMs === void 0
74
- ? void 0
75
- : repzo_UoMs.data) === null || _d === void 0
76
- ? void 0
77
- : _d.length)
78
- ) {
79
- throw "measure units are not found or the nameSpace has more than one";
80
- }
81
- repzo_UoMs.data =
82
- (_e = repzo_UoMs.data) === null || _e === void 0
83
- ? void 0
84
- : _e.filter((UoM) => UoM.integration_meta);
85
- const repzo_UoMs_family = await repzo.measureunitFamily.find({
86
- disabled: false,
87
- per_page: 50000,
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
7
+ const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
8
+ env: commandEvent.env,
88
9
  });
89
- result.repzo_total =
90
- (_f =
91
- repzo_UoMs_family === null || repzo_UoMs_family === void 0
92
- ? void 0
93
- : repzo_UoMs_family.data) === null || _f === void 0
94
- ? void 0
95
- : _f.length;
96
- await commandLog
97
- .addDetail(
98
- `${
99
- (_g =
100
- repzo_UoMs_family === null || repzo_UoMs_family === void 0
101
- ? void 0
102
- : repzo_UoMs_family.data) === null || _g === void 0
103
- ? void 0
104
- : _g.length
105
- } Measure Units Family in Repzo`
106
- )
107
- .commit();
108
- const sap_unique_family = {};
109
- for (
110
- let i = 0;
111
- i < (sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length);
112
- i++
113
- ) {
114
- const sap_UoM = sap_UoMs[i];
115
- const key = sap_UoM.ITEMCODE;
116
- if (!sap_unique_family[key]) sap_unique_family[key] = {};
117
- const uom_key = `${nameSpace}_${sap_UoM.UOMGROUPENTRY}_${sap_UoM.ALTUOMID}`;
118
- sap_unique_family[key][uom_key] = 1;
119
- }
120
- result.sap_total =
121
- (_h = Object.keys(sap_unique_family)) === null || _h === void 0
122
- ? void 0
123
- : _h.length;
124
- await commandLog
125
- .addDetail(`${result.sap_total} Measure Units Family in SAP`)
126
- .commit();
127
- for (let key in sap_unique_family) {
128
- const sap_family = sap_unique_family[key];
129
- const repzo_family = repzo_UoMs_family.data.find((r_family) => {
130
- var _a;
131
- return (
132
- ((_a = r_family.integration_meta) === null || _a === void 0
133
- ? void 0
134
- : _a.id) == `${nameSpace}_${key}`
135
- );
136
- });
137
- let measureunits = [];
138
- Object.keys(sap_family).forEach((unit) => {
139
- var _a;
140
- {
141
- const UoM =
142
- (_a =
143
- repzo_UoMs === null || repzo_UoMs === void 0
144
- ? void 0
145
- : repzo_UoMs.data) === null || _a === void 0
146
- ? void 0
147
- : _a.find((repzo_uom) => {
148
- var _a;
149
- return (
150
- ((_a =
151
- repzo_uom === null || repzo_uom === void 0
152
- ? void 0
153
- : repzo_uom.integration_meta) === null || _a === void 0
154
- ? void 0
155
- : _a.id) == unit
156
- );
157
- });
158
- if (UoM) {
159
- measureunits.push(UoM._id.toString());
160
- }
161
- }
162
- });
163
- const body = {
164
- name: key,
165
- disabled: false,
166
- integration_meta: { id: `${nameSpace}_${key}` },
167
- measureunits: measureunits || [],
168
- company_namespace: [nameSpace],
169
- };
170
- if (!repzo_family) {
171
- // Create
172
- try {
173
- const created_UoM = await repzo.measureunitFamily.create(body);
174
- result.created++;
175
- } catch (e) {
176
- // console.log(
177
- // "Create Measure Unit Family Failed >> ",
178
- // e?.response,
179
- // body
180
- // );
181
- failed_docs_report.push({
182
- method: "create",
183
- doc: body,
184
- error_message: set_error(e),
185
- });
186
- result.failed++;
10
+ const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
11
+ try {
12
+ // console.log("sync_measureunit_family");
13
+ const new_bench_time = new Date().toISOString();
14
+ const bench_time_key = "bench_time_measureunit_family";
15
+ await commandLog.load(commandEvent.sync_id);
16
+ await commandLog
17
+ .addDetail("Repzo SAP: Started Syncing Measure Units Family")
18
+ .commit();
19
+ const nameSpace = commandEvent.nameSpace.join("_");
20
+ const result = {
21
+ sap_total: 0,
22
+ repzo_total: 0,
23
+ sap_UoM_total: 0,
24
+ repzo_UoM_total: 0,
25
+ created: 0,
26
+ updated: 0,
27
+ failed: 0,
28
+ };
29
+ const failed_docs_report = [];
30
+ const sap_UoMs = await get_sap_UoMs(commandEvent.app.formData.sapHostUrl, {});
31
+ result.sap_UoM_total = sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length;
32
+ await commandLog
33
+ .addDetail(`${result.sap_UoM_total} Unit of Measures in SAP`)
34
+ .commit();
35
+ let repzo_UoMs = await repzo.measureunit.find({
36
+ disabled: false,
37
+ per_page: 50000,
38
+ });
39
+ result.repzo_UoM_total = (_b = repzo_UoMs === null || repzo_UoMs === void 0 ? void 0 : repzo_UoMs.data) === null || _b === void 0 ? void 0 : _b.length;
40
+ await commandLog
41
+ .addDetail(`${(_c = repzo_UoMs === null || repzo_UoMs === void 0 ? void 0 : repzo_UoMs.data) === null || _c === void 0 ? void 0 : _c.length} Measure Units in Repzo`)
42
+ .commit();
43
+ if (!((_d = repzo_UoMs === null || repzo_UoMs === void 0 ? void 0 : repzo_UoMs.data) === null || _d === void 0 ? void 0 : _d.length)) {
44
+ throw "measure units are not found or the nameSpace has more than one";
187
45
  }
188
- } else {
189
- if (
190
- repzo_family.name == body.name &&
191
- !((_k = _.xor(
192
- ((_j =
193
- repzo_family === null || repzo_family === void 0
194
- ? void 0
195
- : repzo_family.measureunits) === null || _j === void 0
196
- ? void 0
197
- : _j.map((m) =>
198
- m === null || m === void 0 ? void 0 : m.toString()
199
- )) || [],
200
- (body === null || body === void 0 ? void 0 : body.measureunits) ||
201
- []
202
- )) === null || _k === void 0
203
- ? void 0
204
- : _k.length)
205
- ) {
206
- continue;
46
+ repzo_UoMs.data = (_e = repzo_UoMs.data) === null || _e === void 0 ? void 0 : _e.filter((UoM) => UoM.integration_meta);
47
+ const repzo_UoMs_family = await repzo.measureunitFamily.find({
48
+ disabled: false,
49
+ per_page: 50000,
50
+ });
51
+ result.repzo_total = (_f = repzo_UoMs_family === null || repzo_UoMs_family === void 0 ? void 0 : repzo_UoMs_family.data) === null || _f === void 0 ? void 0 : _f.length;
52
+ await commandLog
53
+ .addDetail(`${(_g = repzo_UoMs_family === null || repzo_UoMs_family === void 0 ? void 0 : repzo_UoMs_family.data) === null || _g === void 0 ? void 0 : _g.length} Measure Units Family in Repzo`)
54
+ .commit();
55
+ const sap_unique_family = {};
56
+ for (let i = 0; i < (sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length); i++) {
57
+ const sap_UoM = sap_UoMs[i];
58
+ const key = sap_UoM.ITEMCODE;
59
+ if (!sap_unique_family[key])
60
+ sap_unique_family[key] = {};
61
+ const uom_key = `${nameSpace}_${sap_UoM.UOMGROUPENTRY}_${sap_UoM.ALTUOMID}`;
62
+ sap_unique_family[key][uom_key] = 1;
207
63
  }
208
- // Update
209
- try {
210
- const updated_UoM = await repzo.measureunitFamily.update(
211
- repzo_family._id,
212
- body
213
- );
214
- result.updated++;
215
- } catch (e) {
216
- // console.log(
217
- // "Update Measure Unit Family Failed >> ",
218
- // e?.response?.data,
219
- // body
220
- // );
221
- failed_docs_report.push({
222
- method: "update",
223
- doc_id:
224
- repzo_family === null || repzo_family === void 0
225
- ? void 0
226
- : repzo_family._id,
227
- doc: body,
228
- error_message: set_error(e),
229
- });
230
- result.failed++;
64
+ result.sap_total = (_h = Object.keys(sap_unique_family)) === null || _h === void 0 ? void 0 : _h.length;
65
+ await commandLog
66
+ .addDetail(`${result.sap_total} Measure Units Family in SAP`)
67
+ .commit();
68
+ for (let key in sap_unique_family) {
69
+ const sap_family = sap_unique_family[key];
70
+ const repzo_family = repzo_UoMs_family.data.find((r_family) => { var _a; return ((_a = r_family.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${key}`; });
71
+ let measureunits = [];
72
+ Object.keys(sap_family).forEach((unit) => {
73
+ var _a;
74
+ {
75
+ const UoM = (_a = repzo_UoMs === null || repzo_UoMs === void 0 ? void 0 : repzo_UoMs.data) === null || _a === void 0 ? void 0 : _a.find((repzo_uom) => { var _a; return ((_a = repzo_uom === null || repzo_uom === void 0 ? void 0 : repzo_uom.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == unit; });
76
+ if (UoM) {
77
+ measureunits.push(UoM._id.toString());
78
+ }
79
+ }
80
+ });
81
+ const body = {
82
+ name: key,
83
+ disabled: false,
84
+ integration_meta: { id: `${nameSpace}_${key}` },
85
+ measureunits: measureunits || [],
86
+ company_namespace: [nameSpace],
87
+ };
88
+ if (!repzo_family) {
89
+ // Create
90
+ try {
91
+ const created_UoM = await repzo.measureunitFamily.create(body);
92
+ result.created++;
93
+ }
94
+ catch (e) {
95
+ // console.log(
96
+ // "Create Measure Unit Family Failed >> ",
97
+ // e?.response,
98
+ // body
99
+ // );
100
+ failed_docs_report.push({
101
+ method: "create",
102
+ doc: body,
103
+ error_message: set_error(e),
104
+ });
105
+ result.failed++;
106
+ }
107
+ }
108
+ else {
109
+ if (repzo_family.name == body.name &&
110
+ !((_k = _.xor(((_j = repzo_family === null || repzo_family === void 0 ? void 0 : repzo_family.measureunits) === null || _j === void 0 ? void 0 : _j.map((m) => m === null || m === void 0 ? void 0 : m.toString())) || [], (body === null || body === void 0 ? void 0 : body.measureunits) || [])) === null || _k === void 0 ? void 0 : _k.length)) {
111
+ continue;
112
+ }
113
+ // Update
114
+ try {
115
+ const updated_UoM = await repzo.measureunitFamily.update(repzo_family._id, body);
116
+ result.updated++;
117
+ }
118
+ catch (e) {
119
+ // console.log(
120
+ // "Update Measure Unit Family Failed >> ",
121
+ // e?.response?.data,
122
+ // body
123
+ // );
124
+ failed_docs_report.push({
125
+ method: "update",
126
+ doc_id: repzo_family === null || repzo_family === void 0 ? void 0 : repzo_family._id,
127
+ doc: body,
128
+ error_message: set_error(e),
129
+ });
130
+ result.failed++;
131
+ }
132
+ }
231
133
  }
232
- }
134
+ // console.log(result);
135
+ await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
136
+ await commandLog
137
+ .setStatus("success", failed_docs_report.length ? failed_docs_report : null)
138
+ .setBody(result)
139
+ .commit();
140
+ return result;
141
+ }
142
+ catch (e) {
143
+ //@ts-ignore
144
+ console.error(((_l = e === null || e === void 0 ? void 0 : e.response) === null || _l === void 0 ? void 0 : _l.data) || e);
145
+ await commandLog.setStatus("fail", e).commit();
146
+ throw e;
233
147
  }
234
- // console.log(result);
235
- await update_bench_time(
236
- repzo,
237
- commandEvent.app._id,
238
- bench_time_key,
239
- new_bench_time
240
- );
241
- await commandLog
242
- .setStatus(
243
- "success",
244
- failed_docs_report.length ? failed_docs_report : null
245
- )
246
- .setBody(result)
247
- .commit();
248
- return result;
249
- } catch (e) {
250
- //@ts-ignore
251
- console.error(
252
- ((_l = e === null || e === void 0 ? void 0 : e.response) === null ||
253
- _l === void 0
254
- ? void 0
255
- : _l.data) || e
256
- );
257
- await commandLog.setStatus("fail", e).commit();
258
- throw e;
259
- }
260
148
  };
@@ -1,4 +1,2 @@
1
1
  import { CommandEvent, Result } from "../types";
2
- export declare const sync_payment_term: (
3
- commandEvent: CommandEvent
4
- ) => Promise<Result>;
2
+ export declare const sync_payment_term: (commandEvent: CommandEvent) => Promise<Result>;