repzo-sap-absjo 1.0.19 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/create_invoice.d.ts +13 -19
- package/lib/actions/create_invoice.js +207 -377
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +107 -195
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +146 -285
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +158 -312
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +126 -223
- 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 +48 -67
- package/lib/commands/brand.d.ts +1 -3
- package/lib/commands/brand.js +100 -174
- 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 +62 -62
- 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 +263 -485
- package/lib/commands/product_disabled.d.ts +1 -3
- package/lib/commands/product_disabled.js +94 -160
- 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/brand.js +90 -90
- 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 +53 -77
- package/lib/util.d.ts +19 -70
- package/lib/util.js +144 -170
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +5 -25
|
@@ -4,203 +4,115 @@ import { v4 as uuid } from "uuid";
|
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
5
|
import { get_invoice_from_sap } from "./create_invoice.js";
|
|
6
6
|
export const create_payment = async (event, options) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const action_sync_id =
|
|
13
|
-
((_b = event === null || event === void 0 ? void 0 : event.headers) ===
|
|
14
|
-
null || _b === void 0
|
|
15
|
-
? void 0
|
|
16
|
-
: _b.action_sync_id) || uuid();
|
|
17
|
-
const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
|
|
18
|
-
let body;
|
|
19
|
-
try {
|
|
20
|
-
// console.log("create_payment");
|
|
21
|
-
await actionLog.load(action_sync_id);
|
|
22
|
-
body = event.body;
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
8
|
+
const repzo = new Repzo((_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey, { env: options.env });
|
|
9
|
+
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();
|
|
10
|
+
const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
|
|
11
|
+
let body;
|
|
23
12
|
try {
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
((_h =
|
|
123
|
-
repzo_payment === null || repzo_payment === void 0
|
|
124
|
-
? void 0
|
|
125
|
-
: repzo_payment.LinkedTxn) === null || _h === void 0
|
|
126
|
-
? void 0
|
|
127
|
-
: _h.Txn_invoice_total) / 1000;
|
|
128
|
-
} else {
|
|
129
|
-
sap_payment.InvoiceID = "";
|
|
130
|
-
sap_payment.InvoiceTotal = "";
|
|
13
|
+
// console.log("create_payment");
|
|
14
|
+
await actionLog.load(action_sync_id);
|
|
15
|
+
body = event.body;
|
|
16
|
+
try {
|
|
17
|
+
if (body)
|
|
18
|
+
body = JSON.parse(body);
|
|
19
|
+
}
|
|
20
|
+
catch (e) { }
|
|
21
|
+
const repzo_serial_number = (_c = body === null || body === void 0 ? void 0 : body.serial_number) === null || _c === void 0 ? void 0 : _c.formatted;
|
|
22
|
+
try {
|
|
23
|
+
await repzo.updateIntegrationMeta.create([
|
|
24
|
+
{ key: "sync_to_sap_started", value: true },
|
|
25
|
+
{ key: "sync_to_sap_succeeded", value: false },
|
|
26
|
+
], { _id: body._id, type: "payments" });
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
console.error(e);
|
|
30
|
+
}
|
|
31
|
+
await actionLog
|
|
32
|
+
.addDetail(`Payment - ${repzo_serial_number} => ${body === null || body === void 0 ? void 0 : body.sync_id}`)
|
|
33
|
+
.addDetail(`Repzo => SAP: Started Create Payment - ${repzo_serial_number}`)
|
|
34
|
+
.commit();
|
|
35
|
+
const SAP_HOST_URL = (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
|
|
36
|
+
if (!SAP_HOST_URL)
|
|
37
|
+
throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
|
|
38
|
+
const repzo_payment = body;
|
|
39
|
+
// Get Repzo Rep
|
|
40
|
+
let repzo_rep;
|
|
41
|
+
if (repzo_payment.creator.type == "rep") {
|
|
42
|
+
repzo_rep = await repzo.rep.get((_e = repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.creator) === null || _e === void 0 ? void 0 : _e._id);
|
|
43
|
+
if (!repzo_rep)
|
|
44
|
+
throw `Rep with _id: ${repzo_payment.creator._id} not found in Repzo`;
|
|
45
|
+
}
|
|
46
|
+
// Get Repzo Client
|
|
47
|
+
const repzo_client = await repzo.client.get(repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.client_id);
|
|
48
|
+
if (!repzo_client)
|
|
49
|
+
throw `Client with _id: ${repzo_payment.client_id} not found in Repzo`;
|
|
50
|
+
const sap_payment = {
|
|
51
|
+
UserId: repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep.integration_id,
|
|
52
|
+
PaymentID: repzo_serial_number,
|
|
53
|
+
ClientCode: repzo_client === null || repzo_client === void 0 ? void 0 : repzo_client.client_code,
|
|
54
|
+
PaymentDate: moment(repzo_payment.paytime, "YYYY-MM-DD").format("YYYYMMDD"),
|
|
55
|
+
Amount: repzo_payment.amount / 1000,
|
|
56
|
+
};
|
|
57
|
+
if (repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.LinkedTxn) {
|
|
58
|
+
const sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
|
|
59
|
+
updatedAt: "",
|
|
60
|
+
Status: "",
|
|
61
|
+
InvoiceId: (_g = (_f = repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.LinkedTxn) === null || _f === void 0 ? void 0 : _f.Txn_serial_number) === null || _g === void 0 ? void 0 : _g.formatted,
|
|
62
|
+
});
|
|
63
|
+
if (!(sap_open_invoices === null || sap_open_invoices === void 0 ? void 0 : sap_open_invoices.length)) {
|
|
64
|
+
throw `Invoice with serial number: ${repzo_payment.LinkedTxn.Txn_serial_number.formatted} was not found on SAP or was closed`;
|
|
65
|
+
}
|
|
66
|
+
sap_payment.InvoiceID = sap_open_invoices[0].InvoiceID;
|
|
67
|
+
sap_payment.InvoiceTotal =
|
|
68
|
+
((_h = repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.LinkedTxn) === null || _h === void 0 ? void 0 : _h.Txn_invoice_total) / 1000;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
sap_payment.InvoiceID = "";
|
|
72
|
+
sap_payment.InvoiceTotal = "";
|
|
73
|
+
}
|
|
74
|
+
if (repzo_payment.payment_type == "check") {
|
|
75
|
+
// bank
|
|
76
|
+
//@ts-ignore
|
|
77
|
+
const repzo_bank = await repzo.bank.get((_j = repzo_payment.check) === null || _j === void 0 ? void 0 : _j.bank);
|
|
78
|
+
if (!repzo_bank) {
|
|
79
|
+
//@ts-ignore
|
|
80
|
+
throw `Bank with _id: ${repzo_payment.check.bank} not found in Repzo`;
|
|
81
|
+
}
|
|
82
|
+
sap_payment.PaymentType = "2";
|
|
83
|
+
sap_payment.ChequeAccount =
|
|
84
|
+
(_k = repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep.integration_meta) === null || _k === void 0 ? void 0 : _k.USERCHECKACCTCODE;
|
|
85
|
+
sap_payment.ChequeDate = moment((_l = repzo_payment.check) === null || _l === void 0 ? void 0 : _l.check_date, "YYYY-MM-DD").format("YYYYMMDD");
|
|
86
|
+
sap_payment.ChequeNumber = (_m = repzo_payment.check) === null || _m === void 0 ? void 0 : _m.check_number;
|
|
87
|
+
sap_payment.BankCode = (_o = repzo_bank.integration_meta) === null || _o === void 0 ? void 0 : _o.BANKCODE;
|
|
88
|
+
sap_payment.CountryCode = (_p = repzo_bank.integration_meta) === null || _p === void 0 ? void 0 : _p.COUNTRY;
|
|
89
|
+
}
|
|
90
|
+
else if (repzo_payment.payment_type == "cash") {
|
|
91
|
+
sap_payment.PaymentType = "1";
|
|
92
|
+
sap_payment.CashAccount = (_q = repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep.integration_meta) === null || _q === void 0 ? void 0 : _q.USERCASHACCOUNT;
|
|
93
|
+
}
|
|
94
|
+
// console.dir(sap_payment, { depth: null });
|
|
95
|
+
actionLog.addDetail(`Repzo => SAP: Payment - ${repzo_serial_number}`, sap_payment);
|
|
96
|
+
const result = await _create(SAP_HOST_URL, "/AddPayment", sap_payment);
|
|
97
|
+
// console.log(result);
|
|
98
|
+
try {
|
|
99
|
+
await repzo.updateIntegrationMeta.create([{ key: "sync_to_sap_succeeded", value: true }], { _id: body._id, type: "payments" });
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
console.error(e);
|
|
103
|
+
}
|
|
104
|
+
await actionLog
|
|
105
|
+
.addDetail(`SAP Responded with `, result)
|
|
106
|
+
.addDetail(`Repzo => SAP: Payment - ${repzo_serial_number}`)
|
|
107
|
+
.setStatus("success")
|
|
108
|
+
.setBody(repzo_payment)
|
|
109
|
+
.commit();
|
|
110
|
+
return result;
|
|
131
111
|
}
|
|
132
|
-
|
|
133
|
-
// bank
|
|
134
|
-
//@ts-ignore
|
|
135
|
-
const repzo_bank = await repzo.bank.get(
|
|
136
|
-
(_j = repzo_payment.check) === null || _j === void 0 ? void 0 : _j.bank
|
|
137
|
-
);
|
|
138
|
-
if (!repzo_bank) {
|
|
112
|
+
catch (e) {
|
|
139
113
|
//@ts-ignore
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
sap_payment.ChequeAccount =
|
|
144
|
-
(_k =
|
|
145
|
-
repzo_rep === null || repzo_rep === void 0
|
|
146
|
-
? void 0
|
|
147
|
-
: repzo_rep.integration_meta) === null || _k === void 0
|
|
148
|
-
? void 0
|
|
149
|
-
: _k.USERCHECKACCTCODE;
|
|
150
|
-
sap_payment.ChequeDate = moment(
|
|
151
|
-
(_l = repzo_payment.check) === null || _l === void 0
|
|
152
|
-
? void 0
|
|
153
|
-
: _l.check_date,
|
|
154
|
-
"YYYY-MM-DD"
|
|
155
|
-
).format("YYYYMMDD");
|
|
156
|
-
sap_payment.ChequeNumber =
|
|
157
|
-
(_m = repzo_payment.check) === null || _m === void 0
|
|
158
|
-
? void 0
|
|
159
|
-
: _m.check_number;
|
|
160
|
-
sap_payment.BankCode =
|
|
161
|
-
(_o = repzo_bank.integration_meta) === null || _o === void 0
|
|
162
|
-
? void 0
|
|
163
|
-
: _o.BANKCODE;
|
|
164
|
-
sap_payment.CountryCode =
|
|
165
|
-
(_p = repzo_bank.integration_meta) === null || _p === void 0
|
|
166
|
-
? void 0
|
|
167
|
-
: _p.COUNTRY;
|
|
168
|
-
} else if (repzo_payment.payment_type == "cash") {
|
|
169
|
-
sap_payment.PaymentType = "1";
|
|
170
|
-
sap_payment.CashAccount =
|
|
171
|
-
(_q =
|
|
172
|
-
repzo_rep === null || repzo_rep === void 0
|
|
173
|
-
? void 0
|
|
174
|
-
: repzo_rep.integration_meta) === null || _q === void 0
|
|
175
|
-
? void 0
|
|
176
|
-
: _q.USERCASHACCOUNT;
|
|
177
|
-
}
|
|
178
|
-
// console.dir(sap_payment, { depth: null });
|
|
179
|
-
actionLog.addDetail(
|
|
180
|
-
`Repzo => SAP: Payment - ${repzo_serial_number}`,
|
|
181
|
-
sap_payment
|
|
182
|
-
);
|
|
183
|
-
const result = await _create(SAP_HOST_URL, "/AddPayment", sap_payment);
|
|
184
|
-
// console.log(result);
|
|
185
|
-
try {
|
|
186
|
-
await repzo.updateIntegrationMeta.create(
|
|
187
|
-
[{ key: "sync_to_sap_succeeded", value: true }],
|
|
188
|
-
{ _id: body._id, type: "payments" }
|
|
189
|
-
);
|
|
190
|
-
} catch (e) {
|
|
191
|
-
console.error(e);
|
|
114
|
+
console.error((e === null || e === void 0 ? void 0 : e.response) || e);
|
|
115
|
+
await actionLog.setStatus("fail", e).setBody(body).commit();
|
|
116
|
+
throw e;
|
|
192
117
|
}
|
|
193
|
-
await actionLog
|
|
194
|
-
.addDetail(`SAP Responded with `, result)
|
|
195
|
-
.addDetail(`Repzo => SAP: Payment - ${repzo_serial_number}`)
|
|
196
|
-
.setStatus("success")
|
|
197
|
-
.setBody(repzo_payment)
|
|
198
|
-
.commit();
|
|
199
|
-
return result;
|
|
200
|
-
} catch (e) {
|
|
201
|
-
//@ts-ignore
|
|
202
|
-
console.error((e === null || e === void 0 ? void 0 : e.response) || e);
|
|
203
|
-
await actionLog.setStatus("fail", e).setBody(body).commit();
|
|
204
|
-
throw e;
|
|
205
|
-
}
|
|
206
118
|
};
|