Esempio n. 1
0
        public void UpdateDealReconcile(SessionInfo sessioninfo, List<DealTranModel> trns)
        {
            DealBusiness _dealBusiness = new DealBusiness();
            LoggingHelper.Debug("Begin UpdateDealReconcile....");
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                foreach (DealTranModel tran in trns)
                {
                    switch (tran.UpdateStates)
                    {
                        case UpdateStates.Adding:
                            unitOfWork.DA_TRNRepository.Add(tran.Transaction);
                            LoggingHelper.Debug(String.Format("Insert DA_TRN {0} [{1}] is completed", tran.Transaction.INT_DEAL_NO, tran.Transaction.ID.ToString()));
                            break;
                        case  UpdateStates.Editing:
                            var update = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == tran.Transaction.ID);
                            if (update == null)
                                throw this.CreateException(new Exception(), "Data not found!");
                            else
                            {
                                update.EXT_DEAL_NO = tran.Transaction.EXT_DEAL_NO;
                                update.EXT_PORTFOLIO = tran.Transaction.EXT_PORTFOLIO;
                                update.MATURITY_DATE = tran.Transaction.MATURITY_DATE;
                                update.STATUS_ID = tran.Transaction.STATUS_ID;
                                update.LOG.MODIFYBYUSERID = tran.Transaction.LOG.MODIFYBYUSERID;
                                update.LOG.MODIFYDATE = tran.Transaction.LOG.MODIFYDATE;
                                update.INSERT_BY_EXT = tran.Transaction.INSERT_BY_EXT;

                            }
                            LoggingHelper.Debug(String.Format("Update DA_TRN {0} [{1}] is completed", update.INT_DEAL_NO, update.ID.ToString()));
                            break;
                        case UpdateStates.Deleting:
                            var delete = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == tran.Transaction.ID);
                            if (delete == null)
                                throw this.CreateException(new Exception(), "Data not found!");
                            else
                                unitOfWork.DA_TRNRepository.Delete(delete);

                            LoggingHelper.Debug(String.Format("Delete DA_TRN {0} [{1}] is completed", delete.INT_DEAL_NO, delete.ID.ToString()));
                            break;
                    }
                }

                unitOfWork.Commit();

                LoggingHelper.Debug("Commit UpdateDealReconcile....");
            }
        }
Esempio n. 2
0
        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 };
            }
        }
Esempio n. 3
0
        public static List<DealViewModel> GetDealInquiryData(SessionInfo sessioninfo
                                                            , string strDMKNo
                                                            , string strOPICNo
                                                            , string strProduct
                                                            , string strCtpy
                                                            , string strPortfolio
                                                            , string strTradeDate
                                                            , string strEffDate
                                                            , string strMatDate
                                                            , string strInstrument
                                                            , string strUser
                                                            , string strStatus
                                                            , string strOverStatus
                                                            , string strProcDate
                                                            , string strSettleStatus)
        {
            DealBusiness _dealBusiness = new DealBusiness();
            UserBusiness _userBusiness = new UserBusiness();
            LookupBusiness _lookupBusiness = new LookupBusiness();

            //Get data from database
            List<DA_TRN> trns = _dealBusiness.GetDealInquiryByFilter(sessioninfo
                                                                        , strDMKNo
                                                                        , strOPICNo
                                                                        , strProduct
                                                                        , strCtpy
                                                                        , strPortfolio
                                                                        , strTradeDate
                                                                        , strEffDate
                                                                        , strMatDate
                                                                        , strInstrument
                                                                        , strUser
                                                                        , strStatus
                                                                        , strProcDate);
            //Get user data
            List<MA_USER> users = _userBusiness.GetAll();
            List<MA_CURRENCY> ccys = _lookupBusiness.GetCurrencyAll();
            List<MA_FREQ_TYPE> freq = _lookupBusiness.GetFreqTypeAll();

            return (from t in trns
                         join user in users on t.LOG.INSERTBYUSERID equals user.ID into ljuser
                         from inputuser in ljuser.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()
                         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()
                         select new DealViewModel
                         {
                             ID = t.ID,
                             EntryDate = t.LOG.INSERTDATE,
                             DMK_NO = t.INT_DEAL_NO,
                             OPICS_NO = t.EXT_DEAL_NO,
                             TradeDate = t.TRADE_DATE.Value,
                             EffectiveDate = t.START_DATE,
                             Instrument = t.MA_INSRUMENT.LABEL,
                             MaturityDate = t.MATURITY_DATE,
                             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.Value ? "FIXED" : "FLOAT",
                             Rate1 = t.FIRST.RATE,
                             Fixing1 = t.FIRST.FIRSTFIXINGAMT,
                             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",
                             Rate2 = t.SECOND.RATE,
                             Fixing2 = t.SECOND.FIRSTFIXINGAMT,
                             SwapPoint2 = t.SECOND.SWAP_POINT,
                             Status = t.MA_STATUS.LABEL,
                             KKContribute = t.KK_CONTRIBUTE,
                             BotContribute = t.BOT_CONTRIBUTE                             ,
                             LimitOverwrite = string.IsNullOrEmpty(t.OVER_APPROVER) ? "No" : t.OVER_AMOUNT > 0 && t.OVER_SETTL_AMOUNT > 0 ? "Yes" : t.OVER_AMOUNT > 0 ? "PCE" : "SET",
                             LimitApprover = t.OVER_APPROVER,
                             Trader = inputuser != null ? inputuser.USERCODE : null,
                             Remark = t.REMARK,
                             CCY1 = ccy1 != null ? ccy1.LABEL : null,
                             CCY2 = ccy2 != null ? ccy2.LABEL : null,
                             SettlementLimit = !t.FLAG_SETTLE.HasValue || !t.FLAG_SETTLE.Value ? "No" : "Yes",
                             Freq1 = subfg1 != null ? subfg1.USERCODE : null,
                             Freq2 = subfg2 != null ? subfg2.USERCODE : null,
                             OpicsTrader = t.INSERT_BY_EXT,
                             TBMA_SENT = t.DA_TMBA_EXTENSION == null ? "N/A" : t.DA_TMBA_EXTENSION.SEND_DATE != null ? "Yes" : "No"
                         }).Where(p => p.LimitOverwrite == strOverStatus || String.IsNullOrEmpty(strOverStatus))
                         .Where(t => t.SettlementLimit == strSettleStatus || string.IsNullOrEmpty(strSettleStatus)).ToList();
        }
