using NP.Base;
using Popbill;
using Popbill.Taxinvoice;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Configuration;
namespace NP.Base.Popbill
{
public class PopbillService
{
///
/// 세금계산서 문서번호{mgtKey} 생성
///
///
public static string MakeMgtKey()
{
string mgtKey = string.Empty;
try
{
string date = DateTime.Now.ToString("yyyy-MM-dd");
string no = 1.ToString("D5");//수정->발행문서 검색 후 순번 + 1 하는 거로 변경
mgtKey = $"{date}-L{no}";
}
catch (PopbillException ex)
{
Logger.TryError(ex.Message, ex);
}
return mgtKey;
}
///
/// 세금계산서 상세정보
///
///
///
public static Taxinvoice GetTaxinvoice(string mgtKey)
{
Taxinvoice taxinvoice = null;
try
{
taxinvoice = PopbillConfig.taxinvoiceService.GetDetailInfo(PopbillConfig.CorpNum, MgtKeyType.SELL, mgtKey);
}
catch (PopbillException ex)
{
Logger.TryError(ex.Message, ex);
}
return taxinvoice;
}
///
/// 세금계산서 공급자정보
///
///
public static Taxinvoice GetTaxinvoiceR()
{
Taxinvoice Taxinvoice = null;
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();
Taxinvoice = new Taxinvoice
{
invoicerAddr = corpInfo?.addr,
invoicerCEOName = corpInfo?.ceoname,
invoicerCorpName = corpInfo?.corpName,
invoicerMgtKey = MakeMgtKey(),
invoicerCorpNum = PopbillConfig.CorpNum,
invoicerBizClass = corpInfo?.bizClass,
invoicerBizType = corpInfo?.bizType,
invoicerContactName = contact?.personName,
invoicerEmail = contact?.email,
invoicerHP = contact?.hp,
invoicerTEL = contact?.tel
};
}
catch (PopbillException ex)
{
Logger.TryError(ex.Message, ex);
}
return Taxinvoice;
}
///
/// 세금계산서 즉시 발행
///
///
///
///
///
public static IssueResponse RegistIssue(Taxinvoice taxinvoice, bool forceIssue, string memo)
{
IssueResponse IssueResponse = null;
try
{
PopbillConfig.taxinvoiceService.RegistIssue(PopbillConfig.CorpNum, taxinvoice, forceIssue, memo);
}
catch (PopbillException ex)
{
Logger.TryError(ex.Message, ex);
}
return IssueResponse;
}
}
}