Exemple #1
0
        /// <summary>
        /// 在庫情報の更新をおこなう
        /// </summary>
        /// <param name="context"></param>
        /// <param name="idohd">移動ヘッダデータ</param>
        /// <param name="dtlTbl">移動明細データテーブル</param>
        /// <param name="isSubtract">減算フラグ(True:減算,False:減算しない)</param>
        private void setS03_STOK_Update(TRAC3Entities context, DataRow hdTbl, DataTable dtlTbl, bool isSubtract)
        {
            T05_IDOHD idohd = convertDataRowToT05_IDOHD_Entity(hdTbl);

            foreach (DataRow row in dtlTbl.Rows)
            {
                T05_IDODTL dtlRow = convertDataRowToT05_IDODTL_Entity(row);

                if (dtlRow.品番コード <= 0)
                {
                    continue;
                }

                int souko = isSubtract ? (int)idohd.出荷元倉庫コード : (int)idohd.出荷先倉庫コード;

                #region 在庫数計算
                decimal stockQty        = 0;
                decimal oldstockQty     = 0;
                bool    isSamekigenFlg  = false; // 賞味期限同一フラグ
                bool    isSameSoukFlg   = false; // 倉庫同一フラグ
                bool    isSameSyohinFlg = false; // 商品同一フラグ

                if (hdTbl.RowState == DataRowState.Modified)
                {
                    isSameSoukFlg = isSubtract ? CheckSameValue(hdTbl, "出荷元倉庫コード") : CheckSameValue(hdTbl, "出荷先倉庫コード");
                }

                if (row.RowState == DataRowState.Added)
                {
                    // 数量分在庫数を加減算
                    stockQty = dtlRow.数量 * (isSubtract ? -1 : 1);
                }
                else if (row.RowState == DataRowState.Modified || (hdTbl.RowState == DataRowState.Modified && !isSameSoukFlg))
                {
                    // 明細を変更または前回と倉庫が異なる場合
                    isSamekigenFlg  = CheckSameValue(row, "賞味期限");
                    isSameSyohinFlg = CheckSameValue(row, "品番コード");

                    // 賞味期限、倉庫、商品が変更された場合、過去在庫を取得
                    if (!isSamekigenFlg || !isSameSoukFlg || !isSameSyohinFlg)
                    {
                        //  減算フラグ(True:減算)の場合:旧賞味期限の在庫を加算、新賞味期限の在庫を減算する
                        //  減算フラグ(True:False)の場合:旧賞味期限の在庫を減算、新賞味期限の在庫を加算する

                        // 旧賞味期限の在庫数
                        oldstockQty = ParseNumeric <decimal>(row["数量", DataRowVersion.Original]) * (isSubtract ? 1 : -1);
                        // 新賞味期限の在庫数
                        stockQty = dtlRow.数量 * (isSubtract ? -1 : 1);
                    }
                    else
                    {
                        // 数量が変更された場合
                        decimal orgQty = ParseNumeric <decimal>(row["数量", DataRowVersion.Original]);
                        stockQty = (dtlRow.数量 - orgQty) * (isSubtract ? -1 : 1);
                    }
                }
                else
                {
                    // 明細対象なし(DataRowState.Unchanged)
                    continue;
                }
                #endregion

                // 賞味期限、倉庫、商品が変更された場合
                if ((row.RowState == DataRowState.Modified && (!isSamekigenFlg || !isSameSoukFlg)) || (hdTbl.RowState == DataRowState.Modified && !isSameSyohinFlg))
                {
                    DateTime dt;
                    S03_STOK oldStok = new S03_STOK();
                    oldStok.庫コード  = isSubtract ? int.Parse(hdTbl["出荷元倉庫コード", DataRowVersion.Original].ToString()) : int.Parse(hdTbl["出荷先倉庫コード", DataRowVersion.Original].ToString());
                    oldStok.品番コード = int.Parse(row["品番コード", DataRowVersion.Original].ToString());
                    oldStok.賞味期限  = row["賞味期限", DataRowVersion.Original] == DBNull.Value ? AppCommon.DateTimeToDate(null, DateTime.MaxValue) :
                                    DateTime.TryParse(row["賞味期限", DataRowVersion.Original].ToString(), out dt) ? dt : AppCommon.DateTimeToDate(null, DateTime.MaxValue);
                    oldStok.在庫数 = oldstockQty;

                    // 旧賞味期限の在庫を更新
                    S03Service.S03_STOK_Update(oldStok);
                }

                // 対象データ設定
                S03_STOK stok = new S03_STOK();
                stok.庫コード  = souko;
                stok.品番コード = dtlRow.品番コード;
                stok.賞味期限  = AppCommon.DateTimeToDate(dtlRow.賞味期限, DateTime.MaxValue);
                stok.在庫数   = stockQty;

                // 新賞味期限の在庫を更新
                S03Service.S03_STOK_Update(stok);

                // 変更状態を確定
                context.SaveChanges();
            }
        }
Exemple #2
0
        public List <SRY19010_Member> SRY19010_GetDataHinList(string s車輌From, string s車輌To, int?[] i車輌List, int p年月, int p前月, int p前年, int i表示順序, string s車輌List)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                string s作成年月;
                s作成年月 = p年月.ToString().Substring(0, 4) + "年" + p年月.ToString().Substring(4, 2) + "月度";


                List <SRY19010_Member> retList = new List <SRY19010_Member>();
                context.Connection.Open();
                try
                {
                    string 車輌ピックアップ指定 = string.Empty;

                    var ZENGETU = (from s14c in context.S14_CAR
                                   where s14c.集計年月 == p前月
                                   select new SRY19010g_Member
                    {
                        車輌Key = s14c.車輌KEY,
                        燃費 = s14c.燃料L == 0 ? 0 : Math.Round((decimal)((s14c.走行KM / s14c.燃料L)), 2),
                        走行KM = s14c.走行KM,
                        燃料L = s14c.燃料L,
                    }).AsQueryable();

                    var ZENNEN = (from s14c in context.S14_CAR
                                  where s14c.集計年月 == p前年
                                  select new SRY19010g_Member
                    {
                        車輌Key = s14c.車輌KEY,
                        燃費 = s14c.燃料L == 0 ? 0 : Math.Round((decimal)((s14c.走行KM / s14c.燃料L)), 2),
                        走行KM = s14c.走行KM,
                        燃料L = s14c.燃料L,
                    }).AsQueryable();

                    var query = (from m05 in context.M05_CAR.Where(c => c.廃車区分 == 0 && c.削除日付 == null)
                                 from m04 in context.M04_DRV.Where(c => c.削除日付 == null && c.乗務員KEY == m05.乗務員KEY).DefaultIfEmpty()
                                 from s14 in context.S14_CAR.Where(c => c.集計年月 == p年月 && c.車輌KEY == m05.車輌KEY)
                                 from s14sb in context.S14_CARSB.Where(c => c.集計年月 == p年月 && c.車輌KEY == m05.車輌KEY && c.経費項目ID == 401).DefaultIfEmpty()
                                 from zengetu in ZENGETU.Where(c => c.車輌Key == m05.車輌KEY).DefaultIfEmpty()
                                 from zennen in ZENNEN.Where(c => c.車輌Key == m05.車輌KEY).DefaultIfEmpty()
                                 select new SRY19010_Member
                    {
                        車輌ID = m05.車輌KEY,
                        車輌番号 = m05.車輌番号,
                        乗務員名 = m04.乗務員名,
                        日数 = s14.稼動日数 == null ? 0 : s14.稼動日数,
                        運賃 = s14.運送収入 == null ? 0 : s14.運送収入,
                        壱日当り = s14.稼動日数 == null ? 0 : s14.稼動日数 == 0 ? 0 : Math.Round((decimal)((s14.運送収入 / s14.稼動日数)), 0),
                        輸送屯数 = s14.輸送屯数 == null ? 0 : s14.輸送屯数,
                        走行KM = s14.走行KM == null ? 0 : s14.走行KM,
                        実車KM = s14.実車KM == null ? 0 : s14.実車KM,
                        燃料L = s14.燃料L == null ? 0 : s14.燃料L,
                        燃費 = s14.燃料L == null ? 0 : s14.燃料L == 0 ? 0 : Math.Round((decimal)((s14.走行KM / s14.燃料L)), 2),
                        燃料代 = s14sb.金額 == null ? 0 : s14sb.金額,

                        前月燃費 = zengetu.燃費 == null ? 0 : zengetu.燃費,
                        前月対比 = zengetu.燃費 == null ? 0 : zengetu.燃費 == 0 ? 0 : s14.燃料L == 0 ? 0 : Math.Round((decimal)((s14.走行KM / s14.燃料L) / zengetu.燃費), 0),
                        前月燃費差益 = zengetu.燃費 == null ? 0 : zengetu.燃費 == 0 ? 0 : s14.燃料L == 0 ? 0 : Math.Round((decimal)((s14sb.金額 / s14.燃料L) * (s14.走行KM / zengetu.燃費)), 0),
                        前月走行KM = zengetu.走行KM == null ? 0 : zengetu.走行KM,
                        前月燃料L = zengetu.燃料L == null ? 0 : zengetu.燃料L,

                        前年燃費 = zennen.燃費 == null ? 0 : zennen.燃費,
                        前年対比 = zennen.燃費 == null ? 0 : zennen.燃費 == 0 ? 0 : s14.燃料L == 0 ? 0 : Math.Round((decimal)((s14.走行KM / s14.燃料L) / zennen.燃費), 0),
                        前年燃費差益 = zennen.燃費 == null ? 0 : zennen.燃費 == 0 ? 0 : s14.燃料L == 0 ? 0 : Math.Round((decimal)((s14sb.金額 / s14.燃料L) * (s14.走行KM / zennen.燃費)), 0),
                        前年走行KM = zennen.走行KM == null ? 0 : zennen.走行KM,
                        前年燃料L = zennen.燃料L == null ? 0 : zennen.燃料L,

                        コードFrom = s車輌From,
                        コードTo = s車輌To,
                        車輌ピックアップ = s車輌List,
                        作成年月 = s作成年月,
                    }).AsQueryable();



                    //***検索条件***//
                    if (!(string.IsNullOrEmpty(s車輌From + s車輌To) && i車輌List.Length == 0))
                    {
                        //From & ToがNULLだった場合
                        if (string.IsNullOrEmpty(s車輌From + s車輌To))
                        {
                            query = query.Where(c => c.車輌ID >= int.MaxValue);
                        }

                        //車輌From処理 Min値
                        if (!string.IsNullOrEmpty(s車輌From))
                        {
                            int i車輌From = AppCommon.IntParse(s車輌From);
                            query = query.Where(c => c.車輌ID >= i車輌From);
                        }

                        //車輌To処理 Max値
                        if (!string.IsNullOrEmpty(s車輌To))
                        {
                            int i車輌TO = AppCommon.IntParse(s車輌To);
                            query = query.Where(c => c.車輌ID <= i車輌TO);
                        }

                        if (i車輌List.Length > 0)
                        {
                            var intCause = i車輌List;
                            query = query.Union(from m05 in context.M05_CAR.Where(c => c.廃車区分 == 0 && c.削除日付 == null)
                                                from m04 in context.M04_DRV.Where(c => c.削除日付 == null && c.乗務員KEY == m05.乗務員KEY).DefaultIfEmpty()
                                                from s14 in context.S14_CAR.Where(c => c.集計年月 == p年月 && c.車輌KEY == m05.車輌KEY)
                                                from s14sb in context.S14_CARSB.Where(c => c.集計年月 == p年月 && c.車輌KEY == m05.車輌KEY && c.経費項目ID == 401).DefaultIfEmpty()
                                                from zengetu in ZENGETU.Where(c => c.車輌Key == m05.車輌KEY).DefaultIfEmpty()
                                                from zennen in ZENNEN.Where(c => c.車輌Key == m05.車輌KEY).DefaultIfEmpty()
                                                where intCause.Contains(m05.車輌ID)
                                                select new SRY19010_Member
                            {
                                車輌ID = m05.車輌KEY,
                                車輌番号 = m05.車輌番号,
                                乗務員名 = m04.乗務員名,
                                日数   = s14.稼動日数 == null ? 0 : s14.稼動日数,
                                運賃   = s14.運送収入 == null ? 0 : s14.運送収入,
                                壱日当り = s14.稼動日数 == null ? 0 : s14.稼動日数 == 0 ? 0 : Math.Round((decimal)((s14.運送収入 / s14.稼動日数)), 0),
                                輸送屯数 = s14.輸送屯数 == null ? 0 : s14.輸送屯数,
                                走行KM = s14.走行KM == null ? 0 : s14.走行KM,
                                実車KM = s14.実車KM == null ? 0 : s14.実車KM,
                                燃料L  = s14.燃料L == null ? 0 : s14.燃料L,
                                燃費   = s14.燃料L == null ? 0 : s14.燃料L == 0 ? 0 : Math.Round((decimal)((s14.走行KM / s14.燃料L)), 2),
                                燃料代  = s14sb.金額 == null ? 0 : s14sb.金額,

                                前月燃費   = zengetu.燃費 == null ? 0 : zengetu.燃費,
                                前月対比   = zengetu.燃費 == null ? 0 : zengetu.燃費 == 0 ? 0 : s14.燃料L == 0 ? 0 : Math.Round((decimal)((s14.走行KM / s14.燃料L) / zengetu.燃費), 0),
                                前月燃費差益 = zengetu.燃費 == null ? 0 : zengetu.燃費 == 0 ? 0 : s14.燃料L == 0 ? 0 : Math.Round((decimal)((s14sb.金額 / s14.燃料L) * (s14.走行KM / zengetu.燃費)), 0),
                                前月走行KM = zengetu.走行KM == null ? 0 : zengetu.走行KM,
                                前月燃料L  = zengetu.燃料L == null ? 0 : zengetu.燃料L,

                                前年燃費   = zennen.燃費 == null ? 0 : zennen.燃費,
                                前年対比   = zennen.燃費 == null ? 0 : zennen.燃費 == 0 ? 0 : s14.燃料L == 0 ? 0 : Math.Round((decimal)((s14.走行KM / s14.燃料L) / zennen.燃費), 0),
                                前年燃費差益 = zennen.燃費 == null ? 0 : zennen.燃費 == 0 ? 0 : s14.燃料L == 0 ? 0 : Math.Round((decimal)((s14sb.金額 / s14.燃料L) * (s14.走行KM / zennen.燃費)), 0),
                                前年走行KM = zennen.走行KM == null ? 0 : zennen.走行KM,
                                前年燃料L  = zennen.燃料L == null ? 0 : zennen.燃料L,

                                コードFrom    = s車輌From,
                                コードTo      = s車輌To,
                                車輌ピックアップ = s車輌List,
                                作成年月       = s作成年月,
                            });
                        }
                    }
                    else
                    {
                        //車輌FromがNullだった場合
                        if (string.IsNullOrEmpty(s車輌From))
                        {
                            query = query.Where(c => c.車輌ID >= int.MinValue);
                        }
                        //車輌ToがNullだった場合
                        if (string.IsNullOrEmpty(s車輌To))
                        {
                            query = query.Where(c => c.車輌ID <= int.MaxValue);
                        }
                    }

                    //乗務員指定の表示
                    if (i車輌List.Length > 0)
                    {
                        for (int i = 0; i < query.Count(); i++)
                        {
                            車輌ピックアップ指定 = 車輌ピックアップ指定 + i車輌List[i].ToString();

                            if (i < i車輌List.Length)
                            {
                                if (i == i車輌List.Length - 1)
                                {
                                    break;
                                }

                                車輌ピックアップ指定 = 車輌ピックアップ指定 + ",";
                            }

                            if (i車輌List.Length == 1)
                            {
                                break;
                            }
                        }
                    }

                    //表示順序変更
                    switch (i表示順序)
                    {
                    case 0:
                        //車輌番号昇順
                        query = query.OrderBy(c => c.車輌ID);
                        break;

                    case 1:
                        query = query.OrderByDescending(c => c.燃料L);
                        break;

                    case 2:
                        //運送収入降順
                        query = query.OrderByDescending(c => c.燃費);
                        break;
                    }

                    query = query.Where(c => c.日数 != 0 || c.運賃 != 0 || c.壱日当り != 0 || c.輸送屯数 != 0 || c.走行KM != 0 || c.実車KM != 0 || c.燃料L != 0 || c.燃費 != 0 || c.燃料代 != 0);

                    retList = query.ToList();
                    return(retList);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 在庫参照データを取得する
        /// </summary>
        /// <param name="stockpileCode"></param>
        /// <param name="paramDic"></param>
        /// <returns></returns>
        public List <Search_S03_STOK> GetData(int stockpileCode, Dictionary <string, string> paramDic)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                DateTime maxDate = AppCommon.GetMaxDate();

                var result =
                    context.S03_STOK
                    .Where(w => w.削除日時 == null && w.庫コード == stockpileCode)
                    .Join(context.V_M09_HIN,
                          x => x.品番コード,
                          y => y.品番コード,
                          (x, y) => new { STOK = x, HIN = y })
                    .ToList()
                    .Select(x => new Search_S03_STOK
                {
                    品番コード = x.STOK.品番コード,
                    自社品番  = x.HIN.自社品番 ?? string.Empty,
                    自社品名  = x.HIN.自社品名 ?? string.Empty,
                    自社色名  = x.HIN.自社色名 ?? string.Empty,
                    賞味期限  = x.STOK.賞味期限 == maxDate ? (DateTime?)null : x.STOK.賞味期限,
                    在庫数   = x.STOK.在庫数,
                    ブランド名 = x.HIN.ブランド名 ?? string.Empty,
                    シリーズ名 = x.HIN.シリーズ名 ?? string.Empty,
                    品群名   = x.HIN.品群名 ?? string.Empty
                });

                #region 画面入力条件適用

                string productCode = paramDic["品番"],
                       productName = paramDic["品名"],
                       colorName   = paramDic["色名"],
                       brandName   = paramDic["ブランド"],
                       seriesName  = paramDic["シリーズ"],
                       hingunName  = paramDic["品群"];

                if (!string.IsNullOrEmpty(productCode))
                {
                    result = result.Where(x => x.自社品番.Contains(productCode));
                }

                if (!string.IsNullOrEmpty(productName))
                {
                    result = result.Where(x => x.自社品名.Contains(productName));
                }

                if (!string.IsNullOrEmpty(colorName))
                {
                    result = result.Where(x => x.自社色名.Contains(colorName));
                }

                if (!string.IsNullOrEmpty(brandName))
                {
                    result = result.Where(x => x.ブランド名.Contains(brandName));
                }

                if (!string.IsNullOrEmpty(seriesName))
                {
                    result = result.Where(x => x.シリーズ名.Contains(seriesName));
                }

                if (!string.IsNullOrEmpty(hingunName))
                {
                    result = result.Where(x => x.品群名.Contains(hingunName));
                }

                #endregion


                return(result.ToList());
            }
        }
Exemple #4
0
        /// <summary>
        /// 移動入力情報を削除する
        /// </summary>
        /// <param name="ds">
        /// 移動データセット
        /// [0:T05_IDOHD、1:T05_IDODTL]
        /// </param>
        /// <param name="userId">ログインユーザID</param>
        /// <returns></returns>
        public void 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))
                {
                    T05Service = new T05(context, userId);
                    S03Service = new S03(context, userId);
                    S04Service = new S04(context, userId, S04.機能ID.振替入力);

                    int number = 0;
                    if (int.TryParse(slipNumber, out number))
                    {
                        try
                        {
                            var idohd =
                                context.T05_IDOHD
                                .Where(x => x.削除日時 == null &&
                                       x.伝票番号 == number)
                                .FirstOrDefault();

                            var idodtl =
                                context.T05_IDODTL
                                .Where(x => x.削除日時 == null &&
                                       x.伝票番号 == number)
                                .ToList();

                            // 伝票データが存在しない場合は処理しない。
                            if (idodtl == null || idodtl.Count == 0)
                            {
                                return;
                            }

                            // 1>> ヘッダ情報削除
                            T05Service.T05_IDOHD_Delete(number);

                            // 2>> 明細情報削除
                            T05Service.T05_IDODTL_Delete(number);

                            // 3>> 在庫情報削除
                            #region 在庫調整

                            foreach (T05_IDODTL row in idodtl)
                            {
                                int souko = row.行番号 == 2 ? (int)idohd.出荷元倉庫コード : (int)idohd.出荷先倉庫コード;

                                // 対象データ設定
                                S03_STOK stok = new S03_STOK();
                                stok.庫コード  = souko;
                                stok.品番コード = row.品番コード;
                                stok.賞味期限  = AppCommon.DateTimeToDate(row.賞味期限, DateTime.MaxValue);
                                stok.在庫数   = row.行番号 == 2 ? row.数量 : row.数量 * (-1);

                                // 旧賞味期限の在庫を更新
                                S03Service.S03_STOK_Update(stok);

                                // 変更状態を確定
                                context.SaveChanges();
                            }

                            #endregion

                            // 4>> 入出庫データの物理削除
                            S04Service.PhysicalDeletionProductHistory(context, number, (int)S04.機能ID.振替入力);

                            // 変更状態を確定
                            context.SaveChanges();

                            tran.Commit();
                        }
                        catch (Exception ex)
                        {
                            tran.Rollback();
                            throw ex;
                        }
                    }
                    else
                    {
                        throw new KeyNotFoundException("伝票番号が正しくありません");
                    }
                }
            }
        }