Esempio n. 4
0
        public List<LimitCheckModel> GetSCEReport(SessionInfo sessioninfo, string strReportDate, string strCtpy, string strSource, string strStatus)
        {
            try
            {
                DateTime dteReport;
                LimitCheckBusiness _limitBusiness = new LimitCheckBusiness();
                DealBusiness _dealBusiness = new DealBusiness();
                CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
                Guid guCtpyID = Guid.Empty;

                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(strCtpy, out guCtpyID))
                {
                    guCtpyID = Guid.Parse(strCtpy);
                }

                var limits = _limitBusiness.GetSCEByCriteria(dteReport, guCtpyID, Guid.Empty, strSource, Guid.Empty, Guid.Empty)
                                            .OrderBy(p => p.SNAME).ThenBy(p => p.FLOW_DATE)
                                            .Distinct(new LimitCheckComparer()).AsQueryable();

                //Get temp limit
                //Look for temp limit when all conditions meet
                // 1. Transaction maturity date <= Temp limit maturity date
                foreach (LimitCheckModel limit in limits)
                {
                    MA_TEMP_CTPY_LIMIT temp_limit = _counterpartyBusiness.GetActiveTempByID(sessioninfo.Process.CurrentDate, limit.FLOW_DATE, limit.CTPY_LIMIT_ID);

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

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

                return limits.ToList();
            }

            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
Esempio n. 5
0
        public List<RepoReportModel> GetRepoReport(SessionInfo sessioninfo, string strReportDate, string strSource, string strCtpy)
        {
            try
            {
                DateTime dteReport;
                LimitCheckBusiness _limitBusiness = new LimitCheckBusiness();
                DealBusiness _dealBusiness = new DealBusiness();
                LimitProductBusiness _limitProductBusiness = new LimitProductBusiness();
                LookupBusiness _lookupBusiness = new LookupBusiness();
                StaticDataBusiness _staticBusiness = new StaticDataBusiness();
                List<RepoReportModel> reports = new List<RepoReportModel>();
                RepoReportModel report;
                Guid guCtpyID = Guid.Empty;

                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 (Guid.TryParse(strCtpy, out guCtpyID))
                {
                    guCtpyID = Guid.Parse(strCtpy);
                }

                Guid guProductID = _lookupBusiness.GetProductByUsercode(ProductCode.REPO.ToString()).ID;
                MA_PCCF rev_pccf = _staticBusiness.GetPCCFByID(sessioninfo, Guid.Parse("84f608c9-8b58-48eb-a6dd-a5407548784a"));
                MA_PCCF rep_gov_pccf = _staticBusiness.GetPCCFByID(sessioninfo, Guid.Parse("28b24b19-e81d-4f82-a2f0-7c834ee3f91c"));
                MA_PCCF rep_soe_pccf = _staticBusiness.GetPCCFByID(sessioninfo, Guid.Parse("7014b05e-198f-4f62-94b0-1d54322efbca"));

                var limits = _limitBusiness.GetPCEByCriteria(dteReport, guCtpyID, guProductID, strSource, Guid.Empty, Guid.Empty).Distinct(new LimitCheckComparer()).ToList();

                foreach (LimitCheckModel limit in limits)
                {
                    report = new RepoReportModel();

                    report.PROCESSING_DATE = limit.PROCESSING_DATE;
                    report.SNAME = limit.SNAME;
                    report.LIMIT_LABEL = limit.LIMIT_LABEL;
                    report.GEN_AMOUNT = limit.GEN_AMOUNT;
                    report.TEMP_AMOUNT = limit.TEMP_AMOUNT;
                    //report.AMOUNT = limit.AMOUNT;
                    report.EXPIRE_DATE = limit.EXPIRE_DATE;
                    report.ORIGINAL_KK_CONTRIBUTE = limit.ORIGINAL_KK_CONTRIBUTE;
                    report.DEAL_CONTRIBUTION = 0;
                    report.REV_AMOUNT = report.AVAILABLE / rev_pccf.C1.Value * 100;
                    report.REP_GOV_5_AMOUNT = report.AVAILABLE / rep_gov_pccf.C5.Value * 100;
                    report.REP_GOV_10_AMOUNT = report.AVAILABLE / rep_gov_pccf.C10.Value * 100;
                    report.REP_GOV_20_AMOUNT = report.AVAILABLE / rep_gov_pccf.C20.Value * 100;
                    report.REP_GOV_20s_AMOUNT = report.AVAILABLE / rep_gov_pccf.more20.Value * 100;
                    report.REP_SOE_5_AMOUNT = report.AVAILABLE / rep_soe_pccf.C5.Value * 100;
                    report.REP_SOE_10_AMOUNT = report.AVAILABLE / rep_soe_pccf.C10.Value * 100;
                    report.REP_SOE_20_AMOUNT = report.AVAILABLE / rep_soe_pccf.C20.Value * 100;
                    report.REP_SOE_20s_AMOUNT = report.AVAILABLE / rep_soe_pccf.more20.Value * 100;

                    reports.Add(report);
                }

                return reports;
            }

            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
Esempio n. 6
0
        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);
            }
        }
