repzo-sap-absjo 1.0.7 → 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 (78) hide show
  1. package/changelog.md +1 -0
  2. package/lib/actions/create_invoice.d.ts +13 -19
  3. package/lib/actions/create_invoice.js +214 -371
  4. package/lib/actions/create_payment.d.ts +1 -4
  5. package/lib/actions/create_payment.js +125 -208
  6. package/lib/actions/create_proforma.d.ts +1 -4
  7. package/lib/actions/create_proforma.js +165 -305
  8. package/lib/actions/create_return_invoice.d.ts +1 -4
  9. package/lib/actions/create_return_invoice.js +177 -332
  10. package/lib/actions/create_transfer.d.ts +1 -4
  11. package/lib/actions/create_transfer.js +142 -234
  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 +326 -612
  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 +334 -337
  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 +2 -1
  75. package/src/actions/create_payment.ts +2 -1
  76. package/src/actions/create_proforma.ts +2 -1
  77. package/src/actions/create_return_invoice.ts +2 -1
  78. package/src/actions/create_transfer.ts +2 -1
@@ -1,303 +1,173 @@
1
1
  import Repzo from "repzo";
2
2
  import { v4 as uuid } from "uuid";
3
- import { _create, set_error } from "../util.js";
3
+ import { _create, set_error, } from "../util.js";
4
4
  export const adjust_inventory = async (commandEvent) => {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
6
- const repzo = new Repzo(
7
- (_a = commandEvent.app.formData) === null || _a === void 0
8
- ? void 0
9
- : _a.repzoApiKey,
10
- {
11
- env: commandEvent.env,
12
- }
13
- );
14
- const commandLog = new Repzo.CommandLog(
15
- repzo,
16
- commandEvent.app,
17
- commandEvent.command
18
- );
19
- try {
20
- // console.log("adjust_inventory");
21
- await commandLog.load(commandEvent.sync_id);
22
- await commandLog
23
- .addDetail("Repzo SAP: Started Adjusting Inventories")
24
- .commit();
25
- const nameSpace = commandEvent.nameSpace.join("_");
26
- const result = {
27
- sap_total: 0,
28
- repzo_total: 0,
29
- items_failed: 0,
30
- created: 0,
31
- updated: 0,
32
- failed: 0,
33
- };
34
- const failed_docs_report = [];
35
- const sap_inventories_items = await get_sap_inventories(
36
- commandEvent.app.formData.sapHostUrl,
37
- {}
38
- );
39
- result.sap_total =
40
- sap_inventories_items === null || sap_inventories_items === void 0
41
- ? void 0
42
- : sap_inventories_items.length;
43
- await commandLog
44
- .addDetail(`${result.sap_total} Stores Balance in SAP`)
45
- .commit();
46
- // Get Repzo Variants
47
- const repzo_variants = await repzo.variant.find({
48
- per_page: 50000,
49
- disabled: false,
50
- withProduct: true,
51
- });
52
- await commandLog
53
- .addDetail(
54
- `${
55
- (_b =
56
- repzo_variants === null || repzo_variants === void 0
57
- ? void 0
58
- : repzo_variants.data) === null || _b === void 0
59
- ? void 0
60
- : _b.length
61
- } Variant(s) in Repzo`
62
- )
63
- .commit();
64
- // Get Repzo Warehouses
65
- const repzo_warehouses = await repzo.warehouse.find({
66
- per_page: 50000,
67
- disabled: false,
68
- });
69
- await commandLog
70
- .addDetail(
71
- `${
72
- (_c =
73
- repzo_warehouses === null || repzo_warehouses === void 0
74
- ? void 0
75
- : repzo_warehouses.data) === null || _c === void 0
76
- ? void 0
77
- : _c.length
78
- } Warehouse(s) in Repzo`
79
- )
80
- .commit();
81
- // Get Repzo Measure Units
82
- const repzo_measureunits = await repzo.measureunit.find({
83
- per_page: 50000,
84
- disabled: false,
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
6
+ const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
7
+ env: commandEvent.env,
85
8
  });
86
- await commandLog
87
- .addDetail(
88
- `${
89
- (_d =
90
- repzo_measureunits === null || repzo_measureunits === void 0
91
- ? void 0
92
- : repzo_measureunits.data) === null || _d === void 0
93
- ? void 0
94
- : _d.length
95
- } Measure Unit(s) in Repzo`
96
- )
97
- .commit();
98
- const repzo_tags = await repzo.tag.find({ type: "area", per_page: 50000 });
99
- result.repzo_total =
100
- (_e =
101
- repzo_tags === null || repzo_tags === void 0
102
- ? void 0
103
- : repzo_tags.data) === null || _e === void 0
104
- ? void 0
105
- : _e.length;
106
- await commandLog
107
- .addDetail(
108
- `${
109
- (_f =
110
- repzo_tags === null || repzo_tags === void 0
111
- ? void 0
112
- : repzo_tags.data) === null || _f === void 0
113
- ? void 0
114
- : _f.length
115
- } Area Tags in Repzo`
116
- )
117
- .commit();
118
- const sap_stores = {};
119
- sap_inventories_items.forEach((item) => {
120
- if (!sap_stores[item.STOREID])
121
- sap_stores[item.STOREID] = { STOREID: item.STOREID, items: [] };
122
- sap_stores[item.STOREID].items.push(item);
123
- });
124
- const sap_inventories = Object.values(sap_stores);
125
- for (let i = 0; i < sap_inventories.length; i++) {
126
- try {
127
- const sap_inventory = sap_inventories[i];
128
- const repzo_warehouse =
129
- (_g =
130
- repzo_warehouses === null || repzo_warehouses === void 0
131
- ? void 0
132
- : repzo_warehouses.data) === null || _g === void 0
133
- ? void 0
134
- : _g.find((wh) => wh.code == sap_inventory.STOREID);
135
- if (!repzo_warehouse) {
136
- throw `Warehouse with code: ${sap_inventory.STOREID} was not found in Repzo`;
137
- }
138
- // Get Repzo Inventory
139
- const repzo_inventory = await repzo.inventory.find({
140
- warehouse_id: repzo_warehouse._id,
141
- per_page: 50000,
9
+ const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
10
+ try {
11
+ // console.log("adjust_inventory");
12
+ await commandLog.load(commandEvent.sync_id);
13
+ await commandLog
14
+ .addDetail("Repzo SAP: Started Adjusting Inventories")
15
+ .commit();
16
+ const nameSpace = commandEvent.nameSpace.join("_");
17
+ const result = {
18
+ sap_total: 0,
19
+ repzo_total: 0,
20
+ items_failed: 0,
21
+ created: 0,
22
+ updated: 0,
23
+ failed: 0,
24
+ };
25
+ const failed_docs_report = [];
26
+ const sap_inventories_items = await get_sap_inventories(commandEvent.app.formData.sapHostUrl, {});
27
+ result.sap_total = sap_inventories_items === null || sap_inventories_items === void 0 ? void 0 : sap_inventories_items.length;
28
+ await commandLog
29
+ .addDetail(`${result.sap_total} Stores Balance in SAP`)
30
+ .commit();
31
+ // Get Repzo Variants
32
+ const repzo_variants = await repzo.variant.find({
33
+ per_page: 50000,
34
+ disabled: false,
35
+ withProduct: true,
142
36
  });
143
- const body = {
144
- time: Date.now(),
145
- sync_id: uuid(),
146
- to: repzo_warehouse._id,
147
- //@ts-ignore
148
- variants: sap_inventory.items
149
- .map((sap_item) => {
150
- var _a, _b, _c, _d;
151
- try {
152
- const variant =
153
- (_a =
154
- repzo_variants === null || repzo_variants === void 0
155
- ? void 0
156
- : repzo_variants.data) === null || _a === void 0
157
- ? void 0
158
- : _a.find((variant) => {
159
- var _a;
160
- return (
161
- ((_a = variant.integration_meta) === null ||
162
- _a === void 0
163
- ? void 0
164
- : _a.ITEMCODE) == sap_item.ITEMID
165
- );
166
- });
167
- if (!variant) {
168
- // console.log(
169
- // `Variant with ITEMCODE: ${sap_item.ITEMID} was not found`
170
- // );
171
- throw `Variant with ITEMCODE: ${sap_item.ITEMID} was not found`;
172
- }
173
- const measureUnit =
174
- (_b =
175
- repzo_measureunits === null || repzo_measureunits === void 0
176
- ? void 0
177
- : repzo_measureunits.data) === null || _b === void 0
178
- ? void 0
179
- : _b.find((measure_unit) => {
180
- var _a, _b;
181
- return (
182
- measure_unit._id.toString() ==
183
- ((_b =
184
- (_a = variant.product) === null || _a === void 0
185
- ? void 0
186
- : _a.sv_measureUnit) === null || _b === void 0
187
- ? void 0
188
- : _b.toString())
189
- );
190
- });
191
- if (!measureUnit) {
192
- // console.log(
193
- // `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`
194
- // );
195
- throw `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`;
196
- }
197
- const qty = measureUnit.factor * sap_item.QTY;
198
- const match_item_in_repzo_inventory =
199
- (_c =
200
- repzo_inventory === null || repzo_inventory === void 0
201
- ? void 0
202
- : repzo_inventory.data) === null || _c === void 0
203
- ? void 0
204
- : _c.find(
205
- (repzo_item) =>
206
- repzo_item.variant_id.toString() ==
207
- variant._id.toString()
208
- );
209
- if (match_item_in_repzo_inventory) {
210
- //@ts-ignore
211
- match_item_in_repzo_inventory.has_match_in_SAP = true;
37
+ await commandLog
38
+ .addDetail(`${(_b = repzo_variants === null || repzo_variants === void 0 ? void 0 : repzo_variants.data) === null || _b === void 0 ? void 0 : _b.length} Variant(s) in Repzo`)
39
+ .commit();
40
+ // Get Repzo Warehouses
41
+ const repzo_warehouses = await repzo.warehouse.find({
42
+ per_page: 50000,
43
+ disabled: false,
44
+ });
45
+ await commandLog
46
+ .addDetail(`${(_c = repzo_warehouses === null || repzo_warehouses === void 0 ? void 0 : repzo_warehouses.data) === null || _c === void 0 ? void 0 : _c.length} Warehouse(s) in Repzo`)
47
+ .commit();
48
+ // Get Repzo Measure Units
49
+ const repzo_measureunits = await repzo.measureunit.find({
50
+ per_page: 50000,
51
+ disabled: false,
52
+ });
53
+ await commandLog
54
+ .addDetail(`${(_d = repzo_measureunits === null || repzo_measureunits === void 0 ? void 0 : repzo_measureunits.data) === null || _d === void 0 ? void 0 : _d.length} Measure Unit(s) in Repzo`)
55
+ .commit();
56
+ const repzo_tags = await repzo.tag.find({ type: "area", per_page: 50000 });
57
+ result.repzo_total = (_e = repzo_tags === null || repzo_tags === void 0 ? void 0 : repzo_tags.data) === null || _e === void 0 ? void 0 : _e.length;
58
+ await commandLog
59
+ .addDetail(`${(_f = repzo_tags === null || repzo_tags === void 0 ? void 0 : repzo_tags.data) === null || _f === void 0 ? void 0 : _f.length} Area Tags in Repzo`)
60
+ .commit();
61
+ const sap_stores = {};
62
+ sap_inventories_items.forEach((item) => {
63
+ if (!sap_stores[item.STOREID])
64
+ sap_stores[item.STOREID] = { STOREID: item.STOREID, items: [] };
65
+ sap_stores[item.STOREID].items.push(item);
66
+ });
67
+ const sap_inventories = Object.values(sap_stores);
68
+ for (let i = 0; i < sap_inventories.length; i++) {
69
+ try {
70
+ const sap_inventory = sap_inventories[i];
71
+ const repzo_warehouse = (_g = repzo_warehouses === null || repzo_warehouses === void 0 ? void 0 : repzo_warehouses.data) === null || _g === void 0 ? void 0 : _g.find((wh) => wh.code == sap_inventory.STOREID);
72
+ if (!repzo_warehouse) {
73
+ throw `Warehouse with code: ${sap_inventory.STOREID} was not found in Repzo`;
212
74
  }
213
- const diff_qty = match_item_in_repzo_inventory
214
- ? qty - match_item_in_repzo_inventory.qty
215
- : qty;
216
- return { variant: variant._id, qty: diff_qty };
217
- } catch (e) {
75
+ // Get Repzo Inventory
76
+ const repzo_inventory = await repzo.inventory.find({
77
+ warehouse_id: repzo_warehouse._id,
78
+ per_page: 50000,
79
+ });
80
+ const body = {
81
+ time: Date.now(),
82
+ sync_id: uuid(),
83
+ to: repzo_warehouse._id,
84
+ //@ts-ignore
85
+ variants: sap_inventory.items
86
+ .map((sap_item) => {
87
+ var _a, _b, _c, _d;
88
+ try {
89
+ const variant = (_a = repzo_variants === null || repzo_variants === void 0 ? void 0 : repzo_variants.data) === null || _a === void 0 ? void 0 : _a.find((variant) => { var _a; return ((_a = variant.integration_meta) === null || _a === void 0 ? void 0 : _a.ITEMCODE) == sap_item.ITEMID; });
90
+ if (!variant) {
91
+ // console.log(
92
+ // `Variant with ITEMCODE: ${sap_item.ITEMID} was not found`
93
+ // );
94
+ throw `Variant with ITEMCODE: ${sap_item.ITEMID} was not found`;
95
+ }
96
+ const measureUnit = (_b = repzo_measureunits === null || repzo_measureunits === void 0 ? void 0 : repzo_measureunits.data) === null || _b === void 0 ? void 0 : _b.find((measure_unit) => {
97
+ var _a, _b;
98
+ return measure_unit._id.toString() ==
99
+ ((_b = (_a = variant.product) === null || _a === void 0 ? void 0 : _a.sv_measureUnit) === null || _b === void 0 ? void 0 : _b.toString());
100
+ });
101
+ if (!measureUnit) {
102
+ // console.log(
103
+ // `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`
104
+ // );
105
+ throw `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`;
106
+ }
107
+ const qty = measureUnit.factor * sap_item.QTY;
108
+ const match_item_in_repzo_inventory = (_c = repzo_inventory === null || repzo_inventory === void 0 ? void 0 : repzo_inventory.data) === null || _c === void 0 ? void 0 : _c.find((repzo_item) => repzo_item.variant_id.toString() == variant._id.toString());
109
+ if (match_item_in_repzo_inventory) {
110
+ //@ts-ignore
111
+ match_item_in_repzo_inventory.has_match_in_SAP = true;
112
+ }
113
+ const diff_qty = match_item_in_repzo_inventory
114
+ ? qty - match_item_in_repzo_inventory.qty
115
+ : qty;
116
+ return { variant: variant._id, qty: diff_qty };
117
+ }
118
+ catch (e) {
119
+ // console.log(e);
120
+ failed_docs_report.push({
121
+ method: "fetchingData",
122
+ doc_id: sap_item.UNITNAME,
123
+ doc: { ...sap_item, STOREID: (_d = sap_inventories[i]) === null || _d === void 0 ? void 0 : _d.STOREID },
124
+ error_message: set_error(e),
125
+ });
126
+ result.items_failed++;
127
+ }
128
+ })
129
+ .concat(...(_h = repzo_inventory === null || repzo_inventory === void 0 ? void 0 : repzo_inventory.data) === null || _h === void 0 ? void 0 : _h.filter((item) => !item.has_match_in_SAP).map((item) => {
130
+ return { variant: item.variant_id, qty: -1 * item.qty };
131
+ }))
132
+ .filter((item) => item && item.qty),
133
+ };
134
+ // console.log(body);
135
+ if (!body.variants.length)
136
+ continue;
137
+ const res = await repzo.adjustInventory.create(body);
138
+ result.created++;
139
+ }
140
+ catch (e) {
218
141
  // console.log(e);
219
142
  failed_docs_report.push({
220
- method: "fetchingData",
221
- doc_id: sap_item.UNITNAME,
222
- doc: {
223
- ...sap_item,
224
- STOREID:
225
- (_d = sap_inventories[i]) === null || _d === void 0
226
- ? void 0
227
- : _d.STOREID,
228
- },
229
- error_message: set_error(e),
143
+ method: "fetchingData",
144
+ doc_id: (_j = sap_inventories[i]) === null || _j === void 0 ? void 0 : _j.STOREID,
145
+ doc: { STOREID: (_k = sap_inventories[i]) === null || _k === void 0 ? void 0 : _k.STOREID },
146
+ error_message: set_error(e),
230
147
  });
231
- result.items_failed++;
232
- }
233
- })
234
- .concat(
235
- ...((_h =
236
- repzo_inventory === null || repzo_inventory === void 0
237
- ? void 0
238
- : repzo_inventory.data) === null || _h === void 0
239
- ? void 0
240
- : _h
241
- .filter((item) => !item.has_match_in_SAP)
242
- .map((item) => {
243
- return { variant: item.variant_id, qty: -1 * item.qty };
244
- }))
245
- )
246
- .filter((item) => item && item.qty),
247
- };
248
- // console.log(body);
249
- if (!body.variants.length) continue;
250
- const res = await repzo.adjustInventory.create(body);
251
- result.created++;
252
- } catch (e) {
253
- // console.log(e);
254
- failed_docs_report.push({
255
- method: "fetchingData",
256
- doc_id:
257
- (_j = sap_inventories[i]) === null || _j === void 0
258
- ? void 0
259
- : _j.STOREID,
260
- doc: {
261
- STOREID:
262
- (_k = sap_inventories[i]) === null || _k === void 0
263
- ? void 0
264
- : _k.STOREID,
265
- },
266
- error_message: set_error(e),
267
- });
268
- result.failed++;
269
- }
148
+ result.failed++;
149
+ }
150
+ }
151
+ // console.log(result);
152
+ await commandLog
153
+ .setStatus("success", failed_docs_report.length ? failed_docs_report : null)
154
+ .setBody(result)
155
+ .commit();
156
+ return result;
157
+ }
158
+ catch (e) {
159
+ //@ts-ignore
160
+ console.error(((_l = e === null || e === void 0 ? void 0 : e.response) === null || _l === void 0 ? void 0 : _l.data) || e);
161
+ await commandLog.setStatus("fail", e).commit();
162
+ throw e;
270
163
  }
271
- // console.log(result);
272
- await commandLog
273
- .setStatus(
274
- "success",
275
- failed_docs_report.length ? failed_docs_report : null
276
- )
277
- .setBody(result)
278
- .commit();
279
- return result;
280
- } catch (e) {
281
- //@ts-ignore
282
- console.error(
283
- ((_l = e === null || e === void 0 ? void 0 : e.response) === null ||
284
- _l === void 0
285
- ? void 0
286
- : _l.data) || e
287
- );
288
- await commandLog.setStatus("fail", e).commit();
289
- throw e;
290
- }
291
164
  };
292
165
  const get_sap_inventories = async (serviceEndPoint, query) => {
293
- try {
294
- const sap_inventories = await _create(
295
- serviceEndPoint,
296
- "/StoresBalance",
297
- {}
298
- );
299
- return sap_inventories.StoresBalance;
300
- } catch (e) {
301
- throw e;
302
- }
166
+ try {
167
+ const sap_inventories = await _create(serviceEndPoint, "/StoresBalance", {});
168
+ return sap_inventories.StoresBalance;
169
+ }
170
+ catch (e) {
171
+ throw e;
172
+ }
303
173
  };
@@ -1,7 +1,5 @@
1
1
  import { CommandEvent, Result } from "../types";
2
- export declare const sync_bank: (commandEvent: CommandEvent) => Promise<
3
- Result & {
2
+ export declare const sync_bank: (commandEvent: CommandEvent) => Promise<Result & {
4
3
  repzo_bank_list_total: number;
5
4
  repzo_bank_list_updated: boolean;
6
- }
7
- >;
5
+ }>;