Exemple #5
0
        public List <SHR13010_Member> SHR13010_GetDataHinList(string s取引先From, string s取引先To, int?[] i取引先List, int i作成年, int i作成月, DateTime d集計月, string s作成年月度, int i作成区分, int i取引区分)
        {
            string 取引先指定ピックアップ = string.Empty;

            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                List <SHR13010_Member> retList = new List <SHR13010_Member>();
                context.Connection.Open();

                //売上データ【全件抽出】
                var query = (from m01 in context.M01_TOK.Where(c => c.削除日付 == null && c.親子区分ID != 3)
                             join s01 in context.S01_TOKS.Where(c => c.回数 == 1) on m01.得意先KEY equals s01.得意先KEY into Group
                             from s01Group in Group
                             group new { s01Group, m01 } by new { m01.得意先ID, m01.略称名, m01.Tサイト日, m01.T集金日, s01Group.集計年月 } into grGroup
                             select new SHR13010_Company_Sales
                {
                    コード = grGroup.Key.得意先ID,
                    取引先名 = grGroup.Key.略称名,
                    サイト = grGroup.Key.Tサイト日,
                    集計日付 = grGroup.Key.集計年月,
                    集金日 = grGroup.Key.T集金日,
                    通行料 = grGroup.Sum(c => c.s01Group.締日通行料),
                    消費税 = grGroup.Sum(c => c.s01Group.締日消費税),
                    売上金額 = grGroup.Sum(c => c.s01Group.締日売上金額),
                    売上金額計 = grGroup.Sum(c => c.s01Group.締日売上金額 + c.s01Group.締日消費税 + c.s01Group.締日通行料),
                }).ToList();

                //支払データ【全件抽出】
                var query2 = (from m01 in context.M01_TOK.Where(c => c.削除日付 == null && c.親子区分ID != 3)
                              join s02 in context.S02_YOSS.Where(c => c.回数 == 1) on m01.得意先KEY equals s02.支払先KEY into Group
                              from s02Group in Group
                              group new { m01, s02Group } by new { m01.得意先ID, m01.略称名, m01.Sサイト日, m01.S集金日, s02Group.集計年月 } into grGroup
                              select new SHR13010_Company_Payment
                {
                    コードs = grGroup.Key.得意先ID,
                    取引先名s = grGroup.Key.略称名,
                    サイトs = grGroup.Key.Sサイト日,
                    集計日付s = grGroup.Key.集計年月,
                    集金日s = grGroup.Key.S集金日,
                    支払通行料 = grGroup.Sum(c => c.s02Group.締日通行料),
                    支払消費税 = grGroup.Sum(c => c.s02Group.締日消費税),
                    傭車金額 = grGroup.Sum(c => c.s02Group.締日売上金額),
                    傭車金額計 = grGroup.Sum(c => c.s02Group.締日売上金額 + c.s02Group.締日消費税 + c.s02Group.締日通行料),
                }).ToList();

                //集計日付に会社ごとのサイト数を計算し【請求月】を算出
                for (int i = 0; i < query.Count; i++)
                {
                    if (Convert.ToDateTime((query[i].集計日付).ToString().Substring(0, 4) + "/" + query[i].集計日付.ToString().Substring(4, 2) + "/01").AddMonths(query[i].サイト) == d集計月)
                    {
                        //サイト数を計算したデータと入力されたデータが同じなら挿入
                        query[i].請求月 = Convert.ToDateTime((query[i].集計日付).ToString().Substring(0, 4) + "/" + query[i].集計日付.ToString().Substring(4, 2) + "/01").AddMonths(query[i].サイト);
                    }
                    else
                    {
                        //集計の必要のないデータには【1111年11月11日】を挿入
                        query[i].請求月 = Convert.ToDateTime("1111/11/11");
                    }
                }
                ;


                //集計日付に会社ごとのサイト数を計算し【支払月】を算出
                for (int i = 0; i < query2.Count; i++)
                {
                    if (Convert.ToDateTime((query2[i].集計日付s).ToString().Substring(0, 4) + "/" + query2[i].集計日付s.ToString().Substring(4, 2) + "/01").AddMonths(query2[i].サイトs) == d集計月)
                    {
                        //サイト数を計算したデータと入力されたデータが同じなら挿入
                        query2[i].支払月s = Convert.ToDateTime((query2[i].集計日付s).ToString().Substring(0, 4) + "/" + query2[i].集計日付s.ToString().Substring(4, 2) + "/01").AddMonths(query2[i].サイトs);
                    }
                    else
                    {
                        //集計の必要のないデータには【1111年11月11日】を挿入
                        query2[i].支払月s = Convert.ToDateTime("1111/11/11");
                    }
                }
                ;

                //必要のないデータを変数化し【RemoveAll】で取り除く
                DateTime Value = Convert.ToDateTime("1111/11/11");
                query.RemoveAll(c => c.請求月 == Value);
                query2.RemoveAll(c => c.支払月s == Value);

                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                #region 売上と支払 両方ともデータがあるとき
                if (query.Count() != 0 && query2.Count() != 0)
                {
                    //2つのクエリの【和集合】を求める
                    var retquery = (from s01 in query select s01.コード).Union(
                        from s02 in query2 select s02.コードs).AsQueryable();

                    //【売上】と【支払】データを1つにまとめる
                    var join = (from ret in retquery
                                from m01 in context.M01_TOK.Where(c => c.削除日付 == null && c.親子区分ID != 3)
                                from q01 in query.Where(c => c.コード == m01.得意先ID).DefaultIfEmpty()
                                from q02 in query2.Where(c => c.コードs == m01.得意先ID).DefaultIfEmpty()
                                group new { m01, q01, q02 } by
                                new
                    {
                        m01.得意先ID,
                        m01.略称名,
                        m01.Tサイト日,
                        m01.Sサイト日,
                        m01.T集金日,
                        m01.S集金日,
                        m01.親子区分ID,
                        m01.取引区分,
                    } into grGroup
                                select new SHR13010_Member
                    {
                        コード = grGroup.Key.得意先ID == null ? 0 : grGroup.Key.得意先ID,
                        取引先名 = grGroup.Key.略称名 == null ? "" : grGroup.Key.略称名,
                        サイト = grGroup.Key.Tサイト日 == null ? 0 : grGroup.Key.Tサイト日,
                        サイトs = grGroup.Key.Sサイト日 == null ? 0 : grGroup.Key.Sサイト日,
                        集金日 = grGroup.Key.T集金日 == null ? 0 : grGroup.Key.T集金日,
                        S集金日 = grGroup.Key.S集金日 == null ? 0 : grGroup.Key.S集金日,
                        親子区分 = grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子" == null ? "" : grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子",
                        取引区分 = grGroup.Key.取引区分 == null ? 10 : grGroup.Key.取引区分,
                        作成年月度 = s作成年月度 == null ? "" : s作成年月度,
                        取引先指定 = s取引先From + "~" + s取引先To,
                        取引先ピックアップ = 取引先指定ピックアップ == "" ? "" : 取引先指定ピックアップ,
                    }).AsQueryable();



                    //<<<データの絞込み>>>
                    if (!(string.IsNullOrEmpty(s取引先From + s取引先To) && i取引先List.Length == 0))
                    {
                        if (string.IsNullOrEmpty(s取引先From + s取引先To))
                        {
                            join = join.Where(c => c.コード >= int.MaxValue);
                        }

                        if (!string.IsNullOrEmpty(s取引先From))
                        {
                            int i取引先From = AppCommon.IntParse(s取引先From);
                            join = join.Where(c => c.コード >= i取引先From);
                        }

                        if (!string.IsNullOrEmpty(s取引先To))
                        {
                            int i取引先To = AppCommon.IntParse(s取引先To);
                            join = join.Where(c => c.コード <= i取引先To);
                        }

                        if (i取引先List.Length > 0)
                        {
                            var intCouse = i取引先List;
                            join = join.Union(from ret in retquery
                                              from m01 in context.M01_TOK.Where(c => c.削除日付 == null && c.親子区分ID != 3)
                                              from q01 in query.Where(c => c.コード == m01.得意先ID).DefaultIfEmpty()
                                              from q02 in query2.Where(c => c.コードs == m01.得意先ID).DefaultIfEmpty()
                                              group new { m01, q01, q02 } by
                                              new
                            {
                                m01.得意先ID,
                                m01.略称名,
                                m01.Tサイト日,
                                m01.Sサイト日,
                                m01.T集金日,
                                m01.S集金日,
                                m01.親子区分ID,
                                m01.取引区分,
                            } into grGroup
                                              where intCouse.Contains(grGroup.Key.得意先ID)
                                              select new SHR13010_Member
                            {
                                コード         = grGroup.Key.得意先ID == null ? 0 : grGroup.Key.得意先ID,
                                取引先名        = grGroup.Key.略称名 == null ? "" : grGroup.Key.略称名,
                                サイト         = grGroup.Key.Tサイト日 == null ? 0 : grGroup.Key.Tサイト日,
                                サイトs        = grGroup.Key.Sサイト日 == null ? 0 : grGroup.Key.Sサイト日,
                                集金日         = grGroup.Key.T集金日 == null ? 0 : grGroup.Key.T集金日,
                                S集金日        = grGroup.Key.S集金日 == null ? 0 : grGroup.Key.S集金日,
                                親子区分        = grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子" == null ? "" : grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子",
                                取引区分        = grGroup.Key.取引区分 == null ? 10 : grGroup.Key.取引区分,
                                作成年月度       = s作成年月度 == null ? "" : s作成年月度,
                                取引先指定       = s取引先From + "~" + s取引先To,
                                取引先ピックアップ = 取引先指定ピックアップ == "" ? "" : 取引先指定ピックアップ,
                            }).OrderBy(c => c.コード).AsQueryable();

                            //取引先指定の表示
                            if (i取引先List.Length > 0)
                            {
                                for (int i = 0; i < query.Count(); i++)
                                {
                                    取引先指定ピックアップ = 取引先指定ピックアップ + i取引先List[i].ToString();

                                    if (i < i取引先List.Length)
                                    {
                                        if (i == i取引先List.Length - 1)
                                        {
                                            break;
                                        }

                                        取引先指定ピックアップ = 取引先指定ピックアップ + ",";
                                    }

                                    if (i取引先List.Length == 1)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(s取引先From))
                        {
                            join = join.Where(c => c.コード >= int.MinValue);
                        }

                        if (string.IsNullOrEmpty(s取引先To))
                        {
                            join = join.Where(c => c.コード <= int.MaxValue);
                        }
                    }

                    //【売上】・【支払】・【売上/支払】データをList化
                    List <SHR13010_Member>          LIST        = join.ToList();
                    List <SHR13010_Company_Sales>   SalesList   = query.ToList();
                    List <SHR13010_Company_Payment> PaymentList = query2.ToList();
                    List <SHR13010_Member>          queryLIST   = new List <SHR13010_Member>();

                    int?name = 0;
                    foreach (var data in LIST)
                    {
                        if (name != data.コード)
                        {
                            queryLIST.Add(data);
                        }
                        name = data.コード;
                    }

                    //売上と支払を1つにしたデータをLoop
                    for (int i = 0; i < queryLIST.Count(); i++)
                    {
                        //QueryListに当てはまる【売上】データがある場合、データ挿入
                        for (int x = 0; x < SalesList.Count(); x++)
                        {
                            if (queryLIST[i].コード == SalesList[x].コード)
                            {
                                queryLIST[i].請求月   = SalesList[x].集計日付;
                                queryLIST[i].通行料   = SalesList[x].通行料;
                                queryLIST[i].消費税   = SalesList[x].消費税;
                                queryLIST[i].売上金額  = SalesList[x].売上金額;
                                queryLIST[i].売上金額計 = SalesList[x].売上金額計;
                            }
                            else
                            {
                                continue;
                            }
                        }

                        //QueryListに当てはまる【支払】データがある場合、データ挿入
                        for (int y = 0; y < PaymentList.Count(); y++)
                        {
                            if (queryLIST[i].コード == PaymentList[y].コードs)
                            {
                                queryLIST[i].支払月   = PaymentList[y].集計日付s;
                                queryLIST[i].支払通行料 = PaymentList[y].支払通行料;
                                queryLIST[i].支払消費税 = PaymentList[y].支払消費税;
                                queryLIST[i].傭車金額  = PaymentList[y].傭車金額;
                                queryLIST[i].傭車金額計 = PaymentList[y].傭車金額計;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    //帳票の【売上額】と【支払額】を比較して額が多いほうの差分データを挿入
                    for (int i = 0; i < queryLIST.Count(); i++)
                    {
                        if (queryLIST[i].売上金額計 > queryLIST[i].傭車金額計)
                        {
                            queryLIST[i].売上 = queryLIST[i].売上金額計 - queryLIST[i].傭車金額計;
                        }
                        else if (queryLIST[i].売上金額計 < queryLIST[i].傭車金額計)
                        {
                            queryLIST[i].支払 = queryLIST[i].傭車金額計 - queryLIST[i].売上金額計;
                        }
                        else
                        {
                            continue;
                        }
                    }



                    //取引ありのみ表示
                    if (i作成区分 == 0)
                    {
                        queryLIST = queryLIST.Where(c => c.売上金額計 != 0 || c.傭車金額計 != 0).ToList();
                    }
                    //【全取引】の企業のみ
                    if (i取引区分 == 1)
                    {
                        queryLIST = queryLIST.Where(c => c.取引区分 == 0).ToList();
                    }

                    //親子区分【子】を非表示に
                    queryLIST = queryLIST.Where(c => c.親子区分 != "子").ToList();

                    //表示順序変更
                    queryLIST = queryLIST.OrderBy(c => c.コード).ToList();

                    return(queryLIST.ToList());
                }
                #endregion

                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                #region 売上データのみ
                else if (query.Count() != 0 && query2.Count() == 0)
                {
                    var retquery = (from s01 in query select s01.コード).Union(
                        from s02 in query2 select s02.コードs).Distinct().AsQueryable();

                    var join = (from ret in retquery
                                from m01 in context.M01_TOK.Where(c => c.削除日付 == null && c.親子区分ID != 3)
                                from q01 in query.Where(c => c.コード == m01.得意先ID).DefaultIfEmpty()
                                group new { m01, q01 } by
                                new
                    {
                        m01.得意先ID,
                        m01.略称名,
                        m01.Tサイト日,
                        m01.Sサイト日,
                        m01.T集金日,
                        m01.S集金日,
                        m01.親子区分ID,
                        m01.取引区分,
                    } into grGroup
                                select new SHR13010_Member
                    {
                        コード = grGroup.Key.得意先ID,
                        取引先名 = grGroup.Key.略称名,
                        サイト = grGroup.Key.Tサイト日,
                        サイトs = grGroup.Key.Sサイト日,
                        集金日 = grGroup.Key.T集金日,
                        S集金日 = grGroup.Key.T集金日,
                        請求月 = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.集計日付) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.集計日付),
                        支払月 = 0,
                        通行料 = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.通行料) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.通行料),
                        支払通行料 = 0,
                        消費税 = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.消費税) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.消費税),
                        支払消費税 = 0,
                        売上金額 = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.売上金額) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.売上金額),
                        傭車金額 = 0,
                        売上金額計 = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.売上金額計) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.売上金額計),
                        傭車金額計 = 0,
                        売上 = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.売上金額計) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.売上金額計),
                        支払 = 0,
                        親子区分 = grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子",
                        取引区分 = grGroup.Key.取引区分,
                        作成年月度 = s作成年月度,
                        取引先指定 = s取引先From + "~" + s取引先To,
                        取引先ピックアップ = 取引先指定ピックアップ == "" ? "" : 取引先指定ピックアップ,
                    }).AsQueryable();

                    //<<<データの絞込み>>>
                    if (!(string.IsNullOrEmpty(s取引先From + s取引先To) && i取引先List.Length == 0))
                    {
                        if (string.IsNullOrEmpty(s取引先From + s取引先To))
                        {
                            join = join.Where(c => c.コード >= int.MaxValue);
                        }

                        if (!string.IsNullOrEmpty(s取引先From))
                        {
                            int i取引先From = AppCommon.IntParse(s取引先From);
                            join = join.Where(c => c.コード >= i取引先From);
                        }

                        if (!string.IsNullOrEmpty(s取引先To))
                        {
                            int i取引先To = AppCommon.IntParse(s取引先To);
                            join = join.Where(c => c.コード <= i取引先To);
                        }

                        if (i取引先List.Length > 0)
                        {
                            var intCouse = i取引先List;
                            join = join.Union(from ret in retquery
                                              from m01 in context.M01_TOK.Where(c => c.削除日付 == null && c.親子区分ID != 3)
                                              from q01 in query.Where(c => c.コード == m01.得意先ID).DefaultIfEmpty()
                                              group new { m01, q01 } by
                                              new
                            {
                                m01.得意先ID,
                                m01.略称名,
                                m01.Tサイト日,
                                m01.Sサイト日,
                                m01.T集金日,
                                m01.S集金日,
                                m01.親子区分ID,
                                m01.取引区分,
                            } into grGroup
                                              where intCouse.Contains(grGroup.Key.得意先ID)
                                              select new SHR13010_Member
                            {
                                コード         = grGroup.Key.得意先ID,
                                取引先名        = grGroup.Key.略称名,
                                サイト         = grGroup.Key.Tサイト日,
                                サイトs        = grGroup.Key.Sサイト日,
                                集金日         = grGroup.Key.T集金日,
                                S集金日        = grGroup.Key.T集金日,
                                請求月         = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.集計日付) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.集計日付),
                                支払月         = 0,
                                通行料         = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.通行料) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.通行料),
                                支払通行料       = 0,
                                消費税         = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.消費税) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.消費税),
                                支払消費税       = 0,
                                売上金額        = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.売上金額) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.売上金額),
                                傭車金額        = 0,
                                売上金額計       = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.売上金額計) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.売上金額計),
                                傭車金額計       = 0,
                                売上          = query.Where(c => c.コード == grGroup.Key.得意先ID).Sum(c => c.売上金額計) == 0 ? 0 : query.Where(c => c.コード == grGroup.Key.得意先ID).Distinct().Sum(c => c.売上金額計),
                                支払          = 0,
                                親子区分        = grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子",
                                取引区分        = grGroup.Key.取引区分,
                                作成年月度       = s作成年月度,
                                取引先指定       = s取引先From + "~" + s取引先To,
                                取引先ピックアップ = 取引先指定ピックアップ == "" ? "" : 取引先指定ピックアップ,
                            });

                            //取引先指定の表示
                            if (i取引先List.Length > 0)
                            {
                                for (int i = 0; i < query.Count(); i++)
                                {
                                    取引先指定ピックアップ = 取引先指定ピックアップ + i取引先List[i].ToString();

                                    if (i < i取引先List.Length)
                                    {
                                        if (i == i取引先List.Length - 1)
                                        {
                                            break;
                                        }

                                        取引先指定ピックアップ = 取引先指定ピックアップ + ",";
                                    }

                                    if (i取引先List.Length == 1)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(s取引先From))
                        {
                            join = join.Where(c => c.コード >= int.MinValue);
                        }

                        if (string.IsNullOrEmpty(s取引先To))
                        {
                            join = join.Where(c => c.コード <= int.MaxValue);
                        }
                    }


                    //取引ありのみ表示
                    if (i作成区分 == 0)
                    {
                        join = join.Where(c => c.売上金額計 != 0 || c.傭車金額計 != 0).Distinct();
                    }

                    //【全取引】の企業のみ
                    if (i取引区分 == 1)
                    {
                        join = join.Where(c => c.取引区分 == 0).Distinct();
                    }

                    //親子区分【子】を非表示に
                    join = join.Where(c => c.親子区分 != "子");

                    //表示順序変更
                    join = join.OrderBy(c => c.コード);

                    return(join.ToList());
                }
                #endregion

                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                #region 支払データのみ

                else if (query.Count() == 0 && query2.Count() != 0)
                {
                    var retquery = (from s01 in query select s01.コード).Union(
                        from s02 in query2 select s02.コードs).AsQueryable();


                    var join = (from ret in retquery
                                from m01 in context.M01_TOK.Where(c => c.削除日付 == null && c.親子区分ID != 3)
                                from q02 in query2.Where(c => c.コードs == m01.得意先ID).DefaultIfEmpty()
                                group new { m01, q02 } by
                                new
                    {
                        m01.得意先ID,
                        m01.略称名,
                        m01.Tサイト日,
                        m01.Sサイト日,
                        m01.T集金日,
                        m01.S集金日,
                        m01.親子区分ID,
                        m01.取引区分,
                    } into grGroup
                                select new SHR13010_Member
                    {
                        コード = grGroup.Key.得意先ID,
                        取引先名 = grGroup.Key.略称名,
                        サイト = grGroup.Key.Tサイト日,
                        サイトs = grGroup.Key.Sサイト日,
                        集金日 = grGroup.Key.T集金日,
                        S集金日 = grGroup.Key.T集金日,
                        請求月 = 0,
                        支払月 = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.集計日付s) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Distinct().Sum(c => c.集計日付s),
                        通行料 = 0,
                        支払通行料 = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.支払通行料) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.支払通行料),
                        消費税 = 0,
                        支払消費税 = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.支払消費税) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.支払消費税),
                        売上金額 = 0,
                        傭車金額 = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額),
                        売上金額計 = 0,
                        傭車金額計 = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額計) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額計),
                        売上 = 0,
                        支払 = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額計) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額計),
                        親子区分 = grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子" == null ? "" : grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子",
                        取引区分 = grGroup.Key.取引区分 == null ? 10 : grGroup.Key.取引区分,
                        作成年月度 = s作成年月度,
                        取引先指定 = s取引先From + "~" + s取引先To,
                        取引先ピックアップ = 取引先指定ピックアップ == "" ? "" : 取引先指定ピックアップ,
                    }).AsQueryable().Distinct();

                    //<<<データの絞込み>>>
                    if (!(string.IsNullOrEmpty(s取引先From + s取引先To) && i取引先List.Length == 0))
                    {
                        if (string.IsNullOrEmpty(s取引先From + s取引先To))
                        {
                            join = join.Where(c => c.コード >= int.MaxValue);
                        }

                        if (!string.IsNullOrEmpty(s取引先From))
                        {
                            int i取引先From = AppCommon.IntParse(s取引先From);
                            join = join.Where(c => c.コード >= i取引先From);
                        }

                        if (!string.IsNullOrEmpty(s取引先To))
                        {
                            int i取引先To = AppCommon.IntParse(s取引先To);
                            join = join.Where(c => c.コード <= i取引先To);
                        }

                        if (i取引先List.Length > 0)
                        {
                            var intCouse = i取引先List;
                            join = join.Union(from ret in retquery
                                              from m01 in context.M01_TOK.Where(c => c.削除日付 == null && c.親子区分ID != 3)
                                              from q02 in query2.Where(c => c.コードs == m01.得意先ID).DefaultIfEmpty()
                                              group new { m01, q02 } by
                                              new
                            {
                                m01.得意先ID,
                                m01.略称名,
                                m01.Tサイト日,
                                m01.Sサイト日,
                                m01.T集金日,
                                m01.S集金日,
                                m01.親子区分ID,
                                m01.取引区分,
                            } into grGroup
                                              where intCouse.Contains(grGroup.Key.得意先ID)
                                              select new SHR13010_Member
                            {
                                コード         = grGroup.Key.得意先ID,
                                取引先名        = grGroup.Key.略称名,
                                サイト         = grGroup.Key.Tサイト日,
                                サイトs        = grGroup.Key.Sサイト日,
                                集金日         = grGroup.Key.T集金日,
                                S集金日        = grGroup.Key.T集金日,
                                請求月         = 0,
                                支払月         = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.集計日付s) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Distinct().Sum(c => c.集計日付s),
                                通行料         = 0,
                                支払通行料       = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.支払通行料) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.支払通行料),
                                消費税         = 0,
                                支払消費税       = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.支払消費税) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.支払消費税),
                                売上金額        = 0,
                                傭車金額        = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額),
                                売上金額計       = 0,
                                傭車金額計       = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額計) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額計),
                                売上          = 0,
                                支払          = query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額計) == 0 ? 0 : query2.Where(c => c.コードs == grGroup.Key.得意先ID).Sum(c => c.傭車金額計),
                                親子区分        = grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子" == null ? "" : grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子",
                                取引区分        = grGroup.Key.取引区分 == null ? 10 : grGroup.Key.取引区分,
                                作成年月度       = s作成年月度,
                                取引先指定       = s取引先From + "~" + s取引先To,
                                取引先ピックアップ = 取引先指定ピックアップ == "" ? "" : 取引先指定ピックアップ,
                            });

                            //取引先指定の表示
                            if (i取引先List.Length > 0)
                            {
                                for (int i = 0; i < query.Count(); i++)
                                {
                                    取引先指定ピックアップ = 取引先指定ピックアップ + i取引先List[i].ToString();

                                    if (i < i取引先List.Length)
                                    {
                                        if (i == i取引先List.Length - 1)
                                        {
                                            break;
                                        }

                                        取引先指定ピックアップ = 取引先指定ピックアップ + ",";
                                    }

                                    if (i取引先List.Length == 1)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(s取引先From))
                        {
                            join = join.Where(c => c.コード >= int.MinValue);
                        }

                        if (string.IsNullOrEmpty(s取引先To))
                        {
                            join = join.Where(c => c.コード <= int.MaxValue);
                        }
                    }


                    //取引ありのみ表示
                    if (i作成区分 == 0)
                    {
                        join = join.Where(c => c.売上金額計 != 0 || c.傭車金額計 != 0);
                    }

                    //【全取引】の企業のみ
                    if (i取引区分 == 1)
                    {
                        join = join.Where(c => c.取引区分 == 0);
                    }

                    //親子区分【子】を非表示に
                    join = join.Where(c => c.親子区分 != "子");

                    //表示順序変更
                    join = join.OrderBy(c => c.コード);

                    return(join.ToList());
                }
                #endregion

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                #region データ無し

                else
                {
                    var join = (from m01 in context.M01_TOK.Where(c => c.削除日付 == null && c.親子区分ID != 3)
                                from s01 in context.S01_TOKS.Where(c => c.得意先KEY == m01.得意先KEY && c.回数 == 1).DefaultIfEmpty()
                                from s02 in context.S02_YOSS.Where(c => c.支払先KEY == m01.得意先KEY && c.回数 == 1).DefaultIfEmpty()
                                group new { m01, s01, s02 } by new
                    {
                        m01.得意先ID,
                        m01.略称名,
                        m01.Tサイト日,
                        m01.Sサイト日,
                        m01.T集金日,
                        m01.S集金日,
                        m01.親子区分ID,
                        m01.取引区分,
                    } into grGroup
                                select new SHR13010_Member
                    {
                        コード = grGroup.Key.得意先ID,
                        取引先名 = grGroup.Key.略称名,
                        サイト = grGroup.Key.Tサイト日,
                        サイトs = grGroup.Key.Sサイト日,
                        集金日 = grGroup.Key.T集金日,
                        S集金日 = grGroup.Key.T集金日,
                        請求月 = 0,
                        支払月 = 0,
                        通行料 = 0,
                        支払通行料 = 0,
                        消費税 = 0,
                        支払消費税 = 0,
                        売上金額 = 0,
                        傭車金額 = 0,
                        売上金額計 = 0,
                        傭車金額計 = 0,
                        売上 = 0,
                        支払 = 0,
                        親子区分 = grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子" == null ? "" : grGroup.Key.親子区分ID == 0 ? "" : grGroup.Key.親子区分ID == 1 ? "親" : grGroup.Key.親子区分ID == 2 ? "親" : "子",
                        取引区分 = grGroup.Key.取引区分 == null ? 10 : grGroup.Key.取引区分,
                        作成年月度 = s作成年月度,
                        取引先指定 = s取引先From + "~" + s取引先To,
                        取引先ピックアップ = 取引先指定ピックアップ == "" ? "" : 取引先指定ピックアップ,
                    }).Distinct().AsQueryable();

                    #endregion


                    //作成区分が0だった場合
                    if (i作成区分 == 0)
                    {
                        //売上・支払が発生していないデータを除く
                        join = join.Where(c => c.売上金額計 != 0 || c.傭車金額計 != 0);
                    }
                    return(join.ToList());
                }

                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
        }