Esempio n. 7
0
        public static DA_TRN GenerateFITransactionObject(SessionInfo sessionInfo
                                                            , string strTradeDate
                                                            , string strBuySell
                                                            , string strInstrument
                                                            , string strCtpy
                                                            , string strPortfolio
                                                            , string strSettlementDate
                                                            , string strYield
                                                            , string strUnit
                                                            , string strCleanPrice
                                                            , string strGrossPrice
                                                            , string strNotional
                                                            , string strCCY
                                                            , string strPceFlag
                                                            , string strSettleFlag
                                                            , string strYeildType
                                                            , string strReportBy
                                                            , string strPurpose
                                                            , string strTerm
                                                            , string strRate
                                                            , string strTBMARemark
                                                            , string strRemark
                                                            , string strProductId)
        {
            DealBusiness _dealBusiness = new DealBusiness();

                return _dealBusiness.GenerateFITransactionObject(sessionInfo
                                                                , strTradeDate
                                                                , strBuySell
                                                                , strInstrument
                                                                , strCtpy
                                                                , strPortfolio
                                                                , strSettlementDate
                                                                , strYield
                                                                , strUnit
                                                                , strCleanPrice
                                                                , strGrossPrice
                                                                , strNotional
                                                                , strCCY
                                                                , strPceFlag
                                                                , strSettleFlag
                                                                , strYeildType
                                                                , strReportBy
                                                                , strPurpose
                                                                , strTerm
                                                                , strRate
                                                                , strTBMARemark
                                                                , strRemark
                                                                , strProductId);
        }
Esempio n. 8
0
        public static object SubmitSwapDeal(SessionInfo sessioninfo
                                                , DA_TRN trn
                                                , string strOverApprover
                                                , string strOverComment
                                                , string strProductId)
        {
            try
                {
                    DealBusiness _dealBusiness = new DealBusiness();

                    string strDealNO = _dealBusiness.SubmitSwapDeal(sessioninfo
                                                                    , trn
                                                                    , strOverApprover
                                                                    , strOverComment
                                                                    , strProductId);

                    return new { Result = "OK", Message = strDealNO };
                }
                catch (Exception ex)
                {
                    return new { Result = "ERROR", Message = ex.Message };
                }
        }
Esempio n. 9
0
 public static DA_TRN GenerateFXSpotTransactionObject(SessionInfo sessionInfo, string strTradeDate, string strSpotDate, string strCtpy, string strPortfolio
                                                         , string strCurrencyPair, string strBS, string strContractCcy, string strCounterCcy
                                                         , string strSpotRate, string strContractAmt, string strCounterAmt, string strRemark, bool settleFlag, string strProductId)
 {
     DealBusiness _dealBusiness = new DealBusiness();
     return _dealBusiness.GenerateFXSpotTransactionObject(sessionInfo, strTradeDate, strSpotDate, strCtpy, strPortfolio
                                                         , strCurrencyPair, strBS, strContractCcy, strCounterCcy
                                                         , strSpotRate, strContractAmt, strCounterAmt, strRemark, settleFlag, strProductId);
 }
