diff --git a/BO/BO.csproj b/BO/BO.csproj index 6f69be3..7a1f6bc 100644 --- a/BO/BO.csproj +++ b/BO/BO.csproj @@ -62,6 +62,9 @@ ..\..\LMS_TSTI\Source\Core\NPTech.LMS.Core\bin\Release\IBatisNet.Common.Logging.Log4Net.dll + + ..\References\Popbill\Linkhub.dll + False ..\References\log4net.dll @@ -77,6 +80,9 @@ False ..\References\NPDao.dll + + ..\References\Popbill\Popbill.dll + ..\packages\Spring.Aop.2.0.1\lib\net45\Spring.Aop.dll diff --git a/BO/Controllers/croomController.cs b/BO/Controllers/croomController.cs index 81fa057..f4fecc0 100644 --- a/BO/Controllers/croomController.cs +++ b/BO/Controllers/croomController.cs @@ -5,6 +5,8 @@ using System.Net.Http; using System.Web.Mvc; using NP.Model; using NP.Base.Popbill; +using Popbill.Taxinvoice; +using System.Collections; namespace NP.BO.Controllers { @@ -793,14 +795,16 @@ namespace NP.BO.Controllers vm.PayTaxItem = Dao.Get("cr.paytaxitem2", new System.Collections.Hashtable() { { "taxno", vm.longval } }); #region 세금계산서 Popbill 연동 - var mgtKey = vm.PayTaxes.First()?.mgtKey; - if (!string.IsNullOrEmpty(mgtKey)) + var mgtkey = vm.PayTaxes.First()?.mgtkey; + if (!string.IsNullOrEmpty(mgtkey)) { - ViewBag.Taxinvoice = PopbillService.GetTaxinvoice(mgtKey); + ViewBag.Taxinvoice = PopbillService.GetTaxinvoice(mgtkey).Data; } else { - ViewBag.Taxinvoice = PopbillService.GetTaxinvoiceR(); + var taxdate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); + mgtkey = PopbillService.MakeMgtKey(Dao, taxdate, MgtKeyType.SELL).Data; + ViewBag.Taxinvoice = PopbillService.GetTaxinvoiceR(mgtkey).Data; } #endregion diff --git a/BO/Views/croom/tax.cshtml b/BO/Views/croom/tax.cshtml index d46b290..15cbb7b 100644 --- a/BO/Views/croom/tax.cshtml +++ b/BO/Views/croom/tax.cshtml @@ -5,7 +5,7 @@
diff --git a/BO/Views/croom/taxdetail.cshtml b/BO/Views/croom/taxdetail.cshtml index 77d9917..ef3c86e 100644 --- a/BO/Views/croom/taxdetail.cshtml +++ b/BO/Views/croom/taxdetail.cshtml @@ -1,6 +1,7 @@ @model NP.Model.VMCRoom @{ var t = Model.PayTaxes.First(); + var taxinvoice = ViewBag.Taxinvoice; }
    @@ -27,17 +28,17 @@ @foreach (var d in Model.PayTaxes) { - - @d.payno - @Html.Raw(string.Format("{1} {2}", d.isjoin, d.isjoin == 1 ? "정" : "비", d.asname)) - @string.Format("{0}({1})", d.username, d.userid) - @d.itemname @(d.ccount > 1 ? string.Format("외 {0}건", d.ccount - 1) : "") - @d.pcnt - @d.taxamt.ToString("#,0") - @d.cdtymd - @(d.taxdate == null ? "" : d.taxdate.Value.ToString("yyyy-MM-dd")) - @(d.iscancel ==1 ? "발행취소" :d.taxdate == null ? "미발행" : "발행완료") - + + @d.payno + @Html.Raw(string.Format("{1} {2}", d.isjoin, d.isjoin == 1 ? "정" : "비", d.asname)) + @string.Format("{0}({1})", d.username, d.userid) + @d.itemname @(d.ccount > 1 ? string.Format("외 {0}건", d.ccount - 1) : "") + @d.pcnt + @d.taxamt.ToString("#,0") + @d.cdtymd + @(d.taxdate == null ? "" : d.taxdate.Value.ToString("yyyy-MM-dd")) + @(d.iscancel ==1 ? "발행취소" :d.taxdate == null ? "미발행" : "발행완료") + } @@ -97,7 +98,8 @@ 발행요청금액 @(t.taxamt.ToString("#,0"))원 - + +
    @@ -107,34 +109,34 @@ 회사명 - + 대표자 - + 사업자등록번호 - + 업태 - + 종목 - + 사업장주소 - + 담당자 - + 연락처 - + 이메일주소 - + 문서번호 - - + +
    @@ -174,7 +176,7 @@ - + @@ -206,8 +208,27 @@ +
    저장 + @if (string.IsNullOrEmpty(t.mgtkey)) + { + 임시저장 및 미리보기 + 계산서 즉시발행 + } + else + { + if (string.IsNullOrEmpty(taxinvoice.ntsconfirmNum)) + { + 임시저장 및 미리보기 + 계산서 즉시발행 + } + else + { + 계산서조회 + } + } + 발행취소 목록
    @Html.Partial("./Partial/dform", Model) @@ -275,5 +296,19 @@ msgadmin(); } } + + function register() { + + } + function view() { + + } + function registIssue() { + + } + function cancelIssue() { + + } } + diff --git a/Base/Controller/ACommonCRoom.cs b/Base/Controller/ACommonCRoom.cs index 978b73c..29719fc 100644 --- a/Base/Controller/ACommonCRoom.cs +++ b/Base/Controller/ACommonCRoom.cs @@ -773,6 +773,66 @@ namespace NP.Base.Controllers } return JsonOK(Dao.Save("cr.paytax.save", d)); } + /// + /// 팝빌 임시저장 및 미리보기(팝빌 임시저장 및 paytax.mgtkey 업데이트 후 세금계산서 인쇄 url 리턴) + /// + /// + /// + [HttpPost] + public JsonResult PayTaxRegister(PayTax d) + { + d.uno = SUserInfo.UserNo; d.uip = GetUserIP(); + if (d.iscancel != 1 && Dao.Get("cr.paytaxes", new Hashtable() { { "payno", d.payno }, { "cno", d.cno }, { "iscancel", 0 }, { "nottaxno", d.taxno } }).Count() > 0) + { + return JsonBack(new JsonRtn() { code = -1 }); + } + return JsonOK(Dao.Save("cr.paytax.save", d)); + } + /// + /// 계산서 즉시발행(팝빌 발행 및 paytax.taxdate ,paytax.mgtkey 업데이트) + /// + /// + /// + [HttpPost] + public JsonResult PayTaxRegistIssue(PayTax d) + { + d.uno = SUserInfo.UserNo; d.uip = GetUserIP(); + if (d.iscancel != 1 && Dao.Get("cr.paytaxes", new Hashtable() { { "payno", d.payno }, { "cno", d.cno }, { "iscancel", 0 }, { "nottaxno", d.taxno } }).Count() > 0) + { + return JsonBack(new JsonRtn() { code = -1 }); + } + return JsonOK(Dao.Save("cr.paytax.save", d)); + } + /// + /// 발행취소(발행전: paytax.iscancel 상태값 변경, 발행완료: 팝빌 발행취소 및 paytax.iscancel 상태값 변경) + /// + /// + /// + [HttpPost] + public JsonResult PayTaxCancelIssue(PayTax d) + { + d.uno = SUserInfo.UserNo; d.uip = GetUserIP(); + if (d.iscancel != 1 && Dao.Get("cr.paytaxes", new Hashtable() { { "payno", d.payno }, { "cno", d.cno }, { "iscancel", 0 }, { "nottaxno", d.taxno } }).Count() > 0) + { + return JsonBack(new JsonRtn() { code = -1 }); + } + return JsonOK(Dao.Save("cr.paytax.save", d)); + } + /// + /// 계산서조회(팝빌 세금계산서 인쇄 url 리턴) + /// + /// + /// + [HttpPost] + public JsonResult PayTaxView(PayTax d) + { + d.uno = SUserInfo.UserNo; d.uip = GetUserIP(); + if (d.iscancel != 1 && Dao.Get("cr.paytaxes", new Hashtable() { { "payno", d.payno }, { "cno", d.cno }, { "iscancel", 0 }, { "nottaxno", d.taxno } }).Count() > 0) + { + return JsonBack(new JsonRtn() { code = -1 }); + } + return JsonOK(Dao.Save("cr.paytax.save", d)); + } [HttpPost] public JsonResult SmartTaxView(String csid) { diff --git a/Base/Popbill/PopbillService.cs b/Base/Popbill/PopbillService.cs index 324189e..0029e26 100644 --- a/Base/Popbill/PopbillService.cs +++ b/Base/Popbill/PopbillService.cs @@ -1,7 +1,10 @@ using NP.Base; +using NP.Dao; +using NP.Model; using Popbill; using Popbill.Taxinvoice; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web.Configuration; @@ -13,59 +16,112 @@ namespace NP.Base.Popbill /// /// 세금계산서 문서번호{mgtKey} 생성 /// - /// - public static string MakeMgtKey() - { - string mgtKey = string.Empty; + /// CommonDao + /// 발행일 + /// 세금계산서 유형 : SELL = 매출, BUY = 매입, TRUSTEE = 위수탁 + /// mgtKey + public static Result MakeMgtKey(CommonDao Dao, DateTime taxdate, MgtKeyType mgtKeyType = MgtKeyType.SELL) + { + Result result = new Result(); + try { - string date = DateTime.Now.ToString("yyyy-MM-dd"); - string no = 1.ToString("D5");//수정->발행문서 검색 후 순번 + 1 하는 거로 변경 - mgtKey = $"{date}-L{no}"; + string mgtkey = string.Empty; + int no = 1; + + var payTax = Dao.Get("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; } catch (PopbillException ex) { + result.Code = ex.code.ToString(); + result.Message = ex.Message; Logger.TryError(ex.Message, ex); } - return mgtKey; + return result; } /// /// 세금계산서 상세정보 - /// - /// - /// - public static Taxinvoice GetTaxinvoice(string mgtKey) - { - Taxinvoice taxinvoice = null; + /// + /// 파트너가 할당한 문서번호 + /// 세금계산서 유형 : SELL = 매출, BUY = 매입, TRUSTEE = 위수탁 + /// Taxinvoice + public static Result GetTaxinvoice(string mgtkey, MgtKeyType mgtKeyType = MgtKeyType.SELL) + { + Result result = new Result(); try { - taxinvoice = PopbillConfig.taxinvoiceService.GetDetailInfo(PopbillConfig.CorpNum, MgtKeyType.SELL, mgtKey); + result.Data = PopbillConfig.taxinvoiceService.GetDetailInfo(PopbillConfig.CorpNum, mgtKeyType, mgtkey); } catch (PopbillException ex) { + result.Code = ex.code.ToString(); + result.Message = ex.Message; Logger.TryError(ex.Message, ex); } - return taxinvoice; + finally + { + if (result.Data == null) + { + result.Data = new Taxinvoice() { invoicerMgtKey = mgtkey }; + } + } + return result; } /// /// 세금계산서 공급자정보 /// - /// - public static Taxinvoice GetTaxinvoiceR() - { - Taxinvoice Taxinvoice = null; + /// 파트너가 할당한 문서번호 + /// Taxinvoice + public static Result GetTaxinvoiceR(string mgtkey) + { + Result result = new Result(); 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 + result.Data = new Taxinvoice { invoicerAddr = corpInfo?.addr, invoicerCEOName = corpInfo?.ceoname, invoicerCorpName = corpInfo?.corpName, - invoicerMgtKey = MakeMgtKey(), + invoicerMgtKey = mgtkey, invoicerCorpNum = PopbillConfig.CorpNum, invoicerBizClass = corpInfo?.bizClass, invoicerBizType = corpInfo?.bizType, @@ -77,30 +133,62 @@ namespace NP.Base.Popbill } catch (PopbillException ex) { + result.Code = ex.code.ToString(); + result.Message = ex.Message; Logger.TryError(ex.Message, ex); } - return Taxinvoice; + return result; + } + + /// + /// 세금계산서 임시저장 + /// + /// Taxinvoice + /// IssueResponse + public static Result Register(Taxinvoice taxinvoice) + { + Result result = new Result(); + try + { + result.Data = PopbillConfig.taxinvoiceService.Register(PopbillConfig.CorpNum, taxinvoice); + } + catch (PopbillException ex) + { + result.Code = ex.code.ToString(); + result.Message = ex.Message; + Logger.TryError(ex.Message, ex); + } + return result; } /// /// 세금계산서 즉시 발행 /// - /// - /// - /// - /// - public static IssueResponse RegistIssue(Taxinvoice taxinvoice, bool forceIssue, string memo) + /// Taxinvoice + /// 지연발행 가능여부 + /// 메모 + /// IssueResponse + public static Result RegistIssue(Taxinvoice taxinvoice, bool forceIssue = false, string memo = "") { - IssueResponse IssueResponse = null; + Result result = new Result();; try { - PopbillConfig.taxinvoiceService.RegistIssue(PopbillConfig.CorpNum, taxinvoice, forceIssue, memo); + result.Data = PopbillConfig.taxinvoiceService.RegistIssue(PopbillConfig.CorpNum, taxinvoice, forceIssue, memo); } catch (PopbillException ex) { + result.Code = ex.code.ToString(); + result.Message = ex.Message; Logger.TryError(ex.Message, ex); } - return IssueResponse; + return result; } } + + public class Result + { + public String Code = null; + public String Message = null; + public T Data; + } } \ No newline at end of file diff --git a/Dao/MyBatis/Maps/CRoom.xml b/Dao/MyBatis/Maps/CRoom.xml index a85fdba..c12bdab 100644 --- a/Dao/MyBatis/Maps/CRoom.xml +++ b/Dao/MyBatis/Maps/CRoom.xml @@ -1237,8 +1237,9 @@ ,ua.isjoin ,row_number() over(order by b.cdt desc) rno ,count(a.taxno) over() pagetotalcount + ,a.mgtkey from ( - select a.taxno,max(cm.cname) cname,a.asaddr,max(bk.bkname) bkname,max(ex.exname) exname,sum(pi.pcnt) pcnt,count(pi.pino) ccount + select a.taxno,max(cm.cname) cname,a.asaddr,max(bk.bkname) bkname,max(ex.exname) exname,sum(pi.pcnt) pcnt,count(pi.pino) ccount, a.mgtkey from paytax a inner join paytaxitem b on b.taxno=a.taxno inner join payitem pi on pi.pino=b.pino @@ -1309,6 +1310,13 @@ from paytax a where a.payno=#payno# + update paytax set @@ -1324,6 +1332,7 @@ ,taxdate=#taxdate# ,taxinfo=#taxinfo# ,iscancel=#iscancel# + ,mgtkey=#mgtkey# where taxno=#taxno#