Exemple #6
0
        /// <summary>
        /// 自社部門マスタ一覧検索データ取得
        /// </summary>
        /// <returns></returns>
        public List <M71_BUM_Member> GetSearchDataForList(string 自社部門コードFROM, string 自社部門コードTO, int[] i自社部門IDList, string 表示方法)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();


                var ret = (from m71 in context.M71_BUM
                           where m71.削除日付 == null
                           select new M71_BUM_Member
                {
                    自社部門ID = m71.自社部門ID,
                    登録日時 = m71.登録日時,
                    更新日時 = m71.更新日時,
                    自社部門名 = m71.自社部門名,
                    かな読み = m71.かな読み,
                    法人ナンバー = m71.法人ナンバー,
                }).AsQueryable();

                if (!(string.IsNullOrEmpty(自社部門コードFROM + 自社部門コードTO) && i自社部門IDList.Length == 0))
                {
                    if (string.IsNullOrEmpty(自社部門コードFROM + 自社部門コードTO))
                    {
                        ret = ret.Where(c => c.自社部門ID >= int.MaxValue);
                    }
                    if (!string.IsNullOrEmpty(自社部門コードFROM))
                    {
                        int i自社部門コードFROM = AppCommon.IntParse(自社部門コードFROM);
                        ret = ret.Where(c => c.自社部門ID >= i自社部門コードFROM);
                    }
                    if (!string.IsNullOrEmpty(自社部門コードTO))
                    {
                        int i自社部門コードTO = AppCommon.IntParse(自社部門コードTO);
                        ret = ret.Where(c => c.自社部門ID <= i自社部門コードTO);
                    }

                    if (i自社部門IDList.Length > 0)
                    {
                        var intCause = i自社部門IDList;

                        ret = ret.Union(from m71 in context.M71_BUM
                                        where m71.削除日付 == null && intCause.Contains(m71.自社部門ID)
                                        select new M71_BUM_Member
                        {
                            自社部門ID = m71.自社部門ID,
                            登録日時   = m71.登録日時,
                            更新日時   = m71.更新日時,
                            自社部門名  = m71.自社部門名,
                            かな読み   = m71.かな読み,
                            法人ナンバー = m71.法人ナンバー,
                        });
                    }
                }

                ret = ret.Distinct();

                if (表示方法 == "0")
                {
                    ret.OrderBy(c => c.自社部門ID);
                }
                else
                {
                    ret.OrderBy(c => c.かな読み);
                }


                return(ret.ToList());
            }
        }
Exemple #7
0
        public List <SRY10010_Member> SRY10010_GetDataList(string s車輌From, string s車輌To, int?[] i車輌List, string s車輌List, DateTime d集計期間From, DateTime d集計期間To)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                string 車輌指定ピックアップ            = string.Empty;
                int    i集計期間From               = AppCommon.IntParse(d集計期間From.ToString("yyyyMM"));
                int    i集計期間To                 = AppCommon.IntParse(d集計期間To.ToString("yyyyMM"));
                List <SRY10010_Member> retList = new List <SRY10010_Member>();
                context.Connection.Open();

                 try
                {
                    //var 車輌自社締日 = (from m87 in context.M87_CNTL.Where(m87 => m87.管理ID == 1)
                    //             select new {m87.車輌自社締日}).ToList();
                    ////int iSime = AppCommon.IntParse(車輌自社締日[0].車輌自社締日.ToString());
                    //iSime += 1;
                    //if ((iSime) >= 32)
                    //{
                    //    iSime = 1;
                    //}
                    //if (iSime.ToString().Length == 1){
                    //    if (!DateTime.TryParse(d集計期間From.ToString("yyyy/MM/0") + iSime.ToString(), out d集計期間From))
                    //    {
                    //        return retList;
                    //    }
                    //}
                    //else
                    //{
                    //    if (!DateTime.TryParse(d集計期間From.ToString("yyyy/MM/") + iSime.ToString(), out d集計期間From))
                    //    {
                    //        return retList;
                    //    }
                    //}

                    //var time = (from s14 in context.V_S14_CAR.Where(c => c.集計年月 >= i集計期間From && c.集計年月 <= i集計期間To)
                    //			select new SRY10010_jikan
                    //			{
                    //				KEY = s14.車輌KEY,
                    //				コード = (from m05 in context.M05_CAR.Where(c => c.車輌KEY == s14.車輌KEY) select m05.車輌ID).FirstOrDefault(),
                    //				拘束時間 = s14.拘束時間,
                    //			}).ToList();
                    //List<SRY10010_jikan> time2 = new List<SRY10010_jikan>();

                    //foreach (var rec in time)
                    //{
                    //	// 各時間項目の時分を、分に変換する。
                    //	rec.拘束時間 = LinqSub.時間TO分(rec.拘束時間);
                    //	time2.Add(rec);
                    //}

                    var query2 = (from s14sb in context.S14_CARSB
                                  join m07 in context.M07_KEI on s14sb.経費項目ID equals m07.経費項目ID into m07Group
                                  select new { s14sb.金額, s14sb.経費項目ID, s14sb.経費項目名, s14sb.固定変動区分, s14sb.更新日時, s14sb.車輌KEY, s14sb.集計年月, s14sb.登録日時, m07Group.FirstOrDefault().経費区分 }
                                  );

                    var query = (from m05 in context.M05_CAR.Where(m05 => m05.削除日付 == null)
                                 join m04 in context.M04_DRV on m05.乗務員KEY equals m04.乗務員KEY into m04Group
                                 join s14 in context.V_S14_CAR.Where(c => c.集計年月 >= i集計期間From && c.集計年月 <= i集計期間To) on m05.車輌KEY equals s14.車輌KEY into s14Group
                                 join s14sb in query2.Where(c => c.集計年月 >= i集計期間From && c.集計年月 <= i集計期間To) on m05.車輌KEY equals s14sb.車輌KEY into s14sbGroup
                                 select new SRY10010_Member
                    {
                        コード = m05.車輌ID,
                        車輌番号 = m05.車輌番号,
                        廃車日 = m05.廃車日,
                        乗務員名 = m04Group.FirstOrDefault().乗務員名,
                        収入日数 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : Math.Round(s14Group.Sum(c => c.運送収入) / s14Group.Sum(c => c.稼動日数), 0),
                        収入時間 = (s14Group.Sum(c => c.拘束時間)) == 0 ? 0 : Math.Round((s14Group.Sum(c => c.運送収入)) / (decimal)((s14Group.Sum(c => c.拘束時間)) / 60), 0),
                        収入KM = s14Group.Sum(c => c.走行KM) == 0 ? 0 : Math.Round(s14Group.Sum(c => c.運送収入) / s14Group.Sum(c => c.走行KM), 0),
                        収入屯数 = s14Group.Sum(c => c.輸送屯数) == 0 ? 0 : Math.Round(s14Group.Sum(c => c.運送収入) / s14Group.Sum(c => c.輸送屯数), 0),
                        固定費日数 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : Math.Round(s14sbGroup.Where(c => c.固定変動区分 == 0).Sum(c => c.金額) / s14Group.Sum(c => c.稼動日数), 0),
                        動費KM = s14Group.Sum(c => c.走行KM) == 0 ? 0 : Math.Round(s14sbGroup.Where(c => c.固定変動区分 == 1).Sum(c => c.金額) / s14Group.Sum(c => c.走行KM), 0),
                        修理日数 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : Math.Round(s14sbGroup.Where(c => c.経費項目ID == s14sbGroup.Where(d => d.経費区分 == 5).Min(d => d.経費項目ID)).Sum(c => c.金額) / s14Group.Sum(c => c.稼動日数), 0),
                        修理KM = s14Group.Sum(c => c.走行KM) == 0 ? 0 : Math.Round(s14sbGroup.Where(c => c.経費項目ID == s14sbGroup.Where(d => d.経費区分 == 5).Min(d => d.経費項目ID)).Sum(c => c.金額) / s14Group.Sum(c => c.走行KM), 0),
                        益日数 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : Math.Round((s14Group.Sum(c => c.運送収入) - s14sbGroup.Sum(c => c.金額)) / s14Group.Sum(c => c.稼動日数), 0),
                        益KM = s14Group.Sum(c => c.走行KM) == 0 ? 0 : Math.Round((s14Group.Sum(c => c.運送収入) - s14sbGroup.Sum(c => c.金額)) / s14Group.Sum(c => c.走行KM), 0),
                        稼働率 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : Math.Round((decimal)(s14Group.Sum(c => c.拘束時間) / (s14Group.Sum(c => c.稼動日数) * 1440)), 2),
                        //稼働率 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : (s14Group.Sum(c => c.稼動日数) * 1440),
                        集計年月From = d集計期間From,
                        集計年月To = d集計期間To,
                        コードFrom = s車輌From,
                        コードTo = s車輌To,
                        車輌List = 車輌指定ピックアップ == "" ? "無" : 車輌指定ピックアップ
                    }).AsQueryable();

                    //foreach (SRY10010_Member row in query)
                    //{
                    //	foreach (SRY10010_jikan row2 in time2)
                    //	{
                    //		if (row.コード == row2.コード)
                    //		{
                    //			row.稼働率 = row.稼働率 == null ? 0 : row.稼働率 == 0 ? 0 : Math.Round((decimal)row2.拘束時間 / (decimal)row.稼働率, MidpointRounding.AwayFromZero);
                    //		}
                    //	}
                    //}

                    query = query.Distinct();
                    int i車輌FROM;
                    int i車輌TO;

                    //部門From処理 Min値
                    if (!string.IsNullOrEmpty(s車輌From))
                    {
                        i車輌FROM = AppCommon.IntParse(s車輌From);
                    }
                    else
                    {
                        i車輌FROM = int.MinValue;
                    }

                    //部門To処理 Max値
                    if (!string.IsNullOrEmpty(s車輌To))
                    {
                        i車輌TO = AppCommon.IntParse(s車輌To);
                    }
                    else
                    {
                        i車輌TO = int.MaxValue;
                    }

                    var intCause = i車輌List;

                    if (string.IsNullOrEmpty(s車輌From + s車輌To))
                    {
                        if (i車輌List.Length > 0)
                        {
                            query = query.Where(q => intCause.Contains(q.コード));
                        }
                    }
                    else
                    {
                        if (i車輌List.Length > 0)
                        {
                            query = query.Where(q => intCause.Contains(q.コード) || (q.コード >= i車輌FROM && q.コード <= i車輌TO));
                        }
                        else
                        {
                            query = query.Where(q => (q.コード >= i車輌FROM && q.コード <= i車輌TO));
                        }
                    }

                    if (i車輌List.Length > 0)
                    {
                        for (int Count = 0; Count < query.Count(); Count++)
                        {
                            車輌指定ピックアップ = 車輌指定ピックアップ + i車輌List[Count].ToString();

                            if (Count < i車輌List.Length)
                            {
                                if (Count == i車輌List.Length - 1)
                                {
                                    break;
                                }

                                車輌指定ピックアップ = 車輌指定ピックアップ + ",";
                            }

                            if (i車輌List.Length == 1)
                            {
                                break;
                            }
                        }
                    }

                    query   = query.Distinct();
                    retList = query.Where(c => c.廃車日 == null || ((((DateTime)c.廃車日).Year * 100 + ((DateTime)c.廃車日).Month) >= i集計期間From)).ToList();
                    //retList = query.ToList();
                    return(retList);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #8
0
        /// <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;
                }
            }
        }
