@things-factory/tax-invoice 10.1.280 → 10.1.281

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.
@@ -0,0 +1,59 @@
1
+ import { EntityManager } from 'typeorm';
2
+ import { InvoiceType } from '../tax-invoice/tax-invoice-codes.js';
3
+ import { HometaxFileReport } from './hometax-tax-invoice-import.js';
4
+ import { HometaxTaxInvoiceList } from './hometax-tax-invoice-list.js';
5
+ /**
6
+ * Tax invoices a collecting service read from Hometax (ADR-0204 decision 2) into the domain - through the same save a
7
+ * downloaded Hometax list goes through (`saveHometaxTaxInvoices`): an approval number already on file is left, one with
8
+ * other facts is a conflict and not overwritten, and the invoices must be the domain's own business's.
9
+ */
10
+ /** A party as the collector gives it (integration-barobill `InvoiceParty`). */
11
+ export interface CollectedInvoiceParty {
12
+ bizNumber: string;
13
+ subId?: string | null;
14
+ name?: string | null;
15
+ ceo?: string | null;
16
+ address?: string | null;
17
+ email?: string | null;
18
+ }
19
+ /** An invoice as the collector gives it (integration-barobill `TaxInvoiceFacts`). */
20
+ export interface CollectedTaxInvoice {
21
+ side: 'sales' | 'purchase';
22
+ approvalNumber: string;
23
+ writeDate: string;
24
+ issuedLocalTime?: string | null;
25
+ sentLocalTime?: string | null;
26
+ modifyCode?: string | null;
27
+ taxType?: string | null;
28
+ purposeType?: string | null;
29
+ supplier: CollectedInvoiceParty;
30
+ buyer: CollectedInvoiceParty;
31
+ supplyAmount: number;
32
+ taxAmount: number;
33
+ totalAmount: number;
34
+ itemName?: string | null;
35
+ remarks?: string[];
36
+ }
37
+ export interface CollectedTaxInvoiceList {
38
+ side: 'sales' | 'purchase';
39
+ invoices: CollectedTaxInvoice[];
40
+ }
41
+ /** The collector's approval number in the Hometax form, 'YYYYMMDD-XXXXXXXX-XXXXXXXX'. */
42
+ export declare function approvalNumberOf(value: string): string | null;
43
+ /**
44
+ * The kind of invoice from the collector's tax type (1 taxed, 2 zero-rated, 3 exempt - an exempt one is a 계산서) and
45
+ * whether it is a correction (a modify code other than 0). A tax type it does not know is a problem, not a guess.
46
+ */
47
+ export declare function invoiceTypeOf(taxType: string | null | undefined, modifyCode: string | null | undefined): InvoiceType | null;
48
+ /** One collected side as the list a Hometax download is read into - its problems named the same way. */
49
+ export declare function collectedHometaxList(list: CollectedTaxInvoiceList, ownerBusinessNumber: string | undefined): HometaxTaxInvoiceList;
50
+ /**
51
+ * Saves the collected lists - all or nothing, as a download is. `ownerBusinessNumber` is the company the collector
52
+ * reads for; each list is said as `<collector> <side>` in the reports.
53
+ */
54
+ export declare function saveCollectedTaxInvoices(tx: EntityManager, context: {
55
+ domain: {
56
+ id: string;
57
+ };
58
+ user?: any;
59
+ }, collector: string, ownerBusinessNumber: string, lists: CollectedTaxInvoiceList[]): Promise<HometaxFileReport[]>;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.approvalNumberOf = approvalNumberOf;
4
+ exports.invoiceTypeOf = invoiceTypeOf;
5
+ exports.collectedHometaxList = collectedHometaxList;
6
+ exports.saveCollectedTaxInvoices = saveCollectedTaxInvoices;
7
+ const tax_invoice_codes_js_1 = require("../tax-invoice/tax-invoice-codes.js");
8
+ const hometax_tax_invoice_import_js_1 = require("./hometax-tax-invoice-import.js");
9
+ /** The collector's approval number in the Hometax form, 'YYYYMMDD-XXXXXXXX-XXXXXXXX'. */
10
+ function approvalNumberOf(value) {
11
+ const plain = String(value ?? '').replace(/-/g, '').trim();
12
+ return /^\d{8}[0-9a-zA-Z]{16}$/.test(plain) ? `${plain.slice(0, 8)}-${plain.slice(8, 16)}-${plain.slice(16)}` : null;
13
+ }
14
+ /**
15
+ * The kind of invoice from the collector's tax type (1 taxed, 2 zero-rated, 3 exempt - an exempt one is a 계산서) and
16
+ * whether it is a correction (a modify code other than 0). A tax type it does not know is a problem, not a guess.
17
+ */
18
+ function invoiceTypeOf(taxType, modifyCode) {
19
+ const revised = !!modifyCode && modifyCode !== '0';
20
+ switch (String(taxType ?? '').trim()) {
21
+ case '1':
22
+ return revised ? tax_invoice_codes_js_1.InvoiceType.REVISED_GENERAL_TAX_INVOICE : tax_invoice_codes_js_1.InvoiceType.GENERAL_TAX_INVOICE;
23
+ case '2':
24
+ return revised ? tax_invoice_codes_js_1.InvoiceType.REVISED_ZERORATED_TAX_INVOICE : tax_invoice_codes_js_1.InvoiceType.ZERO_RATED_TAX_INVOICE;
25
+ case '3':
26
+ return revised ? tax_invoice_codes_js_1.InvoiceType.REVISED_GENERAL_INVOICE : tax_invoice_codes_js_1.InvoiceType.GENERAL_INVOICE;
27
+ default:
28
+ return null;
29
+ }
30
+ }
31
+ const PURPOSES = { '1': tax_invoice_codes_js_1.Purpose.RECEIPT, '2': tax_invoice_codes_js_1.Purpose.BILLING };
32
+ const dayOf = (localTime) => (localTime && /^\d{4}-\d{2}-\d{2}/.test(localTime) ? localTime.slice(0, 10) : undefined);
33
+ const numberCategoryOf = (digits) => (digits.length === 13 ? tax_invoice_codes_js_1.BusinessRegistrationCategory.RESIDENT_REGISTRATION_NUMBER : tax_invoice_codes_js_1.BusinessRegistrationCategory.BUSINESS_REGISTRATION_NUMBER);
34
+ /** One collected side as the list a Hometax download is read into - its problems named the same way. */
35
+ function collectedHometaxList(list, ownerBusinessNumber) {
36
+ const category = list.side === 'sales' ? tax_invoice_codes_js_1.Category.EXPORT : tax_invoice_codes_js_1.Category.IMPORT;
37
+ const problems = [];
38
+ const invoices = [];
39
+ for (const one of list.invoices ?? []) {
40
+ const approvalNo = approvalNumberOf(one.approvalNumber);
41
+ if (!approvalNo) {
42
+ problems.push({ code: 'bad-approval-number', value: String(one.approvalNumber ?? '') });
43
+ continue;
44
+ }
45
+ const invoiceType = invoiceTypeOf(one.taxType, one.modifyCode);
46
+ if (!invoiceType) {
47
+ problems.push({ code: 'unknown-invoice-kind', approvalNo, value: String(one.taxType ?? '') });
48
+ continue;
49
+ }
50
+ const supplier = String(one.supplier?.bizNumber ?? '').replace(/\D/g, '');
51
+ const buyer = String(one.buyer?.bizNumber ?? '').replace(/\D/g, '');
52
+ const taxInvoice = {
53
+ category,
54
+ approvalNo,
55
+ issueDate: String(one.writeDate ?? '').slice(0, 10),
56
+ signatureDate: dayOf(one.issuedLocalTime),
57
+ transmissionDate: dayOf(one.sentLocalTime),
58
+ invoiceType,
59
+ purpose: PURPOSES[String(one.purposeType ?? '').trim()],
60
+ supplierBusinessRegistrationCategory: numberCategoryOf(supplier),
61
+ supplierBusinessRegistrationNumber: supplier,
62
+ supplierBranchIdentification: one.supplier?.subId || undefined,
63
+ supplierBusinessName: one.supplier?.name ?? '',
64
+ supplierRepresentativeName: one.supplier?.ceo ?? '',
65
+ supplierAddress: one.supplier?.address || undefined,
66
+ supplierContactEmail: one.supplier?.email || undefined,
67
+ buyerBusinessRegistrationCategory: numberCategoryOf(buyer),
68
+ buyerBusinessRegistrationNumber: buyer,
69
+ buyerBranchIdentification: one.buyer?.subId || undefined,
70
+ buyerBusinessName: one.buyer?.name ?? '',
71
+ buyerRepresentativeName: one.buyer?.ceo ?? '',
72
+ buyerAddress: one.buyer?.address || undefined,
73
+ supplyAmount: Number(one.supplyAmount),
74
+ taxAmount: Number(one.taxAmount),
75
+ totalAmount: Number(one.totalAmount)
76
+ };
77
+ const remark = (one.remarks ?? []).filter(Boolean).join(' ');
78
+ if (remark)
79
+ taxInvoice.remark0 = remark;
80
+ invoices.push({
81
+ taxInvoice,
82
+ taxInvoiceItems: [{ sequence: 1, supplyDate: taxInvoice.issueDate, itemName: one.itemName ?? undefined, supplyPrice: taxInvoice.supplyAmount, taxPrice: taxInvoice.taxAmount }]
83
+ });
84
+ }
85
+ return { category, ownerBusinessNumber, invoices, problems, notes: [] };
86
+ }
87
+ /**
88
+ * Saves the collected lists - all or nothing, as a download is. `ownerBusinessNumber` is the company the collector
89
+ * reads for; each list is said as `<collector> <side>` in the reports.
90
+ */
91
+ async function saveCollectedTaxInvoices(tx, context, collector, ownerBusinessNumber, lists) {
92
+ const owner = String(ownerBusinessNumber ?? '').replace(/\D/g, '') || undefined;
93
+ return (0, hometax_tax_invoice_import_js_1.saveHometaxTaxInvoices)(tx, context, (lists ?? []).map(list => ({ fileName: `${collector} ${list.side}`, list: collectedHometaxList(list, owner) })));
94
+ }
95
+ //# sourceMappingURL=collected-tax-invoices.js.map
@@ -2,6 +2,7 @@ import { HometaxResolver } from './hometax-resolver.js';
2
2
  export * from './hometax-tax-invoice-list.js';
