@things-factory/tax-invoice 6.2.143 → 6.2.144
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/client/pages/tax-invoice-send/tax-invoice-send-page.ts +34 -15
- package/dist-client/pages/tax-invoice-send/tax-invoice-send-page.d.ts +7 -3
- package/dist-client/pages/tax-invoice-send/tax-invoice-send-page.js +28 -13
- package/dist-client/pages/tax-invoice-send/tax-invoice-send-page.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/service/tax-invoice-api/tax-invoice-api-mutation.js +20 -1
- package/dist-server/service/tax-invoice-api/tax-invoice-api-mutation.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/service/tax-invoice-api/tax-invoice-api-mutation.ts +25 -3
|
@@ -54,11 +54,13 @@ let TaxInvoiceApiMutation = class TaxInvoiceApiMutation {
|
|
|
54
54
|
const businessRegistrationNumber = apiInfo.businessRegistrationNumber;
|
|
55
55
|
const { aid = '', bearer = '', customer_no = '' } = apiInfo === null || apiInfo === void 0 ? void 0 : apiInfo.attributes;
|
|
56
56
|
let failCount = 0;
|
|
57
|
+
let failMessage = [];
|
|
57
58
|
// 1. 밸리데이션 및 데이터 파싱
|
|
58
59
|
let newTaxInvoiceSendList = taxInvoiceSendList.map(taxInvoiceSend => this._parseTaxInvoiceSendForApi(taxInvoiceSend, aid, customer_no));
|
|
59
60
|
// 2. 세금계산서 발행 API 호출
|
|
60
61
|
const apiResult = await (0, tax_invoice_send_1.sendTaxInvoiceByUniposApi)(businessRegistrationNumber, aid, bearer, newTaxInvoiceSendList);
|
|
61
62
|
if (apiResult === false) {
|
|
63
|
+
// TODO 로그 찍기
|
|
62
64
|
throw new Error('tax invoice send exception: api error');
|
|
63
65
|
}
|
|
64
66
|
// 3. 성공하면 세금계산서 DB에 저장
|
|
@@ -74,11 +76,12 @@ let TaxInvoiceApiMutation = class TaxInvoiceApiMutation {
|
|
|
74
76
|
}
|
|
75
77
|
else {
|
|
76
78
|
failCount++;
|
|
79
|
+
failMessage.push(`${item.inv_seq}: ${item.message}`);
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
// 실패가 1개라도 있으면 에러
|
|
80
83
|
if (failCount > 0) {
|
|
81
|
-
throw new Error(failCount + '개의 계산서 등록에
|
|
84
|
+
throw new Error(failCount + '개의 계산서 등록에 실패하였습니다.\n' + failMessage.join('\n'));
|
|
82
85
|
}
|
|
83
86
|
return true;
|
|
84
87
|
}
|
|
@@ -97,6 +100,14 @@ let TaxInvoiceApiMutation = class TaxInvoiceApiMutation {
|
|
|
97
100
|
!taxInvoice.issueDate) {
|
|
98
101
|
throw new Error('tax invoice send exception: no essential value');
|
|
99
102
|
}
|
|
103
|
+
// 공급자 사업자 등록번호가 전부 숫자이며 10자리 인지 체크
|
|
104
|
+
if (isNaN(taxInvoice.supplierBusinessRegistrationNumber) || taxInvoice.supplierBusinessRegistrationNumber.length !== 10) {
|
|
105
|
+
throw new Error('tax invoice send exception: Supplier Business Registration Number is wrong');
|
|
106
|
+
}
|
|
107
|
+
// 공급받는자 사업자 등록번호가 전부 숫자이며 10자리 인지 체크
|
|
108
|
+
if (isNaN(taxInvoice.buyerBusinessRegistrationNumber) || taxInvoice.buyerBusinessRegistrationNumber.length !== 10) {
|
|
109
|
+
throw new Error('tax invoice send exception: Buyer Business Registration Number is wrong');
|
|
110
|
+
}
|
|
100
111
|
// 작성일자가 오늘 날짜를 넘어가면 에러
|
|
101
112
|
if (taxInvoice.issueDate > today) {
|
|
102
113
|
throw new Error('tax invoice send exception: issueDate error');
|
|
@@ -106,6 +117,10 @@ let TaxInvoiceApiMutation = class TaxInvoiceApiMutation {
|
|
|
106
117
|
if (paymentAmount > 0 && paymentAmount !== taxInvoice.totalAmount) {
|
|
107
118
|
throw new Error('tax invoice send exception: summary is not same');
|
|
108
119
|
}
|
|
120
|
+
// 영세업자인데 세금이 있으면 에러
|
|
121
|
+
if (taxInvoice.invoiceType === tax_invoice_1.InvoiceType.ZERO_RATED_TAX_INVOICE && taxInvoice.taxAmount > 0) {
|
|
122
|
+
throw new Error('tax invoice send exception: tax price is exist');
|
|
123
|
+
}
|
|
109
124
|
for (let item of taxInvoiceItems) {
|
|
110
125
|
// 아이템 필수값 체크
|
|
111
126
|
if (!item.supplyDate || !item.itemName || !item.quantity || !item.unitPrice) {
|
|
@@ -115,6 +130,10 @@ let TaxInvoiceApiMutation = class TaxInvoiceApiMutation {
|
|
|
115
130
|
if (taxInvoice.issueDate < item.supplyDate) {
|
|
116
131
|
throw new Error('tax invoice send exception: item supplyDate is bigger than issueDate');
|
|
117
132
|
}
|
|
133
|
+
// 영세업자인데 아이템 세금이 있으면 에러
|
|
134
|
+
if (taxInvoice.invoiceType === tax_invoice_1.InvoiceType.ZERO_RATED_TAX_INVOICE && item.taxPrice > 0) {
|
|
135
|
+
throw new Error('tax invoice send exception: item tax price is exist');
|
|
136
|
+
}
|
|
118
137
|
newTaxInvoiceItems.push({
|
|
119
138
|
tii_seqnumeric: item.sequence,
|
|
120
139
|
tii_purchaseexpirydatetime: item.supplyDate.replace(/-/g, ''),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tax-invoice-api-mutation.js","sourceRoot":"","sources":["../../../server/service/tax-invoice-api/tax-invoice-api-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,uDAAiD;AACjD,iEAA2E;AAC3E,2EAAqE;AACrE,4DAAiE;AACjE,sEAA2E;AAC3E,sEAAgF;AAGzE,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAG1B,AAAN,KAAK,CAAC,2BAA2B,CACe,OAA6B,EACpE,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,IAAI,OAAO,GAAG,EAAE,CAAA;QAChB,MAAM,cAAc,GAAG,OAA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,oCAAoC,EAAE,CAAC;IACxD,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAAiB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;iEAS7E;AAIK;IAFL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,6BAA6B,EAAE,CAAC;IAE1E,mBAAA,IAAA,kBAAG,EAAC,oBAAoB,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,qCAAc,CAAC,CAAC,CAAA;IACnD,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;iEAmDP;AAnHU,qBAAqB;IADjC,IAAA,uBAAQ,EAAC,+BAAa,CAAC;GACX,qBAAqB,CAiPjC;AAjPY,sDAAqB","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { TaxInvoiceApi } from './tax-invoice-api'\nimport { TaxInvoiceApiPatch, TaxInvoiceSend } from './tax-invoice-api-type'\nimport { TaxInvoiceItem } from '../tax-invoice-item/tax-invoice-item'\nimport { Category, TaxInvoice } from '../tax-invoice/tax-invoice'\nimport { sendTaxInvoiceByUniposApi } from '../unipost-api/tax-invoice-send'\nimport { parseTaxInvoiceByUnipostFormat } from '../tax-invoice/tax-invoice-util'\n\n@Resolver(TaxInvoiceApi)\nexport class TaxInvoiceApiMutation {\n @Directive('@transaction')\n @Mutation(returns => [TaxInvoiceApi], { description: 'To modify Tax Invoice Api information' })\n async updateMultipleTaxInvoiceApi(\n @Arg('patches', type => [TaxInvoiceApiPatch]) patches: TaxInvoiceApiPatch[],\n @Ctx() context: ResolverContext\n ): Promise<TaxInvoiceApi[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const taxInvoiceApiRepo = tx.getRepository(TaxInvoiceApi)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await taxInvoiceApiRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const taxAuditResult = await taxInvoiceApiRepo.findOneBy({ id: updateRecord.id })\n\n const result = await taxInvoiceApiRepo.save({\n ...taxAuditResult,\n ...updateRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple Tax Invoice Api' })\n async deleteTaxInvoiceApis(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(TaxInvoiceApi).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To Send Tax Invoices By Api' })\n async sendTaxInvoicesByApi(\n @Arg('taxInvoiceSendList', type => [TaxInvoiceSend]) taxInvoiceSendList: TaxInvoiceSend[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n if (taxInvoiceSendList.length === 0) throw new Error('tax invoice send exception: no list')\n\n const { domain, user, tx } = context.state\n const taxInvoiceRepo = tx.getRepository(TaxInvoice)\n const taxInvoiceItemRepo = tx.getRepository(TaxInvoiceItem)\n const taxInvoiceApiRepo = tx.getRepository(TaxInvoiceApi)\n\n const apiInfo = await taxInvoiceApiRepo.findOneBy({ isDefault: true })\n const businessRegistrationNumber = apiInfo.businessRegistrationNumber\n const { aid = '', bearer = '', customer_no = '' } = apiInfo?.attributes\n let failCount = 0\n\n // 1. 밸리데이션 및 데이터 파싱\n let newTaxInvoiceSendList = taxInvoiceSendList.map(taxInvoiceSend => this._parseTaxInvoiceSendForApi(taxInvoiceSend, aid, customer_no))\n\n // 2. 세금계산서 발행 API 호출\n const apiResult = await sendTaxInvoiceByUniposApi(businessRegistrationNumber, aid, bearer, newTaxInvoiceSendList)\n if (apiResult === false) {\n throw new Error('tax invoice send exception: api error')\n }\n\n // 3. 성공하면 세금계산서 DB에 저장\n for (let item of apiResult) {\n if (item?.success) {\n const { taxInvoice, taxInvoiceItems } = parseTaxInvoiceByUnipostFormat(item?.tAliceEntry, item?.tAliceEntry?.tAliceItemList, Category.EXPORT)\n\n // 세금계산서 저장\n const newTaxInvoice = await taxInvoiceRepo.save({\n ...taxInvoice,\n domain,\n creator: user,\n updater: user\n })\n\n // 아이템 저장\n for (const item of taxInvoiceItems) {\n await taxInvoiceItemRepo.save({ ...item, taxInvoice: newTaxInvoice, domain, creator: user })\n }\n } else {\n failCount++\n }\n }\n\n // 실패가 1개라도 있으면 에러\n if (failCount > 0) {\n throw new Error(failCount + '개의 계산서 등록에 실패하였습니다.')\n }\n\n return true\n }\n\n // 유니스포트에 받을수 있는 포맷으로 데이터 파싱\n private _parseTaxInvoiceSendForApi(taxInvoiceSend, aid, customer_no) {\n const { taxInvoice, taxInvoiceItems } = taxInvoiceSend\n let newTaxInvoiceItems: any = []\n const today = new Intl.DateTimeFormat('fr-CA', { timeZone: 'Asia/Seoul' }).format(new Date()) // YYYY-MM-DD\n\n // 필수값 체크\n if (\n !taxInvoice.supplierBusinessRegistrationNumber ||\n !taxInvoice.supplierBusinessName ||\n !taxInvoice.supplierRepresentativeName ||\n !taxInvoice.buyerBusinessRegistrationNumber ||\n !taxInvoice.buyerBusinessName ||\n !taxInvoice.buyerRepresentativeName ||\n !taxInvoice.issueDate\n ) {\n throw new Error('tax invoice send exception: no essential value')\n }\n\n // 작성일자가 오늘 날짜를 넘어가면 에러\n if (taxInvoice.issueDate > today) {\n throw new Error('tax invoice send exception: issueDate error')\n }\n\n // 현금, 수표, 어음, 외상미수금이 있을시 총 합계금액과 금액 동일 체크\n const paymentAmount: number =\n taxInvoice.paymentAmountCash + taxInvoice.paymentAmountCheck + taxInvoice.paymentAmountPromissoryNote + taxInvoice.paymentAmountAccountsReceivable\n\n if (paymentAmount > 0 && paymentAmount !== taxInvoice.totalAmount) {\n throw new Error('tax invoice send exception: summary is not same')\n }\n\n for (let item of taxInvoiceItems) {\n // 아이템 필수값 체크\n if (!item.supplyDate || !item.itemName || !item.quantity || !item.unitPrice) {\n throw new Error('tax invoice send exception: no item essential value')\n }\n\n // 아이템의 일자가 작성일자보다 크면 에러\n if (taxInvoice.issueDate < item.supplyDate) {\n throw new Error('tax invoice send exception: item supplyDate is bigger than issueDate')\n }\n\n newTaxInvoiceItems.push({\n tii_seqnumeric: item.sequence,\n tii_purchaseexpirydatetime: item.supplyDate.replace(/-/g, ''),\n tii_nametext: item.itemName,\n tii_informationtext: item.specification,\n tii_chargeableunitquantity: item.quantity,\n tii_unitprice_unitamount: item.unitPrice,\n tii_invoiceamount: item.supplyPrice,\n tii_totaltax_calcamount: item.taxPrice,\n tii_descriptiontext: item.remark\n })\n }\n\n return {\n aid: aid,\n inv_seq: today.replace(/-/g, '') + customer_no,\n exd_refdoc_id: null,\n tid_issuedatetime: taxInvoice.issueDate.replace(/-/g, ''),\n tid_typecode: taxInvoice.invoiceType,\n tid_purposecode: taxInvoice.purpose,\n tid_amendcode: taxInvoice.revisedReason,\n tid_originalissueid: null,\n tid_desc0: taxInvoice.remark0,\n tid_desc1: null,\n tid_desc2: null,\n tit_alice_specorg_biztypecode: taxInvoice.supplierBusinessRegistrationCategory,\n tit_alice_id: taxInvoice.supplierBusinessRegistrationNumber,\n tit_alice_specorg_taxregid: taxInvoice.supplierBranchIdentification,\n tit_alice_name: taxInvoice.supplierBusinessName,\n tit_alice_specperson_name: taxInvoice.supplierRepresentativeName,\n tit_alice_specaddr_lineone: taxInvoice.supplierAddress,\n tit_alice_typecode: taxInvoice.supplierBusinessType,\n tit_alice_classcode: taxInvoice.supplierIndustryType,\n tit_alice_defcont_deptname: taxInvoice.supplierDepartment,\n tit_alice_defcont_personname: taxInvoice.supplierContactName,\n tit_alice_defcont_telcomm: taxInvoice.supplierContactPhone,\n tit_alice_defcont_uricomm: taxInvoice.supplierContactEmail,\n tit_alice_defcont_cellphone: taxInvoice.supplierContactCellPhone,\n tit_bob_specorg_biztypecode: taxInvoice.buyerBusinessRegistrationCategory,\n tit_bob_id: taxInvoice.buyerBusinessRegistrationNumber,\n tit_bob_specorg_taxregid: taxInvoice.buyerBranchIdentification,\n tit_bob_name: taxInvoice.buyerBusinessName,\n tit_bob_specperson_name: taxInvoice.buyerRepresentativeName,\n tit_bob_specaddr_lineone: taxInvoice.buyerAddress,\n tit_bob_typecode: taxInvoice.buyerBusinessType,\n tit_bob_classcode: taxInvoice.buyerIndustryType,\n tit_bob_1stdefcont_deptname: taxInvoice.buyer1stDepartment,\n tit_bob_1stdefcont_personname: taxInvoice.buyer1stContactName,\n tit_bob_1stdefcont_telcomm: taxInvoice.buyer1stContactPhone,\n tit_bob_1stdefcont_uricomm: taxInvoice.buyer1stContactEmail,\n tit_bob_1stdefcont_cellphone: taxInvoice.buyer1stContactCellPhone,\n tit_bob_2nddefcont_deptname: taxInvoice.buyer2ndDepartment,\n tit_bob_2nddefcont_personname: taxInvoice.buyer2ndContactName,\n tit_bob_2nddefcont_telcomm: taxInvoice.buyer2ndContactPhone,\n tit_bob_2nddefcont_uricomm: taxInvoice.buyer2ndContactEmail,\n tit_bob_2nddefcont_cellphone: taxInvoice.buyer2ndContactCellPhone,\n tit_broker_specorg_biztypecode: taxInvoice.agentBusinessRegistrationCategory,\n tit_broker_id: taxInvoice.agentBusinessRegistrationNumber,\n tit_broker_specorg_taxregid: taxInvoice.agentBranchIdentification,\n tit_broker_name: taxInvoice.agentBusinessName,\n tit_broker_specperson_name: taxInvoice.agentRepresentativeName,\n tit_broker_specaddr_lineone: taxInvoice.agentAddress,\n tit_broker_typecode: taxInvoice.agentBusinessType,\n tit_broker_classcode: taxInvoice.agentIndustryType,\n tit_broker_defcont_deptname: taxInvoice.agentDepartment,\n tit_broker_defcont_personname: taxInvoice.agentContactName,\n tit_broker_defcont_telcomm: taxInvoice.agentContactPhone,\n tit_broker_defcont_uricomm: taxInvoice.agentContactEmail,\n tit_broker_defcont_cellphone: taxInvoice.agentContactCellPhone,\n tit_specpay_paidamount10: taxInvoice.paymentAmountCash,\n tit_specpay_paidamount20: taxInvoice.paymentAmountCheck,\n tit_specpay_paidamount30: taxInvoice.paymentAmountPromissoryNote,\n tit_specpay_paidamount40: taxInvoice.paymentAmountAccountsReceivable,\n tit_specsum_chargeamount: taxInvoice.supplyAmount,\n tit_specsum_taxamount: taxInvoice.taxAmount,\n tit_specsum_grandamount: taxInvoice.totalAmount,\n inv_sign: '',\n biz_tocharlesconfirmstatus: null,\n tAliceItemList: newTaxInvoiceItems\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tax-invoice-api-mutation.js","sourceRoot":"","sources":["../../../server/service/tax-invoice-api/tax-invoice-api-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,uDAAiD;AACjD,iEAA2E;AAC3E,2EAAqE;AACrE,4DAA8E;AAC9E,sEAA2E;AAC3E,sEAAgF;AAGzE,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAG1B,AAAN,KAAK,CAAC,2BAA2B,CACe,OAA6B,EACpE,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,IAAI,OAAO,GAAG,EAAE,CAAA;QAChB,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,CAAA;QACzF,MAAM,cAAc,GAAG,OAAO,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C,IAAA,uBAAQ,EAAC,+BAAa,CAAC;GACX,qBAAqB,CAuQjC;AAvQY,sDAAqB","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { TaxInvoiceApi } from './tax-invoice-api'\nimport { TaxInvoiceApiPatch, TaxInvoiceSend } from './tax-invoice-api-type'\nimport { TaxInvoiceItem } from '../tax-invoice-item/tax-invoice-item'\nimport { Category, InvoiceType, TaxInvoice } from '../tax-invoice/tax-invoice'\nimport { sendTaxInvoiceByUniposApi } from '../unipost-api/tax-invoice-send'\nimport { parseTaxInvoiceByUnipostFormat } from '../tax-invoice/tax-invoice-util'\n\n@Resolver(TaxInvoiceApi)\nexport class TaxInvoiceApiMutation {\n @Directive('@transaction')\n @Mutation(returns => [TaxInvoiceApi], { description: 'To modify Tax Invoice Api information' })\n async updateMultipleTaxInvoiceApi(\n @Arg('patches', type => [TaxInvoiceApiPatch]) patches: TaxInvoiceApiPatch[],\n @Ctx() context: ResolverContext\n ): Promise<TaxInvoiceApi[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const taxInvoiceApiRepo = tx.getRepository(TaxInvoiceApi)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await taxInvoiceApiRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const taxAuditResult = await taxInvoiceApiRepo.findOneBy({ id: updateRecord.id })\n\n const result = await taxInvoiceApiRepo.save({\n ...taxAuditResult,\n ...updateRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple Tax Invoice Api' })\n async deleteTaxInvoiceApis(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(TaxInvoiceApi).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To Send Tax Invoices By Api' })\n async sendTaxInvoicesByApi(\n @Arg('taxInvoiceSendList', type => [TaxInvoiceSend]) taxInvoiceSendList: TaxInvoiceSend[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n if (taxInvoiceSendList.length === 0) throw new Error('tax invoice send exception: no list')\n\n const { domain, user, tx } = context.state\n const taxInvoiceRepo = tx.getRepository(TaxInvoice)\n const taxInvoiceItemRepo = tx.getRepository(TaxInvoiceItem)\n const taxInvoiceApiRepo = tx.getRepository(TaxInvoiceApi)\n\n const apiInfo = await taxInvoiceApiRepo.findOneBy({ isDefault: true })\n const businessRegistrationNumber = apiInfo.businessRegistrationNumber\n const { aid = '', bearer = '', customer_no = '' } = apiInfo?.attributes\n let failCount = 0\n let failMessage = []\n\n // 1. 밸리데이션 및 데이터 파싱\n let newTaxInvoiceSendList = taxInvoiceSendList.map(taxInvoiceSend => this._parseTaxInvoiceSendForApi(taxInvoiceSend, aid, customer_no))\n\n // 2. 세금계산서 발행 API 호출\n const apiResult = await sendTaxInvoiceByUniposApi(businessRegistrationNumber, aid, bearer, newTaxInvoiceSendList)\n if (apiResult === false) {\n // TODO 로그 찍기\n throw new Error('tax invoice send exception: api error')\n }\n\n // 3. 성공하면 세금계산서 DB에 저장\n for (let item of apiResult) {\n if (item?.success) {\n const { taxInvoice, taxInvoiceItems } = parseTaxInvoiceByUnipostFormat(item?.tAliceEntry, item?.tAliceEntry?.tAliceItemList, Category.EXPORT)\n\n // 세금계산서 저장\n const newTaxInvoice = await taxInvoiceRepo.save({\n ...taxInvoice,\n domain,\n creator: user,\n updater: user\n })\n\n // 아이템 저장\n for (const item of taxInvoiceItems) {\n await taxInvoiceItemRepo.save({ ...item, taxInvoice: newTaxInvoice, domain, creator: user })\n }\n } else {\n failCount++\n failMessage.push(`${item.inv_seq}: ${item.message}`)\n }\n }\n\n // 실패가 1개라도 있으면 에러\n if (failCount > 0) {\n throw new Error(failCount + '개의 계산서 등록에 실패하였습니다.\\n' + failMessage.join('\\n'))\n }\n\n return true\n }\n\n // 유니스포트에 받을수 있는 포맷으로 데이터 파싱\n private _parseTaxInvoiceSendForApi(taxInvoiceSend, aid, customer_no) {\n const { taxInvoice, taxInvoiceItems } = taxInvoiceSend\n let newTaxInvoiceItems: any = []\n const today = new Intl.DateTimeFormat('fr-CA', { timeZone: 'Asia/Seoul' }).format(new Date()) // YYYY-MM-DD\n\n // 필수값 체크\n if (\n !taxInvoice.supplierBusinessRegistrationNumber ||\n !taxInvoice.supplierBusinessName ||\n !taxInvoice.supplierRepresentativeName ||\n !taxInvoice.buyerBusinessRegistrationNumber ||\n !taxInvoice.buyerBusinessName ||\n !taxInvoice.buyerRepresentativeName ||\n !taxInvoice.issueDate\n ) {\n throw new Error('tax invoice send exception: no essential value')\n }\n\n // 공급자 사업자 등록번호가 전부 숫자이며 10자리 인지 체크\n if (isNaN(taxInvoice.supplierBusinessRegistrationNumber) || taxInvoice.supplierBusinessRegistrationNumber.length !== 10) {\n throw new Error('tax invoice send exception: Supplier Business Registration Number is wrong')\n }\n\n // 공급받는자 사업자 등록번호가 전부 숫자이며 10자리 인지 체크\n if (isNaN(taxInvoice.buyerBusinessRegistrationNumber) || taxInvoice.buyerBusinessRegistrationNumber.length !== 10) {\n throw new Error('tax invoice send exception: Buyer Business Registration Number is wrong')\n }\n\n // 작성일자가 오늘 날짜를 넘어가면 에러\n if (taxInvoice.issueDate > today) {\n throw new Error('tax invoice send exception: issueDate error')\n }\n\n // 현금, 수표, 어음, 외상미수금이 있을시 총 합계금액과 금액 동일 체크\n const paymentAmount: number =\n taxInvoice.paymentAmountCash + taxInvoice.paymentAmountCheck + taxInvoice.paymentAmountPromissoryNote + taxInvoice.paymentAmountAccountsReceivable\n if (paymentAmount > 0 && paymentAmount !== taxInvoice.totalAmount) {\n throw new Error('tax invoice send exception: summary is not same')\n }\n\n // 영세업자인데 세금이 있으면 에러\n if (taxInvoice.invoiceType === InvoiceType.ZERO_RATED_TAX_INVOICE && taxInvoice.taxAmount > 0) {\n throw new Error('tax invoice send exception: tax price is exist')\n }\n\n for (let item of taxInvoiceItems) {\n // 아이템 필수값 체크\n if (!item.supplyDate || !item.itemName || !item.quantity || !item.unitPrice) {\n throw new Error('tax invoice send exception: no item essential value')\n }\n\n // 아이템의 일자가 작성일자보다 크면 에러\n if (taxInvoice.issueDate < item.supplyDate) {\n throw new Error('tax invoice send exception: item supplyDate is bigger than issueDate')\n }\n\n // 영세업자인데 아이템 세금이 있으면 에러\n if (taxInvoice.invoiceType === InvoiceType.ZERO_RATED_TAX_INVOICE && item.taxPrice > 0) {\n throw new Error('tax invoice send exception: item tax price is exist')\n }\n\n newTaxInvoiceItems.push({\n tii_seqnumeric: item.sequence,\n tii_purchaseexpirydatetime: item.supplyDate.replace(/-/g, ''),\n tii_nametext: item.itemName,\n tii_informationtext: item.specification,\n tii_chargeableunitquantity: item.quantity,\n tii_unitprice_unitamount: item.unitPrice,\n tii_invoiceamount: item.supplyPrice,\n tii_totaltax_calcamount: item.taxPrice,\n tii_descriptiontext: item.remark\n })\n }\n\n return {\n aid: aid,\n inv_seq: today.replace(/-/g, '') + customer_no,\n exd_refdoc_id: null,\n tid_issuedatetime: taxInvoice.issueDate.replace(/-/g, ''),\n tid_typecode: taxInvoice.invoiceType,\n tid_purposecode: taxInvoice.purpose,\n tid_amendcode: taxInvoice.revisedReason,\n tid_originalissueid: null,\n tid_desc0: taxInvoice.remark0,\n tid_desc1: null,\n tid_desc2: null,\n tit_alice_specorg_biztypecode: taxInvoice.supplierBusinessRegistrationCategory,\n tit_alice_id: taxInvoice.supplierBusinessRegistrationNumber,\n tit_alice_specorg_taxregid: taxInvoice.supplierBranchIdentification,\n tit_alice_name: taxInvoice.supplierBusinessName,\n tit_alice_specperson_name: taxInvoice.supplierRepresentativeName,\n tit_alice_specaddr_lineone: taxInvoice.supplierAddress,\n tit_alice_typecode: taxInvoice.supplierBusinessType,\n tit_alice_classcode: taxInvoice.supplierIndustryType,\n tit_alice_defcont_deptname: taxInvoice.supplierDepartment,\n tit_alice_defcont_personname: taxInvoice.supplierContactName,\n tit_alice_defcont_telcomm: taxInvoice.supplierContactPhone,\n tit_alice_defcont_uricomm: taxInvoice.supplierContactEmail,\n tit_alice_defcont_cellphone: taxInvoice.supplierContactCellPhone,\n tit_bob_specorg_biztypecode: taxInvoice.buyerBusinessRegistrationCategory,\n tit_bob_id: taxInvoice.buyerBusinessRegistrationNumber,\n tit_bob_specorg_taxregid: taxInvoice.buyerBranchIdentification,\n tit_bob_name: taxInvoice.buyerBusinessName,\n tit_bob_specperson_name: taxInvoice.buyerRepresentativeName,\n tit_bob_specaddr_lineone: taxInvoice.buyerAddress,\n tit_bob_typecode: taxInvoice.buyerBusinessType,\n tit_bob_classcode: taxInvoice.buyerIndustryType,\n tit_bob_1stdefcont_deptname: taxInvoice.buyer1stDepartment,\n tit_bob_1stdefcont_personname: taxInvoice.buyer1stContactName,\n tit_bob_1stdefcont_telcomm: taxInvoice.buyer1stContactPhone,\n tit_bob_1stdefcont_uricomm: taxInvoice.buyer1stContactEmail,\n tit_bob_1stdefcont_cellphone: taxInvoice.buyer1stContactCellPhone,\n tit_bob_2nddefcont_deptname: taxInvoice.buyer2ndDepartment,\n tit_bob_2nddefcont_personname: taxInvoice.buyer2ndContactName,\n tit_bob_2nddefcont_telcomm: taxInvoice.buyer2ndContactPhone,\n tit_bob_2nddefcont_uricomm: taxInvoice.buyer2ndContactEmail,\n tit_bob_2nddefcont_cellphone: taxInvoice.buyer2ndContactCellPhone,\n tit_broker_specorg_biztypecode: taxInvoice.agentBusinessRegistrationCategory,\n tit_broker_id: taxInvoice.agentBusinessRegistrationNumber,\n tit_broker_specorg_taxregid: taxInvoice.agentBranchIdentification,\n tit_broker_name: taxInvoice.agentBusinessName,\n tit_broker_specperson_name: taxInvoice.agentRepresentativeName,\n tit_broker_specaddr_lineone: taxInvoice.agentAddress,\n tit_broker_typecode: taxInvoice.agentBusinessType,\n tit_broker_classcode: taxInvoice.agentIndustryType,\n tit_broker_defcont_deptname: taxInvoice.agentDepartment,\n tit_broker_defcont_personname: taxInvoice.agentContactName,\n tit_broker_defcont_telcomm: taxInvoice.agentContactPhone,\n tit_broker_defcont_uricomm: taxInvoice.agentContactEmail,\n tit_broker_defcont_cellphone: taxInvoice.agentContactCellPhone,\n tit_specpay_paidamount10: taxInvoice.paymentAmountCash,\n tit_specpay_paidamount20: taxInvoice.paymentAmountCheck,\n tit_specpay_paidamount30: taxInvoice.paymentAmountPromissoryNote,\n tit_specpay_paidamount40: taxInvoice.paymentAmountAccountsReceivable,\n tit_specsum_chargeamount: taxInvoice.supplyAmount,\n tit_specsum_taxamount: taxInvoice.taxAmount,\n tit_specsum_grandamount: taxInvoice.totalAmount,\n inv_sign: '',\n biz_tocharlesconfirmstatus: null,\n tAliceItemList: newTaxInvoiceItems\n }\n }\n}\n"]}
|