/// <summary> /// 新製品情報取得 /// </summary> /// <param name="pSetId"></param> /// <returns></returns> public DataSet GetNewShin(int pSetId) { DataSet dsM10NewShin = new DataSet(); using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { context.Connection.Open(); List <M10_NEWSHINHD> hdList = context.M10_NEWSHINHD.Where(c => c.SETID == pSetId).ToList(); List <M10_NEWSHINDTL> dtlList = context.M10_NEWSHINDTL.Where(c => c.SETID == pSetId).OrderBy(o => o.構成行).ToList(); List <M10_NEWSHIZAI> shizaiList = context.M10_NEWSHIZAI.Where(c => c.SETID == pSetId).OrderBy(o => o.行番号).ToList(); List <M10_NEWETC> etcList = context.M10_NEWETC.Where(c => c.SETID == pSetId).OrderBy(o => o.行番号).ToList(); // Datatable変換 DataTable dthd = KESSVCEntry.ConvertListToDataTable(hdList); DataTable dtdtl = KESSVCEntry.ConvertListToDataTable(dtlList); DataTable dtshizai = KESSVCEntry.ConvertListToDataTable(shizaiList); DataTable dtetc = KESSVCEntry.ConvertListToDataTable(etcList); dthd.TableName = M10_HEADER_TABLE_NAME; dsM10NewShin.Tables.Add(dthd); dtdtl.TableName = M10_DETAIL_TABLE_NAME; dsM10NewShin.Tables.Add(dtdtl); dtshizai.TableName = M10_ZHIZAI_TABLE_NAME; dsM10NewShin.Tables.Add(dtshizai); dtetc.TableName = M10_ETC_TABLE_NAME; dsM10NewShin.Tables.Add(dtetc); return(dsM10NewShin); } }
/// <summary> /// 仕入検索情報を取得する /// </summary> /// <param name="companyCode">自社コード</param> /// <param name="slipNumber">伝票番号</param> /// <returns></returns> public DataSet ReturnsSearch(string companyCode, string slipNumber, int userId) { DataSet t03ds = new DataSet(); List <T03.T03_SRHD_RT_Extension> hdList = getM03_SRHD_RT_Extension(companyCode, slipNumber, userId); List <T03.T03_SRDTL_RT_Extension> dtlList = getT03_SRDTL_RT_Extension(slipNumber); M73 taxService = new M73(); List <M73_ZEI> taxList = taxService.GetDataList(); if (hdList.Count == 0) { return(t03ds); } // Datatable変換 DataTable dthd = KESSVCEntry.ConvertListToDataTable(hdList); DataTable dtdtl = KESSVCEntry.ConvertListToDataTable(dtlList); DataTable dttax = KESSVCEntry.ConvertListToDataTable(taxList); dthd.TableName = T03_HEADER_TABLE_NAME; t03ds.Tables.Add(dthd); dtdtl.TableName = T03_DETAIL_TABLE_NAME; t03ds.Tables.Add(dtdtl); dttax.TableName = M73_TABLE_NAME; t03ds.Tables.Add(dttax); return(t03ds); }
/// <summary> /// 仕入入力検索情報を取得する /// </summary> /// <param name="companyCode">自社コード</param> /// <param name="slipNumber">伝票番号</param> /// <returns></returns> public DataSet GetData(string companyCode, string slipNumber, int userId) { DataSet t03ds = new DataSet(); M73 taxService = new M73(); List <T03.T03_SRHD_Extension> hdList = getM03_SRHD_Extension(companyCode, slipNumber); List <T03.T03_SRDTL_Extension> dtlList = getT03_SRDTL_Extension(slipNumber); List <M73_ZEI> taxList = taxService.GetDataList(); List <DLY03010.S11_KAKUTEI_INFO> fixList = getS11_KAKUTEI_Extension(hdList); if (hdList.Count == 0) { if (string.IsNullOrEmpty(slipNumber)) { // 伝票番号未入力の場合は新規伝票扱いとする M88 svc = new M88(); int code = int.Parse(companyCode); T03.T03_SRHD_Extension hd = new T03.T03_SRHD_Extension(); hd.伝票番号 = svc.getNextNumber(CommonConstants.明細番号ID.ID01_売上_仕入_移動, userId); hd.会社名コード = code.ToString(); hd.仕入日 = com.GetDbDateTime(); hdList.Add(hd); } else { // 指定伝票が見つからない場合 return(null); } } int rowCnt = 1; foreach (T03_SRDTL row in dtlList) { row.行番号 = rowCnt++; } // Datatable変換 DataTable dthd = KESSVCEntry.ConvertListToDataTable(hdList); DataTable dtdtl = KESSVCEntry.ConvertListToDataTable(dtlList); DataTable dttax = KESSVCEntry.ConvertListToDataTable(taxList); DataTable dtfix = KESSVCEntry.ConvertListToDataTable(fixList); dthd.TableName = T03_HEADER_TABLE_NAME; t03ds.Tables.Add(dthd); dtdtl.TableName = T03_DETAIL_TABLE_NAME; t03ds.Tables.Add(dtdtl); dttax.TableName = M73_TABLE_NAME; t03ds.Tables.Add(dttax); dtfix.TableName = S11_TABLE_NAME; t03ds.Tables.Add(dtfix); return(t03ds); }
/// <summary> /// 入金入力 検索情報を取得する /// </summary> /// <param name="companyCode">会社名コード(入金先自社コード)</param> /// <param name="slipNumber">伝票番号</param> /// <param name="userId">ログインユーザID</param> /// <returns></returns> public DataSet GetData(string companyCode, string slipNumber, int userId) { DataSet t11ds = new DataSet(); List <T11_NYKNHD_Extension> hdList = getM11_NYKNHD_Extension(companyCode, slipNumber); List <T11_NYKNDTL_Extension> dtlList = getT11_NYKNDTL_Extension(slipNumber); if (hdList.Count == 0) { if (string.IsNullOrEmpty(slipNumber)) { // 伝票番号未入力の場合は新規伝票扱いとしてデータを作成 M88 svc = new M88(); int code = int.Parse(companyCode); // 新規伝票番号を取得して設定 T11_NYKNHD_Extension hd = new T11_NYKNHD_Extension(); hd.伝票番号 = svc.getNextNumber(Const.明細番号ID.ID05_入金, userId); hd.入金先自社コード = companyCode; hd.入金日 = DateTime.Now; hdList.Add(hd); } else { // 伝票番号誤りの場合は検索を終了する return(null); } } int rowCnt = 1; foreach (T11_NYKNDTL_Extension row in dtlList) { row.行番号 = rowCnt++; } // Datatable変換 DataTable dthd = KESSVCEntry.ConvertListToDataTable(hdList); DataTable dtdtl = KESSVCEntry.ConvertListToDataTable(dtlList); dthd.TableName = TABLE_HEADER; t11ds.Tables.Add(dthd); dtdtl.TableName = TABLE_DETAIL; t11ds.Tables.Add(dtdtl); return(t11ds); }
/// <summary> /// 出金予定表の基本情報を取得する /// </summary> /// <param name="condition"> /// == 検索条件 == /// 自社コード /// 出金年月 /// 出金日 /// 全出金日 /// 仕入先コード /// 仕入先枝番 /// 作成区分 /// </param> /// <returns></returns> private DataTable getCommonData(Dictionary <string, string> condition) { // 検索パラメータを展開 int myCompany, paymentYearMonth, createType; int? paymentDay, customerCode, customerEda; bool isAllDays; getFormParams(condition, out myCompany, out paymentYearMonth, out paymentDay, out isAllDays, out customerCode, out customerEda, out createType); using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { var baseList = context.V_SHR06010 .Where(w => w.自社コード == myCompany && w.K支払年月 == paymentYearMonth); #region 任意入力条件の適用 if (customerCode != null && customerEda != null) { baseList = baseList .Where(w => w.K支払先コード == customerCode && w.K支払先枝番 == customerEda); } if (paymentDay != null) { baseList = baseList .Where(w => w.K入金日 == paymentDay); } if (createType == 1) { baseList = baseList .Where(w => w.支払予定額 != 0); } #endregion // データを出金年月日順でソート baseList = baseList .OrderBy(o => o.自社コード) .ThenBy(t => t.K支払年月) .ThenBy(t => t.K入金日) .ThenBy(t => t.K支払先コード) .ThenBy(t => t.K支払先枝番); return(KESSVCEntry.ConvertListToDataTable <V_SHR06010>(baseList.ToList())); } }
/// <summary> /// 移動検索情報を取得する /// </summary> /// <param name="companyCode">自社コード(会社名コード)</param> /// <param name="slipNumber">伝票番号</param> /// <param name="userId">ログインユーザID</param> /// <returns></returns> public DataSet GetData(string companyCode, string slipNumber, int userId) { DataSet t05ds = new DataSet(); List <T05_IDOHD_Extension> hdList = getT05_IDOHD_Extension(companyCode, slipNumber); List <T05_IDODTL_Extension> dtlList = getT05_IDODTL_Extension(companyCode, slipNumber); if (hdList.Count == 0) { if (string.IsNullOrEmpty(slipNumber)) { // 未入力の場合は新規伝票として作成 M88 svc = new M88(); int code = int.Parse(companyCode); // 新規伝票番号を取得して設定 T05_IDOHD_Extension hd = new T05_IDOHD_Extension(); hd.伝票番号 = svc.getNextNumber(CommonConstants.明細番号ID.ID01_売上_仕入_移動, userId); hd.会社名コード = code; hd.日付 = DateTime.Now; hd.移動区分 = CommonConstants.移動区分.振替移動.GetHashCode(); hdList.Add(hd); } else { // 入力アリの場合は番号誤りなので検索を終了する return(null); } } // Datatableに変換 DataTable dthd = KESSVCEntry.ConvertListToDataTable(hdList); DataTable dtInDtl = KESSVCEntry.ConvertListToDataTable(dtlList.Where(c => c.行番号 == 1).ToList()); DataTable dtOutDtl = KESSVCEntry.ConvertListToDataTable(dtlList.Where(c => c.行番号 == 2).ToList()); // テーブル名を設定 dthd.TableName = TABLE_HEADER; dtInDtl.TableName = NYUKO_TABLE_DETAIL; dtOutDtl.TableName = SYUKO_TABLE_DETAIL; // データセットに追加 t05ds.Tables.Add(dthd); t05ds.Tables.Add(dtInDtl); t05ds.Tables.Add(dtOutDtl); return(t05ds); }
/// <summary> /// 仕入入力情報の削除をおこなう /// </summary> /// <param name="slipNumber">伝票番号</param> /// <param name="userId">ユーザID</param> /// <returns></returns> public int Delete(string slipNumber, int userId) { using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { context.Connection.Open(); using (var tran = context.Connection.BeginTransaction(System.Data.IsolationLevel.Serializable)) { int number = 0; if (int.TryParse(slipNumber, out number)) { T03Service = new T03(context, userId); // No.156-1 Add S03Service = new S03(context, userId); S04Service = new S04(context, userId, S04.機能ID.仕入入力); try { // ①仕入ヘッダ論理削除 T03_SRHD hdData = T03Service.T03_SRHD_Delete(number); // ②仕入明細論理削除 List <T03_SRDTL> dtlList = T03Service.T03_SRDTL_Delete(number); // ③在庫更新 foreach (T03_SRDTL row in dtlList) { S03_STOK stok = new S03_STOK(); stok.庫コード = T03Service.get倉庫コード(hdData.会社名コード); stok.品番コード = row.品番コード; stok.賞味期限 = AppCommon.DateTimeToDate(row.賞味期限, DateTime.MaxValue); stok.在庫数 = row.数量 * -1; S03Service.S03_STOK_Update(stok); } // ④入出庫履歴作成 DataTable wkTbl = KESSVCEntry.ConvertListToDataTable <T03_SRDTL>(dtlList); wkTbl.AcceptChanges(); // No.156-1 Add foreach (DataRow row in wkTbl.Rows) { // 削除分を判定させる為、RowStateを変更する row.Delete(); } setS04_HISTORY_Create(context, hdData, wkTbl, null); // No.156-1 Mod,No-258 Mod // 変更状態を確定 context.SaveChanges(); // No.156-1 Add } catch { tran.Rollback(); throw new Exception("削除処理実行中にエラーが発生しました。"); } } else { throw new KeyNotFoundException("伝票番号が正しくありません"); } tran.Commit(); } } return(1); }
/// <summary> /// 売掛一覧データ取得 /// </summary> /// <param name="context"></param> /// <param name="company">会社コード</param> /// <param name="targetStDate">集計開始日</param> /// <param name="targetEdDate">集計終了日</param> /// <param name="customerCode">得意先コード</param> /// <param name="customerEda">得意先枝番</param> /// <returns></returns> private DataTable getData(TRAC3Entities context, int company, DateTime targetStDate, DateTime targetEdDate, int?customerCode, int?customerEda) { DataTable dt = new DataTable(); List <PrintMember> UrikakeList = new List <PrintMember>(); // No.386 Mod // 自社マスタ var targetJis = context.M70_JIS .Where(w => w.削除日時 == null && w.自社コード == company) .First(); // 金種(名称)データ取得 var goldType = context.M99_COMBOLIST .Where(w => w.分類 == "随時" && w.機能 == "入金問合せ" && w.カテゴリ == "金種"); var UrikakeQuery = context.S08_URIKAKE .Where(w => w.自社コード == company && w.日付 >= targetStDate && w.日付 <= targetEdDate && w.得意先コード == (customerCode == null ? w.得意先コード : customerCode) && w.得意先枝番 == (customerEda == null ? w.得意先枝番 : customerEda)) .GroupJoin(context.M01_TOK.Where(c => c.削除日時 == null), x => new { コード = x.得意先コード, 枝番 = x.得意先枝番 }, y => new { コード = y.取引先コード, 枝番 = y.枝番 }, (x, y) => new { x, y }) .SelectMany(m => m.y.DefaultIfEmpty(), (a, b) => new { URIKAKE = a.x, TOK = b }) .GroupJoin(context.M09_HIN.Where(w => w.削除日時 == null), x => x.URIKAKE.品番コード, y => y.品番コード, (x, y) => new { x, y }) .SelectMany(m => m.y.DefaultIfEmpty(), (c, d) => new { c.x.URIKAKE, c.x.TOK, HIN = d }) .GroupJoin(context.M06_IRO.Where(c => c.削除日時 == null), x => x.HIN.自社色, y => y.色コード, (x, y) => new { x, y }) .SelectMany(m => m.y.DefaultIfEmpty(), (e, f) => new { e.x.URIKAKE, e.x.TOK, e.x.HIN, IRO = f }) .Select(x => new PrintMember { 自社コード = x.URIKAKE.自社コード, 自社名 = targetJis.自社名, 得意先コード = x.URIKAKE.得意先コード, 得意先枝番 = x.URIKAKE.得意先枝番, 得意先名称 = x.TOK.略称名, 日付 = x.URIKAKE.日付, 伝票番号 = x.URIKAKE.伝票番号, 行番号 = x.URIKAKE.行番号, 自社色 = x.URIKAKE.金種コード == 0 ? x.IRO.色名称 : string.Empty, 自社品番 = x.HIN.自社品番, 自社品名 = x.URIKAKE.金種コード == 0 ? x.URIKAKE.自社品名 : goldType.Where(c => c.コード == x.URIKAKE.金種コード).Select(c => c.表示名).FirstOrDefault(), 数量 = x.URIKAKE.数量, 単位 = x.HIN.単位, 単価 = x.URIKAKE.単価, 金額 = x.URIKAKE.金額, 通常税率消費税 = x.URIKAKE.通常税率消費税, 軽減税率消費税 = x.URIKAKE.軽減税率消費税, 入金金額 = x.URIKAKE.入金額, 前月繰越 = x.URIKAKE.前月繰越, 残高 = x.URIKAKE.残高, }) .ToList(); // 日付をCSV出力用に整形 foreach (var row in UrikakeQuery) { row.s日付 = row.日付.ToString("yyyy/MM/dd"); // No.386 Add Start if (UrikakeQuery.Where(c => c.得意先コード == row.得意先コード && c.得意先枝番 == row.得意先枝番).Count() <= 1) { if (row.伝票番号 == 0 && row.入金金額 == 0 && row.前月繰越 == 0 && row.残高 == 0) { continue; } } UrikakeList.Add(row); // No.386 Add End } var resultList = UrikakeList.OrderBy(c => c.自社コード).ThenBy(c => c.得意先コード).ThenBy(c => c.得意先枝番).ThenBy(c => c.日付) .ThenBy(c => c.伝票番号).ThenBy(c => c.行番号).ToList(); dt = KESSVCEntry.ConvertListToDataTable <PrintMember>(resultList.ToList()); return(dt); }
/// <summary> /// 仕入一覧データ取得 /// </summary> /// <param name="context">context</param> /// <param name="company">会社コード</param> /// <param name="yearMonth">作成年月</param> /// <param name="tokList">支払先リスト</param> /// <param name="printKbn">印刷区分 0:集約する 1:集約しない</param> /// <returns></returns> private DataTable getData(TRAC3Entities context, int company, int yearMonth, List <M01_TOK> tokList, int printKbn) { DataTable dt = new DataTable(); // 仕入一覧データ取得 List <S07_SRIHD> sriList = getHeaderData(context, company, yearMonth, tokList); if (sriList == null) { return(null); } // 取得データを統合して結果リストを作成 if (printKbn == 印刷区分.集約しない.GetHashCode()) { var resultList = sriList.GroupJoin(tokList, x => new { コード = x.支払先コード, 枝番 = x.支払先枝番 }, y => new { コード = y.取引先コード, 枝番 = y.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y, (a, b) => new { SHD = a.x, TOK = b }) .GroupJoin(context.M70_JIS.Where(w => w.削除日時 == null), x => x.SHD.自社コード, y => y.自社コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (c, d) => new { c.x.SHD, c.x.TOK, JIS = d }) .GroupBy(g => new { g.SHD.自社コード, g.JIS.自社名, g.SHD.支払年月, g.SHD.支払先コード, g.SHD.支払先枝番, g.TOK.略称名, g.TOK.得意先名1 }) .Select(x => new PrintMember { 自社コード = x.Key.自社コード, // No.227,228 Add 自社名 = x.Key.自社名, // No.227,228 Add 仕入先コード = string.Format("{0:0000} - {1:00}", x.Key.支払先コード, x.Key.支払先枝番), 仕入先名称 = x.Key.略称名 == null ? x.Key.得意先名1 : x.Key.略称名, 前月繰越 = (long)x.Sum(s => s.SHD.前月残高), 出金金額 = (long)x.Sum(s => s.SHD.出金額), 繰越残高 = (long)x.Sum(s => s.SHD.前月残高) - (long)x.Sum(s => s.SHD.出金額), 通常税率対象支払額 = (long)x.Sum(s => s.SHD.通常税率対象金額), 軽減税率対象支払額 = (long)x.Sum(s => s.SHD.軽減税率対象金額), 通常税消費税 = (long)x.Sum(s => s.SHD.通常税率消費税), 軽減税消費税 = (long)x.Sum(s => s.SHD.軽減税率消費税), 税込支払額 = (long)x.Sum(s => s.SHD.通常税率対象金額) + (long)x.Sum(s => s.SHD.通常税率消費税), 軽減税込支払額 = (long)x.Sum(s => s.SHD.軽減税率対象金額) + (long)x.Sum(s => s.SHD.軽減税率消費税), 非課税支払額 = (long)x.Sum(s => s.SHD.非課税支払額), 当月支払額 = (long)x.Sum(s => s.SHD.当月支払額), }).ToList(); resultList = resultList.OrderBy(o => o.仕入先コード).ToList(); dt = KESSVCEntry.ConvertListToDataTable <PrintMember>(resultList); } else { List <PrintMember> hanshaList = new List <PrintMember>(); List <PrintMember> wkList = new List <PrintMember>(); // 販社リスト取得 var hanList = tokList .GroupJoin(context.M70_JIS.Where(w => w.削除日時 == null && w.自社区分 == (int)CommonConstants.自社区分.販社 && w.取引先コード != null && w.枝番 != null), x => new { code = x.取引先コード, eda = x.枝番 }, y => new { code = (int)y.取引先コード, eda = (int)y.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y, (a, b) => new { HAN = a.x, JIS = b }).ToList(); if (hanList.Count() > 0) { // 販社は集約しせず抽出 hanshaList = sriList.GroupJoin(hanList, x => new { コード = x.支払先コード, 枝番 = x.支払先枝番 }, y => new { コード = y.HAN.取引先コード, 枝番 = y.HAN.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y, (a, b) => new { SHD = a.x, TOK = b }) .GroupJoin(context.M70_JIS.Where(w => w.削除日時 == null), x => x.SHD.自社コード, y => y.自社コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (c, d) => new { c.x.SHD, c.x.TOK, JIS = d }) .GroupBy(g => new { g.SHD.自社コード, g.JIS.自社名, g.SHD.支払年月, g.SHD.支払先コード, g.SHD.支払先枝番, g.TOK.HAN.略称名, g.TOK.HAN.得意先名1 }) .Select(x => new PrintMember { 自社コード = x.Key.自社コード, // No.227,228 Add 自社名 = x.Key.自社名, // No.227,228 Add 仕入先コード = string.Format("{0:0000} - {1:00}", x.Key.支払先コード, x.Key.支払先枝番), 仕入先名称 = x.Key.略称名 == null ? x.Key.得意先名1 : x.Key.略称名, 前月繰越 = (long)x.Sum(s => s.SHD.前月残高), 出金金額 = (long)x.Sum(s => s.SHD.出金額), 繰越残高 = (long)x.Sum(s => s.SHD.前月残高) - (long)x.Sum(s => s.SHD.出金額), 通常税率対象支払額 = (long)x.Sum(s => s.SHD.通常税率対象金額), 軽減税率対象支払額 = (long)x.Sum(s => s.SHD.軽減税率対象金額), 通常税消費税 = (long)x.Sum(s => s.SHD.通常税率消費税), 軽減税消費税 = (long)x.Sum(s => s.SHD.軽減税率消費税), 税込支払額 = (long)x.Sum(s => s.SHD.通常税率対象金額) + (long)x.Sum(s => s.SHD.通常税率消費税), 軽減税込支払額 = (long)x.Sum(s => s.SHD.軽減税率対象金額) + (long)x.Sum(s => s.SHD.軽減税率消費税), 非課税支払額 = (long)x.Sum(s => s.SHD.非課税支払額), 当月支払額 = (long)x.Sum(s => s.SHD.当月支払額), }).ToList(); } // 販社以外の得意先は集約して抽出 tokList = tokList.Where(x => hanList.Select(s => s.HAN.取引先コード).Contains(x.取引先コード) == false).ToList(); if (tokList.Count > 0) { wkList = sriList.GroupJoin(tokList, x => new { コード = x.支払先コード, 枝番 = x.支払先枝番 }, y => new { コード = y.取引先コード, 枝番 = y.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y, (a, b) => new { SHD = a.x, TOK = b }) .GroupJoin(context.M70_JIS.Where(w => w.削除日時 == null), x => x.SHD.自社コード, y => y.自社コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (c, d) => new { c.x.SHD, c.x.TOK, JIS = d }) .GroupBy(g => new { g.SHD.自社コード, g.JIS.自社名, g.SHD.支払年月, g.SHD.支払先コード, g.TOK.得意先名1 //g.TOK.略称名 }) .Select(x => new PrintMember { 自社コード = x.Key.自社コード, // No.227,228 Add 自社名 = x.Key.自社名, // No.227,228 Add 仕入先コード = string.Format("{0:0000} - 00", x.Key.支払先コード), 仕入先名称 = x.Key.得意先名1 == null ? "" : x.Key.得意先名1, 前月繰越 = (long)x.Sum(s => s.SHD.前月残高), 出金金額 = (long)x.Sum(s => s.SHD.出金額), 繰越残高 = (long)x.Sum(s => s.SHD.前月残高) - (long)x.Sum(s => s.SHD.出金額), 通常税率対象支払額 = (long)x.Sum(s => s.SHD.通常税率対象金額), 軽減税率対象支払額 = (long)x.Sum(s => s.SHD.軽減税率対象金額), 通常税消費税 = (long)x.Sum(s => s.SHD.通常税率消費税), 軽減税消費税 = (long)x.Sum(s => s.SHD.軽減税率消費税), 税込支払額 = (long)x.Sum(s => s.SHD.通常税率対象金額) + (long)x.Sum(s => s.SHD.通常税率消費税), 軽減税込支払額 = (long)x.Sum(s => s.SHD.軽減税率対象金額) + (long)x.Sum(s => s.SHD.軽減税率消費税), 非課税支払額 = (long)x.Sum(s => s.SHD.非課税支払額), 当月支払額 = (long)x.Sum(s => s.SHD.当月支払額), }).ToList(); } // 販社リストと得意先リストを結合 var resultList = hanshaList.ToList().Concat(wkList); resultList = resultList.OrderBy(o => o.仕入先コード).ToList(); dt = KESSVCEntry.ConvertListToDataTable <PrintMember>(resultList.ToList()); } return(dt); }
/// <summary> /// 確定済チェック /// </summary> /// <param name="自社コード"></param> /// <param name="得意先コード"></param> /// <param name="得意先枝番"></param> /// <param name="仕入先コード"></param> /// <param name="仕入先枝番"></param> /// <returns></returns> public DataTable CheckFix(string 自社コード, string 得意先コード, string 得意先枝番, string 仕入先コード, string 仕入先枝番) { using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { context.Connection.Open(); // パラメータ型変換 int iVal = 0; int company = int.TryParse(自社コード, out iVal) ? iVal : -1; int tCode = int.TryParse(得意先コード, out iVal) ? iVal : -1; int tEda = int.TryParse(得意先枝番, out iVal) ? iVal : -1; int sCode = int.TryParse(仕入先コード, out iVal) ? iVal : -1; int sEda = int.TryParse(仕入先枝番, out iVal) ? iVal : -1; IEnumerable <TKS90010_FIX_INFO> tFixData = null; IEnumerable <TKS90010_FIX_INFO> sFixData = null; // 得意先情報 if (!string.IsNullOrEmpty(得意先コード)) { var tokData = context.M01_TOK.Where(w => w.取引先コード == tCode && w.枝番 == tEda && w.削除日時 == null); tFixData = tokData .GroupJoin(context.S11_KAKUTEI.Where(w => w.確定区分 == (int)CommonConstants.確定区分.請求), x => new { jis = x.担当会社コード, tKbn = x.取引区分, day = (int)x.T締日 }, y => new { jis = y.自社コード, tKbn = y.取引区分, day = y.締日 }, (x, y) => new { x, y }) .SelectMany(z => z.y.DefaultIfEmpty(), (a, b) => new { TOK = a.x, FIX = b }) .ToList() .Select(s => new TKS90010_FIX_INFO { 自社コード = s.FIX != null ? s.FIX.自社コード : (int?)null, 区分 = CommonConstants.確定区分_請求, 確定区分 = s.FIX != null ? s.FIX.確定区分 : (int?)null, 取引区分 = s.TOK.取引区分, 取引先コード = s.TOK.取引先コード.ToString(), 枝番 = s.TOK.枝番.ToString(), 取引先名 = s.TOK.略称名, 締日 = s.FIX != null ? s.FIX.締日 : (int?)null, 確定日 = s.FIX != null ? s.FIX.確定日 : (DateTime?)null }) .Union (tokData .GroupJoin(context.S11_KAKUTEI.Where(w => w.確定区分 == (int)CommonConstants.確定区分.支払), x => new { jis = x.担当会社コード, tKbn = x.取引区分, day = (int)x.S締日 }, y => new { jis = y.自社コード, tKbn = y.取引区分, day = y.締日 }, (x, y) => new { x, y }) .SelectMany(z => z.y.DefaultIfEmpty(), (a, b) => new { TOK = a.x, FIX = b }) .ToList() .Select(s => new TKS90010_FIX_INFO { 自社コード = s.FIX != null ? s.FIX.自社コード : (int?)null, 区分 = CommonConstants.確定区分_支払, 確定区分 = s.FIX != null ? s.FIX.確定区分 : (int?)null, 取引区分 = s.TOK.取引区分, 取引先コード = s.TOK.取引先コード.ToString(), 枝番 = s.TOK.枝番.ToString(), 取引先名 = s.TOK.略称名, 締日 = s.FIX != null ? s.FIX.締日 : (int?)null, 確定日 = s.FIX != null ? s.FIX.確定日 : (DateTime?)null })); } // 仕入先情報 if (!string.IsNullOrEmpty(仕入先コード)) { var sTokData = context.M01_TOK.Where(w => w.取引先コード == sCode && w.枝番 == sEda && w.削除日時 == null); sFixData = sTokData .GroupJoin(context.S11_KAKUTEI.Where(w => w.確定区分 == (int)CommonConstants.確定区分.支払), x => new { jis = x.担当会社コード, tKbn = x.取引区分, day = (int)x.S締日 }, y => new { jis = y.自社コード, tKbn = y.取引区分, day = y.締日 }, (x, y) => new { x, y }) .SelectMany(z => z.y.DefaultIfEmpty(), (a, b) => new { TOK = a.x, FIX = b }) .ToList() .Select(s => new TKS90010_FIX_INFO { 自社コード = s.FIX != null ? s.FIX.自社コード : (int?)null, 区分 = CommonConstants.確定区分_支払, 確定区分 = s.FIX != null ? s.FIX.確定区分 : (int?)null, 取引区分 = s.TOK.取引区分, 取引先コード = s.TOK.取引先コード.ToString(), 枝番 = s.TOK.枝番.ToString(), 取引先名 = s.TOK.略称名, 締日 = s.FIX != null ? s.FIX.締日 : (int?)null, 確定日 = s.FIX != null ? s.FIX.確定日 : (DateTime?)null }) .Union (sTokData .GroupJoin(context.S11_KAKUTEI.Where(w => w.確定区分 == (int)CommonConstants.確定区分.請求), x => new { jis = x.担当会社コード, tKbn = x.取引区分, day = (int)x.T締日 }, y => new { jis = y.自社コード, tKbn = y.取引区分, day = y.締日 }, (x, y) => new { x, y }) .SelectMany(z => z.y.DefaultIfEmpty(), (a, b) => new { TOK = a.x, FIX = b }) .ToList() .Select(s => new TKS90010_FIX_INFO { 自社コード = s.FIX != null ? s.FIX.自社コード : (int?)null, 区分 = CommonConstants.確定区分_請求, 確定区分 = s.FIX != null ? s.FIX.確定区分 : (int?)null, 取引区分 = s.TOK.取引区分, 取引先コード = s.TOK.取引先コード.ToString(), 枝番 = s.TOK.枝番.ToString(), 取引先名 = s.TOK.略称名, 締日 = s.FIX != null ? s.FIX.締日 : (int?)null, 確定日 = s.FIX != null ? s.FIX.確定日 : (DateTime?)null })); } // 確定データを連結 tFixData = tFixData != null ? (sFixData != null ? tFixData.Concat(sFixData) : tFixData) : sFixData; // Datatable変換 DataTable fixDt = KESSVCEntry.ConvertListToDataTable(tFixData.ToList()); return(fixDt); } }
/// <summary> /// 支払一覧表の基本情報を取得する /// </summary> /// <param name="condition"></param> /// <returns></returns> private DataTable getCommonData(Dictionary <string, string> condition) { // 検索パラメータを展開 int myCompany, createYearMonth; int? closingDay, customerCode, customerEda; bool isAllDays; getFormParams(condition, out myCompany, out createYearMonth, out closingDay, out isAllDays, out customerCode, out customerEda); // ベースとなる支払ヘッダ情報を取得 List <S02_SHRHD_Data> hdList = getHeaderData(condition); var hdData = hdList.GroupBy(g => new { g.自社コード, g.自社名, g.支払年月, g.支払締日, g.支払先コード, g.支払先枝番, g.通常消費税, g.軽減消費税 }) .Select(s => new { s.Key.自社コード, s.Key.自社名, // No.227,228 Add s.Key.支払年月, s.Key.支払締日, s.Key.支払先コード, s.Key.支払先枝番, s.Key.通常消費税, s.Key.軽減消費税 }); // 詳細データ件数を取得 List <S02_SHRDTL> dtlList = getDetailData(condition); var dtlData = dtlList.Select(s => new { s.自社コード, s.支払年月, s.支払締日, s.支払先コード, s.支払先枝番, s.仕入日, // No.326 Add s.品番コード, s.自社品名, // No.390 Add s.単価, s.数量, s.金額, s.摘要, // No.336 Add }); // 取引先情報を取得 List <M01_TOK> tokList = getTokData(hdList); // 品番情報を取得 List <M09_HIN> hinList = getHinData(dtlList); // 取得データを統合して結果リストを作成 var resultList = hdData.GroupJoin(dtlData, x => new { x.自社コード, x.支払年月, x.支払締日, x.支払先コード, x.支払先枝番 }, y => new { y.自社コード, y.支払年月, y.支払締日, y.支払先コード, y.支払先枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y, (a, b) => new { NHD = a.x, NDTL = b }) .GroupJoin(hinList, x => new { x.NDTL.品番コード }, y => new { y.品番コード }, (x, y) => new { x, y }) .SelectMany(x => x.y, (c, d) => new { c.x.NHD, c.x.NDTL, HIN = d }) .GroupJoin(tokList, x => new { コード = x.NHD.支払先コード, 枝番 = x.NHD.支払先枝番 }, y => new { コード = y.取引先コード, 枝番 = y.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y, (e, f) => new { e.x.NHD, e.x.NDTL, e.x.HIN, TOK = f }) .OrderBy(o => o.NHD.支払先コード) .ThenBy(t => t.NHD.支払先枝番) .ToList() .Select(x => new PrintMember { 自社コード = x.NHD.自社コード, // No.277,288 Add 自社名 = x.NHD.自社名, // No.277,288 Add 仕入先コード = string.Format("{0:D4} - {1:D2}", x.NHD.支払先コード, x.NHD.支払先枝番), // No-150, No.223 Mod 仕入先名称 = x.TOK == null ? "" : x.TOK.略称名, // No.326 Mod 支払締日 = x.NHD.支払締日.ToString(), 仕入日 = x.NDTL.仕入日, // No.326 Mod 品番コード = x.NDTL.品番コード, 自社品番 = x.HIN.自社品番, 色コード = x.HIN.自社色, //品名 = x.HIN.自社品名, 品名 = !string.IsNullOrEmpty(x.NDTL.自社品名) ? x.NDTL.自社品名 : x.HIN.自社品名, // No.390 Add 単価 = x.NDTL.単価, 数量 = x.NDTL.数量, 金額 = x.NDTL.金額, 通常消費税 = (int)x.NHD.通常消費税, 軽減消費税 = (int)x.NHD.軽減消費税, 摘要 = x.NDTL.摘要, // No.336 Add }); return(KESSVCEntry.ConvertListToDataTable <PrintMember>(resultList.ToList())); }
/// <summary> /// 移動検索情報を取得する /// </summary> /// <param name="companyCode">自社コード(会社名コード)</param> /// <param name="slipNumber">伝票番号</param> /// <param name="userId">ログインユーザID</param> /// <returns></returns> public DataSet GetData(string companyCode, string slipNumber, int userId) { DataSet t05ds = new DataSet(); List <T05_IDOHD_Extension> hdList = getM05_IDOHD_Extension(companyCode, slipNumber); List <T05_IDODTL_Extension> dtlList = getT05_IDODTL_Extension(slipNumber); if (hdList.Count == 0) { if (string.IsNullOrEmpty(slipNumber)) { // 未入力の場合は新規伝票として作成 M88 svc = new M88(); int code = int.Parse(companyCode); // 新規伝票番号を取得して設定 T05_IDOHD_Extension hd = new T05_IDOHD_Extension(); hd.伝票番号 = svc.getNextNumber(CommonConstants.明細番号ID.ID01_売上_仕入_移動, userId); hd.会社名コード = code; hd.日付 = DateTime.Now; hd.移動区分 = CommonConstants.移動区分.通常移動.GetHashCode(); hdList.Add(hd); } else { // 入力アリの場合は番号誤りなので検索を終了する return(null); } } int rowCnt = 1; foreach (T05_IDODTL_Extension row in dtlList) { row.行番号 = rowCnt++; } // Datatable変換 DataTable dthd = KESSVCEntry.ConvertListToDataTable(hdList); DataTable dtdtl = KESSVCEntry.ConvertListToDataTable(dtlList); //// 不足レコードの補充 //T05_IDOHD idohd = convertDataRowToT05_IDOHD_Entity(dthd.Rows[0]); //for (int i = 10 - dtdtl.Rows.Count; i >= 0; i--) //{ // DataRow row = dtdtl.NewRow(); // row["伝票番号"] = idohd.伝票番号; // row["行番号"] = 10 - i; // dtdtl.Rows.Add(row); //} dthd.TableName = TABLE_HEADER; t05ds.Tables.Add(dthd); dtdtl.TableName = TABLE_DETAIL; t05ds.Tables.Add(dtdtl); return(t05ds); }
/// <summary> /// 請求書印字データを取得する /// </summary> /// <param name="condition"> /// == 検索条件 == /// 自社コード /// 作成年月日 /// 作成年月 /// 作成締日 /// 得意先コード /// 得意先枝番 /// </param> /// <param name="ds"> /// [0]請求一覧データ /// </param> /// <returns></returns> public DataSet GetPrintData(Dictionary <string, string> condition, DataSet ds) { DataSet dsResult = new DataSet(); DataTable tbl = ds.Tables[0]; // パラメータの型変換 int ival; int myCompany = int.Parse(condition["自社コード"]); int createYM = int.Parse(condition["作成年月"].Replace("/", "")); DateTime printDate = DateTime.Parse(condition["作成年月日"]); int? closingDate = int.TryParse(condition["作成締日"], out ival) ? ival : (int?)null; int? customerCd = int.TryParse(condition["得意先コード"], out ival) ? ival : (int?)null; int? customerEda = int.TryParse(condition["得意先枝番"], out ival) ? ival : (int?)null; using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { foreach (DataRow row in tbl.Rows) { SearchDataMember mem = getSearchDataMemberRow(row); if (mem.印刷区分 == false) { continue; } // 前月情報を取得 DateTime befYearMonth = new DateTime(createYM / 100, createYM % 100, 1).AddMonths(-1); int iBefYearMonth = befYearMonth.Year * 100 + befYearMonth.Month; #region 必要情報の取得 // 対象の請求ヘッダを取得 var seihd = context.S01_SEIHD.Where(w => w.自社コード == myCompany && w.請求年月 == createYM && (w.請求締日 == closingDate || closingDate == null) && w.請求先コード == mem.得意先コード && w.請求先枝番 == mem.得意先枝番 && w.入金日 == mem.入金日 && w.回数 == mem.回数) .FirstOrDefault(); // 取引先情報を取得 var tok = context.M01_TOK.Where(w => w.削除日時 == null && w.取引先コード == seihd.請求先コード && w.枝番 == seihd.請求先枝番) .FirstOrDefault(); // 前月の入金日 //int befPaymentDate = iBefYearMonth * 100 + tok.T入金日1 ?? 31; // 前月の請求ヘッダを取得 var befSeihd = context.S01_SEIHD.Where(w => w.自社コード == myCompany && w.請求年月 == iBefYearMonth && //(w.請求締日 == closingDate || closingDate == null) && w.請求先コード == mem.得意先コード && w.請求先枝番 == mem.得意先枝番 && //w.入金日 == befPaymentDate && w.回数 == mem.回数) .OrderByDescending(w => w.請求締日) .ThenByDescending(w => w.回数) .FirstOrDefault(); #endregion // 前月の締期間を算出 //DateTime befEndDate = AppCommon.GetClosingDate(befYearMonth.Year, befYearMonth.Month, closingDate, 0); //DateTime befStrDate = befEndDate.AddMonths(-1).AddDays(-1); long 前月入金額; // 各入金額を取得する if (befSeihd != null) { 前月入金額 = getNyukinData(context, seihd.自社コード, seihd.請求先コード, seihd.請求先枝番, (DateTime)befSeihd.集計開始日, (DateTime)befSeihd.集計最終日); } else { DateTime befEndDate = AppCommon.GetClosingDate(befYearMonth.Year, befYearMonth.Month, closingDate, 0); DateTime befStrDate = befEndDate.AddMonths(-1).AddDays(-1); 前月入金額 = getNyukinData(context, seihd.自社コード, seihd.請求先コード, seihd.請求先枝番, befEndDate, befStrDate); } long 今月入金額 = getNyukinData(context, seihd.自社コード, seihd.請求先コード, seihd.請求先枝番, (DateTime)seihd.集計開始日, (DateTime)seihd.集計最終日); #region 帳票ヘッダ情報取得 var hdResult = context.S01_SEIHD.Where(w => w.自社コード == myCompany && w.請求年月 == createYM && w.請求締日 == mem.締日 && w.請求先コード == mem.得意先コード && w.請求先枝番 == mem.得意先枝番 && w.入金日 == mem.入金日 && w.回数 == mem.回数) .GroupJoin(context.M01_TOK.Where(w => w.削除日時 == null), x => new { コード = x.請求先コード, 枝番 = x.請求先枝番 }, y => new { コード = y.取引先コード, 枝番 = y.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { SEIHD = a.x, TOK = b }) .GroupJoin(context.M70_JIS.Where(w => w.削除日時 == null), x => x.SEIHD.自社コード, y => y.自社コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (c, d) => new { c.x.SEIHD, c.x.TOK, JIS = d }) .ToList() .Select(x => new PrintHeaderMember { PagingKey = string.Concat(x.SEIHD.請求先コード, "-", x.SEIHD.請求先枝番, "-", x.SEIHD.入金日, ">", x.SEIHD.回数), 自社コード = x.SEIHD.自社コード.ToString(), 請求年月 = x.SEIHD.請求年月.ToString(), 請求先コード = x.SEIHD.請求先コード.ToString(), 請求先枝番 = x.SEIHD.請求先枝番.ToString(), 得意先コード = string.Format("{0:D4}", x.SEIHD.請求先コード), // No.223 Mod 得意先枝番 = string.Format("{0:D2}", x.SEIHD.請求先枝番), // No.233 Mod 回数 = x.SEIHD.回数, 請求年 = x.SEIHD.請求年月 / 100, 請求月 = x.SEIHD.請求年月 % 100, 請求先郵便番号 = x.TOK.郵便番号, 請求先住所1 = x.TOK.住所1, 請求先住所2 = x.TOK.住所2, 得意先名称 = x.TOK.得意先名1, 得意先名称2 = x.TOK.得意先名2, 得意先部課名称 = x.TOK.部課名称, 自社名称 = x.JIS.自社名, 自社郵便番号 = x.JIS.郵便番号, 自社住所 = x.JIS.住所1.Trim() + x.JIS.住所2.Trim(), 自社TEL = x.JIS.電話番号, 自社FAX = x.JIS.FAX, 締日 = (x.TOK.T締日 >= 31) ? "末" : x.TOK.T締日.ToString(), 発行日付 = printDate.ToString("yyyy/MM/dd"), 前回請求額 = x.SEIHD.前月残高, //20190906 mod-s CB 軽減税率対応 DB値を設定に変更 //今回入金額 = 今月入金額, //繰越残高 = (前月入金額 - (befSeihd != null ? befSeihd.当月請求額 : 0)), 今回入金額 = x.SEIHD.入金額, 繰越残高 = x.SEIHD.繰越残高, //20190906 mod-e CB 軽減税率対応 御買上額 = x.SEIHD.売上額, 消費税S = x.SEIHD.消費税, 消費税K = 0, 今回請求額 = x.SEIHD.当月請求額, //20190903 mod&add-s CB 軽減税率対応 //振込先 = x.JIS.振込銀行1 振込先 = x.JIS.振込銀行1, 通常税率対象金額 = x.SEIHD.通常税率対象金額, 軽減税率対象金額 = x.SEIHD.軽減税率対象金額, 通常税率消費税 = x.SEIHD.通常税率消費税, 軽減税率消費税 = x.SEIHD.軽減税率消費税, 非税売上額 = x.SEIHD.非税売上額, 集計最終日 = x.SEIHD.集計最終日 //20190903 add-e CB 軽減税率対応 }); #endregion #region 帳票明細情報取得 var dtlResult = context.S01_SEIDTL.Where(w => w.自社コード == myCompany && w.請求年月 == createYM && w.請求締日 == mem.締日 && w.請求先コード == mem.得意先コード && w.請求先枝番 == mem.得意先枝番 && w.入金日 == mem.入金日 && w.回数 == mem.回数) .GroupJoin(context.M09_HIN.Where(w => w.削除日時 == null), x => x.品番コード, y => y.品番コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { SDTL = a.x, HIN = b }) .GroupJoin(context.M10_TOKHIN.Where(w => w.削除日時 == null && w.取引先コード == mem.得意先コード && w.枝番 == mem.得意先枝番), x => x.HIN.品番コード, y => y.品番コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (c, d) => new { c.x.SDTL, c.x.HIN, TOKHIN = d }) .ToList() .Select(x => new PrintDetailMember { PagingKey = string.Concat(x.SDTL.請求先コード, "-", x.SDTL.請求先枝番, "-", x.SDTL.入金日, ">", x.SDTL.回数), 自社コード = x.SDTL.自社コード.ToString(), 請求年月 = x.SDTL.請求年月.ToString(), 請求先コード = x.SDTL.請求先コード.ToString(), 請求先枝番 = x.SDTL.請求先枝番.ToString(), 得意先コード = string.Format("{0:D4}", x.SDTL.請求先コード), // No.223 Mod 得意先枝番 = string.Format("{0:D2}", x.SDTL.請求先枝番), // No.223 Mod 回数 = x.SDTL.回数, 伝票番号 = x.SDTL.伝票番号, // No-181 Mod 売上日 = x.SDTL.売上日.ToString("yyyy/MM/dd"), 自社品番 = x.HIN.自社品番, 相手品番 = x.TOKHIN == null ? "" : x.TOKHIN.得意先品番コード, 品番名称 = !string.IsNullOrEmpty(x.SDTL.自社品名) ? x.SDTL.自社品名 : x.HIN.自社品名, // No.389 Mod 数量 = x.SDTL.数量, 単価 = x.SDTL.単価, 金額 = x.SDTL.金額, //20190902 CB mod - s 軽減税率対応 //軽減税率適用 = x.HIN.消費税区分 == (int)CommonConstants.商品消費税区分.軽減税率 ? "*" : "" 軽減税率適用 = x.HIN.消費税区分 == (int)CommonConstants.商品消費税区分.軽減税率 ? "軽" : x.HIN.消費税区分 == (int)CommonConstants.商品消費税区分.非課税 ? "非" : "", //20190902 CB mod - e 摘要 = x.SDTL.摘要 }) .OrderBy(o => o.売上日).ThenBy(o => o.伝票番号); // No-181 Add #endregion #region 期間内の入金明細 var nyukinDtl = context.T11_NYKNHD.Where(c => c.入金先自社コード == myCompany && c.得意先コード == mem.得意先コード && c.得意先枝番 == mem.得意先枝番 && c.入金日 >= seihd.集計開始日 && c.入金日 <= seihd.集計最終日 && c.削除日時 == null ) .GroupJoin(context.T11_NYKNDTL.Where(c => c.削除日時 == null), x => x.伝票番号, y => y.伝票番号, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { HD = a.x, DTL = b }) .GroupJoin(context.M99_COMBOLIST.Where(c => c.分類 == "随時" && c.機能 == "入金問合せ" && c.カテゴリ == "金種"), x => x.DTL.金種コード, y => y.コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { NYU = a.x, CMB = b }) .ToList() .Select(x => new PrintDetailMember { PagingKey = string.Concat(mem.得意先コード, "-", mem.得意先枝番, "-", mem.入金日, ">", mem.回数), 自社コード = myCompany.ToString(), 請求年月 = createYM.ToString(), 請求先コード = mem.得意先コード.ToString(), 請求先枝番 = mem.得意先枝番.ToString(), 得意先コード = string.Format("{0:D4}", mem.得意先コード), // No.223 Mod 得意先枝番 = string.Format("{0:D2}", mem.得意先枝番), // No.223 Mod 回数 = mem.回数, 伝票番号 = x.NYU.HD.伝票番号, // No-181 Mod 売上日 = x.NYU.HD.入金日.ToString("yyyy/MM/dd"), 自社品番 = string.Empty, 相手品番 = string.Empty, 品番名称 = x.CMB.表示名 == null ? string.Empty : x.CMB.表示名, 数量 = 0, 単価 = 0, 金額 = x.NYU.DTL.金額, 軽減税率適用 = "", 摘要 = x.NYU.DTL.摘要, }); //売上日→伝票番号の順でソート var dtl = dtlResult.Concat(nyukinDtl).OrderBy(o => o.売上日).ThenBy(o => o.伝票番号); #endregion //20190910 CB add - s 軽減税率対応 //S01_SEIHDの集計最終日を基準としてM73_ZEIから税率を取得 DataTable dt; dt = KESSVCEntry.ConvertListToDataTable <PrintHeaderMember>(hdResult.AsQueryable().ToList()); M73 M73Service; M73Service = new M73(); foreach (DataRow dr in dt.Rows) { // drを使った処理(カラムにアクセスする場合は dr["カラム名"]と表記) DateTime?DateTimeWk = (DateTime)dr["集計最終日"]; if (DateTimeWk != null) { //共通関数仕様 +1日 DateTime answer = (DateTime)DateTimeWk; answer = answer.AddDays(1); List <M73.M73_ZEI_Member> lstM73 = M73Service.GetData(answer, -1); dr["軽減税率"] = lstM73[0].軽減税率; dr["消費税率"] = lstM73[0].消費税率; } } //20190910 CB add - e 軽減税率対応 //20190910 CB mod - s 軽減税率対応 //DataTable hdDt = KESSVCEntry.ConvertListToDataTable<PrintHeaderMember>(hdResult.AsQueryable().ToList()); DataTable hdDt = dt; //20190910 CB mod - e 軽減税率対応 hdDt.TableName = PRINT_HEADER_TABLE_NAME; DataTable dtlDt = KESSVCEntry.ConvertListToDataTable <PrintDetailMember>(dtl.AsQueryable().ToList()); dtlDt.TableName = PRINT_DETAIL_TABLE_NAME; if (dtlDt.Rows.Count == 0 && (decimal)hdDt.Rows[0]["今回請求額"] != 0) { DataRow dr = dtlDt.NewRow(); dr["PagingKey"] = hdDt.Rows[0]["PagingKey"]; dr["自社コード"] = hdDt.Rows[0]["自社コード"]; dr["請求年月"] = hdDt.Rows[0]["請求年月"]; dr["請求先コード"] = hdDt.Rows[0]["請求先コード"]; dr["請求先枝番"] = hdDt.Rows[0]["請求先枝番"]; dr["得意先コード"] = hdDt.Rows[0]["得意先コード"]; dr["得意先枝番"] = hdDt.Rows[0]["得意先枝番"]; dr["回数"] = hdDt.Rows[0]["回数"]; dtlDt.Rows.Add(dr); } if (dsResult.Tables.Contains(hdDt.TableName)) { // 2件目以降 dsResult.Tables[PRINT_HEADER_TABLE_NAME].Merge(hdDt); dsResult.Tables[PRINT_DETAIL_TABLE_NAME].Merge(dtlDt); } else { // 1件目 dsResult.Tables.Add(hdDt); dsResult.Tables.Add(dtlDt); } } } return(dsResult); }
/// <summary> /// 調整計算確定処理をおこなう /// </summary> /// <param name="paramDic">パラメータDic</param> /// <param name="userId">ログインユーザID</param> public void SetConfirm(Dictionary <string, string> paramDic, int userId) { int compCd = int.Parse(paramDic[PARAM_NAME_COMPANY]), year = int.Parse(paramDic[PARAM_NAME_YEAR].Replace("/", "")); decimal rate = decimal.Parse(paramDic[PARAM_NAME_RATE]); using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { context.Connection.Open(); using (var tran = context.Connection.BeginTransaction(System.Data.IsolationLevel.Serializable)) { try { // 取引先情報取得 var hanData = context.M70_JIS .Where(w => w.削除日時 == null && w.自社コード == compCd) .Join(context.M01_TOK, x => new { code = x.取引先コード ?? 0, eda = x.枝番 ?? 0 }, y => new { code = y.取引先コード, eda = y.枝番 }, (x, y) => new { JIS = x, TOK = y }) .FirstOrDefault(); // 決算月・請求締日から売上集計期間を算出する int pMonth = hanData.JIS.決算月 ?? CommonConstants.DEFAULT_SETTLEMENT_MONTH, pYear = pMonth < 4 ? year + 1 : year; DateTime lastMonth = new DateTime(pYear, pMonth, 1); DateTime targetMonth = lastMonth.AddMonths(-11); while (targetMonth <= lastMonth) { // 開始日は前月締日を設定 // No.101-3 Mod Start DateTime calcStartDate = AppCommon.GetClosingDate(targetMonth.AddMonths(-1).Year, targetMonth.AddMonths(-1).Month, hanData.TOK.T締日 ?? CommonConstants.DEFAULT_CLOSING_DAY); // 終了日は当月締日の前日を設定 DateTime calcEndDate = AppCommon.GetClosingDate(targetMonth.Year, targetMonth.Month, hanData.TOK.T締日 ?? CommonConstants.DEFAULT_CLOSING_DAY).AddDays(-1); // No.101-3 Mod End var hdList = context.T02_URHD_HAN .Where(v => v.削除日時 == null && v.販社コード == compCd && v.売上日 >= calcStartDate && v.売上日 <= calcEndDate); foreach (var hdRow in hdList) { // 売上ヘッダ情報更新 hdRow.消費税 = hdRow.調整消費税 ?? 0; hdRow.最終更新者 = userId; hdRow.最終更新日時 = com.GetDbDateTime(); hdRow.AcceptChanges(); // 仕入情報が存在するか var srhd = context.T03_SRHD_HAN.Where(w => w.削除日時 == null && w.伝票番号 == hdRow.伝票番号) .FirstOrDefault(); if (srhd != null) { // 仕入がある場合は値を更新する srhd.消費税 = hdRow.調整消費税; srhd.最終更新者 = userId; srhd.最終更新日時 = com.GetDbDateTime(); srhd.AcceptChanges(); } // 売上明細情報更新 foreach (var dtlRow in context.T02_URDTL_HAN.Where(w => w.削除日時 == null && w.伝票番号 == hdRow.伝票番号)) { dtlRow.単価 = dtlRow.調整単価 ?? 0; dtlRow.金額 = dtlRow.調整金額; dtlRow.最終更新者 = userId; dtlRow.最終更新日時 = com.GetDbDateTime(); dtlRow.AcceptChanges(); if (srhd != null) { // 仕入があれば対象の仕入明細の値を更新する var srdtl = context.T03_SRDTL_HAN.Where(w => w.伝票番号 == dtlRow.伝票番号 && w.行番号 == dtlRow.行番号) .FirstOrDefault(); if (srdtl == null) { continue; } srdtl.単価 = dtlRow.調整単価 ?? 0; srdtl.金額 = dtlRow.調整金額 ?? 0; srdtl.最終更新者 = userId; srdtl.最終更新日時 = com.GetDbDateTime(); srdtl.AcceptChanges(); } } } // データ更新後に締集計をおこなう TKS01010 clampService = new TKS01010(); // 集計処理に必要なデータを作成 var jis = context.M70_JIS.Where(w => w.削除日時 == null && w.自社区分 == (int)CommonConstants.自社区分.自社) .First(); TKS01010.TKS01010_SearchMember srcMem = new TKS01010.TKS01010_SearchMember(); srcMem.ID = string.Format("{0:D3} - {1:D2}", hanData.TOK.取引先コード, hanData.TOK.枝番); srcMem.得意先コード = hanData.TOK.取引先コード; srcMem.得意先枝番 = hanData.TOK.枝番; srcMem.得意先名 = hanData.TOK.得意先名1; // No.101-3 Mod Start srcMem.締日 = hanData.TOK.T締日 ?? CommonConstants.DEFAULT_CLOSING_DAY; // No.101-3 Mod End srcMem.開始日付1 = calcStartDate; srcMem.終了日付1 = calcEndDate; // No.101-3 Mod Start srcMem.入金日 = AppCommon.GetClosingDate(targetMonth.Year, targetMonth.Month, hanData.TOK.T入金日1 ?? CommonConstants.DEFAULT_CLOSING_DAY, hanData.TOK.Tサイト1 ?? 0); // No-169 Mod // No.101-3 Mod End List <TKS01010.TKS01010_SearchMember> list = new List <TKS01010.TKS01010_SearchMember>(); list.Add(srcMem); DataTable dt = KESSVCEntry.ConvertListToDataTable(list); DataSet ds = new DataSet(); ds.Tables.Add(dt); // 集計実行 clampService.BillingAggregation(ds, jis.自社コード, targetMonth.Year * 100 + targetMonth.Month, userId); // 次データの為に各値をカウントアップ targetMonth = targetMonth.AddMonths(1); } // 変更状態を確定 context.SaveChanges(); // トランザクションコミット tran.Commit(); } catch (Exception ex) { // トランザクションロールバック tran.Rollback(); throw ex; } }// end transaction } }
/// <summary> /// 請求書印字データを取得する /// </summary> /// <param name="condition"> /// == 検索条件 == /// 自社コード /// 作成年月日 /// 作成年月 /// 作成締日 /// 得意先コード /// 得意先枝番 /// </param> /// <param name="ds"> /// [0]請求一覧データ /// </param> /// <returns></returns> public DataSet GetPrintDetail(Dictionary <string, string> condition) { DataSet dsResult = new DataSet(); // パラメータの型変換 DateTime printDate = DateTime.Parse(condition["作成年月日"]); using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { // 対象の請求ヘッダを取得 List <S02_SHRHD_Data> hdList = getHeaderData(condition); #region 帳票ヘッダ情報取得 var hdResult = hdList .GroupJoin(context.M01_TOK.Where(w => w.削除日時 == null), x => new { コード = x.支払先コード, 枝番 = x.支払先枝番 }, y => new { コード = y.取引先コード, 枝番 = y.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { SHRHD = a.x, TOK = b }) .GroupJoin(context.M70_JIS.Where(w => w.削除日時 == null), x => x.SHRHD.自社コード, y => y.自社コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (c, d) => new { c.x.SHRHD, c.x.TOK, JIS = d }) .OrderBy(o => o.SHRHD.支払先コード) .ThenBy(t => t.SHRHD.支払先枝番) .ToList() .Select(x => new PrintHeaderMember { PagingKey = string.Concat(x.SHRHD.支払先コード, "-", x.SHRHD.支払先枝番, "-", x.SHRHD.支払日, ">", x.SHRHD.回数), 自社コード = x.SHRHD.自社コード.ToString(), 支払年月 = x.SHRHD.支払年月.ToString(), 支払先コード = x.SHRHD.支払先コード.ToString(), 支払先枝番 = x.SHRHD.支払先枝番.ToString(), 得意先コード = string.Format("{0:D4}", x.SHRHD.支払先コード), // No.223 Mod 得意先枝番 = string.Format("{0:D2}", x.SHRHD.支払先枝番), // No.233 Mod 回数 = x.SHRHD.回数, 支払年 = x.SHRHD.支払年月 / 100, 支払月 = x.SHRHD.支払年月 % 100, 支払先郵便番号 = x.TOK.郵便番号, 支払先住所1 = x.TOK.住所1, 支払先住所2 = x.TOK.住所2, 得意先名称 = x.TOK.得意先名1, 得意先名称2 = x.TOK.得意先名2, 得意先部課名称 = x.TOK.部課名称, 自社名称 = x.JIS.自社名, 自社郵便番号 = x.JIS.郵便番号, 自社住所 = x.JIS.住所1.Trim() + x.JIS.住所2.Trim(), 自社TEL = x.JIS.電話番号, 自社FAX = x.JIS.FAX, 締日 = (x.TOK.S締日 >= 31) ? "末" : x.TOK.S締日.ToString(), 発行日付 = printDate.ToString("yyyy/MM/dd"), 支払額 = x.SHRHD.支払額, 消費税S = x.SHRHD.消費税, 今回支払額 = x.SHRHD.支払額 + x.SHRHD.消費税, 前回支払額 = x.SHRHD.前回支払額, 今回出金額 = x.SHRHD.今回出金額, 繰越残高 = x.SHRHD.繰越残高, 通常税率対象金額 = x.SHRHD.通常税率対象金額, 軽減税率対象金額 = x.SHRHD.軽減税率対象金額, 通常税率消費税 = x.SHRHD.通常税率消費税, 軽減税率消費税 = x.SHRHD.軽減税率消費税, 非税売上額 = x.SHRHD.非課税支払額, 集計最終日 = x.SHRHD.集計最終日 }); #endregion #region 帳票明細情報取得 // 対象の請求ヘッダを取得 List <S02_SHRDTL> dtlList = getDetailData(condition); var dtlResult = dtlList.GroupJoin(context.M09_HIN.Where(w => w.削除日時 == null), x => x.品番コード, y => y.品番コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { SDTL = a.x, HIN = b }) .GroupJoin(context.M10_TOKHIN.Where(w => w.削除日時 == null), x => new { コード = x.SDTL.支払先コード, 枝番 = x.SDTL.支払先枝番 }, y => new { コード = y.取引先コード, 枝番 = y.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (c, d) => new { c.x.SDTL, c.x.HIN, TOKHIN = d }) .OrderBy(o => o.SDTL.支払先コード) .ThenBy(o => o.SDTL.支払先枝番) .ToList() .Select(x => new PrintDetailMember { PagingKey = string.Concat(x.SDTL.支払先コード, "-", x.SDTL.支払先枝番, "-", x.SDTL.支払日, ">", x.SDTL.回数), 自社コード = x.SDTL.自社コード.ToString(), 支払年月 = x.SDTL.支払年月.ToString(), 支払先コード = x.SDTL.支払先コード.ToString(), 支払先枝番 = x.SDTL.支払先枝番.ToString(), 得意先コード = string.Format("{0:D4}", x.SDTL.支払先コード), 得意先枝番 = string.Format("{0:D2}", x.SDTL.支払先枝番), 回数 = x.SDTL.回数, 伝票番号 = x.SDTL.伝票番号, 仕入日 = x.SDTL.仕入日.ToString("yyyy/MM/dd"), 自社品番 = x.HIN.自社品番, 相手品番 = x.TOKHIN == null ? "" : x.TOKHIN.得意先品番コード, 品番名称 = !string.IsNullOrEmpty(x.SDTL.自社品名) ? x.SDTL.自社品名 : x.HIN.自社品名, // No.389 Mod 数量 = x.SDTL.数量, 単価 = x.SDTL.単価, 金額 = x.SDTL.金額, //20190902 CB mod - s 軽減税率対応 //軽減税率適用 = x.HIN.消費税区分 == (int)CommonConstants.商品消費税区分.軽減税率 ? "*" : "" 軽減税率適用 = x.SDTL.伝票区分 != (int)CommonConstants.支払伝票区分.仕入伝票 ? "" : (x.HIN.消費税区分 == (int)CommonConstants.商品消費税区分.軽減税率 ? "軽" : x.HIN.消費税区分 == (int)CommonConstants.商品消費税区分.非課税 ? "非" : ""), //20190902 CB mod - e 摘要 = x.SDTL.摘要 }); #endregion #region 期間内の出金明細 foreach (var mem in hdList.ToList()) { var shukinDtl = context.T12_PAYHD.Where(c => c.出金元自社コード == mem.自社コード && c.得意先コード == mem.支払先コード && c.得意先枝番 == mem.支払先枝番 && c.出金日 >= mem.集計開始日 && c.出金日 <= mem.集計最終日 && c.削除日時 == null ) .GroupJoin(context.T12_PAYDTL.Where(c => c.削除日時 == null), x => x.伝票番号, y => y.伝票番号, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { HD = a.x, DTL = b }) .GroupJoin(context.M99_COMBOLIST.Where(c => c.分類 == "随時" && c.機能 == "出金問合せ" && c.カテゴリ == "金種"), x => x.DTL.金種コード, y => y.コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { SHU = a.x, CMB = b }) .ToList() .Select(x => new PrintDetailMember { PagingKey = string.Concat(mem.支払先コード, "-", mem.支払先枝番, "-", mem.支払日, ">", mem.回数), 自社コード = mem.自社コード.ToString(), 支払年月 = mem.支払年月.ToString(), 支払先コード = mem.支払先コード.ToString(), 支払先枝番 = mem.支払先枝番.ToString(), 得意先コード = string.Format("{0:D4}", mem.支払先コード), // No.223 Mod 得意先枝番 = string.Format("{0:D2}", mem.支払先枝番), // No.223 Mod 回数 = mem.回数, 伝票番号 = x.SHU.HD.伝票番号, // No-181 Mod 仕入日 = x.SHU.HD.出金日.ToString("yyyy/MM/dd"), 自社品番 = string.Empty, 相手品番 = string.Empty, 品番名称 = x.CMB.表示名 == null ? string.Empty : x.CMB.表示名, 数量 = 0, 単価 = 0, 金額 = x.SHU.DTL.金額, 軽減税率適用 = "", 摘要 = x.SHU.DTL.摘要, }); //売上日→伝票番号の順でソート dtlResult = dtlResult.Concat(shukinDtl).OrderBy(o => o.仕入日).ThenBy(o => o.伝票番号); } #endregion //S01_SHRHDの集計最終日を基準としてM73_ZEIから税率を取得 DataTable dt; dt = KESSVCEntry.ConvertListToDataTable <PrintHeaderMember>(hdResult.AsQueryable().ToList()); M73 M73Service; M73Service = new M73(); foreach (DataRow dr in dt.Rows) { // drを使った処理(カラムにアクセスする場合は dr["カラム名"]と表記) DateTime?DateTimeWk = (DateTime)dr["集計最終日"]; if (DateTimeWk != null) { //共通関数仕様 +1日 DateTime answer = (DateTime)DateTimeWk; answer = answer.AddDays(1); List <M73.M73_ZEI_Member> lstM73 = M73Service.GetData(answer, -1); dr["軽減税率"] = lstM73[0].軽減税率; dr["消費税率"] = lstM73[0].消費税率; } } DataTable hdDt = dt; hdDt.TableName = PRINT_HEADER_TABLE_NAME; DataTable dtlDt = KESSVCEntry.ConvertListToDataTable <PrintDetailMember>(dtlResult.AsQueryable().ToList()); dtlDt.TableName = PRINT_DETAIL_TABLE_NAME; if (dsResult.Tables.Contains(hdDt.TableName)) { // 2件目以降 dsResult.Tables[PRINT_HEADER_TABLE_NAME].Merge(hdDt); dsResult.Tables[PRINT_DETAIL_TABLE_NAME].Merge(dtlDt); } else { // 1件目 dsResult.Tables.Add(hdDt); dsResult.Tables.Add(dtlDt); } } return(dsResult); }
/// <summary> /// 支払一覧表の基本情報を取得する /// </summary> /// <param name="condition"></param> /// <returns></returns> private DataTable getCommonData(Dictionary <string, string> condition) { // 検索パラメータを展開 int myCompany, createYearMonth, createType; int? closingDay, customerCode, customerEda; bool isAllDays; getFormParams(condition, out myCompany, out createYearMonth, out closingDay, out isAllDays, out customerCode, out customerEda, out createType); // ベースとなる支払ヘッダ情報を取得 List <S02_SHRHD_Data> hdList = getHeaderData(condition); var hdData = hdList.GroupBy(g => new { g.自社コード, g.自社名, g.支払年月, g.支払締日, g.支払先コード, g.支払先枝番 }) .Select(s => new { s.Key.自社コード, s.Key.自社名, // No.227,228 Add s.Key.支払年月, s.Key.支払締日, s.Key.支払先コード, s.Key.支払先枝番, 前月残高 = s.Sum(m => m.前月残高), 通常支払額 = s.Sum(m => m.通常税率対象金額), 軽減支払額 = s.Sum(m => m.軽減税率対象金額), 通常消費税 = s.Sum(m => m.通常税率消費税), 軽減消費税 = s.Sum(m => m.軽減税率消費税), 売上額 = s.Sum(m => m.支払額), 値引額 = s.Sum(m => m.値引額), 非税売上額 = s.Sum(m => m.非課税支払額), 消費税 = s.Sum(m => m.消費税), 当月支払額 = s.Sum(m => m.当月支払額) }); // 詳細データ件数を取得 List <S02_SHRDTL> dtlList = getDetailData(condition); var dtlData = dtlList.GroupBy(g => new { g.自社コード, g.支払年月, g.支払締日, g.支払先コード, g.支払先枝番 }) .Select(s => new { s.Key.自社コード, s.Key.支払年月, s.Key.支払締日, s.Key.支払先コード, s.Key.支払先枝番, 件数 = s.Count() }); // 入金データを取得(金額集計済) List <T12_PAY_Data> payList = getPayData(createYearMonth / 100, createYearMonth % 100, hdList); // 取引先情報を取得 List <M01_TOK> tokList = getTokData(hdList); // 取得データを統合して結果リストを作成 var resultList = hdData.GroupJoin(dtlData, x => new { x.自社コード, x.支払先コード, x.支払先枝番 }, y => new { y.自社コード, y.支払先コード, y.支払先枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { NHD = a.x, NDTL = b }) .GroupJoin(payList, x => new { x.NHD.自社コード, コード = x.NHD.支払先コード, 枝番 = x.NHD.支払先枝番 }, y => new { y.自社コード, コード = y.得意先コード, 枝番 = y.得意先枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (c, d) => new { c.x.NHD, c.x.NDTL, PAY = d }) .GroupJoin(tokList, x => new { コード = x.NHD.支払先コード, 枝番 = x.NHD.支払先枝番 }, y => new { コード = y.取引先コード, 枝番 = y.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (e, f) => new { e.x.NHD, e.x.NDTL, e.x.PAY, TOK = f }) .OrderBy(o => o.NHD.支払先コード) .ThenBy(t => t.NHD.支払先枝番) .ToList() .Select(x => new PrintMember { 自社コード = x.NHD.自社コード, // No.227,228 Add 自社名 = x.NHD.自社名, // No.227,228 Add 仕入先コード = string.Format("{0:D4} - {1:D2}", x.NHD.支払先コード, x.NHD.支払先枝番), // No-149, No.223 Mod 仕入先名称 = x.TOK == null ? "" : x.TOK.略称名, 支払締日 = x.NHD.支払締日.ToString(), 前月残高 = x.NHD.前月残高, 出金金額 = x.PAY == null ? 0 : x.PAY.出金額, 支払額 = x.NHD.売上額, 値引額 = x.NHD.値引額, 非課税支払額 = x.NHD.非税売上額, 消費税 = x.NHD.消費税, 当月支払額 = x.NHD.当月支払額, 件数 = x.NDTL == null ? 0 : x.NDTL.件数, 通常支払額 = x.NHD.通常支払額, 軽減支払額 = x.NHD.軽減支払額, 通常消費税 = x.NHD.通常消費税, 軽減消費税 = x.NHD.軽減消費税, }); return(KESSVCEntry.ConvertListToDataTable <PrintMember>(resultList.ToList())); }
/// <summary> /// 請求一覧表の基本情報を取得する /// </summary> /// <param name="condition"></param> /// <returns></returns> private DataTable getCommonData(Dictionary <string, string> condition) { // 検索パラメータを展開 int myCompany, createYearMonth, createType; int? closingDay, customerCode, customerEda; bool isAllDays; getFormParams(condition, out myCompany, out createYearMonth, out closingDay, out isAllDays, out customerCode, out customerEda, out createType); // ベースとなる請求ヘッダ情報を取得 List <S01_SEIHD_Data> hdList = getHeaderData(condition); // No.227,228 Mod var hdData = hdList.GroupBy(g => new { g.自社コード, g.自社名 , g.請求年月, g.請求締日 , g.請求先コード, g.請求先枝番 , g.入金日, g.集計最終日 }) .Select(s => new { s.Key.自社コード, s.Key.自社名, // No.227,228 Mod s.Key.請求年月, s.Key.請求締日, s.Key.請求先コード, s.Key.請求先枝番, s.Key.入金日, s.Key.集計最終日, 回数 = s.Sum(m => m.回数), 前月残高 = s.Sum(m => m.前月残高), 入金金額 = s.Sum(m => m.入金額), 繰越残高 = s.Sum(m => m.繰越残高), 売上額 = s.Sum(m => m.売上額), 非税売上額 = s.Sum(m => m.非税売上額), 消費税 = s.Sum(m => m.消費税), 当月請求額 = s.Sum(m => m.当月請求額) }); // 請求明細データ件数を取得 List <S01_SEIDTL> dtlList = getDetailData(condition); var dtlData = dtlList.GroupBy(g => new { g.自社コード , g.請求年月 , g.請求締日 , g.請求先コード , g.請求先枝番 , g.入金日 , g.回数 }) .Select(s => new { s.Key.自社コード, s.Key.請求年月, s.Key.請求締日, s.Key.請求先コード, s.Key.請求先枝番, s.Key.入金日, s.Key.回数, 件数 = s.Count() }); // 入金データを取得(金額集計済) List <T11_NYKN_Data> nykList = getNyukinData(createYearMonth / 100, createYearMonth % 100, hdList); // 取引先情報を取得 List <M01_TOK> tokList = getTokData(hdList); // 取得データを統合して結果リストを作成 var resultList = hdData.GroupJoin(dtlData, x => new { x.自社コード, x.請求先コード, x.請求先枝番, x.請求年月, x.請求締日, x.入金日, x.回数 }, y => new { y.自社コード, y.請求先コード, y.請求先枝番, y.請求年月, y.請求締日, y.入金日, y.回数 }, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { NHD = a.x, NDTL = b }) .GroupJoin(nykList, x => new { x.NHD.自社コード, コード = x.NHD.請求先コード, 枝番 = x.NHD.請求先枝番 }, y => new { y.自社コード, コード = y.得意先コード, 枝番 = y.得意先枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (c, d) => new { c.x.NHD, c.x.NDTL, NYKN = d }) .GroupJoin(tokList, x => new { コード = x.NHD.請求先コード, 枝番 = x.NHD.請求先枝番 }, y => new { コード = y.取引先コード, 枝番 = y.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (e, f) => new { e.x.NHD, e.x.NDTL, e.x.NYKN, TOK = f }) .OrderBy(o => o.NHD.請求先コード) .ThenBy(t => t.NHD.請求先枝番) .ToList() .Select(x => new PrintMember { 自社コード = x.NHD.自社コード, // No.227,228 Add 自社名 = x.NHD.自社名, // No.227,228 Add 得意先コード = string.Format("{0:D4} - {1:D2}", x.NHD.請求先コード, x.NHD.請求先枝番), // No.132-1,No.223 Mod 得意先名称 = x.TOK == null ? "" : x.TOK.略称名, // No.229 Mod 回数 = x.NHD.回数, 請求締日 = x.NHD.集計最終日.ToString(), //都度請求のデータがあるため集計最終日 前月残高 = x.NHD.前月残高, 入金金額 = x.NHD.入金金額, 繰越残高 = x.NHD.繰越残高, 売上額 = x.NHD.売上額, 非課税売上額 = x.NHD.非税売上額, 消費税 = x.NHD.消費税, 当月請求額 = x.NHD.当月請求額, 件数 = x.NDTL == null ? 0 : x.NDTL.件数 }).Distinct(); DataTable dt; dt = KESSVCEntry.ConvertListToDataTable <PrintMember>(resultList.ToList()); //DataView dv = new DataView(dt); //DataTable retdt = dv.ToTable(true,"自社コード", "自社名", "得意先コード", "得意先名称", "回数", "請求締日", "前月残高", "入金金額", "繰越残高", "売上額", "非課税売上額", "消費税", "当月請求額", "件数"); foreach (DataRow dr in dt.Rows) { string sWk = dr["請求締日"].ToString(); if (sWk.Trim().Length > 0) { //MM/DD 成型 string sMMdd = sWk.Substring(5, 5); dr["請求締日"] = sMMdd; } } return(dt); }