Esempio n. 10
0
        /// <summary>
        /// Build Transation for Matching Deal between DMK Deal No. and OPICS Deal No.
        /// </summary>
        /// <param name="sessioninfo"></param>
        /// <param name="opicdeals"></param>
        /// <param name="deal"></param>
        /// <param name="UpdateDeals"></param>
        private static void BuildTransation(SessionInfo sessioninfo, List<DEALModel> opicdeals, 
            DA_TRN deal, ref List<DA_TRN> UpdateDeals)
        {
            ReconcileBusiness _reconcileBusiness = new ReconcileBusiness();
            StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
            DealBusiness _dealBusiness = new DealBusiness();
            CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
            InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
            List<DealTranModel> DealTrans = new List<DealTranModel>();

            DA_TRN newDeal = null;
            LoggingHelper.Debug("BuildTransation OPICS data and DMK deal");

            if (opicdeals != null)
            {
                bool flag = true;
                foreach (DEALModel opicdeal in opicdeals)
                {
                    flag = ValidateOPICS(opicdeal);
                    if( !flag ) break;
                }
                if (flag)
                {
                    //Begin transaction - Update DMK Deal No
                    deal.EXT_DEAL_NO = opicdeals[0].EXT_DEAL_NO;
                    deal.EXT_PORTFOLIO = opicdeals[0].EXT_PORTFOLIO;
                    deal.STATUS_ID = _lookupvaluesRepository.StatusRepository.GetByLabel(StatusCode.MATCHED.ToString()).ID;
                    deal.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId;
                    deal.LOG.MODIFYDATE = DateTime.Now;
                    deal.INSERT_BY_EXT = opicdeals[0].INSERT_BY_EXT;

                    ProductCode eProduct = (ProductCode)Enum.Parse(typeof(ProductCode), opicdeals[0].PRODUCT.Replace(" ", string.Empty));

                    //Update dealmaker data
                    DealTrans.Add(new DealTranModel() { UpdateStates = UpdateStates.Editing, Transaction = deal, ProductTransaction = eProduct });

                    //Create DMK Deal from OPICS Deal
                    foreach (DEALModel opicdeal in opicdeals)
                    {
                        newDeal = GenerateTrnObject(sessioninfo, opicdeal, deal, sessioninfo.Process.NextDate);

                        //Import Opics transaction
                        DealTrans.Add(new DealTranModel() { UpdateStates = UpdateStates.Adding, Transaction = newDeal, ProductTransaction = eProduct });
                    }
                    //Update transaction
                    _reconcileBusiness.UpdateDealReconcile(sessioninfo, DealTrans);
                }
            }
        }
Esempio n. 11
0
        /// <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;
        }
Esempio n. 12
0
        /// <summary>
        /// Match deal between DMK deal no and OPICS deal no on processing date
        /// </summary>
        /// <param name="sessioninfo"></param>
        /// <param name="processdate"></param>
        /// <param name="DMKDealID"></param>
        /// <param name="OPICSNo"></param>
        /// <returns></returns>
        public static object MatchingDeal(SessionInfo sessioninfo, DateTime processdate, Guid DMKDealID, string OPICSNo)
        {
            DealBusiness _dealBusiness = new DealBusiness();
            OpicsBusiness _opicsBusiness = new OpicsBusiness();
            DA_TRN deal = null;
            string[] OPICSNoArr = OPICSNo.Split(',');
            List<DA_TRN> UpdateDeals = new List<DA_TRN>();
            List<DEALModel> opicdeals = null;
            try
            {
                LoggingHelper.Debug("Match deal process on " + processdate.ToString());

                //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) };

                //Find Deal in OPICS deal
                opicdeals = _opicsBusiness.GetOPICSDealExternal(processdate).Where(p => OPICSNoArr.Contains(p.EXT_DEAL_NO)).ToList();
                foreach(string product in opicdeals.Select(o => o.PRODUCT).ToArray() )
                {
                    if (!deal.MA_PRODUCT.LABEL.Equals(product))
                    {
                        return new { Result = "ERROR", Message = "Product does not match." };
                    }
                }
                foreach (string cpty in opicdeals.Select(o => o.CPTY).ToArray())
                {
                if (!deal.MA_COUTERPARTY.USERCODE.ToString().Equals(cpty.Trim()))
                {
                    return new { Result = "ERROR", Message = "Counterparty does not match." };
                }
                }

                //Build transaction each deal
                BuildTransation(sessioninfo, opicdeals, deal, ref UpdateDeals);

                LoggingHelper.Debug("End Match deal process on " + processdate.ToString());
                return new
                {
                    Result = "OK",
                    Message = String.Format("Match deal completed, between {0} and {1}.", deal.INT_DEAL_NO, OPICSNo)
                };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Esempio n. 13
0
        /// <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 };
            }
        }
