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