2021-04-22 18:28:05 +09:00
|
|
|
|
using NP.Base;
|
2021-04-23 18:18:52 +09:00
|
|
|
|
using NP.Dao;
|
|
|
|
|
|
using NP.Model;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
using Popbill;
|
|
|
|
|
|
using Popbill.Taxinvoice;
|
|
|
|
|
|
using System;
|
2021-04-23 18:18:52 +09:00
|
|
|
|
using System.Collections;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Web.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NP.Base.Popbill
|
|
|
|
|
|
{
|
|
|
|
|
|
public class PopbillService
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 세금계산서 문서번호{mgtKey} 생성
|
|
|
|
|
|
/// </summary>
|
2021-04-23 18:18:52 +09:00
|
|
|
|
/// <param name="Dao">CommonDao</param>
|
|
|
|
|
|
/// <param name="taxdate">발행일</param>
|
|
|
|
|
|
/// <param name="mgtKeyType">세금계산서 유형 : SELL = 매출, BUY = 매입, TRUSTEE = 위수탁</param>
|
|
|
|
|
|
/// <returns>mgtKey</returns>
|
|
|
|
|
|
public static Result<String> MakeMgtKey(CommonDao Dao, DateTime taxdate, MgtKeyType mgtKeyType = MgtKeyType.SELL)
|
|
|
|
|
|
{
|
|
|
|
|
|
Result<String> result = new Result<string>();
|
|
|
|
|
|
|
2021-04-22 18:28:05 +09:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2021-04-23 18:18:52 +09:00
|
|
|
|
string mgtkey = string.Empty;
|
|
|
|
|
|
int no = 1;
|
|
|
|
|
|
|
|
|
|
|
|
var payTax = Dao.Get<PayTax>("cr.paytax.formgtkey", new Hashtable() { { "taxdate", taxdate } }).FirstOrDefault();
|
|
|
|
|
|
if (payTax == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
payTax = new PayTax() { };
|
|
|
|
|
|
}
|
|
|
|
|
|
if (payTax.taxdate == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
payTax.taxdate = taxdate;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(payTax.mgtkey))
|
|
|
|
|
|
{
|
|
|
|
|
|
var strNo = payTax.mgtkey.Substring(payTax.mgtkey.IndexOf("L") + 1);
|
|
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(strNo, out no))
|
|
|
|
|
|
{
|
|
|
|
|
|
++no;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mgtkey = $"{taxdate:yyyy-MM-dd}-L{no:D5}";
|
|
|
|
|
|
|
|
|
|
|
|
bool isUse = true;
|
|
|
|
|
|
int checkLimit = 10;
|
|
|
|
|
|
while (isUse && checkLimit > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
isUse = PopbillConfig.taxinvoiceService.CheckMgtKeyInUse(PopbillConfig.CorpNum, mgtKeyType, mgtkey);
|
|
|
|
|
|
if (isUse)
|
|
|
|
|
|
{
|
|
|
|
|
|
++no;
|
|
|
|
|
|
mgtkey = $"{taxdate:yyyy-MM-dd}-L{no:D5}";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
--checkLimit;
|
|
|
|
|
|
}
|
|
|
|
|
|
result.Data = mgtkey;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
}
|
|
|
|
|
|
catch (PopbillException ex)
|
|
|
|
|
|
{
|
2021-04-23 18:18:52 +09:00
|
|
|
|
result.Code = ex.code.ToString();
|
|
|
|
|
|
result.Message = ex.Message;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
Logger.TryError(ex.Message, ex);
|
|
|
|
|
|
}
|
2021-04-23 18:18:52 +09:00
|
|
|
|
return result;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 세금계산서 상세정보
|
2021-04-23 18:18:52 +09:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="mgtkey">파트너가 할당한 문서번호</param>
|
|
|
|
|
|
/// <param name="mgtKeyType">세금계산서 유형 : SELL = 매출, BUY = 매입, TRUSTEE = 위수탁</param>
|
|
|
|
|
|
/// <returns>Taxinvoice</returns>
|
|
|
|
|
|
public static Result<Taxinvoice> GetTaxinvoice(string mgtkey, MgtKeyType mgtKeyType = MgtKeyType.SELL)
|
|
|
|
|
|
{
|
|
|
|
|
|
Result<Taxinvoice> result = new Result<Taxinvoice>();
|
2021-04-22 18:28:05 +09:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2021-04-23 18:18:52 +09:00
|
|
|
|
result.Data = PopbillConfig.taxinvoiceService.GetDetailInfo(PopbillConfig.CorpNum, mgtKeyType, mgtkey);
|
2021-04-22 18:28:05 +09:00
|
|
|
|
}
|
|
|
|
|
|
catch (PopbillException ex)
|
|
|
|
|
|
{
|
2021-04-23 18:18:52 +09:00
|
|
|
|
result.Code = ex.code.ToString();
|
|
|
|
|
|
result.Message = ex.Message;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
Logger.TryError(ex.Message, ex);
|
|
|
|
|
|
}
|
2021-04-23 18:18:52 +09:00
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
if (result.Data == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
result.Data = new Taxinvoice() { invoicerMgtKey = mgtkey };
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 세금계산서 공급자정보
|
|
|
|
|
|
/// </summary>
|
2021-04-23 18:18:52 +09:00
|
|
|
|
/// <param name="mgtkey">파트너가 할당한 문서번호</param>
|
|
|
|
|
|
/// <returns>Taxinvoice</returns>
|
|
|
|
|
|
public static Result<Taxinvoice> GetTaxinvoiceR(string mgtkey)
|
|
|
|
|
|
{
|
|
|
|
|
|
Result<Taxinvoice> result = new Result<Taxinvoice>();
|
2021-04-22 18:28:05 +09:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
CorpInfo corpInfo = PopbillConfig.taxinvoiceService.GetCorpInfo(PopbillConfig.CorpNum, PopbillConfig.UserID);
|
|
|
|
|
|
Contact contact = PopbillConfig.taxinvoiceService.ListContact(PopbillConfig.CorpNum, PopbillConfig.UserID).Where(w => w.mgrYN == true).FirstOrDefault();
|
2021-04-23 18:18:52 +09:00
|
|
|
|
result.Data = new Taxinvoice
|
2021-04-22 18:28:05 +09:00
|
|
|
|
{
|
|
|
|
|
|
invoicerAddr = corpInfo?.addr,
|
|
|
|
|
|
invoicerCEOName = corpInfo?.ceoname,
|
|
|
|
|
|
invoicerCorpName = corpInfo?.corpName,
|
2021-04-23 18:18:52 +09:00
|
|
|
|
invoicerMgtKey = mgtkey,
|
2021-04-22 18:28:05 +09:00
|
|
|
|
invoicerCorpNum = PopbillConfig.CorpNum,
|
|
|
|
|
|
invoicerBizClass = corpInfo?.bizClass,
|
|
|
|
|
|
invoicerBizType = corpInfo?.bizType,
|
|
|
|
|
|
invoicerContactName = contact?.personName,
|
|
|
|
|
|
invoicerEmail = contact?.email,
|
|
|
|
|
|
invoicerHP = contact?.hp,
|
|
|
|
|
|
invoicerTEL = contact?.tel
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (PopbillException ex)
|
|
|
|
|
|
{
|
2021-04-23 18:18:52 +09:00
|
|
|
|
result.Code = ex.code.ToString();
|
|
|
|
|
|
result.Message = ex.Message;
|
|
|
|
|
|
Logger.TryError(ex.Message, ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 세금계산서 임시저장
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="taxinvoice">Taxinvoice</param>
|
|
|
|
|
|
/// <returns>IssueResponse</returns>
|
|
|
|
|
|
public static Result<Response> Register(Taxinvoice taxinvoice)
|
|
|
|
|
|
{
|
|
|
|
|
|
Result<Response> result = new Result<Response>();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
result.Data = PopbillConfig.taxinvoiceService.Register(PopbillConfig.CorpNum, taxinvoice);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (PopbillException ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
result.Code = ex.code.ToString();
|
|
|
|
|
|
result.Message = ex.Message;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
Logger.TryError(ex.Message, ex);
|
|
|
|
|
|
}
|
2021-04-23 18:18:52 +09:00
|
|
|
|
return result;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 세금계산서 즉시 발행
|
|
|
|
|
|
/// </summary>
|
2021-04-23 18:18:52 +09:00
|
|
|
|
/// <param name="taxinvoice">Taxinvoice</param>
|
|
|
|
|
|
/// <param name="forceIssue">지연발행 가능여부</param>
|
|
|
|
|
|
/// <param name="memo">메모</param>
|
|
|
|
|
|
/// <returns>IssueResponse</returns>
|
|
|
|
|
|
public static Result<IssueResponse> RegistIssue(Taxinvoice taxinvoice, bool forceIssue = false, string memo = "")
|
2021-04-22 18:28:05 +09:00
|
|
|
|
{
|
2021-04-23 18:18:52 +09:00
|
|
|
|
Result<IssueResponse> result = new Result<IssueResponse>();;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2021-04-23 18:18:52 +09:00
|
|
|
|
result.Data = PopbillConfig.taxinvoiceService.RegistIssue(PopbillConfig.CorpNum, taxinvoice, forceIssue, memo);
|
2021-04-22 18:28:05 +09:00
|
|
|
|
}
|
|
|
|
|
|
catch (PopbillException ex)
|
|
|
|
|
|
{
|
2021-04-23 18:18:52 +09:00
|
|
|
|
result.Code = ex.code.ToString();
|
|
|
|
|
|
result.Message = ex.Message;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
Logger.TryError(ex.Message, ex);
|
|
|
|
|
|
}
|
2021-04-23 18:18:52 +09:00
|
|
|
|
return result;
|
2021-04-22 18:28:05 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-04-23 18:18:52 +09:00
|
|
|
|
|
|
|
|
|
|
public class Result<T>
|
|
|
|
|
|
{
|
|
|
|
|
|
public String Code = null;
|
|
|
|
|
|
public String Message = null;
|
|
|
|
|
|
public T Data;
|
|
|
|
|
|
}
|
2021-04-22 18:28:05 +09:00
|
|
|
|
}
|