示例#1
0
        public List <LimitCheckModel> GetCountryReport(SessionInfo sessioninfo, string strReportDate, string strCountry, string strSource, string strStatus)
        {
            try
            {
                DateTime             dteReport;
                LimitCheckBusiness   _limitBusiness        = new LimitCheckBusiness();
                DealBusiness         _dealBusiness         = new DealBusiness();
                CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
                CountryBusiness      _countryBusiness      = new CountryBusiness();
                Guid             guCountryID = Guid.Empty;
                MA_COUNTRY_LIMIT temp_limit  = null;

                if (String.IsNullOrEmpty(strReportDate))
                {
                    throw this.CreateException(new Exception(), "Please input report date.");
                }
                else if (!DateTime.TryParseExact(strReportDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteReport))
                {
                    throw this.CreateException(new Exception(), "Invalid report date.");
                }
                else
                {
                    dteReport = DateTime.ParseExact(strReportDate, "dd/MM/yyyy", null);
                }

                if (_dealBusiness.CountByProcessDate(dteReport) == 0)
                {
                    throw this.CreateException(new Exception(), "No data for selected report date.");
                }

                if (Guid.TryParse(strCountry, out guCountryID))
                {
                    guCountryID = Guid.Parse(strCountry);
                }

                List <LimitCheckModel> sets = _limitBusiness.GetCountrySETByCriteria(dteReport, guCountryID, strSource, Guid.Empty, Guid.Empty);
                List <LimitCheckModel> pces = _limitBusiness.GetCountryPCEByCriteria(dteReport, guCountryID, strSource, Guid.Empty, Guid.Empty);

                var reports = (from report in sets.Union(pces)
                               join pce in pces on report.COUNTRY_ID equals pce.COUNTRY_ID
                               select new LimitCheckModel
                {
                    COUNTRY_LABEL = report.COUNTRY_LABEL,
                    COUNTRY_ID = report.COUNTRY_ID,
                    FLAG_CONTROL = report.FLAG_CONTROL,
                    GEN_AMOUNT = report.AMOUNT,
                    PROCESSING_DATE = report.PROCESSING_DATE,
                    EXPIRE_DATE = report.EXPIRE_DATE,
                    FLOW_DATE = report.FLOW_DATE,
                    SET_CONTRIBUTE = report.SET_CONTRIBUTE,
                    PCE_CONTRIBUTE = pce.PCE_CONTRIBUTE
                }).GroupBy(g => new
                {
                    g.COUNTRY_ID,
                    g.COUNTRY_LABEL,
                    g.FLAG_CONTROL,
                    g.GEN_AMOUNT,
                    g.PROCESSING_DATE,
                    g.EXPIRE_DATE,
                    g.FLOW_DATE,
                    g.PCE_CONTRIBUTE
                }).Select(s => new LimitCheckModel
                {
                    COUNTRY_LABEL          = s.Key.COUNTRY_LABEL,
                    COUNTRY_ID             = s.Key.COUNTRY_ID,
                    FLAG_CONTROL           = s.Key.FLAG_CONTROL,
                    GEN_AMOUNT             = s.Key.GEN_AMOUNT,
                    PROCESSING_DATE        = s.Key.PROCESSING_DATE,
                    EXPIRE_DATE            = s.Key.EXPIRE_DATE,
                    FLOW_DATE              = s.Key.FLOW_DATE,
                    PCE_CONTRIBUTE         = s.Key.PCE_CONTRIBUTE,
                    SET_CONTRIBUTE         = s.Sum(x => x.SET_CONTRIBUTE),
                    ORIGINAL_KK_CONTRIBUTE = s.Key.PCE_CONTRIBUTE + s.Sum(y => y.SET_CONTRIBUTE)
                }).ToList();

                foreach (var report in reports)
                {
                    temp_limit = _countryBusiness.GetActiveTempByCountryID(sessioninfo.Process.CurrentDate, report.FLOW_DATE, report.COUNTRY_ID);

                    if (temp_limit != null)
                    {
                        report.TEMP_AMOUNT = temp_limit.AMOUNT;
                    }
                }

                if (strStatus != "")
                {
                    reports = reports.Where(t => t.STATUS.IndexOf(strStatus, StringComparison.OrdinalIgnoreCase) >= 0).ToList();
                }

                return(reports.OrderBy(p => p.COUNTRY_LABEL).ThenBy(t => t.FLOW_DATE).ToList());
            }

            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }