Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        /// <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));
        }