repzo-sap-absjo 1.0.30 → 1.0.32
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 +1 -2
- package/lib/actions/create_invoice.js +1 -0
- package/lib/actions/create_payment.js +66 -31
- package/lib/actions/create_return_invoice.js +1 -0
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +4 -2
- package/src/actions/create_payment.ts +28 -6
- package/src/actions/create_return_invoice.ts +3 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EVENT, Config } from "../types";
|
|
2
|
-
interface SAPOpenInvoice {
|
|
2
|
+
export interface SAPOpenInvoice {
|
|
3
3
|
CustomerNumber: string;
|
|
4
4
|
FatherCode: string;
|
|
5
5
|
DocDate: string;
|
|
@@ -23,4 +23,3 @@ export declare const get_invoice_from_sap: (
|
|
|
23
23
|
InvoiceId: string;
|
|
24
24
|
}
|
|
25
25
|
) => Promise<SAPOpenInvoice[]>;
|
|
26
|
-
export {};
|
|
@@ -4,7 +4,7 @@ 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
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
8
8
|
const repzo = new Repzo(
|
|
9
9
|
(_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
|
|
10
10
|
{ env: options.env }
|
|
@@ -96,35 +96,70 @@ export const create_payment = async (event, options) => {
|
|
|
96
96
|
? void 0
|
|
97
97
|
: repzo_payment.LinkedTxn
|
|
98
98
|
) {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
(_g =
|
|
104
|
-
(_f =
|
|
105
|
-
repzo_payment === null || repzo_payment === void 0
|
|
106
|
-
? void 0
|
|
107
|
-
: repzo_payment.LinkedTxn) === null || _f === void 0
|
|
99
|
+
const repzo_inv_serial_number =
|
|
100
|
+
(_g =
|
|
101
|
+
(_f =
|
|
102
|
+
repzo_payment === null || repzo_payment === void 0
|
|
108
103
|
? void 0
|
|
109
|
-
:
|
|
104
|
+
: repzo_payment.LinkedTxn) === null || _f === void 0
|
|
110
105
|
? void 0
|
|
111
|
-
: _g
|
|
106
|
+
: _f.Txn_serial_number) === null || _g === void 0
|
|
107
|
+
? void 0
|
|
108
|
+
: _g.formatted;
|
|
109
|
+
const repzo_invoices = await repzo.invoice.find({
|
|
110
|
+
"serial_number.formatted": repzo_inv_serial_number,
|
|
112
111
|
});
|
|
112
|
+
const repzo_invoice =
|
|
113
|
+
(_h =
|
|
114
|
+
repzo_invoices === null || repzo_invoices === void 0
|
|
115
|
+
? void 0
|
|
116
|
+
: repzo_invoices.data) === null || _h === void 0
|
|
117
|
+
? void 0
|
|
118
|
+
: _h.find((inv) => {
|
|
119
|
+
var _a;
|
|
120
|
+
return (
|
|
121
|
+
((_a = inv.serial_number) === null || _a === void 0
|
|
122
|
+
? void 0
|
|
123
|
+
: _a.formatted) == repzo_inv_serial_number
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
if (!repzo_invoice) {
|
|
127
|
+
throw `Invoice with serial number: ${repzo_inv_serial_number} was not found on Repzo`;
|
|
128
|
+
}
|
|
129
|
+
let sap_open_invoices = [];
|
|
130
|
+
if (repzo_invoice.advanced_serial_number) {
|
|
131
|
+
sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
|
|
132
|
+
updatedAt: "",
|
|
133
|
+
Status: "",
|
|
134
|
+
InvoiceId: repzo_invoice.advanced_serial_number,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
113
137
|
if (
|
|
114
138
|
!(sap_open_invoices === null || sap_open_invoices === void 0
|
|
115
139
|
? void 0
|
|
116
140
|
: sap_open_invoices.length)
|
|
117
141
|
) {
|
|
118
|
-
|
|
142
|
+
sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
|
|
143
|
+
updatedAt: "",
|
|
144
|
+
Status: "",
|
|
145
|
+
InvoiceId: repzo_inv_serial_number,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (
|
|
149
|
+
!(sap_open_invoices === null || sap_open_invoices === void 0
|
|
150
|
+
? void 0
|
|
151
|
+
: sap_open_invoices.length)
|
|
152
|
+
) {
|
|
153
|
+
throw `Invoice with serial number: ${repzo_inv_serial_number} & advance serial number: ${repzo_invoice.advanced_serial_number} was not found on SAP or was closed`;
|
|
119
154
|
}
|
|
120
155
|
sap_payment.InvoiceID = sap_open_invoices[0].InvoiceID;
|
|
121
156
|
sap_payment.InvoiceTotal =
|
|
122
|
-
((
|
|
157
|
+
((_j =
|
|
123
158
|
repzo_payment === null || repzo_payment === void 0
|
|
124
159
|
? void 0
|
|
125
|
-
: repzo_payment.LinkedTxn) === null ||
|
|
160
|
+
: repzo_payment.LinkedTxn) === null || _j === void 0
|
|
126
161
|
? void 0
|
|
127
|
-
:
|
|
162
|
+
: _j.Txn_invoice_total) / 1000;
|
|
128
163
|
} else {
|
|
129
164
|
sap_payment.InvoiceID = "";
|
|
130
165
|
sap_payment.InvoiceTotal = "";
|
|
@@ -133,7 +168,7 @@ export const create_payment = async (event, options) => {
|
|
|
133
168
|
// bank
|
|
134
169
|
//@ts-ignore
|
|
135
170
|
const repzo_bank = await repzo.bank.get(
|
|
136
|
-
(
|
|
171
|
+
(_k = repzo_payment.check) === null || _k === void 0 ? void 0 : _k.bank
|
|
137
172
|
);
|
|
138
173
|
if (!repzo_bank) {
|
|
139
174
|
//@ts-ignore
|
|
@@ -141,39 +176,39 @@ export const create_payment = async (event, options) => {
|
|
|
141
176
|
}
|
|
142
177
|
sap_payment.PaymentType = "2";
|
|
143
178
|
sap_payment.ChequeAccount =
|
|
144
|
-
(
|
|
179
|
+
(_l =
|
|
145
180
|
repzo_rep === null || repzo_rep === void 0
|
|
146
181
|
? void 0
|
|
147
|
-
: repzo_rep.integration_meta) === null ||
|
|
182
|
+
: repzo_rep.integration_meta) === null || _l === void 0
|
|
148
183
|
? void 0
|
|
149
|
-
:
|
|
184
|
+
: _l.USERCHECKACCTCODE;
|
|
150
185
|
sap_payment.ChequeDate = moment(
|
|
151
|
-
(
|
|
186
|
+
(_m = repzo_payment.check) === null || _m === void 0
|
|
152
187
|
? void 0
|
|
153
|
-
:
|
|
188
|
+
: _m.check_date,
|
|
154
189
|
"YYYY-MM-DD"
|
|
155
190
|
).format("YYYYMMDD");
|
|
156
191
|
sap_payment.ChequeNumber =
|
|
157
|
-
(
|
|
192
|
+
(_o = repzo_payment.check) === null || _o === void 0
|
|
158
193
|
? void 0
|
|
159
|
-
:
|
|
194
|
+
: _o.check_number;
|
|
160
195
|
sap_payment.BankCode =
|
|
161
|
-
(
|
|
196
|
+
(_p = repzo_bank.integration_meta) === null || _p === void 0
|
|
162
197
|
? void 0
|
|
163
|
-
:
|
|
198
|
+
: _p.BANKCODE;
|
|
164
199
|
sap_payment.CountryCode =
|
|
165
|
-
(
|
|
200
|
+
(_q = repzo_bank.integration_meta) === null || _q === void 0
|
|
166
201
|
? void 0
|
|
167
|
-
:
|
|
202
|
+
: _q.COUNTRY;
|
|
168
203
|
} else if (repzo_payment.payment_type == "cash") {
|
|
169
204
|
sap_payment.PaymentType = "1";
|
|
170
205
|
sap_payment.CashAccount =
|
|
171
|
-
(
|
|
206
|
+
(_r =
|
|
172
207
|
repzo_rep === null || repzo_rep === void 0
|
|
173
208
|
? void 0
|
|
174
|
-
: repzo_rep.integration_meta) === null ||
|
|
209
|
+
: repzo_rep.integration_meta) === null || _r === void 0
|
|
175
210
|
? void 0
|
|
176
|
-
:
|
|
211
|
+
: _r.USERCASHACCOUNT;
|
|
177
212
|
}
|
|
178
213
|
// console.dir(sap_payment, { depth: null });
|
|
179
214
|
actionLog.addDetail(
|
|
@@ -271,6 +271,7 @@ export const create_return_invoice = async (event, options) => {
|
|
|
271
271
|
});
|
|
272
272
|
}
|
|
273
273
|
const sap_return_invoice = {
|
|
274
|
+
RepzoSerial: repzo_invoice.serial_number.formatted,
|
|
274
275
|
RefNum:
|
|
275
276
|
repzo_invoice.advanced_serial_number ||
|
|
276
277
|
repzo_invoice.serial_number.formatted,
|
package/package.json
CHANGED
|
@@ -26,7 +26,8 @@ interface SAPInvoiceItem {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
interface SAPInvoice {
|
|
29
|
-
|
|
29
|
+
RepzoSerial: string; // serial_number.formatted: "INV-1021-4"
|
|
30
|
+
RefNum: string; // advanced_serial_number || serial_number.formatted: "INV-1021-4",
|
|
30
31
|
SalPersCode?: string; // "106", // Required
|
|
31
32
|
DocDate: string; // "20211229",
|
|
32
33
|
DocDueDate: string; // "20211229",
|
|
@@ -38,7 +39,7 @@ interface SAPInvoice {
|
|
|
38
39
|
U_ISTDQR?: string;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
interface SAPOpenInvoice {
|
|
42
|
+
export interface SAPOpenInvoice {
|
|
42
43
|
CustomerNumber: string; // "400065-53";
|
|
43
44
|
FatherCode: string; // "400065";
|
|
44
45
|
DocDate: string; // "2022-12-14T21:00:00Z";
|
|
@@ -285,6 +286,7 @@ export const create_invoice = async (event: EVENT, options: Config) => {
|
|
|
285
286
|
}
|
|
286
287
|
|
|
287
288
|
const sap_invoice: SAPInvoice = {
|
|
289
|
+
RepzoSerial: repzo_invoice.serial_number.formatted,
|
|
288
290
|
RefNum:
|
|
289
291
|
repzo_invoice.advanced_serial_number ||
|
|
290
292
|
repzo_invoice.serial_number.formatted,
|
|
@@ -4,7 +4,7 @@ import { _fetch, _create, _update, _delete } from "../util.js";
|
|
|
4
4
|
import { Service } from "repzo/src/types";
|
|
5
5
|
import { v4 as uuid } from "uuid";
|
|
6
6
|
import moment from "moment-timezone";
|
|
7
|
-
import { get_invoice_from_sap } from "./create_invoice.js";
|
|
7
|
+
import { get_invoice_from_sap, SAPOpenInvoice } from "./create_invoice.js";
|
|
8
8
|
|
|
9
9
|
interface SAPPayment {
|
|
10
10
|
PaymentID: string; // "PAY-1041-3";
|
|
@@ -87,13 +87,35 @@ export const create_payment = async (event: EVENT, options: Config) => {
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
if (repzo_payment?.LinkedTxn) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
const repzo_inv_serial_number =
|
|
91
|
+
repzo_payment?.LinkedTxn?.Txn_serial_number?.formatted;
|
|
92
|
+
const repzo_invoices = await repzo.invoice.find({
|
|
93
|
+
"serial_number.formatted": repzo_inv_serial_number,
|
|
94
94
|
});
|
|
95
|
+
const repzo_invoice = repzo_invoices?.data?.find(
|
|
96
|
+
(inv) => inv.serial_number?.formatted == repzo_inv_serial_number
|
|
97
|
+
);
|
|
98
|
+
if (!repzo_invoice) {
|
|
99
|
+
throw `Invoice with serial number: ${repzo_inv_serial_number} was not found on Repzo`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let sap_open_invoices: SAPOpenInvoice[] = [];
|
|
103
|
+
if (repzo_invoice.advanced_serial_number) {
|
|
104
|
+
sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
|
|
105
|
+
updatedAt: "",
|
|
106
|
+
Status: "",
|
|
107
|
+
InvoiceId: repzo_invoice.advanced_serial_number,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (!sap_open_invoices?.length) {
|
|
111
|
+
sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
|
|
112
|
+
updatedAt: "",
|
|
113
|
+
Status: "",
|
|
114
|
+
InvoiceId: repzo_inv_serial_number,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
95
117
|
if (!sap_open_invoices?.length) {
|
|
96
|
-
throw `Invoice with serial number: ${
|
|
118
|
+
throw `Invoice with serial number: ${repzo_inv_serial_number} & advance serial number: ${repzo_invoice.advanced_serial_number} was not found on SAP or was closed`;
|
|
97
119
|
}
|
|
98
120
|
sap_payment.InvoiceID = sap_open_invoices[0].InvoiceID;
|
|
99
121
|
sap_payment.InvoiceTotal =
|
|
@@ -19,7 +19,8 @@ interface SAPInvoiceItem {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
interface SAPInvoice {
|
|
22
|
-
|
|
22
|
+
RepzoSerial: string; // serial_number.formatted: "INV-1021-4"
|
|
23
|
+
RefNum: string; // advanced_serial_number || serial_number.formatted: "INV-1021-4",
|
|
23
24
|
SalPersCode?: string; // "106", // Required
|
|
24
25
|
DocDate: string; // "20211229",
|
|
25
26
|
DocDueDate: string; // "20211229",
|
|
@@ -208,6 +209,7 @@ export const create_return_invoice = async (event: EVENT, options: Config) => {
|
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
const sap_return_invoice: SAPInvoice = {
|
|
212
|
+
RepzoSerial: repzo_invoice.serial_number.formatted,
|
|
211
213
|
RefNum:
|
|
212
214
|
repzo_invoice.advanced_serial_number ||
|
|
213
215
|
repzo_invoice.serial_number.formatted,
|