Esempio n. 14
0
        public static object ImportExternalByProcessDate(SessionInfo sessioninfo)
        {
            OpicsBusiness _opicsBusiness = new OpicsBusiness();
            DealBusiness _dealBusiness = new DealBusiness();
            ReconcileBusiness _reconcileBusiness = new ReconcileBusiness();
            List<DealTranModel> DealTrans = new List<DealTranModel>();
            var results = new List<object>();

            try
            {
                LoggingHelper.Debug("Get OPICS Deal on " + sessioninfo.Process.PreviousDate.ToString());

                //Get data from OPICS
                List<DEALModel> opicsdeals = _opicsBusiness.GetOPICSDealExternal(sessioninfo.Process.PreviousDate);
                List<CASHFLOWModel> opicscashflows = _opicsBusiness.GetOPICSCashflow(sessioninfo.Process.PreviousDate);

                List<DA_TRN> importeddeals = _dealBusiness.GetImportedDealsByProcessDate(sessioninfo.Process.CurrentDate);

                //Ignore imported deals
                var query = from o in opicsdeals
                            where !importeddeals.Any(d => d.EXT_DEAL_NO == o.EXT_DEAL_NO)
                            select o;

                LoggingHelper.Debug("Import Passed OPICS Deal");
                foreach (DEALModel opicdeal in query.ToList())
                {
                    if (ValidateOPICS(opicdeal))
                        ImportPassedOPICSDeal(sessioninfo, opicdeal, sessioninfo.Process.CurrentDate, ref DealTrans);
                }

                LoggingHelper.Debug("End Import Passed OPICS Deal as " + query.Count().ToString());

                if (DealTrans.Count > 0)
                {
                    //Insert to database
                    LoggingHelper.Debug("Insert OPICS deals on " + sessioninfo.Process.PreviousDate.ToString());

                    _reconcileBusiness.UpdateDealReconcile(sessioninfo, DealTrans);
                }

                results.Add(new { Object = "OPICS Deals", Total = DealTrans.Count});

                //Import Cashflows from OPICS
                List<DA_TRN_CASHFLOW> cashflows = null;

                if (opicscashflows != null && opicscashflows.Count > 0)
                {
                    List<DA_TRN> allimporteddeals = importeddeals.Union(from t in DealTrans select t.Transaction).ToList();
                    List<DA_TRN_CASHFLOW> importedcashflows = _dealBusiness.GetFlowsByProcessDate(sessioninfo.Process.CurrentDate);

                    cashflows = GenerateCashflowObject(sessioninfo, opicscashflows, importedcashflows, allimporteddeals);

                    if (cashflows.Count > 0)
                    {
                        _reconcileBusiness.ImportCashflows(sessioninfo, cashflows);
                    }
                }
                results.Add(new { Object = "OPICS Cashflows", Total = cashflows == null ? 0 : cashflows.Count });

                //Return result to jTable
                return new
                {
                    Result = "OK",
                    //Records = count > 0 ? sortedRecords.Skip(startIndex).Take(count).ToList() : sortedRecords,
                    Records = results,
                    TotalRecordCount = results.Count
                };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Esempio n. 15
0
        public static object GetDealExternalByProcessDate(SessionInfo sessioninfo, DateTime processdate, int startIndex, int count, string sorting)
        {
            OpicsBusiness _opicsBusiness = new OpicsBusiness();
            DealBusiness _dealBusiness = new DealBusiness();
            ReconcileBusiness _reconcileBusiness = new ReconcileBusiness();
            List<DealTranModel> DealTrans = new List<DealTranModel>();
            try
            {
                FlagReconcile(sessioninfo, true);
                LoggingHelper.Debug("Locked Reconcile table " + processdate.ToString());
                LoggingHelper.Debug("Get OPICS Deal on " + processdate.ToString());
                //Get data from database
                List<DEALModel> dealopics = _opicsBusiness.GetOPICSDealExternal(processdate);
                List<DA_TRN> importeddeals = _dealBusiness.GetImportedDealsByProcessDate(sessioninfo.Process.NextDate);

                //Ignore imported DMK Deals
                var query = from o in dealopics
                            where !importeddeals.Any(d => d.EXT_DEAL_NO == o.EXT_DEAL_NO)
                            select o;

                //Import unimported OPIC deals, and engine date < process date
                var passedopicdeals = query.Where(d => d.INSERT_DATE.Date < processdate.Date);

                //todaydeals for display on screen
                var todaydeals = from o in query
                                 where !passedopicdeals.Any(p => p.EXT_DEAL_NO == o.EXT_DEAL_NO)
                                 select o;

                //20140129
                //OPICS deals which are cancelled after reconcile have been run once, must be deleted from DMK
                var cancelleddeals = from o in importeddeals
                                     where !dealopics.Any(p => p.EXT_DEAL_NO == o.EXT_DEAL_NO)
                                     select o;

                if (passedopicdeals != null)
                {
                    LoggingHelper.Debug("Import Passed OPICS Deal");

                    foreach (DEALModel passedopicdeal in passedopicdeals.ToList())
                    {
                        if (ValidateOPICS(passedopicdeal))
                            ImportPassedOPICSDeal(sessioninfo, passedopicdeal, sessioninfo.Process.NextDate, ref DealTrans);
                    }

                    if (cancelleddeals != null)
                    {
                        foreach (DA_TRN trn in cancelleddeals.ToList())
                        {
                            DealTrans.Add(new DealTranModel() { ProductTransaction = (ProductCode)Enum.Parse(typeof(ProductCode), trn.MA_PRODUCT.LABEL.Replace(" ", string.Empty)), Transaction = trn, UpdateStates = UpdateStates.Deleting });
                        }
                    }
                    LoggingHelper.Debug("End Import Passed OPICS Deal as " + passedopicdeals.Count().ToString());

                    if (DealTrans.Count > 0)
                    {
                        LoggingHelper.Debug("UpdateDealReconcile for passed deal on " + processdate.ToString());

                        _reconcileBusiness.UpdateDealReconcile(sessioninfo, DealTrans);
                    }
                }

                //Sort order by sorting
                string[] sortsp = sorting.Split(' ');
                IQueryable<DEALModel> orderedRecords = todaydeals.AsQueryable().OrderBy(sortsp[0], sortsp[1]);
                IEnumerable<DEALModel> sortedRecords = orderedRecords.ToList();
                //if (sortsp[1].ToLower() == "desc") sortedRecords = sortedRecords.Reverse();
                FlagReconcile(sessioninfo, false);
                LoggingHelper.Debug("Un-locked Reconcile table " + processdate.ToString());
                //Return result to jTable
                return new { Result = "OK",
                             Records = count > 0 ? sortedRecords.Skip(startIndex).Take(count).ToList() : sortedRecords,
                             TotalRecordCount = sortedRecords.ToList().Count
                };
            }
            catch (Exception ex)
            {
                FlagReconcile(sessioninfo,false);
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Esempio n. 16
0
        public static object SendFIReport(SessionInfo sessioninfo, string IDs)
        {
            try
                {

                    string[] TrnsID = IDs.Split(',');
                    DealBusiness _dealBusiness = new DealBusiness();
                    LookupBusiness _lookupBusiness = new LookupBusiness();
                    MA_TBMA_CONFIG config = _lookupBusiness.GetTBMAConfig(sessioninfo);
                    Guid productID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID;
                    List<DA_TRN> trns = _dealBusiness.GetDealInternalByProcessDate(sessioninfo.Process.CurrentDate)
                                       .Where(a => a.PRODUCT_ID.Value == productID && TrnsID.Contains(a.ID.ToString()) && a.DA_TMBA_EXTENSION.SEND_DATE == null).ToList();
                    var validateTBMA_NAME = (from o1 in trns
                                            where string.IsNullOrEmpty(o1.MA_COUTERPARTY.TBMA_NAME)
                                            select o1.MA_COUTERPARTY.SNAME).Distinct().ToArray();

                    //verify required info
                    if (validateTBMA_NAME.Length > 0) {
                        throw CreateException(new Exception(), "TBMA_NAME can't be empty. Please input TBMA_NAME on counterparty " + string.Join(",", validateTBMA_NAME));
                    }
                    if (config == null)
                        throw CreateException(new Exception(), "Cannot get configurations. Please contact administrator");

                    foreach (DA_TRN trn in trns)
                    {
                        _dealBusiness.CreatingTBMAReportFile(sessioninfo, trn, config);
                    }

                    Guid[] TrnsIDSend = trns.Select(t => t.ID).ToArray();
                    _dealBusiness.UpdateFISendReport(sessioninfo, TrnsIDSend);
                    return new
                    {
                        Result = "OK",
                        Message = String.Format("Sending report completed")
                    };
                }
                catch (Exception ex)
                {
                    return new { Result = "ERROR", Message = ex.Message };
                }
        }
Esempio n. 17
0
        public static object SubmitFXSwapDeal(SessionInfo sessioninfo
                                                , DA_TRN trn1
                                                , DA_TRN trn2
                                                , string strOverApprover
                                                , string strOverComment
                                                , string strProductId1
                                                , string strProductId2)
        {
            try
             {
                 DealBusiness _dealBusiness = new DealBusiness();

                 string strDealNO1 = _dealBusiness.SubmitFXDeal(sessioninfo
                                                                 , trn1
                                                                 , strOverApprover
                                                                 , strOverComment
                                                                 , strProductId1);
                 trn2.INT_DEAL_NO = strDealNO1;
                 string strDealNO2 = _dealBusiness.SubmitFXDeal(sessioninfo
                                                                 , trn2
                                                                 , strOverApprover
                                                                 , strOverComment
                                                                 , strProductId2
                                                                 );
                 return new { Result = "OK", Message = strDealNO1 };
             }
             catch (Exception ex)
             {
                 return new { Result = "ERROR", Message = ex.Message };
             }
        }
Esempio n. 18
0
 public static DA_TRN GenerateFXSwapTransactionObject2(SessionInfo sessionInfo, string strTradeDate, string strCtpy, string strPortfolio, string strCurrencyPair
                                                         , string strContractCcy, string strCounterCcy, string strSpotRate
                                                         , string strBSFar, string strSetDateFar, string strSwapPointFar
                                                         , string strContractAmtFar, string strCounterAmtFar, string strSpotDate, string strRemark, bool settleFlag, int Version)
 {
     DealBusiness _dealBusiness = new DealBusiness();
      return _dealBusiness.GenerateFXSwapTransactionObject2(sessionInfo, strTradeDate, strCtpy, strPortfolio, strCurrencyPair
                                                        , strContractCcy, strCounterCcy, strSpotRate
                                                        , strBSFar, strSetDateFar, strSwapPointFar
                                                        , strContractAmtFar, strCounterAmtFar, strSpotDate, strRemark, settleFlag, Version);
 }
Esempio n. 19
0
        public static LimitDisplayModel CheckSwapSCE(SessionInfo sessioninfo, DA_TRN trn, string strExcludeID)
        {
            DealBusiness _dealBusiness = new DealBusiness();

            return _dealBusiness.CheckSwapSCE(sessioninfo, trn, strExcludeID);
        }
Esempio n. 20
0
 public static DA_TRN GenerateRepoTransactionObject(SessionInfo sessioninfo
                                                     , string  strTradeDate
                                                     , string strBuySell
                                                     , string strInstrument
                                                     , string strCtpy
                                                     , string strPortfolio
                                                     , string strEffectiveDate
                                                     , string strMaturityDate
                                                     , string strNotional
                                                     , string strProductId
                                                     , string strRemark)
 {
     DealBusiness _dealBusiness = new DealBusiness();
      return _dealBusiness.GenerateRepoTransactionObject(sessioninfo, strTradeDate, strBuySell, strInstrument
                                                     , strCtpy, strPortfolio, strEffectiveDate, strMaturityDate
                                                     , strNotional, strProductId, strRemark);
 }
Esempio n. 21
0
        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);
            }
        }
Esempio n. 22
0
        public static DA_TRN GenerateSwapTransactionObject(SessionInfo sessionInfo, string strTradeDate, string strInstrument, string strCtpy, string strPortfolio
                                                                , string strEffDate, string strMatDate, string strNotional1
                                                                , string strCCY1, string strFFL1, string strFFix1, string strRate1, string strFreq1
                                                                , string strNotional2, string strCCY2, string strFFL2, string strFFix2, string strRate2, string strFreq2
                                                                , int intDaySpan,string strRemark, string strProductId)
        {
            DealBusiness _dealBusiness = new DealBusiness();
                return _dealBusiness.GenerateSwapTransactionObject(sessionInfo, strTradeDate, strInstrument, strCtpy, strPortfolio
                                                                    , strEffDate, strMatDate, strNotional1
                                                                    , strCCY1, strFFL1, strFFix1, strRate1, strFreq1
                                                                    , strNotional2, strCCY2, strFFL2, strFFix2, strRate2, strFreq2
                                                                    , intDaySpan, strRemark, strProductId);

                //return trn;
        }
Esempio n. 23
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);
            }
        }
