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.
- package/changelog.md +1 -0
- package/lib/actions/create_invoice.d.ts +13 -19
- package/lib/actions/create_invoice.js +214 -371
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +125 -208
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +165 -305
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +177 -332
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +142 -234
- package/lib/actions/index.js +15 -23
- package/lib/commands/adjust_inventory.d.ts +2 -4
- package/lib/commands/adjust_inventory.js +160 -290
- package/lib/commands/bank.d.ts +2 -4
- package/lib/commands/bank.js +157 -279
- package/lib/commands/basic.js +47 -66
- package/lib/commands/category.d.ts +1 -3
- package/lib/commands/category.js +104 -178
- package/lib/commands/channel.d.ts +1 -3
- package/lib/commands/channel.js +117 -198
- package/lib/commands/client.d.ts +32 -34
- package/lib/commands/client.js +244 -404
- package/lib/commands/client_disabled.d.ts +1 -3
- package/lib/commands/client_disabled.js +94 -163
- package/lib/commands/index.d.ts +11 -15
- package/lib/commands/index.js +60 -60
- package/lib/commands/join.js +66 -192
- package/lib/commands/measureunit.d.ts +14 -19
- package/lib/commands/measureunit.js +191 -289
- package/lib/commands/measureunit_family.d.ts +8 -10
- package/lib/commands/measureunit_family.js +138 -250
- package/lib/commands/payment_term.d.ts +1 -3
- package/lib/commands/payment_term.js +123 -202
- package/lib/commands/price_list.d.ts +15 -15
- package/lib/commands/price_list.js +326 -612
- package/lib/commands/product.d.ts +30 -32
- package/lib/commands/product.js +243 -425
- package/lib/commands/product_disabled.d.ts +1 -3
- package/lib/commands/product_disabled.js +94 -164
- package/lib/commands/rep.js +141 -221
- package/lib/commands/tag.js +109 -174
- package/lib/commands/tax.js +112 -177
- package/lib/commands/warehouse.d.ts +1 -3
- package/lib/commands/warehouse.js +119 -207
- package/lib/index.d.ts +12 -21
- package/lib/test/actions/create_invoice.js +188 -193
- package/lib/test/actions/create_payment.js +107 -112
- package/lib/test/actions/create_proforma.js +216 -220
- package/lib/test/actions/create_return_invoice.js +200 -205
- package/lib/test/actions/create_transfer.js +115 -120
- package/lib/test/commands/adjust_inventory.js +90 -90
- package/lib/test/commands/bank.js +90 -90
- package/lib/test/commands/basic.js +327 -328
- package/lib/test/commands/category.js +90 -90
- package/lib/test/commands/channel.js +90 -90
- package/lib/test/commands/client.js +353 -355
- package/lib/test/commands/client_disabled.js +90 -90
- package/lib/test/commands/join.js +327 -328
- package/lib/test/commands/measureunit.js +90 -90
- package/lib/test/commands/measureunit_family.js +90 -90
- package/lib/test/commands/payment_term.js +90 -90
- package/lib/test/commands/price_list.js +334 -337
- package/lib/test/commands/product.js +90 -90
- package/lib/test/commands/product_disabled.js +90 -90
- package/lib/test/commands/rep.js +344 -346
- package/lib/test/commands/tag.js +90 -90
- package/lib/test/commands/tax.js +90 -90
- package/lib/test/commands/warehouse.js +90 -90
- package/lib/types.d.ts +60 -83
- package/lib/util.d.ts +19 -70
- package/lib/util.js +144 -170
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +2 -1
- package/src/actions/create_payment.ts +2 -1
- package/src/actions/create_proforma.ts +2 -1
- package/src/actions/create_return_invoice.ts +2 -1
- 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
|
-
|
|
7
|
-
|
|
8
|
-
(
|
|
9
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
:
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
};
|