Exemple #9
0
        public List <TKS19010_Member2> TKS19010_GetData(string p車輌From, string p車輌To, int?[] p車輌List, string s車輌List, string p作成締日, string p作成年, string p作成月, DateTime p集計期間From, DateTime p集計期間To)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                try
                {
                    DateTime d作成年月;
                    DateTime Wk;
                    d作成年月 = DateTime.TryParse(p作成年 + "/" + p作成月 + "/" + 01, out Wk) ? Wk : DateTime.Today;

                    int p作成年月;

                    if (p作成月.Length == 1)
                    {
                        p作成年月 = AppCommon.IntParse(p作成年 + "0" + p作成月);
                    }
                    else
                    {
                        p作成年月 = AppCommon.IntParse(p作成年 + p作成月);
                    }

                    //日付格納LIST
                    List <TKS19010_Member_day> retList_day = new List <TKS19010_Member_day>();

                    DateTime d日付 = DateTime.TryParse(p集計期間From.ToString(), out Wk) ? Wk :DateTime.Today;
                    //日付、曜日計算処理
                    for (int i = 0; d日付 <= p集計期間To; d日付 = d日付.AddDays(1))
                    {
                        retList_day.Add(new TKS19010_Member_day()
                        {
                            日付 = d日付,
                            曜日 = ("日月火水木金土").Substring(AppCommon.IntParse(d日付.DayOfWeek.ToString("d")), 1) + "曜",
                        });
                    }

                    //                List<TKS19010_Member1> retList = new List<TKS19010_Member1>();

                    context.Connection.Open();

                    //try
                    //{

                    #region 集計


                    var query = (from rday in retList_day
                                 from m05 in context.M05_CAR.Where(q => q.削除日付 == null)
                                 join m17 in context.M17_CYSN.Where(q => q.年月 == p作成年月) on m05.車輌KEY equals m17.車輌KEY into m17Group
                                 join t01 in context.T01_TRN.Where(t01 => ((t01.入力区分 != 3) || (t01.入力区分 == 3 && t01.明細行 == 1))) on new { a = rday.日付, b = m05.車輌KEY } equals new { a = t01.請求日付, b = (int)(t01.車輌KEY == null ? 0 : t01.車輌KEY) } into t01Group
                                 //from t01g in t01Group.DefaultIfEmpty()
                                 orderby m05.車輌ID, rday.日付
                                 select new TKS19010_Member1
                    {
                        日付 = rday.日付,
                        車輌ID = m05.車輌ID,
                        車輌名 = m05.車輌番号,
                        日計 = (t01Group.Sum(q => q.売上金額) == null ? 0 : t01Group.Sum(q => q.売上金額))
                             + (t01Group.Sum(q => q.請求割増1) == null ? 0 : t01Group.Sum(q => q.請求割増1))
                             + (t01Group.Sum(q => q.請求割増2) == null ? 0 : t01Group.Sum(q => q.請求割増2)),
                        予算 = m17Group.Select(q => q.売上予算).FirstOrDefault(),

                        //コードFrom = p車輌From,
                        //コードTo = p車輌To,
                        //ピックアップ指定 = s車輌List,
                        //開始日付 = p集計期間From,
                        //終了日付 = p集計期間To,
                        //年月 = d作成年月,
                    }).AsQueryable();


                    var carlet = (from q in query
                                  group q by q.車輌ID into qGroup
                                  select new TKS19010_Let
                    {
                        車輌ID = qGroup.Key,
                        合計 = qGroup.Sum(q => q.日計),
                    }).AsQueryable();

                    query = (from q in query
                             let bb = from b in carlet where b.合計 != 0 select b.車輌ID
                                      where bb.Contains(q.車輌ID)
                                      select new TKS19010_Member1
                    {
                        日付 = q.日付,
                        車輌ID = q.車輌ID,
                        車輌名 = q.車輌名,
                        日計 = q.日計,
                        予算 = q.予算,
                    }).AsQueryable();


                    var query2 = (from rday in retList_day
                                  join t01 in context.T01_TRN.Where(t01 => ((t01.入力区分 != 3) || (t01.入力区分 == 3 && t01.明細行 == 1))) on new { a = rday.日付 } equals new { a = t01.請求日付 } into t01Group
                                  //from t01g in t01Group.DefaultIfEmpty()
                                  orderby rday.日付
                                  select new TKS19010_Member1
                    {
                        日付 = rday.日付,
                        車輌ID = 0,
                        車輌名 = "全車輌",
                        日計 = (t01Group.Sum(q => q.売上金額) == null ? 0 : t01Group.Sum(q => q.売上金額))
                             + (t01Group.Sum(q => q.請求割増1) == null ? 0 : t01Group.Sum(q => q.請求割増1))
                             + (t01Group.Sum(q => q.請求割増2) == null ? 0 : t01Group.Sum(q => q.請求割増2)),
                        予算 = context.M17_CYSN.Where(q => q.年月 == p作成年月).Any() == false ? 0 : context.M17_CYSN.Where(q => q.年月 == p作成年月).Sum(q => q.売上予算),
                        //コードFrom = p車輌From,
                        //コードTo = p車輌To,
                        //ピックアップ指定 = s車輌List,
                        //開始日付 = p集計期間From,
                        //終了日付 = p集計期間To,
                        //年月 = d作成年月,
                    }).AsQueryable();

                    var query3 = query;

                    //車輌From処理 Min値
                    if (!string.IsNullOrEmpty(p車輌From))
                    {
                        int i車輌From = AppCommon.IntParse(p車輌From);
                        query = query.Where(c => c.車輌ID >= i車輌From);
                    }

                    //車輌To処理 Max値
                    if (!string.IsNullOrEmpty(p車輌To))
                    {
                        int i車輌TO = AppCommon.IntParse(p車輌To);
                        query = query.Where(c => c.車輌ID <= i車輌TO);
                    }

                    if (p車輌List.Length > 0)
                    {
                        if ((string.IsNullOrEmpty(p車輌From)) && (string.IsNullOrEmpty(p車輌To)))
                        {
                            query = query3.Where(q => p車輌List.Contains(q.車輌ID));
                        }
                        else
                        {
                            query = query.Union(query3.Where(q => p車輌List.Contains(q.車輌ID)));
                        }
                    }
                    query = query.Distinct();


                    query3 = query.Union(query2).OrderBy(q => q.車輌ID).ThenBy(q => q.日付);

                    //var query3 = query.OrderBy(q => q.車輌ID).ThenBy(q => q.日付);

                    var query4 = query3.ToList();

                    int     m17code = 0;
                    decimal Ruikei  = 0;
                    foreach (var Lst in query4)
                    {
                        if (m17code != Lst.車輌ID)
                        {
                            Ruikei  = 0;
                            m17code = Lst.車輌ID;
                        }
                        Ruikei += Lst.日計;
                        Lst.累計  = Ruikei;
                        Lst.予算残 = Lst.予算 - Ruikei;
                        Lst.達成率 = Lst.予算 == 0 ? 0 : Math.Round((Ruikei / Lst.予算 * 100), 1, MidpointRounding.AwayFromZero);
                    }
                    ;



                    #endregion

                    //TKS19010_DATASET dset = new TKS19010_DATASET()
                    //{
                    //    売上構成グラフ = query1,
                    //    得意先上位グラフ = query2,
                    //    傭車先上位グラフ = query3,
                    //    損益分岐点グラフ = query4,
                    //};


                    var bumid = (from que in query4
                                 group que by new { que.車輌ID } into queGroup
                                 select new TKS19010_Member1()
                    {
                        車輌ID = queGroup.Key.車輌ID,
                    }).AsQueryable();

                    List <TKS19010_Member2> retList = new List <TKS19010_Member2>();
                    int cnt = 0;
                    int?bumid1 = null, bumid2 = null, bumid3 = null, bumid4 = null;
                    foreach (var id in bumid)
                    {
                        switch (cnt)
                        {
                        case 0:
                            bumid1 = id.車輌ID;
                            break;

                        case 1:
                            bumid2 = id.車輌ID;
                            break;

                        case 2:
                            bumid3 = id.車輌ID;
                            break;
                            //case 3:
                            //    bumid4 = id.車輌ID;
                            //    break;
                        }
                        cnt += 1;

                        if (cnt >= 3)
                        {
                            var q1 = query4.Where(q => q.車輌ID == bumid1);
                            var q2 = query4.Where(q => q.車輌ID == bumid2);
                            var q3 = query4.Where(q => q.車輌ID == bumid3);
                            var q4 = query4.Where(q => q.車輌ID == bumid4);

                            foreach (var row in q1)
                            {
                                TKS19010_Member2 list = new TKS19010_Member2()
                                {
                                    日付    = row.日付,
                                    車輌ID1 = row.車輌ID,
                                    車輌名1  = row.車輌名,
                                    日計1   = row.日計,
                                    累計1   = row.累計,
                                    予算残1  = row.予算残,
                                    達成率1  = row.達成率,
                                    予算1   = row.予算,

                                    車輌ID2 = q2.Where(q => q.日付 == row.日付).Select(q => q.車輌ID).FirstOrDefault(),
                                    車輌名2  = q2.Where(q => q.日付 == row.日付).Select(q => q.車輌名).FirstOrDefault(),
                                    日計2   = q2.Where(q => q.日付 == row.日付).Select(q => q.日計).FirstOrDefault(),
                                    累計2   = q2.Where(q => q.日付 == row.日付).Select(q => q.累計).FirstOrDefault(),
                                    予算残2  = q2.Where(q => q.日付 == row.日付).Select(q => q.予算残).FirstOrDefault(),
                                    達成率2  = q2.Where(q => q.日付 == row.日付).Select(q => q.達成率).FirstOrDefault(),
                                    予算2   = q2.Where(q => q.日付 == row.日付).Select(q => q.予算).FirstOrDefault(),

                                    車輌ID3 = q3.Where(q => q.日付 == row.日付).Select(q => q.車輌ID).FirstOrDefault(),
                                    車輌名3  = q3.Where(q => q.日付 == row.日付).Select(q => q.車輌名).FirstOrDefault(),
                                    日計3   = q3.Where(q => q.日付 == row.日付).Select(q => q.日計).FirstOrDefault(),
                                    累計3   = q3.Where(q => q.日付 == row.日付).Select(q => q.累計).FirstOrDefault(),
                                    予算残3  = q3.Where(q => q.日付 == row.日付).Select(q => q.予算残).FirstOrDefault(),
                                    達成率3  = q3.Where(q => q.日付 == row.日付).Select(q => q.達成率).FirstOrDefault(),
                                    予算3   = q3.Where(q => q.日付 == row.日付).Select(q => q.予算).FirstOrDefault(),

                                    コードFrom  = p車輌From,
                                    コードTo    = p車輌To,
                                    ピックアップ指定 = s車輌List,
                                    開始年月日    = p集計期間From,
                                    終了年月日    = p集計期間To,
                                    年月       = d作成年月,
                                };
                                retList.Add(list);
                            }



                            cnt    = 0;
                            bumid1 = null; bumid2 = null; bumid3 = null; bumid4 = null;
                        }
                    }
                    //余り分があれば
                    if (cnt > 0)
                    {
                        var q1 = query4.Where(q => q.車輌ID == bumid1);
                        var q2 = query4.Where(q => q.車輌ID == bumid2);
                        var q3 = query4.Where(q => q.車輌ID == bumid3);
                        var q4 = query4.Where(q => q.車輌ID == bumid4);

                        foreach (var row in q1)
                        {
                            TKS19010_Member2 list = new TKS19010_Member2()
                            {
                                日付    = row.日付,
                                車輌ID1 = row.車輌ID,
                                車輌名1  = row.車輌名,
                                日計1   = row.日計,
                                累計1   = row.累計,
                                予算残1  = row.予算残,
                                達成率1  = row.達成率,
                                予算1   = row.予算,

                                車輌ID2 = q2.Where(q => q.日付 == row.日付).Select(q => q.車輌ID).FirstOrDefault(),
                                車輌名2  = q2.Where(q => q.日付 == row.日付).Select(q => q.車輌名).FirstOrDefault(),
                                日計2   = q2.Where(q => q.日付 == row.日付).Select(q => q.日計).FirstOrDefault(),
                                累計2   = q2.Where(q => q.日付 == row.日付).Select(q => q.累計).FirstOrDefault(),
                                予算残2  = q2.Where(q => q.日付 == row.日付).Select(q => q.予算残).FirstOrDefault(),
                                達成率2  = q2.Where(q => q.日付 == row.日付).Select(q => q.達成率).FirstOrDefault(),
                                予算2   = q2.Where(q => q.日付 == row.日付).Select(q => q.予算).FirstOrDefault(),

                                車輌ID3 = q3.Where(q => q.日付 == row.日付).Select(q => q.車輌ID).FirstOrDefault(),
                                車輌名3  = q3.Where(q => q.日付 == row.日付).Select(q => q.車輌名).FirstOrDefault(),
                                日計3   = q3.Where(q => q.日付 == row.日付).Select(q => q.日計).FirstOrDefault(),
                                累計3   = q3.Where(q => q.日付 == row.日付).Select(q => q.累計).FirstOrDefault(),
                                予算残3  = q3.Where(q => q.日付 == row.日付).Select(q => q.予算残).FirstOrDefault(),
                                達成率3  = q3.Where(q => q.日付 == row.日付).Select(q => q.達成率).FirstOrDefault(),
                                予算3   = q3.Where(q => q.日付 == row.日付).Select(q => q.予算).FirstOrDefault(),

                                コードFrom  = p車輌From,
                                コードTo    = p車輌To,
                                ピックアップ指定 = s車輌List,
                                開始年月日    = p集計期間From,
                                終了年月日    = p集計期間To,
                                年月       = d作成年月,
                            };
                            retList.Add(list);
                        }
                    }



                    return(retList);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #10
0
        public List <TKS19010_Member1> TKS19010_GetData_CSV(string p車輌From, string p車輌To, int?[] p車輌List, string s車輌List, string p作成締日, string p作成年, string p作成月, DateTime p集計期間From, DateTime p集計期間To)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                try
                {
                    DateTime d作成年月;
                    DateTime Wk;
                    d作成年月 = DateTime.TryParse(p作成年 + "/" + p作成月 + "/" + 01, out Wk) ? Wk : DateTime.Today;

                    int p作成年月;

                    if (p作成月.Length == 1)
                    {
                        p作成年月 = AppCommon.IntParse(p作成年 + "0" + p作成月);
                    }
                    else
                    {
                        p作成年月 = AppCommon.IntParse(p作成年 + p作成月);
                    }

                    //日付格納LIST
                    List <TKS19010_Member_day> retList_day = new List <TKS19010_Member_day>();

                    DateTime d日付 = DateTime.TryParse(p集計期間From.ToString(), out Wk) ? Wk : DateTime.Today;
                    //日付、曜日計算処理
                    for (int i = 0; d日付 <= p集計期間To; d日付 = d日付.AddDays(1))
                    {
                        retList_day.Add(new TKS19010_Member_day()
                        {
                            日付 = d日付,
                            曜日 = ("日月火水木金土").Substring(AppCommon.IntParse(d日付.DayOfWeek.ToString("d")), 1) + "曜",
                        });
                    }

                    //                List<TKS19010_Member1> retList = new List<TKS19010_Member1>();

                    context.Connection.Open();

                    //try
                    //{

                    #region 集計


                    var query = (from rday in retList_day
                                 from m05 in context.M05_CAR.Where(q => q.削除日付 == null)
                                 join m17 in context.M17_CYSN.Where(q => q.年月 == p作成年月) on m05.車輌KEY equals m17.車輌KEY into m17Group
                                 join t01 in context.T01_TRN.Where(t01 => ((t01.入力区分 != 3) || (t01.入力区分 == 3 && t01.明細行 == 1))) on new { a = rday.日付, b = m05.車輌KEY } equals new { a = t01.請求日付, b = (int)(t01.車輌KEY == null ? 0 : t01.車輌KEY) } into t01Group
                                 //from t01g in t01Group.DefaultIfEmpty()
                                 orderby m05.車輌ID, rday.日付
                                 select new TKS19010_Member1
                    {
                        日付 = rday.日付,
                        車輌ID = m05.車輌ID,
                        車輌名 = m05.車輌番号,
                        日計 = (t01Group.Sum(q => q.売上金額) == null ? 0 : t01Group.Sum(q => q.売上金額))
                             + (t01Group.Sum(q => q.請求割増1) == null ? 0 : t01Group.Sum(q => q.請求割増1))
                             + (t01Group.Sum(q => q.請求割増2) == null ? 0 : t01Group.Sum(q => q.請求割増2)),
                        予算 = m17Group.Select(q => q.売上予算).FirstOrDefault(),

                        //コードFrom = p車輌From,
                        //コードTo = p車輌To,
                        //ピックアップ指定 = s車輌List,
                        //開始日付 = p集計期間From,
                        //終了日付 = p集計期間To,
                        //年月 = d作成年月,
                    }).AsQueryable();


                    var carlet = (from q in query
                                  group q by q.車輌ID into qGroup
                                  select new TKS19010_Let
                    {
                        車輌ID = qGroup.Key,
                        合計 = qGroup.Sum(q => q.日計),
                    }).AsQueryable();

                    query = (from q in query
                             let bb = from b in carlet where b.合計 != 0 select b.車輌ID
                                      where bb.Contains(q.車輌ID)
                                      select new TKS19010_Member1
                    {
                        日付 = q.日付,
                        車輌ID = q.車輌ID,
                        車輌名 = q.車輌名,
                        日計 = q.日計,
                        予算 = q.予算,
                    }).AsQueryable();


                    var query2 = (from rday in retList_day
                                  join t01 in context.T01_TRN.Where(t01 => ((t01.入力区分 != 3) || (t01.入力区分 == 3 && t01.明細行 == 1))) on new { a = rday.日付 } equals new { a = t01.請求日付 } into t01Group
                                  //from t01g in t01Group.DefaultIfEmpty()
                                  orderby rday.日付
                                  select new TKS19010_Member1
                    {
                        日付 = rday.日付,
                        車輌ID = 0,
                        車輌名 = "全車輌",
                        日計 = (t01Group.Sum(q => q.売上金額) == null ? 0 : t01Group.Sum(q => q.売上金額))
                             + (t01Group.Sum(q => q.請求割増1) == null ? 0 : t01Group.Sum(q => q.請求割増1))
                             + (t01Group.Sum(q => q.請求割増2) == null ? 0 : t01Group.Sum(q => q.請求割増2)),
                        予算 = context.M17_CYSN.Where(q => q.年月 == p作成年月).Any() == false ? 0 : context.M17_CYSN.Where(q => q.年月 == p作成年月).Sum(q => q.売上予算),
                        //コードFrom = p車輌From,
                        //コードTo = p車輌To,
                        //ピックアップ指定 = s車輌List,
                        //開始日付 = p集計期間From,
                        //終了日付 = p集計期間To,
                        //年月 = d作成年月,
                    }).AsQueryable();

                    var query3 = query;

                    //車輌From処理 Min値
                    if (!string.IsNullOrEmpty(p車輌From))
                    {
                        int i車輌From = AppCommon.IntParse(p車輌From);
                        query = query.Where(c => c.車輌ID >= i車輌From);
                    }

                    //車輌To処理 Max値
                    if (!string.IsNullOrEmpty(p車輌To))
                    {
                        int i車輌TO = AppCommon.IntParse(p車輌To);
                        query = query.Where(c => c.車輌ID <= i車輌TO);
                    }

                    if (p車輌List.Length > 0)
                    {
                        if ((string.IsNullOrEmpty(p車輌From)) && (string.IsNullOrEmpty(p車輌To)))
                        {
                            query = query3.Where(q => p車輌List.Contains(q.車輌ID));
                        }
                        else
                        {
                            query = query.Union(query3.Where(q => p車輌List.Contains(q.車輌ID)));
                        }
                    }
                    query = query.Distinct();


                    query3 = query.Union(query2).OrderBy(q => q.車輌ID).ThenBy(q => q.日付);

                    //var query3 = query.OrderBy(q => q.車輌ID).ThenBy(q => q.日付);

                    var query4 = query3.ToList();

                    int     m17code = 0;
                    decimal Ruikei  = 0;
                    foreach (var Lst in query4)
                    {
                        if (m17code != Lst.車輌ID)
                        {
                            Ruikei  = 0;
                            m17code = Lst.車輌ID;
                        }
                        Ruikei += Lst.日計;
                        Lst.累計  = Ruikei;
                        Lst.予算残 = Lst.予算 - Ruikei;
                        Lst.達成率 = Lst.予算 == 0 ? 0 : Math.Round((Ruikei / Lst.予算 * 100), 1, MidpointRounding.AwayFromZero);
                    }
                    ;



                    #endregion

                    return(query4);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// F9(登録ボタン)での登録
        /// </summary>
        public void NINSERT_GetData(List <SERCHE_MST32010> dt, string s作成年月)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                using (var tran = new TransactionScope())
                {
                    try
                    {
                        DateTime d年月   = Convert.ToDateTime(s作成年月.Substring(0, 4) + "/" + s作成年月.Substring(5, 2) + "/01");
                        int      i開始年月 = Convert.ToInt32(s作成年月.Substring(0, 4) + s作成年月.Substring(5, 2));
                        int      i終了年月 = AppCommon.IntParse(d年月.AddMonths(11).Year.ToString() + d年月.AddMonths(11).ToString("MM"));

                        var del = (from m17 in context.M17_CYSN where m17.年月 >= i開始年月 && m17.年月 <= i終了年月 select m17);
                        foreach (var row in del)
                        {
                            context.DeleteObject(row);
                        }
                        ;

                        foreach (var row in dt)
                        {
                            M17_CYSN m17_row = new M17_CYSN();
                            m17_row.車輌KEY = row.車輌KEY;
                            m17_row.年月    = row.年月1;
                            m17_row.売上予算  = row.月1;
                            m17_row.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row);
                            context.SaveChanges();

                            M17_CYSN m17_row2 = new M17_CYSN();
                            m17_row2.車輌KEY = row.車輌KEY;
                            m17_row2.年月    = row.年月2;
                            m17_row2.売上予算  = row.月2;
                            m17_row2.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row2);
                            context.SaveChanges();

                            M17_CYSN m17_row3 = new M17_CYSN();
                            m17_row3.車輌KEY = row.車輌KEY;
                            m17_row3.年月    = row.年月3;
                            m17_row3.売上予算  = row.月3;
                            m17_row3.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row3);
                            context.SaveChanges();

                            M17_CYSN m17_row4 = new M17_CYSN();
                            m17_row4.車輌KEY = row.車輌KEY;
                            m17_row4.年月    = row.年月4;
                            m17_row4.売上予算  = row.月4;
                            m17_row4.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row4);
                            context.SaveChanges();

                            M17_CYSN m17_row5 = new M17_CYSN();
                            m17_row5.車輌KEY = row.車輌KEY;
                            m17_row5.年月    = row.年月5;
                            m17_row5.売上予算  = row.月5;
                            m17_row5.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row5);
                            context.SaveChanges();

                            M17_CYSN m17_row6 = new M17_CYSN();
                            m17_row6.車輌KEY = row.車輌KEY;
                            m17_row6.年月    = row.年月6;
                            m17_row6.売上予算  = row.月6;
                            m17_row6.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row6);
                            context.SaveChanges();

                            M17_CYSN m17_row7 = new M17_CYSN();
                            m17_row7.車輌KEY = row.車輌KEY;
                            m17_row7.年月    = row.年月7;
                            m17_row7.売上予算  = row.月7;
                            m17_row7.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row7);
                            context.SaveChanges();

                            M17_CYSN m17_row8 = new M17_CYSN();
                            m17_row8.車輌KEY = row.車輌KEY;
                            m17_row8.年月    = row.年月8;
                            m17_row8.売上予算  = row.月8;
                            m17_row8.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row8);
                            context.SaveChanges();

                            M17_CYSN m17_row9 = new M17_CYSN();
                            m17_row9.車輌KEY = row.車輌KEY;
                            m17_row9.年月    = row.年月9;
                            m17_row9.売上予算  = row.月9;
                            m17_row9.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row9);
                            context.SaveChanges();

                            M17_CYSN m17_row10 = new M17_CYSN();
                            m17_row10.車輌KEY = row.車輌KEY;
                            m17_row10.年月    = row.年月10;
                            m17_row10.売上予算  = row.月10;
                            m17_row10.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row10);
                            context.SaveChanges();

                            M17_CYSN m17_row11 = new M17_CYSN();
                            m17_row11.車輌KEY = row.車輌KEY;
                            m17_row11.年月    = row.年月11;
                            m17_row11.売上予算  = row.月11;
                            m17_row11.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row11);
                            context.SaveChanges();

                            M17_CYSN m17_row12 = new M17_CYSN();
                            m17_row12.車輌KEY = row.車輌KEY;
                            m17_row12.年月    = row.年月12;
                            m17_row12.売上予算  = row.月12;
                            m17_row12.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row12);
                            context.SaveChanges();
                        }
                        ;

                        tran.Complete();
                        return;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
Exemple #12
0
        /// <summary>
        /// 先月データ取得
        /// </summary>
        /// <param name="s作成年月"></param>
        /// <returns></returns>
        public List <SERCHE_MST32010> LAST_MANTH_MST32010(string s作成年月)
        {
            DateTime d年月 = Convert.ToDateTime(s作成年月.Substring(0, 4).ToString() + "/" + s作成年月.Substring(5, 2).ToString() + "/" + "01");

            int ii年月1  = AppCommon.IntParse(d年月.Year.ToString() + d年月.ToString("MM"));
            int ii年月2  = AppCommon.IntParse(d年月.AddMonths(1).Year.ToString() + d年月.AddMonths(1).ToString("MM"));
            int ii年月3  = AppCommon.IntParse(d年月.AddMonths(2).Year.ToString() + d年月.AddMonths(2).ToString("MM"));
            int ii年月4  = AppCommon.IntParse(d年月.AddMonths(3).Year.ToString() + d年月.AddMonths(3).ToString("MM"));
            int ii年月5  = AppCommon.IntParse(d年月.AddMonths(4).Year.ToString() + d年月.AddMonths(4).ToString("MM"));
            int ii年月6  = AppCommon.IntParse(d年月.AddMonths(5).Year.ToString() + d年月.AddMonths(5).ToString("MM"));
            int ii年月7  = AppCommon.IntParse(d年月.AddMonths(6).Year.ToString() + d年月.AddMonths(6).ToString("MM"));
            int ii年月8  = AppCommon.IntParse(d年月.AddMonths(7).Year.ToString() + d年月.AddMonths(7).ToString("MM"));
            int ii年月9  = AppCommon.IntParse(d年月.AddMonths(8).Year.ToString() + d年月.AddMonths(8).ToString("MM"));
            int ii年月10 = AppCommon.IntParse(d年月.AddMonths(9).Year.ToString() + d年月.AddMonths(9).ToString("MM"));
            int ii年月11 = AppCommon.IntParse(d年月.AddMonths(10).Year.ToString() + d年月.AddMonths(10).ToString("MM"));
            int ii年月12 = AppCommon.IntParse(d年月.AddMonths(11).Year.ToString() + d年月.AddMonths(11).ToString("MM"));


            d年月 = d年月.AddYears(-1);

            int i年月1  = AppCommon.IntParse(d年月.Year.ToString() + d年月.ToString("MM"));
            int i年月2  = AppCommon.IntParse(d年月.AddMonths(1).Year.ToString() + d年月.AddMonths(1).ToString("MM"));
            int i年月3  = AppCommon.IntParse(d年月.AddMonths(2).Year.ToString() + d年月.AddMonths(2).ToString("MM"));
            int i年月4  = AppCommon.IntParse(d年月.AddMonths(3).Year.ToString() + d年月.AddMonths(3).ToString("MM"));
            int i年月5  = AppCommon.IntParse(d年月.AddMonths(4).Year.ToString() + d年月.AddMonths(4).ToString("MM"));
            int i年月6  = AppCommon.IntParse(d年月.AddMonths(5).Year.ToString() + d年月.AddMonths(5).ToString("MM"));
            int i年月7  = AppCommon.IntParse(d年月.AddMonths(6).Year.ToString() + d年月.AddMonths(6).ToString("MM"));
            int i年月8  = AppCommon.IntParse(d年月.AddMonths(7).Year.ToString() + d年月.AddMonths(7).ToString("MM"));
            int i年月9  = AppCommon.IntParse(d年月.AddMonths(8).Year.ToString() + d年月.AddMonths(8).ToString("MM"));
            int i年月10 = AppCommon.IntParse(d年月.AddMonths(9).Year.ToString() + d年月.AddMonths(9).ToString("MM"));
            int i年月11 = AppCommon.IntParse(d年月.AddMonths(10).Year.ToString() + d年月.AddMonths(10).ToString("MM"));
            int i年月12 = AppCommon.IntParse(d年月.AddMonths(11).Year.ToString() + d年月.AddMonths(11).ToString("MM"));


            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                var query = (from m05 in context.M05_CAR.Where(c => c.削除日付 == null)
                             join m17 in context.M17_CYSN on m05.車輌KEY equals m17.車輌KEY into m17Group
                             select new SERCHE_MST32010
                {
                    車輌KEY = m05.車輌KEY,
                    車輌コード = m05.車輌ID,
                    車番 = m05.車輌番号,
                    月1 = m17Group.Where(c => c.年月 == i年月1).Select(c => c.売上予算).FirstOrDefault(),
                    月2 = m17Group.Where(c => c.年月 == i年月2).Select(c => c.売上予算).FirstOrDefault(),
                    月3 = m17Group.Where(c => c.年月 == i年月3).Select(c => c.売上予算).FirstOrDefault(),
                    月4 = m17Group.Where(c => c.年月 == i年月4).Select(c => c.売上予算).FirstOrDefault(),
                    月5 = m17Group.Where(c => c.年月 == i年月5).Select(c => c.売上予算).FirstOrDefault(),
                    月6 = m17Group.Where(c => c.年月 == i年月6).Select(c => c.売上予算).FirstOrDefault(),
                    月7 = m17Group.Where(c => c.年月 == i年月7).Select(c => c.売上予算).FirstOrDefault(),
                    月8 = m17Group.Where(c => c.年月 == i年月8).Select(c => c.売上予算).FirstOrDefault(),
                    月9 = m17Group.Where(c => c.年月 == i年月9).Select(c => c.売上予算).FirstOrDefault(),
                    月10 = m17Group.Where(c => c.年月 == i年月10).Select(c => c.売上予算).FirstOrDefault(),
                    月11 = m17Group.Where(c => c.年月 == i年月11).Select(c => c.売上予算).FirstOrDefault(),
                    月12 = m17Group.Where(c => c.年月 == i年月12).Select(c => c.売上予算).FirstOrDefault(),
                    年月1 = ii年月1,
                    年月2 = ii年月2,
                    年月3 = ii年月3,
                    年月4 = ii年月4,
                    年月5 = ii年月5,
                    年月6 = ii年月6,
                    年月7 = ii年月7,
                    年月8 = ii年月8,
                    年月9 = ii年月9,
                    年月10 = ii年月10,
                    年月11 = ii年月11,
                    年月12 = ii年月12,
                }).AsQueryable();
                var queryLIST = query.ToList();

                return(queryLIST);
            }
        }
