示例#1
0
        public override DataSet GetData(List <reportParm> parms)
        {
            //報表資料
            List <DepositReportSealData> ReportDataList = new List <DepositReportSealData>();
            var    resultsTable  = new DataSet();
            var    ReportData    = new DepositReportSealData();
            string vdept         = parms.Where(x => x.key == "vdept").FirstOrDefault()?.value ?? string.Empty;
            string vsect         = parms.Where(x => x.key == "vsect").FirstOrDefault()?.value ?? string.Empty;
            string JobProject    = parms.Where(x => x.key == "vJobProject").FirstOrDefault()?.value ?? string.Empty;
            string APLY_DT_From  = parms.Where(x => x.key == "APLY_DT_From").FirstOrDefault()?.value ?? string.Empty; //庫存日期
            string APLY_ODT_From = parms.Where(x => x.key == "APLY_ODT_From").FirstOrDefault()?.value ?? string.Empty;
            string APLY_ODT_To   = parms.Where(x => x.key == "APLY_ODT_To").FirstOrDefault()?.value ?? string.Empty;

            using (TreasuryDBEntities db = new TreasuryDBEntities())
            {
                var _APLY_DT       = TypeTransfer.stringToDateTime(APLY_DT_From).DateToLatestTime();
                var _APLY_DT_Date  = _APLY_DT.Date;
                var dtn            = DateTime.Now.Date;
                var _APLY_ODT_From = TypeTransfer.stringToDateTimeN(APLY_ODT_From);
                var _APLY_ODT_To   = TypeTransfer.stringToDateTimeN(APLY_ODT_To).DateToLatestTime();

                int TOTAL = 0;
                INVENTORY_STATUSs.AddRange(new List <string>()
                {
                    ((int)AccessInventoryType._5).ToString(), //預約取出,計庫存
                    ((int)AccessInventoryType._6).ToString(), //已被取出,計庫存
                    ((int)AccessInventoryType._9).ToString()
                });                                           //預約存入,計庫存
                //預約取出 , 用印  , 存入用印
                var _IS = db.ITEM_SEAL.AsNoTracking()         //判斷是否在庫
                          .Where(x => INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS), _APLY_DT_Date == dtn)
                          .Where(x =>
                                 (INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS) && x.PUT_DATE_ACCESS <= _APLY_DT) // 在庫 且 存入日期 <= 庫存日期  //(18/12/27 update x.PUT_DATE => x.PUT_DATE_ACCESS)
                                 ||
                                 (x.INVENTORY_STATUS == INVENTORY_STATUSg &&
                                  x.PUT_DATE_ACCESS <= _APLY_DT && //(18 / 12 / 27 update x.PUT_DATE => x.PUT_DATE_ACCESS)
                                  _APLY_DT < x.GET_DATE),          //存入日期 <= 庫存日期 且 庫存日期 < 取出日期
                                 _APLY_DT_Date != dtn)
                          .Where(x => x.CHARGE_DEPT == vdept, vdept != "All")
                          .Where(x => x.CHARGE_SECT == vsect, vsect != "All")
                          .Where(x => x.PUT_DATE_ACCESS >= _APLY_ODT_From, _APLY_ODT_From != null) //(18 / 12 / 27 update x.PUT_DATE => x.PUT_DATE_ACCESS)
                          .Where(x => x.PUT_DATE_ACCESS <= _APLY_ODT_To, _APLY_ODT_To != null)     //(18 / 12 / 27 update x.PUT_DATE => x.PUT_DATE_ACCESS)
                          .Where(x => x.TREA_ITEM_NAME == JobProject).ToList();

                var depts = new List <VW_OA_DEPT>();
                //var types = new List<SYS_CODE>();
                using (DB_INTRAEntities dbINTRA = new DB_INTRAEntities())
                {
                    depts = dbINTRA.VW_OA_DEPT.AsNoTracking().Where(x => x.DPT_CD != null).ToList();
                }

                //types = db.SYS_CODE.AsNoTracking().Where(x => x.CODE !=null).ToList();

                foreach (var Sealdata in _IS.OrderBy(x => x.PUT_DATE_ACCESS).ThenByDescending(x => x.LAST_UPDATE_DT) /*.ThenBy(x=>x.CHARGE_DEPT).ThenBy(x=>x.CHARGE_SECT)*/)
                {
                    TOTAL++;
                    var _CHARGE_DEPT = getEmpName(depts, Sealdata.CHARGE_DEPT);
                    var _CHARGE_SECT = getEmpName(depts, Sealdata.CHARGE_SECT)?.Replace(_CHARGE_DEPT, "")?.Trim();
                    ReportData = new DepositReportSealData()
                    {
                        ROW            = TOTAL,
                        PUT_DATE       = Sealdata.PUT_DATE_ACCESS.dateTimeToStr(),
                        CHARGE_DEPT    = _CHARGE_DEPT,
                        CHARGE_SECT    = _CHARGE_SECT,
                        SEAL_DESC      = Sealdata.SEAL_DESC,
                        MEMO           = Sealdata.MEMO,
                        CHARGE_DEPT_ID = Sealdata.CHARGE_DEPT,
                        CHARGE_SECT_ID = Sealdata.CHARGE_SECT
                    };
                    ReportDataList.Add(ReportData);
                }
            }
            resultsTable.Tables.Add(ReportDataList.ToDataTable());
            return(resultsTable);
        }
