示例#1
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);
                }
            }
        }
示例#2
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 };
            }
        }
示例#3
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 };
            }
        }
示例#4
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 };
            }
        }