Esempio n. 24
0
 public static DA_TRN GetByID(Guid id)
 {
     DealBusiness _dealBusiness = new DealBusiness();
         return _dealBusiness.GetByID(id);
 }
Esempio n. 25
0
        public List<DA_TRN_CASHFLOW> GetSCEDetailReport(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 cashflows = _dealBusiness.GetFlowsByProcessDate(dteReport).AsQueryable();

                if (!string.IsNullOrEmpty(strSource))
                {
                    cashflows = cashflows.Where(p => p.DA_TRN.SOURCE == strSource);
                }

                if (Guid.TryParse(strCtpy, out guTemp))
                {
                    cashflows = cashflows.Where(p => p.DA_TRN.CTPY_ID == Guid.Parse(strCtpy));
                }

                if (Guid.TryParse(strProduct, out guTemp))
                {
                    cashflows = cashflows.Where(p => p.DA_TRN.PRODUCT_ID == Guid.Parse(strProduct));
                }

                return cashflows.OrderBy(p => p.DA_TRN.INT_DEAL_NO).ThenByDescending(p => p.FLAG_FIRST).ThenBy(p => p.SEQ).ToList();
            }

            catch (DataServicesException ex)
            {
                throw this.CreateException(ex, null);
            }
        }
Esempio n. 26
0
        public static List<FIDealModel> GetDealInternalByProcessDate(SessionInfo sessioninfo)
        {
            DealBusiness _dealBusiness = new DealBusiness();
            UserBusiness _userBusiness = new UserBusiness();
            LookupBusiness _lookupBusiness = new LookupBusiness();
            List<MA_CURRENCY> ccys = _lookupBusiness.GetCurrencyAll();
            List<MA_USER> users = _userBusiness.GetAll();
            Guid productID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID;
            List<DA_TRN> trns = _dealBusiness.GetDealInternalByProcessDate(sessioninfo.Process.CurrentDate);

            return (from t in trns.Where(a => a.PRODUCT_ID.Value == productID && a.DA_TMBA_EXTENSION != null)
                      join user in users on t.LOG.INSERTBYUSERID equals user.ID into ljuser
                      from inputuser in ljuser.DefaultIfEmpty()
                      join tempccy1 in ccys on t.FIRST.CCY_ID equals tempccy1.ID  into ljccy1
                      from ccy1 in ljccy1.DefaultIfEmpty()
                      join tbmauser in users on  t.DA_TMBA_EXTENSION.SENDER_ID equals tbmauser.ID  into ljtbmauser
                      from tbmainputuser in ljtbmauser.DefaultIfEmpty()
                      orderby t.LOG.INSERTDATE descending
                      select new FIDealModel
                      {
                          ID = t.ID,
                          DMK_NO = t.INT_DEAL_NO,
                          OPICS_NO = t.EXT_DEAL_NO,
                          InsertState = t.MA_STATUS.LABEL == StatusCode.CANCELLED.ToString()
                                            ? "Cancelled"
                                            : t.DA_TMBA_EXTENSION.SEND_DATE != null
                                                ? "Sent"
                                                : 1800 - DateTime.Now.Subtract(t.LOG.INSERTDATE).TotalSeconds <=0
                                                    ? "Late"
                                                    : (1800 - Math.Round( DateTime.Now.Subtract(t.LOG.INSERTDATE).TotalSeconds)).ToString() ,
                          TradeDate = t.TRADE_DATE.Value,
                          MaturityDate = t.MATURITY_DATE,
                          Instrument = t.MA_INSRUMENT.LABEL,
                          BuySell = t.FLAG_BUYSELL,
                          Portfolio = t.MA_PORTFOLIO.LABEL,
                          Counterparty = t.MA_COUTERPARTY.SNAME,
                          Yield = t.FIRST.RATE.Value,
                          GrossValue = t.FIRST.NOTIONAL.Value,
                          CCY = ccy1 != null ? ccy1.LABEL : null,
                          Trader = inputuser != null ? inputuser.USERCODE : null,
                          Status = t.MA_STATUS.LABEL,
                          PCE = t.KK_CONTRIBUTE.HasValue ? t.KK_CONTRIBUTE.Value : 0,
                          Sender = tbmainputuser != null ? tbmainputuser.USERCODE : null,
                          Unit = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.UNIT : 0,
                          CleanPrice = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.CLEAN_PRICE : 0,
                          GrossPrice = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.GROSS_PRICE : 0,
                          YieldType = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.YIELD_TYPE : string.Empty,
                          ReporyBy = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.IS_REPORT_CLEAN ? "Clean Price" : "Gross Price" : string.Empty,
                          Purpose = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.PURPOSE : string.Empty,
                          Term = t.DA_TMBA_EXTENSION != null && t.DA_TMBA_EXTENSION.TERM.HasValue ? t.DA_TMBA_EXTENSION.TERM.Value : 0,
                          Rate = t.DA_TMBA_EXTENSION != null && t.DA_TMBA_EXTENSION.RATE.HasValue ? t.DA_TMBA_EXTENSION.RATE.Value : 0,
                          TBMA_Remark = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.REMARK : string.Empty,
                          SendTime = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.SEND_DATE.HasValue ? t.DA_TMBA_EXTENSION.SEND_DATE.Value.ToString("dd MMM yyy HH:mm") : string.Empty : string.Empty,
                          PrimaryMarket = t.FLAG_PCE.Value ? "Yes" : "No",
                          NonDVP = t.FLAG_SETTLE.Value ? "Yes" : "No"
                      }).ToList();
        }