示例#2
0
        public override DataSet GetData(List <reportParm> parms)
        {
            //報表資料
            List <DepositReportESTATEData> ReportDataList = new List <DepositReportESTATEData>();
            var    resultsTable  = new DataSet();
            var    ReportData    = new DepositReportESTATEData();
            string vdept         = parms.Where(x => x.key == "vdept").FirstOrDefault()?.value ?? string.Empty;
            string vsect         = parms.Where(x => x.key == "vsect").FirstOrDefault()?.value ?? string.Empty;
            string BOOK_NO       = parms.Where(x => x.key == "vBook_No").FirstOrDefault()?.value ?? string.Empty;
            string JobProject    = parms.Where(x => x.key == "vJobProject").FirstOrDefault()?.value ?? string.Empty;
            string APLY_DT_From  = parms.Where(x => x.key == "APLY_DT_From").FirstOrDefault()?.value ?? string.Empty; //庫存日期
            string APLY_ODT_From = parms.Where(x => x.key == "APLY_ODT_From").FirstOrDefault()?.value ?? string.Empty;
            string APLY_ODT_To   = parms.Where(x => x.key == "APLY_ODT_To").FirstOrDefault()?.value ?? string.Empty;

            using (TreasuryDBEntities db = new TreasuryDBEntities())
            {
                var _APLY_DT       = TypeTransfer.stringToDateTime(APLY_DT_From).DateToLatestTime();
                var _APLY_DT_Date  = _APLY_DT.Date;
                var dtn            = DateTime.Now.Date;
                var _APLY_ODT_From = TypeTransfer.stringToDateTimeN(APLY_ODT_From);
                var _APLY_ODT_To   = TypeTransfer.stringToDateTimeN(APLY_ODT_To).DateToLatestTime();

                int TOTAL = 0;
                INVENTORY_STATUSs.AddRange(new List <string>()
                {
                    ((int)AccessInventoryType._5).ToString(),    //預約取出,計庫存
                    ((int)AccessInventoryType._6).ToString(),    //已被取出,計庫存
                    ((int)AccessInventoryType._9).ToString()
                });                                              //預約存入,計庫存
                var _IRE = db.ITEM_REAL_ESTATE.AsNoTracking().ToList();

                _IRE = db.ITEM_REAL_ESTATE.AsNoTracking()//判斷是否在庫
                       .Where(x => INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS), _APLY_DT_Date == dtn)
                       .Where(x =>
                              (INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS) && x.PUT_DATE <= _APLY_DT) // 在庫 且 存入日期 <= 庫存日期
                              ||
                              (x.INVENTORY_STATUS == INVENTORY_STATUSg &&
                               x.PUT_DATE <= _APLY_DT &&
                               _APLY_DT < x.GET_DATE), //存入日期 <= 庫存日期 且 庫存日期 < 取出日期
                              _APLY_DT_Date != dtn)
                       .Where(x => x.CHARGE_DEPT == vdept, vdept != "All")
                       .Where(x => x.CHARGE_SECT == vsect, vsect != "All")
                       .Where(x => x.GROUP_NO.ToString() == BOOK_NO, BOOK_NO != "All")
                       .Where(x => x.PUT_DATE >= _APLY_ODT_From, _APLY_ODT_From != null)
                       .Where(x => x.PUT_DATE <= _APLY_ODT_To, _APLY_ODT_To != null).ToList();

                var depts = new List <VW_OA_DEPT>();
                var types = new List <SYS_CODE>();
                var book  = new List <ITEM_BOOK>();
                using (DB_INTRAEntities dbINTRA = new DB_INTRAEntities())
                {
                    depts = dbINTRA.VW_OA_DEPT.AsNoTracking().Where(x => x.DPT_CD != null).ToList();
                }
                types = db.SYS_CODE.AsNoTracking().Where(x => x.CODE != null && x.CODE_TYPE == "ESTATE_TYPE").ToList();
                book  = db.ITEM_BOOK.AsNoTracking().Where(x => x.GROUP_NO.ToString() != null).ToList();
                _IRE.ForEach(x =>
                {
                    x.ESTATE_FORM_NO = types.FirstOrDefault(y => y.CODE_VALUE == x.ESTATE_FORM_NO)?.CODE;
                });
                foreach (var ESTATEdata in _IRE.OrderBy(x => x.GROUP_NO).ThenBy(x => x.PUT_DATE).ThenBy(x => x.ESTATE_FORM_NO).ThenBy(x => x.ESTATE_DATE).ThenBy(x => x.OWNERSHIP_CERT_NO))
                {
                    TOTAL++;
                    var _CHARGE_DEPT = getEmpName(depts, ESTATEdata.CHARGE_DEPT);
                    var _CHARGE_SECT = getEmpName(depts, ESTATEdata.CHARGE_SECT)?.Replace(_CHARGE_DEPT, "")?.Trim();
                    ReportData = new DepositReportESTATEData()
                    {
                        ROW               = TOTAL,
                        PUT_DATE          = ESTATEdata.PUT_DATE.dateTimeToStr(),
                        ESTATE_FORM_NO    = types.FirstOrDefault(x => x.CODE == ESTATEdata.ESTATE_FORM_NO)?.CODE_VALUE,
                        ESTATE_DATE       = ESTATEdata.ESTATE_DATE.dateTimeToStr(),
                        OWNERSHIP_CERT_NO = ESTATEdata.OWNERSHIP_CERT_NO,
                        LAND_BUILDING_NO  = ESTATEdata.LAND_BUILDING_NO,
                        HOUSE_NO          = ESTATEdata.HOUSE_NO,
                        ESTATE_SEQ        = ESTATEdata.ESTATE_SEQ,
                        BOOK_NO_DETAIL    = ESTATEdata.GROUP_NO.ToString(),
                        BUILDING_NAME     = getBuildName(book, ESTATEdata.GROUP_NO.ToString()),
                        LOCATED           = getLocated(book, ESTATEdata.GROUP_NO.ToString()),
                        CHARGE_DEPT       = _CHARGE_DEPT,
                        CHARGE_SECT       = _CHARGE_SECT,
                        CHARGE_DEPT_ID    = ESTATEdata.CHARGE_DEPT,
                        CHARGE_SECT_ID    = ESTATEdata.CHARGE_SECT,
                        MEMO              = ESTATEdata.MEMO,
                    };
                    ReportDataList.Add(ReportData);
                }
            }
            resultsTable.Tables.Add(ReportDataList.ToDataTable());
            return(resultsTable);
        }