Exemple #13
0
        /// <summary>
        /// 仕入ヘッダ情報を取得する
        /// </summary>
        /// <param name="companyCode">会社名コード</param>
        /// <param name="slipNumber">伝票番号</param>
        /// <param name="userId">ログインユーザID</param>
        /// <returns></returns>
        private List <T03.T03_SRHD_RT_Extension> getM03_SRHD_RT_Extension(string companyCode, string slipNumber, int userId)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                int code, num;
                if (int.TryParse(companyCode, out code) && int.TryParse(slipNumber, out num))
                {
                    var result =
                        context.T03_SRHD.Where(w => w.削除日時 == null && w.会社名コード == code && w.伝票番号 == num)
                        .GroupJoin(context.T03_SRHD.Where(w => w.削除日時 == null),
                                   x => x.元伝票番号,
                                   y => y.伝票番号,
                                   (x, y) => new { x, y })
                        .SelectMany(s => s.y.DefaultIfEmpty(), (a, b) => new { SRTHD = a.x, SRHD = b })
                        .ToList();

                    if (result.Select(s => s.SRTHD.仕入区分).FirstOrDefault() == CommonConstants.仕入区分.返品.GetHashCode())
                    {
                        // 返品レコードとしてデータを作成
                        var resultRthd =
                            result.Select(x => new T03.T03_SRHD_RT_Extension
                        {
                            伝票番号   = x.SRTHD.伝票番号.ToString(),
                            会社名コード = x.SRTHD.会社名コード.ToString(),
                            仕入日    = x.SRTHD.仕入日,
                            入力区分   = x.SRTHD.入力区分,
                            仕入区分   = x.SRTHD.仕入区分,
                            仕入先コード = x.SRTHD.仕入先コード.ToString(),
                            仕入先枝番  = x.SRTHD.仕入先枝番.ToString(),
                            入荷先コード = x.SRTHD.入荷先コード.ToString(),
                            発注番号   = x.SRTHD.発注番号.ToString(),
                            備考     = x.SRTHD.備考,
                            // No-94 Add Start
                            通常税率対象金額 = x.SRTHD.通常税率対象金額 ?? 0,
                            軽減税率対象金額 = x.SRTHD.軽減税率対象金額 ?? 0,
                            通常税率消費税  = x.SRTHD.通常税率消費税 ?? 0,
                            軽減税率消費税  = x.SRTHD.軽減税率消費税 ?? 0,
                            // No-94 Add End
                            // No-95 Add Start
                            小計  = x.SRTHD.小計 ?? 0,
                            総合計 = x.SRTHD.総合計 ?? 0,
                            // No-95 Add End
                            消費税   = x.SRTHD.消費税,
                            元伝票番号 = x.SRHD == null ? "" : x.SRHD.伝票番号.ToString(),
                            元仕入日  = x.SRHD == null ? (DateTime?)null : x.SRHD.仕入日,
                            データ状態 = false
                        })
                            .ToList();

                        return(resultRthd);
                    }
                    else
                    {
                        // 仕入レコードとしてデータを作成
                        // ①新規伝票番号を取得
                        M88      seqSv     = new M88();
                        int      newSeqNum = seqSv.getNextNumber(CommonConstants.明細番号ID.ID01_売上_仕入_移動, userId);
                        DateTime retDate   = (DateTime)AppCommon.DateTimeToDate(DateTime.Now);

                        var resultSrhd =
                            result.Select(x => new T03.T03_SRHD_RT_Extension
                        {
                            伝票番号   = newSeqNum.ToString(),
                            会社名コード = x.SRTHD.会社名コード.ToString(),
                            仕入日    = retDate,
                            入力区分   = x.SRTHD.入力区分,
                            仕入区分   = CommonConstants.仕入区分.返品.GetHashCode(),
                            仕入先コード = x.SRTHD.仕入先コード.ToString(),
                            仕入先枝番  = x.SRTHD.仕入先枝番.ToString(),
                            入荷先コード = x.SRTHD.入荷先コード.ToString(),
                            発注番号   = x.SRTHD.発注番号.ToString(),
                            備考     = x.SRTHD.備考,
                            // No-94 Add Start
                            通常税率対象金額 = x.SRTHD.通常税率対象金額 ?? 0,
                            軽減税率対象金額 = x.SRTHD.軽減税率対象金額 ?? 0,
                            通常税率消費税  = x.SRTHD.通常税率消費税 ?? 0,
                            軽減税率消費税  = x.SRTHD.軽減税率消費税 ?? 0,
                            // No-94 Add End
                            // No-95 Add Start
                            小計  = x.SRTHD.小計 ?? 0,
                            総合計 = x.SRTHD.総合計 ?? 0,
                            // No-95 Add End
                            消費税   = x.SRTHD.消費税,
                            元伝票番号 = x.SRTHD.伝票番号.ToString(),
                            元仕入日  = x.SRTHD.仕入日,
                            データ状態 = true
                        })
                            .ToList();

                        return(resultSrhd);
                    }
                }
                else
                {
                    return(new List <T03.T03_SRHD_RT_Extension>());
                }
            }
        }
Exemple #14
0
        /// <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;
            }
        }
Exemple #15
0
        public List <SRY10010_Member_CSV> SRY10010_GetData_CSV(string s車輌From, string s車輌To, int?[] i車輌List, string s車輌List, DateTime d集計期間From, DateTime d集計期間To)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                int i集計期間From = AppCommon.IntParse(d集計期間From.ToString("yyyyMM"));
                int i集計期間To   = AppCommon.IntParse(d集計期間To.ToString("yyyyMM"));
                List <SRY10010_Member_CSV> retList = new List <SRY10010_Member_CSV>();
                context.Connection.Open();

                try
                {
                    //var 車輌自社締日 = (from m87 in context.M87_CNTL.Where(m87 => m87.管理ID == 1)
                    //             select new {m87.車輌自社締日}).ToList();
                    ////int iSime = AppCommon.IntParse(車輌自社締日[0].車輌自社締日.ToString());
                    //iSime += 1;
                    //if ((iSime) >= 32)
                    //{
                    //    iSime = 1;
                    //}
                    //if (iSime.ToString().Length == 1){
                    //    if (!DateTime.TryParse(d集計期間From.ToString("yyyy/MM/0") + iSime.ToString(), out d集計期間From))
                    //    {
                    //        return retList;
                    //    }
                    //}
                    //else
                    //{
                    //    if (!DateTime.TryParse(d集計期間From.ToString("yyyy/MM/") + iSime.ToString(), out d集計期間From))
                    //    {
                    //        return retList;
                    //    }
                    //}

                    var query2 = (from s14sb in context.S14_CARSB
                                  join m07 in context.M07_KEI on s14sb.経費項目ID equals m07.経費項目ID into m07Group
                                  select new { s14sb.金額, s14sb.経費項目ID, s14sb.経費項目名, s14sb.固定変動区分, s14sb.更新日時, s14sb.車輌KEY, s14sb.集計年月, s14sb.登録日時, m07Group.FirstOrDefault().経費区分 }
                                  );

                    var query = (from m05 in context.M05_CAR.Where(m05 => m05.削除日付 == null)
                                 join m04 in context.M04_DRV on m05.乗務員KEY equals m04.乗務員KEY into m04Group
                                 join s14 in context.V_S14_CAR.Where(c => c.集計年月 >= i集計期間From && c.集計年月 <= i集計期間To) on m05.車輌KEY equals s14.車輌KEY into s14Group
                                 join s14sb in query2.Where(c => c.集計年月 >= i集計期間From && c.集計年月 <= i集計期間To) on m05.車輌KEY equals s14sb.車輌KEY into s14sbGroup
                                 select new SRY10010_Member_CSV
                    {
                        コード = m05.車輌ID,
                        車輌番号 = m05.車輌番号,
                        廃車日 = m05.廃車日,
                        乗務員名 = m04Group.FirstOrDefault().乗務員名,
                        収入日数 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : Math.Round(s14Group.Sum(c => c.運送収入) / s14Group.Sum(c => c.稼動日数), 0),
                        収入時間 = (s14Group.Sum(c => c.拘束時間) * 60) == 0 ? 0 : Math.Round((s14Group.Sum(c => c.運送収入)) / (decimal)((s14Group.Sum(c => c.拘束時間)) / 60), 0),
                        収入KM = s14Group.Sum(c => c.走行KM) == 0 ? 0 : Math.Round(s14Group.Sum(c => c.運送収入) / s14Group.Sum(c => c.走行KM), 0),
                        収入屯数 = s14Group.Sum(c => c.輸送屯数) == 0 ? 0 : Math.Round(s14Group.Sum(c => c.運送収入) / s14Group.Sum(c => c.輸送屯数), 0),
                        固定費日数 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : Math.Round(s14sbGroup.Where(c => c.固定変動区分 == 0).Sum(c => c.金額) / s14Group.Sum(c => c.稼動日数), 0),
                        動費KM = s14Group.Sum(c => c.走行KM) == 0 ? 0 : Math.Round(s14sbGroup.Where(c => c.固定変動区分 == 1).Sum(c => c.金額) / s14Group.Sum(c => c.走行KM), 0),
                        修理日数 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : Math.Round(s14sbGroup.Where(c => c.経費項目ID == s14sbGroup.Where(d => d.経費区分 == 5).Min(d => d.経費項目ID)).Sum(c => c.金額) / s14Group.Sum(c => c.稼動日数), 0),
                        修理KM = s14Group.Sum(c => c.走行KM) == 0 ? 0 : Math.Round(s14sbGroup.Where(c => c.経費項目ID == s14sbGroup.Where(d => d.経費区分 == 5).Min(d => d.経費項目ID)).Sum(c => c.金額) / s14Group.Sum(c => c.走行KM), 0),
                        益日数 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : Math.Round((s14Group.Sum(c => c.運送収入) - s14sbGroup.Sum(c => c.金額)) / s14Group.Sum(c => c.稼動日数), 0),
                        益KM = s14Group.Sum(c => c.走行KM) == 0 ? 0 : Math.Round((s14Group.Sum(c => c.運送収入) - s14sbGroup.Sum(c => c.金額)) / s14Group.Sum(c => c.走行KM), 0),
                        稼働率 = s14Group.Sum(c => c.稼動日数) == 0 ? 0 : Math.Round((decimal)(s14Group.Sum(c => c.拘束時間) / (s14Group.Sum(c => c.稼動日数) * 1440)), 2),
                    }).AsQueryable();

                    query = query.Distinct();
                    int i車輌FROM;
                    int i車輌TO;
                    //部門From処理 Min値
                    if (!string.IsNullOrEmpty(s車輌From))
                    {
                        i車輌FROM = AppCommon.IntParse(s車輌From);
                    }
                    else
                    {
                        i車輌FROM = int.MinValue;
                    }

                    //部門To処理 Max値
                    if (!string.IsNullOrEmpty(s車輌To))
                    {
                        i車輌TO = AppCommon.IntParse(s車輌To);
                    }
                    else
                    {
                        i車輌TO = int.MaxValue;
                    }

                    var intCause = i車輌List;
                    if (string.IsNullOrEmpty(s車輌From + s車輌To))
                    {
                        if (i車輌List.Length > 0)
                        {
                            query = query.Where(q => intCause.Contains(q.コード));
                        }
                    }
                    else
                    {
                        if (i車輌List.Length > 0)
                        {
                            query = query.Where(q => intCause.Contains(q.コード) || (q.コード >= i車輌FROM && q.コード <= i車輌TO));
                        }
                        else
                        {
                            query = query.Where(q => (q.コード >= i車輌FROM && q.コード <= i車輌TO));
                        }
                    }

                    query   = query.Distinct();
                    retList = query.Where(c => c.廃車日 == null || ((((DateTime)c.廃車日).Year * 100 + ((DateTime)c.廃車日).Month) >= i集計期間From)).ToList();
                    return(retList);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #16
0
        /// <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);
        }
Exemple #17
0
        /// <summary>
        /// NNG06010 印刷
        /// </summary>
        /// <param name="p商品ID">部門コード</param>
        /// <returns>T01</returns>
        public List <NNG06010_Member_CSV> GetDataList_CSV(string p部門From, string p部門To, int?[] i部門List, int p作成締日, DateTime d集計期間From, DateTime d集計期間To, string p作成年度, string s部門List, int i表示順)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                List <NNG06010_Member_CSV> retList = new List <NNG06010_Member_CSV>();
                context.Connection.Open();

                int[] lst;
                lst = (from m71 in context.M71_BUM
                       let t01l = from t01 in context.T01_TRN.Where(t01 => (t01.請求日付 >= d集計期間From && t01.請求日付 <= d集計期間To) && (t01.入力区分 != 3 || (t01.入力区分 == 3 && t01.明細行 == 1))) select t01.自社部門ID
                                  where t01l.Contains(m71.自社部門ID)
                                  select m71.自社部門ID).ToArray();

                var query = (from m71 in context.M71_BUM
                             join t01 in context.T01_TRN.Where(t01 => (t01.請求日付 >= d集計期間From && t01.請求日付 <= d集計期間To) && (t01.入力区分 != 3 || (t01.入力区分 == 3 && t01.明細行 == 1))) on m71.自社部門ID equals t01.自社部門ID into t01Group
                             where t01Group.Where(t01 => t01.自社部門ID == m71.自社部門ID).Any() == true
                             select new NNG06010_Member_CSV
                {
                    コード = m71.自社部門ID,
                    部門名 = m71.自社部門名,
                    売上金額 = t01Group.Sum(t01 => t01.売上金額) == null ? 0 : t01Group.Sum(t01 => t01.売上金額),
                    割増1 = t01Group.Sum(t01 => t01.請求割増1) == null ? 0 : t01Group.Sum(t01 => t01.請求割増1),
                    割増2 = t01Group.Sum(t01 => t01.請求割増2) == null ? 0 : t01Group.Sum(t01 => t01.請求割増2),
                    通行料 = t01Group.Sum(t01 => t01.通行料) == null ? 0 : t01Group.Sum(t01 => t01.通行料),
                    売上合計 = t01Group.Sum(t01 => t01.売上金額 + t01.請求割増1 + t01.請求割増2 + t01.通行料) == null ? 0 : t01Group.Sum(t01 => t01.売上金額 + t01.請求割増1 + t01.請求割増2 + t01.通行料),
                    傭車使用売上 = t01Group.Where(t01gr => t01gr.支払先KEY > 0).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2 + t01gr.通行料),
                    支払金額 = t01Group.Where(t01gr => t01gr.支払先KEY > 0).Sum(t01gr => t01gr.支払金額),
                    支払通行料 = t01Group.Where(t01gr => t01gr.支払先KEY > 0).Sum(t01gr => t01gr.支払通行料),
                    差益 = t01Group.Where(t01gr => t01gr.支払先KEY > 0).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2 + t01gr.通行料 - t01gr.支払金額 - t01gr.支払通行料),
                    差益率 = t01Group.Where(t01gr => t01gr.支払先KEY > 0).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2 + t01gr.通行料) == 0 ? 0 :
                          Math.Round((decimal)t01Group.Where(t01gr => t01gr.支払先KEY > 0).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2 + t01gr.通行料 - t01gr.支払金額 - t01gr.支払通行料) / t01Group.Where(t01gr => t01gr.支払先KEY > 0).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2 + t01gr.通行料), 2),
                    件数 = t01Group.Count(),
                    未定件数 = t01Group.Count(t01gr => t01gr.売上未定区分 == 1),

                    かな読み = m71.かな読み,
                }).AsQueryable();


                int i部門FROM;
                int i部門TO;
                //部門From処理 Min値
                if (!string.IsNullOrEmpty(p部門From))
                {
                    i部門FROM = AppCommon.IntParse(p部門From);
                }
                else
                {
                    i部門FROM = int.MinValue;
                }

                //部門To処理 Max値
                if (!string.IsNullOrEmpty(p部門To))
                {
                    i部門TO = AppCommon.IntParse(p部門To);
                }
                else
                {
                    i部門TO = int.MaxValue;
                }

                var intCause = i部門List;
                if (string.IsNullOrEmpty(p部門From + p部門To))
                {
                    if (i部門List.Length > 0)
                    {
                        query = query.Where(q => intCause.Contains(q.コード));
                    }
                }
                else
                {
                    if (i部門List.Length > 0)
                    {
                        query = query.Where(q => intCause.Contains(q.コード) || (q.コード >= i部門FROM && q.コード <= i部門TO));
                    }
                    else
                    {
                        query = query.Where(q => (q.コード >= i部門FROM && q.コード <= i部門TO));
                    }
                }

                //表示順序処理
                switch (i表示順)
                {
                case 0:
                    query = query.OrderBy(c => c.コード);
                    break;

                case 1:
                    query = query.OrderBy(c => c.かな読み);
                    break;

                case 2:
                    query = query.OrderByDescending(c => c.売上金額);
                    break;
                }

                //結果をリスト化
                query   = query.Distinct();
                retList = query.ToList();
                return(retList);
            }
        }
