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
@@ -3,341 +3,186 @@ 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_return_invoice = 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_return_invoice");
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
- if (body === null || body === void 0 ? void 0 : body._id) {
32
- body.integration_meta =
33
- (body === null || body === void 0 ? void 0 : body.integration_meta) ||
34
- {};
35
- body.integration_meta.sync_to_sap_started = true;
36
- body.integration_meta.sync_to_sap_succeeded = false;
37
- await repzo.invoice.update(body._id, {
38
- integration_meta: body.integration_meta,
39
- });
40
- }
41
- } catch (e) {
42
- console.error(e);
43
- await actionLog
44
- .addDetail(
45
- `Failed updating integration_meta of Return Invoice: ${repzo_serial_number}`
46
- )
47
- .commit();
48
- }
49
- await actionLog
50
- .addDetail(
51
- `Return Invoice - ${repzo_serial_number} => ${
52
- body === null || body === void 0 ? void 0 : body.sync_id
53
- }`
54
- )
55
- .addDetail(
56
- `Repzo => SAP: Started Create Return Invoice - ${repzo_serial_number}`
57
- )
58
- .commit();
59
- const SAP_HOST_URL =
60
- (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
61
- if (!SAP_HOST_URL)
62
- throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
63
- const repzo_invoice = body;
64
- // Get Return Reason
65
- let return_reasons =
66
- (_e = options.data) === null || _e === void 0
67
- ? void 0
68
- : _e.return_reasons;
69
- try {
70
- if (typeof return_reasons == "string")
71
- return_reasons = JSON.parse(return_reasons);
72
- } catch (e) {}
73
- // Get Repzo Rep
74
- let repzo_rep;
75
- if (repzo_invoice.creator.type == "rep") {
76
- repzo_rep = await repzo.rep.get(
77
- (_f =
78
- repzo_invoice === null || repzo_invoice === void 0
79
- ? void 0
80
- : repzo_invoice.creator) === null || _f === void 0
81
- ? void 0
82
- : _f._id
83
- );
84
- if (!repzo_rep)
85
- throw `Rep with _id: ${repzo_invoice.creator._id} not found in Repzo`;
86
- }
87
- // Get Repzo Client
88
- const repzo_client = await repzo.client.get(
89
- repzo_invoice === null || repzo_invoice === void 0
90
- ? void 0
91
- : repzo_invoice.client_id
92
- );
93
- if (!repzo_client)
94
- throw `Client with _id: ${repzo_invoice.client_id} not found in Repzo`;
95
- // Get Repzo Warehouse
96
- const repzo_warehouse = await repzo.warehouse.get(
97
- repzo_invoice.origin_warehouse
98
- );
99
- if (!repzo_warehouse)
100
- throw `warehouse with _id: ${repzo_invoice.origin_warehouse} not found in Repzo`;
101
- const repzo_tax_ids = {};
102
- const repzo_measureunit_ids = {};
103
- const repzo_product_ids = {};
104
- (_g = repzo_invoice.return_items) === null || _g === void 0
105
- ? void 0
106
- : _g.forEach((item) => {
107
- var _a, _b, _c;
108
- if (item) {
109
- repzo_tax_ids[
110
- (_a = item.tax) === null || _a === void 0 ? void 0 : _a._id
111
- ] = true;
112
- repzo_measureunit_ids[
113
- (_b = item.measureunit) === null || _b === void 0
114
- ? void 0
115
- : _b._id
116
- ] = true;
117
- repzo_product_ids[
118
- (_c = item.variant) === null || _c === void 0
119
- ? void 0
120
- : _c.product_id
121
- ] = true;
122
- }
12
+ // console.log("create_return_invoice");
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
+ if (body === null || body === void 0 ? void 0 : body._id) {
23
+ body.integration_meta = (body === null || body === void 0 ? void 0 : body.integration_meta) || {};
24
+ body.integration_meta.sync_to_sap_started = true;
25
+ body.integration_meta.sync_to_sap_succeeded =
26
+ body.integration_meta.sync_to_sap_succeeded || false;
27
+ await repzo.invoice.update(body._id, {
28
+ integration_meta: body.integration_meta,
29
+ });
30
+ }
31
+ }
32
+ catch (e) {
33
+ console.error(e);
34
+ await actionLog
35
+ .addDetail(`Failed updating integration_meta of Return Invoice: ${repzo_serial_number}`)
36
+ .commit();
37
+ }
38
+ await actionLog
39
+ .addDetail(`Return Invoice - ${repzo_serial_number} => ${body === null || body === void 0 ? void 0 : body.sync_id}`)
40
+ .addDetail(`Repzo => SAP: Started Create Return Invoice - ${repzo_serial_number}`)
41
+ .commit();
42
+ const SAP_HOST_URL = (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
43
+ if (!SAP_HOST_URL)
44
+ throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
45
+ const repzo_invoice = body;
46
+ // Get Return Reason
47
+ let return_reasons = (_e = options.data) === null || _e === void 0 ? void 0 : _e.return_reasons;
48
+ try {
49
+ if (typeof return_reasons == "string")
50
+ return_reasons = JSON.parse(return_reasons);
51
+ }
52
+ catch (e) { }
53
+ // Get Repzo Rep
54
+ let repzo_rep;
55
+ if (repzo_invoice.creator.type == "rep") {
56
+ repzo_rep = await repzo.rep.get((_f = repzo_invoice === null || repzo_invoice === void 0 ? void 0 : repzo_invoice.creator) === null || _f === void 0 ? void 0 : _f._id);
57
+ if (!repzo_rep)
58
+ throw `Rep with _id: ${repzo_invoice.creator._id} not found in Repzo`;
59
+ }
60
+ // Get Repzo Client
61
+ const repzo_client = await repzo.client.get(repzo_invoice === null || repzo_invoice === void 0 ? void 0 : repzo_invoice.client_id);
62
+ if (!repzo_client)
63
+ throw `Client with _id: ${repzo_invoice.client_id} not found in Repzo`;
64
+ // Get Repzo Warehouse
65
+ const repzo_warehouse = await repzo.warehouse.get(repzo_invoice.origin_warehouse);
66
+ if (!repzo_warehouse)
67
+ throw `warehouse with _id: ${repzo_invoice.origin_warehouse} not found in Repzo`;
68
+ const repzo_tax_ids = {};
69
+ const repzo_measureunit_ids = {};
70
+ const repzo_product_ids = {};
71
+ (_g = repzo_invoice.return_items) === null || _g === void 0 ? void 0 : _g.forEach((item) => {
72
+ var _a, _b, _c;
73
+ if (item) {
74
+ repzo_tax_ids[(_a = item.tax) === null || _a === void 0 ? void 0 : _a._id] = true;
75
+ repzo_measureunit_ids[(_b = item.measureunit) === null || _b === void 0 ? void 0 : _b._id] = true;
76
+ repzo_product_ids[(_c = item.variant) === null || _c === void 0 ? void 0 : _c.product_id] = true;
77
+ }
123
78
  });
124
- const repzo_taxes = await repzo.patchAction.create(
125
- {
126
- slug: "tax",
127
- readQuery: [
128
- {
129
- key: "_id",
130
- value: Object.keys(repzo_tax_ids),
131
- operator: "in",
132
- },
133
- ],
134
- },
135
- { per_page: 50000 }
136
- );
137
- const repzo_measureunits = await repzo.patchAction.create(
138
- {
139
- slug: "measureunits",
140
- readQuery: [
141
- {
142
- key: "_id",
143
- value: Object.keys(repzo_measureunit_ids),
144
- operator: "in",
145
- },
146
- ],
147
- },
148
- { per_page: 50000 }
149
- );
150
- const repzo_products = await repzo.patchAction.create(
151
- {
152
- slug: "product",
153
- readQuery: [
154
- {
155
- key: "_id",
156
- value: Object.keys(repzo_product_ids),
157
- operator: "in",
158
- },
159
- ],
160
- },
161
- { per_page: 50000 }
162
- );
163
- // Prepare SAP_invoice_items
164
- const return_items = [];
165
- for (
166
- let i = 0;
167
- i <
168
- ((_h =
169
- repzo_invoice === null || repzo_invoice === void 0
170
- ? void 0
171
- : repzo_invoice.return_items) === null || _h === void 0
172
- ? void 0
173
- : _h.length);
174
- i++
175
- ) {
176
- const item = repzo_invoice.return_items[i];
177
- // Get Repzo Tax
178
- const repzo_tax =
179
- (_j =
180
- repzo_taxes === null || repzo_taxes === void 0
181
- ? void 0
182
- : repzo_taxes.data) === null || _j === void 0
183
- ? void 0
184
- : _j.find((t) => {
185
- var _a, _b, _c;
186
- return (
187
- ((_a = t._id) === null || _a === void 0
188
- ? void 0
189
- : _a.toString()) ==
190
- ((_c =
191
- (_b = item.tax) === null || _b === void 0
192
- ? void 0
193
- : _b._id) === null || _c === void 0
194
- ? void 0
195
- : _c.toString())
196
- );
197
- });
198
- if (!repzo_tax) throw `Tax with _id: ${item.tax._id} not found in Repzo`;
199
- // Get Repzo UoM
200
- const repzo_measureunit =
201
- (_k =
202
- repzo_measureunits === null || repzo_measureunits === void 0
203
- ? void 0
204
- : repzo_measureunits.data) === null || _k === void 0
205
- ? void 0
206
- : _k.find((m) => {
207
- var _a, _b, _c;
208
- return (
209
- ((_a = m._id) === null || _a === void 0
210
- ? void 0
211
- : _a.toString()) ==
212
- ((_c =
213
- (_b = item.measureunit) === null || _b === void 0
214
- ? void 0
215
- : _b._id) === null || _c === void 0
216
- ? void 0
217
- : _c.toString())
218
- );
79
+ const repzo_taxes = await repzo.patchAction.create({
80
+ slug: "tax",
81
+ readQuery: [
82
+ {
83
+ key: "_id",
84
+ value: Object.keys(repzo_tax_ids),
85
+ operator: "in",
86
+ },
87
+ ],
88
+ }, { per_page: 50000 });
89
+ const repzo_measureunits = await repzo.patchAction.create({
90
+ slug: "measureunits",
91
+ readQuery: [
92
+ {
93
+ key: "_id",
94
+ value: Object.keys(repzo_measureunit_ids),
95
+ operator: "in",
96
+ },
97
+ ],
98
+ }, { per_page: 50000 });
99
+ const repzo_products = await repzo.patchAction.create({
100
+ slug: "product",
101
+ readQuery: [
102
+ {
103
+ key: "_id",
104
+ value: Object.keys(repzo_product_ids),
105
+ operator: "in",
106
+ },
107
+ ],
108
+ }, { per_page: 50000 });
109
+ // Prepare SAP_invoice_items
110
+ const return_items = [];
111
+ for (let i = 0; i < ((_h = repzo_invoice === null || repzo_invoice === void 0 ? void 0 : repzo_invoice.return_items) === null || _h === void 0 ? void 0 : _h.length); i++) {
112
+ const item = repzo_invoice.return_items[i];
113
+ // Get Repzo Tax
114
+ const repzo_tax = (_j = repzo_taxes === null || repzo_taxes === void 0 ? void 0 : repzo_taxes.data) === null || _j === void 0 ? void 0 : _j.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()); });
115
+ if (!repzo_tax)
116
+ throw `Tax with _id: ${item.tax._id} not found in Repzo`;
117
+ // Get Repzo UoM
118
+ const repzo_measureunit = (_k = repzo_measureunits === null || repzo_measureunits === void 0 ? void 0 : repzo_measureunits.data) === null || _k === void 0 ? void 0 : _k.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()); });
119
+ if (!repzo_measureunit)
120
+ throw `Uom with _id: ${(_l = item.measureunit) === null || _l === void 0 ? void 0 : _l._id} not found in Repzo`;
121
+ // Get Repzo Product
122
+ const repzo_product = (_m = repzo_products === null || repzo_products === void 0 ? void 0 : repzo_products.data) === null || _m === void 0 ? void 0 : _m.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()); });
123
+ if (!repzo_product)
124
+ throw `Product with _id: ${item.measureunit._id} not found in Repzo`;
125
+ // Get SAP return_reason
126
+ const item_return_reason = return_reasons === null || return_reasons === void 0 ? void 0 : return_reasons.find((r) => r.repzo_id === item.return_reason);
127
+ return_items.push({
128
+ ItemCode: item.variant.variant_name,
129
+ Quantity: -1 * item.qty,
130
+ TaxCode: repzo_tax.integration_meta.TaxCode,
131
+ UnitPrice: (item.price * repzo_measureunit.factor) / 1000,
132
+ DiscountPerc: "0",
133
+ //@ts-ignore
134
+ LineTotal: (-1 * item.total_before_tax) / 1000,
135
+ UomCode: repzo_measureunit.integration_meta.ALTUOMID,
136
+ Brand: (_o = repzo_product.integration_meta) === null || _o === void 0 ? void 0 : _o.BRAND,
137
+ Department: ((_p = repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep.integration_meta) === null || _p === void 0 ? void 0 : _p.DEPARTMENTCODE) ||
138
+ ((_q = options.data) === null || _q === void 0 ? void 0 : _q.DepartmentCode),
139
+ Return_Reason: item_return_reason === null || item_return_reason === void 0 ? void 0 : item_return_reason.sap_id,
219
140
  });