示例#3
0
        public override DataSet GetData(List <reportParm> parms)
        {
            //報表資料
            List <DepositReportMargingData> ReportDataList = new List <DepositReportMargingData>();
            var    resultsTable  = new DataSet();
            var    ReportData    = new DepositReportMargingData();
            string vdept         = parms.Where(x => x.key == "vdept").FirstOrDefault()?.value ?? string.Empty;
            string vsect         = parms.Where(x => x.key == "vsect").FirstOrDefault()?.value ?? string.Empty;
            string JobProject    = parms.Where(x => x.key == "vJobProject").FirstOrDefault()?.value ?? string.Empty;
            string APLY_DT_From  = parms.Where(x => x.key == "APLY_DT_From").FirstOrDefault()?.value ?? string.Empty; //庫存日期
            string APLY_ODT_From = parms.Where(x => x.key == "APLY_ODT_From").FirstOrDefault()?.value ?? string.Empty;
            string APLY_ODT_To   = parms.Where(x => x.key == "APLY_ODT_To").FirstOrDefault()?.value ?? string.Empty;

            using (TreasuryDBEntities db = new TreasuryDBEntities())
            {
                var _APLY_DT       = TypeTransfer.stringToDateTime(APLY_DT_From).DateToLatestTime();
                var _APLY_DT_Date  = _APLY_DT.Date;
                var dtn            = DateTime.Now.Date;
                var _APLY_ODT_From = TypeTransfer.stringToDateTimeN(APLY_ODT_From);
                var _APLY_ODT_To   = TypeTransfer.stringToDateTimeN(APLY_ODT_To).DateToLatestTime();

                INVENTORY_STATUSs.AddRange(new List <string>()
                {
                    ((int)AccessInventoryType._5).ToString(),    //預約取出,計庫存
                    ((int)AccessInventoryType._6).ToString(),    //已被取出,計庫存
                    ((int)AccessInventoryType._9).ToString()
                });                                              //預約存入,計庫存

                var _IRD = db.ITEM_REFUNDABLE_DEP.AsNoTracking() //判斷是否在庫
                           .Where(x => INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS), _APLY_DT_Date == dtn)
                           .Where(x =>
                                  (INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS) && x.PUT_DATE <= _APLY_DT) // 在庫 且 存入日期 <= 庫存日期
                                  ||
                                  (x.INVENTORY_STATUS == INVENTORY_STATUSg &&
                                   x.PUT_DATE <= _APLY_DT &&
                                   _APLY_DT < x.GET_DATE), //存入日期 <= 庫存日期 且 庫存日期 < 取出日期
                                  _APLY_DT_Date != dtn)
                           .Where(x => x.CHARGE_DEPT == vdept, vdept != "All")
                           .Where(x => x.CHARGE_SECT == vsect, vsect != "All")
                           .Where(x => x.PUT_DATE >= _APLY_ODT_From, _APLY_ODT_From != null)
                           .Where(x => x.PUT_DATE <= _APLY_ODT_To, _APLY_ODT_To != null)
                           .ToList();

                var depts = new List <VW_OA_DEPT>();
                var types = new List <SYS_CODE>();
                using (DB_INTRAEntities dbINTRA = new DB_INTRAEntities())
                {
                    depts = dbINTRA.VW_OA_DEPT.AsNoTracking().Where(x => x.DPT_CD != null).ToList();
                }

                types = db.SYS_CODE.AsNoTracking().Where(x => x.CODE != null).ToList();

                foreach (var Stockdata in _IRD.OrderBy(x => x.MARGIN_DEP_TYPE).ThenBy(x => x.ITEM_ID).ThenBy(x => x.BOOK_NO).ThenBy(x => x.PUT_DATE).ThenBy(x => x.CHARGE_DEPT).ThenBy(x => x.CHARGE_SECT))
                {
                    var _CHARGE_DEPT = getEmpName(depts, Stockdata.CHARGE_DEPT);
                    var _CHARGE_SECT = !_CHARGE_DEPT.IsNullOrWhiteSpace() ? getEmpName(depts, Stockdata.CHARGE_SECT)?.Replace(_CHARGE_DEPT, "")?.Trim() : null;
                    ReportData = new DepositReportMargingData()
                    {
                        MARGIN_DEP_TYPE = getMDTtype(types, Stockdata.MARGIN_DEP_TYPE),
                        ITEM_ID         = Stockdata.ITEM_ID,
                        BOOK_NO         = Stockdata.BOOK_NO,
                        PUT_DATE        = Stockdata.PUT_DATE.dateTimeToStr(),
                        CHARGE_DEPT     = _CHARGE_DEPT,
                        CHARGE_SECT     = !_CHARGE_SECT.IsNullOrWhiteSpace() ? _CHARGE_SECT : null,
                        TRAD_PARTNERS   = Stockdata.TRAD_PARTNERS,
                        AMOUNT          = Stockdata.AMOUNT,
                        WORKPLACE_CODE  = Stockdata.WORKPLACE_CODE,
                        DESCRIPTION     = Stockdata.DESCRIPTION,
                        MEMO            = Stockdata.MEMO,
                        CHARGE_DEPT_ID  = Stockdata.CHARGE_DEPT,
                        CHARGE_SECT_ID  = Stockdata.CHARGE_SECT
                    };
                    ReportDataList.Add(ReportData);
                }
            }
            resultsTable.Tables.Add(ReportDataList.ToDataTable());
            return(resultsTable);
        }
示例#4
0
        public override DataSet GetData(List <reportParm> parms)
        {
            //報表資料
            List <DepositReportCAData> ReportDataList = new List <DepositReportCAData>();
            var    resultsTable  = new DataSet();
            var    ReportData    = new DepositReportCAData();
            string vdept         = parms.Where(x => x.key == "vdept").FirstOrDefault()?.value ?? string.Empty;
            string vsect         = parms.Where(x => x.key == "vsect").FirstOrDefault()?.value ?? string.Empty;
            string JobProject    = parms.Where(x => x.key == "vJobProject").FirstOrDefault()?.value ?? string.Empty;
            string APLY_DT_From  = parms.Where(x => x.key == "APLY_DT_From").FirstOrDefault()?.value ?? string.Empty; //庫存日期
            string APLY_ODT_From = parms.Where(x => x.key == "APLY_ODT_From").FirstOrDefault()?.value ?? string.Empty;
            string APLY_ODT_To   = parms.Where(x => x.key == "APLY_ODT_To").FirstOrDefault()?.value ?? string.Empty;

            using (TreasuryDBEntities db = new TreasuryDBEntities())
            {
                var _APLY_DT       = TypeTransfer.stringToDateTime(APLY_DT_From).DateToLatestTime();
                var _APLY_DT_Date  = _APLY_DT.Date;
                var dtn            = DateTime.Now.Date;
                var _APLY_ODT_From = TypeTransfer.stringToDateTimeN(APLY_ODT_From);
                var _APLY_ODT_To   = TypeTransfer.stringToDateTimeN(APLY_ODT_To).DateToLatestTime();
                int TOTAL          = 0;
                INVENTORY_STATUSs.AddRange(new List <string>()
                {
                    ((int)AccessInventoryType._5).ToString(), //預約取出,計庫存
                    ((int)AccessInventoryType._6).ToString(), //已被取出,計庫存
                    ((int)AccessInventoryType._9).ToString()
                });                                           //預約存入,計庫存
                var _IC = db.ITEM_CA.AsNoTracking()           //判斷是否在庫
                          .Where(x => INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS), _APLY_DT_Date == dtn)
                          .Where(x =>
                                 (INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS) && x.PUT_DATE <= _APLY_DT) // 在庫 且 存入日期 <= 庫存日期
                                 ||
                                 (x.INVENTORY_STATUS == INVENTORY_STATUSg &&
                                  x.PUT_DATE <= _APLY_DT &&
                                  _APLY_DT < x.GET_DATE), //存入日期 <= 庫存日期 且 庫存日期 < 取出日期
                                 _APLY_DT_Date != dtn)
                          .Where(x => x.CHARGE_DEPT == vdept, vdept != "All")
                          .Where(x => x.CHARGE_SECT == vsect, vsect != "All")
                          .Where(x => x.PUT_DATE >= _APLY_ODT_From, _APLY_ODT_From != null)
                          .Where(x => x.PUT_DATE <= _APLY_ODT_To, _APLY_ODT_To != null)
                          .ToList();

                var depts = new List <VW_OA_DEPT>();
                var types = new List <SYS_CODE>();
                using (DB_INTRAEntities dbINTRA = new DB_INTRAEntities())
                {
                    depts = dbINTRA.VW_OA_DEPT.AsNoTracking().Where(x => x.DPT_CD != null).ToList();
                }
                types = db.SYS_CODE.AsNoTracking().Where(x => x.CODE != null).ToList();
                foreach (var CAdata in _IC /*.OrderBy(x => x.PUT_DATE).ThenBy(x=>x.CHARGE_DEPT)*/.OrderBy(x => x.CHARGE_DEPT).ThenBy(x => x.CHARGE_SECT).ThenBy(x => x.CA_USE).ThenBy(x => x.CA_DESC).ThenBy(x => x.BANK).ThenBy(x => x.CA_NUMBER))
                {
                    TOTAL++;
                    var _CHARGE_DEPT = getEmpName(depts, CAdata.CHARGE_DEPT);
                    var _CHARGE_SECT = getEmpName(depts, CAdata.CHARGE_SECT)?.Replace(_CHARGE_DEPT, "")?.Trim();
                    ReportData = new DepositReportCAData()
                    {
                        ROW            = TOTAL,
                        PUT_DATE       = CAdata.PUT_DATE.dateTimeToStr(),
                        CHARGE_DEPT    = _CHARGE_DEPT,
                        CHARGE_SECT    = _CHARGE_SECT,
                        CA_DESC        = getCAdesc(types, CAdata.CA_DESC),
                        CA_USE         = getCAuse(types, CAdata.CA_USE),
                        BANK           = CAdata.BANK,
                        CA_NUMBER      = CAdata.CA_NUMBER,
                        MEMO           = CAdata.MEMO,
                        CHARGE_DEPT_ID = CAdata.CHARGE_DEPT,
                        CHARGE_SECT_ID = CAdata.CHARGE_SECT
                    };
                    ReportDataList.Add(ReportData);
                }
            }
            resultsTable.Tables.Add(ReportDataList.ToDataTable());
            return(resultsTable);
        }
