-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
81 lines (69 loc) · 2.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
const { soap } = require("strong-soap");
const UYUMSOFT_WSDL_URL =
"https://efatura-test.uyumsoft.com.tr/Services/Integration?wsdl";
const UYUMSOFT_USERNAME = "Uyumsoft";
const UYUMSOFT_PASSWORD = "Uyumsoft";
function createSoapClient(wsdlUrl, username, password) {
return new Promise((resolve, reject) => {
soap.createClient(wsdlUrl, {}, (err, client) => {
if (err) {
reject(err);
return;
}
const wsSecurity = new soap.WSSecurity(username, password);
client.setSecurity(wsSecurity);
resolve(client);
});
});
}
async function getInboxInvoices(client) {
const { GetInboxInvoices } = client;
const { result, envelope, soapHeader } = await GetInboxInvoices({
query: {
PageIndex: 0,
PageSize: 20,
ExecutionStartDate: null,
ExecutionEndDate: null,
// InvoiceIds: [],
// InvoiceNumbers: [],
SetTaken: false,
OnlyNewestInvoices: false,
},
});
if (result?.GetInboxInvoicesResult?.$attributes?.IsSucceded !== "true") {
return undefined;
}
return result.GetInboxInvoicesResult.Value;
}
async function main() {
console.log("Creating SOAP client...");
const client = await createSoapClient(
UYUMSOFT_WSDL_URL,
UYUMSOFT_USERNAME,
UYUMSOFT_PASSWORD
);
console.log("Fetching invoice list...");
const invoiceList = await getInboxInvoices(client);
if (invoiceList == null) {
console.error("Invoice list cannot be fetched");
return;
}
const invoiceSummaryList = invoiceList.Items.map((item) => {
const {
IssueDate,
AccountingSupplierParty,
AccountingCustomerParty,
LegalMonetaryTotal: { PayableAmount },
} = item.Invoice;
return {
"Issue Date": IssueDate,
"Accounting Supplier Party": AccountingSupplierParty.Party.PartyName.Name,
"Accounting Customer Party": AccountingCustomerParty.Party.PartyName.Name,
Amount: `${PayableAmount.$value} ${PayableAmount.$attributes.currencyID}`,
};
});
console.log("Invoices:");
console.table(invoiceSummaryList);
console.log("Done.");
}
main();