220
- if (!repzo_measureunit)
221
- throw `Uom with _id: ${
222
- (_l = item.measureunit) === null || _l === void 0 ? void 0 : _l._id
223
- } not found in Repzo`;
224
- // Get Repzo Product
225
- const repzo_product =
226
- (_m =
227
- repzo_products === null || repzo_products === void 0
228
- ? void 0
229
- : repzo_products.data) === null || _m === void 0
230
- ? void 0
231
- : _m.find((p) => {
232
- var _a, _b, _c;
233
- return (
234
- ((_a = p._id) === null || _a === void 0
235
- ? void 0
236
- : _a.toString()) ==
237
- ((_c =
238
- (_b = item.variant) === null || _b === void 0
239
- ? void 0
240
- : _b.product_id) === null || _c === void 0
241
- ? void 0
242
- : _c.toString())
243
- );
244
- });
245
- if (!repzo_product)
246
- throw `Product with _id: ${item.measureunit._id} not found in Repzo`;
247
- // Get SAP return_reason
248
- const item_return_reason =
249
- return_reasons === null || return_reasons === void 0
250
- ? void 0
251
- : return_reasons.find((r) => r.repzo_id === item.return_reason);
252
- return_items.push({
253
- ItemCode: item.variant.variant_name,
254
- Quantity: -1 * item.qty,
255
- TaxCode: repzo_tax.integration_meta.TaxCode,
256
- UnitPrice: (item.price * repzo_measureunit.factor) / 1000,
257
- DiscountPerc: "0",
258
- //@ts-ignore
259
- LineTotal: (-1 * item.total_before_tax) / 1000,
260
- UomCode: repzo_measureunit.integration_meta.ALTUOMID,
261
- Brand:
262
- (_o = repzo_product.integration_meta) === null || _o === void 0
263
- ? void 0
264
- : _o.BRAND,
265
- Department:
266
- ((_p =
267
- repzo_rep === null || repzo_rep === void 0
268
- ? void 0
269
- : repzo_rep.integration_meta) === null || _p === void 0
270
- ? void 0
271
- : _p.DEPARTMENTCODE) ||
272
- ((_q = options.data) === null || _q === void 0
273
- ? void 0
274
- : _q.DepartmentCode),
275
- Return_Reason:
276
- item_return_reason === null || item_return_reason === void 0
277
- ? void 0
278
- : item_return_reason.sap_id,
279
- });
141
+ }
142
+ const sap_return_invoice = {
143
+ RefNum: repzo_invoice.serial_number.formatted,
144
+ SalPersCode: repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep.integration_id,
145
+ DocDate: moment(repzo_invoice.issue_date, "YYYY-MM-DD").format("YYYYMMDD"),
146
+ DocDueDate: moment(repzo_invoice.due_date, "YYYY-MM-DD").format("YYYYMMDD"),
147
+ ClientCode: repzo_client.client_code,
148
+ DiscountPerc: "0",
149
+ Note: repzo_invoice.comment,
150
+ WarehouseCode: repzo_warehouse.code,
151
+ LinesDetails: return_items,
152
+ };
153
+ // console.dir(sap_return_invoice, { depth: null });
154
+ await actionLog
155
+ .addDetail(`Repzo => SAP: Invoice - ${repzo_serial_number}`, sap_return_invoice)
156
+ .commit();
157
+ const result = await _create(SAP_HOST_URL, "/AddCreditMemo", sap_return_invoice);
158
+ // console.log(result);
159
+ try {
160
+ if (body === null || body === void 0 ? void 0 : body._id) {
161
+ body.integration_meta = (body === null || body === void 0 ? void 0 : body.integration_meta) || {};
162
+ body.integration_meta.sync_to_sap_succeeded = true;
163
+ await repzo.invoice.update(body._id, {
164
+ integration_meta: body.integration_meta,
165
+ });
166
+ }
167
+ }
168
+ catch (e) {
169
+ console.error(e);
170
+ await actionLog
171
+ .addDetail(`Failed updating integration_meta of Return Invoice: ${repzo_serial_number}`)
172
+ .commit();
173
+ }
174
+ await actionLog
175
+ .addDetail(`SAP Responded with `, result)
176
+ .addDetail(`Repzo => SAP: Return Invoice - ${repzo_serial_number}`)
177
+ .setStatus("success")
178
+ .setBody(repzo_invoice)
179
+ .commit();
180
+ return result;
280
181
  }