示例#5
0
        public override DataSet GetData(List <reportParm> parms)
        {
            //報表資料
            List <DepositReportDEPOSIT_DEP_ORDER_M_Data> ReportDataList  = new List <DepositReportDEPOSIT_DEP_ORDER_M_Data>();
            List <DepositReportDEPOSIT_DEP_ORDER_M_Data> ReportDataList2 = new List <DepositReportDEPOSIT_DEP_ORDER_M_Data>();
            var    resultsTable  = new DataSet();
            var    ReportData    = new DepositReportDEPOSIT_DEP_ORDER_M_Data();
            string vdept         = parms.Where(x => x.key == "vdept").FirstOrDefault()?.value ?? string.Empty;          //權責部門
            string vsect         = parms.Where(x => x.key == "vsect").FirstOrDefault()?.value ?? string.Empty;          //權責科別
            string JobProject    = parms.Where(x => x.key == "vJobProject").FirstOrDefault()?.value ?? string.Empty;    //庫存表名稱
            string APLY_DT_From  = parms.Where(x => x.key == "APLY_DT_From").FirstOrDefault()?.value ?? string.Empty;   //庫存日期
            string APLY_ODT_From = parms.Where(x => x.key == "APLY_ODT_From").FirstOrDefault()?.value ?? string.Empty;  //入庫日期(起)
            string APLY_ODT_To   = parms.Where(x => x.key == "APLY_ODT_To").FirstOrDefault()?.value ?? string.Empty;    //入庫日期(迄)
            string TRAD_Partners = parms.Where(x => x.key == "vTRAD_Partners").FirstOrDefault()?.value ?? string.Empty; //交易對象

            using (TreasuryDBEntities db = new TreasuryDBEntities())
            {
                var _APLY_DT         = TypeTransfer.stringToDateTime(APLY_DT_From).DateToLatestTime();
                var _APLY_DT_Date    = _APLY_DT.Date;
                var dtn              = DateTime.Now.Date;
                var dtnStr           = dtn.ToString("yyyy/MM/dd");
                var _APLY_ODT_From   = TypeTransfer.stringToDateTimeN(APLY_ODT_From);
                var _APLY_ODT_To     = TypeTransfer.stringToDateTimeN(APLY_ODT_To).DateToLatestTime();
                var _DEP_SET_QUALITY = db.ITEM_DEP_ORDER_M.AsNoTracking().Select(x => x.DEP_SET_QUALITY).ToList();

                List <ITEM_DEP_ORDER_M> _IDOM = new List <ITEM_DEP_ORDER_M>();

                var _IDOM_N = db.ITEM_DEP_ORDER_M.AsNoTracking()
                              .Where(x => INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS), _APLY_DT_Date == dtn)
                              .Where(x =>
                                     (INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS) && x.PUT_DATE <= _APLY_DT) // 在庫 且 存入日期 <= 庫存日期
                                     ||
                                     (x.INVENTORY_STATUS == INVENTORY_STATUSg &&
                                      x.PUT_DATE <= _APLY_DT &&
                                      _APLY_DT < x.GET_DATE), //存入日期 <= 庫存日期 且 庫存日期 < 取出日期
                                     _APLY_DT_Date != dtn)
                              .Where(x => x.TRAD_PARTNERS == TRAD_Partners, TRAD_Partners != "All")
                              .Where(x => x.CHARGE_DEPT == vdept, vdept != "All")
                              .Where(x => x.CHARGE_SECT == vsect, vsect != "All")
                              .Where(x => x.PUT_DATE >= _APLY_ODT_From, _APLY_ODT_From != null)
                              .Where(x => x.PUT_DATE <= _APLY_ODT_To, _APLY_ODT_To != null)
                              .Where(x => x.DEP_SET_QUALITY == "N") //設質否等於N
                              .ToList();

                _IDOM.AddRange(_IDOM_N);

                var _IDOM_Y = db.ITEM_DEP_ORDER_M.AsNoTracking()
                              .Where(x => x.PUT_DATE <= _APLY_DT && _APLY_DT < x.TRANS_EXPIRY_DATE)
                              //存入日期 <= 庫存日期 且 庫存日期 < 轉期後到期日
                              .Where(x => x.TRAD_PARTNERS == TRAD_Partners, TRAD_Partners != "All")
                              .Where(x => x.CHARGE_DEPT == vdept, vdept != "All")
                              .Where(x => x.CHARGE_SECT == vsect, vsect != "All")
                              .Where(x => x.PUT_DATE >= _APLY_ODT_From, _APLY_ODT_From != null)
                              .Where(x => x.PUT_DATE <= _APLY_ODT_To, _APLY_ODT_To != null)
                              .Where(x => x.DEP_SET_QUALITY == "Y") //設質否等於Y
                              .ToList();

                _IDOM.AddRange(_IDOM_Y);

                var _IDOM_ItemIDs     = _IDOM.Select(x => x.ITEM_ID).ToList();
                var _ITEM_DEP_ORDER_D = db.ITEM_DEP_ORDER_D.AsNoTracking()
                                        .Where(x => _IDOM_ItemIDs.Contains(x.ITEM_ID)).ToList();

                var depts = new List <VW_OA_DEPT>();
                var types = new List <SYS_CODE>();
                using (DB_INTRAEntities dbINTRA = new DB_INTRAEntities())
                {
                    depts = dbINTRA.VW_OA_DEPT.AsNoTracking().Where(x => x.DPT_CD != null).ToList();
                }

                types = db.SYS_CODE.AsNoTracking().Where(x => x.CODE != null).ToList();

                foreach (var Stockdata in _IDOM
                         //.OrderByDescending(x => x.CURRENCY != "NTD")
                         //.ThenBy(x => x.CURRENCY)
                         //.ThenBy(x => x.DEP_TYPE)
                         //.ThenByDescending(x => x.COMMIT_DATE)
                         //.ThenBy(x => x.DEP_SET_QUALITY)
                         )
                {
                    ReportDataList.Add(new DepositReportDEPOSIT_DEP_ORDER_M_Data()
                    {
                        ITEMID          = Stockdata.ITEM_ID,
                        PUT_DATE        = Stockdata.PUT_DATE?.dateTimeToStr(),
                        COMMIT_DATE     = Stockdata.COMMIT_DATE.dateTimeToStr(),
                        EXPIRY_DATE     = Stockdata.EXPIRY_DATE.dateTimeToStr(),
                        TRAD_PARTNERS   = Stockdata.TRAD_PARTNERS,
                        CURRENCY        = Stockdata.CURRENCY,
                        CURRENCY_Flag   = Stockdata.CURRENCY == "NTD" ? "台幣" : "外幣",
                        DEP_TYPE        = getDEPName(types, Stockdata.DEP_TYPE),
                        INTEREST_RATE   = Stockdata.INTEREST_RATE,
                        MEMO            = Stockdata.MEMO,
                        CHARGE_DEPT_ID  = Stockdata.CHARGE_DEPT,
                        CHARGE_SECT_ID  = Stockdata.CHARGE_SECT,
                        DEP_SET_QUALITY = Stockdata.DEP_SET_QUALITY,
                    });
                }

                //群組 : 類別 & 交易類型 群組
                foreach (var group in ReportDataList.GroupBy(x => new { x.CURRENCY_Flag, x.DEP_TYPE }).OrderBy(x => x.Key.CURRENCY_Flag))
                {
                    Dictionary <string, decimal> _data = new Dictionary <string, decimal>();
                    //201905220094-00  190524 Edited by Bianco 新增張數小計
                    Dictionary <string, int> _data_CNT = new Dictionary <string, int>();

                    #region 排序一 庫存日=承作日期時,庫存日當日承作的定期存單排在最上面 再依到期日先後/登打順序排列
                    int _pk_id = 0;
                    foreach (var item in group.Where(x => x.DEP_SET_QUALITY == "N" && x.PUT_DATE == x.COMMIT_DATE && x.COMMIT_DATE == APLY_DT_From)
                             .OrderBy(x => x.PUT_DATE == dtnStr).ThenBy(x => x.EXPIRY_DATE).ThenBy(x => x.ITEMID))
                    {
                        _pk_id = _pk_id + 1;
                        //var _setData = setData(_ITEM_DEP_ORDER_D, item);
                        var _setData = setData(_ITEM_DEP_ORDER_D, item, _pk_id);
                        ReportDataList2.AddRange(_setData.Item1);
                        string  key   = $@"{item.CURRENCY},{item.DEP_SET_QUALITY}"; //幣別,設質否
                        decimal value = 0M;
                        int     count = 0;                                          //201905220094-00  190524 Edited by Bianco 新增張數小計

                        if (_data.TryGetValue(key, out value))
                        {
                            value     += _setData.Item2;
                            _data[key] = value;
                        }
                        else
                        {
                            _data.Add(key, _setData.Item2);
                        }
                        //201905220094-00  190524 Edited by Bianco 新增張數小計
                        if (_data_CNT.TryGetValue(key, out count))
                        {
                            count         += _setData.Item3;
                            _data_CNT[key] = count;
                        }
                        else
                        {
                            _data_CNT.Add(key, _setData.Item3);
                        }
                    }

                    #endregion 排序一 庫存日=承作日期時,庫存日當日承作的定期存單排在最上面 再依到期日先後/登打順序排列

                    #region 排序二 其他的定期存單列示在中間區塊 再依到期日/承作日/登打順序排列
                    _pk_id = 0;
                    foreach (var item in group.Where(x => x.DEP_SET_QUALITY == "N" && (x.PUT_DATE != x.COMMIT_DATE || x.COMMIT_DATE != APLY_DT_From))
                             .OrderBy(x => x.EXPIRY_DATE).ThenBy(x => x.COMMIT_DATE).ThenBy(x => x.ITEMID))
                    {
                        _pk_id = _pk_id + 1;
                        //var _setData = setData(_ITEM_DEP_ORDER_D, item);
                        var _setData = setData(_ITEM_DEP_ORDER_D, item, _pk_id);
                        ReportDataList2.AddRange(_setData.Item1);
                        string  key   = $@"{item.CURRENCY},{item.DEP_SET_QUALITY}"; //幣別,設質否
                        decimal value = 0M;
                        int     count = 0;                                          //201905220094-00  190524 Edited by Bianco 新增張數小計

                        if (_data.TryGetValue(key, out value))
                        {
                            value     += _setData.Item2;
                            _data[key] = value;
                        }
                        else
                        {
                            _data.Add(key, _setData.Item2);
                        }
                        //201905220094-00  190524 Edited by Bianco 新增張數小計
                        if (_data_CNT.TryGetValue(key, out count))
                        {
                            count         += _setData.Item3;
                            _data_CNT[key] = count;
                        }
                        else
                        {
                            _data_CNT.Add(key, _setData.Item3);
                        }
                    }

                    #endregion 排序二 其他的定期存單列示在中間區塊 再依到期日/承作日/登打順序排列

                    #region 排序三 質押存單排在報表最下面 再承作日期/到期日/登打順序排列

                    foreach (var item in group.Where(x => x.DEP_SET_QUALITY == "Y")
                             .OrderBy(x => x.COMMIT_DATE).ThenBy(x => x.EXPIRY_DATE).ThenBy(x => x.ITEMID))
                    {
                        _pk_id = _pk_id + 1;
                        //var _setData = setData(_ITEM_DEP_ORDER_D, item);
                        var _setData = setData(_ITEM_DEP_ORDER_D, item, _pk_id);
                        ReportDataList2.AddRange(_setData.Item1);
                        string  key   = $@"{item.CURRENCY},{item.DEP_SET_QUALITY}"; //幣別,設質否
                        decimal value = 0M;
                        int     count = 0;                                          //201905220094-00  190524 Edited by Bianco 新增張數小計

                        if (_data.TryGetValue(key, out value))
                        {
                            value     += _setData.Item2;
                            _data[key] = value;
                        }
                        else
                        {
                            _data.Add(key, _setData.Item2);
                        }
                        //201905220094-00  190524 Edited by Bianco 新增張數小計
                        if (_data_CNT.TryGetValue(key, out count))
                        {
                            count         += _setData.Item3;
                            _data_CNT[key] = count;
                        }
                        else
                        {
                            _data_CNT.Add(key, _setData.Item3);
                        }
                    }

                    #endregion 排序三 質押存單排在報表最下面 再承作日期/到期日/登打順序排列

                    //排序 : 承作日期(降冪)+設質否(按N、Y順序)
                    //foreach (var item in group.OrderByDescending(x => x.CURRENCY != "NTD").ThenByDescending(x => x.COMMIT_DATE).ThenBy(x => x.DEP_SET_QUALITY))
                    //{
                    //    decimal total_DENOMINATION = 0M;

                    //    List<DepositReportDEPOSIT_DEP_ORDER_M_Data> tempData =
                    //        new List<DepositReportDEPOSIT_DEP_ORDER_M_Data>();

                    //    //明細
                    //    foreach (var i in _ITEM_DEP_ORDER_D.Where(x => x.ITEM_ID == item.ITEMID).OrderBy(x => x.DATA_SEQ))
                    //    {
                    //        ReportData = new DepositReportDEPOSIT_DEP_ORDER_M_Data()
                    //        {
                    //            TYPE = "1",
                    //            ITEMID = item.ITEMID,
                    //            COMMIT_DATE = item.COMMIT_DATE,
                    //            EXPIRY_DATE = item.EXPIRY_DATE,
                    //            TRAD_PARTNERS = item.TRAD_PARTNERS,
                    //            CURRENCY = item.CURRENCY,
                    //            CURRENCY_Flag = item.CURRENCY_Flag,
                    //            DEP_TYPE = item.DEP_TYPE,
                    //            INTEREST_RATE = item.INTEREST_RATE,
                    //            DEP_NO_B = i.DEP_NO_B,
                    //            DEP_NO_E = i.DEP_NO_E,
                    //            DEP_CNT = i.DEP_CNT,
                    //            DENOMINATION = i.DENOMINATION,
                    //            SUBTOTAL_DENOMINATION = i.SUBTOTAL_DENOMINATION,
                    //            //SUMTOTAL_DENOMINATION = 0,
                    //            MEMO = item.MEMO,
                    //            CHARGE_DEPT_ID = item.CHARGE_DEPT,
                    //            CHARGE_SECT_ID = item.CHARGE_SECT,
                    //            DEP_SET_QUALITY = item.DEP_SET_QUALITY,
                    //        };
                    //        total_DENOMINATION += ReportData.SUBTOTAL_DENOMINATION;
                    //        tempData.Add(ReportData);
                    //        //ReportDataList2.Add(ReportData);
                    //    }

                    //    tempData.ForEach(x => x.SUMTOTAL_DENOMINATION = total_DENOMINATION);
                    //    ReportDataList2.AddRange(tempData);

                    //    //ReportDataList2.Add(new DepositReportDEPOSIT_DEP_ORDER_M_Data() {
                    //    //    TYPE = "1",
                    //    //    ITEMID = item.ITEMID,
                    //    //    COMMIT_DATE = item.COMMIT_DATE,
                    //    //    EXPIRY_DATE = item.EXPIRY_DATE,
                    //    //    TRAD_PARTNERS = item.TRAD_PARTNERS,
                    //    //    CURRENCY = item.CURRENCY,
                    //    //    CURRENCY_Flag = item.CURRENCY_Flag,
                    //    //    DEP_TYPE = item.DEP_TYPE,
                    //    //    INTEREST_RATE = item.INTEREST_RATE,
                    //    //    DEP_CNT = 0,
                    //    //    DENOMINATION = 0,
                    //    //    SUBTOTAL_DENOMINATION = 0,
                    //    //    SUMTOTAL_DENOMINATION = total_DENOMINATION,
                    //    //    DEP_SET_QUALITY = item.DEP_SET_QUALITY
                    //    //});

                    //    string key = $@"{item.CURRENCY},{item.DEP_SET_QUALITY}"; //幣別,設質否
                    //    decimal value = 0M;
                    //    if (_data.TryGetValue(key, out value))
                    //    {
                    //        value += total_DENOMINATION;
                    //        _data[key] = value;
                    //    }
                    //    else
                    //    {
                    //        _data.Add(key, total_DENOMINATION);
                    //    }
                    //}

                    ReportDataList2.Add(new DepositReportDEPOSIT_DEP_ORDER_M_Data()
                    {
                        TYPE = "3",
                        SUMTOTAL_DENOMINATION = _data.Sum(x => x.Value),
                        CURRENCY_Flag         = group.Key.CURRENCY_Flag,
                        DEP_TYPE         = group.Key.DEP_TYPE,
                        SUMTOTAL_DEP_CNT = _data_CNT.Sum(x => x.Value)        //201905220094-00  190524 Edited by Bianco 新增張數小計
                    });

                    ReportDataList2.Add(new DepositReportDEPOSIT_DEP_ORDER_M_Data()
                    {
                        TYPE          = "3",
                        CURRENCY_Flag = group.Key.CURRENCY_Flag,
                        DEP_TYPE      = group.Key.DEP_TYPE,
                    });

                    ReportDataList2.Add(new DepositReportDEPOSIT_DEP_ORDER_M_Data()
                    {
                        TYPE = "3",
                        //COMMIT_DATE = "幣別",
                        //EXPIRY_DATE = "設質否",
                        //TRAD_PARTNERS = "面額合計",
                        PK_ID         = "幣別",
                        COMMIT_DATE   = "設質否",
                        EXPIRY_DATE   = "面額合計",
                        CURRENCY_Flag = group.Key.CURRENCY_Flag,
                        DEP_TYPE      = group.Key.DEP_TYPE,
                    });

                    foreach (var d in _data.OrderBy(x => x.Key))
                    {
                        ReportDataList2.Add(new DepositReportDEPOSIT_DEP_ORDER_M_Data()
                        {
                            TYPE = "3",
                            //COMMIT_DATE = d.Key.Split(',')[0],
                            //EXPIRY_DATE = d.Key.Split(',')[1],
                            //TRAD_PARTNERS = d.Value.ToString().formateThousand(),
                            PK_ID         = d.Key.Split(',')[0],
                            COMMIT_DATE   = d.Key.Split(',')[1],
                            EXPIRY_DATE   = d.Value.ToString().formateThousand(),
                            CURRENCY_Flag = group.Key.CURRENCY_Flag,
                            DEP_TYPE      = group.Key.DEP_TYPE,
                        });
                    }
                }
            }

            resultsTable.Tables.Add(ReportDataList2.ToDataTable());
            return(resultsTable);
        }