Esempio n. 27
0
        public static DA_TRN GetFXSwapPair(SessionInfo sessioninfo, string strIntDealNo, int intVersion, Guid id)
        {
            DealBusiness _dealBusiness = new DealBusiness();

             return _dealBusiness.GetFXSwapPair(strIntDealNo, intVersion, id);
        }
Esempio n. 28
0
        public static LimitDisplayModel CheckFXSwapCountryLimit(SessionInfo sessioninfo, DA_TRN trn1, DA_TRN trn2, string strExcludeID)
        {
            DealBusiness _dealBusiness = new DealBusiness();

            return _dealBusiness.CheckFXSwapCountryLimit(sessioninfo, trn1, trn2, strExcludeID);
        }
Esempio n. 29
0
        public static object CancelDeal(SessionInfo sessioninfo, DA_TRN trn)
        {
            try
            {
                LookupBusiness _lookupBusiness = new LookupBusiness();
                UserBusiness _userBusiness = new UserBusiness();
                DealBusiness _dealbusiness = new DealBusiness();
                DA_TRN t = _dealbusiness.CancelDeal(sessioninfo, trn);
                DA_TRN t2 = _dealbusiness.GetDealByDealNo(t.INT_DEAL_NO,t.VERSION).FirstOrDefault(p => p.ID != t.ID);
                if (t2 != null) _dealbusiness.CancelDeal(sessioninfo, t2);
                var inputuser = _userBusiness.GetAll().FirstOrDefault(u => u.ID == t.LOG.INSERTBYUSERID);

                var query = new DealViewModel
                            {
                                ID = t.ID,
                                EntryDate = t.LOG.INSERTDATE,
                                DMK_NO = t.INT_DEAL_NO
                                ,
                                OPICS_NO = t.EXT_DEAL_NO,
                                TradeDate = t.TRADE_DATE.Value
                                ,
                                EffectiveDate = t.START_DATE,
                                Instrument = t.MA_INSRUMENT.LABEL
                                ,
                                MaturityDate = t.MATURITY_DATE,
                                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.Value ? "FIXED" : "FLOAT"
                                ,
                                Rate1 = t.FIRST.RATE,
                                Fixing1 = t.FIRST.FIRSTFIXINGAMT,
                                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"
                                ,
                                Rate2 = t.SECOND.RATE,
                                Fixing2 = t.SECOND.FIRSTFIXINGAMT,
                                SwapPoint2 = t.SECOND.SWAP_POINT,
                                Status =  _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.ID == t.STATUS_ID).LABEL
                                ,
                                KKContribute = t.KK_CONTRIBUTE,
                                BotContribute = t.BOT_CONTRIBUTE
                                ,
                                LimitOverwrite = string.IsNullOrEmpty(t.OVER_APPROVER) ? "No" : t.OVER_AMOUNT > 0 && t.OVER_SETTL_AMOUNT > 0 ? "Yes" : t.OVER_AMOUNT > 0 ? "PCE" : "SET"
                                ,
                                LimitApprover = t.OVER_APPROVER
                                ,
                                Trader = inputuser != null ? inputuser.USERCODE : ""
                                ,
                                Remark = t.REMARK
                            };
                return new { Result = "OK", Record = query, DealPairID = t2 != null? t2.ID.ToString() : string.Empty };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Esempio n. 30
0
 /// <summary>
 /// Rollback Transaction
 /// </summary>
 /// <param name="sessioninfo"></param>
 /// <param name="deal"></param>
 private static void RollbackTransaction(SessionInfo sessioninfo, DA_TRN deal)
 {
     DealBusiness _dealBusiness = new DealBusiness();
     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;
     //Update data
     _dealBusiness.Update(sessioninfo, deal);
 }