public List<DA_TRN> GetPCEDetailReport(SessionInfo sessioninfo, string strReportDate, string strCtpy, string strProduct, string strSource) { try { DateTime dteReport; DealBusiness _dealBusiness = new DealBusiness(); Guid guTemp; 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."); } var trns = _dealBusiness.GetDealByProcessDate(dteReport).Where(p => p.MA_STATUS.LABEL.ToString() != StatusCode.CANCELLED.ToString()).AsQueryable(); if (!string.IsNullOrEmpty(strSource)) { trns = trns.Where(p => p.SOURCE == strSource); } if (Guid.TryParse(strCtpy, out guTemp)) { trns = trns.Where(t => t.CTPY_ID == Guid.Parse(strCtpy)); } if (Guid.TryParse(strProduct, out guTemp)) { trns = trns.Where(s => s.PRODUCT_ID == Guid.Parse(strProduct)); } return trns.ToList(); } catch (DataServicesException ex) { throw this.CreateException(ex, null); } }
public List<DA_TRN> GetLimitOverwriteReport(SessionInfo sessionInfo, string strReportDate, string strCtpy) { try { DateTime dteReport; Guid guCtpyID = Guid.Empty; DealBusiness _dealBusiness = new DealBusiness(); if (String.IsNullOrEmpty(strReportDate)) throw this.CreateException(new Exception(), "Please input date."); else if (!DateTime.TryParseExact(strReportDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteReport)) throw this.CreateException(new Exception(), "Invalid date."); else dteReport = DateTime.ParseExact(strReportDate, "dd/MM/yyyy", null); var trns = _dealBusiness.GetDealByProcessDate(dteReport).AsQueryable(); trns = trns.Where(t => t.OVER_APPROVER != null && t.SOURCE == "INT" && t.MA_STATUS.LABEL != StatusCode.CANCELLED.ToString()); if (Guid.TryParse(strCtpy, out guCtpyID)) { trns = trns.Where(a => a.CTPY_ID == guCtpyID); } return trns.ToList(); } catch (DataServicesException ex) { throw this.CreateException(ex, null); } }
/// <summary> /// Cancel deal by ID /// </summary> /// <param name="sessioninfo"></param> /// <param name="DMKDealID"></param> /// <returns></returns> public static object CancellingDeal(SessionInfo sessioninfo, Guid DMKDealID) { ReconcileBusiness _reconcileBusiness = new ReconcileBusiness(); DealBusiness _dealBusiness = new DealBusiness(); List<DealTranModel> DealTrans = new List<DealTranModel>(); DA_TRN deal = null; DA_TRN deal2 = null; List<DA_TRN> dealExts = null; string extdealno = string.Empty; try { LoggingHelper.Debug("Cancelling deal"); //find deal before deal = _dealBusiness.GetByID(DMKDealID); if (deal == null) return new { Result = "ERROR", Message = String.Format("Deal {0} is not found.", deal.INT_DEAL_NO) }; if (deal.MA_PRODUCT.LABEL.Replace(" ", string.Empty) == ProductCode.FXSWAP.ToString()) deal2 = _dealBusiness.GetDealByProcessDate(sessioninfo.Process.CurrentDate).FirstOrDefault(p => p.INT_DEAL_NO == deal.INT_DEAL_NO && p.VERSION == deal.VERSION && p.ID != deal.ID); if (deal.MA_PRODUCT.LABEL.Replace(" ", string.Empty) == ProductCode.FXSWAP.ToString() && deal2 == null) return new { Result = "ERROR", Message = String.Format("Deal {0} is not found.", deal.INT_DEAL_NO) }; dealExts = _dealBusiness.GetByExternalByInternalDealNo(sessioninfo.Process.NextDate, deal.INT_DEAL_NO); if (dealExts == null) return new { Result = "ERROR", Message = String.Format("OPICS Deal is not found.") }; // extdealno = deal.EXT_DEAL_NO; deal.EXT_DEAL_NO = null; deal.EXT_PORTFOLIO = null; deal.STATUS_ID = _lookupvaluesRepository.StatusRepository.GetByLabel(StatusCode.OPEN.ToString()).ID; deal.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId; deal.LOG.MODIFYDATE = DateTime.Now; deal.INSERT_BY_EXT = null; DealTrans.Add(new DealTranModel() { ProductTransaction = (ProductCode)Enum.Parse(typeof(ProductCode), deal.MA_PRODUCT.LABEL.Replace(" ","")), Transaction = deal, UpdateStates = UpdateStates.Editing }); if (deal2 != null) { deal2.EXT_DEAL_NO = null; deal2.EXT_PORTFOLIO = null; deal2.STATUS_ID = _lookupvaluesRepository.StatusRepository.GetByLabel(StatusCode.OPEN.ToString()).ID; deal2.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId; deal2.LOG.MODIFYDATE = DateTime.Now; deal2.INSERT_BY_EXT = null; DealTrans.Add(new DealTranModel() { ProductTransaction = (ProductCode)Enum.Parse(typeof(ProductCode), deal2.MA_PRODUCT.LABEL.Replace(" ", "")), Transaction = deal2, UpdateStates = UpdateStates.Editing }); } foreach (DA_TRN dealExt in dealExts) { DealTrans.Add(new DealTranModel() { ProductTransaction = (ProductCode)Enum.Parse(typeof(ProductCode), dealExt.MA_PRODUCT.LABEL.Replace(" ", "")), Transaction = dealExt, UpdateStates = UpdateStates.Deleting }); } _reconcileBusiness.UpdateDealReconcile(sessioninfo, DealTrans); LoggingHelper.Debug("End Cancelling deal"); return new { Result = "OK", Message = String.Format("Process cancel the deal between DMK Deal no {0} and OPICS Deal no {1} completed", deal.INT_DEAL_NO, extdealno) }; } catch (Exception ex) { return new { Result = "ERROR", Message = ex.Message }; } }
/// <summary> /// Auto Match And Update Deals /// </summary> /// <param name="sessioninfo"></param> /// <param name="processdate"></param> /// <param name="opicdeals"></param> /// <param name="deals"></param> private static void AutoMatchAndUpdateDeals(SessionInfo sessioninfo, DateTime processdate, List<DEALModel> opicdeals, out List<DA_TRN> deals) { DealBusiness _dealBusiness = new DealBusiness(); List<DA_TRN> UpdateDeals = new List<DA_TRN>(); List<DA_TRN> MatchDeals = new List<DA_TRN>(); List<DEALModel> _opicdeals = null; LoggingHelper.Debug("AutoMatchAndUpdateDeals on " + processdate.ToString()); deals = _dealBusiness.GetDealByProcessDate(processdate, StatusCode.OPEN); if (deals != null) { if (opicdeals != null) { //for loop for deal on process date foreach (DA_TRN deal in deals) { //Condition for Match deal between DMK and OPICS, INSERT_DATE = Processing Date switch ((ProductCode)Enum.Parse(typeof(ProductCode), deal.MA_PRODUCT.LABEL.Replace(" ", string.Empty))) { case ProductCode.FXSWAP: _opicdeals = opicdeals.Where<DEALModel>(p => p.INT_DEAL_NO == deal.INT_DEAL_NO && p.INSERT_DATE.Date == processdate.Date && p.FLAG_NEARFAR == deal.FLAG_NEARFAR).ToList(); break; default: _opicdeals = opicdeals.Where<DEALModel>(p => p.INT_DEAL_NO == deal.INT_DEAL_NO && p.INSERT_DATE.Date == processdate.Date).ToList(); break; } //Build transaction each deal if (_opicdeals != null && _opicdeals.Count > 0) { bool match = CheckAddonCondition(deal, _opicdeals); if (match) { BuildTransation(sessioninfo, _opicdeals, deal, ref UpdateDeals); MatchDeals.Add(deal); } } else { //Not match, will be import auto for this processing date } } foreach (DA_TRN matchdeal in MatchDeals) deals.Remove(matchdeal); } } bool done = false; //include some statements done = true; }
public static object GetDealByProcessDateStatusCode(SessionInfo sessioninfo, DateTime processdate, StatusCode statuscode, int startIndex, int count, string sorting) { DealBusiness _dealBusiness = new DealBusiness(); OpicsBusiness _opicsBusiness = new OpicsBusiness(); LookupBusiness _lookupBusiness = new LookupBusiness(); List<DA_TRN> deals = null; List<DA_TRN> dealExts = null; List<DEALModel> opicdeals = null; try { //Get data from database if (statuscode == StatusCode.MATCHED) { LoggingHelper.Debug("Get DMK Deal is matched on " + processdate.ToString()); deals = _dealBusiness.GetDealByProcessDate(processdate, StatusCode.MATCHED); dealExts = _dealBusiness.GetImportedDealsByProcessDate(sessioninfo.Process.NextDate); } else { LoggingHelper.Debug("Get DMK Deal is not matched on " + processdate.ToString()); //Get data from database opicdeals = _opicsBusiness.GetOPICSDealExternal(processdate); //auto match with OPICS deal AutoMatchAndUpdateDeals(sessioninfo, processdate, opicdeals, out deals); } if (dealExts == null) dealExts = new List<DA_TRN>(); List<MA_FREQ_TYPE> freq = _lookupBusiness.GetFreqTypeAll(); List<MA_CURRENCY> ccys = _lookupBusiness.GetCurrencyAll(); //Sorting string[] sortsp = sorting.Split(' '); List<DealViewModel> dealviews = (from t in deals join p in dealExts on new { t.INT_DEAL_NO, t.FLAG_NEARFAR } equals new { p.INT_DEAL_NO, p.FLAG_NEARFAR } into ps join f1 in freq on t.FIRST.FREQTYPE_ID equals f1.ID into fg1 from subfg1 in fg1.DefaultIfEmpty() join f2 in freq on t.SECOND.FREQTYPE_ID equals f2.ID into fg2 from subfg2 in fg2.DefaultIfEmpty() join tempccy1 in ccys on t.FIRST.CCY_ID equals tempccy1.ID into ljccy1 from ccy1 in ljccy1.DefaultIfEmpty() join tempccy2 in ccys on t.SECOND.CCY_ID equals tempccy2.ID into ljccy2 from ccy2 in ljccy2.DefaultIfEmpty() where t.MA_STATUS.LABEL.Contains(statuscode.ToString()) && t.MATURITY_DATE.HasValue ? t.MATURITY_DATE.Value > sessioninfo.Process.CurrentDate : true select new DealViewModel { ID = t.ID, EntryDate = t.LOG.INSERTDATE, DMK_NO = t.INT_DEAL_NO, OPICS_NO = ps == null ? t.EXT_DEAL_NO : string.Join(",", ps.Select(i => i.EXT_DEAL_NO)), TradeDate = t.TRADE_DATE.Value, EffectiveDate = t.START_DATE, Instrument = t.MA_INSRUMENT.LABEL, MaturityDate = t.MATURITY_DATE.HasValue ? t.MATURITY_DATE : null, BuySell = t.FLAG_BUYSELL, Product = t.MA_PRODUCT.LABEL, Portfolio = t.MA_PORTFOLIO.LABEL, Counterparty = t.MA_COUTERPARTY.SNAME, Notional1 = t.FIRST.NOTIONAL, PayRec1 = t.FIRST.FLAG_PAYREC, FixedFloat1 = !t.FIRST.FLAG_FIXED.HasValue ? null : t.FIRST.FLAG_FIXED == true ? "FIXED" : "FLOAT", Fixing1 = t.FIRST.FIRSTFIXINGAMT, Rate1 = t.FIRST.RATE, SwapPoint1 = t.FIRST.SWAP_POINT, Notional2 = t.SECOND.NOTIONAL, PayRec2 = t.SECOND.FLAG_PAYREC, FixedFloat2 = !t.SECOND.FLAG_FIXED.HasValue ? null : t.SECOND.FLAG_FIXED == true ? "FIXED" : "FLOAT", Fixing2 = t.SECOND.FIRSTFIXINGAMT, Rate2 = t.SECOND.RATE, SwapPoint2 = t.SECOND.SWAP_POINT, Status = t.MA_STATUS.LABEL, KKContribute = t.KK_CONTRIBUTE, BotContribute = t.BOT_CONTRIBUTE, Remark = t.REMARK, Freq1 = subfg1 != null ? subfg1.USERCODE : null, Freq2 = subfg2 != null ? subfg2.USERCODE : null, CCY1 = ccy1 != null ? ccy1.LABEL : null, CCY2 = ccy2 != null ? ccy2.LABEL : null }).AsQueryable().OrderBy(sortsp[0], sortsp[1]).ToList(); //Return result to jTable return new { Result = "OK", Records = dealviews.Count > 0 ? dealviews.Skip(startIndex).Take(count).ToList() : dealviews, TotalRecordCount = dealviews.Count }; } catch (Exception ex) { return new { Result = "ERROR", Message = ex.Message }; } }