示例#6
0
        public override DataSet GetData(List <reportParm> parms)
        {
            //報表資料
            List <DepositReportSTOCKData> ReportDataList = new List <DepositReportSTOCKData>();
            var    resultsTable  = new DataSet();
            var    ReportData    = new DepositReportSTOCKData();
            string vdept         = parms.Where(x => x.key == "vdept").FirstOrDefault()?.value ?? string.Empty;
            string vsect         = parms.Where(x => x.key == "vsect").FirstOrDefault()?.value ?? string.Empty;
            string BOOK_NO       = parms.Where(x => x.key == "vName").FirstOrDefault()?.value ?? string.Empty;
            string JobProject    = parms.Where(x => x.key == "vJobProject").FirstOrDefault()?.value ?? string.Empty;
            string APLY_DT_From  = parms.Where(x => x.key == "APLY_DT_From").FirstOrDefault()?.value ?? string.Empty; //庫存日期
            string APLY_ODT_From = parms.Where(x => x.key == "APLY_ODT_From").FirstOrDefault()?.value ?? string.Empty;
            string APLY_ODT_To   = parms.Where(x => x.key == "APLY_ODT_To").FirstOrDefault()?.value ?? string.Empty;

            using (TreasuryDBEntities db = new TreasuryDBEntities())
            {
                var _APLY_DT       = TypeTransfer.stringToDateTime(APLY_DT_From).DateToLatestTime();
                var _APLY_DT_Date  = _APLY_DT.Date;
                var dtn            = DateTime.Now.Date;
                var _APLY_ODT_From = TypeTransfer.stringToDateTimeN(APLY_ODT_From);
                var _APLY_ODT_To   = TypeTransfer.stringToDateTimeN(APLY_ODT_To).DateToLatestTime();
                var _IS            = new List <ITEM_STOCK>();

                _IS = db.ITEM_STOCK.AsNoTracking()//判斷是否在庫
                      .Where(x => INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS), _APLY_DT_Date == dtn)
                      .Where(x =>
                             (INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS) && x.PUT_DATE <= _APLY_DT) // 在庫 且 存入日期 <= 庫存日期
                             ||
                             (x.INVENTORY_STATUS == INVENTORY_STATUSg &&
                              x.PUT_DATE <= _APLY_DT &&
                              _APLY_DT < x.GET_DATE), //存入日期 <= 庫存日期 且 庫存日期 < 取出日期
                             _APLY_DT_Date != dtn)
                      .Where(x => x.CHARGE_DEPT == vdept, vdept != "All")
                      .Where(x => x.CHARGE_SECT == vsect, vsect != "All")
                      .Where(x => x.PUT_DATE >= _APLY_ODT_From, _APLY_ODT_From != null)
                      .Where(x => x.PUT_DATE <= _APLY_ODT_To, _APLY_ODT_To != null)
                      .Where(x => x.GROUP_NO.ToString() == BOOK_NO, BOOK_NO != "All") //判斷為全部或單一
                      .ToList();

                var depts = new List <VW_OA_DEPT>();
                var area  = new List <SYS_CODE>();
                var types = new List <SYS_CODE>();
                var book  = new List <ITEM_BOOK>();
                using (DB_INTRAEntities dbINTRA = new DB_INTRAEntities())
                {
                    depts = dbINTRA.VW_OA_DEPT.AsNoTracking().Where(x => x.DPT_CD != null).ToList();
                }

                area  = db.SYS_CODE.AsNoTracking().Where(x => x.CODE != null && x.CODE_TYPE == "STOCK_AREA").ToList();
                types = db.SYS_CODE.AsNoTracking().Where(x => x.CODE != null && x.CODE_TYPE == "STOCK_TYPE").ToList();
                book  = db.ITEM_BOOK.AsNoTracking().Where(x => x.GROUP_NO.ToString() != null).ToList();

                foreach (var STOCKdata in _IS.OrderBy(x => x.GROUP_NO).ThenBy(x => x.PUT_DATE).ThenBy(x => x.TREA_BATCH_NO).ThenBy(x => x.CHARGE_DEPT).ThenBy(x => x.CHARGE_SECT).ThenBy(x => x.GROUP_NO).ThenBy(x => x.STOCK_NO_PREAMBLE).ThenBy(x => x.STOCK_NO_B))
                {
                    var _CHARGE_DEPT = getEmpName(depts, STOCKdata.CHARGE_DEPT);
                    var _CHARGE_SECT = getEmpName(depts, STOCKdata.CHARGE_SECT)?.Replace(_CHARGE_DEPT, "")?.Trim();

                    ReportData = new DepositReportSTOCKData()
                    {
                        PUT_DATE                = STOCKdata.PUT_DATE.dateTimeToStr(),
                        STOCK_NO_B              = STOCKdata.STOCK_NO_B,
                        STOCK_NO_E              = STOCKdata.STOCK_NO_E,
                        STOCK_CNT               = STOCKdata.STOCK_CNT,
                        DENOMINATION            = STOCKdata.DENOMINATION,
                        NUMBER_OF_SHARES        = STOCKdata.NUMBER_OF_SHARES,
                        AREA                    = area.FirstOrDefault(z => z.CODE == getArea(book, STOCKdata.GROUP_NO.ToString()))?.CODE_VALUE,
                        STOCK_TYPE              = types.FirstOrDefault(z => z.CODE == STOCKdata.STOCK_TYPE)?.CODE_VALUE,
                        BATCH_NO                = STOCKdata.TREA_BATCH_NO.ToString(),
                        STOCK_NO_PREAMBLE       = STOCKdata.STOCK_NO_PREAMBLE,
                        AMOUNT_PER_SHARE        = STOCKdata.AMOUNT_PER_SHARE,
                        SINGLE_NUMBER_OF_SHARES = STOCKdata.SINGLE_NUMBER_OF_SHARES,
                        CHARGE_DEPT             = _CHARGE_DEPT,
                        CHARGE_SECT             = _CHARGE_SECT,
                        MEMO                    = STOCKdata.MEMO,
                        BOOK_NO                 = STOCKdata.GROUP_NO.ToString(),
                        NAME                    = getName(book, STOCKdata.GROUP_NO.ToString()),
                        CHARGE_DEPT_ID          = STOCKdata.CHARGE_DEPT,
                        CHARGE_SECT_ID          = STOCKdata.CHARGE_SECT
                    };
                    ReportDataList.Add(ReportData);
                }
            }
            resultsTable.Tables.Add(ReportDataList.ToDataTable());
            return(resultsTable);
        }
