/// <summary> /// 仕入一覧ヘッダデータ取得 /// </summary> /// <param name="context"></param> /// <param name="company"></param> /// <param name="yearMonth"></param> /// <param name="tokList"></param> /// <returns></returns> private List <S07_SRIHD> getHeaderData(TRAC3Entities context, int company, int yearMonth, List <M01_TOK> tokList) { List <S07_SRIHD> shdList = new List <S07_SRIHD>(); foreach (M01_TOK tok in tokList) { DateTime paymentDate; // 入金日の算出 try { paymentDate = AppCommon.GetClosingDate(yearMonth / 100, yearMonth % 100, tok.S入金日1 ?? CommonConstants.DEFAULT_CLOSING_DAY, tok.Sサイト1 ?? 0); } catch { // 基本的にあり得ないがこの場合は当月末日を指定 paymentDate = new DateTime(yearMonth / 100, yearMonth % 100, DateTime.DaysInMonth(yearMonth / 100, yearMonth % 100)); } int paymentDay = paymentDate.Year * 10000 + paymentDate.Month * 100 + paymentDate.Day; List <S07_SRIHD> wk = context.S07_SRIHD.Where(w => w.自社コード == company && w.支払年月 == yearMonth && w.支払先コード == tok.取引先コード && w.支払先枝番 == tok.枝番 && w.支払日 == paymentDay && (w.当月支払額 != 0 || w.前月残高 != 0 || w.支払額 != 0)).ToList(); shdList = shdList.Concat(wk).ToList(); } return(shdList); }
/// <summary> /// 調整後の売上集計情報を取得する /// </summary> /// <param name="context"></param> /// <param name="year"></param> /// <param name="compCd"></param> /// <returns></returns> private Dictionary <string, long?> getSalesAjustData(TRAC3Entities context, int year, int compCd) { Dictionary <string, long?> resultDic = new Dictionary <string, long?>(); // 取引先情報取得 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 ajustData = context.T02_URHD_HAN .Where(w => w.削除日時 == null && w.販社コード == compCd && w.売上日 >= calcStartDate && w.売上日 <= calcEndDate) .Join(context.T02_URDTL_HAN.Where(w => w.削除日時 == null), x => x.伝票番号, y => y.伝票番号, (a, b) => new { UHD = a, UDTL = b }); long?ajustPrice = ajustData.Sum(m => m.UHD.売上区分 < (int)CommonConstants.売上区分.通常売上返品 ? m.UDTL.調整金額 : m.UDTL.調整金額 * -1) ?? 0; // 計算結果を格納 resultDic.Add(targetMonth.ToString("yyyy/MM"), ajustPrice); // 次データの為に各値をカウントアップ targetMonth = targetMonth.AddMonths(1); } return(resultDic); }
/// <summary> /// 集計処理 /// </summary> /// <param name="context"></param> /// <param name="company">自社コード</param> /// <param name="yearMonth">請求年月</param> /// <param name="code">取引先コード</param> /// <param name="eda">枝番</param> /// <param name="userId">userId</param> public void getAggregateData(TRAC3Entities context, int company, int yearMonth, int code, int eda, int userId) { DateTime targetStDate = new DateTime(yearMonth / 100, yearMonth % 100, 1); DateTime targetEdDate = new DateTime(yearMonth / 100, yearMonth % 100, 1).AddMonths(1).AddDays(-1); // 対象の取引先が「自社」の場合は販社仕入を参照する為、ロジックを分岐する var tokdata = context.M01_TOK.Where(w => w.削除日時 == null && w.取引先コード == code && w.枝番 == eda) .GroupJoin(context.M70_JIS.Where(w => w.削除日時 == null && 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.DefaultIfEmpty(), (a, b) => new { TOK = a.x, JIS = b }) .FirstOrDefault(); DateTime paymentDate; // 入金日の算出 try { paymentDate = AppCommon.GetClosingDate(targetStDate.Year, targetStDate.Month, tokdata.TOK.S入金日1 ?? CommonConstants.DEFAULT_CLOSING_DAY, tokdata.TOK.Sサイト1 ?? 0); } catch { // 基本的にあり得ないがこの場合は当月末日を指定 paymentDate = new DateTime(targetStDate.Year, targetStDate.Month, DateTime.DaysInMonth(targetStDate.Year, targetStDate.Month)); } if (tokdata.JIS != null && tokdata.JIS.自社区分 == CommonConstants.自社区分.自社.GetHashCode()) { // ヘッダ情報の登録 setHeaderInfoHan(context, company, yearMonth, tokdata.JIS.自社コード, targetStDate, targetEdDate, code, eda, paymentDate, userId); } else { // ヘッダ情報の登録 setHeaderInfo(context, company, yearMonth, code, eda, targetStDate, targetEdDate, paymentDate, userId); } }
/// <summary> /// 対象の出金情報を取得する /// </summary> /// <param name="condition"></param> /// <returns></returns> private List <T12_PAY_Data> getPayData(int year, int month, List <S02_SHRHD_Data> hdList) { List <T12_PAY_Data> payList = new List <T12_PAY_Data>(); using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { foreach (var hdRow in hdList) { // -- 締日の範囲日付を算出 DateTime startDate = AppCommon.GetClosingDate(year, month, hdRow.支払締日, -1).AddDays(1); // No.306 Mod DateTime endDate = AppCommon.GetClosingDate(year, month, hdRow.支払締日, 0); //.AddDays(-1); var nykhd = context.T12_PAYHD .Where(w => w.削除日時 == null && w.出金元自社コード == hdRow.自社コード && w.得意先コード == hdRow.支払先コード && w.得意先枝番 == hdRow.支払先枝番 && w.出金日 >= startDate && w.出金日 <= endDate) .Join(context.T12_PAYDTL, x => x.伝票番号, y => y.伝票番号, (x, y) => new { PAYHD = x, PAYDTL = y }) .GroupBy(g => new { g.PAYHD.出金元自社コード, g.PAYHD.得意先コード, g.PAYHD.得意先枝番 }) .Select(s => new T12_PAY_Data { 自社コード = s.Key.出金元自社コード, 得意先コード = (int)s.Key.得意先コード, 得意先枝番 = (int)s.Key.得意先枝番, 出金額 = s.Sum(m => m.PAYDTL.金額) }); payList.AddRange(nykhd.ToList()); } return(payList); } }
/// <summary> /// 対象の入金(ヘッダ)情報を取得する /// </summary> /// <param name="condition"></param> /// <returns></returns> private List <T11_NYKN_Data> getNyukinData(int year, int month, List <S01_SEIHD_Data> hdList) { List <T11_NYKN_Data> nykList = new List <T11_NYKN_Data>(); using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { foreach (var hdRow in hdList) { // -- 締日の範囲日付を算出 DateTime startDate = AppCommon.GetClosingDate(year, month, hdRow.請求締日, -1).AddDays(1); // No.306 Mod DateTime endDate = AppCommon.GetClosingDate(year, month, hdRow.請求締日, 0); // No.306 Mod var nykhd = context.T11_NYKNHD .Where(w => w.削除日時 == null && w.入金先自社コード == hdRow.自社コード && w.得意先コード == hdRow.請求先コード && w.得意先枝番 == hdRow.請求先枝番 && w.入金日 >= startDate && w.入金日 <= endDate) .Join(context.T11_NYKNDTL, x => x.伝票番号, y => y.伝票番号, (x, y) => new { NYKNHD = x, NYKNDTL = y }) .GroupBy(g => new { g.NYKNHD.入金先自社コード, g.NYKNHD.得意先コード, g.NYKNHD.得意先枝番 }) .Select(s => new T11_NYKN_Data { 自社コード = s.Key.入金先自社コード, 得意先コード = (int)s.Key.得意先コード, 得意先枝番 = (int)s.Key.得意先枝番, 入金額 = s.Sum(m => m.NYKNDTL.金額) }); nykList.AddRange(nykhd.ToList()); } return(nykList); } }
/// <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="paramDic">パラメータDic</param> /// <param name="userId">ログインユーザID</param> public List <BSK05010_SearchMember> SetCalculate(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]); M73 zeiService = new M73(); 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; // 締日前日が集計最終日 // No.101-3 Mod Start DateTime priodEndDate = AppCommon.GetClosingDate(pYear, pMonth, hanData.TOK.T締日 ?? CommonConstants.DEFAULT_CLOSING_DAY).AddDays(-1); // No.101-3 Mod End // 最終日から12ヶ月遡って翌日を集計開始日とする DateTime priodStrDate = priodEndDate.AddMonths(-12).AddDays(1); //debugLog.WriteLine(string.Format("集計期間:{0}~{1}", priodStrDate.ToString("yyyy/MM/dd"), priodEndDate.ToString("yyyy/MM/dd"))); #region 販社明細の調整計算(単価・金額) // 対象期間内の販社売上明細を取得 var dtlList = context.T02_URDTL_HAN .Where(w => w.削除日時 == null && context.T02_URHD_HAN .Where(v => v.削除日時 == null && v.販社コード == compCd && v.売上日 >= priodStrDate && v.売上日 <= priodEndDate) .Select(s => s.伝票番号) .Contains(w.伝票番号)); foreach (var data in dtlList) { decimal calcRate = rate / 100m + 1; // 調整比率を調整額として反映 data.調整単価 = Math.Round(data.単価 * calcRate, 0); data.調整金額 = decimal.ToInt32(Math.Round((data.金額 ?? 0) * calcRate, 0)); //debugLog.WriteLine(string.Format("Rate:{0:#,0.##}", calcRate)); //debugLog.WriteLine(string.Format("単価:{0:#,0} ⇒ {1:#,0.##}", data.単価, data.調整単価)); //debugLog.WriteLine(string.Format("金額:{0:#,0} ⇒ {1:#,0.##}", data.金額, data.調整金額)); //debugLog.WriteLine("--------------------"); data.AcceptChanges(); } #endregion // 変更状態を確定 context.SaveChanges(); #region 販社ヘッダの調整計算(消費税) var hdList = context.T02_URHD_HAN .Where(w => w.削除日時 == null && w.販社コード == compCd && w.売上日 >= priodStrDate && w.売上日 <= priodEndDate); foreach (var data in hdList) { int sumTax = 0; foreach (var row in context.T02_URDTL_HAN.Where(w => w.削除日時 == null && w.伝票番号 == data.伝票番号)) { // No.101-3 Mod Start sumTax += decimal.ToInt32( zeiService.getCalculatTax(hanData.TOK.T税区分ID, data.売上日, row.品番コード, row.調整金額 ?? 0, row.数量, hanData.TOK.T消費税区分)); // No.272 Mod // No.101-3 Mod End } data.調整消費税 = sumTax; data.調整比率 = rate; data.AcceptChanges(); } #endregion // 変更状態を確定 context.SaveChanges(); // トランザクションコミット tran.Commit(); } catch (Exception ex) { // トランザクションロールバック tran.Rollback(); throw ex; } }// end transaction } // データを再取得して返却 return(GetDataList(paramDic)); }
/// <summary> /// 売上明細問合せ検索をおこなう(販社) /// </summary> /// <param name="p自社コード"></param> /// <param name="p自社販社区分"></param> /// <param name="cond"> /// === 検索条件辞書 === /// 売上日From /// 売上日To /// 売上区分 /// 得意先コード /// 得意先枝番 /// </param> /// <returns></returns> public List <SearchDataMember> GetData_Hansha(int p自社コード, Dictionary <string, string> cond) { // 画面パラメータを展開 DateTime wkDt; int wkVal; DateTime?salesDateFrom = DateTime.TryParse(cond["売上日From"], out wkDt) ? wkDt : (DateTime?)null, salesDateTo = DateTime.TryParse(cond["売上日To"], out wkDt) ? wkDt : (DateTime?)null; int salesKbn = int.Parse(cond["売上区分"]); int?customerCode = int.TryParse(cond["得意先コード"], out wkVal) ? wkVal : (int?)null, customerEda = int.TryParse(cond["得意先枝番"], out wkVal) ? wkVal : (int?)null; string myProductCode = cond["自社品番"]; using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { try { // 売上区分(名称)データ取得 var salesKbnData = context.M99_COMBOLIST .Where(w => w.分類 == "随時" && w.機能 == "請求明細問合せ" && w.カテゴリ == "売上区分"); // (販社)売上データ var urHanData = context.M70_JIS .Where(w => w.削除日時 == null && w.取引先コード != null && w.枝番 != null && w.自社区分 == (int)CommonConstants.自社区分.販社) .Join(context.T02_URHD_HAN.Where(w => w.削除日時 == null), x => x.自社コード, y => y.販社コード, (x, y) => new { JIS = x, UHD_HAN = y }) .Join(context.T02_URDTL_HAN.Where(w => w.削除日時 == null), x => x.UHD_HAN.伝票番号, y => y.伝票番号, (x, y) => new { JIS = x.JIS, UHD = x.UHD_HAN, UDTL = y }) .Join(context.M09_HIN.Where(w => w.削除日時 == null), x => x.UDTL.品番コード, y => y.品番コード, (x, y) => new { JIS = x.JIS, UHD = x.UHD, UDTL = x.UDTL, HIN = y }); #region 検索条件による絞込み if (salesDateFrom != null) { urHanData = urHanData.Where(x => x.UHD.売上日 >= salesDateFrom); } if (salesDateTo != null) { urHanData = urHanData.Where(x => x.UHD.売上日 <= salesDateTo); } if (salesKbn > 0) { urHanData = urHanData.Where(w => w.UHD.売上区分 == salesKbn); } if (!string.IsNullOrEmpty(myProductCode)) { urHanData = urHanData.Where(w => w.HIN.自社品番 == myProductCode); } if (customerCode != null && customerEda != null) { urHanData = urHanData.Where(w => w.JIS.取引先コード == customerCode && w.JIS.枝番 == customerEda); } #endregion var resultList = urHanData .Join(salesKbnData, x => x.UHD.売上区分, y => y.コード, (x, y) => new { x.UHD, x.UDTL, x.JIS, x.HIN, KBN = y }) .GroupJoin(context.M01_TOK, x => new { code = (int)x.JIS.取引先コード, eda = (int)x.JIS.枝番 }, y => new { code = y.取引先コード, eda = y.枝番 }, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { a.x.UHD, a.x.UDTL, a.x.JIS, a.x.HIN, a.x.KBN, TOK = b }) .GroupJoin(context.M06_IRO, x => x.HIN.自社色, y => y.色コード, (x, y) => new { x, y }) .SelectMany(x => x.y.DefaultIfEmpty(), (e, f) => new { e.x.UHD, e.x.UDTL, e.x.JIS, e.x.HIN, e.x.KBN, e.x.TOK, IRO = f }) .OrderBy(o => o.UHD.販社コード) .ThenBy(t => t.JIS.枝番) .ThenBy(t => t.UHD.売上日) .ThenBy(t => t.UHD.伝票番号) .ThenBy(t => t.UDTL.行番号) .ToList() .Select(x => new SearchDataMember { 会社名コード = x.UHD.会社名コード, // No.227,228 Add 自社名 = x.JIS.自社名 ?? "", // No.227,228 Add 売上日 = x.UHD.売上日.ToShortDateString(), 請求日 = x.UHD.売上日.Day > x.TOK.T締日 ? AppCommon.GetClosingDate(x.UHD.売上日.Year, x.UHD.売上日.Month, x.TOK.T締日 ?? 31, 1).ToShortDateString() : AppCommon.GetClosingDate(x.UHD.売上日.Year, x.UHD.売上日.Month, x.TOK.T締日 ?? 31, 0).ToShortDateString(), 売上区分 = x.KBN.表示名, 伝票番号 = x.UHD.伝票番号.ToString(), 元伝票番号 = string.Empty, 行番号 = x.UDTL.行番号, 得意先コード = string.Format("{0:D4} - {1:D2}", x.JIS.取引先コード, x.JIS.枝番), // No.227,228 Add 得意先 = x.TOK != null ? x.TOK.略称名 : string.Empty, 品番コード = x.UDTL.品番コード, 自社品番 = x.HIN != null ? x.HIN.自社品番 : string.Empty, 自社品名 = !string.IsNullOrEmpty(x.UDTL.自社品名) ? x.UDTL.自社品名 : x.HIN != null ? x.HIN.自社品名 : string.Empty, // No.390 Mod 自社色 = x.IRO != null ? x.IRO.色名称 : string.Empty, 賞味期限 = x.UDTL.賞味期限 == null ? null : x.UDTL.賞味期限.Value.ToShortDateString(), 単価 = x.UDTL.単価, 数量 = x.UDTL.数量, 単位 = x.UDTL.単位, 金額 = x.UDTL.金額 == null ? 0 : x.UHD.売上区分 < (int)CommonConstants.売上区分.通常売上返品 ? (int)x.UDTL.金額 : (int)x.UDTL.金額 * -1, 摘要 = x.UDTL.摘要, 受注番号 = x.UHD.受注番号.ToString(), 品伝票番号 = x.UHD.品伝票番号.ToString(), }) .ToList(); return(resultList); } catch (System.ArgumentException agex) { throw agex; } catch (Exception ex) { throw ex; } } }
/// <summary> /// 請求未処理得意先のデータを抽出 /// </summary> /// <param name="seikyuList"></param> /// <param name="paymentYearMonth"></param> /// <returns></returns> private List <PrintMenber> CreateMiseikyu(TRAC3Entities context, int myCompany, int paymentYearMonth, int?paymentDay, int?customerCode, int?customerEda) { List <PrintMenber> retList = new List <PrintMenber>(); List <M01_TOK> tokList = (from tok in context.M01_TOK from sei in context.S01_SEIHD.Where(c => c.請求先コード == tok.取引先コード && c.請求先枝番 == tok.枝番 && c.自社コード == tok.担当会社コード && c.入金日 / 100 == paymentYearMonth).DefaultIfEmpty() where tok.担当会社コード == myCompany && sei.請求先コード == null select tok).ToList(); #region 条件絞り込み // 締日が指定されている場合 No.414 Mod if (paymentDay != null) { tokList = tokList.Where(w => w.T入金日1 == paymentDay).ToList(); } // 取引先が指定されている場合 if (customerCode != null && customerEda != null) { tokList = tokList.Where(w => w.取引先コード == customerCode && w.枝番 == customerEda).ToList(); } if (customerCode != null && customerEda == null) { tokList = tokList.Where(w => w.取引先コード == customerCode).ToList(); } #endregion DateTime dt入金月 = new DateTime(paymentYearMonth / 100, paymentYearMonth % 100, 1); foreach (M01_TOK tok in tokList) { //得意先マスタから請求期間を割り出す。 int iSeikyuSite = tok.Tサイト1 != null ? (int)tok.Tサイト1 : -1; if (iSeikyuSite < 0) { continue; } if (tok.T締日 == null || tok.T入金日1 == null) { continue; } DateTime dt請求月 = dt入金月.AddMonths(-iSeikyuSite); int i入金日 = (int)tok.T入金日1 == 31 ? DateTime.DaysInMonth(dt入金月.Year, dt入金月.Month) : (int)tok.T入金日1; int i締日 = (int)tok.T締日 == 31 ? DateTime.DaysInMonth(dt請求月.Year, dt請求月.Month) : (int)tok.T締日; if (i締日 == 0) { i締日 = i入金日 == 31 ? DateTime.DaysInMonth(dt請求月.Year, dt請求月.Month) : i入金日; } if (i入金日 == 0) { i入金日 = i締日 == 31 ? DateTime.DaysInMonth(dt入金月.Year, dt入金月.Month) : i締日; } if (i締日 == 0 || i入金日 == 0) { continue; } try { DateTime dt入金日 = new DateTime(dt入金月.Year, dt入金月.Month, i入金日); DateTime dt請求To = new DateTime(dt請求月.Year, dt請求月.Month, i締日); DateTime dt請求From = (int)tok.T締日 == 31 ? (new DateTime(dt請求月.Year, dt請求月.Month, 1)) : (dt請求To.AddMonths(-1).AddDays(1)); //割り出した請求期間の売上の合計を計算する var uriage = context.T02_URHD.Where(c => c.得意先コード == tok.取引先コード && c.得意先枝番 == tok.枝番 && c.売上日 >= dt請求From && c.売上日 <= dt請求To) .GroupJoin(context.M70_JIS.Where(w => w.削除日時 == null), x => x.会社名コード, y => y.自社コード, (x, y) => new { x, y }) .SelectMany(z => z.y.DefaultIfEmpty(), (a, b) => new { URI = a.x, JIS = b }) .GroupBy(g => new { g.URI.会社名コード, g.JIS.自社名, // No.227,228 Add }) .ToList() .Select(s => new PrintMenber { 自社コード = s.Key.会社名コード, 自社名 = s.Key.自社名, 得意先コード = string.Format("{0:D4} - {1:D2}", tok.取引先コード, tok.枝番), 取引先コード = tok.取引先コード, 枝番 = tok.枝番, 得意先名 = tok.略称名, 締処理 = "未", 売上額 = (long)s.Sum(m => m.URI.小計), 消費税 = s.Sum(m => m.URI.消費税), 回収予定額 = (long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税), 請求年月 = Convert.ToDateTime(dt請求To).ToShortDateString(), // No.414 Mod 締日 = (int)tok.T締日, 現金・振込・小切手 = tok.Tサイト2 == null ? ((long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税)) : tok.T入金日2 == null ? ((long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税)) : // T請求区分:1(以上)の場合 // 請求条件金額の手形をxx枚発行し残金を現金とする tok.T請求区分 == (int)CommonConstants.請求・支払区分.ID01_以上 ? tok.T請求条件 > 0 ? ((long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税)) % tok.T請求条件 : 0 : // T請求区分:(以下)の場合 // 請求条件金額の手形を発行し、残金を現金とする tok.T請求条件 > 0 ? ((long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税)) - tok.T請求条件 > 0 ? ((long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税)) - tok.T請求条件 : (long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税) : // 手形請求条件金額に満たない場合、全額を現金に振り分ける (long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税), 手形 = tok.Tサイト2 == null ? 0 : tok.T入金日2 == null ? 0 : // T請求区分:1(以上)の場合 // 請求条件金額の手形をxx枚発行する tok.T請求区分 == (int)CommonConstants.請求・支払区分.ID01_以上 ? tok.T請求条件 > 0 ? (((long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税)) / tok.T請求条件) * tok.T請求条件 : ((long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税)) : // T請求区分:2(以下)の場合 // 請求条件金額の手形を発行する ((long)s.Sum(m => m.URI.小計) + s.Sum(m => m.URI.消費税)) - tok.T請求条件 >= 0 ? tok.T請求条件 : 0, 入金予定日 = dt入金日.ToString("yyyy/MM/dd"), 期日 = tok.Tサイト2 == null ? null : tok.T入金日2 == null ? null : AppCommon.GetClosingDate(paymentYearMonth / 100, paymentYearMonth % 100, (int)tok.T入金日2, (int)tok.Tサイト2).ToShortDateString() }).FirstOrDefault(); if (uriage == null) { continue; } retList.Add(uriage); } catch { throw; } } return(retList); }
/// <summary> /// 入金予定表の基本情報を取得する /// </summary> /// <param name="condition"> /// == 検索条件 == /// 自社コード /// 入金年月 /// 入金日 /// 全入金日 /// 得意先コード /// 得意先枝番 /// 作成区分 /// </param> /// <returns></returns> private List <PrintMenber> 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); try { using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { // 対象として取引区分:得意先、相殺、販社を対象とする List <int> kbnList = new List <int>() { (int)CommonConstants.取引区分.得意先, (int)CommonConstants.取引区分.相殺, (int)CommonConstants.取引区分.販社 }; // 集計得意先を取得 List <M01_TOK> tokList = context.M01_TOK.Where(w => w.削除日時 == null && kbnList.Contains(w.取引区分) && w.担当会社コード == myCompany).ToList(); // 請求情報取得 No.414 Mod var seiData = context.S01_SEIHD .Where(w => w.自社コード == myCompany && w.入金日 / 100 == paymentYearMonth).ToList(); #region 条件絞り込み // 締日が指定されている場合 No.414 Mod if (paymentDay != null) { int ival; DateTime closeDay = AppCommon.GetClosingDate(paymentYearMonth / 100, paymentYearMonth % 100, (int)paymentDay, 0); int nyuknDay = Int32.TryParse(closeDay.ToShortDateString().Replace("/", ""), out ival) ? ival : -1; // 請求ヘッダ.入金日に一致するデータを取得 seiData = seiData.Where(w => w.入金日 == nyuknDay).ToList(); } // 取引先が指定されている場合 if (customerCode != null && customerEda != null) { tokList = tokList.Where(w => w.取引先コード == customerCode && w.枝番 == customerEda).ToList(); } if (customerCode != null && customerEda == null) { tokList = tokList.Where(w => w.取引先コード == customerCode).ToList(); } #endregion tokList = tokList.OrderBy(o => o.取引先コード).ThenBy(t => t.枝番).ToList(); #region 集計処理 // 得意先毎に集計を実施 List <PrintMenber> resultList = new List <PrintMenber>(); foreach (M01_TOK tok in tokList) { var resultData = seiData.Where(w => w.請求先コード == tok.取引先コード && w.請求先枝番 == tok.枝番) .GroupJoin(context.M70_JIS.Where(w => w.削除日時 == null), x => x.自社コード, y => y.自社コード, (x, y) => new { x, y }) .SelectMany(z => z.y.DefaultIfEmpty(), (a, b) => new { SHD = a.x, JIS = b }) .ToList() .Select(s => new PrintMenber { 自社コード = s.SHD.自社コード, 自社名 = s.JIS.自社名, 得意先コード = string.Format("{0:D4} - {1:D2}", tok.取引先コード, tok.枝番), 取引先コード = tok.取引先コード, 枝番 = tok.枝番, 得意先名 = tok.略称名, 締処理 = "済", 売上額 = s.SHD.売上額, 消費税 = s.SHD.消費税, 回収予定額 = s.SHD.売上額 + s.SHD.消費税, 請求年月 = s.SHD.集計最終日 != null? Convert.ToDateTime(s.SHD.集計最終日).ToShortDateString() : s.SHD.請求年月日.ToShortDateString(), // No.414 Mod 締日 = s.SHD.請求締日, 現金・振込・小切手 = tok.Tサイト2 == null ? s.SHD.売上額 + s.SHD.消費税 : tok.T入金日2 == null ? s.SHD.売上額 + s.SHD.消費税 : // T請求区分:1(以上)の場合 // 請求条件金額の手形をxx枚発行し残金を現金とする tok.T請求区分 == (int)CommonConstants.請求・支払区分.ID01_以上 ? //tok.T請求条件 > 0 ? // (s.SHD.売上額 + s.SHD.消費税) % tok.T請求条件 : // 0 : tok.T請求条件 - (s.SHD.売上額 + s.SHD.消費税) > 0 ? (s.SHD.売上額 + s.SHD.消費税) : 0 : // T請求区分:(以下)の場合 // 請求条件金額の手形を発行し、残金を現金とする tok.T請求条件 > 0 ? (s.SHD.売上額 + s.SHD.消費税) - tok.T請求条件 > 0 ? (s.SHD.売上額 + s.SHD.消費税) - tok.T請求条件 : s.SHD.売上額 + s.SHD.消費税 : // 手形請求条件金額に満たない場合、全額を現金に振り分ける s.SHD.売上額 + s.SHD.消費税, 手形 = tok.Tサイト2 == null ? 0 : tok.T入金日2 == null ? 0 : // T請求区分:1(以上)の場合 // 請求条件金額の手形をxx枚発行する tok.T請求区分 == (int)CommonConstants.請求・支払区分.ID01_以上 ? //tok.T請求条件 > 0 ? // ((s.SHD.売上額 + s.SHD.消費税) / tok.T請求条件) * tok.T請求条件 : // s.SHD.売上額 + s.SHD.消費税 : tok.T請求条件 - (s.SHD.売上額 + s.SHD.消費税) <= 0 ? s.SHD.売上額 + s.SHD.消費税 : 0: // T請求区分:2(以下)の場合 // 請求条件金額の手形を発行する s.SHD.売上額 + s.SHD.消費税 - tok.T請求条件 >= 0 ? tok.T請求条件 : 0, 入金予定日 = s.SHD.入金日.ToString().Insert(4, "/").Insert(7, "/"), 期日 = tok.Tサイト2 == null ? null : tok.T入金日2 == null ? null : AppCommon.GetClosingDate(s.SHD.請求年月 / 100, s.SHD.請求年月 % 100, (int)tok.T入金日2, (int)tok.Tサイト2).ToShortDateString() }); resultList.AddRange(resultData); } #endregion // 条件絞り込み // 入金予定ありのみ if (createType == 1 || createType == 3) { resultList = resultList.Where(w => w.回収予定額 != 0).ToList(); } //請求処理前の得意先データを作成 if (createType == 3) { List <PrintMenber> addMiSeikyuuList = CreateMiseikyu(context, myCompany, paymentYearMonth, paymentDay, customerCode, customerEda); //NULLチェック if (addMiSeikyuuList != null) { resultList.AddRange(addMiSeikyuuList); } } return(resultList .OrderBy(o => o.自社コード) .ThenBy(t => t.入金予定日) .ThenBy(t => t.請求年月) .ThenBy(t => t.得意先コード) .ToList()); } } catch (Exception ex) { throw ex; } }