@things-factory/tax-invoice 8.0.75 → 8.0.79

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/tax-invoice",
3
- "version": "8.0.75",
3
+ "version": "8.0.79",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -34,5 +34,5 @@
34
34
  "@things-factory/export-ui-excel": "^8.0.64",
35
35
  "@things-factory/shell": "^8.0.64"
36
36
  },
37
- "gitHead": "38a8615a18e19430b260b10dc2b1ca134fc46165"
37
+ "gitHead": "d3e06a1f18781c320e9de3438f67db525e4e6a66"
38
38
  }
@@ -14,6 +14,7 @@ import {
14
14
  getTaxInvoiceByUniposApi
15
15
  } from '../unipost-api/tax-invoice-inquiry'
16
16
  import { parseTaxInvoiceByUnipostFormat } from './tax-invoice-util'
17
+ import { logger } from '@things-factory/env'
17
18
 
18
19
  @Resolver(TaxInvoice)
19
20
  export class TaxInvoiceMutation {
@@ -101,18 +102,24 @@ export class TaxInvoiceMutation {
101
102
  @Directive('@transaction')
102
103
  @Mutation(returns => Boolean, { description: 'create tax invoice data by API' })
103
104
  async fetchTaxInvoiceByApi(@Ctx() context: ResolverContext): Promise<boolean> {
105
+ logger.info('fetchTaxInvoiceByApi')
104
106
  const { domain, user, tx } = context.state
105
107
  const taxInvoiceApiRepo = tx.getRepository(TaxInvoiceApi)
106
108
  const taxInvoiceRepo = tx.getRepository(TaxInvoice)
107
109
  const insertedData: ConfirmData[] = [] // API 호출 후 결과 회신용
108
110
 
111
+ // TODO 여기 기본값으로 가져와야하는거 아님?
109
112
  const apiInfo = (await taxInvoiceApiRepo.find())[0]
110
113
  const businessRegistrationNumber = apiInfo.businessRegistrationNumber
111
114
  const { aid = '', bearer = '' } = apiInfo?.attributes
112
115
 
116
+ logger.info('apiInfo : ', apiInfo)
117
+
113
118
  // API 호출하여 세금계산서 데이터 가져옴
114
119
  const { issueNoList, taxList } = await getTaxInvoiceByUniposApi(businessRegistrationNumber, aid, bearer)
115
120
 
121
+ logger.info('issueNoList, taxList : ', issueNoList, taxList)
122
+
116
123
  // 이미 있는 데이터 아이디 검색
117
124
  const existingTaxInvoice = await taxInvoiceRepo.find({
118
125
  select: ['issueNo'],
@@ -120,6 +127,8 @@ export class TaxInvoiceMutation {
120
127
  })
121
128
  const existingIds = existingTaxInvoice.map(taxInvoice => taxInvoice.issueNo)
122
129
 
130
+ logger.info('existingTaxInvoice : ', existingTaxInvoice)
131
+
123
132
  // 매입, 매출 for문
124
133
  for (let tax of taxList) {
125
134
  // 있는지 없는지 확인 (이미 있는 세금계산서는 패스)
@@ -142,7 +151,10 @@ export class TaxInvoiceMutation {
142
151
  }
143
152
 
144
153
  // 유니 포스트에 조회 후 결과 회신 API 호출
145
- callTaxInvoiceConfirm(businessRegistrationNumber, aid, bearer, insertedData)
154
+ const confirmResult = await callTaxInvoiceConfirm(businessRegistrationNumber, aid, bearer, insertedData)
155
+
156
+ logger.info('insertedData : ', insertedData)
157
+ logger.info('confirmResult : ', confirmResult)
146
158
 
147
159
  return true
148
160
  }
@@ -99,10 +99,14 @@ export class TaxInvoiceQuery {
99
99
 
100
100
  @FieldResolver(type => Boolean)
101
101
  async isMatched(@Root() taxInvoice: TaxInvoice): Promise<boolean> {
102
- const binding = await getRepository('tax_invoice_binding').findOne({
103
- where: { taxInvoice: { id: taxInvoice.id } }
104
- })
105
-
106
- return !!binding
102
+ try {
103
+ const binding = await getRepository('tax_invoice_binding').findOne({
104
+ where: { taxInvoice: { id: taxInvoice.id } }
105
+ })
106
+
107
+ return !!binding
108
+ } catch (e) {
109
+ return false
110
+ }
107
111
  }
108
112
  }
@@ -1,6 +1,7 @@
1
1
  import { Category } from '../tax-invoice/tax-invoice'
2
2
  import { config } from '@things-factory/env'
3
3
  // import getTestTaxInvoiceData from './test-data'
4
+ import { logger } from '@things-factory/env'
4
5
 
5
6
  const UNITAX_CONFIG = config.get('unitax', {})
6
7
  // 세금계산서 조회 API
@@ -34,11 +35,15 @@ export async function getTaxInvoiceByUniposApi(businessRegistrationNumber: strin
34
35
  for (const taxType of taxTypeArr) {
35
36
  const response = await _callTaxInvoiceInquiry(businessRegistrationNumber, aid, bearer, taxType)
36
37
 
38
+ logger.info('response : ', response)
39
+
37
40
  // 성공 일시 세금 계산서 데이터 배열에 추가
38
41
  if (response.status === 200) {
39
42
  const category = taxType === 'AR' ? Category.EXPORT : Category.IMPORT // 유니포스트의 타입 => 우리 솔루션 형태로 변환
40
43
  const taxData = await response.json()
41
44
 
45
+ logger.info('taxData : ', taxData)
46
+
42
47
  if (taxData.success === true) {
43
48
  for (let tax of taxData.tAliceEntry) {
44
49
  issueNoList.push(tax.exd_id)
@@ -64,7 +69,14 @@ export async function getTaxInvoiceByUniposApi(businessRegistrationNumber: strin
64
69
  }
65
70
  }
66
71
 
67
- async function _callTaxInvoiceInquiry(businessRegistrationNumber: string, aid: string, bearer: string, taxType: UnipostTaxType) {
72
+ async function _callTaxInvoiceInquiry(
73
+ businessRegistrationNumber: string,
74
+ aid: string,
75
+ bearer: string,
76
+ taxType: UnipostTaxType
77
+ ) {
78
+ businessRegistrationNumber = businessRegistrationNumber.replace(/-/g, '')
79
+
68
80
  const response = await fetch(INQUIRY_URL, {
69
81
  method: 'POST',
70
82
  headers: {
@@ -83,7 +95,14 @@ async function _callTaxInvoiceInquiry(businessRegistrationNumber: string, aid: s
83
95
 
84
96
  return response
85
97
  }
86
- export async function callTaxInvoiceConfirm(businessRegistrationNumber: string, aid: string, bearer: string, confirmData: ConfirmData[]) {
98
+ export async function callTaxInvoiceConfirm(
99
+ businessRegistrationNumber: string,
100
+ aid: string,
101
+ bearer: string,
102
+ confirmData: ConfirmData[]
103
+ ) {
104
+ businessRegistrationNumber = businessRegistrationNumber.replace(/-/g, '')
105
+
87
106
  const response = await fetch(CONFIRM_URL, {
88
107
  method: 'POST',
89
108
  headers: {
@@ -4,7 +4,12 @@ const UNITAX_CONFIG = config.get('unitax', {})
4
4
  // 세금계산서 발행 API
5
5
  const SEND_URL = UNITAX_CONFIG.SEND_URL || ''
6
6
 
7
- export async function sendTaxInvoiceByUniposApi(businessRegistrationNumber: string, aid: string, bearer: string, taxInvoiceSendList) {
7
+ export async function sendTaxInvoiceByUniposApi(
8
+ businessRegistrationNumber: string,
9
+ aid: string,
10
+ bearer: string,
11
+ taxInvoiceSendList
12
+ ) {
8
13
  if (!businessRegistrationNumber || !aid || !bearer || !taxInvoiceSendList) {
9
14
  throw new Error('no parameter in unipos api')
10
15
  }
@@ -14,7 +19,14 @@ export async function sendTaxInvoiceByUniposApi(businessRegistrationNumber: stri
14
19
  return response?.status === 200 ? await response.json() : false
15
20
  }
16
21
 
17
- async function _callTaxInvoiceSend(businessRegistrationNumber: string, aid: string, bearer: string, taxInvoiceSendList) {
22
+ async function _callTaxInvoiceSend(
23
+ businessRegistrationNumber: string,
24
+ aid: string,
25
+ bearer: string,
26
+ taxInvoiceSendList
27
+ ) {
28
+ businessRegistrationNumber = businessRegistrationNumber.replace(/-/g, '')
29
+
18
30
  try {
19
31
  return await fetch(SEND_URL, {
20
32
  method: 'POST',