public ResponseTPLMGet TPLMGet2([FromBody] RequestTPLMGet request) { try { TPLMBLL bll = new TPLMBLL(); return(bll.TPLMGet(request)); } catch (Exception ex) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
/// <summary> /// 模板加载 /// </summary> /// <param name="request"></param> /// <returns></returns> public ResponseTPLMGet TPLGet(RequestTPLMGet request) { ResponseTPLMGet response = new ResponseTPLMGet(); using (cnn = GetConnection()) { var ts = cnn.BeginTransaction(); try { var user = UserInfoGet(request.Token, ts); var head = cnn.QuerySingle <TKS_FAS_DocTPL>("select * from TKS_FAS_DocTPL where id=@Id", new { Id = request.Data.Id }, ts); AccountSetBLL account = new AccountSetBLL(cnn); var period = account.GetActivePeriod(user.AccountId, ts); //模板体明细 var detail = cnn.Query <TKS_FAS_DocDetailTPL>( @"select * from tks_fas_docDetailTPL where parentId=@ParentId", new { ParentId = head.Id }, ts).ToList(); //如果是固定资产,则需要捞取当前账套的所有固定资产的每月折旧额,生成计提折旧凭证 //需要对detail进行再包装 if (head.TPLTarget == 3) { #region 固定资产,计提折旧 FixedAssetsBLL fbll = new FixedAssetsBLL(cnn); //获取固定资产 List <TKS_FAS_FixedAssets> fixedAssets = fbll.FixedAssetsGetByAcccount(user.AccountId, period, ts); //凭证明细 List <TKS_FAS_DocDetailTPL> newDetail = new List <TKS_FAS_DocDetailTPL>(); head.AMT_DBT = 0; foreach (var item in fixedAssets) { if (item.DepreciationMethod == "2") { continue; } if (item.IsStartPeriodDepreciation == 0 && item.StartPeriod == period.Id) { continue; } if (item.DpreMonth < item.PreUseMonth) { //固定资产累计折旧科目,产生到凭证 //用固定资产表单上的科目覆盖模板的科目 for (var i = 0; i < detail.Count; i++) { //update by Hero.Zhang 每次循环前必须将借贷金额初始化 detail[i].Money_Credit = 0; detail[i].Money_Debit = 0; if (detail[i].Credit_Debit == 1) { detail[i].SubjectCode = item.ADSubjectCode; //detail[i].SubjectDescription = item.ADSubjectCode + " " + item.ADSubjectName; detail[i].SubjectDescription = item.ADSubjectName; } else if (detail[i].Credit_Debit == 0) { detail[i].SubjectCode = item.DCostSubjectCode; detail[i].SubjectDescription = item.DCostSubjectName; } } //填充金额 var d = FillDetail(item.DprePerMonth, detail); newDetail.AddRange(d); head.AMT_DBT += item.DprePerMonth; //if (item.ADSubjectCode == "1502001") //{ // test.Add(item); //} } } //分组合并 var lst = newDetail.GroupBy(x => new { x.Id, x.ParentId, x.LineNo, x.AccountId, x.Year, x.SubjectCode, x.SubjectDescription, x.Summary, x.Credit_Debit, x.PartnerCode, x.Unit, x.CurrencyCode, x.CalItem1, x.CalValue1, x.CalItem2, x.CalValue2, x.CalItem3, x.CalValue3, x.CalItem4, x.CalValue4, x.CalItem5, x.CalValue5, x.Rate, x.Quantity, x.Price, x.IsCurrency, x.IsQuantity, x.IsCalHelper, x.Balance, x.YB, x.IPercent, x.SourceType }).Select(x => new TKS_FAS_DocDetailTPL { Id = x.First().Id, ParentId = x.First().ParentId, LineNo = x.First().LineNo, AccountId = x.First().AccountId, Year = x.First().Year, SubjectCode = x.First().SubjectCode, SubjectDescription = x.First().SubjectDescription, Summary = x.First().Summary, Credit_Debit = x.First().Credit_Debit, PartnerCode = x.First().PartnerCode, Unit = x.First().Unit, CurrencyCode = x.First().CurrencyCode, CalItem1 = x.First().CalItem1, CalValue1 = x.First().CalValue1, CalItem2 = x.First().CalItem2, CalValue2 = x.First().CalValue2, CalItem3 = x.First().CalItem3, CalValue3 = x.First().CalValue3, CalItem4 = x.First().CalItem4, CalValue4 = x.First().CalValue4, CalItem5 = x.First().CalItem5, CalValue5 = x.First().CalValue5, Rate = x.First().Rate, Quantity = x.First().Quantity, Price = x.First().Price, IsCurrency = x.First().IsCurrency, IsQuantity = x.First().IsQuantity, IsCalHelper = x.First().IsCalHelper, Balance = x.First().Balance, YB = x.First().YB, IPercent = x.First().IPercent, SourceType = x.First().SourceType, Money_Credit = x.Sum(s => s.Money_Credit), Money_Debit = x.Sum(s => s.Money_Debit) }).ToList(); //detail = newDetail; detail = lst; #endregion } else if (head.TPLTarget == 7) { #region 固定资产变动单类型 var changeTypeToTpl = cnn.QuerySingleOrDefault <TKS_FAS_FixedAssetsChange>( "select * from TKS_FAS_FixedAssetsChange where Id=@Id ", new { Id = request.Key }, ts); if (changeTypeToTpl != null) { //固定资产变动类型新增的情况 string fixsql = @"select B.* from TKS_FAS_FixedAssetsChange A left join TKS_FAS_FixedAssets B on A.parentId=B.id where A.id=@ID"; TKS_FAS_FixedAssets fixedAssets = cnn.QuerySingleOrDefault <TKS_FAS_FixedAssets>(fixsql, new { ID = request.Key }, ts); if (fixedAssets == null) { throw new Exception("固定资产不存在"); } FillDetail(request.Money, detail); if (changeTypeToTpl.ChangeType == 1) { #region 新增 for (var i = 0; i < detail.Count; i++) { if (detail[i].SubjectCode == "1501") { detail[i].SubjectCode = fixedAssets.GDCode; detail[i].SubjectDescription = fixedAssets.GDName; } else if (detail[i].SubjectCode == "217100101") { if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = fixedAssets.InputVAT; } else { detail[i].Money_Credit = fixedAssets.InputVAT; } } else if (detail[i].SubjectCode == "1002") { if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = request.Money + fixedAssets.InputVAT; } else { detail[i].Money_Credit = request.Money + fixedAssets.InputVAT; } } } request.Money += fixedAssets.InputVAT; #endregion } else if (changeTypeToTpl.ChangeType == 8) { #region 报废 for (var i = 0; i < detail.Count; i++) { if (detail[i].SubjectCode == "1501") { if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = fixedAssets.InitialAssetValue; } else { detail[i].Money_Credit = fixedAssets.InitialAssetValue; } } else if (detail[i].SubjectCode == "1502") { if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = fixedAssets.AccumulativeDpre + fixedAssets.DprePerMonth;//累计折旧+每月折旧额 } else { detail[i].Money_Credit = fixedAssets.AccumulativeDpre + fixedAssets.DprePerMonth; } } else if (detail[i].SubjectCode == "1701") { if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = fixedAssets.InitialAssetValue - fixedAssets.AccumulativeDpre - fixedAssets.DprePerMonth;//减去累计折旧和每月折旧额 } else { detail[i].Money_Credit = fixedAssets.InitialAssetValue - fixedAssets.AccumulativeDpre - fixedAssets.DprePerMonth; } } } request.Money = fixedAssets.InitialAssetValue; #endregion } } else { FillDetail(request.Money, detail); } #endregion } else if (head.TPLTarget == 2) { #region 发票上传 //var fp = cnn.Query<TKS_FAS_Invoice>( // "select * from TKS_FAS_Invoice where id=@Id", new { Id =request.Data.Id}, ts); //if (fp == null) //{ // throw new NormalException("未找到对应发票"); //} FillDetail(request.Money, detail); decimal total = 0; for (var i = 0; i < detail.Count; i++) { if (detail[i].SourceType == 0) { //发生额比例,不做处理 } else if (detail[i].SourceType == 1) { //含税金额 if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = request.Money; } else { detail[i].Money_Credit = request.Money; } } else if (detail[i].SourceType == 2) { //税金 if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = request.Tax; } else { detail[i].Money_Credit = request.Tax; } } else if (detail[i].SourceType == 3) { //未税金额 if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = request.Money - request.Tax; } else { detail[i].Money_Credit = request.Money - request.Tax; } } total += detail[i].Money_Debit; } request.Money = total; #endregion } else { FillDetail(request.Money, detail); } if (request.Money > 0) { head.AMT_DBT = request.Money; } ts.Commit(); response.IsSuccess = true; response.Message = "加载完毕"; response.Head = head; response.Detail = detail; #region add by Hero.Zhang 判断科目行是否有子科目 for (int i = 0; i < detail.Count(); i++) { var item = detail[i]; List <TKS_FAS_AccountSubject> sub = cnn.Query <TKS_FAS_AccountSubject>(@"select * from TKS_FAS_AccountSubject where AccountId=@AccountId and RootCode=@RootCode", new { AccountId = user.AccountId, RootCode = item.SubjectCode }, ts).ToList(); if (sub.Count > 1) { response.CheckParent = "1"; response.Message += "</br>第" + (i + 1).ToString() + "行有子科目,请重新选择"; } } #endregion return(response); } catch (Exception ex) { ts.Rollback(); return(this.DealException(response, ex) as ResponseTPLMGet); } } }
/// <summary> /// 综合模板管理(无需选择账套) /// </summary> /// <param name="request"></param> /// <returns></returns> public ResponseTPLMGet TPLMGet(RequestTPLMGet request) { ResponseTPLMGet response = new ResponseTPLMGet(); using (cnn = GetConnection()) { var ts = cnn.BeginTransaction(); try { var user = UserInfoGetButAccount(request.Token, ts); var head = cnn.QuerySingle <TKS_FAS_DocTPL>("select * from TKS_FAS_DocTPL where id=@Id", new { Id = request.Data.Id }, ts); //模板体明细 var detail = cnn.Query <TKS_FAS_DocDetailTPL>( @"select * from tks_fas_docDetailTPL where parentId=@ParentId", new { ParentId = head.Id }, ts).ToList(); //如果是固定资产,则需要捞取当前账套的所有固定资产的每月折旧额,生成计提折旧凭证 //需要对detail进行再包装 if (head.TPLTarget == 3) { #region 固定资产,计提折旧 FillDetail(request.Money, detail); #endregion } else if (head.TPLTarget == 7) { #region 固定资产变动单类型 var changeTypeToTpl = cnn.QuerySingleOrDefault <TKS_FAS_FixedAssetsChange>( "select * from TKS_FAS_FixedAssetsChange where Id=@Id and changeType=1", new { Id = request.Key }, ts); if (changeTypeToTpl != null) { //固定资产变动类型新增的情况 string fixsql = @"select B.* from TKS_FAS_FixedAssetsChange A left join TKS_FAS_FixedAssets B on A.parentId=B.id where A.id=@ID"; TKS_FAS_FixedAssets fixedAssets = cnn.QuerySingleOrDefault <TKS_FAS_FixedAssets>(fixsql, new { ID = request.Key }, ts); if (fixedAssets == null) { throw new Exception("固定资产不存在"); } FillDetail(request.Money, detail); for (var i = 0; i < detail.Count; i++) { if (detail[i].SubjectCode == "1501") { detail[i].SubjectCode = fixedAssets.GDCode; detail[i].SubjectDescription = fixedAssets.GDName; } else if (detail[i].SubjectCode == "217100101") { if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = fixedAssets.InputVAT; } else { detail[i].Money_Credit = fixedAssets.InputVAT; } } else if (detail[i].SubjectCode == "1002") { if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = request.Money + fixedAssets.InputVAT; } else { detail[i].Money_Credit = request.Money + fixedAssets.InputVAT; } } } request.Money += fixedAssets.InputVAT; } else { FillDetail(request.Money, detail); } #endregion } else if (head.TPLTarget == 2) { #region 发票上传 //var fp = cnn.Query<TKS_FAS_Invoice>( // "select * from TKS_FAS_Invoice where id=@Id", new { Id =request.Data.Id}, ts); //if (fp == null) //{ // throw new NormalException("未找到对应发票"); //} FillDetail(request.Money, detail); decimal total = 0; for (var i = 0; i < detail.Count; i++) { if (detail[i].SourceType == 0) { //发生额比例,不做处理 } else if (detail[i].SourceType == 1) { //含税金额 if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = request.Money; } else { detail[i].Money_Credit = request.Money; } } else if (detail[i].SourceType == 2) { //税金 if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = request.Tax; } else { detail[i].Money_Credit = request.Tax; } } else if (detail[i].SourceType == 3) { //未税金额 if (detail[i].Credit_Debit == 0) { detail[i].Money_Debit = request.Money - request.Tax; } else { detail[i].Money_Credit = request.Money - request.Tax; } } total += detail[i].Money_Debit; } request.Money = total; #endregion } else { FillDetail(request.Money, detail); } if (request.Money > 0) { head.AMT_DBT = request.Money; } ts.Commit(); response.IsSuccess = true; response.Message = "加载完毕"; response.Head = head; response.Detail = detail; #region add by Hero.Zhang 判断科目行是否有子科目 for (int i = 0; i < detail.Count(); i++) { var item = detail[i]; List <TKS_FAS_AccountSubject> sub = cnn.Query <TKS_FAS_AccountSubject>(@"select * from TKS_FAS_AccountSubject where AccountId=@AccountId and RootCode=@RootCode", new { AccountId = user.AccountId, RootCode = item.SubjectCode }, ts).ToList(); if (sub.Count > 1) { response.CheckParent = "1"; response.Message += "</br>第" + (i + 1).ToString() + "行有子科目,请重新选择"; } } #endregion return(response); } catch (Exception ex) { ts.Rollback(); return(this.DealException(response, ex) as ResponseTPLMGet); } } }