Exemple #18
0
        /// <summary>
        /// JMI06010 印刷
        /// </summary>
        /// <param name="p商品ID">乗務員コード</param>
        /// <returns>T01</returns>
        public List <JMI06010_Member_CSV> GetDataList_CSV(string p乗務員From, string p乗務員To, int?[] i乗務員List, int p作成締日, DateTime d集計期間From, DateTime d集計期間To, string p作成年度, string s乗務員List)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                int drvfrom = AppCommon.IntParse(p乗務員From) == 0 ? int.MinValue : AppCommon.IntParse(p乗務員From);
                int drvto   = AppCommon.IntParse(p乗務員To) == 0 ? int.MaxValue : AppCommon.IntParse(p乗務員To);
                if ((string.IsNullOrEmpty(p乗務員From + p乗務員To) && i乗務員List.Length != 0))
                {
                    drvfrom = int.MaxValue;
                    drvto   = int.MaxValue;
                }

                List <JMI06010_Member_CSV> retList  = new List <JMI06010_Member_CSV>();
                List <JMI06010_Date>       retList2 = new List <JMI06010_Date>();

                context.Connection.Open();

                for (DateTime dDate = d集計期間From; dDate <= d集計期間To; dDate = dDate.AddDays(1))
                {
                    retList2.Add(new JMI06010_Date()
                    {
                        日付 = dDate
                    });
                }

                int[] lst;
                lst = (from m04 in context.M04_DRV
                       let t01l = from t01 in context.T01_TRN.Where(t01 => (t01.請求日付 >= d集計期間From && t01.請求日付 <= d集計期間To) && (t01.入力区分 != 3 || (t01.入力区分 == 3 && t01.明細行 != 1))) select t01.乗務員KEY
                                  let t02l = from t02 in context.V_T02_UTRN.Where(t02 => t02.労務日 >= d集計期間From && t02.労務日 <= d集計期間To) select t02.乗務員KEY
                                             let t03l = from t03 in context.T03_KTRN.Where(t03 => t03.経費発生日 >= d集計期間From && t03.経費発生日 <= d集計期間To) select t03.乗務員KEY
                                                        where t01l.Contains(m04.乗務員KEY) || t02l.Contains(m04.乗務員KEY) || t03l.Contains(m04.乗務員KEY)
                                                        select m04.乗務員KEY).ToArray();

                var query2 = (from t in context.T03_KTRN
                              join m07 in context.M07_KEI on t.経費項目ID equals m07.経費項目ID
                              where m07.固定変動区分 == 1
                              select new JMI06010_KTRN
                {
                    日付 = t.経費発生日,
                    経費項目ID = t.経費項目ID,
                    金額 = t.金額,
                    乗務員KEY = t.乗務員KEY,
                }).AsQueryable();

                var query = (from retdate in retList2
                             from m04 in context.M04_DRV.Where(c => (c.乗務員ID >= drvfrom && c.乗務員ID <= drvto || (i乗務員List.Contains(c.乗務員ID))))
                             join t01 in context.T01_TRN.Where(t01 => (t01.請求日付 >= d集計期間From && t01.請求日付 <= d集計期間To) && (t01.入力区分 != 3 || (t01.入力区分 == 3 && t01.明細行 != 1))) on retdate.日付 equals t01.請求日付 into t01Group
                             join t02 in context.V_T02_UTRN.Where(t02 => t02.労務日 >= d集計期間From && t02.労務日 <= d集計期間To) on retdate.日付 equals t02.労務日 into t02Group
                             join t03 in query2.Where(t03 => t03.日付 >= d集計期間From && t03.日付 <= d集計期間To) on retdate.日付 equals t03.日付 into t03Group
                             let t01l = from t01 in context.T01_TRN.Where(t01 => t01.請求日付 >= d集計期間From && t01.請求日付 <= d集計期間To) select t01.乗務員KEY
                                        let t02l = from t02 in context.V_T02_UTRN.Where(t02 => t02.労務日 >= d集計期間From && t02.労務日 <= d集計期間To) select t02.乗務員KEY
                                                   let t03l = from t03 in context.T03_KTRN.Where(t03 => t03.経費発生日 >= d集計期間From && t03.経費発生日 <= d集計期間To) select t03.乗務員KEY
                                                              where lst.Contains(m04.乗務員KEY)
                                                              //where t01l.Contains(m04.乗務員KEY) || t02l.Contains(m04.乗務員KEY) || t03l.Contains(m04.乗務員KEY)
                                                              orderby m04.乗務員ID, retdate.日付
                             select new JMI06010_Member_CSV
                {
                    日付 = retdate.日付,
                    売上金額 = t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2) == null ? 0 : t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2),
                    通行料 = t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.通行料) == null ? 0 : t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.通行料),
                    売上合計 = t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2 + t01gr.通行料) == null ? 0 : t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2 + t01gr.通行料),
                    社内金額 = t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付 && t01gr.支払先KEY == null).Sum(t01 => t01.支払金額) == null ? 0 : t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付 && t01gr.支払先KEY == null).Sum(t01 => t01.支払金額),
                    歩合金額 = Math.Round((t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付 && t01gr.支払先KEY == null).Sum(t01 => t01.支払金額) * m04.歩合率 / 100), 0) == null ? 0 : Math.Round((t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付 && t01gr.支払先KEY == null).Sum(t01 => t01.支払金額) * m04.歩合率 / 100), 0),
                    経費合計 = t03Group.Where(t03gr => t03gr.乗務員KEY == m04.乗務員KEY && t03gr.日付 == retdate.日付).Sum(t03gr => t03gr.金額),
                    拘束H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.拘束時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.拘束時間),
                    運転H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.運転時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.運転時間),
                    高速H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.高速時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.高速時間),
                    作業H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.作業時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.作業時間),
                    待機H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.待機時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.待機時間),
                    休憩H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.休憩時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.休憩時間),
                    残業H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.残業時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.残業時間),
                    深夜H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.深夜時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.深夜時間),
                    走行KM = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.走行KM) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.走行KM),
                    実車KM = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.実車KM) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.実車KM),
                    コード = m04.乗務員ID,
                    乗務員名 = m04.乗務員名,
                    歩合率 = m04.歩合率,
                }).AsQueryable();



                //if (!(string.IsNullOrEmpty(p乗務員From + p乗務員To) && i乗務員List.Length == 0))
                //{

                //	//乗務員が検索対象に入っていない時全データ取得
                //	if (string.IsNullOrEmpty(p乗務員From + p乗務員To))
                //	{
                //		query = query.Where(c => c.コード >= int.MaxValue);
                //	}

                //	//乗務員From処理 Min値
                //	if (!string.IsNullOrEmpty(p乗務員From))
                //	{
                //		int i乗務員FROM = AppCommon.IntParse(p乗務員From);
                //		query = query.Where(c => c.コード >= i乗務員FROM);
                //	}

                //	//乗務員To処理 Max値
                //	if (!string.IsNullOrEmpty(p乗務員To))
                //	{
                //		int i乗務員TO = AppCommon.IntParse(p乗務員To);
                //		query = query.Where(c => c.コード <= i乗務員TO);
                //	}


                //	if (i乗務員List.Length > 0)
                //	{
                //		var intCause = i乗務員List;

                //		query = query.Union(from retdate in retList2
                //							from m04 in context.M04_DRV
                //							join t01 in context.T01_TRN.Where(t01 => (t01.請求日付 >= d集計期間From && t01.請求日付 <= d集計期間To) && (t01.入力区分 != 3 || (t01.入力区分 == 3 && t01.明細行 != 1))) on retdate.日付 equals t01.請求日付 into t01Group
                //							join t02 in context.V_T02_UTRN.Where(t02 => t02.労務日 >= d集計期間From && t02.労務日 <= d集計期間To) on retdate.日付 equals t02.労務日 into t02Group
                //							join t03 in query2.Where(t03 => t03.日付 >= d集計期間From && t03.日付 <= d集計期間To) on retdate.日付 equals t03.日付 into t03Group
                //							let t01l = from t01 in context.T01_TRN.Where(t01 => t01.請求日付 >= d集計期間From && t01.請求日付 <= d集計期間To) select t01.乗務員KEY
                //							let t02l = from t02 in context.V_T02_UTRN.Where(t02 => t02.労務日 >= d集計期間From && t02.労務日 <= d集計期間To) select t02.乗務員KEY
                //							let t03l = from t03 in context.T03_KTRN.Where(t03 => t03.経費発生日 >= d集計期間From && t03.経費発生日 <= d集計期間To) select t03.乗務員KEY
                //							where lst.Contains(m04.乗務員KEY) && intCause.Contains(m04.乗務員ID)
                //							//where t01l.Contains(m04.乗務員KEY) || t02l.Contains(m04.乗務員KEY) || t03l.Contains(m04.乗務員KEY)
                //							orderby m04.乗務員ID, retdate.日付
                //							select new JMI06010_Member_CSV
                //							{
                //								日付 = retdate.日付,
                //								売上金額 = t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2) == null ? 0 : t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2),
                //								通行料 = t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.通行料) == null ? 0 : t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.通行料),
                //								売上合計 = t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2 + t01gr.通行料) == null ? 0 : t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付).Sum(t01gr => t01gr.売上金額 + t01gr.請求割増1 + t01gr.請求割増2 + t01gr.通行料),
                //								社内金額 = t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付 && t01gr.支払先KEY == null).Sum(t01 => t01.支払金額) == null ? 0 : t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付 && t01gr.支払先KEY == null).Sum(t01 => t01.支払金額),
                //								歩合金額 = Math.Round((t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付 && t01gr.支払先KEY == null).Sum(t01 => t01.支払金額) * m04.歩合率 / 100), 0) == null ? 0 : Math.Round((t01Group.Where(t01gr => t01gr.乗務員KEY == m04.乗務員KEY && t01gr.請求日付 == retdate.日付 && t01gr.支払先KEY == null).Sum(t01 => t01.支払金額) * m04.歩合率 / 100), 0),
                //								経費合計 = t03Group.Where(t03gr => t03gr.乗務員KEY == m04.乗務員KEY && t03gr.日付 == retdate.日付).Sum(t03gr => t03gr.金額),
                //								拘束H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.拘束時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.拘束時間),
                //								運転H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.運転時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.運転時間),
                //								高速H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.高速時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.高速時間),
                //								作業H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.作業時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.作業時間),
                //								待機H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.待機時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.待機時間),
                //								休憩H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.休憩時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.休憩時間),
                //								残業H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.残業時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.残業時間),
                //								深夜H = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.深夜時間) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.深夜時間),
                //								走行KM = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.走行KM) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.走行KM),
                //								実車KM = t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.実車KM) == null ? 0 : t02Group.Where(t02gr => t02gr.乗務員KEY == m04.乗務員KEY && t02gr.労務日 == retdate.日付).Sum(t02gr => t02gr.実車KM),
                //								コード = m04.乗務員ID,
                //								乗務員名 = m04.乗務員名,
                //								歩合率 = m04.歩合率,

                //							});
                //	}
                //	else
                //	{
                //		query = query.Where(c => c.コード > int.MinValue && c.コード < int.MaxValue);
                //	}

                //}

                query = query.Distinct();
                //結果をリスト化

                retList = (from q in query.ToArray()
                           orderby q.コード, q.日付
                           select new JMI06010_Member_CSV
                {
                    日付 = q.日付,
                    売上金額 = q.売上金額,
                    通行料 = q.通行料,
                    売上合計 = q.売上合計,
                    社内金額 = q.社内金額,
                    歩合金額 = q.歩合金額,
                    経費合計 = q.経費合計,
                    拘束H = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.拘束H),
                    運転H = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.運転H),
                    高速H = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.高速H),
                    作業H = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.作業H),
                    待機H = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.待機H),
                    休憩H = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.休憩H),
                    残業H = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.残業H),
                    深夜H = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.深夜H),
                    走行KM = q.走行KM,
                    実車KM = q.実車KM,
                    コード = q.コード,
                    乗務員名 = q.乗務員名,
                    歩合率 = q.歩合率,
                }).ToList();
                return(retList);
            }
        }
Exemple #19
0
        /// <summary>
        /// 在庫データ取得
        /// </summary>
        /// <param name="context">TRAC3Entities</param>
        /// <param name="pMyCompany">自社コード</param>
        /// <param name="pStocktakingDate">棚卸日</param>
        /// <param name="pParamDic">パラメータ辞書</param>
        public List <StocktakingDataMember> GetStockList(TRAC3Entities context, int pMyCompany, string pStocktakingDate, Dictionary <string, string> pParamDic)
        {
            DateTime dteStocktaking = DateTime.Parse(pStocktakingDate);

            // ---------------------------
            // 情報取得
            // ---------------------------
            // 棚卸在庫情報(品番マスタ,倉庫マスタ,在庫テーブル)

            List <StocktakingDataMember> retResult = new List <StocktakingDataMember>();

            var stockList =
                context.S03_STOK.Where(w => w.削除日時 == null)
                .Join(context.M22_SOUK.Where(w => w.削除日時 == null && w.場所会社コード == pMyCompany), x => x.庫コード, y => y.庫コード, (x, y) => new { STOK = x, SOUK = y })
                .Join(context.M09_HIN.Where(w => w.削除日時 == null), x => x.STOK.品番コード, y => y.品番コード, (x, y) => new { x.STOK, x.SOUK, HIN = y })
                .GroupJoin(context.S10_STOCKTAKING.Where(w => w.棚卸日 == dteStocktaking && w.更新済みFLG == 1 && w.削除日時 == null),
                           x => new { 庫コード = x.STOK.庫コード, 品番コード = x.STOK.品番コード, 賞味期限 = x.STOK.賞味期限 },
                           y => new { 庫コード = y.庫コード, 品番コード = y.品番コード, 賞味期限 = y.賞味期限 },
                           (x, y) => new { x, y })
                .SelectMany(x => x.y.DefaultIfEmpty(), (a, b) => new { a.x.STOK, a.x.SOUK, a.x.HIN, STOCKTAKING = b })
                .GroupJoin(context.M06_IRO.Where(w => w.削除日時 == null), x => x.HIN.自社色, y => y.色コード, (x, y) => new { x, y })
                .SelectMany(x => x.y.DefaultIfEmpty(), (e, f) => new { e.x.STOK, e.x.SOUK, e.x.HIN, e.x.STOCKTAKING, IRO = f })
                .GroupJoin(context.M14_BRAND.Where(w => w.削除日時 == null), x => x.HIN.ブランド, y => y.ブランドコード, (x, y) => new { x, y })
                .SelectMany(x => x.y.DefaultIfEmpty(), (g, h) => new { g.x.STOK, g.x.SOUK, g.x.HIN, g.x.STOCKTAKING, g.x.IRO, BRAND = h })
                .GroupJoin(context.M15_SERIES.Where(w => w.削除日時 == null), x => x.HIN.シリーズ, y => y.シリーズコード, (x, y) => new { x, y })
                .SelectMany(x => x.y.DefaultIfEmpty(), (i, j) => new { i.x.STOK, i.x.SOUK, i.x.HIN, i.x.STOCKTAKING, i.x.IRO, i.x.BRAND, SERIES = j })
                .Where(c => c.STOCKTAKING == null)
                .AsQueryable();


            #region 入力項目による絞込

            // 倉庫の条件チェック
            string Warehouse = pParamDic["倉庫コード"];
            if (string.IsNullOrEmpty(Warehouse) == false)
            {
                int iWarehouse = int.Parse(Warehouse);
                stockList = stockList.Where(w => w.STOK.庫コード == iWarehouse);
            }

            #endregion

            // ---------------------------
            // 出力形式に成型
            // ---------------------------
            retResult = stockList
                        .Select(s => new StocktakingDataMember
            {
                棚卸日   = dteStocktaking,
                庫コード  = s.STOK.庫コード,
                庫名    = s.SOUK.庫略称名,
                品番コード = s.STOK.品番コード,
                自社品番  = s.HIN.自社品番,
                自社品名  = s.HIN.自社品名,
                シリーズ  = s.SERIES == null ? null : s.SERIES.シリーズコード,
                ブランド  = s.BRAND == null ? null : s.BRAND.ブランドコード,
                自社色   = s.IRO == null ? null : s.IRO.色名称,
                賞味期限  = s.STOK.賞味期限,

                数量       = s.STOK == null ? 0 : s.STOK.在庫数,
                単位       = s.HIN.単位,
                実在庫数     = 0,
                品番追加FLG  = 0,
                更新済みFLG  = 0,
                商品分類     = s.HIN.商品分類,
                新規データFLG = true,
                行追加FLG   = false,
            })
                        .ToList();

            DateTime maxDate = AppCommon.GetMaxDate();

            foreach (var row in retResult)
            {
                row.表示用賞味期限 = maxDate == row.賞味期限 ? "" : row.賞味期限.ToString("yyyy/MM/dd");
            }

            return(retResult);
        }
Exemple #20
0
        /// <summary>
        /// TKS11010 締日帳票CSV
        /// </summary>
        /// <param name="p商品ID">得意先コード</param>
        /// <returns>S02</returns>
        public List <TKS11010_Member_CSV> SEARCH_TKS11010_GetDataList_CSV(string p得意先From, string p得意先To, int?[] i得意先List, string p作成集金日, bool b全集金日, string p作成年, string p作成月, int 作成区分_CValue, int?集計, DateTime?d集計期間From, DateTime?d集計期間To)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                List <TKS11010_Member_CSV> retList   = new List <TKS11010_Member_CSV>();
                List <TKS11010_Member_CSV> queryList = new List <TKS11010_Member_CSV>();
                context.Connection.Open();

                //支払先指定 表示用
                string 得意先指定表示 = string.Empty;
                //サイト計算
                var query2 = (from m01 in context.M01_TOK.Where(m01 => m01.削除日付 == null && m01.親子区分ID != 3)
                              select new TKS11010_Member2
                {
                    得意先ID = m01.得意先ID,
                    得意先名 = m01.略称名,
                    得意先KEY = m01.得意先KEY,
                    サイト = m01.Tサイト日,
                    締日 = m01.T締日,
                    集金日 = m01.T集金日,
                    親子区分ID = m01.親子区分ID,
                    作成年月 = 集計 ?? 0,
                }).ToList();

                DateTime d集計年月 = DateTime.Now;
                for (int i = 0; i < query2.Count; i++)
                {
                    if (DateTime.TryParse(((p作成年).ToString() + "/" + (p作成月).ToString() + "/" + "01"), out d集計年月))
                    {
                        query2[i].年月 = ((d集計年月.AddMonths(Convert.ToInt32(-query2[i].サイト)).Year) * 100) + (d集計年月.AddMonths(Convert.ToInt32(-query2[i].サイト)).Month);
                    }
                    ;
                }
                ;

                var query = (from q01 in query2
                             join v01 in context.S01_TOKS on new { q01.得意先KEY, nen = q01.年月 } equals new { v01.得意先KEY, nen = v01.集計年月 } into v01Group
                             join nyukin in context.S01_TOKS on new { q01.得意先KEY, nen = q01.作成年月 } equals new { nyukin.得意先KEY, nen = nyukin.集計年月 } into nyukinGroup
                             select new TKS11010_Member_CSV
                {
                    得意先コード = q01.得意先ID,
                    得意先名 = q01.得意先名,
                    親子区分ID = q01.親子区分ID == 0 ? "" : q01.親子区分ID == 1 ? "親" : q01.親子区分ID == 2 ? "親" : "子",
                    集金日 = q01.集金日 == null ? 0 : q01.集金日,
                    サイト = q01.サイト == null ? 0 : q01.サイト,
                    売上金額 = v01Group.Sum(v01g => v01g.締日売上金額),
                    内課税額 = v01Group.Sum(v01g => v01g.締日課税売上),
                    消費税 = v01Group.Sum(v01g => v01g.締日消費税),
                    通行料 = v01Group.Sum(v01g => v01g.締日通行料),
                    回収予定額 = v01Group.Sum(v01g => v01g.締日売上金額 + v01g.締日通行料 + v01g.締日消費税),
                    請求年月 = null,
                    締日 = q01.締日 == null ? 0 : q01.締日,
                    当月入金額 = nyukinGroup.Sum(c => c.締日入金現金 + c.締日入金手形),
                    入金調整額 = nyukinGroup.Sum(c => c.締日入金その他),
                    入金合計額 = nyukinGroup.Sum(c => c.締日入金現金 + c.締日入金手形 + c.締日入金その他),
                    集計年月 = q01.年月,
                    全集金日 = p作成集金日 == string.Empty ? "全集金日" : p作成集金日,
                    対象年月 = d集計期間From,
                    表示区分 = 作成区分_CValue == 0 ? "(回収予定あり得意先のみ)" : 作成区分_CValue == 1 ? "(回収予定無し得意先含む)" : "",
                }).AsQueryable();

                if (!(string.IsNullOrEmpty(p得意先From + p得意先To) && i得意先List.Length == 0))
                {
                    //得意先が検索対象に入っていない時全データ取得
                    if (string.IsNullOrEmpty(p得意先From + p得意先To))
                    {
                        query = query.Where(c => c.得意先コード >= int.MaxValue);
                    }

                    //得意先From処理 Min値
                    if (!string.IsNullOrEmpty(p得意先From))
                    {
                        int i支払先FROM = AppCommon.IntParse(p得意先From);
                        query = query.Where(c => c.得意先コード >= i支払先FROM);
                    }

                    //得意先To処理 Max値
                    if (!string.IsNullOrEmpty(p得意先To))
                    {
                        int i支払先TO = AppCommon.IntParse(p得意先To);
                        query = query.Where(c => c.得意先コード <= i支払先TO);
                    }

                    //全締日集計処理
                    if (b全集金日 == true)
                    {
                        query = query.Where(c => c.集金日 >= 1 && c.集金日 <= 31);
                    }

                    //締日処理 
                    if (!string.IsNullOrEmpty(p作成集金日))
                    {
                        int?p変換作成締日 = AppCommon.IntParse(p作成集金日);
                        query = query.Where(c => c.集金日 == p変換作成締日);
                    }

                    if (i得意先List.Length > 0)
                    {
                        var intCause = i得意先List;
                        query = query.Union(from q01 in query2
                                            join v01 in context.S01_TOKS on new { q01.得意先KEY, nen = q01.年月 } equals new { v01.得意先KEY, nen = v01.集計年月 } into v01Group
                                            join nyukin in context.S01_TOKS on new { q01.得意先KEY, nen = q01.作成年月 } equals new { nyukin.得意先KEY, nen = nyukin.集計年月 } into nyukinGroup
                                            where intCause.Contains(q01.得意先ID)
                                            select new TKS11010_Member_CSV
                        {
                            得意先コード = q01.得意先ID,
                            得意先名   = q01.得意先名,
                            親子区分ID = q01.親子区分ID == 0 ? "" : q01.親子区分ID == 1 ? "親" : q01.親子区分ID == 2 ? "親" : "子",
                            集金日    = q01.集金日 == null ? 0 : q01.集金日,
                            サイト    = q01.サイト == null ? 0 : q01.サイト,
                            売上金額   = v01Group.Sum(v01g => v01g.締日売上金額),
                            内課税額   = v01Group.Sum(v01g => v01g.締日課税売上),
                            消費税    = v01Group.Sum(v01g => v01g.締日消費税),
                            通行料    = v01Group.Sum(v01g => v01g.締日通行料),
                            回収予定額  = v01Group.Sum(v01g => v01g.締日売上金額 + v01g.締日通行料 + v01g.締日消費税),
                            請求年月   = null,
                            締日     = q01.締日 == null ? 0 : q01.締日,
                            当月入金額  = nyukinGroup.Sum(c => c.締日入金現金 + c.締日入金手形),
                            入金調整額  = nyukinGroup.Sum(c => c.締日入金その他),
                            入金合計額  = nyukinGroup.Sum(c => c.締日入金現金 + c.締日入金手形 + c.締日入金その他),
                            集計年月   = q01.年月,
                            全集金日   = p作成集金日 == string.Empty ? "全集金日" : p作成集金日,
                            対象年月   = d集計期間From,
                            表示区分   = 作成区分_CValue == 0 ? "(回収予定あり得意先のみ)" : 作成区分_CValue == 1 ? "(回収予定無し得意先含む)" : "",
                        }).AsQueryable();

                        //全締日集計処理
                        if (b全集金日 == true)
                        {
                            query = query.Where(c => c.集金日 >= 1 && c.集金日 <= 31);
                        }

                        //締日処理 
                        if (!string.IsNullOrEmpty(p作成集金日))
                        {
                            int?p変換作成締日 = AppCommon.IntParse(p作成集金日);
                            query = query.Where(c => c.集金日 == p変換作成締日);
                        }
                    }
                }
                else
                {
                    //得意先From処理 Min値
                    if (string.IsNullOrEmpty(p得意先From))
                    {
                        query = query.Where(c => c.得意先コード >= int.MinValue);
                    }

                    //得意先To処理 Max値
                    if (string.IsNullOrEmpty(p得意先To))
                    {
                        query = query.Where(c => c.得意先コード <= int.MaxValue);
                    }

                    //全締日集計処理
                    if (b全集金日 == true)
                    {
                        query = query.Where(c => c.集金日 >= 1 && c.集金日 <= 31);
                    }

                    //締日処理
                    if (!string.IsNullOrEmpty(p作成集金日))
                    {
                        int?p変換作成締日 = AppCommon.IntParse(p作成集金日);
                        query = query.Where(c => c.集金日 == p変換作成締日);
                    }
                }

                //内訳別表示処理
                //売上あり:0
                //売上なし:1
                switch (作成区分_CValue)
                {
                //支払取引全体
                case 0:
                    query = query.Where(c => c.回収予定額 != 0);
                    break;

                //支払先
                case 1:
                    //query = query.Where(c => c.回収予定額 >= 0);
                    break;

                default:
                    break;
                }

                //支払先指定の表示
                if (i得意先List.Length > 0)
                {
                    for (int i = 0; i < query.Count(); i++)
                    {
                        得意先指定表示 = 得意先指定表示 + i得意先List[i].ToString();

                        if (i < i得意先List.Length)
                        {
                            if (i == i得意先List.Length - 1)
                            {
                                break;
                            }
                            得意先指定表示 = 得意先指定表示 + ",";
                        }
                        if (i得意先List.Length == 1)
                        {
                            break;
                        }
                    }
                }

                List <TKS11010_Member_CSV> queryLIST = new List <TKS11010_Member_CSV>();
                queryLIST = query.ToList();

                for (int i = 0; i < queryLIST.Count(); i++)
                {
                    if (queryLIST[i].請求年月 == null)
                    {
                        if (queryLIST[i].サイト != null)
                        {
                            DateTime Wk;
                            Wk = DateTime.TryParse(p作成年 + "/" + p作成月 + "/" + "01", out Wk) ? Wk : DateTime.Today;
                            DateTime dtBirth = Wk;
                            dtBirth           = dtBirth.AddMonths(Convert.ToInt32(-queryLIST[i].サイト));
                            queryLIST[i].請求年月 = dtBirth;
                        }
                    }
                }
                return(queryLIST.ToList());
            }
        }
