repzo-sap-absjo 1.0.8 → 1.0.9

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