示例#7
0
        public override DataSet GetData(List <reportParm> parms)
        {
            //報表資料
            List <DepositReportITEMIMPData> ReportDataList = new List <DepositReportITEMIMPData>();
            var    resultsTable  = new DataSet();
            var    ReportData    = new DepositReportITEMIMPData();
            string vdept         = parms.Where(x => x.key == "vdept").FirstOrDefault()?.value ?? string.Empty;
            string vsect         = parms.Where(x => x.key == "vsect").FirstOrDefault()?.value ?? string.Empty;
            string JobProject    = parms.Where(x => x.key == "vJobProject").FirstOrDefault()?.value ?? string.Empty;
            string APLY_DT_From  = parms.Where(x => x.key == "APLY_DT_From").FirstOrDefault()?.value ?? string.Empty; //庫存日期
            string APLY_ODT_From = parms.Where(x => x.key == "APLY_ODT_From").FirstOrDefault()?.value ?? string.Empty;
            string APLY_ODT_To   = parms.Where(x => x.key == "APLY_ODT_To").FirstOrDefault()?.value ?? string.Empty;

            using (TreasuryDBEntities db = new TreasuryDBEntities())
            {
                var _APLY_DT       = TypeTransfer.stringToDateTime(APLY_DT_From).DateToLatestTime();
                var _APLY_DT_Date  = _APLY_DT.Date;
                var dtn            = DateTime.Now.Date;
                var _APLY_ODT_From = TypeTransfer.stringToDateTimeN(APLY_ODT_From);
                var _APLY_ODT_To   = TypeTransfer.stringToDateTimeN(APLY_ODT_To).DateToLatestTime();

                //int TOTAL= 0;
                INVENTORY_STATUSs.AddRange(new List <string>()
                {
                    ((int)AccessInventoryType._5).ToString(), //預約取出,計庫存
                    ((int)AccessInventoryType._6).ToString(), //已被取出,計庫存
                    ((int)AccessInventoryType._9).ToString()
                });                                           //預約存入,計庫存
                var _II = db.ITEM_IMPO.AsNoTracking()         //判斷是否在庫
                          .Where(x => INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS), _APLY_DT_Date == dtn)
                          .Where(x =>
                                 (INVENTORY_STATUSs.Contains(x.INVENTORY_STATUS) && x.PUT_DATE <= _APLY_DT) // 在庫 且 存入日期 <= 庫存日期
                                 ||
                                 (x.INVENTORY_STATUS == INVENTORY_STATUSg &&
                                  x.PUT_DATE <= _APLY_DT &&
                                  _APLY_DT < x.GET_DATE), //存入日期 <= 庫存日期 且 庫存日期 < 取出日期
                                 _APLY_DT_Date != dtn)
                          .Where(x => x.CHARGE_DEPT == vdept, vdept != "All")
                          .Where(x => x.CHARGE_SECT == vsect, vsect != "All")
                          .Where(x => x.PUT_DATE >= _APLY_ODT_From, _APLY_ODT_From != null)
                          .Where(x => x.PUT_DATE <= _APLY_ODT_To, _APLY_ODT_To != null)
                          .ToList();

                var depts = new List <VW_OA_DEPT>();
                var types = new List <SYS_CODE>();
                using (DB_INTRAEntities dbINTRA = new DB_INTRAEntities())
                {
                    depts = dbINTRA.VW_OA_DEPT.AsNoTracking().Where(x => x.DPT_CD != null).ToList();
                }

                types = db.SYS_CODE.AsNoTracking().Where(x => x.CODE != null).ToList();

                if (_APLY_DT_Date != dtn)
                {
                    List <string> Item_IDs = _II.Select(x => x.ITEM_ID_FROM == null ? x.ITEM_ID : x.ITEM_ID_FROM).Distinct().ToList();

                    List <ITEM_IMPO> ITEM_IMPOs = db.ITEM_IMPO.AsNoTracking().Where(x => Item_IDs.Contains(x.ITEM_ID)).ToList();

                    List <ITEM_IMPO> GetITEM_IMPOs = db.ITEM_IMPO.AsNoTracking()
                                                     .Where(x => x.ITEM_ID_FROM != null && Item_IDs.Contains(x.ITEM_ID_FROM) && _APLY_DT > x.GET_DATE).ToList();
                    //取出日 < 庫存日,之前取出

                    foreach (var item in ITEM_IMPOs)
                    {
                        var _CHARGE_DEPT = getEmpName(depts, item.CHARGE_DEPT);
                        var _CHARGE_SECT = getEmpName(depts, item.CHARGE_SECT)?.Replace(_CHARGE_DEPT, "")?.Trim();
                        ReportData = new DepositReportITEMIMPData()
                        {
                            ITEM_ID              = item.ITEM_ID,
                            PUT_DATE             = item.PUT_DATE.dateTimeToStr(),
                            CHARGE_DEPT          = _CHARGE_DEPT,
                            CHARGE_SECT          = _CHARGE_SECT,
                            ITEM_NAME            = item.ITEM_NAME,
                            QUANTITY             = GetQUANTITY(item, GetITEM_IMPOs),
                            AMOUNT               = item.AMOUNT,
                            EXPECTED_ACCESS_DATE = item.EXPECTED_ACCESS_DATE.dateTimeToStr(),
                            DESCRIPTION          = item.DESCRIPTION,
                            MEMO           = item.MEMO,
                            CHARGE_DEPT_ID = item.CHARGE_DEPT,
                            CHARGE_SECT_ID = item.CHARGE_SECT
                        };
                        ReportDataList.Add(ReportData);
                    }
                }
                else
                {
                    foreach (var item in _II)
                    {
                        var _CHARGE_DEPT = getEmpName(depts, item.CHARGE_DEPT);
                        var _CHARGE_SECT = getEmpName(depts, item.CHARGE_SECT)?.Replace(_CHARGE_DEPT, "")?.Trim();
                        ReportData = new DepositReportITEMIMPData()
                        {
                            ITEM_ID              = item.ITEM_ID,
                            PUT_DATE             = item.PUT_DATE.dateTimeToStr(),
                            CHARGE_DEPT          = _CHARGE_DEPT,
                            CHARGE_SECT          = _CHARGE_SECT,
                            ITEM_NAME            = item.ITEM_NAME,
                            QUANTITY             = item.REMAINING,
                            AMOUNT               = item.AMOUNT,
                            EXPECTED_ACCESS_DATE = item.EXPECTED_ACCESS_DATE.dateTimeToStr(),
                            DESCRIPTION          = item.DESCRIPTION,
                            MEMO           = item.MEMO,
                            CHARGE_DEPT_ID = item.CHARGE_DEPT,
                            CHARGE_SECT_ID = item.CHARGE_SECT
                        };
                        ReportDataList.Add(ReportData);
                    }
                }
            }
            resultsTable.Tables.Add(ReportDataList
                                    .OrderBy(x => x.ITEM_ID)
                                    .ThenBy(x => x.PUT_DATE)
                                    .ThenBy(x => x.CHARGE_DEPT_ID)
                                    .ThenBy(x => x.CHARGE_SECT_ID)
                                    .ToList().ToDataTable());
            return(resultsTable);
        }