3
3
  export * from './hometax-tax-invoice-import.js';
4
4
  export * from './hometax-type.js';
5
+ export * from './collected-tax-invoices.js';
5
6
  export { importHometaxTaxInvoiceFiles } from './hometax-resolver.js';
6
7
  export declare const entities: any[];
7
8
  export declare const resolvers: (typeof HometaxResolver)[];
@@ -6,6 +6,7 @@ const hometax_resolver_js_1 = require("./hometax-resolver.js");
6
6
  tslib_1.__exportStar(require("./hometax-tax-invoice-list.js"), exports);
7
7
  tslib_1.__exportStar(require("./hometax-tax-invoice-import.js"), exports);
8
8
  tslib_1.__exportStar(require("./hometax-type.js"), exports);
9
+ tslib_1.__exportStar(require("./collected-tax-invoices.js"), exports);
9
10
  var hometax_resolver_js_2 = require("./hometax-resolver.js");
10
11
  Object.defineProperty(exports, "importHometaxTaxInvoiceFiles", { enumerable: true, get: function () { return hometax_resolver_js_2.importHometaxTaxInvoiceFiles; } });
11
12
  exports.entities = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/tax-invoice",
3
- "version": "10.1.280",
3
+ "version": "10.1.281",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "files": [
@@ -50,14 +50,14 @@
50
50
  "@operato/input": "^10.29.79",
51
51
  "@operato/layout": "^10.29.69",
52
52
  "@operato/shell": "^10.29.69",
53
- "@things-factory/ai-assistant": "^10.1.280",
54
- "@things-factory/attachment-base": "^10.1.280",
55
- "@things-factory/auth-base": "^10.1.280",
56
- "@things-factory/env": "^10.1.280",
57
- "@things-factory/export-ui-excel": "^10.1.280",
58
- "@things-factory/shell": "^10.1.280",
53
+ "@things-factory/ai-assistant": "^10.1.281",
54
+ "@things-factory/attachment-base": "^10.1.281",
55
+ "@things-factory/auth-base": "^10.1.281",
56
+ "@things-factory/env": "^10.1.281",
57
+ "@things-factory/export-ui-excel": "^10.1.281",
58
+ "@things-factory/shell": "^10.1.281",
59
59
  "graphql-upload": "^15.0.2",
60
60
  "xlsx": "^0.18.5"
61
61
  },
62
- "gitHead": "14ce4b7f5957272d63115af316a7dc1ab030e152"
62
+ "gitHead": "c872f4723dcd72808f3c60a7d6c95521d4c2bbca"
63
63
  }