281
- const sap_return_invoice = {
282
- RefNum: repzo_invoice.serial_number.formatted,
283
- SalPersCode:
284
- repzo_rep === null || repzo_rep === void 0
285
- ? void 0
286
- : repzo_rep.integration_id,
287
- DocDate: moment(repzo_invoice.issue_date, "YYYY-MM-DD").format(
288
- "YYYYMMDD"
289
- ),
290
- DocDueDate: moment(repzo_invoice.due_date, "YYYY-MM-DD").format(
291
- "YYYYMMDD"
292
- ),
293
- ClientCode: repzo_client.client_code,
294
- DiscountPerc: "0",
295
- Note: repzo_invoice.comment,
296
- WarehouseCode: repzo_warehouse.code,
297
- LinesDetails: return_items,
298
- };
299
- // console.dir(sap_return_invoice, { depth: null });
300
- await actionLog
301
- .addDetail(
302
- `Repzo => SAP: Invoice - ${repzo_serial_number}`,
303
- sap_return_invoice
304
- )
305
- .commit();
306
- const result = await _create(
307
- SAP_HOST_URL,
308
- "/AddCreditMemo",
309
- sap_return_invoice
310
- );
311
- // console.log(result);
312
- try {
313
- if (body === null || body === void 0 ? void 0 : body._id) {
314
- body.integration_meta =
315
- (body === null || body === void 0 ? void 0 : body.integration_meta) ||
316
- {};
317
- body.integration_meta.sync_to_sap_succeeded = true;
318
- await repzo.invoice.update(body._id, {
319
- integration_meta: body.integration_meta,
320
- });
321
- }
322
- } catch (e) {
323
- console.error(e);
324
- await actionLog
325
- .addDetail(
326
- `Failed updating integration_meta of Return Invoice: ${repzo_serial_number}`
327
- )
328
- .commit();
182
+ catch (e) {
183
+ //@ts-ignore
184
+ console.error((e === null || e === void 0 ? void 0 : e.response) || e);
185
+ await actionLog.setStatus("fail", e).setBody(body).commit();
186
+ throw e;
329
187
  }
330
- await actionLog
331
- .addDetail(`SAP Responded with `, result)
332
- .addDetail(`Repzo => SAP: Return Invoice - ${repzo_serial_number}`)
333
- .setStatus("success")
334
- .setBody(repzo_invoice)
335
- .commit();
336
- return result;
337
- } catch (e) {
338
- //@ts-ignore
339
- console.error((e === null || e === void 0 ? void 0 : e.response) || e);
340
- await actionLog.setStatus("fail", e).setBody(body).commit();
341
- throw e;
342
- }
343
188
  };
@@ -1,5 +1,2 @@
1
1
  import { EVENT, Config } from "../types";
2
- export declare const create_transfer: (
3
- event: EVENT,
4
- options: Config
5
- ) => Promise<any>;
2
+ export declare const create_transfer: (event: EVENT, options: Config) => Promise<any>;