kassza 0.12.0 → 0.14.0
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/README.en.md +48 -0
- package/README.md +427 -32
- package/agents/README.md +26 -6
- package/agents/api.md +218 -3
- package/agents/pitfalls.md +27 -3
- package/agents/recipes.md +280 -51
- package/agents/skills/kassza/SKILL.md +14 -8
- package/agents/skills/migrate-from-szamlazz-js/SKILL.md +39 -0
- package/dist/batch/index.cjs +346 -0
- package/dist/batch/index.d.cts +91 -0
- package/dist/batch/index.d.ts +91 -0
- package/dist/batch/index.js +339 -0
- package/dist/cli.cjs +643 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +643 -0
- package/dist/client-CLFvJCVW.cjs +1452 -0
- package/dist/{client-CL3fuH6A.js → client-Cvf-hTz_.js} +306 -515
- package/dist/client-DeWWQ-RZ.d.ts +341 -0
- package/dist/client-SVZu25MB.d.cts +341 -0
- package/dist/context-CFNKzStE.d.cts +449 -0
- package/dist/context-kb33TgzE.d.ts +449 -0
- package/dist/cookie-stores/index.cjs +21 -150
- package/dist/cookie-stores/index.d.cts +4 -63
- package/dist/cookie-stores/index.d.ts +4 -63
- package/dist/cookie-stores/index.js +3 -144
- package/dist/create-CflXrPip.js +204 -0
- package/dist/create-CvUvLUaT.cjs +257 -0
- package/dist/{create-once-D0pwuenl.cjs → create-once-9yxR_Er_.cjs} +291 -33
- package/dist/create-once-Bh6fOWkW.d.cts +20 -0
- package/dist/{create-once-CqdYmQD8.js → create-once-Ca2gMk1h.js} +250 -34
- package/dist/create-once-VKp0tVow.d.ts +20 -0
- package/dist/{crypto-B8lERvR1.cjs → crypto-Dpn4FHQ6.cjs} +9 -0
- package/dist/{crypto-DK_osBVy.js → crypto-usDg8L2K.js} +4 -1
- package/dist/data-link/index.cjs +232 -0
- package/dist/data-link/index.d.cts +29 -0
- package/dist/data-link/index.d.ts +29 -0
- package/dist/data-link/index.js +224 -0
- package/dist/delegation/index.cjs +35 -34
- package/dist/delegation/index.d.cts +2 -1
- package/dist/delegation/index.d.ts +2 -1
- package/dist/delegation/index.js +4 -3
- package/dist/{errors-DLrb0g64.js → errors-DtN4g5Z9.js} +9 -1
- package/dist/{errors-DxeuTslP.cjs → errors-EE96_6D_.cjs} +20 -0
- package/dist/get-BdMTseh4.cjs +271 -0
- package/dist/get-Byc9T5WO.d.cts +151 -0
- package/dist/get-Byc9T5WO.d.ts +151 -0
- package/dist/get-CZEShCcj.js +260 -0
- package/dist/index-BhUPY_EH.d.cts +109 -0
- package/dist/index-BqGgQ4t3.d.ts +109 -0
- package/dist/{index-CYAGCdKJ.d.cts → index-C-7yWV7L.d.cts} +24 -1
- package/dist/{index-CYAGCdKJ.d.ts → index-C-7yWV7L.d.ts} +24 -1
- package/dist/index.cjs +19 -5
- package/dist/index.d.cts +11 -19
- package/dist/index.d.ts +11 -19
- package/dist/index.js +6 -6
- package/dist/ipn/index.cjs +26 -5
- package/dist/ipn/index.d.cts +12 -1
- package/dist/ipn/index.d.ts +12 -1
- package/dist/ipn/index.js +26 -6
- package/dist/issue-Bin4tKD_.cjs +988 -0
- package/dist/issue-DMA1Nbr1.js +905 -0
- package/dist/journal/index.cjs +454 -0
- package/dist/journal/index.d.cts +18 -0
- package/dist/journal/index.d.ts +18 -0
- package/dist/journal/index.js +445 -0
- package/dist/journal-DvI81Kt7.d.cts +114 -0
- package/dist/journal-Y9qrIB8G.d.ts +114 -0
- package/dist/mcp/index.cjs +10 -0
- package/dist/mcp/index.d.cts +71 -0
- package/dist/mcp/index.d.ts +71 -0
- package/dist/mcp/index.js +2 -0
- package/dist/money/index.cjs +2 -1
- package/dist/money/index.d.cts +2 -2
- package/dist/money/index.d.ts +2 -2
- package/dist/money/index.js +2 -2
- package/dist/{money-DAA7OwiO.js → money-Cw457SD6.js} +120 -12
- package/dist/{money-DrhGkWHW.cjs → money-K9j0wPit.cjs} +124 -10
- package/dist/nav/index.cjs +1046 -0
- package/dist/nav/index.d.cts +247 -0
- package/dist/nav/index.d.ts +247 -0
- package/dist/nav/index.js +1012 -0
- package/dist/nav-BNbc8U0R.cjs +203 -0
- package/dist/nav-BcCerwWS.js +156 -0
- package/dist/node/index.cjs +124 -0
- package/dist/node/index.d.cts +35 -0
- package/dist/node/index.d.ts +35 -0
- package/dist/node/index.js +120 -0
- package/dist/observe/index.cjs +311 -0
- package/dist/observe/index.d.cts +53 -0
- package/dist/observe/index.d.ts +53 -0
- package/dist/observe/index.js +303 -0
- package/dist/once-BN_3B5OF.cjs +103 -0
- package/dist/once-CqqZxsXG.js +74 -0
- package/dist/parse-Cr7yQ3_z.js +291 -0
- package/dist/parse-DOA2XQ3e.cjs +380 -0
- package/dist/payments/barion.cjs +26 -2
- package/dist/payments/barion.d.cts +2 -2
- package/dist/payments/barion.d.ts +2 -2
- package/dist/payments/barion.js +26 -2
- package/dist/payments/index.cjs +7 -2
- package/dist/payments/index.d.cts +4 -4
- package/dist/payments/index.d.ts +4 -4
- package/dist/payments/index.js +3 -3
- package/dist/payments/paypal.cjs +16 -2
- package/dist/payments/paypal.d.cts +2 -2
- package/dist/payments/paypal.d.ts +2 -2
- package/dist/payments/paypal.js +16 -2
- package/dist/payments/revolut.cjs +17 -3
- package/dist/payments/revolut.d.cts +2 -2
- package/dist/payments/revolut.d.ts +2 -2
- package/dist/payments/revolut.js +17 -3
- package/dist/payments/simplepay.cjs +37 -5
- package/dist/payments/simplepay.d.cts +2 -2
- package/dist/payments/simplepay.d.ts +2 -2
- package/dist/payments/simplepay.js +37 -5
- package/dist/payments/stripe.cjs +20 -3
- package/dist/payments/stripe.d.cts +2 -2
- package/dist/payments/stripe.d.ts +2 -2
- package/dist/payments/stripe.js +20 -3
- package/dist/push-BXj0Sf0Z.d.ts +52 -0
- package/dist/push-D4nNbCNV.d.cts +52 -0
- package/dist/reference-B5TATqb5.js +124 -0
- package/dist/reference-BIdYMK0t.cjs +183 -0
- package/dist/reports/index.cjs +11 -164
- package/dist/reports/index.d.cts +1 -1
- package/dist/reports/index.d.ts +1 -1
- package/dist/reports/index.js +1 -154
- package/dist/request-body-CH6ZGOrq.cjs +34 -0
- package/dist/request-body-uZHMRlQr.js +29 -0
- package/dist/serialize-B2eFh3D-.js +219 -0
- package/dist/serialize-CquIsxA-.cjs +290 -0
- package/dist/server-BrJUbXs7.js +1505 -0
- package/dist/server-Dw9j8Mnd.cjs +1558 -0
- package/dist/session-Ckl5eJhV.d.ts +7 -0
- package/dist/{session-CKOuE6Jc.cjs → session-DeM5vjvC.cjs} +69 -13
- package/dist/{session-rMKaJcmq.js → session-SaEEXu2N.js} +58 -14
- package/dist/session-YbChChx7.d.cts +7 -0
- package/dist/storage/fs.cjs +1 -1
- package/dist/storage/fs.js +1 -1
- package/dist/storage/index.cjs +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/store-C1rHd9DB.d.cts +19 -0
- package/dist/store-C1rHd9DB.d.ts +19 -0
- package/dist/stores/index.cjs +24 -0
- package/dist/stores/index.d.cts +4 -0
- package/dist/stores/index.d.ts +4 -0
- package/dist/stores/index.js +3 -0
- package/dist/stores-BNrS0dWl.cjs +506 -0
- package/dist/stores-DhjGBrl_.js +441 -0
- package/dist/testing/index.cjs +1500 -15
- package/dist/testing/index.d.cts +198 -3
- package/dist/testing/index.d.ts +198 -3
- package/dist/testing/index.js +1498 -15
- package/dist/{types-COf1LAD-.d.ts → types-B1A8mUIE.d.cts} +14 -2
- package/dist/{types-COf1LAD-.d.cts → types-ByAEvGsZ.d.ts} +14 -2
- package/dist/{types-k--zHf4l.d.ts → types-D1zDOH_F.d.ts} +1 -1
- package/dist/{types-DH8QoNZK.d.cts → types-lnKkQdot.d.cts} +1 -1
- package/dist/warnings-B3DXnveC.d.cts +31 -0
- package/dist/warnings-B3DXnveC.d.ts +31 -0
- package/dist/warnings-DeIw5RFj.cjs +20 -0
- package/dist/warnings-DwTl5J-2.js +15 -0
- package/dist/{webhook-D4lvtex1.js → webhook-CQVShAfI.js} +47 -26
- package/dist/{webhook-C76bV-4R.cjs → webhook-Ckj-_hPD.cjs} +70 -25
- package/dist/webhook-CmdhGiH5.d.cts +11 -0
- package/dist/webhook-D6lEejob.d.ts +11 -0
- package/llms.txt +6 -5
- package/package.json +134 -4
- package/dist/client-CickRRFr.d.ts +0 -838
- package/dist/client-CsmGIFRS.cjs +0 -1637
- package/dist/client-DvWZoX_E.d.cts +0 -838
- package/dist/issue-BsyYdrIG.cjs +0 -1531
- package/dist/issue-C6Fcjvln.js +0 -1274
- package/dist/session-Dm_45x8K.d.cts +0 -11
- package/dist/session-Dm_45x8K.d.ts +0 -11
- package/dist/webhook-CfaDgcL0.d.cts +0 -6
- package/dist/webhook-q2OzNwd7.d.ts +0 -6
package/dist/testing/index.cjs
CHANGED
|
@@ -1,9 +1,1481 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_create_once = require("../create-once-
|
|
3
|
-
const require_errors = require("../errors-
|
|
4
|
-
const
|
|
2
|
+
const require_create_once = require("../create-once-9yxR_Er_.cjs");
|
|
3
|
+
const require_errors = require("../errors-EE96_6D_.cjs");
|
|
4
|
+
const require_binary = require("../binary-B89HM03_.cjs");
|
|
5
|
+
const require_serialize = require("../serialize-CquIsxA-.cjs");
|
|
6
|
+
const require_issue = require("../issue-Bin4tKD_.cjs");
|
|
5
7
|
const require_dates = require("../dates-CPgBodkP.cjs");
|
|
6
|
-
const
|
|
8
|
+
const require_rounding = require("../rounding-TxoWy2ww.cjs");
|
|
9
|
+
const require_vat = require("../vat-g35srbNG.cjs");
|
|
10
|
+
const require_money = require("../money-K9j0wPit.cjs");
|
|
11
|
+
const require_create = require("../create-CvUvLUaT.cjs");
|
|
12
|
+
//#region src/testing/fake-agent-http.ts
|
|
13
|
+
const XML_CONTENT_TYPE = "application/xml; charset=UTF-8";
|
|
14
|
+
const TEXT_CONTENT_TYPE = "text/plain; charset=UTF-8";
|
|
15
|
+
const PDF_CONTENT_TYPE = "application/pdf";
|
|
16
|
+
const ERROR_ROOTS = {
|
|
17
|
+
invoice: "xmlszamlavalasz",
|
|
18
|
+
receipt: "xmlnyugtavalasz",
|
|
19
|
+
"receipt-send": "xmlnyugtasendvalasz",
|
|
20
|
+
proforma: "xmlszamladbkdelvalasz"
|
|
21
|
+
};
|
|
22
|
+
function encodeHeaderValue(value) {
|
|
23
|
+
return encodeURIComponent(value).replace(/%20/g, "+");
|
|
24
|
+
}
|
|
25
|
+
function xmlResponse(xml, headers = {}) {
|
|
26
|
+
return {
|
|
27
|
+
status: 200,
|
|
28
|
+
headers: {
|
|
29
|
+
"content-type": XML_CONTENT_TYPE,
|
|
30
|
+
...headers
|
|
31
|
+
},
|
|
32
|
+
body: xml
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function textResponse(text, headers = {}, status = 200) {
|
|
36
|
+
return {
|
|
37
|
+
status,
|
|
38
|
+
headers: {
|
|
39
|
+
"content-type": TEXT_CONTENT_TYPE,
|
|
40
|
+
...headers
|
|
41
|
+
},
|
|
42
|
+
body: text
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function pdfResponse(pdf, headers = {}) {
|
|
46
|
+
return {
|
|
47
|
+
status: 200,
|
|
48
|
+
headers: {
|
|
49
|
+
"content-type": PDF_CONTENT_TYPE,
|
|
50
|
+
...headers
|
|
51
|
+
},
|
|
52
|
+
body: pdf
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function serverErrorResponse() {
|
|
56
|
+
return {
|
|
57
|
+
status: 500,
|
|
58
|
+
headers: { "content-type": "text/html; charset=UTF-8" },
|
|
59
|
+
body: "<!DOCTYPE html><html><body><h1>500 Internal Server Error</h1></body></html>"
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function namespaceOf(root) {
|
|
63
|
+
return `http://www.szamlazz.hu/${root}`;
|
|
64
|
+
}
|
|
65
|
+
function xmlDocument(root, children) {
|
|
66
|
+
return require_serialize.buildXmlDocument({
|
|
67
|
+
root,
|
|
68
|
+
namespace: namespaceOf(root),
|
|
69
|
+
children
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function errorHeaders(failure) {
|
|
73
|
+
return {
|
|
74
|
+
szlahu_error: encodeHeaderValue(failure.message),
|
|
75
|
+
...failure.code === void 0 ? {} : { szlahu_error_code: String(failure.code) }
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function errorText(failure) {
|
|
79
|
+
return `[ERR] ${failure.code === void 0 ? "" : `[${failure.code}] `}${failure.message}\n----------\nkassza hamis Agent\n`;
|
|
80
|
+
}
|
|
81
|
+
function errorResponse(style, failure) {
|
|
82
|
+
if (style === "text") return textResponse(errorText(failure), errorHeaders(failure));
|
|
83
|
+
return xmlResponse(xmlDocument(ERROR_ROOTS[style], [
|
|
84
|
+
require_serialize.el("sikeres", false),
|
|
85
|
+
require_serialize.optionalEl("hibakod", failure.code),
|
|
86
|
+
require_serialize.el("hibauzenet", failure.message)
|
|
87
|
+
]), style === "invoice" ? errorHeaders(failure) : {});
|
|
88
|
+
}
|
|
89
|
+
function invoiceResultHeaders(fields) {
|
|
90
|
+
const headers = {};
|
|
91
|
+
if (fields.number !== void 0) headers.szlahu_szamlaszam = encodeHeaderValue(fields.number);
|
|
92
|
+
if (fields.netTotal !== void 0) headers.szlahu_nettovegosszeg = require_serialize.formatXmlNumber(fields.netTotal);
|
|
93
|
+
if (fields.grossTotal !== void 0) headers.szlahu_bruttovegosszeg = require_serialize.formatXmlNumber(fields.grossTotal);
|
|
94
|
+
if (fields.outstanding !== void 0) headers.szlahu_kintlevoseg = require_serialize.formatXmlNumber(fields.outstanding);
|
|
95
|
+
if (fields.paymentMethod !== void 0) headers.szlahu_fizetesmod = encodeHeaderValue(fields.paymentMethod);
|
|
96
|
+
return headers;
|
|
97
|
+
}
|
|
98
|
+
function invoiceResultResponse(fields, version) {
|
|
99
|
+
const headers = invoiceResultHeaders(fields);
|
|
100
|
+
if (version === 2) return xmlResponse(xmlDocument("xmlszamlavalasz", [
|
|
101
|
+
require_serialize.el("sikeres", true),
|
|
102
|
+
require_serialize.optionalEl("szamlaszam", fields.number),
|
|
103
|
+
require_serialize.optionalEl("szamlanetto", fields.netTotal),
|
|
104
|
+
require_serialize.optionalEl("szamlabrutto", fields.grossTotal),
|
|
105
|
+
require_serialize.optionalEl("kintlevoseg", fields.outstanding),
|
|
106
|
+
require_serialize.optionalEl("pdf", fields.pdf && require_binary.bytesToBase64(fields.pdf))
|
|
107
|
+
]), headers);
|
|
108
|
+
if (fields.pdf) return pdfResponse(fields.pdf, headers);
|
|
109
|
+
return textResponse(`xmlagentresponse=DONE${fields.number === void 0 ? "" : `;${fields.number}`}\n`, headers);
|
|
110
|
+
}
|
|
111
|
+
function toFetchResponse(response) {
|
|
112
|
+
const body = typeof response.body === "string" ? response.body : new Blob([response.body]);
|
|
113
|
+
return new Response(body, {
|
|
114
|
+
status: response.status,
|
|
115
|
+
headers: response.headers
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/testing/fake-agent-state.ts
|
|
120
|
+
var FakeAgentFailure = class extends Error {
|
|
121
|
+
name = "FakeAgentFailure";
|
|
122
|
+
code;
|
|
123
|
+
constructor(code, message) {
|
|
124
|
+
super(message);
|
|
125
|
+
this.code = code;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
function agentFailure(code, message) {
|
|
129
|
+
return new FakeAgentFailure(code, message ?? require_errors.AGENT_ERROR_CODES[code]?.message ?? `Hiba (${code}).`);
|
|
130
|
+
}
|
|
131
|
+
function nextCounter(state, key) {
|
|
132
|
+
const next = (state.counters.get(key) ?? 0) + 1;
|
|
133
|
+
state.counters.set(key, next);
|
|
134
|
+
return next;
|
|
135
|
+
}
|
|
136
|
+
function today(state) {
|
|
137
|
+
return require_dates.toBudapestDate(state.now());
|
|
138
|
+
}
|
|
139
|
+
function nextDocumentNumber(state, series) {
|
|
140
|
+
const year = today(state).slice(0, 4);
|
|
141
|
+
return `${series}-${year}-${nextCounter(state, `${series}|${year}`)}`;
|
|
142
|
+
}
|
|
143
|
+
function nextDocumentId(state) {
|
|
144
|
+
return nextCounter(state, "#id");
|
|
145
|
+
}
|
|
146
|
+
function fakePdf(label) {
|
|
147
|
+
return require_binary.encodeUtf8(`%PDF-1.4\n%kassza hamis Agent: ${label}\n%%EOF\n`);
|
|
148
|
+
}
|
|
149
|
+
function taxpayerKey(value) {
|
|
150
|
+
return value.replace(/\D/g, "").slice(0, 8);
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/testing/fake-agent-items.ts
|
|
154
|
+
const SERVER_VAT_CODES = /* @__PURE__ */ new Set([
|
|
155
|
+
"TAM",
|
|
156
|
+
"AAM",
|
|
157
|
+
"EU",
|
|
158
|
+
"EUK",
|
|
159
|
+
"MAA",
|
|
160
|
+
"F.AFA",
|
|
161
|
+
"K.AFA",
|
|
162
|
+
"ÁKK",
|
|
163
|
+
"TAHK",
|
|
164
|
+
"TEHK",
|
|
165
|
+
"EUT",
|
|
166
|
+
"EUKT",
|
|
167
|
+
"HO",
|
|
168
|
+
"EUE",
|
|
169
|
+
"EUFADE",
|
|
170
|
+
"EUFAD37",
|
|
171
|
+
"ATK",
|
|
172
|
+
"NAM",
|
|
173
|
+
"EAM",
|
|
174
|
+
"KBAUK",
|
|
175
|
+
"KBAET"
|
|
176
|
+
]);
|
|
177
|
+
const NUMERIC_RATES = new Set(require_vat.NUMERIC_VAT_RATES);
|
|
178
|
+
const AMOUNT_FIELDS = {
|
|
179
|
+
invoice: {
|
|
180
|
+
net: "nettoErtek",
|
|
181
|
+
vat: "afaErtek",
|
|
182
|
+
gross: "bruttoErtek"
|
|
183
|
+
},
|
|
184
|
+
receipt: {
|
|
185
|
+
net: "netto",
|
|
186
|
+
vat: "afa",
|
|
187
|
+
gross: "brutto"
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const HUF_TOLERANCE = 2;
|
|
191
|
+
const FOREIGN_TOLERANCE = .02;
|
|
192
|
+
const SUM_EPSILON = 1e-6;
|
|
193
|
+
const RECEIPT_DECIMALS = 2;
|
|
194
|
+
const TOTAL_DECIMALS = 6;
|
|
195
|
+
function xmlFailure(detail) {
|
|
196
|
+
return new FakeAgentFailure(57, `XML beolvasási hiba: ${detail}`);
|
|
197
|
+
}
|
|
198
|
+
function requiredText$2(element, name, position) {
|
|
199
|
+
const value = require_serialize.childText(element, name);
|
|
200
|
+
if (value === void 0) throw xmlFailure(`hiányzik a(z) ${position}. tétel <${name}> eleme.`);
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
function requiredNumber(element, name, position) {
|
|
204
|
+
const value = require_serialize.childNumber(element, name);
|
|
205
|
+
if (value === void 0) throw xmlFailure(`a(z) ${position}. tétel <${name}> eleme hiányzik vagy nem szám.`);
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
function parseVat(raw, itemName) {
|
|
209
|
+
const numeric = Number(raw.replace(",", "."));
|
|
210
|
+
if (Number.isFinite(numeric) && NUMERIC_RATES.has(numeric)) return { rate: numeric };
|
|
211
|
+
if (SERVER_VAT_CODES.has(raw)) return {
|
|
212
|
+
rate: 0,
|
|
213
|
+
code: raw
|
|
214
|
+
};
|
|
215
|
+
throw new FakeAgentFailure(395, `Érvénytelen áfakulcs: ${raw}. Termék: ${itemName}`);
|
|
216
|
+
}
|
|
217
|
+
function ledgerOf(element) {
|
|
218
|
+
const revenue = require_serialize.childText(element, "arbevetel");
|
|
219
|
+
const vat = require_serialize.childText(element, "afa");
|
|
220
|
+
return revenue === void 0 && vat === void 0 ? void 0 : {
|
|
221
|
+
revenue,
|
|
222
|
+
vat
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function parseItem(element, kind, position) {
|
|
226
|
+
const fields = AMOUNT_FIELDS[kind];
|
|
227
|
+
const name = requiredText$2(element, "megnevezes", position);
|
|
228
|
+
const vat = parseVat(requiredText$2(element, "afakulcs", position), name);
|
|
229
|
+
return {
|
|
230
|
+
name,
|
|
231
|
+
identifier: require_serialize.childText(element, "azonosito"),
|
|
232
|
+
quantity: requiredNumber(element, "mennyiseg", position),
|
|
233
|
+
unit: requiredText$2(element, "mennyisegiEgyseg", position),
|
|
234
|
+
netUnitPrice: requiredNumber(element, "nettoEgysegar", position),
|
|
235
|
+
vatRate: vat.rate,
|
|
236
|
+
vatCode: vat.code,
|
|
237
|
+
netAmount: requiredNumber(element, fields.net, position),
|
|
238
|
+
vatAmount: requiredNumber(element, fields.vat, position),
|
|
239
|
+
grossAmount: requiredNumber(element, fields.gross, position),
|
|
240
|
+
comment: require_serialize.childText(element, "megjegyzes"),
|
|
241
|
+
ledger: kind === "receipt" ? ledgerOf(require_serialize.findChild(element, "fokonyv")) : void 0
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function parseItems(root, kind) {
|
|
245
|
+
const elements = require_serialize.findChildren(require_serialize.findChild(root, "tetelek"), "tetel");
|
|
246
|
+
if (elements.length === 0) throw xmlFailure("legalább egy tételt (<tetel>) meg kell adni.");
|
|
247
|
+
return elements.map((element, index) => parseItem(element, kind, index + 1));
|
|
248
|
+
}
|
|
249
|
+
function amountFailure(code, item) {
|
|
250
|
+
return new FakeAgentFailure(code, `${{
|
|
251
|
+
259: "A tétel nettó értéke nem megfelelő; nettó érték = nettó egységár x mennyiség.",
|
|
252
|
+
260: "A tétel áfa értéke nem megfelelő; áfa érték = tétel nettó értéke x áfakulcs mértéke / 100.",
|
|
253
|
+
261: "A tétel bruttó értéke nem megfelelő; bruttó érték = tétel nettó értéke + tétel áfa értéke.",
|
|
254
|
+
363: "A tétel bruttó értékének egész számnak kell lennie.",
|
|
255
|
+
364: "A tétel nettó értéke maximum 2 tizedes jegyet tartalmazhat.",
|
|
256
|
+
365: "A tétel áfa értéke maximum 2 tizedes jegyet tartalmazhat."
|
|
257
|
+
}[code] ?? "Hibás tételösszeg."} Termék: ${item.name}`);
|
|
258
|
+
}
|
|
259
|
+
function netMismatch(item, tolerance) {
|
|
260
|
+
return Math.abs(item.netUnitPrice * item.quantity - item.netAmount) > tolerance;
|
|
261
|
+
}
|
|
262
|
+
function vatMismatch(item, tolerance) {
|
|
263
|
+
return Math.abs(item.netAmount * item.vatRate / 100 - item.vatAmount) > tolerance;
|
|
264
|
+
}
|
|
265
|
+
function grossMismatch(item) {
|
|
266
|
+
return Math.abs(item.netAmount + item.vatAmount - item.grossAmount) > SUM_EPSILON;
|
|
267
|
+
}
|
|
268
|
+
function assertInvoiceItems(items, currency, hasMarginVat) {
|
|
269
|
+
const tolerance = require_vat.isHuf(currency) ? HUF_TOLERANCE : FOREIGN_TOLERANCE;
|
|
270
|
+
items.forEach((item, index) => {
|
|
271
|
+
if (netMismatch(item, tolerance)) throw amountFailure(259, item);
|
|
272
|
+
if (!hasMarginVat(index) && vatMismatch(item, tolerance)) throw amountFailure(260, item);
|
|
273
|
+
if (grossMismatch(item)) throw amountFailure(261, item);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function assertReceiptItems(items, currency) {
|
|
277
|
+
if (!require_vat.isHuf(currency)) return;
|
|
278
|
+
for (const item of items) {
|
|
279
|
+
if (grossMismatch(item)) throw amountFailure(261, item);
|
|
280
|
+
if (!Number.isInteger(item.grossAmount)) throw amountFailure(363, item);
|
|
281
|
+
if (require_rounding.decimalPlaces(item.netAmount) > RECEIPT_DECIMALS) throw amountFailure(364, item);
|
|
282
|
+
if (require_rounding.decimalPlaces(item.vatAmount) > RECEIPT_DECIMALS) throw amountFailure(365, item);
|
|
283
|
+
if (netMismatch(item, HUF_TOLERANCE)) throw amountFailure(259, item);
|
|
284
|
+
if (vatMismatch(item, HUF_TOLERANCE)) throw amountFailure(260, item);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function sum(values) {
|
|
288
|
+
return require_rounding.roundMoney(values.reduce((total, value) => total + value, 0), TOTAL_DECIMALS);
|
|
289
|
+
}
|
|
290
|
+
function totalsOf(items) {
|
|
291
|
+
return {
|
|
292
|
+
net: sum(items.map((item) => item.netAmount)),
|
|
293
|
+
vat: sum(items.map((item) => item.vatAmount)),
|
|
294
|
+
gross: sum(items.map((item) => item.grossAmount))
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function vatGroupsOf(items) {
|
|
298
|
+
const groups = /* @__PURE__ */ new Map();
|
|
299
|
+
for (const item of items) {
|
|
300
|
+
const key = `${item.vatCode ?? ""}|${item.vatRate}`;
|
|
301
|
+
groups.set(key, [...groups.get(key) ?? [], item]);
|
|
302
|
+
}
|
|
303
|
+
return [...groups.values()].flatMap((group) => {
|
|
304
|
+
const [first] = group;
|
|
305
|
+
if (!first) return [];
|
|
306
|
+
const totals = totalsOf(group);
|
|
307
|
+
return [{
|
|
308
|
+
vatRate: first.vatRate,
|
|
309
|
+
vatCode: first.vatCode,
|
|
310
|
+
net: totals.net,
|
|
311
|
+
vat: totals.vat,
|
|
312
|
+
gross: totals.gross
|
|
313
|
+
}];
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
function negateItem(item) {
|
|
317
|
+
return {
|
|
318
|
+
...item,
|
|
319
|
+
quantity: -item.quantity,
|
|
320
|
+
netAmount: -item.netAmount,
|
|
321
|
+
vatAmount: -item.vatAmount,
|
|
322
|
+
grossAmount: -item.grossAmount
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function negateTotals(totals) {
|
|
326
|
+
return {
|
|
327
|
+
net: -totals.net,
|
|
328
|
+
vat: -totals.vat,
|
|
329
|
+
gross: -totals.gross
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function outstandingOf(gross, paid) {
|
|
333
|
+
return gross > 0 ? Math.max(0, sum([gross, -paid])) : 0;
|
|
334
|
+
}
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/testing/fake-agent-account.ts
|
|
337
|
+
const NAV_API_NAMESPACE = "http://schemas.nav.gov.hu/OSA/3.0/api";
|
|
338
|
+
const TAXPAYER_ID_PATTERN = /^\d{8}$/;
|
|
339
|
+
const CONNECT_PRINCIPAL_MESSAGES = {
|
|
340
|
+
created: "DONE",
|
|
341
|
+
ownerInviteResent: "Már létező fiók, nincs fiókgazdája. Fiókgazdai meghívó (megbízott számlakibocsátás) email újraküldve.",
|
|
342
|
+
joinRequestSent: "Már létező fiók fiókgazdával. Csatlakozási kérelmet küldtünk a fiókgazdának.",
|
|
343
|
+
joinRequestResent: "Már létező fiók fiókgazdával. A csatlakozási kérelem emailt újraküldtük a fiókgazdának."
|
|
344
|
+
};
|
|
345
|
+
function authenticateDelegate(state, username, password) {
|
|
346
|
+
const delegate = state.delegates.get(username);
|
|
347
|
+
if (!delegate) return false;
|
|
348
|
+
if (delegate.password !== password || !delegate.approved) throw agentFailure(3);
|
|
349
|
+
if (state.principals.get(delegate.taxpayerId)?.state !== "owned") throw agentFailure(250);
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
function authenticate(state, credentials) {
|
|
353
|
+
const { agentKey, username, password } = credentials;
|
|
354
|
+
if (agentKey !== void 0) {
|
|
355
|
+
if (!state.config.strictAuth || state.config.agentKeys.has(agentKey)) return;
|
|
356
|
+
throw agentFailure(3);
|
|
357
|
+
}
|
|
358
|
+
if (username === void 0 || password === void 0) throw agentFailure(3);
|
|
359
|
+
if (authenticateDelegate(state, username, password)) return;
|
|
360
|
+
if (!state.config.strictAuth || state.users.get(username) === password) return;
|
|
361
|
+
throw agentFailure(3);
|
|
362
|
+
}
|
|
363
|
+
function acceptDelegation(state, taxNumber) {
|
|
364
|
+
const key = taxpayerKey(taxNumber);
|
|
365
|
+
const principal = state.principals.get(key);
|
|
366
|
+
if (!principal) throw new TypeError(`Nincs ilyen megbízói fiók a hamis Agentben: ${taxNumber}`);
|
|
367
|
+
state.principals.set(key, {
|
|
368
|
+
...principal,
|
|
369
|
+
state: "owned"
|
|
370
|
+
});
|
|
371
|
+
for (const [email, delegate] of state.delegates) if (delegate.taxpayerId === key) state.delegates.set(email, {
|
|
372
|
+
...delegate,
|
|
373
|
+
approved: true
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function addressNode(taxpayer) {
|
|
377
|
+
const { address } = taxpayer;
|
|
378
|
+
if (!address) return void 0;
|
|
379
|
+
return require_serialize.el("taxpayerAddressList", [require_serialize.el("taxpayerAddressItem", [require_serialize.el("taxpayerAddressType", "HQ"), require_serialize.el("taxpayerAddress", [
|
|
380
|
+
require_serialize.el("countryCode", "HU"),
|
|
381
|
+
require_serialize.el("postalCode", address.postalCode),
|
|
382
|
+
require_serialize.el("city", address.city),
|
|
383
|
+
require_serialize.optionalEl("streetName", address.streetName),
|
|
384
|
+
require_serialize.optionalEl("publicPlaceCategory", address.publicPlaceCategory),
|
|
385
|
+
require_serialize.optionalEl("number", address.number)
|
|
386
|
+
])])]);
|
|
387
|
+
}
|
|
388
|
+
function taxpayerDataNode(taxpayerId, taxpayer) {
|
|
389
|
+
return require_serialize.el("taxpayerData", [
|
|
390
|
+
require_serialize.el("taxpayerName", taxpayer.name),
|
|
391
|
+
require_serialize.optionalEl("taxpayerShortName", taxpayer.shortName),
|
|
392
|
+
require_serialize.el("taxNumberDetail", [
|
|
393
|
+
require_serialize.el("taxpayerId", taxpayerId),
|
|
394
|
+
require_serialize.optionalEl("vatCode", taxpayer.vatCode),
|
|
395
|
+
require_serialize.optionalEl("countyCode", taxpayer.countyCode)
|
|
396
|
+
]),
|
|
397
|
+
require_serialize.optionalEl("incorporation", taxpayer.incorporation),
|
|
398
|
+
addressNode(taxpayer)
|
|
399
|
+
]);
|
|
400
|
+
}
|
|
401
|
+
function handleQueryTaxpayer(state, request) {
|
|
402
|
+
const taxpayerId = require_serialize.childText(request.root, "torzsszam");
|
|
403
|
+
if (taxpayerId === void 0 || !TAXPAYER_ID_PATTERN.test(taxpayerId)) throw xmlFailure("a <torzsszam> elemben 8 jegyű adószám-törzsszám kell.");
|
|
404
|
+
const taxpayer = state.config.taxpayers[taxpayerId];
|
|
405
|
+
const valid = taxpayer !== void 0 && taxpayer.valid !== false;
|
|
406
|
+
const timestamp = state.now().toISOString();
|
|
407
|
+
return xmlResponse(require_serialize.buildXmlDocument({
|
|
408
|
+
root: "QueryTaxpayerResponse",
|
|
409
|
+
namespace: NAV_API_NAMESPACE,
|
|
410
|
+
children: [
|
|
411
|
+
require_serialize.el("header", [
|
|
412
|
+
require_serialize.el("requestId", `KASSZAFAKE${nextCounter(state, "#nav")}`),
|
|
413
|
+
require_serialize.el("timestamp", timestamp),
|
|
414
|
+
require_serialize.el("requestVersion", "3.0"),
|
|
415
|
+
require_serialize.el("headerVersion", "1.0")
|
|
416
|
+
]),
|
|
417
|
+
require_serialize.el("result", [require_serialize.el("funcCode", "OK")]),
|
|
418
|
+
require_serialize.el("infoDate", timestamp),
|
|
419
|
+
require_serialize.el("taxpayerValidity", valid),
|
|
420
|
+
valid && taxpayer && taxpayerDataNode(taxpayerId, taxpayer)
|
|
421
|
+
]
|
|
422
|
+
}));
|
|
423
|
+
}
|
|
424
|
+
function connectResponse(message) {
|
|
425
|
+
const encoded = encodeHeaderValue(message);
|
|
426
|
+
return textResponse(`xmlagentresponse=${encoded}\n`, { XML_AGENT_RESPONSE: encoded });
|
|
427
|
+
}
|
|
428
|
+
function handleConnectPrincipal(state, request) {
|
|
429
|
+
const company = require_serialize.findChild(request.root, "cegMb");
|
|
430
|
+
const user = require_serialize.findChild(request.root, "usrMb");
|
|
431
|
+
const taxNumber = require_serialize.childText(company, "cegtaxnumber");
|
|
432
|
+
if (taxNumber === void 0) throw xmlFailure("hiányzik a(z) <cegMb/cegtaxnumber> elem.");
|
|
433
|
+
const key = taxpayerKey(taxNumber);
|
|
434
|
+
const principal = state.principals.get(key);
|
|
435
|
+
const email = require_serialize.childText(user, "usremail");
|
|
436
|
+
const password = require_serialize.childText(user, "usrpassword");
|
|
437
|
+
if (email === void 0 || password === void 0) throw xmlFailure("hiányzik a(z) <usrMb/usremail> vagy <usrMb/usrpassword> elem.");
|
|
438
|
+
if (!principal) {
|
|
439
|
+
state.principals.set(key, {
|
|
440
|
+
state: "unowned",
|
|
441
|
+
joinRequests: 0
|
|
442
|
+
});
|
|
443
|
+
state.delegates.set(email, {
|
|
444
|
+
taxpayerId: key,
|
|
445
|
+
password,
|
|
446
|
+
approved: true
|
|
447
|
+
});
|
|
448
|
+
return connectResponse(CONNECT_PRINCIPAL_MESSAGES.created);
|
|
449
|
+
}
|
|
450
|
+
if (principal.state === "unowned") return connectResponse(CONNECT_PRINCIPAL_MESSAGES.ownerInviteResent);
|
|
451
|
+
if (!state.delegates.has(email)) state.delegates.set(email, {
|
|
452
|
+
taxpayerId: key,
|
|
453
|
+
password,
|
|
454
|
+
approved: false
|
|
455
|
+
});
|
|
456
|
+
state.principals.set(key, {
|
|
457
|
+
...principal,
|
|
458
|
+
joinRequests: principal.joinRequests + 1
|
|
459
|
+
});
|
|
460
|
+
return connectResponse(principal.joinRequests === 0 ? CONNECT_PRINCIPAL_MESSAGES.joinRequestSent : CONNECT_PRINCIPAL_MESSAGES.joinRequestResent);
|
|
461
|
+
}
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region src/testing/fake-agent-invoice-xml.ts
|
|
464
|
+
const UNIFIED_PAYMENT_METHODS = [
|
|
465
|
+
"átutalás",
|
|
466
|
+
"készpénz",
|
|
467
|
+
"bankkártya",
|
|
468
|
+
"csekk",
|
|
469
|
+
"utánvét",
|
|
470
|
+
"ajándékutalvány",
|
|
471
|
+
"barion",
|
|
472
|
+
"barter",
|
|
473
|
+
"csoportos beszedés",
|
|
474
|
+
"OTP Simple",
|
|
475
|
+
"kompenzáció",
|
|
476
|
+
"kupon",
|
|
477
|
+
"PayPal",
|
|
478
|
+
"PayU",
|
|
479
|
+
"SZÉP kártya",
|
|
480
|
+
"utalvány",
|
|
481
|
+
"MasterCard Mobile",
|
|
482
|
+
"Borgun",
|
|
483
|
+
"EP kártya",
|
|
484
|
+
"térítésmentes",
|
|
485
|
+
"egyéb"
|
|
486
|
+
];
|
|
487
|
+
const OTHER_PAYMENT_METHOD = "egyéb";
|
|
488
|
+
const CASH_PAYMENT_METHOD = "készpénz";
|
|
489
|
+
const SELLER_ID = 1;
|
|
490
|
+
const DOMESTIC_LOCATION = 1;
|
|
491
|
+
const PAPER_APPEARANCE = 0;
|
|
492
|
+
const E_INVOICE_APPEARANCE = 2;
|
|
493
|
+
function unifiedPaymentMethod(method) {
|
|
494
|
+
const normalized = method.trim().toLowerCase();
|
|
495
|
+
return UNIFIED_PAYMENT_METHODS.find((candidate) => candidate.toLowerCase() === normalized) ?? OTHER_PAYMENT_METHOD;
|
|
496
|
+
}
|
|
497
|
+
function sellerNode(invoice) {
|
|
498
|
+
const { seller } = invoice;
|
|
499
|
+
return require_serialize.el("szallito", [
|
|
500
|
+
require_serialize.el("id", SELLER_ID),
|
|
501
|
+
require_serialize.el("nev", seller.name),
|
|
502
|
+
require_serialize.el("cim", [
|
|
503
|
+
require_serialize.optionalEl("orszag", seller.country),
|
|
504
|
+
require_serialize.el("irsz", seller.zip),
|
|
505
|
+
require_serialize.el("telepules", seller.city),
|
|
506
|
+
require_serialize.el("cim", seller.address)
|
|
507
|
+
]),
|
|
508
|
+
require_serialize.el("adoszam", seller.taxNumber),
|
|
509
|
+
require_serialize.optionalEl("bank", [require_serialize.optionalEl("nev", seller.bankName), require_serialize.optionalEl("bankszamla", seller.bankAccount)])
|
|
510
|
+
]);
|
|
511
|
+
}
|
|
512
|
+
function headerNode(invoice, testAccount) {
|
|
513
|
+
const unified = unifiedPaymentMethod(invoice.paymentMethod);
|
|
514
|
+
return require_serialize.el("alap", [
|
|
515
|
+
require_serialize.el("id", invoice.id),
|
|
516
|
+
require_serialize.el("szamlaszam", invoice.number),
|
|
517
|
+
require_serialize.el("gazdEsemAzon", invoice.id),
|
|
518
|
+
require_serialize.el("tipus", invoice.typeCode),
|
|
519
|
+
require_serialize.el("eszamla", invoice.eInvoice ? E_INVOICE_APPEARANCE : PAPER_APPEARANCE),
|
|
520
|
+
require_serialize.optionalEl("hivszamlaszam", invoice.referencedInvoiceNumber),
|
|
521
|
+
require_serialize.optionalEl("hivdijbekszam", invoice.referencedProformaNumber),
|
|
522
|
+
require_serialize.el("kelt", invoice.issueDate),
|
|
523
|
+
require_serialize.el("telj", invoice.fulfillmentDate),
|
|
524
|
+
require_serialize.el("fizh", invoice.dueDate),
|
|
525
|
+
require_serialize.el("fizmod", invoice.paymentMethod),
|
|
526
|
+
require_serialize.el("fizmodunified", unified),
|
|
527
|
+
require_serialize.el("keszpenz", unified === CASH_PAYMENT_METHOD),
|
|
528
|
+
require_serialize.optionalEl("rendelesszam", invoice.orderNumber),
|
|
529
|
+
require_serialize.el("nyelv", invoice.language),
|
|
530
|
+
require_serialize.el("devizanem", invoice.currency),
|
|
531
|
+
require_serialize.optionalEl("devizabank", invoice.exchangeBank),
|
|
532
|
+
require_serialize.optionalEl("devizaarf", invoice.exchangeRate),
|
|
533
|
+
require_serialize.optionalEl("megjegyzes", invoice.comment),
|
|
534
|
+
require_serialize.el("penzforg", false),
|
|
535
|
+
require_serialize.el("kata", false),
|
|
536
|
+
require_serialize.el("katafokonyv", false),
|
|
537
|
+
require_serialize.optionalEl("email", invoice.buyer.email),
|
|
538
|
+
require_serialize.el("teszt", testAccount),
|
|
539
|
+
require_serialize.el("sztornozott", invoice.reversed)
|
|
540
|
+
]);
|
|
541
|
+
}
|
|
542
|
+
function buyerNode(invoice) {
|
|
543
|
+
const { buyer } = invoice;
|
|
544
|
+
return require_serialize.el("vevo", [
|
|
545
|
+
require_serialize.el("nev", buyer.name),
|
|
546
|
+
require_serialize.optionalEl("azonosito", buyer.identifier),
|
|
547
|
+
require_serialize.el("cim", [
|
|
548
|
+
require_serialize.optionalEl("orszag", buyer.country),
|
|
549
|
+
require_serialize.el("irsz", buyer.zip),
|
|
550
|
+
require_serialize.el("telepules", buyer.city),
|
|
551
|
+
require_serialize.el("cim", buyer.address)
|
|
552
|
+
]),
|
|
553
|
+
require_serialize.optionalEl("email", buyer.email),
|
|
554
|
+
require_serialize.el("adoszam", buyer.taxNumber ?? ""),
|
|
555
|
+
require_serialize.optionalEl("csoportazonosito", buyer.groupTaxNumber),
|
|
556
|
+
require_serialize.optionalEl("adoszameu", buyer.euTaxNumber),
|
|
557
|
+
require_serialize.el("lokacio", DOMESTIC_LOCATION),
|
|
558
|
+
require_serialize.el("privatePersonIndicator", buyer.taxNumber === void 0 && buyer.euTaxNumber === void 0)
|
|
559
|
+
]);
|
|
560
|
+
}
|
|
561
|
+
function itemNode$1(item, index) {
|
|
562
|
+
return require_serialize.el("tetel", [
|
|
563
|
+
require_serialize.el("nev", item.name),
|
|
564
|
+
require_serialize.optionalEl("azonosito", item.identifier),
|
|
565
|
+
require_serialize.el("mennyiseg", item.quantity),
|
|
566
|
+
require_serialize.el("mennyisegiegyseg", item.unit),
|
|
567
|
+
require_serialize.el("nettoegysegar", item.netUnitPrice),
|
|
568
|
+
require_serialize.optionalEl("afatipus", item.vatCode),
|
|
569
|
+
require_serialize.el("afakulcs", item.vatRate),
|
|
570
|
+
require_serialize.el("netto", item.netAmount),
|
|
571
|
+
require_serialize.el("afa", item.vatAmount),
|
|
572
|
+
require_serialize.el("brutto", item.grossAmount),
|
|
573
|
+
require_serialize.optionalEl("megjegyzes", item.comment),
|
|
574
|
+
require_serialize.el("sztetordering", index + 1)
|
|
575
|
+
]);
|
|
576
|
+
}
|
|
577
|
+
function vatGroupNode(group) {
|
|
578
|
+
return require_serialize.el("afakulcsossz", [
|
|
579
|
+
require_serialize.optionalEl("afatipus", group.vatCode),
|
|
580
|
+
require_serialize.el("afakulcs", group.vatRate),
|
|
581
|
+
require_serialize.el("netto", group.net),
|
|
582
|
+
require_serialize.el("afa", group.vat),
|
|
583
|
+
require_serialize.el("brutto", group.gross)
|
|
584
|
+
]);
|
|
585
|
+
}
|
|
586
|
+
function totalNode(totals) {
|
|
587
|
+
return require_serialize.el("totalossz", [
|
|
588
|
+
require_serialize.el("netto", totals.net),
|
|
589
|
+
require_serialize.el("afa", totals.vat),
|
|
590
|
+
require_serialize.el("brutto", totals.gross)
|
|
591
|
+
]);
|
|
592
|
+
}
|
|
593
|
+
function paymentNode$1(payment) {
|
|
594
|
+
return require_serialize.el("kifizetes", [
|
|
595
|
+
require_serialize.el("datum", payment.date),
|
|
596
|
+
require_serialize.el("jogcim", payment.method),
|
|
597
|
+
require_serialize.el("osszeg", payment.amount),
|
|
598
|
+
require_serialize.optionalEl("megjegyzes", payment.comment)
|
|
599
|
+
]);
|
|
600
|
+
}
|
|
601
|
+
function renderInvoiceXml(invoice, testAccount, includePdf) {
|
|
602
|
+
return require_serialize.buildXmlDocument({
|
|
603
|
+
root: "szamla",
|
|
604
|
+
namespace: "http://www.szamlazz.hu/szamla",
|
|
605
|
+
children: [
|
|
606
|
+
sellerNode(invoice),
|
|
607
|
+
headerNode(invoice, testAccount),
|
|
608
|
+
buyerNode(invoice),
|
|
609
|
+
require_serialize.el("tetelek", invoice.items.map(itemNode$1)),
|
|
610
|
+
require_serialize.el("osszegek", [...vatGroupsOf(invoice.items).map(vatGroupNode), totalNode(invoice.totals)]),
|
|
611
|
+
invoice.payments.length > 0 && require_serialize.el("kifizetesek", invoice.payments.map(paymentNode$1)),
|
|
612
|
+
includePdf && require_serialize.el("pdf", require_binary.bytesToBase64(fakePdf(invoice.number)))
|
|
613
|
+
]
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
//#endregion
|
|
617
|
+
//#region src/testing/fake-agent-request.ts
|
|
618
|
+
const REQUEST_ROOTS = {
|
|
619
|
+
createInvoice: "xmlszamla",
|
|
620
|
+
reverseInvoice: "xmlszamlast",
|
|
621
|
+
registerPayment: "xmlszamlakifiz",
|
|
622
|
+
getInvoicePdf: "xmlszamlapdf",
|
|
623
|
+
getInvoiceXml: "xmlszamlaxml",
|
|
624
|
+
deleteProforma: "xmlszamladbkdel",
|
|
625
|
+
createReceipt: "xmlnyugtacreate",
|
|
626
|
+
reverseReceipt: "xmlnyugtast",
|
|
627
|
+
getReceipt: "xmlnyugtaget",
|
|
628
|
+
sendReceipt: "xmlnyugtasend",
|
|
629
|
+
queryTaxpayer: "xmltaxpayer",
|
|
630
|
+
connectPrincipal: "XmlCegMb"
|
|
631
|
+
};
|
|
632
|
+
const MAX_ATTACHMENTS = 5;
|
|
633
|
+
const ACTION_FIELDS = Object.entries(require_create_once.AGENT_ACTIONS);
|
|
634
|
+
async function readForm(input, init) {
|
|
635
|
+
if (init?.body instanceof FormData) return init.body;
|
|
636
|
+
try {
|
|
637
|
+
return await (input instanceof Request && init === void 0 ? input : new Request(input, init)).formData();
|
|
638
|
+
} catch {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
async function entryText(value) {
|
|
643
|
+
return typeof value === "string" ? value : value.text();
|
|
644
|
+
}
|
|
645
|
+
function attachmentsOf(form) {
|
|
646
|
+
const attachments = [];
|
|
647
|
+
for (let index = 1; index <= MAX_ATTACHMENTS; index++) {
|
|
648
|
+
const value = form.get(`attachfile${index}`);
|
|
649
|
+
if (value instanceof Blob) attachments.push({
|
|
650
|
+
filename: value instanceof File ? value.name : "",
|
|
651
|
+
size: value.size
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
return attachments;
|
|
655
|
+
}
|
|
656
|
+
async function readFakeAgentForm(input, init) {
|
|
657
|
+
const form = await readForm(input, init);
|
|
658
|
+
if (!form) return {
|
|
659
|
+
action: void 0,
|
|
660
|
+
xml: void 0,
|
|
661
|
+
attachments: []
|
|
662
|
+
};
|
|
663
|
+
for (const [action, field] of ACTION_FIELDS) {
|
|
664
|
+
const value = form.get(field);
|
|
665
|
+
if (value !== null) return {
|
|
666
|
+
action,
|
|
667
|
+
xml: await entryText(value),
|
|
668
|
+
attachments: attachmentsOf(form)
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
return {
|
|
672
|
+
action: void 0,
|
|
673
|
+
xml: void 0,
|
|
674
|
+
attachments: attachmentsOf(form)
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function parseFakeAgentRequest(action, xml, attachments) {
|
|
678
|
+
let root;
|
|
679
|
+
try {
|
|
680
|
+
root = require_serialize.parseXml(xml);
|
|
681
|
+
} catch (error) {
|
|
682
|
+
throw new FakeAgentFailure(57, `XML beolvasási hiba.${error instanceof Error ? ` ${error.message}` : ""}`);
|
|
683
|
+
}
|
|
684
|
+
const expected = REQUEST_ROOTS[action];
|
|
685
|
+
if (root.name !== expected) throw new FakeAgentFailure(57, `XML beolvasási hiba. A(z) ${action} művelethez <${expected}> gyökérelem kell, érkezett: <${root.name}>.`);
|
|
686
|
+
return {
|
|
687
|
+
action,
|
|
688
|
+
xml,
|
|
689
|
+
root,
|
|
690
|
+
attachments
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
function credentialsOf(root) {
|
|
694
|
+
for (const holder of [
|
|
695
|
+
require_serialize.findChild(root, "login"),
|
|
696
|
+
require_serialize.findChild(root, "beallitasok"),
|
|
697
|
+
root
|
|
698
|
+
]) {
|
|
699
|
+
const agentKey = require_serialize.childText(holder, "szamlaagentkulcs");
|
|
700
|
+
const username = require_serialize.childText(holder, "felhasznalo") ?? require_serialize.childText(holder, "loginname");
|
|
701
|
+
const password = require_serialize.childText(holder, "jelszo") ?? require_serialize.childText(holder, "password");
|
|
702
|
+
if (agentKey !== void 0 || username !== void 0 || password !== void 0) return {
|
|
703
|
+
agentKey,
|
|
704
|
+
username,
|
|
705
|
+
password
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
return {};
|
|
709
|
+
}
|
|
710
|
+
function responseVersion(root) {
|
|
711
|
+
return require_serialize.childNumber(require_serialize.findChild(root, "beallitasok"), "valaszVerzio") ?? require_serialize.childNumber(root, "valaszVerzio") ?? 1;
|
|
712
|
+
}
|
|
713
|
+
function errorStyleFor(action, root) {
|
|
714
|
+
switch (action) {
|
|
715
|
+
case "createInvoice":
|
|
716
|
+
case "reverseInvoice":
|
|
717
|
+
case "registerPayment":
|
|
718
|
+
case "getInvoicePdf": return root !== void 0 && responseVersion(root) === 2 ? "invoice" : "text";
|
|
719
|
+
case "getInvoiceXml": return "invoice";
|
|
720
|
+
case "deleteProforma": return "proforma";
|
|
721
|
+
case "createReceipt":
|
|
722
|
+
case "reverseReceipt":
|
|
723
|
+
case "getReceipt": return "receipt";
|
|
724
|
+
case "sendReceipt": return "receipt-send";
|
|
725
|
+
case "queryTaxpayer":
|
|
726
|
+
case "connectPrincipal": return "text";
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
//#endregion
|
|
730
|
+
//#region src/testing/fake-agent-invoices.ts
|
|
731
|
+
const LANGUAGES = /* @__PURE__ */ new Set([
|
|
732
|
+
"hu",
|
|
733
|
+
"en",
|
|
734
|
+
"de",
|
|
735
|
+
"it",
|
|
736
|
+
"ro",
|
|
737
|
+
"sk",
|
|
738
|
+
"hr",
|
|
739
|
+
"fr",
|
|
740
|
+
"es",
|
|
741
|
+
"cz",
|
|
742
|
+
"pl",
|
|
743
|
+
"bg",
|
|
744
|
+
"nl",
|
|
745
|
+
"ru",
|
|
746
|
+
"si"
|
|
747
|
+
]);
|
|
748
|
+
const DUPLICATE_WINDOW_MS = 1728e5;
|
|
749
|
+
const MAX_PAYMENTS = 5;
|
|
750
|
+
const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
751
|
+
function requiredText$1(parent, name, path) {
|
|
752
|
+
const value = require_serialize.childText(parent, name);
|
|
753
|
+
if (value === void 0) throw xmlFailure(`hiányzik a(z) <${path}/${name}> elem.`);
|
|
754
|
+
return value;
|
|
755
|
+
}
|
|
756
|
+
function checkedDate(value, name, path) {
|
|
757
|
+
if (!DATE_PATTERN.test(value)) throw xmlFailure(`a(z) <${path}/${name}> nem ÉÉÉÉ-HH-NN formátumú dátum: ${value}.`);
|
|
758
|
+
return value;
|
|
759
|
+
}
|
|
760
|
+
function requiredDate(parent, name, path) {
|
|
761
|
+
return checkedDate(requiredText$1(parent, name, path), name, path);
|
|
762
|
+
}
|
|
763
|
+
function optionalDate(parent, name, path) {
|
|
764
|
+
const value = require_serialize.childText(parent, name);
|
|
765
|
+
return value === void 0 ? void 0 : checkedDate(value, name, path);
|
|
766
|
+
}
|
|
767
|
+
function typeCodeOf(header) {
|
|
768
|
+
if (require_serialize.childBoolean(header, "dijbekero") === true) return "D";
|
|
769
|
+
if (require_serialize.childBoolean(header, "elolegszamla") === true) return "ES";
|
|
770
|
+
if (require_serialize.childBoolean(header, "vegszamla") === true) return "VS";
|
|
771
|
+
if (require_serialize.childBoolean(header, "helyesbitoszamla") === true) return "HS";
|
|
772
|
+
if (require_serialize.childBoolean(header, "szallitolevel") === true) return "SL";
|
|
773
|
+
return "SZ";
|
|
774
|
+
}
|
|
775
|
+
function seriesOf(typeCode, prefix, eInvoice) {
|
|
776
|
+
if (typeCode === "D") return `D-${prefix}`;
|
|
777
|
+
if (typeCode === "SL") return `SZL-${prefix}`;
|
|
778
|
+
return eInvoice ? `E-${prefix}` : prefix;
|
|
779
|
+
}
|
|
780
|
+
function buyerOf(root) {
|
|
781
|
+
const buyer = require_serialize.findChild(root, "vevo");
|
|
782
|
+
return {
|
|
783
|
+
name: requiredText$1(buyer, "nev", "vevo"),
|
|
784
|
+
identifier: require_serialize.childText(buyer, "azonosito"),
|
|
785
|
+
country: require_serialize.childText(buyer, "orszag"),
|
|
786
|
+
zip: requiredText$1(buyer, "irsz", "vevo"),
|
|
787
|
+
city: requiredText$1(buyer, "telepules", "vevo"),
|
|
788
|
+
address: requiredText$1(buyer, "cim", "vevo"),
|
|
789
|
+
email: require_serialize.childText(buyer, "email"),
|
|
790
|
+
taxNumber: require_serialize.childText(buyer, "adoszam"),
|
|
791
|
+
groupTaxNumber: require_serialize.childText(buyer, "csoportazonosito"),
|
|
792
|
+
euTaxNumber: require_serialize.childText(buyer, "adoszamEU")
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
function sellerOf(state, root) {
|
|
796
|
+
const seller = require_serialize.findChild(root, "elado");
|
|
797
|
+
const defaults = state.config.seller;
|
|
798
|
+
return {
|
|
799
|
+
...defaults,
|
|
800
|
+
bankName: require_serialize.childText(seller, "bank") ?? defaults.bankName,
|
|
801
|
+
bankAccount: require_serialize.childText(seller, "bankszamlaszam") ?? defaults.bankAccount
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
function resolvePrefix$1(state, header) {
|
|
805
|
+
const prefix = require_serialize.childText(header, "szamlaszamElotag") ?? state.config.defaultInvoicePrefix;
|
|
806
|
+
const allowed = state.config.invoicePrefixes;
|
|
807
|
+
if (allowed !== void 0 && !allowed.has(prefix)) throw agentFailure(202);
|
|
808
|
+
return prefix;
|
|
809
|
+
}
|
|
810
|
+
function marginVatOf(root, header) {
|
|
811
|
+
const wholeInvoice = require_serialize.childBoolean(header, "arresAfa") === true;
|
|
812
|
+
const items = require_serialize.findChildren(require_serialize.findChild(root, "tetelek"), "tetel");
|
|
813
|
+
return (index) => wholeInvoice || require_serialize.childText(items[index], "arresAfaAlap") !== void 0;
|
|
814
|
+
}
|
|
815
|
+
function readInvoiceRequest(state, root) {
|
|
816
|
+
const settings = require_serialize.findChild(root, "beallitasok");
|
|
817
|
+
const header = require_serialize.findChild(root, "fejlec");
|
|
818
|
+
if (!header) throw xmlFailure("hiányzik a <fejlec> blokk.");
|
|
819
|
+
const currency = requiredText$1(header, "penznem", "fejlec");
|
|
820
|
+
const language = requiredText$1(header, "szamlaNyelve", "fejlec");
|
|
821
|
+
if (!LANGUAGES.has(language)) throw xmlFailure(`ismeretlen számlanyelv: ${language}.`);
|
|
822
|
+
const issueDate = requiredDate(header, "keltDatum", "fejlec");
|
|
823
|
+
const fulfillmentDate = requiredDate(header, "teljesitesDatum", "fejlec");
|
|
824
|
+
const dueDate = requiredDate(header, "fizetesiHataridoDatum", "fejlec");
|
|
825
|
+
const paymentMethod = requiredText$1(header, "fizmod", "fejlec");
|
|
826
|
+
const buyer = buyerOf(root);
|
|
827
|
+
const items = parseItems(root, "invoice");
|
|
828
|
+
const prefix = resolvePrefix$1(state, header);
|
|
829
|
+
assertInvoiceItems(items, currency, marginVatOf(root, header));
|
|
830
|
+
const typeCode = typeCodeOf(header);
|
|
831
|
+
const eInvoice = require_serialize.childBoolean(settings, "eszamla") === true;
|
|
832
|
+
const totals = totalsOf(items);
|
|
833
|
+
const foreign = !require_vat.isHuf(currency);
|
|
834
|
+
return {
|
|
835
|
+
preview: require_serialize.childBoolean(header, "elonezetpdf") === true,
|
|
836
|
+
downloadPdf: require_serialize.childBoolean(settings, "szamlaLetoltes") === true,
|
|
837
|
+
fields: {
|
|
838
|
+
prefix,
|
|
839
|
+
series: seriesOf(typeCode, prefix, eInvoice),
|
|
840
|
+
typeCode,
|
|
841
|
+
eInvoice,
|
|
842
|
+
issueDate,
|
|
843
|
+
fulfillmentDate,
|
|
844
|
+
dueDate,
|
|
845
|
+
paymentMethod,
|
|
846
|
+
language,
|
|
847
|
+
currency,
|
|
848
|
+
exchangeBank: foreign ? require_serialize.childText(header, "arfolyamBank") : void 0,
|
|
849
|
+
exchangeRate: foreign ? require_serialize.childNumber(header, "arfolyam") : void 0,
|
|
850
|
+
comment: require_serialize.childText(header, "megjegyzes"),
|
|
851
|
+
orderNumber: require_serialize.childText(header, "rendelesSzam"),
|
|
852
|
+
externalId: require_serialize.childText(settings, "szamlaKulsoAzon"),
|
|
853
|
+
referencedInvoiceNumber: require_serialize.childText(header, "helyesbitettSzamlaszam") ?? require_serialize.childText(header, "elolegSzamlaszam"),
|
|
854
|
+
referencedProformaNumber: require_serialize.childText(header, "dijbekeroSzamlaszam"),
|
|
855
|
+
seller: sellerOf(state, root),
|
|
856
|
+
buyer,
|
|
857
|
+
items,
|
|
858
|
+
totals,
|
|
859
|
+
payments: require_serialize.childBoolean(header, "fizetve") === true ? [{
|
|
860
|
+
date: issueDate,
|
|
861
|
+
method: paymentMethod,
|
|
862
|
+
amount: totals.gross
|
|
863
|
+
}] : [],
|
|
864
|
+
reversed: false,
|
|
865
|
+
deleted: false
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
function activeInvoice(state, number) {
|
|
870
|
+
const invoice = state.invoices.get(number);
|
|
871
|
+
return invoice && !invoice.deleted ? invoice : void 0;
|
|
872
|
+
}
|
|
873
|
+
function paidAmount(invoice) {
|
|
874
|
+
return invoice.payments.reduce((sum, payment) => sum + payment.amount, 0);
|
|
875
|
+
}
|
|
876
|
+
function resultFields(invoice, pdf) {
|
|
877
|
+
return {
|
|
878
|
+
number: invoice.number,
|
|
879
|
+
netTotal: invoice.totals.net,
|
|
880
|
+
grossTotal: invoice.totals.gross,
|
|
881
|
+
outstanding: invoice.typeCode === "SS" ? void 0 : outstandingOf(invoice.totals.gross, paidAmount(invoice)),
|
|
882
|
+
paymentMethod: invoice.paymentMethod,
|
|
883
|
+
pdf: pdf ? fakePdf(invoice.number) : void 0
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
function invoiceResult(invoice, version, downloadPdf) {
|
|
887
|
+
return invoiceResultResponse(resultFields(invoice, downloadPdf), version);
|
|
888
|
+
}
|
|
889
|
+
function isSameInvoice(existing, fields) {
|
|
890
|
+
return existing.buyer.name === fields.buyer.name && existing.totals.gross === fields.totals.gross && existing.issueDate === fields.issueDate && existing.dueDate === fields.dueDate && existing.fulfillmentDate === fields.fulfillmentDate;
|
|
891
|
+
}
|
|
892
|
+
function findOrderDuplicate(state, fields) {
|
|
893
|
+
const { orderNumber, typeCode } = fields;
|
|
894
|
+
if (!state.config.uniqueInvoiceOrderNumbers || orderNumber === void 0 || typeCode === "HS") return;
|
|
895
|
+
return [...state.invoices.values()].findLast((invoice) => invoice.typeCode === typeCode && invoice.orderNumber === orderNumber && !invoice.reversed && !invoice.deleted);
|
|
896
|
+
}
|
|
897
|
+
function handleCreateInvoice(state, request) {
|
|
898
|
+
const version = responseVersion(request.root);
|
|
899
|
+
const { fields, preview, downloadPdf } = readInvoiceRequest(state, request.root);
|
|
900
|
+
if (preview) return invoiceResultResponse({
|
|
901
|
+
netTotal: fields.totals.net,
|
|
902
|
+
grossTotal: fields.totals.gross,
|
|
903
|
+
pdf: fakePdf("előnézet")
|
|
904
|
+
}, version);
|
|
905
|
+
const duplicate = findOrderDuplicate(state, fields);
|
|
906
|
+
if (duplicate) {
|
|
907
|
+
if (!(state.now().getTime() - duplicate.createdAt <= DUPLICATE_WINDOW_MS) || !isSameInvoice(duplicate, fields)) throw agentFailure(152, `Már létező rendelésszám: ${fields.orderNumber}. Az ismétlődés engedélyezhető a Beállítások oldalon.`);
|
|
908
|
+
return invoiceResult(duplicate, version, downloadPdf);
|
|
909
|
+
}
|
|
910
|
+
const invoice = {
|
|
911
|
+
...fields,
|
|
912
|
+
id: nextDocumentId(state),
|
|
913
|
+
number: nextDocumentNumber(state, fields.series),
|
|
914
|
+
createdAt: state.now().getTime()
|
|
915
|
+
};
|
|
916
|
+
state.invoices.set(invoice.number, invoice);
|
|
917
|
+
return invoiceResult(invoice, version, downloadPdf);
|
|
918
|
+
}
|
|
919
|
+
function reversalOf(state, original, root) {
|
|
920
|
+
const settings = require_serialize.findChild(root, "beallitasok");
|
|
921
|
+
const header = require_serialize.findChild(root, "fejlec");
|
|
922
|
+
const buyer = require_serialize.findChild(root, "vevo");
|
|
923
|
+
const issueDate = optionalDate(header, "keltDatum", "fejlec") ?? today(state);
|
|
924
|
+
return {
|
|
925
|
+
...original,
|
|
926
|
+
id: nextDocumentId(state),
|
|
927
|
+
number: nextDocumentNumber(state, original.series),
|
|
928
|
+
typeCode: "SS",
|
|
929
|
+
createdAt: state.now().getTime(),
|
|
930
|
+
eInvoice: original.eInvoice || require_serialize.childBoolean(settings, "eszamla") === true,
|
|
931
|
+
issueDate,
|
|
932
|
+
fulfillmentDate: optionalDate(header, "teljesitesDatum", "fejlec") ?? original.fulfillmentDate,
|
|
933
|
+
dueDate: issueDate,
|
|
934
|
+
comment: require_serialize.childText(header, "megjegyzes"),
|
|
935
|
+
externalId: require_serialize.childText(settings, "szamlaKulsoAzon"),
|
|
936
|
+
referencedInvoiceNumber: original.number,
|
|
937
|
+
referencedProformaNumber: void 0,
|
|
938
|
+
buyer: {
|
|
939
|
+
...original.buyer,
|
|
940
|
+
email: require_serialize.childText(buyer, "email") ?? original.buyer.email,
|
|
941
|
+
taxNumber: require_serialize.childText(buyer, "adoszam") ?? original.buyer.taxNumber
|
|
942
|
+
},
|
|
943
|
+
items: original.items.map(negateItem),
|
|
944
|
+
totals: negateTotals(original.totals),
|
|
945
|
+
payments: [],
|
|
946
|
+
reversed: false,
|
|
947
|
+
deleted: false
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
function handleReverseInvoice(state, request) {
|
|
951
|
+
const { root } = request;
|
|
952
|
+
const version = responseVersion(root);
|
|
953
|
+
const downloadPdf = require_serialize.childBoolean(require_serialize.findChild(root, "beallitasok"), "szamlaLetoltes") === true;
|
|
954
|
+
const number = requiredText$1(require_serialize.findChild(root, "fejlec"), "szamlaszam", "fejlec");
|
|
955
|
+
const original = activeInvoice(state, number);
|
|
956
|
+
if (!original) throw agentFailure(7, `Hiányzó adat: sztornózandó számla (ismeretlen számlaszám: ${number}).`);
|
|
957
|
+
if (original.typeCode === "D" || original.typeCode === "SL") return invoiceResult(original, version, downloadPdf);
|
|
958
|
+
if (original.typeCode === "SS") throw new FakeAgentFailure(void 0, `A(z) ${number} sztornó számla, nem sztornózható.`);
|
|
959
|
+
if (original.reversed) throw new FakeAgentFailure(void 0, `A(z) ${number} számlát már sztornózták.`);
|
|
960
|
+
const reversal = reversalOf(state, original, root);
|
|
961
|
+
state.invoices.set(original.number, {
|
|
962
|
+
...original,
|
|
963
|
+
reversed: true
|
|
964
|
+
});
|
|
965
|
+
state.invoices.set(reversal.number, reversal);
|
|
966
|
+
return invoiceResult(reversal, version, downloadPdf);
|
|
967
|
+
}
|
|
968
|
+
function paymentOf$1(element, index) {
|
|
969
|
+
const path = `kifizetes[${index + 1}]`;
|
|
970
|
+
const amount = require_serialize.childNumber(element, "osszeg");
|
|
971
|
+
if (amount === void 0) throw xmlFailure(`a(z) <${path}/osszeg> hiányzik vagy nem szám.`);
|
|
972
|
+
return {
|
|
973
|
+
date: requiredDate(element, "datum", path),
|
|
974
|
+
method: requiredText$1(element, "jogcim", path),
|
|
975
|
+
amount,
|
|
976
|
+
comment: require_serialize.childText(element, "leiras")
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
function handleRegisterPayment(state, request) {
|
|
980
|
+
const { root } = request;
|
|
981
|
+
const settings = require_serialize.findChild(root, "beallitasok");
|
|
982
|
+
const number = requiredText$1(settings, "szamlaszam", "beallitasok");
|
|
983
|
+
const additive = require_serialize.childBoolean(settings, "additiv");
|
|
984
|
+
if (additive === void 0) throw xmlFailure("hiányzik a(z) <beallitasok/additiv> elem.");
|
|
985
|
+
const elements = require_serialize.findChildren(root, "kifizetes");
|
|
986
|
+
if (elements.length > MAX_PAYMENTS) throw xmlFailure(`egy kérésben legfeljebb ${MAX_PAYMENTS} <kifizetes> elem lehet.`);
|
|
987
|
+
const entries = elements.map(paymentOf$1);
|
|
988
|
+
const invoice = activeInvoice(state, number);
|
|
989
|
+
if (!invoice) throw agentFailure(7, `Hiányzó adat: ismeretlen számlaszám (${number}).`);
|
|
990
|
+
const updated = {
|
|
991
|
+
...invoice,
|
|
992
|
+
payments: additive ? [...invoice.payments, ...entries] : entries
|
|
993
|
+
};
|
|
994
|
+
state.invoices.set(number, updated);
|
|
995
|
+
const fields = {
|
|
996
|
+
...resultFields(updated, false),
|
|
997
|
+
paymentMethod: void 0
|
|
998
|
+
};
|
|
999
|
+
if (responseVersion(root) === 2) return invoiceResultResponse(fields, 2);
|
|
1000
|
+
return textResponse("xmlagentresponse=DONE\n", invoiceResultHeaders(fields));
|
|
1001
|
+
}
|
|
1002
|
+
function lookupInvoice(state, root) {
|
|
1003
|
+
const number = require_serialize.childText(root, "szamlaszam");
|
|
1004
|
+
if (number !== void 0) return activeInvoice(state, number);
|
|
1005
|
+
const orderNumber = require_serialize.childText(root, "rendelesSzam");
|
|
1006
|
+
const externalId = require_serialize.childText(root, "szamlaKulsoAzon");
|
|
1007
|
+
if (orderNumber === void 0 && externalId === void 0) throw xmlFailure("add meg a számlaszámot, a rendelésszámot vagy a külső azonosítót.");
|
|
1008
|
+
return [...state.invoices.values()].findLast((invoice) => !invoice.deleted && (orderNumber !== void 0 ? invoice.orderNumber === orderNumber : invoice.externalId === externalId));
|
|
1009
|
+
}
|
|
1010
|
+
function handleGetInvoicePdf(state, request) {
|
|
1011
|
+
const invoice = lookupInvoice(state, request.root);
|
|
1012
|
+
if (!invoice) throw agentFailure(7, "Hiányzó adat: számla pdf (ismeretlen számlaszám, rendelésszám vagy külső azonosító).");
|
|
1013
|
+
return invoiceResult(invoice, responseVersion(request.root), true);
|
|
1014
|
+
}
|
|
1015
|
+
function handleGetInvoiceXml(state, request) {
|
|
1016
|
+
const invoice = lookupInvoice(state, request.root);
|
|
1017
|
+
if (!invoice) throw agentFailure(7, "Hiányzó adat: számla xml (ismeretlen számlaszám, rendelésszám vagy külső azonosító).");
|
|
1018
|
+
const includePdf = require_serialize.childBoolean(request.root, "pdf") === true;
|
|
1019
|
+
return xmlResponse(renderInvoiceXml(invoice, state.config.testAccount, includePdf));
|
|
1020
|
+
}
|
|
1021
|
+
function handleDeleteProforma(state, request) {
|
|
1022
|
+
const header = require_serialize.findChild(request.root, "fejlec");
|
|
1023
|
+
const number = require_serialize.childText(header, "szamlaszam");
|
|
1024
|
+
const orderNumber = require_serialize.childText(header, "rendelesszam");
|
|
1025
|
+
if (number === void 0 && orderNumber === void 0) throw xmlFailure("add meg a díjbekérő számát vagy a rendelésszámot.");
|
|
1026
|
+
const targets = [...state.invoices.values()].filter((invoice) => invoice.typeCode === "D" && !invoice.deleted && (number !== void 0 ? invoice.number === number : invoice.orderNumber === orderNumber));
|
|
1027
|
+
if (targets.length === 0) throw agentFailure(335);
|
|
1028
|
+
for (const target of targets) state.invoices.set(target.number, {
|
|
1029
|
+
...target,
|
|
1030
|
+
deleted: true
|
|
1031
|
+
});
|
|
1032
|
+
return xmlResponse(xmlDocument("xmlszamladbkdelvalasz", [require_serialize.el("sikeres", true)]));
|
|
1033
|
+
}
|
|
1034
|
+
//#endregion
|
|
1035
|
+
//#region src/testing/fake-agent-receipts.ts
|
|
1036
|
+
const PREFIX_PATTERN = /^[A-Z0-9]+$/;
|
|
1037
|
+
const MONEY_DECIMALS = 2;
|
|
1038
|
+
function requiredText(parent, name, path) {
|
|
1039
|
+
const value = require_serialize.childText(parent, name);
|
|
1040
|
+
if (value === void 0) throw xmlFailure(`hiányzik a(z) <${path}/${name}> elem.`);
|
|
1041
|
+
return value;
|
|
1042
|
+
}
|
|
1043
|
+
function assertUnusedCallId(state, callId) {
|
|
1044
|
+
if (callId === void 0) return;
|
|
1045
|
+
if ([...state.receipts.values()].some((receipt) => receipt.callId === callId)) throw agentFailure(338, `A hívásazonosító már létezik: ${callId}.`);
|
|
1046
|
+
}
|
|
1047
|
+
function isInvoicePrefix(state, prefix) {
|
|
1048
|
+
if (state.config.invoicePrefixes?.has(prefix)) return true;
|
|
1049
|
+
return [...state.invoices.values()].some((invoice) => invoice.prefix === prefix);
|
|
1050
|
+
}
|
|
1051
|
+
function resolvePrefix(state, header) {
|
|
1052
|
+
const prefix = requiredText(header, "elotag", "fejlec");
|
|
1053
|
+
if (!PREFIX_PATTERN.test(prefix)) throw agentFailure(337);
|
|
1054
|
+
if (isInvoicePrefix(state, prefix)) throw agentFailure(336);
|
|
1055
|
+
const enabled = state.config.receiptPrefixes;
|
|
1056
|
+
if (enabled !== void 0 && !enabled.has(prefix)) throw agentFailure(524);
|
|
1057
|
+
return prefix;
|
|
1058
|
+
}
|
|
1059
|
+
function paymentOf(element, index) {
|
|
1060
|
+
const path = `kifizetesek/kifizetes[${index + 1}]`;
|
|
1061
|
+
const amount = require_serialize.childNumber(element, "osszeg");
|
|
1062
|
+
if (amount === void 0) throw xmlFailure(`a(z) <${path}/osszeg> hiányzik vagy nem szám.`);
|
|
1063
|
+
return {
|
|
1064
|
+
method: requiredText(element, "fizetoeszkoz", path),
|
|
1065
|
+
amount,
|
|
1066
|
+
description: require_serialize.childText(element, "leiras")
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
function assertPaymentsMatch(payments, gross) {
|
|
1070
|
+
if (payments.length === 0) return;
|
|
1071
|
+
const paid = require_rounding.roundMoney(payments.reduce((sum, payment) => sum + payment.amount, 0), MONEY_DECIMALS);
|
|
1072
|
+
if (paid !== require_rounding.roundMoney(gross, MONEY_DECIMALS)) throw agentFailure(340, `A kifizetett összeg (${paid}) eltér a bruttó végösszegtől (${gross}).`);
|
|
1073
|
+
}
|
|
1074
|
+
function assertUniqueOrderNumber(state, orderNumber) {
|
|
1075
|
+
if (!state.config.uniqueReceiptOrderNumbers || orderNumber === void 0) return;
|
|
1076
|
+
if ([...state.receipts.values()].some((receipt) => receipt.type === "NY" && receipt.orderNumber === orderNumber && !receipt.reversed)) throw agentFailure(152, `Már létező rendelésszám: ${orderNumber}. Az ismétlődés engedélyezhető a Beállítások oldalon.`);
|
|
1077
|
+
}
|
|
1078
|
+
function exchangeOf(header, currency) {
|
|
1079
|
+
if (require_vat.isHuf(currency)) return {
|
|
1080
|
+
exchangeBank: void 0,
|
|
1081
|
+
exchangeRate: void 0
|
|
1082
|
+
};
|
|
1083
|
+
const exchangeRate = require_serialize.childNumber(header, "devizaarf");
|
|
1084
|
+
const exchangeBank = require_serialize.childText(header, "devizabank");
|
|
1085
|
+
if (exchangeRate === void 0 || exchangeRate <= 0 || exchangeBank === void 0) throw xmlFailure(`devizás (${currency}) nyugtánál az árfolyam (devizaarf) és a bank (devizabank) megadása kötelező.`);
|
|
1086
|
+
return {
|
|
1087
|
+
exchangeBank,
|
|
1088
|
+
exchangeRate
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
function itemNode(item) {
|
|
1092
|
+
return require_serialize.el("tetel", [
|
|
1093
|
+
require_serialize.el("megnevezes", item.name),
|
|
1094
|
+
require_serialize.optionalEl("azonosito", item.identifier),
|
|
1095
|
+
require_serialize.el("nettoEgysegar", item.netUnitPrice),
|
|
1096
|
+
require_serialize.el("mennyiseg", item.quantity),
|
|
1097
|
+
require_serialize.el("mennyisegiEgyseg", item.unit),
|
|
1098
|
+
require_serialize.el("netto", item.netAmount),
|
|
1099
|
+
require_serialize.optionalEl("afatipus", item.vatCode),
|
|
1100
|
+
require_serialize.el("afakulcs", item.vatRate),
|
|
1101
|
+
require_serialize.el("afa", item.vatAmount),
|
|
1102
|
+
require_serialize.el("brutto", item.grossAmount),
|
|
1103
|
+
item.ledger && require_serialize.optionalEl("fokonyv", [require_serialize.optionalEl("arbevetel", item.ledger.revenue), require_serialize.optionalEl("afa", item.ledger.vat)])
|
|
1104
|
+
]);
|
|
1105
|
+
}
|
|
1106
|
+
function paymentNode(payment) {
|
|
1107
|
+
return require_serialize.el("kifizetes", [
|
|
1108
|
+
require_serialize.el("fizetoeszkoz", payment.method),
|
|
1109
|
+
require_serialize.el("osszeg", payment.amount),
|
|
1110
|
+
require_serialize.optionalEl("leiras", payment.description)
|
|
1111
|
+
]);
|
|
1112
|
+
}
|
|
1113
|
+
function receiptNode(receipt, testAccount) {
|
|
1114
|
+
return require_serialize.el("nyugta", [
|
|
1115
|
+
require_serialize.el("alap", [
|
|
1116
|
+
require_serialize.el("id", receipt.id),
|
|
1117
|
+
require_serialize.optionalEl("hivasAzonosito", receipt.callId),
|
|
1118
|
+
require_serialize.el("nyugtaszam", receipt.number),
|
|
1119
|
+
require_serialize.el("tipus", receipt.type),
|
|
1120
|
+
require_serialize.el("stornozott", receipt.reversed),
|
|
1121
|
+
require_serialize.optionalEl("stornozottNyugtaszam", receipt.reversedNumber),
|
|
1122
|
+
require_serialize.el("kelt", receipt.issueDate),
|
|
1123
|
+
require_serialize.el("fizmod", receipt.paymentMethod),
|
|
1124
|
+
require_serialize.el("penznem", receipt.currency),
|
|
1125
|
+
require_serialize.optionalEl("devizabank", receipt.exchangeBank),
|
|
1126
|
+
require_serialize.optionalEl("devizaarf", receipt.exchangeRate),
|
|
1127
|
+
require_serialize.optionalEl("megjegyzes", receipt.comment),
|
|
1128
|
+
require_serialize.optionalEl("fokonyvVevo", receipt.customerLedgerId),
|
|
1129
|
+
require_serialize.el("teszt", testAccount),
|
|
1130
|
+
require_serialize.optionalEl("rendelesSzam", receipt.orderNumber)
|
|
1131
|
+
]),
|
|
1132
|
+
require_serialize.el("tetelek", receipt.items.map(itemNode)),
|
|
1133
|
+
receipt.payments.length > 0 && require_serialize.el("kifizetesek", receipt.payments.map(paymentNode)),
|
|
1134
|
+
require_serialize.el("osszegek", [...vatGroupsOf(receipt.items).map(vatGroupNode), totalNode(receipt.totals)])
|
|
1135
|
+
]);
|
|
1136
|
+
}
|
|
1137
|
+
function receiptResponse(state, receipt, includePdf) {
|
|
1138
|
+
return xmlResponse(xmlDocument("xmlnyugtavalasz", [
|
|
1139
|
+
require_serialize.el("sikeres", true),
|
|
1140
|
+
includePdf && require_serialize.el("nyugtaPdf", require_binary.bytesToBase64(fakePdf(receipt.number))),
|
|
1141
|
+
receiptNode(receipt, state.config.testAccount)
|
|
1142
|
+
]));
|
|
1143
|
+
}
|
|
1144
|
+
function downloadPdfOf(root) {
|
|
1145
|
+
return require_serialize.childBoolean(require_serialize.findChild(root, "beallitasok"), "pdfLetoltes") === true;
|
|
1146
|
+
}
|
|
1147
|
+
function handleCreateReceipt(state, request) {
|
|
1148
|
+
const { root } = request;
|
|
1149
|
+
const header = require_serialize.findChild(root, "fejlec");
|
|
1150
|
+
if (!header) throw xmlFailure("hiányzik a <fejlec> blokk.");
|
|
1151
|
+
const callId = require_serialize.childText(header, "hivasAzonosito");
|
|
1152
|
+
assertUnusedCallId(state, callId);
|
|
1153
|
+
const prefix = resolvePrefix(state, header);
|
|
1154
|
+
const paymentMethod = requiredText(header, "fizmod", "fejlec");
|
|
1155
|
+
const currency = require_serialize.childText(header, "penznem") ?? "HUF";
|
|
1156
|
+
const exchange = exchangeOf(header, currency);
|
|
1157
|
+
const items = parseItems(root, "receipt");
|
|
1158
|
+
assertReceiptItems(items, currency);
|
|
1159
|
+
const totals = totalsOf(items);
|
|
1160
|
+
const payments = require_serialize.findChildren(require_serialize.findChild(root, "kifizetesek"), "kifizetes").map(paymentOf);
|
|
1161
|
+
assertPaymentsMatch(payments, totals.gross);
|
|
1162
|
+
const orderNumber = require_serialize.childText(header, "rendelesSzam");
|
|
1163
|
+
assertUniqueOrderNumber(state, orderNumber);
|
|
1164
|
+
const receipt = {
|
|
1165
|
+
id: nextDocumentId(state),
|
|
1166
|
+
number: nextDocumentNumber(state, prefix),
|
|
1167
|
+
prefix,
|
|
1168
|
+
callId,
|
|
1169
|
+
type: "NY",
|
|
1170
|
+
reversed: false,
|
|
1171
|
+
issueDate: today(state),
|
|
1172
|
+
paymentMethod,
|
|
1173
|
+
currency,
|
|
1174
|
+
...exchange,
|
|
1175
|
+
comment: require_serialize.childText(header, "megjegyzes"),
|
|
1176
|
+
customerLedgerId: require_serialize.childText(header, "fokonyvVevo"),
|
|
1177
|
+
orderNumber,
|
|
1178
|
+
items,
|
|
1179
|
+
payments,
|
|
1180
|
+
totals,
|
|
1181
|
+
sentTo: []
|
|
1182
|
+
};
|
|
1183
|
+
state.receipts.set(receipt.number, receipt);
|
|
1184
|
+
return receiptResponse(state, receipt, downloadPdfOf(root));
|
|
1185
|
+
}
|
|
1186
|
+
function handleReverseReceipt(state, request) {
|
|
1187
|
+
const { root } = request;
|
|
1188
|
+
const header = require_serialize.findChild(root, "fejlec");
|
|
1189
|
+
const number = requiredText(header, "nyugtaszam", "fejlec");
|
|
1190
|
+
const callId = require_serialize.childText(header, "hivasAzonosito");
|
|
1191
|
+
assertUnusedCallId(state, callId);
|
|
1192
|
+
const original = state.receipts.get(number);
|
|
1193
|
+
if (!original) throw agentFailure(339, "Hiányzó adat: sztornózandó nyugta (nincs ilyen nyugtaszám)");
|
|
1194
|
+
if (original.type === "SN") throw new FakeAgentFailure(void 0, "Hiányzó adat: sztornózandó nyugta (ez a nyugta egy sztornónyugta)");
|
|
1195
|
+
if (original.reversed) throw new FakeAgentFailure(void 0, `Hiányzó adat: sztornózandó nyugta (ezt a nyugtát már sztornózták: ${number})`);
|
|
1196
|
+
const reversal = {
|
|
1197
|
+
...original,
|
|
1198
|
+
id: nextDocumentId(state),
|
|
1199
|
+
number: nextDocumentNumber(state, original.prefix),
|
|
1200
|
+
callId,
|
|
1201
|
+
type: "SN",
|
|
1202
|
+
reversed: false,
|
|
1203
|
+
reversedNumber: original.number,
|
|
1204
|
+
issueDate: today(state),
|
|
1205
|
+
items: original.items.map(negateItem),
|
|
1206
|
+
payments: original.payments.map((payment) => ({
|
|
1207
|
+
...payment,
|
|
1208
|
+
amount: -payment.amount
|
|
1209
|
+
})),
|
|
1210
|
+
totals: negateTotals(original.totals),
|
|
1211
|
+
sentTo: []
|
|
1212
|
+
};
|
|
1213
|
+
state.receipts.set(original.number, {
|
|
1214
|
+
...original,
|
|
1215
|
+
reversed: true
|
|
1216
|
+
});
|
|
1217
|
+
state.receipts.set(reversal.number, reversal);
|
|
1218
|
+
return receiptResponse(state, reversal, downloadPdfOf(root));
|
|
1219
|
+
}
|
|
1220
|
+
function handleGetReceipt(state, request) {
|
|
1221
|
+
const { root } = request;
|
|
1222
|
+
const header = require_serialize.findChild(root, "fejlec");
|
|
1223
|
+
const number = require_serialize.childText(header, "nyugtaszam");
|
|
1224
|
+
const orderNumber = require_serialize.childText(header, "rendelesSzam");
|
|
1225
|
+
if (number === void 0 && orderNumber === void 0) throw xmlFailure("add meg a nyugtaszámot (nyugtaszam) vagy a rendelésszámot (rendelesSzam).");
|
|
1226
|
+
const receipt = number !== void 0 ? state.receipts.get(number) : [...state.receipts.values()].findLast((candidate) => candidate.orderNumber === orderNumber);
|
|
1227
|
+
if (!receipt) throw agentFailure(339);
|
|
1228
|
+
return receiptResponse(state, receipt, downloadPdfOf(root));
|
|
1229
|
+
}
|
|
1230
|
+
function handleSendReceipt(state, request) {
|
|
1231
|
+
const { root } = request;
|
|
1232
|
+
const number = requiredText(require_serialize.findChild(root, "fejlec"), "nyugtaszam", "fejlec");
|
|
1233
|
+
const email = require_serialize.findChild(root, "emailKuldes");
|
|
1234
|
+
const recipients = require_serialize.childText(email, "email");
|
|
1235
|
+
if (recipients === void 0) throw agentFailure(7, "Hiányzó adat: email elem.");
|
|
1236
|
+
if (require_serialize.childText(email, "emailTargy") === void 0) throw agentFailure(7, "Hiányzó adat: emailtargy elem.");
|
|
1237
|
+
const receipt = state.receipts.get(number);
|
|
1238
|
+
if (!receipt) throw agentFailure(339);
|
|
1239
|
+
const addresses = recipients.split(/[,;]/).map((address) => address.trim()).filter((address) => address !== "");
|
|
1240
|
+
state.receipts.set(number, {
|
|
1241
|
+
...receipt,
|
|
1242
|
+
sentTo: [...receipt.sentTo, addresses]
|
|
1243
|
+
});
|
|
1244
|
+
return xmlResponse(xmlDocument("xmlnyugtasendvalasz", [require_serialize.el("sikeres", true)]));
|
|
1245
|
+
}
|
|
1246
|
+
//#endregion
|
|
1247
|
+
//#region src/testing/fake-agent.ts
|
|
1248
|
+
const HANDLERS = {
|
|
1249
|
+
createInvoice: handleCreateInvoice,
|
|
1250
|
+
reverseInvoice: handleReverseInvoice,
|
|
1251
|
+
registerPayment: handleRegisterPayment,
|
|
1252
|
+
getInvoicePdf: handleGetInvoicePdf,
|
|
1253
|
+
getInvoiceXml: handleGetInvoiceXml,
|
|
1254
|
+
deleteProforma: handleDeleteProforma,
|
|
1255
|
+
createReceipt: handleCreateReceipt,
|
|
1256
|
+
reverseReceipt: handleReverseReceipt,
|
|
1257
|
+
getReceipt: handleGetReceipt,
|
|
1258
|
+
sendReceipt: handleSendReceipt,
|
|
1259
|
+
queryTaxpayer: handleQueryTaxpayer,
|
|
1260
|
+
connectPrincipal: handleConnectPrincipal
|
|
1261
|
+
};
|
|
1262
|
+
const NAMED_FAULTS = {
|
|
1263
|
+
ghostSuccess: {
|
|
1264
|
+
stage: "after",
|
|
1265
|
+
effect: "timeout"
|
|
1266
|
+
},
|
|
1267
|
+
timeout: {
|
|
1268
|
+
stage: "before",
|
|
1269
|
+
effect: "timeout"
|
|
1270
|
+
},
|
|
1271
|
+
networkError: {
|
|
1272
|
+
stage: "before",
|
|
1273
|
+
effect: "network"
|
|
1274
|
+
},
|
|
1275
|
+
serverError: {
|
|
1276
|
+
stage: "before",
|
|
1277
|
+
effect: "server-error"
|
|
1278
|
+
},
|
|
1279
|
+
maintenance: {
|
|
1280
|
+
stage: "before",
|
|
1281
|
+
effect: "code",
|
|
1282
|
+
code: 1
|
|
1283
|
+
},
|
|
1284
|
+
partialSuccess: {
|
|
1285
|
+
stage: "after",
|
|
1286
|
+
effect: "code",
|
|
1287
|
+
code: 56
|
|
1288
|
+
},
|
|
1289
|
+
testAccountLimit: {
|
|
1290
|
+
stage: "before",
|
|
1291
|
+
effect: "code",
|
|
1292
|
+
code: 167
|
|
1293
|
+
},
|
|
1294
|
+
duplicateCallId: {
|
|
1295
|
+
stage: "before",
|
|
1296
|
+
effect: "code",
|
|
1297
|
+
code: 338
|
|
1298
|
+
},
|
|
1299
|
+
duplicateOrderNumber: {
|
|
1300
|
+
stage: "before",
|
|
1301
|
+
effect: "code",
|
|
1302
|
+
code: 152
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
const DEFAULT_SELLER = {
|
|
1306
|
+
name: "Kassza Teszt Kft.",
|
|
1307
|
+
taxNumber: "12345676-2-42",
|
|
1308
|
+
zip: "1111",
|
|
1309
|
+
city: "Budapest",
|
|
1310
|
+
address: "Teszt utca 1."
|
|
1311
|
+
};
|
|
1312
|
+
const DEFAULT_INVOICE_PREFIX = "KASSZA";
|
|
1313
|
+
const KNOWN_ACTIONS = new Set(Object.keys(require_create_once.AGENT_ACTIONS));
|
|
1314
|
+
function behaviorOf(fault) {
|
|
1315
|
+
if (typeof fault === "string") {
|
|
1316
|
+
const behavior = NAMED_FAULTS[fault];
|
|
1317
|
+
if (!behavior) throw new TypeError(`Ismeretlen hamis Agent hiba: ${String(fault)}`);
|
|
1318
|
+
return behavior;
|
|
1319
|
+
}
|
|
1320
|
+
if (!Number.isInteger(fault.code) || fault.code < 1) throw new TypeError(`A hibakód pozitív egész szám legyen, kapott: ${String(fault.code)}`);
|
|
1321
|
+
return {
|
|
1322
|
+
stage: fault.afterSuccess === true ? "after" : "before",
|
|
1323
|
+
effect: "code",
|
|
1324
|
+
code: fault.code,
|
|
1325
|
+
message: fault.message
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1328
|
+
function pendingFault(fault, options) {
|
|
1329
|
+
const times = options.times ?? 1;
|
|
1330
|
+
if (!Number.isInteger(times) || times < 1) throw new TypeError(`A times értéke legalább 1 egész szám legyen, kapott: ${String(times)}`);
|
|
1331
|
+
if (options.action !== void 0 && !KNOWN_ACTIONS.has(options.action)) throw new TypeError(`Ismeretlen Agent művelet: ${String(options.action)}`);
|
|
1332
|
+
return {
|
|
1333
|
+
behavior: behaviorOf(fault),
|
|
1334
|
+
action: options.action,
|
|
1335
|
+
remaining: times
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
function duplicateFlags(value) {
|
|
1339
|
+
if (typeof value === "boolean") return {
|
|
1340
|
+
invoices: value,
|
|
1341
|
+
receipts: value
|
|
1342
|
+
};
|
|
1343
|
+
return {
|
|
1344
|
+
invoices: value?.invoices === true,
|
|
1345
|
+
receipts: value?.receipts === true
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
function normalizedTaxpayers(taxpayers) {
|
|
1349
|
+
return Object.fromEntries(Object.entries(taxpayers ?? {}).map(([taxNumber, taxpayer]) => [taxpayerKey(taxNumber), taxpayer]));
|
|
1350
|
+
}
|
|
1351
|
+
function seededPrincipals(options) {
|
|
1352
|
+
return new Map(Object.entries(options.principals ?? {}).map(([taxNumber, state]) => [taxpayerKey(taxNumber), {
|
|
1353
|
+
state,
|
|
1354
|
+
joinRequests: 0
|
|
1355
|
+
}]));
|
|
1356
|
+
}
|
|
1357
|
+
function createState(options) {
|
|
1358
|
+
const duplicates = duplicateFlags(options.rejectDuplicateOrderNumbers);
|
|
1359
|
+
return {
|
|
1360
|
+
now: options.now ?? (() => /* @__PURE__ */ new Date()),
|
|
1361
|
+
config: {
|
|
1362
|
+
seller: {
|
|
1363
|
+
...DEFAULT_SELLER,
|
|
1364
|
+
...options.seller
|
|
1365
|
+
},
|
|
1366
|
+
testAccount: options.testAccount ?? true,
|
|
1367
|
+
defaultInvoicePrefix: options.defaultInvoicePrefix ?? options.invoicePrefixes?.[0] ?? DEFAULT_INVOICE_PREFIX,
|
|
1368
|
+
invoicePrefixes: options.invoicePrefixes && new Set(options.invoicePrefixes),
|
|
1369
|
+
receiptPrefixes: options.receiptPrefixes && new Set(options.receiptPrefixes),
|
|
1370
|
+
uniqueInvoiceOrderNumbers: duplicates.invoices,
|
|
1371
|
+
uniqueReceiptOrderNumbers: duplicates.receipts,
|
|
1372
|
+
strictAuth: options.agentKeys !== void 0 || options.users !== void 0,
|
|
1373
|
+
agentKeys: new Set(options.agentKeys ?? []),
|
|
1374
|
+
taxpayers: normalizedTaxpayers(options.taxpayers)
|
|
1375
|
+
},
|
|
1376
|
+
invoices: /* @__PURE__ */ new Map(),
|
|
1377
|
+
receipts: /* @__PURE__ */ new Map(),
|
|
1378
|
+
counters: /* @__PURE__ */ new Map(),
|
|
1379
|
+
principals: seededPrincipals(options),
|
|
1380
|
+
delegates: /* @__PURE__ */ new Map(),
|
|
1381
|
+
users: new Map(Object.entries(options.users ?? {}))
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
function timeoutError() {
|
|
1385
|
+
return new DOMException("A hamis Agent nem küldött választ (időtúllépés).", "TimeoutError");
|
|
1386
|
+
}
|
|
1387
|
+
function orderNumberOf(root) {
|
|
1388
|
+
return require_serialize.childText(require_serialize.findChild(root, "fejlec"), "rendelesSzam");
|
|
1389
|
+
}
|
|
1390
|
+
function faultFailure(behavior, root) {
|
|
1391
|
+
const code = behavior.code ?? 1;
|
|
1392
|
+
if (behavior.message !== void 0) return new FakeAgentFailure(code, behavior.message);
|
|
1393
|
+
if (code === 152) return agentFailure(152, `Már létező rendelésszám: ${orderNumberOf(root) ?? "XXX"}. Az ismétlődés engedélyezhető a Beállítások oldalon.`);
|
|
1394
|
+
return agentFailure(code);
|
|
1395
|
+
}
|
|
1396
|
+
function respondBefore(behavior, request) {
|
|
1397
|
+
if (behavior.effect === "timeout") throw timeoutError();
|
|
1398
|
+
if (behavior.effect === "network") throw new TypeError("fetch failed");
|
|
1399
|
+
if (behavior.effect === "server-error") return serverErrorResponse();
|
|
1400
|
+
return errorResponse(errorStyleFor(request.action, request.root), faultFailure(behavior, request.root));
|
|
1401
|
+
}
|
|
1402
|
+
function createFakeAgentFetch(options = {}) {
|
|
1403
|
+
let state = createState(options);
|
|
1404
|
+
const requests = [];
|
|
1405
|
+
const faults = [];
|
|
1406
|
+
const scheduleInitialFaults = () => {
|
|
1407
|
+
for (const scheduled of options.faults ?? []) faults.push(pendingFault(scheduled.fault, scheduled));
|
|
1408
|
+
};
|
|
1409
|
+
scheduleInitialFaults();
|
|
1410
|
+
const takeFault = (action) => {
|
|
1411
|
+
const index = faults.findIndex((fault) => fault.action === void 0 || fault.action === action);
|
|
1412
|
+
const fault = faults[index];
|
|
1413
|
+
if (!fault) return void 0;
|
|
1414
|
+
fault.remaining -= 1;
|
|
1415
|
+
if (fault.remaining === 0) faults.splice(index, 1);
|
|
1416
|
+
return fault.behavior;
|
|
1417
|
+
};
|
|
1418
|
+
const perform = (request) => {
|
|
1419
|
+
try {
|
|
1420
|
+
authenticate(state, credentialsOf(request.root));
|
|
1421
|
+
return {
|
|
1422
|
+
response: HANDLERS[request.action](state, request),
|
|
1423
|
+
ok: true
|
|
1424
|
+
};
|
|
1425
|
+
} catch (error) {
|
|
1426
|
+
if (!(error instanceof FakeAgentFailure)) throw error;
|
|
1427
|
+
return {
|
|
1428
|
+
response: errorResponse(errorStyleFor(request.action, request.root), error),
|
|
1429
|
+
ok: false
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
const handle = (action, xml, attachments) => {
|
|
1434
|
+
let request;
|
|
1435
|
+
try {
|
|
1436
|
+
request = parseFakeAgentRequest(action, xml, attachments);
|
|
1437
|
+
} catch (error) {
|
|
1438
|
+
if (!(error instanceof FakeAgentFailure)) throw error;
|
|
1439
|
+
return errorResponse(errorStyleFor(action, void 0), error);
|
|
1440
|
+
}
|
|
1441
|
+
const fault = takeFault(action);
|
|
1442
|
+
if (fault?.stage === "before") return respondBefore(fault, request);
|
|
1443
|
+
const { response, ok } = perform(request);
|
|
1444
|
+
if (fault?.effect === "timeout") throw timeoutError();
|
|
1445
|
+
if (fault && ok) return errorResponse(errorStyleFor(action, request.root), faultFailure(fault, request.root));
|
|
1446
|
+
return response;
|
|
1447
|
+
};
|
|
1448
|
+
const fakeFetch = async (input, init) => {
|
|
1449
|
+
init?.signal?.throwIfAborted();
|
|
1450
|
+
const record = await readFakeAgentForm(input, init);
|
|
1451
|
+
requests.push(record);
|
|
1452
|
+
if (record.action === void 0 || record.xml === void 0) return toFetchResponse(errorResponse("text", agentFailure(53)));
|
|
1453
|
+
return toFetchResponse(handle(record.action, record.xml, record.attachments));
|
|
1454
|
+
};
|
|
1455
|
+
return {
|
|
1456
|
+
fetch: fakeFetch,
|
|
1457
|
+
requests,
|
|
1458
|
+
get invoices() {
|
|
1459
|
+
return state.invoices;
|
|
1460
|
+
},
|
|
1461
|
+
get receipts() {
|
|
1462
|
+
return state.receipts;
|
|
1463
|
+
},
|
|
1464
|
+
fail(fault, faultOptions = {}) {
|
|
1465
|
+
faults.push(pendingFault(fault, faultOptions));
|
|
1466
|
+
},
|
|
1467
|
+
acceptDelegation(taxNumber) {
|
|
1468
|
+
acceptDelegation(state, taxNumber);
|
|
1469
|
+
},
|
|
1470
|
+
reset() {
|
|
1471
|
+
state = createState(options);
|
|
1472
|
+
requests.length = 0;
|
|
1473
|
+
faults.length = 0;
|
|
1474
|
+
scheduleInitialFaults();
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
//#endregion
|
|
7
1479
|
//#region src/testing/index.ts
|
|
8
1480
|
const MOCK_PDF = new TextEncoder().encode("%PDF-1.4\n1 0 obj << /Type /Catalog >> endobj\ntrailer << /Root 1 0 R >>\n%%EOF\n");
|
|
9
1481
|
function notFound(code, message) {
|
|
@@ -38,11 +1510,18 @@ function normalizePayments(input, today) {
|
|
|
38
1510
|
description: input.description
|
|
39
1511
|
}];
|
|
40
1512
|
}
|
|
1513
|
+
let mockScopes = 0;
|
|
41
1514
|
function createMockKassza(options = {}) {
|
|
42
1515
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
43
1516
|
const calls = [];
|
|
44
1517
|
const failures = /* @__PURE__ */ new Map();
|
|
45
|
-
const
|
|
1518
|
+
const hooks = options.hooks;
|
|
1519
|
+
const emit = (event) => require_create_once.emitDocumentEvent(hooks?.onDocument, event, {
|
|
1520
|
+
mode: hooks?.onDocumentError,
|
|
1521
|
+
onWarning: hooks?.onWarning
|
|
1522
|
+
});
|
|
1523
|
+
mockScopes += 1;
|
|
1524
|
+
const guard = { scope: `mock:${mockScopes}` };
|
|
46
1525
|
const invoices = /* @__PURE__ */ new Map();
|
|
47
1526
|
const receipts = /* @__PURE__ */ new Map();
|
|
48
1527
|
const sequences = /* @__PURE__ */ new Map();
|
|
@@ -171,10 +1650,10 @@ function createMockKassza(options = {}) {
|
|
|
171
1650
|
};
|
|
172
1651
|
const createReceiptRecord = (input, callId) => {
|
|
173
1652
|
const defaults = options.defaults?.receipt ?? {};
|
|
174
|
-
|
|
1653
|
+
require_create.buildCreateReceiptXml([], defaults, input);
|
|
175
1654
|
assertUniqueCallId(callId);
|
|
176
1655
|
const currency = input.currency ?? defaults.currency ?? "HUF";
|
|
177
|
-
const calculated =
|
|
1656
|
+
const calculated = require_create.calculateReceiptItems(input.items, currency);
|
|
178
1657
|
const totals = require_money.summarizeItems(calculated.map((item) => item.amounts));
|
|
179
1658
|
const prefix = (input.prefix ?? defaults.prefix ?? "NY").trim();
|
|
180
1659
|
const paymentMethod = (input.paymentMethod ?? defaults.paymentMethod ?? "").trim();
|
|
@@ -255,7 +1734,7 @@ function createMockKassza(options = {}) {
|
|
|
255
1734
|
const invoicesApi = {
|
|
256
1735
|
async create(input) {
|
|
257
1736
|
const document = await run("invoices.create", [input], () => createInvoiceRecord(input));
|
|
258
|
-
await
|
|
1737
|
+
await emit({
|
|
259
1738
|
kind: "invoice",
|
|
260
1739
|
action: "created",
|
|
261
1740
|
number: document.number,
|
|
@@ -267,7 +1746,7 @@ function createMockKassza(options = {}) {
|
|
|
267
1746
|
createOnce: (input, requestOptions) => run("invoices.createOnce", [input], () => require_issue.createInvoiceOnce(invoicesApi, input, {
|
|
268
1747
|
recoveryDelayMs: 0,
|
|
269
1748
|
...requestOptions
|
|
270
|
-
})),
|
|
1749
|
+
}, guard)),
|
|
271
1750
|
preview: (input) => run("invoices.preview", [input], () => {
|
|
272
1751
|
const items = require_create_once.resolveInvoice(options.defaults?.invoice ?? {}, input, now()).items.map((item) => item.amounts);
|
|
273
1752
|
const totals = require_money.summarizeItems(items);
|
|
@@ -320,7 +1799,7 @@ function createMockKassza(options = {}) {
|
|
|
320
1799
|
...downloadPdf ? { pdf: MOCK_PDF } : {}
|
|
321
1800
|
};
|
|
322
1801
|
});
|
|
323
|
-
await
|
|
1802
|
+
await emit({
|
|
324
1803
|
kind: "invoice",
|
|
325
1804
|
action: "reversed",
|
|
326
1805
|
number: document.number,
|
|
@@ -348,7 +1827,7 @@ function createMockKassza(options = {}) {
|
|
|
348
1827
|
outstanding: Math.max(0, found.details.totals.grossAmount - paid)
|
|
349
1828
|
};
|
|
350
1829
|
});
|
|
351
|
-
await
|
|
1830
|
+
await emit({
|
|
352
1831
|
kind: "invoice",
|
|
353
1832
|
action: "payment",
|
|
354
1833
|
number: document.invoiceNumber,
|
|
@@ -356,6 +1835,10 @@ function createMockKassza(options = {}) {
|
|
|
356
1835
|
});
|
|
357
1836
|
return document;
|
|
358
1837
|
},
|
|
1838
|
+
registerPaymentOnce: (input, requestOptions) => run("invoices.registerPaymentOnce", [input], () => require_create_once.registerPaymentOnce(invoicesApi, input, {
|
|
1839
|
+
recoveryDelayMs: 0,
|
|
1840
|
+
...requestOptions
|
|
1841
|
+
}, guard)),
|
|
359
1842
|
async clearPayments(input) {
|
|
360
1843
|
const document = await run("invoices.clearPayments", [input], () => {
|
|
361
1844
|
const found = findInvoice(typeof input === "string" ? input : input.invoiceNumber);
|
|
@@ -367,7 +1850,7 @@ function createMockKassza(options = {}) {
|
|
|
367
1850
|
outstanding: found.details.totals.grossAmount
|
|
368
1851
|
};
|
|
369
1852
|
});
|
|
370
|
-
await
|
|
1853
|
+
await emit({
|
|
371
1854
|
kind: "invoice",
|
|
372
1855
|
action: "payment",
|
|
373
1856
|
number: document.invoiceNumber,
|
|
@@ -396,7 +1879,7 @@ function createMockKassza(options = {}) {
|
|
|
396
1879
|
const receiptsApi = {
|
|
397
1880
|
async create(input) {
|
|
398
1881
|
const document = await run("receipts.create", [input], () => createReceiptRecord(input, input.callId));
|
|
399
|
-
await
|
|
1882
|
+
await emit({
|
|
400
1883
|
kind: "receipt",
|
|
401
1884
|
action: "created",
|
|
402
1885
|
number: document.number,
|
|
@@ -407,7 +1890,7 @@ function createMockKassza(options = {}) {
|
|
|
407
1890
|
createOnce: (input, requestOptions) => run("receipts.createOnce", [input], () => require_create_once.createReceiptOnce(receiptsApi, input, {
|
|
408
1891
|
recoveryDelayMs: 0,
|
|
409
1892
|
...requestOptions
|
|
410
|
-
})),
|
|
1893
|
+
}, guard)),
|
|
411
1894
|
async reverse(input) {
|
|
412
1895
|
const receiptNumber = typeof input === "string" ? input : input.receiptNumber;
|
|
413
1896
|
const callId = typeof input === "string" ? void 0 : input.callId;
|
|
@@ -440,7 +1923,7 @@ function createMockKassza(options = {}) {
|
|
|
440
1923
|
pdf: MOCK_PDF
|
|
441
1924
|
};
|
|
442
1925
|
});
|
|
443
|
-
await
|
|
1926
|
+
await emit({
|
|
444
1927
|
kind: "receipt",
|
|
445
1928
|
action: "reversed",
|
|
446
1929
|
number: document.number,
|
|
@@ -504,5 +1987,7 @@ function createMockKassza(options = {}) {
|
|
|
504
1987
|
};
|
|
505
1988
|
}
|
|
506
1989
|
//#endregion
|
|
1990
|
+
exports.CONNECT_PRINCIPAL_MESSAGES = CONNECT_PRINCIPAL_MESSAGES;
|
|
507
1991
|
exports.MOCK_PDF = MOCK_PDF;
|
|
1992
|
+
exports.createFakeAgentFetch = createFakeAgentFetch;
|
|
508
1993
|
exports.createMockKassza = createMockKassza;
|