repzo-sap-absjo 1.0.18 → 1.0.20

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 (75) hide show
  1. package/lib/actions/create_invoice.d.ts +13 -19
  2. package/lib/actions/create_invoice.js +207 -365
  3. package/lib/actions/create_payment.d.ts +1 -4
  4. package/lib/actions/create_payment.js +107 -195
  5. package/lib/actions/create_proforma.d.ts +1 -4
  6. package/lib/actions/create_proforma.js +146 -285
  7. package/lib/actions/create_return_invoice.d.ts +1 -4
  8. package/lib/actions/create_return_invoice.js +158 -312
  9. package/lib/actions/create_transfer.d.ts +1 -4
  10. package/lib/actions/create_transfer.js +126 -223
  11. package/lib/actions/index.js +15 -23
  12. package/lib/commands/adjust_inventory.d.ts +2 -4
  13. package/lib/commands/adjust_inventory.js +160 -290
  14. package/lib/commands/bank.d.ts +2 -4
  15. package/lib/commands/bank.js +157 -279
  16. package/lib/commands/basic.js +48 -67
  17. package/lib/commands/brand.d.ts +1 -3
  18. package/lib/commands/brand.js +100 -174
  19. package/lib/commands/category.d.ts +1 -3
  20. package/lib/commands/category.js +104 -178
  21. package/lib/commands/channel.d.ts +1 -3
  22. package/lib/commands/channel.js +117 -198
  23. package/lib/commands/client.d.ts +32 -34
  24. package/lib/commands/client.js +244 -404
  25. package/lib/commands/client_disabled.d.ts +1 -3
  26. package/lib/commands/client_disabled.js +94 -163
  27. package/lib/commands/index.d.ts +11 -15
  28. package/lib/commands/index.js +62 -62
  29. package/lib/commands/join.js +66 -192
  30. package/lib/commands/measureunit.d.ts +14 -19
  31. package/lib/commands/measureunit.js +191 -289
  32. package/lib/commands/measureunit_family.d.ts +8 -10
  33. package/lib/commands/measureunit_family.js +138 -250
  34. package/lib/commands/payment_term.d.ts +1 -3
  35. package/lib/commands/payment_term.js +123 -202
  36. package/lib/commands/price_list.d.ts +15 -15
  37. package/lib/commands/price_list.js +326 -612
  38. package/lib/commands/product.d.ts +30 -32
  39. package/lib/commands/product.js +263 -485
  40. package/lib/commands/product_disabled.d.ts +1 -3
  41. package/lib/commands/product_disabled.js +94 -160
  42. package/lib/commands/rep.js +141 -221
  43. package/lib/commands/tag.js +109 -174
  44. package/lib/commands/tax.js +112 -177
  45. package/lib/commands/warehouse.d.ts +1 -3
  46. package/lib/commands/warehouse.js +119 -207
  47. package/lib/index.d.ts +12 -21
  48. package/lib/test/actions/create_invoice.js +188 -193
  49. package/lib/test/actions/create_payment.js +107 -112
  50. package/lib/test/actions/create_proforma.js +216 -220
  51. package/lib/test/actions/create_return_invoice.js +200 -205
  52. package/lib/test/actions/create_transfer.js +115 -120
  53. package/lib/test/commands/adjust_inventory.js +90 -90
  54. package/lib/test/commands/bank.js +90 -90
  55. package/lib/test/commands/basic.js +327 -328
  56. package/lib/test/commands/brand.js +90 -90
  57. package/lib/test/commands/category.js +90 -90
  58. package/lib/test/commands/channel.js +90 -90
  59. package/lib/test/commands/client.js +353 -355
  60. package/lib/test/commands/client_disabled.js +90 -90
  61. package/lib/test/commands/join.js +327 -328
  62. package/lib/test/commands/measureunit.js +90 -90
  63. package/lib/test/commands/measureunit_family.js +90 -90
  64. package/lib/test/commands/payment_term.js +90 -90
  65. package/lib/test/commands/price_list.js +334 -337
  66. package/lib/test/commands/product.js +90 -90
  67. package/lib/test/commands/product_disabled.js +90 -90
  68. package/lib/test/commands/rep.js +344 -346
  69. package/lib/test/commands/tag.js +90 -90
  70. package/lib/test/commands/tax.js +90 -90
  71. package/lib/test/commands/warehouse.js +90 -90
  72. package/lib/types.d.ts +53 -77
  73. package/lib/util.d.ts +19 -70
  74. package/lib/util.js +144 -170
  75. package/package.json +1 -1