Exemple #21
0
        /// <summary>
        /// JMI02010 印刷
        /// </summary>
        /// <param name="p商品ID">乗務員コード</param>
        /// <returns>T01</returns>
        public List <JMI02010_Member_CSV> GetDataList_CSV(string p乗務員From, string p乗務員To, int?[] i乗務員List, int p作成締日, DateTime d集計期間From, DateTime d集計期間To, int p作成年度)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                DataTable tbl = new DataTable();
                List <JMI02010_Member_CSV> retList = new List <JMI02010_Member_CSV>();

                ////テストリスト型LINQ組込テスト
                //List<JMI> retList2 = new List<JMI>();
                //retList2.Add(new JMI() { 日付 = DateTime.Now, day=1 });


                context.Connection.Open();

                ////テストリスト型LINQ組込テスト
                //var querymtest = (from m07 in context.M07_KEI
                //                from rr2 in retList2
                //                select new JMI02010_M07
                //                {
                //                    経費ID = m07.経費項目ID,
                //                    経費名 = m07.経費項目名,
                //                }).ToList();


                //全件表示
                var querym07 = (from m07 in context.M07_KEI
                                select new JMI02010_M07
                {
                    経費ID = m07.経費項目ID,
                    経費名 = m07.経費項目名,
                }).ToList();

                var    querywhere = querym07.Where(x => x.経費ID == 601).ToList();
                string KEI1       = querywhere[0].経費名.ToString();
                querywhere = querym07.Where(x => x.経費ID == 602).ToList();
                string KEI2 = querywhere[0].経費名.ToString();
                querywhere = querym07.Where(x => x.経費ID == 603).ToList();
                string KEI3 = querywhere[0].経費名.ToString();
                querywhere = querym07.Where(x => x.経費ID == 604).ToList();
                string KEI4 = querywhere[0].経費名.ToString();
                querywhere = querym07.Where(x => x.経費ID == 605).ToList();
                string KEI5 = querywhere[0].経費名.ToString();
                querywhere = querym07.Where(x => x.経費ID == 606).ToList();
                string KEI6 = querywhere[0].経費名.ToString();
                querywhere = querym07.Where(x => x.経費ID == 607).ToList();
                string KEI7 = querywhere[0].経費名.ToString();



                var query = (from t02 in context.T02_UTRN.Where(x => x.勤務開始日 >= d集計期間From && x.勤務開始日 <= d集計期間To)
                             join m04 in context.M04_DRV on t02.乗務員KEY equals m04.乗務員KEY
                             join t01 in context.T01_TRN.Where(t01 => t01.入力区分 != 3 || (t01.入力区分 == 3 && t01.明細行 != 1)) on t02.明細番号 equals t01.明細番号 into t01Group
                             join t03 in context.T03_KTRN on t02.明細番号 equals t03.明細番号 into t03Group
                             select new JMI02010_Member_CSV
                {
                    出庫 = t02.勤務開始日,
                    帰庫 = t02.勤務終了日,
                    車番 = t02.車輌番号,
                    社内金額 = t01Group.Where(order => order.支払先KEY == null).Sum(order => order.支払金額) == null ? 0 : t01Group.Where(order => order.支払先KEY == null).Sum(order => order.支払金額),
                    経費1 = t03Group.Where(order2 => order2.経費項目ID == 601 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 601 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                    経費2 = t03Group.Where(order2 => order2.経費項目ID == 602 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 602 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                    経費3 = t03Group.Where(order2 => order2.経費項目ID == 603 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 603 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                    経費4 = t03Group.Where(order2 => order2.経費項目ID == 604 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 604 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                    経費5 = t03Group.Where(order2 => order2.経費項目ID == 605 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 605 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                    経費6 = t03Group.Where(order2 => order2.経費項目ID == 606 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 606 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                    経費7 = t03Group.Where(order2 => order2.経費項目ID == 607 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 607 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                    その他経費 = t03Group.Where(order2 => order2.経費項目ID != 601 && order2.経費項目ID != 602 &&
                                           order2.経費項目ID != 603 && order2.経費項目ID != 604 &&
                                           order2.経費項目ID != 605 && order2.経費項目ID != 606 &&
                                           order2.経費項目ID != 607 &&
                                           order2.経費項目ID != 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額)
                            == null ? 0 : t03Group.Where(order2 => order2.経費項目ID != 601 && order2.経費項目ID != 602 &&
                                                         order2.経費項目ID != 603 && order2.経費項目ID != 604 &&
                                                         order2.経費項目ID != 605 && order2.経費項目ID != 606 &&
                                                         order2.経費項目ID != 607 &&
                                                         order2.経費項目ID != 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),

                    燃料L数 = t03Group.Where(order2 => order2.経費項目ID == 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.数量) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.数量),
                    燃料代 = t03Group.Where(order2 => order2.経費項目ID == 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                    走行KM = t02.走行KM == null ? 0 : t02.走行KM,
                    歩合率 = m04.歩合率 == null ? 0 : m04.歩合率,
                    歩合金額 = 0,

                    コード = m04.乗務員ID,
                    乗務員名 = m04.乗務員名,
                    期間From = d集計期間From,
                    期間To = d集計期間To,
                }).AsQueryable();

                if (!(string.IsNullOrEmpty(p乗務員From + p乗務員To) && i乗務員List.Length == 0))
                {
                    //乗務員が検索対象に入っていない時全データ取得
                    if (string.IsNullOrEmpty(p乗務員From + p乗務員To))
                    {
                        query = query.Where(c => c.コード >= int.MaxValue);
                    }

                    //乗務員From処理 Min値
                    if (!string.IsNullOrEmpty(p乗務員From))
                    {
                        int i乗務員FROM = AppCommon.IntParse(p乗務員From);
                        query = query.Where(c => c.コード >= i乗務員FROM);
                    }

                    //乗務員To処理 Max値
                    if (!string.IsNullOrEmpty(p乗務員To))
                    {
                        int i乗務員TO = AppCommon.IntParse(p乗務員To);
                        query = query.Where(c => c.コード <= i乗務員TO);
                    }



                    if (i乗務員List.Length > 0)
                    {
                        var intCause = i乗務員List;


                        query = query.Union(from t02 in context.T02_UTRN.Where(x => x.勤務開始日 >= d集計期間From && x.勤務開始日 <= d集計期間To)
                                            join m04 in context.M04_DRV on t02.乗務員KEY equals m04.乗務員KEY
                                            join t01 in context.T01_TRN.Where(t01 => t01.入力区分 != 3 || (t01.入力区分 == 3 && t01.明細行 != 1)) on t02.明細番号 equals t01.明細番号 into t01Group
                                            join t03 in context.T03_KTRN on t02.明細番号 equals t03.明細番号 into t03Group
                                            where intCause.Contains(m04.乗務員ID)
                                            select new JMI02010_Member_CSV
                        {
                            出庫    = t02.勤務開始日,
                            帰庫    = t02.勤務終了日,
                            車番    = t02.車輌番号,
                            社内金額  = t01Group.Where(order => order.支払先KEY == null).Sum(order => order.支払金額) == null ? 0 : t01Group.Where(order => order.支払先KEY == null).Sum(order => order.支払金額),
                            経費1   = t03Group.Where(order2 => order2.経費項目ID == 601 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 601 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                            経費2   = t03Group.Where(order2 => order2.経費項目ID == 602 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 602 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                            経費3   = t03Group.Where(order2 => order2.経費項目ID == 603 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 603 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                            経費4   = t03Group.Where(order2 => order2.経費項目ID == 604 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 604 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                            経費5   = t03Group.Where(order2 => order2.経費項目ID == 605 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 605 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                            経費6   = t03Group.Where(order2 => order2.経費項目ID == 606 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 606 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                            経費7   = t03Group.Where(order2 => order2.経費項目ID == 607 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 607 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                            その他経費 = t03Group.Where(order2 => order2.経費項目ID != 601 && order2.経費項目ID != 602 &&
                                                   order2.経費項目ID != 603 && order2.経費項目ID != 604 &&
                                                   order2.経費項目ID != 605 && order2.経費項目ID != 606 &&
                                                   order2.経費項目ID != 607 &&
                                                   order2.経費項目ID != 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額)
                                    == null ? 0 : t03Group.Where(order2 => order2.経費項目ID != 601 && order2.経費項目ID != 602 &&
                                                                 order2.経費項目ID != 603 && order2.経費項目ID != 604 &&
                                                                 order2.経費項目ID != 605 && order2.経費項目ID != 606 &&
                                                                 order2.経費項目ID != 607 &&
                                                                 order2.経費項目ID != 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),

                            燃料L数 = t03Group.Where(order2 => order2.経費項目ID == 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.数量) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.数量),
                            燃料代  = t03Group.Where(order2 => order2.経費項目ID == 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額) == null ? 0 : t03Group.Where(order2 => order2.経費項目ID == 401 && order2.乗務員KEY == t02.乗務員KEY).Sum(order2 => order2.金額),
                            走行KM = t02.走行KM == null ? 0 : t02.走行KM,
                            歩合率  = m04.歩合率 == null ? 0 : m04.歩合率,
                            歩合金額 = 0,

                            コード    = m04.乗務員ID,
                            乗務員名   = m04.乗務員名,
                            期間From = d集計期間From,
                            期間To   = d集計期間To,
                        });
                    }
                    else
                    {
                        query = query.Where(c => c.コード > int.MinValue && c.コード < int.MaxValue);
                    }
                }

                query = query.Distinct();

                //結果をリスト化
                retList = query.ToList();
                retList = (retList.OrderBy(a => a.コード).ThenBy(a => a.出庫)).ToList();
                //retList = (from q in retList orderby q.コード, q.出庫 select q);
                return(retList);
            }
        }
Exemple #22
0
        /// <summary>
        /// 得意先別車種別単価一覧表プレビュー用出力
        /// 得意先別車種別単価一覧表CSV用出力
        /// </summary>
        /// <returns></returns>
        /// <param name="s01toks">S02_toks__Member</param>
        public List <S02_YOSS_Member_Preview_csv> GetSearchListData(string p得意先IDFrom, string p得意先IDTo, string p処理年月From, string p処理年月To, string p回数From, string p回数To, int[] i得意先List)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                var query = (from s01 in context.S02_YOSS
                             from m01 in context.M01_TOK.Where(m01 => m01.得意先KEY == s01.支払先KEY)
                             //where s01.削除日付 == null

                             select new S02_YOSS_Member_Preview_csv
                {
                    支払先KEY = m01.得意先ID,
                    得意先名 = m01.略称名,
                    集計年月 = s01.集計年月,
                    回数 = s01.回数,
                    締集計開始日 = s01.締集計開始日,
                    締集計終了日 = s01.締集計終了日,
                    締日前月残高 = s01.締日前月残高,
                    締日入金現金 = s01.締日入金手形,
                    締日入金手形 = s01.締日入金手形,
                    締日入金その他 = s01.締日入金その他,
                    締日売上金額 = s01.締日売上金額,
                    締日通行料 = s01.締日通行料,
                    締日非課税売上 = s01.締日非課税売上,
                    締日課税売上 = s01.締日課税売上,
                    締日消費税 = s01.締日消費税,
                    締日内傭車売上 = s01.締日内傭車売上,
                    締日内傭車料 = s01.締日内傭車料,
                    締日未定件数 = s01.締日未定件数,
                    締日件数 = s01.締日件数,
                });


                if (!string.IsNullOrEmpty(p得意先IDFrom))
                {
                    int ip得意先IDFrom = AppCommon.IntParse(p得意先IDFrom);
                    query = query.Where(c => c.支払先KEY >= ip得意先IDFrom);
                }
                if (!string.IsNullOrEmpty(p得意先IDTo))
                {
                    int ip得意先IDTo = AppCommon.IntParse(p得意先IDTo);
                    query = query.Where(c => c.支払先KEY <= ip得意先IDTo);
                }

                if (!string.IsNullOrEmpty(p処理年月From))
                {
                    int ip処理年月From = AppCommon.IntParse(p処理年月From);
                    query = query.Where(c => c.集計年月 >= ip処理年月From);
                }
                if (!string.IsNullOrEmpty(p処理年月To))
                {
                    int ip処理年月To = AppCommon.IntParse(p処理年月To);
                    query = query.Where(c => c.集計年月 <= ip処理年月To);
                }

                if (!string.IsNullOrEmpty(p回数From))
                {
                    int ip回数From = AppCommon.IntParse(p回数From);
                    query = query.Where(c => c.回数 >= ip回数From);
                }
                if (!string.IsNullOrEmpty(p回数To))
                {
                    int ip回数To = AppCommon.IntParse(p回数To);
                    query = query.Where(c => c.集計年月 <= ip回数To);
                }


                if (i得意先List.Length > 0)
                {
                    var intCause = i得意先List;

                    query = query.Union(from s01 in context.S02_YOSS
                                        from m01 in context.M01_TOK.Where(m01 => m01.得意先KEY == s01.支払先KEY)
                                        where intCause.Contains(m01.得意先KEY)
                                        select new S02_YOSS_Member_Preview_csv
                    {
                        支払先KEY  = m01.得意先ID,
                        得意先名    = m01.略称名,
                        集計年月    = s01.集計年月,
                        回数      = s01.回数,
                        締集計開始日  = s01.締集計開始日,
                        締集計終了日  = s01.締集計終了日,
                        締日前月残高  = s01.締日前月残高,
                        締日入金現金  = s01.締日入金手形,
                        締日入金手形  = s01.締日入金手形,
                        締日入金その他 = s01.締日入金その他,
                        締日売上金額  = s01.締日売上金額,
                        締日通行料   = s01.締日通行料,
                        締日非課税売上 = s01.締日非課税売上,
                        締日課税売上  = s01.締日課税売上,
                        締日消費税   = s01.締日消費税,
                        締日内傭車売上 = s01.締日内傭車売上,
                        締日内傭車料  = s01.締日内傭車料,
                        締日未定件数  = s01.締日未定件数,
                        締日件数    = s01.締日件数,
                    });
                }


                //削除データ検索条件

                query = query.OrderBy(c => (c.支払先KEY));

                return(query.ToList());
            }
        }
Exemple #23
0
        /// <summary>
        /// NNG03010 乗務員月別売上合計表
        /// </summary>
        /// <param name="p商品ID">部門コード</param>
        /// <returns>S02</returns>
        public List <NNG03010_Member> NNG03010_GetDataHinList(string s乗務員From, string s乗務員To, int?[] i乗務員List, int i表示区分, int i表示順序, bool 前年前々年,
                                                              string s作成年月度1, string s作成年月度2, int[] d開始年月日, int[] d前年開始年月日, int[] d前々年開始年月日)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                List <NNG03010_Member> retList = new List <NNG03010_Member>();
                context.Connection.Open();

                string 乗務員ピックアップ指定 = string.Empty;

                #region  数定義

                int 開始年月日1  = d開始年月日[0];
                int 開始年月日2  = d開始年月日[1];
                int 開始年月日3  = d開始年月日[2];
                int 開始年月日4  = d開始年月日[3];
                int 開始年月日5  = d開始年月日[4];
                int 開始年月日6  = d開始年月日[5];
                int 開始年月日7  = d開始年月日[6];
                int 開始年月日8  = d開始年月日[7];
                int 開始年月日9  = d開始年月日[8];
                int 開始年月日10 = d開始年月日[9];
                int 開始年月日11 = d開始年月日[10];
                int 開始年月日12 = d開始年月日[11];

                //前年
                int 前年開始年月日1  = d前年開始年月日[0];
                int 前年開始年月日2  = d前年開始年月日[1];
                int 前年開始年月日3  = d前年開始年月日[2];
                int 前年開始年月日4  = d前年開始年月日[3];
                int 前年開始年月日5  = d前年開始年月日[4];
                int 前年開始年月日6  = d前年開始年月日[5];
                int 前年開始年月日7  = d前年開始年月日[6];
                int 前年開始年月日8  = d前年開始年月日[7];
                int 前年開始年月日9  = d前年開始年月日[8];
                int 前年開始年月日10 = d前年開始年月日[9];
                int 前年開始年月日11 = d前年開始年月日[10];
                int 前年開始年月日12 = d前年開始年月日[11];

                //前々年
                int 前々年開始年月日1  = d前々年開始年月日[0];
                int 前々年開始年月日2  = d前々年開始年月日[1];
                int 前々年開始年月日3  = d前々年開始年月日[2];
                int 前々年開始年月日4  = d前々年開始年月日[3];
                int 前々年開始年月日5  = d前々年開始年月日[4];
                int 前々年開始年月日6  = d前々年開始年月日[5];
                int 前々年開始年月日7  = d前々年開始年月日[6];
                int 前々年開始年月日8  = d前々年開始年月日[7];
                int 前々年開始年月日9  = d前々年開始年月日[8];
                int 前々年開始年月日10 = d前々年開始年月日[9];
                int 前々年開始年月日11 = d前々年開始年月日[10];
                int 前々年開始年月日12 = d前々年開始年月日[11];

                //月名
                //DateTime d年月日 = DateTime.Parse(開始年月日1.ToString().Substring(0, 4) + "/" + 開始年月日1.ToString().Substring(4, 2) + "/" + "01");
                DateTime d年月日;
                DateTime.TryParse(開始年月日1.ToString().Substring(0, 4) + "/" + 開始年月日1.ToString().Substring(4, 2) + "/" + "01", out d年月日);

                string s月名1  = d年月日.Month + "月";
                string s月名2  = d年月日.AddMonths(1).Month + "月";
                string s月名3  = d年月日.AddMonths(2).Month + "月";
                string s月名4  = d年月日.AddMonths(3).Month + "月";
                string s月名5  = d年月日.AddMonths(4).Month + "月";
                string s月名6  = d年月日.AddMonths(5).Month + "月";
                string s月名7  = d年月日.AddMonths(6).Month + "月";
                string s月名8  = d年月日.AddMonths(7).Month + "月";
                string s月名9  = d年月日.AddMonths(8).Month + "月";
                string s月名10 = d年月日.AddMonths(9).Month + "月";
                string s月名11 = d年月日.AddMonths(10).Month + "月";
                string s月名12 = d年月日.AddMonths(11).Month + "月";


                #endregion

                #region 当年

                var Goukei = (from m04 in context.M04_DRV.Where(c => c.削除日付 == null)
                              join v01 in context.V_乗務員月別売上合計表 on m04.乗務員ID equals v01.乗務員ID into V01Group
                              select new NNG03010g
                {
                    乗務員コード = m04.乗務員ID,
                    当年合計 = V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額),
                    前年合計 = V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Sum(c => c.売上金額),
                    前々年合計 = V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Sum(c => c.売上金額),
                }).AsQueryable();

                if (!(string.IsNullOrEmpty(s乗務員From + s乗務員To)) && i乗務員List.Length == 0)
                {
                    if (!string.IsNullOrEmpty(s乗務員From))
                    {
                        int i乗務員From = AppCommon.IntParse(s乗務員From);
                        Goukei = Goukei.Where(c => c.乗務員コード >= i乗務員From);
                    }

                    if (!string.IsNullOrEmpty(s乗務員To))
                    {
                        int i乗務員To = AppCommon.IntParse(s乗務員To);
                        Goukei = Goukei.Where(c => c.乗務員コード <= i乗務員To);
                    }

                    if (i乗務員List.Length > 0)
                    {
                        var OutSide = i乗務員List;
                        Goukei = Goukei.Union(from m04 in context.M04_DRV.Where(c => c.削除日付 == null)
                                              join v01 in context.V_乗務員月別売上合計表 on m04.乗務員ID equals v01.乗務員ID into V01Group
                                              where OutSide.Contains(m04.乗務員ID)
                                              select new NNG03010g
                        {
                            乗務員コード = m04.乗務員ID,
                            当年合計   = V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額),
                            前年合計   = V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Sum(c => c.売上金額),
                            前々年合計  = V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Sum(c => c.売上金額),
                        });
                    }
                }
                else
                {
                    Goukei = Goukei.Where(c => c.乗務員コード >= int.MinValue && c.乗務員コード <= int.MaxValue);
                }

                var Item = (from gok in Goukei
                            select new Total
                {
                    当年合計 = Goukei.Sum(c => c.当年合計),
                    前年合計 = Goukei.Sum(c => c.前年合計),
                    前々年合計 = Goukei.Sum(c => c.前々年合計),
                }).Distinct().AsQueryable();



                var query = (from m04 in context.M04_DRV.Where(c => c.削除日付 == null)
                             join v01 in context.V_乗務員月別売上合計表 on m04.乗務員ID equals v01.乗務員ID into V01Group
                             select new NNG03010_Member
                {
                    作成年度1 = s作成年月度1,
                    作成年度2 = s作成年月度2,
                    乗務員コード = m04.乗務員ID,
                    運転者名 = m04.乗務員名,
                    区分 = 前年前々年 == false ? "" : "当年",
                    月1 = V01Group.Where(c => c.集計年月 == 開始年月日1).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日1).Sum(c => c.売上金額),
                    月2 = V01Group.Where(c => c.集計年月 == 開始年月日2).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日2).Sum(c => c.売上金額),
                    月3 = V01Group.Where(c => c.集計年月 == 開始年月日3).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日3).Sum(c => c.売上金額),
                    月4 = V01Group.Where(c => c.集計年月 == 開始年月日4).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日4).Sum(c => c.売上金額),
                    月5 = V01Group.Where(c => c.集計年月 == 開始年月日5).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日5).Sum(c => c.売上金額),
                    月6 = V01Group.Where(c => c.集計年月 == 開始年月日6).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日6).Sum(c => c.売上金額),
                    月7 = V01Group.Where(c => c.集計年月 == 開始年月日7).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日7).Sum(c => c.売上金額),
                    月8 = V01Group.Where(c => c.集計年月 == 開始年月日8).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日8).Sum(c => c.売上金額),
                    月9 = V01Group.Where(c => c.集計年月 == 開始年月日9).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日9).Sum(c => c.売上金額),
                    月10 = V01Group.Where(c => c.集計年月 == 開始年月日10).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日10).Sum(c => c.売上金額),
                    月11 = V01Group.Where(c => c.集計年月 == 開始年月日11).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日11).Sum(c => c.売上金額),
                    月12 = V01Group.Where(c => c.集計年月 == 開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 開始年月日12).Sum(c => c.売上金額),
                    表示区分 = i表示区分 == 0 ? "(売上有り乗務員のみ)" : "(売上無し乗務員含む)",
                    表示順序 = i表示順序 == 0 ? "乗務員ID" : i表示順序 == 1 ? "乗務員名" : "合計金額",
                    年合計 = V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額),
                    平均 = V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Count(c => c.売上金額 != 0) == 0 ? 0 : V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額) / V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Count(c => c.売上金額 != 0),
                    構成比 = Math.Round((decimal)V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額 * 100 / Item.Sum(d => d.当年合計))) == null ? 0 : Math.Round((decimal)V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額 * 100 / Item.Sum(d => d.当年合計))),
                    月名1 = s月名1,
                    月名2 = s月名2,
                    月名3 = s月名3,
                    月名4 = s月名4,
                    月名5 = s月名5,
                    月名6 = s月名6,
                    月名7 = s月名7,
                    月名8 = s月名8,
                    月名9 = s月名9,
                    月名10 = s月名10,
                    月名11 = s月名11,
                    月名12 = s月名12,
                    当年売上 = V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額),
                    売上順位データ = 前年前々年 == false ? V01Group.Where(v01 => v01.集計年月 >= 開始年月日1 && v01.集計年月 <= 開始年月日12).Sum(v01 => v01.売上金額) == null ? 0 : V01Group.Where(v01 => v01.集計年月 >= 前々年開始年月日12 && v01.集計年月 <= 前々年開始年月日12).Sum(v01 => v01.売上金額) : V01Group.Where(v01 => v01.集計年月 >= 前々年開始年月日12 && v01.集計年月 <= 開始年月日12).Sum(v01 => v01.売上金額) == null ? 0 : V01Group.Where(v01 => v01.集計年月 >= 前々年開始年月日12 && v01.集計年月 <= 開始年月日12).Sum(v01 => v01.売上金額),
                    乗務員指定 = s乗務員From + "~" + s乗務員To,
                    乗務員ピックアップ = 乗務員ピックアップ指定 == "" ? "無" : 乗務員ピックアップ指定,
                    総年合計 = 0,
                }).AsQueryable();
                //ピックアップ
                if (i乗務員List.Length > 0)
                {
                    for (int i = 0; i < query.Count(); i++)
                    {
                        乗務員ピックアップ指定 = 乗務員ピックアップ指定 + i乗務員List[i].ToString();

                        if (i < i乗務員List.Length)
                        {
                            if (i == i乗務員List.Length - 1)
                            {
                                break;
                            }

                            乗務員ピックアップ指定 = 乗務員ピックアップ指定 + ",";
                        }

                        if (i乗務員List.Length == 1)
                        {
                            break;
                        }
                    }
                }

                #endregion

                #region 前年
                //<<<前年データ集計>>>
                if (前年前々年 == true)
                {
                    query = query.Union(from m04 in context.M04_DRV.Where(c => c.削除日付 == null)
                                        join v01 in context.V_乗務員月別売上合計表 on m04.乗務員ID equals v01.乗務員ID into V01Group
                                        select new NNG03010_Member
                    {
                        作成年度1       = s作成年月度1,
                        作成年度2       = s作成年月度2,
                        乗務員コード      = m04.乗務員ID,
                        運転者名        = m04.乗務員名,
                        区分          = 前年前々年 == false ? "" : "前年",
                        月1          = V01Group.Where(c => c.集計年月 == 前年開始年月日1).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日1).Sum(c => c.売上金額),
                        月2          = V01Group.Where(c => c.集計年月 == 前年開始年月日2).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日2).Sum(c => c.売上金額),
                        月3          = V01Group.Where(c => c.集計年月 == 前年開始年月日3).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日3).Sum(c => c.売上金額),
                        月4          = V01Group.Where(c => c.集計年月 == 前年開始年月日4).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日4).Sum(c => c.売上金額),
                        月5          = V01Group.Where(c => c.集計年月 == 前年開始年月日5).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日5).Sum(c => c.売上金額),
                        月6          = V01Group.Where(c => c.集計年月 == 前年開始年月日6).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日6).Sum(c => c.売上金額),
                        月7          = V01Group.Where(c => c.集計年月 == 前年開始年月日7).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日7).Sum(c => c.売上金額),
                        月8          = V01Group.Where(c => c.集計年月 == 前年開始年月日8).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日8).Sum(c => c.売上金額),
                        月9          = V01Group.Where(c => c.集計年月 == 前年開始年月日9).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日9).Sum(c => c.売上金額),
                        月10         = V01Group.Where(c => c.集計年月 == 前年開始年月日10).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日10).Sum(c => c.売上金額),
                        月11         = V01Group.Where(c => c.集計年月 == 前年開始年月日11).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日11).Sum(c => c.売上金額),
                        月12         = V01Group.Where(c => c.集計年月 == 前年開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前年開始年月日12).Sum(c => c.売上金額),
                        表示区分        = i表示区分 == 0 ? "(売上有り乗務員のみ)" : "(売上無し乗務員含む)",
                        表示順序        = i表示順序 == 0 ? "乗務員ID" : i表示順序 == 1 ? "乗務員名" : "合計金額",
                        年合計         = V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Sum(c => c.売上金額),
                        平均          = V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Count(c => c.売上金額 != 0) == 0 ? 0 : V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Sum(c => c.売上金額) / V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Count(c => c.売上金額 != 0),
                        構成比         = Math.Round((decimal)V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Sum(c => c.売上金額 * 100 / Item.Sum(d => d.前年合計))) == null ? 0 : Math.Round((decimal)V01Group.Where(c => c.集計年月 >= 前年開始年月日1 && c.集計年月 <= 前年開始年月日12).Sum(c => c.売上金額 * 100 / Item.Sum(d => d.前年合計))),
                        月名1         = s月名1,
                        月名2         = s月名2,
                        月名3         = s月名3,
                        月名4         = s月名4,
                        月名5         = s月名5,
                        月名6         = s月名6,
                        月名7         = s月名7,
                        月名8         = s月名8,
                        月名9         = s月名9,
                        月名10        = s月名10,
                        月名11        = s月名11,
                        月名12        = s月名12,
                        当年売上        = V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額),
                        売上順位データ     = V01Group.Where(v01 => v01.集計年月 >= 前々年開始年月日12 && v01.集計年月 <= 開始年月日12).Sum(v01 => v01.売上金額) == null ? 0 : V01Group.Where(v01 => v01.集計年月 >= 前々年開始年月日12 && v01.集計年月 <= 開始年月日12).Sum(v01 => v01.売上金額),
                        乗務員指定       = s乗務員From + "~" + s乗務員To,
                        乗務員ピックアップ = 乗務員ピックアップ指定 == "" ? "無" : 乗務員ピックアップ指定,
                        総年合計        = 0,
                    }).AsQueryable();


                    #endregion

                    #region 前々年
                    //<<<前々年のデータ>>>
                    query = query.Union(from m04 in context.M04_DRV.Where(c => c.削除日付 == null)
                                        join v01 in context.V_乗務員月別売上合計表 on m04.乗務員ID equals v01.乗務員ID into V01Group
                                        select new NNG03010_Member
                    {
                        作成年度1       = s作成年月度1,
                        作成年度2       = s作成年月度2,
                        乗務員コード      = m04.乗務員ID,
                        運転者名        = m04.乗務員名,
                        区分          = 前年前々年 == false ? "" : "前々年",
                        月1          = V01Group.Where(c => c.集計年月 == 前々年開始年月日1).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日1).Sum(c => c.売上金額),
                        月2          = V01Group.Where(c => c.集計年月 == 前々年開始年月日2).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日2).Sum(c => c.売上金額),
                        月3          = V01Group.Where(c => c.集計年月 == 前々年開始年月日3).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日3).Sum(c => c.売上金額),
                        月4          = V01Group.Where(c => c.集計年月 == 前々年開始年月日4).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日4).Sum(c => c.売上金額),
                        月5          = V01Group.Where(c => c.集計年月 == 前々年開始年月日5).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日5).Sum(c => c.売上金額),
                        月6          = V01Group.Where(c => c.集計年月 == 前々年開始年月日6).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日6).Sum(c => c.売上金額),
                        月7          = V01Group.Where(c => c.集計年月 == 前々年開始年月日7).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日7).Sum(c => c.売上金額),
                        月8          = V01Group.Where(c => c.集計年月 == 前々年開始年月日8).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日8).Sum(c => c.売上金額),
                        月9          = V01Group.Where(c => c.集計年月 == 前々年開始年月日9).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日9).Sum(c => c.売上金額),
                        月10         = V01Group.Where(c => c.集計年月 == 前々年開始年月日10).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日10).Sum(c => c.売上金額),
                        月11         = V01Group.Where(c => c.集計年月 == 前々年開始年月日11).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日11).Sum(c => c.売上金額),
                        月12         = V01Group.Where(c => c.集計年月 == 前々年開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 == 前々年開始年月日12).Sum(c => c.売上金額),
                        表示区分        = i表示区分 == 0 ? "(売上有り乗務員のみ)" : "(売上無し乗務員含む)",
                        表示順序        = i表示順序 == 0 ? "乗務員ID" : i表示順序 == 1 ? "乗務員名" : "合計金額",
                        年合計         = V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Sum(c => c.売上金額),
                        平均          = V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Count(c => c.売上金額 != 0) == 0 ? 0 : V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Sum(c => c.売上金額) / V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Count(c => c.売上金額 != 0),
                        構成比         = Math.Round((decimal)V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Sum(c => c.売上金額 * 100 / Item.Sum(d => d.前々年合計))) == null ? 0 : Math.Round((decimal)V01Group.Where(c => c.集計年月 >= 前々年開始年月日1 && c.集計年月 <= 前々年開始年月日12).Sum(c => c.売上金額 * 100 / Item.Sum(d => d.前々年合計))),
                        月名1         = s月名1,
                        月名2         = s月名2,
                        月名3         = s月名3,
                        月名4         = s月名4,
                        月名5         = s月名5,
                        月名6         = s月名6,
                        月名7         = s月名7,
                        月名8         = s月名8,
                        月名9         = s月名9,
                        月名10        = s月名10,
                        月名11        = s月名11,
                        月名12        = s月名12,
                        当年売上        = V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額) == null ? 0 : V01Group.Where(c => c.集計年月 >= 開始年月日1 && c.集計年月 <= 開始年月日12).Sum(c => c.売上金額),
                        売上順位データ     = V01Group.Where(v01 => v01.集計年月 >= 前々年開始年月日12 && v01.集計年月 <= 開始年月日12).Sum(v01 => v01.売上金額) == null ? 0 : V01Group.Where(v01 => v01.集計年月 >= 前々年開始年月日12 && v01.集計年月 <= 開始年月日12).Sum(v01 => v01.売上金額),
                        乗務員指定       = s乗務員From + "~" + s乗務員To,
                        乗務員ピックアップ = 乗務員ピックアップ指定 == "" ? "無" : 乗務員ピックアップ指定,
                        総年合計        = 0,
                    }).AsQueryable();
                    query = query.Distinct();
                }
                #endregion

                #region データ条件項目

                //表示順序
                switch (i表示順序)
                {
                case 0:
                    query = query.OrderBy(c => c.乗務員コード).ThenByDescending(c => c.区分);
                    break;

                case 1:
                    query = query.OrderBy(c => c.運転者名).ThenBy(c => c.乗務員コード).ThenByDescending(c => c.区分);
                    break;

                case 2:
                    query = query.OrderByDescending(c => c.売上順位データ).ThenBy(c => c.乗務員コード).ThenByDescending(c => c.区分);
                    break;
                }

                //表示区分
                if (i表示区分 == 0)
                {
                    query = query.Where(c => c.当年売上 > 0);
                }
                else
                {
                    query = query.Where(c => c.当年売上 >= 0);
                }

                var     intCause = i乗務員List;
                decimal?p合計      = 0;
                decimal?T当年合計    = 0;
                decimal?Z前年合計    = 0;
                decimal?Z前々年合計   = 0;
                //ピックアップ処理
                if (string.IsNullOrEmpty(s乗務員From + s乗務員To))
                {
                    if (i乗務員List.Length > 0)
                    {
                        query = query.Where(c => intCause.Contains(c.乗務員コード));
                    }

                    //前年全前年
                    if (前年前々年 == true)
                    {
                        //総年合計計算
                        retList = query.ToList();
                        for (int i = 0; i < retList.Count; i++)
                        {
                            if (retList[i].区分 == "当年")
                            {
                                p合計   = retList[i].年合計;
                                T当年合計 = p合計 + T当年合計;
                            }

                            if (retList[i].区分 == "前年")
                            {
                                p合計   = retList[i].年合計;
                                Z前年合計 = p合計 + Z前年合計;
                            }

                            if (retList[i].区分 == "前々年")
                            {
                                p合計    = retList[i].年合計;
                                Z前々年合計 = p合計 + Z前々年合計;
                            }
                        }

                        //構成比計算
                        for (int j = 0; j < retList.Count; j++)
                        {
                            if (retList[j].区分 == "当年")
                            {
                                retList[j].総年合計 = T当年合計;
                            }

                            if (retList[j].区分 == "前年")
                            {
                                retList[j].総年合計 = Z前年合計;
                            }

                            if (retList[j].区分 == "前々年")
                            {
                                retList[j].総年合計 = Z前々年合計;
                            }

                            //0除算処理
                            //構成比計算
                            if (retList[j].総年合計 == 0)
                            {
                                retList[j].構成比 = (retList[j].年合計 / 1) * 100;
                                Math.Round((decimal)retList[j].構成比, 0);
                            }
                            else
                            {
                                retList[j].構成比 = (retList[j].年合計 / retList[j].総年合計) * 100;
                                Math.Round((decimal)retList[j].構成比, 0);
                            }
                        }
                    }
                    else
                    {
                        //当年処理
                        //総年合計計算
                        retList = query.ToList();
                        for (int i = 0; i < retList.Count; i++)
                        {
                            p合計   = retList[i].年合計;
                            T当年合計 = p合計 + T当年合計;
                        }

                        //構成比計算
                        for (int j = 0; j < retList.Count; j++)
                        {
                            retList[j].総年合計 = T当年合計;
                            //0除算処理
                            //構成比計算
                            if (retList[j].総年合計 == 0)
                            {
                                retList[j].構成比 = (retList[j].年合計 / 1) * 100;
                                Math.Round((decimal)retList[j].構成比, 0);
                            }
                            else
                            {
                                retList[j].構成比 = (retList[j].年合計 / retList[j].総年合計) * 100;
                                Math.Round((decimal)retList[j].構成比, 0);
                            }
                        }
                    }
                }
                else
                {
                    //From、To、ピックアップ指定を入力された場合
                    int iFrom = 1;
                    int iTo   = 999999999;
                    iFrom = AppCommon.IntParse(s乗務員From);
                    iTo   = AppCommon.IntParse(s乗務員To);

                    if (i乗務員List.Length > 0)
                    {
                        query = query.Where(c => intCause.Contains(c.乗務員コード) || (c.乗務員コード >= iFrom && c.乗務員コード <= iTo));

                        //前年全前年
                        if (前年前々年 == true)
                        {
                            //総年合計計算
                            retList = query.ToList();
                            for (int i = 0; i < retList.Count; i++)
                            {
                                if (retList[i].区分 == "当年")
                                {
                                    p合計   = retList[i].年合計;
                                    T当年合計 = p合計 + T当年合計;
                                }

                                if (retList[i].区分 == "前年")
                                {
                                    p合計   = retList[i].年合計;
                                    Z前年合計 = p合計 + Z前年合計;
                                }

                                if (retList[i].区分 == "前々年")
                                {
                                    p合計    = retList[i].年合計;
                                    Z前々年合計 = p合計 + Z前々年合計;
                                }
                            }

                            //構成比計算
                            for (int j = 0; j < retList.Count; j++)
                            {
                                if (retList[j].区分 == "当年")
                                {
                                    retList[j].総年合計 = T当年合計;
                                }

                                if (retList[j].区分 == "前年")
                                {
                                    retList[j].総年合計 = Z前年合計;
                                }

                                if (retList[j].区分 == "前々年")
                                {
                                    retList[j].総年合計 = Z前々年合計;
                                }

                                //0除算処理
                                //構成比計算
                                if (retList[j].総年合計 == 0)
                                {
                                    retList[j].構成比 = (retList[j].年合計 / 1) * 100;
                                    Math.Round((decimal)retList[j].構成比, 0);
                                }
                                else
                                {
                                    retList[j].構成比 = (retList[j].年合計 / retList[j].総年合計) * 100;
                                    Math.Round((decimal)retList[j].構成比, 0);
                                }
                            }
                        }
                        else
                        {
                            //前年全前年
                            if (前年前々年 == true)
                            {
                                //総年合計計算
                                retList = query.ToList();
                                for (int i = 0; i < retList.Count; i++)
                                {
                                    if (retList[i].区分 == "当年")
                                    {
                                        p合計   = retList[i].年合計;
                                        T当年合計 = p合計 + T当年合計;
                                    }

                                    if (retList[i].区分 == "前年")
                                    {
                                        p合計   = retList[i].年合計;
                                        Z前年合計 = p合計 + Z前年合計;
                                    }

                                    if (retList[i].区分 == "前々年")
                                    {
                                        p合計    = retList[i].年合計;
                                        Z前々年合計 = p合計 + Z前々年合計;
                                    }
                                }

                                //構成比計算
                                for (int j = 0; j < retList.Count; j++)
                                {
                                    if (retList[j].区分 == "当年")
                                    {
                                        retList[j].総年合計 = T当年合計;
                                    }

                                    if (retList[j].区分 == "前年")
                                    {
                                        retList[j].総年合計 = Z前年合計;
                                    }

                                    if (retList[j].区分 == "前々年")
                                    {
                                        retList[j].総年合計 = Z前々年合計;
                                    }

                                    //0除算処理
                                    //構成比計算
                                    if (retList[j].総年合計 == 0)
                                    {
                                        retList[j].構成比 = (retList[j].年合計 / 1) * 100;
                                        Math.Round((decimal)retList[j].構成比, 0);
                                    }
                                    else
                                    {
                                        retList[j].構成比 = (retList[j].年合計 / retList[j].総年合計) * 100;
                                        Math.Round((decimal)retList[j].構成比, 0);
                                    }
                                }
                            }
                            else
                            {
                                //当年処理
                                //総年合計計算
                                retList = query.ToList();
                                for (int i = 0; i < retList.Count; i++)
                                {
                                    p合計   = retList[i].年合計;
                                    T当年合計 = p合計 + T当年合計;
                                }

                                //構成比計算
                                for (int j = 0; j < retList.Count; j++)
                                {
                                    retList[j].総年合計 = T当年合計;
                                    //0除算処理
                                    //構成比計算
                                    if (retList[j].総年合計 == 0)
                                    {
                                        retList[j].構成比 = (retList[j].年合計 / 1) * 100;
                                        Math.Round((decimal)retList[j].構成比, 0);
                                    }
                                    else
                                    {
                                        retList[j].構成比 = (retList[j].年合計 / retList[j].総年合計) * 100;
                                        Math.Round((decimal)retList[j].構成比, 0);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        query = query.Where(c => (c.乗務員コード >= iFrom && c.乗務員コード <= iTo));

                        //前年全前年
                        if (前年前々年 == true)
                        {
                            //総年合計計算
                            retList = query.ToList();
                            for (int i = 0; i < retList.Count; i++)
                            {
                                if (retList[i].区分 == "当年")
                                {
                                    p合計   = retList[i].年合計;
                                    T当年合計 = p合計 + T当年合計;
                                }

                                if (retList[i].区分 == "前年")
                                {
                                    p合計   = retList[i].年合計;
                                    Z前年合計 = p合計 + Z前年合計;
                                }

                                if (retList[i].区分 == "前々年")
                                {
                                    p合計    = retList[i].年合計;
                                    Z前々年合計 = p合計 + Z前々年合計;
                                }
                            }

                            //構成比計算
                            for (int j = 0; j < retList.Count; j++)
                            {
                                if (retList[j].区分 == "当年")
                                {
                                    retList[j].総年合計 = T当年合計;
                                }

                                if (retList[j].区分 == "前年")
                                {
                                    retList[j].総年合計 = Z前年合計;
                                }

                                if (retList[j].区分 == "前々年")
                                {
                                    retList[j].総年合計 = Z前々年合計;
                                }

                                //0除算処理
                                //構成比計算
                                if (retList[j].総年合計 == 0)
                                {
                                    retList[j].構成比 = (retList[j].年合計 / 1) * 100;
                                    Math.Round((decimal)retList[j].構成比, 0);
                                }
                                else
                                {
                                    retList[j].構成比 = (retList[j].年合計 / retList[j].総年合計) * 100;
                                    Math.Round((decimal)retList[j].構成比, 0);
                                }
                            }
                        }
                        else
                        {
                            //前年全前年
                            if (前年前々年 == true)
                            {
                                //総年合計計算
                                retList = query.ToList();
                                for (int i = 0; i < retList.Count; i++)
                                {
                                    if (retList[i].区分 == "当年")
                                    {
                                        p合計   = retList[i].年合計;
                                        T当年合計 = p合計 + T当年合計;
                                    }

                                    if (retList[i].区分 == "前年")
                                    {
                                        p合計   = retList[i].年合計;
                                        Z前年合計 = p合計 + Z前年合計;
                                    }

                                    if (retList[i].区分 == "前々年")
                                    {
                                        p合計    = retList[i].年合計;
                                        Z前々年合計 = p合計 + Z前々年合計;
                                    }
                                }

                                //構成比計算
                                for (int j = 0; j < retList.Count; j++)
                                {
                                    if (retList[j].区分 == "当年")
                                    {
                                        retList[j].総年合計 = T当年合計;
                                    }

                                    if (retList[j].区分 == "前年")
                                    {
                                        retList[j].総年合計 = Z前年合計;
                                    }

                                    if (retList[j].区分 == "前々年")
                                    {
                                        retList[j].総年合計 = Z前々年合計;
                                    }

                                    //0除算処理
                                    //構成比計算
                                    if (retList[j].総年合計 == 0)
                                    {
                                        retList[j].構成比 = (retList[j].年合計 / 1) * 100;
                                        Math.Round((decimal)retList[j].構成比, 0);
                                    }
                                    else
                                    {
                                        retList[j].構成比 = (retList[j].年合計 / retList[j].総年合計) * 100;
                                        Math.Round((decimal)retList[j].構成比, 0);
                                    }
                                }
                            }
                            else
                            {
                                //当年処理
                                //総年合計計算
                                retList = query.ToList();
                                for (int i = 0; i < retList.Count; i++)
                                {
                                    p合計   = retList[i].年合計;
                                    T当年合計 = p合計 + T当年合計;
                                }

                                //構成比計算
                                for (int j = 0; j < retList.Count; j++)
                                {
                                    retList[j].総年合計 = T当年合計;
                                    //0除算処理
                                    //構成比計算
                                    if (retList[j].総年合計 == 0)
                                    {
                                        retList[j].構成比 = (retList[j].年合計 / 1) * 100;
                                        Math.Round((decimal)retList[j].構成比, 0);
                                    }
                                    else
                                    {
                                        retList[j].構成比 = (retList[j].年合計 / retList[j].総年合計) * 100;
                                        Math.Round((decimal)retList[j].構成比, 0);
                                    }
                                }
                            }
                        }
                    }
                }


                //出力
                return(retList);
            }
        }