@@ -3,294 +3,155 @@ import { _create } from "../util.js";
3
3
  import { v4 as uuid } from "uuid";
4
4
  import moment from "moment-timezone";
5
5
  export const create_proforma = async (event, options) => {
6
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
7
- const repzo = new Repzo(
8
- (_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
9
- { env: options.env }
10
- );
11
- const action_sync_id =
12
- ((_b = event === null || event === void 0 ? void 0 : event.headers) ===
13
- null || _b === void 0
14
- ? void 0
15
- : _b.action_sync_id) || uuid();
16
- const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
17
- let body;
18
- try {
19
- // console.log("create_proforma");
20
- await actionLog.load(action_sync_id);
21
- body = event.body;
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
7
+ const repzo = new Repzo((_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey, { env: options.env });
8
+ const action_sync_id = ((_b = event === null || event === void 0 ? void 0 : event.headers) === null || _b === void 0 ? void 0 : _b.action_sync_id) || uuid();
9
+ const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
10
+ let body;
22
11
  try {
23
- if (body) body = JSON.parse(body);
24
- } catch (e) {}
25
- const repzo_serial_number =
26
- (_c = body === null || body === void 0 ? void 0 : body.serial_number) ===
27
- null || _c === void 0
28
- ? void 0
29
- : _c.formatted;
30
- try {
31
- await repzo.updateIntegrationMeta.create(
32
- [
33
- { key: "sync_to_sap_started", value: true },
34
- { key: "sync_to_sap_succeeded", value: false },
35
- ],
36
- { _id: body._id, type: "proformas" }
37
- );
38
- } catch (e) {
39
- console.error(e);
40
- }
41
- await actionLog
42
- .addDetail(
43
- `SalesOrder - ${repzo_serial_number} => ${
44
- body === null || body === void 0 ? void 0 : body.sync_id
45
- }`
46
- )
47
- .addDetail(
48
- `Repzo => SAP: Started Create SalesOrder - ${repzo_serial_number}`
49
- )
50
- .commit();
51
- const SAP_HOST_URL =
52
- (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
53
- if (!SAP_HOST_URL)
54
- throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
55
- const repzo_proforma = body;
56
- // Get Repzo Rep
57
- let repzo_rep;
58
- if (repzo_proforma.creator.type == "rep") {
59
- repzo_rep = await repzo.rep.get(
60
- (_e =
61
- repzo_proforma === null || repzo_proforma === void 0
62
- ? void 0
63
- : repzo_proforma.creator) === null || _e === void 0
64
- ? void 0
65
- : _e._id
66
- );
67
- if (!repzo_rep)
68
- throw `Rep with _id: ${repzo_proforma.creator._id} not found in Repzo`;
69
- }
70
- // Get Repzo Client
71
- const repzo_client = await repzo.client.get(
72
- repzo_proforma === null || repzo_proforma === void 0
73
- ? void 0
74
- : repzo_proforma.client_id
75
- );
76
- if (!repzo_client)
77
- throw `Client with _id: ${repzo_proforma.client_id} not found in Repzo`;
78
- const repzo_tax_ids = {};
79
- const repzo_measureunit_ids = {};
80
- const repzo_product_ids = {};
81
- (_f = repzo_proforma.items) === null || _f === void 0
82
- ? void 0
83
- : _f.forEach((item) => {
84
- var _a, _b, _c;
85
- if (item) {
86
- repzo_tax_ids[
87
- (_a = item.tax) === null || _a === void 0 ? void 0 : _a._id
88
- ] = true;
89
- repzo_measureunit_ids[
90
- (_b = item.measureunit) === null || _b === void 0
91
- ? void 0
92
- : _b._id
93
- ] = true;
94
- repzo_product_ids[
95
- (_c = item.variant) === null || _c === void 0
96
- ? void 0
97
- : _c.product_id
98
- ] = true;
99
- }
12
+ // console.log("create_proforma");
13
+ await actionLog.load(action_sync_id);
14
+ body = event.body;
15
+ try {
16
+ if (body)
17
+ body = JSON.parse(body);
18
+ }
19
+ catch (e) { }
20
+ const repzo_serial_number = (_c = body === null || body === void 0 ? void 0 : body.serial_number) === null || _c === void 0 ? void 0 : _c.formatted;
21
+ try {
22
+ await repzo.updateIntegrationMeta.create([
23
+ { key: "sync_to_sap_started", value: true },
24
+ { key: "sync_to_sap_succeeded", value: false },
25
+ ], { _id: body._id, type: "proformas" });
26
+ }
27
+ catch (e) {
28
+ console.error(e);
29
+ }
30
+ await actionLog
31
+ .addDetail(`SalesOrder - ${repzo_serial_number} => ${body === null || body === void 0 ? void 0 : body.sync_id}`)
32
+ .addDetail(`Repzo => SAP: Started Create SalesOrder - ${repzo_serial_number}`)
33
+ .commit();
34
+ const SAP_HOST_URL = (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
35
+ if (!SAP_HOST_URL)
36
+ throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
37
+ const repzo_proforma = body;
38
+ // Get Repzo Rep
39
+ let repzo_rep;
40
+ if (repzo_proforma.creator.type == "rep") {
41
+ repzo_rep = await repzo.rep.get((_e = repzo_proforma === null || repzo_proforma === void 0 ? void 0 : repzo_proforma.creator) === null || _e === void 0 ? void 0 : _e._id);
42
+ if (!repzo_rep)
43
+ throw `Rep with _id: ${repzo_proforma.creator._id} not found in Repzo`;
44
+ }
45
+ // Get Repzo Client
46
+ const repzo_client = await repzo.client.get(repzo_proforma === null || repzo_proforma === void 0 ? void 0 : repzo_proforma.client_id);
47
+ if (!repzo_client)
48
+ throw `Client with _id: ${repzo_proforma.client_id} not found in Repzo`;
49
+ const repzo_tax_ids = {};
50
+ const repzo_measureunit_ids = {};
51
+ const repzo_product_ids = {};
52
+ (_f = repzo_proforma.items) === null || _f === void 0 ? void 0 : _f.forEach((item) => {
53
+ var _a, _b, _c;
54
+ if (item) {
55
+ repzo_tax_ids[(_a = item.tax) === null || _a === void 0 ? void 0 : _a._id] = true;
56
+ repzo_measureunit_ids[(_b = item.measureunit) === null || _b === void 0 ? void 0 : _b._id] = true;
57
+ repzo_product_ids[(_c = item.variant) === null || _c === void 0 ? void 0 : _c.product_id] = true;
58
+ }
100
59
  });
101
- const repzo_taxes = await repzo.patchAction.create(
102
- {
103
- slug: "tax",
104
- readQuery: [
105
- {
106
- key: "_id",
107
- value: Object.keys(repzo_tax_ids),
108
- operator: "in",
109
- },
110
- ],
111
- },
112
- { per_page: 50000 }
113
- );
114
- const repzo_measureunits = await repzo.patchAction.create(
115
- {
116
- slug: "measureunits",
117
- readQuery: [
118
- {
119
- key: "_id",
120
- value: Object.keys(repzo_measureunit_ids),
121
- operator: "in",
122
- },
123
- ],
124
- },
125
- { per_page: 50000 }
126
- );
127
- const repzo_products = await repzo.patchAction.create(
128
- {
129
- slug: "product",
130
- readQuery: [
131
- {
132
- key: "_id",
133
- value: Object.keys(repzo_product_ids),
134
- operator: "in",
135
- },
136
- ],
137
- },
138
- { per_page: 50000 }
139
- );
140
- // Prepare SAP_invoice_items
141
- const items = [];
142
- for (
143
- let i = 0;
144
- i <
145
- ((_g =
146
- repzo_proforma === null || repzo_proforma === void 0
147
- ? void 0
148
- : repzo_proforma.items) === null || _g === void 0
149
- ? void 0
150
- : _g.length);
151
- i++
152
- ) {
153
- const item = repzo_proforma.items[i];
154
- // Get Repzo Tax
155
- const repzo_tax =
156
- (_h =
157
- repzo_taxes === null || repzo_taxes === void 0
158
- ? void 0
159
- : repzo_taxes.data) === null || _h === void 0
160
- ? void 0
161
- : _h.find((t) => {
162
- var _a, _b, _c;
163
- return (
164
- ((_a = t._id) === null || _a === void 0
165
- ? void 0
166
- : _a.toString()) ==
167
- ((_c =
168
- (_b = item.tax) === null || _b === void 0
169
- ? void 0
170
- : _b._id) === null || _c === void 0
171
- ? void 0
172
- : _c.toString())
173
- );
174
- });
175
- if (!repzo_tax) throw `Tax with _id: ${item.tax._id} not found in Repzo`;
176
- // Get Repzo UoM
177
- const repzo_measureunit =
178
- (_j =
179
- repzo_measureunits === null || repzo_measureunits === void 0
180
- ? void 0
181
- : repzo_measureunits.data) === null || _j === void 0
182
- ? void 0
183
- : _j.find((m) => {
184
- var _a, _b, _c;
185
- return (
186
- ((_a = m._id) === null || _a === void 0
187
- ? void 0
188
- : _a.toString()) ==
189
- ((_c =
190
- (_b = item.measureunit) === null || _b === void 0
191
- ? void 0
192
- : _b._id) === null || _c === void 0
193
- ? void 0
194
- : _c.toString())
195
- );
60
+ const repzo_taxes = await repzo.patchAction.create({
61
+ slug: "tax",
62
+ readQuery: [
63
+ {
64
+ key: "_id",
65
+ value: Object.keys(repzo_tax_ids),
66
+ operator: "in",
67
+ },
68
+ ],
69
+ }, { per_page: 50000 });
70
+ const repzo_measureunits = await repzo.patchAction.create({
71
+ slug: "measureunits",
72
+ readQuery: [
73
+ {
74
+ key: "_id",
75
+ value: Object.keys(repzo_measureunit_ids),
76
+ operator: "in",
77
+ },
78
+ ],
79
+ }, { per_page: 50000 });
80
+ const repzo_products = await repzo.patchAction.create({
81
+ slug: "product",
82
+ readQuery: [
83
+ {
84
+ key: "_id",
85
+ value: Object.keys(repzo_product_ids),
86
+ operator: "in",
87
+ },
88
+ ],
89
+ }, { per_page: 50000 });
90
+ // Prepare SAP_invoice_items
91
+ const items = [];
92
+ for (let i = 0; i < ((_g = repzo_proforma === null || repzo_proforma === void 0 ? void 0 : repzo_proforma.items) === null || _g === void 0 ? void 0 : _g.length); i++) {
93
+ const item = repzo_proforma.items[i];
94
+ // Get Repzo Tax
95
+ const repzo_tax = (_h = repzo_taxes === null || repzo_taxes === void 0 ? void 0 : repzo_taxes.data) === null || _h === void 0 ? void 0 : _h.find((t) => { var _a, _b, _c; return ((_a = t._id) === null || _a === void 0 ? void 0 : _a.toString()) == ((_c = (_b = item.tax) === null || _b === void 0 ? void 0 : _b._id) === null || _c === void 0 ? void 0 : _c.toString()); });
96
+ if (!repzo_tax)
97
+ throw `Tax with _id: ${item.tax._id} not found in Repzo`;
98
+ // Get Repzo UoM
99
+ const repzo_measureunit = (_j = repzo_measureunits === null || repzo_measureunits === void 0 ? void 0 : repzo_measureunits.data) === null || _j === void 0 ? void 0 : _j.find((m) => { var _a, _b, _c; return ((_a = m._id) === null || _a === void 0 ? void 0 : _a.toString()) == ((_c = (_b = item.measureunit) === null || _b === void 0 ? void 0 : _b._id) === null || _c === void 0 ? void 0 : _c.toString()); });
100
+ if (!repzo_measureunit)
101
+ throw `Uom with _id: ${(_k = item.measureunit) === null || _k === void 0 ? void 0 : _k._id} not found in Repzo`;
102
+ // Get Repzo Product
103
+ const repzo_product = (_l = repzo_products === null || repzo_products === void 0 ? void 0 : repzo_products.data) === null || _l === void 0 ? void 0 : _l.find((p) => { var _a, _b, _c; return ((_a = p._id) === null || _a === void 0 ? void 0 : _a.toString()) == ((_c = (_b = item.variant) === null || _b === void 0 ? void 0 : _b.product_id) === null || _c === void 0 ? void 0 : _c.toString()); });
104
+ if (!repzo_product)
105
+ throw `Product with _id: ${item.measureunit._id} not found in Repzo`;
106
+ items.push({
107
+ ItemCode: item.variant.variant_name,
108
+ Quantity: item.qty,
109
+ TaxCode: repzo_tax.integration_meta.TaxCode,
110
+ UnitPrice: (item.price * repzo_measureunit.factor) / 1000,
111
+ DiscountPerc: "0",
112
+ //@ts-ignore
113
+ LineTotal: item.total_before_tax / 1000,
114
+ UomCode: repzo_measureunit.integration_meta.ALTUOMID,
115
+ Brand: (_m = repzo_product.integration_meta) === null || _m === void 0 ? void 0 : _m.BRAND,
116
+ Department: ((_o = repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep.integration_meta) === null || _o === void 0 ? void 0 : _o.DEPARTMENTCODE) ||
117
+ ((_p = options.data) === null || _p === void 0 ? void 0 : _p.DepartmentCode), // "D2"
196
118
  });
197
- if (!repzo_measureunit)
198
- throw `Uom with _id: ${
199
- (_k = item.measureunit) === null || _k === void 0 ? void 0 : _k._id
200
- } not found in Repzo`;
201
- // Get Repzo Product
202
- const repzo_product =
203
- (_l =
204
- repzo_products === null || repzo_products === void 0
205
- ? void 0
206
- : repzo_products.data) === null || _l === void 0
207
- ? void 0
208
- : _l.find((p) => {
209
- var _a, _b, _c;
210
- return (
211
- ((_a = p._id) === null || _a === void 0
212
- ? void 0
213
- : _a.toString()) ==
214
- ((_c =
215
- (_b = item.variant) === null || _b === void 0
216
- ? void 0
217
- : _b.product_id) === null || _c === void 0
218
- ? void 0
219
- : _c.toString())
220
- );
221
- });
222
- if (!repzo_product)
223
- throw `Product with _id: ${item.measureunit._id} not found in Repzo`;
224
- items.push({
225
- ItemCode: item.variant.variant_name,
226
- Quantity: item.qty,
227
- TaxCode: repzo_tax.integration_meta.TaxCode,
228
- UnitPrice: (item.price * repzo_measureunit.factor) / 1000,
229
- DiscountPerc: "0",
230
- //@ts-ignore
231
- LineTotal: item.total_before_tax / 1000,
232
- UomCode: repzo_measureunit.integration_meta.ALTUOMID,
233
- Brand:
234
- (_m = repzo_product.integration_meta) === null || _m === void 0
235
- ? void 0
236
- : _m.BRAND,
237
- Department:
238
- ((_o =
239
- repzo_rep === null || repzo_rep === void 0
240
- ? void 0
241
- : repzo_rep.integration_meta) === null || _o === void 0
242
- ? void 0
243
- : _o.DEPARTMENTCODE) ||
244
- ((_p = options.data) === null || _p === void 0
245
- ? void 0
246
- : _p.DepartmentCode), // "D2"
247
- });
119
+ }
120
+ const sap_invoice = {
121
+ RefNum: repzo_proforma.serial_number.formatted,
122
+ SalPersCode: repzo_rep
123
+ ? repzo_rep.integration_id
124
+ : (_q = options.data) === null || _q === void 0 ? void 0 : _q.SalPersCode,
125
+ DocDate: moment(repzo_proforma.issue_date, "YYYY-MM-DD").format("YYYYMMDD"),
126
+ DocDueDate: moment(repzo_proforma.issue_date, "YYYY-MM-DD").format("YYYYMMDD"),
127
+ ClientCode: repzo_client.client_code,
128
+ DiscountPerc: "0",
129
+ Note: repzo_proforma.comment,
130
+ // WarehouseCode: "1",
131
+ LinesDetails: items,
132
+ };
133
+ // console.dir(sap_invoice, { depth: null });
134
+ actionLog.addDetail(`Repzo => SAP: SalesOrder - ${repzo_serial_number}`, sap_invoice); // .commit();
135
+ const result = await _create(SAP_HOST_URL, "/AddOrder", sap_invoice);
136
+ // console.log(result);
137
+ try {
138
+ await repzo.updateIntegrationMeta.create([{ key: "sync_to_sap_succeeded", value: true }], { _id: body._id, type: "proformas" });
139
+ }
140
+ catch (e) {
141
+ console.error(e);
142
+ }
143
+ await actionLog
144
+ .addDetail(`SAP Responded with `, result)
145
+ .addDetail(`Repzo => SAP: SalesOrder - ${repzo_serial_number}`)
146
+ .setStatus("success")
147
+ .setBody(repzo_proforma)
148
+ .commit();
149
+ return result;
248
150
  }
249
- const sap_invoice = {
250
- RefNum: repzo_proforma.serial_number.formatted,
251
- SalPersCode: repzo_rep
252
- ? repzo_rep.integration_id
253
- : (_q = options.data) === null || _q === void 0
254
- ? void 0
255
- : _q.SalPersCode,
256
- DocDate: moment(repzo_proforma.issue_date, "YYYY-MM-DD").format(
257
- "YYYYMMDD"
258
- ),
259
- DocDueDate: moment(repzo_proforma.issue_date, "YYYY-MM-DD").format(
260
- "YYYYMMDD"
261
- ),
262
- ClientCode: repzo_client.client_code,
263
- DiscountPerc: "0",
264
- Note: repzo_proforma.comment,
265
- // WarehouseCode: "1",
266
- LinesDetails: items,
267
- };
268
- // console.dir(sap_invoice, { depth: null });
269
- actionLog.addDetail(
270
- `Repzo => SAP: SalesOrder - ${repzo_serial_number}`,
271
- sap_invoice
272
- ); // .commit();
273
- const result = await _create(SAP_HOST_URL, "/AddOrder", sap_invoice);
274
- // console.log(result);
275
- try {
276
- await repzo.updateIntegrationMeta.create(
277
- [{ key: "sync_to_sap_succeeded", value: true }],
278
- { _id: body._id, type: "proformas" }
279
- );
280
- } catch (e) {
281
- console.error(e);
151
+ catch (e) {
152
+ //@ts-ignore
153
+ console.error((e === null || e === void 0 ? void 0 : e.response) || e);
154
+ await actionLog.setStatus("fail", e).setBody(body).commit();
155
+ throw e;
282
156
  }
283
- await actionLog
284
- .addDetail(`SAP Responded with `, result)
285
- .addDetail(`Repzo => SAP: SalesOrder - ${repzo_serial_number}`)
286
- .setStatus("success")
287
- .setBody(repzo_proforma)
288
- .commit();
289
- return result;
290
- } catch (e) {
291
- //@ts-ignore
292
- console.error((e === null || e === void 0 ? void 0 : e.response) || e);
293
- await actionLog.setStatus("fail", e).setBody(body).commit();
294
- throw e;
295
- }
296
157
  };
@@ -1,5 +1,2 @@
1
1
  import { EVENT, Config } from "../types";
2
- export declare const create_return_invoice: (
3
- event: EVENT,
4
- options: Config
5
- ) => Promise<any>;
2
+ export declare const create_return_invoice: (event: EVENT, options: Config) => Promise<any>;