Пример #1
0
 public DA_TRN CancelDeal(SessionInfo sessioninfo, DA_TRN trn)
 {
     LookupBusiness _lookupBusiness = new LookupBusiness();
     using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
     {
         var foundTrn = unitOfWork.DA_TRNRepository.GetById(trn.ID,true);
         if (foundTrn == null)
             throw this.CreateException(new Exception(), "Data not found!");
         else if (!Guid.Equals(foundTrn.LOG.INSERTBYUSERID, sessioninfo.CurrentUserId))
         {
             throw this.CreateException(new Exception(), "You have no right to cancel this transaction");
         }
         else if (!(foundTrn.ENGINE_DATE.Date == sessioninfo.Process.CurrentDate && foundTrn.SOURCE == "INT"))
         {
             throw this.CreateException(new Exception(), "You cannot cancel the past deals");
         }
         else
         {
             //foundTrn.STATUS_ID = new Guid("1ccd7506-b98c-4afa-838e-24378d9b3c2e");
             foundTrn.REMARK = trn.REMARK;
             foundTrn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.CANCELLED.ToString()).ID;
             foundTrn.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId;
             foundTrn.LOG.MODIFYDATE = DateTime.Now;
             trn = foundTrn;
             unitOfWork.Commit();
         }
     }
     return trn;
 }
Пример #2
0
 public MemoryLookupValues()
 {
     Frequencies = _lookupBusiness.GetFreqTypeAll();
     Products    = _lookupBusiness.GetProductAll();
     Statuses    = _lookupBusiness.GetStatusAll();
     Portfolios  = _lookupBusiness.GetPortfolioAll();
     Limits      = _lookupBusiness.GetLimitAll();
     Currencies  = _lookupBusiness.GetCurrencyAll();
 }
Пример #3
0
        public static object GetStatusOptions(SessionInfo sessioninfo)
        {
            try
            {
                LookupBusiness _lookupBusiness = new LookupBusiness();
                //Get data from database
                var products = _lookupBusiness.GetStatusAll().Select(c => new { DisplayText = c.LABEL, Value = c.ID });

                //Return result to jTable
                return(new { Result = "OK", Options = products });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Пример #4
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 };
            }
        }
Пример #5
0
        public static object GetStatusOptions(SessionInfo sessioninfo)
        {
            try
            {
                LookupBusiness _lookupBusiness = new LookupBusiness();
                //Get data from database
                var products = _lookupBusiness.GetStatusAll().Select(c => new { DisplayText = c.LABEL, Value = c.ID });

                //Return result to jTable
                return new { Result = "OK", Options = products };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Пример #6
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 });
            }
        }
Пример #7
0
        public 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)
        {
            LookupBusiness _lookupBusiness = new LookupBusiness();
            DA_TRN trn = new DA_TRN();
            DA_TRN lastrn  = null;
            Guid guTemp;
            if (Guid.TryParse(strProductId, out guTemp)) {
                lastrn = new DA_TRN();
                lastrn = GetByID(guTemp);
            }
            trn.ID = Guid.NewGuid();
            trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;
            trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);
            trn.START_DATE = trn.TRADE_DATE;
            trn.MATURITY_DATE = DateTime.ParseExact(strSpotDate, "dd/MM/yyyy", null);
            trn.CTPY_ID = Guid.Parse(strCtpy);
            trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);
            trn.INSTRUMENT_ID = Guid.Parse(strCurrencyPair);
            trn.FIRST.CCY_ID = Guid.Parse(strContractCcy);
            trn.SECOND.CCY_ID = Guid.Parse(strCounterCcy);
            trn.FIRST.RATE = Convert.ToDecimal(strSpotRate);
            trn.FLAG_BUYSELL = strBS;
            trn.FIRST.NOTIONAL = trn.FLAG_BUYSELL == "B" ? Convert.ToDecimal(strContractAmt) : -Convert.ToDecimal(strContractAmt);
            trn.SECOND.NOTIONAL = trn.FLAG_BUYSELL == "B" ? -Convert.ToDecimal(strCounterAmt) : Convert.ToDecimal(strCounterAmt);
            trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO;
            trn.SOURCE = SourceType.INT.ToString();
            trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1;
            trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL.Replace(" ", string.Empty) == ProductCode.FXSPOT.ToString()).ID;
            trn.FIRST.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "R" : "P";
            trn.SECOND.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "P" : "R";
            trn.LOG.INSERTDATE = DateTime.Now;
            trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
            trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
            trn.FLAG_SETTLE = !settleFlag;
            trn.REMARK = strRemark;
            var ccys = _lookupBusiness.GetCurrencyAll().AsQueryable();
            var n1 = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID  && p.LABEL == "THB");
            var n2 = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID  && p.LABEL == "THB");
            var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
            if (n1 != null)
                trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value);
            else if (n2 != null)
                trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value);
            else
            {
                var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                var secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);

                if (firstRate != null && secondRate != null)
                {
                    if (Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE))
                        trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE);
                    else
                        trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE);
                }
                else
                {
                    var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                    throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                }
             }

            //StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
            //trn.KK_PCCF = _staticdataBusiness.GetFXPCCF(sessionInfo, trn);
            //trn.KK_CONTRIBUTE = trn.NOTIONAL_THB.Value * trn.KK_PCCF / 100;

            DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW();

            flow1.ID = Guid.NewGuid();
            flow1.DA_TRN_ID = trn.ID;
            flow1.FLAG_FIRST = true;
            flow1.RATE = trn.FIRST.RATE;
            flow1.FLOW_DATE = trn.MATURITY_DATE;
            flow1.FLOW_AMOUNT = trn.FIRST.NOTIONAL;
            if (n1 != null)
                flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value);
            else
            {
                var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                if (a != null){
                    flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE);
                }
                else{
                    var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                    throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                }

            }
            flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE;
            flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

            DA_TRN_CASHFLOW flow2 = new DA_TRN_CASHFLOW();

            flow2.ID = Guid.NewGuid();
            flow2.DA_TRN_ID = trn.ID;
            flow2.FLAG_FIRST = false;
            flow2.FLOW_DATE = trn.MATURITY_DATE;
            flow2.FLOW_AMOUNT = trn.SECOND.NOTIONAL;
            if (n2 != null)
                flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value);
            else
            {
                var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                if (a != null)
                {
                    flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value * a.RATE);
                }
                else
                {
                    var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID);
                    throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                }
            }

            flow2.LOG.INSERTDATE = trn.LOG.INSERTDATE;
            flow2.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

            trn.DA_TRN_FLOW.Add(flow1);
            trn.DA_TRN_FLOW.Add(flow2);
            return trn;
        }
Пример #8
0
        public 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)
        {
            //Validate business logics here
            //throw error to UI if fail validation
            LookupBusiness _lookupBusiness = new LookupBusiness();
            DA_TRN trn = new DA_TRN();
            DA_TRN lastrn = null;
            DateTime dteTemp;
            Decimal decTemp;
            Guid guTemp;
            if (Guid.TryParse(strProductId, out guTemp))
            {
                lastrn = new DA_TRN();
                lastrn = GetByID(guTemp);
            }
            trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;

            if (strCtpy == "null")
                throw this.CreateException(new Exception(), "Please input counterparty.");
            else
                trn.CTPY_ID = Guid.Parse(strCtpy);

            if (String.IsNullOrEmpty(strTradeDate))
                throw this.CreateException(new Exception(), "Please input trade date.");
            else if (!DateTime.TryParseExact(strTradeDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteTemp))
                throw this.CreateException(new Exception(), "Invalid trade date.");
            else
                trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);

            if (String.IsNullOrEmpty(strSettlementDate))
                throw this.CreateException(new Exception(), "Please input settlement date.");
            else if (!DateTime.TryParseExact(strSettlementDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteTemp))
                throw this.CreateException(new Exception(), "Invalid settlement date.");
            else
            {
                trn.MATURITY_DATE = DateTime.ParseExact(strSettlementDate, "dd/MM/yyyy", null);
                trn.START_DATE = trn.MATURITY_DATE;
            }

            if (strInstrument == "null")
                throw this.CreateException(new Exception(), "Please input instrument.");
            else
                trn.INSTRUMENT_ID = Guid.Parse(strInstrument);

            if (String.IsNullOrEmpty(strNotional))
                throw this.CreateException(new Exception(), "Please input notional amount.");
            else if (!Decimal.TryParse(strNotional, out decTemp))
                throw this.CreateException(new Exception(), "Invalid notional amount.");
            else if (Convert.ToDecimal(strNotional) <= 0)
                throw this.CreateException(new Exception(), "Invalid notional amount.");
            else
                trn.FIRST.NOTIONAL = Convert.ToDecimal(strNotional);

            if (strPortfolio == "-1")
                throw this.CreateException(new Exception(), "Please select portfolio.");
            else
                trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);

            if (trn.MATURITY_DATE < trn.TRADE_DATE)
            {
                throw this.CreateException(new Exception(), "Settlement date cannot be before trade date.");
            }
            if ((strPurpose.Trim() == TBMA_PURPOSE.FIN.ToString() || strPurpose.Trim() == TBMA_PURPOSE.FINB.ToString() || strPurpose.Trim() == TBMA_PURPOSE.FINP.ToString()) && (strTBMARemark.Trim() == string.Empty || strRate.Trim() == string.Empty || strTerm.Trim() == string.Empty))
            {
                throw this.CreateException(new Exception(), "Please input Term, Rate and Remark.");
            }
            if (lastrn != null) {
                if (strRemark == "")
                    throw this.CreateException(new Exception(), "Please input comment.");
                else trn.REMARK = strRemark;
            }
            trn.ID = Guid.NewGuid();
            trn.FLAG_SETTLE = strSettleFlag == "1" ? true : false;
            trn.FLAG_BUYSELL = strBuySell;
            trn.FIRST.CCY_ID = Guid.Parse(strCCY);
            trn.FIRST.RATE = Convert.ToDecimal(strYield);
            trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID;
            trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1;
            trn.SOURCE = SourceType.INT.ToString();
            trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
            trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO;
            var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
            var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == trn.TRADE_DATE);
            if (a == null)
            {
                var ccys = _lookupBusiness.GetCurrencyAll().FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                throw this.CreateException(new Exception(), "Error : There is no " + ccys.LABEL + " spot rate on " + strTradeDate + " trade date.");
            }
            trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE);
            trn.FLAG_PCE = strPceFlag == "1" ? true : false;
            trn.LOG.INSERTDATE = DateTime.Now;
            trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
            DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW();
            flow1.ID = Guid.NewGuid();
            flow1.DA_TRN_ID = trn.ID;
            flow1.FLAG_FIRST = true;
            flow1.FLOW_DATE = trn.MATURITY_DATE;
            flow1.FLOW_AMOUNT = trn.FLAG_BUYSELL == "B" ? -trn.FIRST.NOTIONAL : trn.FIRST.NOTIONAL;
            flow1.FLOW_AMOUNT_THB = trn.FLAG_BUYSELL == "B" ? -trn.NOTIONAL_THB : trn.NOTIONAL_THB;
            flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE;
            flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;
            trn.DA_TRN_FLOW.Add(flow1);

            DA_TMBA_EXTENSION tbma = new DA_TMBA_EXTENSION();
            tbma.ID = trn.ID;
            tbma.PURPOSE = strPurpose;
            tbma.YIELD_TYPE = strYeildType;
            tbma.CLEAN_PRICE = Convert.ToDecimal(strCleanPrice);
            tbma.GROSS_PRICE = Convert.ToDecimal(strGrossPrice);
            tbma.UNIT = Convert.ToInt32(strUnit);
            if (strTerm != string.Empty)
                tbma.TERM = Convert.ToInt32(strTerm);
            if (strRate != string.Empty)
                tbma.RATE = Convert.ToDecimal(strRate);
            if (strTBMARemark != string.Empty)
                tbma.REMARK = strTBMARemark;
            tbma.IS_REPORT_CLEAN = strReportBy == "0" ? true : false;

            if (lastrn != null)
            {
                tbma.SEND_DATE = lastrn.DA_TMBA_EXTENSION.SEND_DATE;
                tbma.SENDER_ID = lastrn.DA_TMBA_EXTENSION.SENDER_ID;
            }

            trn.DA_TMBA_EXTENSION = tbma;
            return trn;
        }
Пример #9
0
        public string SubmitSwapDeal(SessionInfo sessioninfo
										, DA_TRN trn
										, string strOverApprover
										, string strOverComment
										, string strProductId)
        {
            //trn.STATUS_ID = Guid.Parse("9161ed18-1298-44fa-ba7d-34522cb40d66");
            //trn.INT_DEAL_NO = GetNewDealNo(sessioninfo.Process.CurrentDate);

            //StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
            //trn.KK_PCCF = _staticdataBusiness.GetSwapKKPCCF(sessioninfo, trn);
            //trn.KK_CONTRIBUTE = trn.FIRST.NOTIONAL * trn.KK_PCCF / 100;
            //trn.BOT_PCCF = _staticdataBusiness.GetSwapBOTPCCF(sessioninfo, trn);
            //trn.BOT_CONTRIBUTE = trn.FIRST.NOTIONAL * trn.BOT_PCCF / 100;
            LookupBusiness _lookupBusiness = new LookupBusiness();
            if (!String.IsNullOrEmpty(strOverApprover))
            {
                trn.OVER_APPROVER = strOverApprover;
                trn.OVER_COMMENT = strOverComment;
            }

            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                Guid guTemp;
                if (Guid.TryParse(strProductId, out guTemp))
                {
                    var foundDeal = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == guTemp);
                    if (foundDeal == null)
                        throw this.CreateException(new Exception(), "Data not found!");
                    else
                    {
                        foundDeal.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.CANCELLED.ToString()).ID;
                        foundDeal.REMARK = trn.REMARK;
                    }
                }
                trn.REMARK = null;
                if (trn.INT_DEAL_NO == null)
                    trn.INT_DEAL_NO = GetNewDealNo(sessioninfo.Process.CurrentDate);
                unitOfWork.DA_TRNRepository.Add(trn);
                unitOfWork.Commit();
            }
            return trn.INT_DEAL_NO;
        }
Пример #10
0
        public string SubmitRepoDeal(SessionInfo sessioninfo
												 , DA_TRN trn
												 , string strOverApprover
												 , string strOverComment
												 , string strProductId)
        {
            LookupBusiness _lookupBusiness = new LookupBusiness();
             if (!String.IsNullOrEmpty(strOverApprover))
             {
                 trn.OVER_APPROVER = strOverApprover;
                 trn.OVER_COMMENT = strOverComment;
             }

             using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
             {
                 Guid guTemp;
                 if (Guid.TryParse(strProductId, out guTemp))
                 {
                     var foundDeal = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == guTemp);
                     if (foundDeal == null)
                         throw this.CreateException(new Exception(), "Data not found!");
                     else
                     {
                         foundDeal.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.CANCELLED.ToString()).ID;
                         foundDeal.REMARK = trn.REMARK;
                     }
                 }
                 trn.REMARK = null;
                 if (trn.INT_DEAL_NO == null)
                     trn.INT_DEAL_NO = GetNewDealNo(sessioninfo.Process.CurrentDate);
                 unitOfWork.DA_TRNRepository.Add(trn);
                 unitOfWork.Commit();
             }
             return trn.INT_DEAL_NO;
        }
Пример #11
0
        public 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)
        {
            LookupBusiness _lookupBusiness = new LookupBusiness();
            DA_TRN trn = new DA_TRN();
            DA_TRN lastrn = null;
            Guid guTemp;
            if (Guid.TryParse(strProductId, out guTemp))
            {
                lastrn = new DA_TRN();
                lastrn = GetByID(guTemp);
            }
            trn.ID = Guid.NewGuid();
            trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;
            trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);
            trn.INSTRUMENT_ID = Guid.Parse(strInstrument);
            trn.CTPY_ID = Guid.Parse(strCtpy);
            trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);
            trn.START_DATE = DateTime.ParseExact(strEffDate, "dd/MM/yyyy", null);
            trn.MATURITY_DATE = DateTime.ParseExact(strMatDate, "dd/MM/yyyy", null);
            trn.FIRST.NOTIONAL = Convert.ToDecimal(strNotional1);
            trn.SECOND.NOTIONAL  = Convert.ToDecimal(strNotional2);
            //Fix Currency Type
            trn.FIRST.CCY_ID =  Guid.Parse(strCCY1);
            trn.SECOND.CCY_ID= Guid.Parse(strCCY2);
            trn.FIRST.FLAG_PAYREC = "P";
            trn.FIRST.FLAG_FIXED = strFFL1 == "1" ? true : false;

            if (!trn.FIRST.FLAG_FIXED.Value)
            {
                trn.FIRST.FIRSTFIXINGAMT = Convert.ToDecimal(strFFix1);
            }
            trn.FIRST.RATE = Convert.ToDecimal(strRate1);
            trn.FIRST.FREQTYPE_ID = Guid.Parse(strFreq1);
            trn.SECOND.FLAG_PAYREC = "R";
            trn.SECOND.FLAG_FIXED = strFFL2 == "1" ? true : false;

            if (!trn.SECOND.FLAG_FIXED.Value)
            {
                trn.SECOND.FIRSTFIXINGAMT = Convert.ToDecimal(strFFix2);
            }
            trn.SECOND.RATE = Convert.ToDecimal(strRate2);
            trn.SECOND.FREQTYPE_ID = Guid.Parse(strFreq2);

            if (lastrn != null)
            {
                if (strRemark == "")
                    throw this.CreateException(new Exception(), "Please input comment.");
                else trn.REMARK = strRemark;
            }
            trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.SWAP.ToString()).ID;
            trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1;
            trn.SOURCE = SourceType.INT.ToString();
            trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
            trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO;
            trn.FLAG_SETTLE = true;
            trn.LOG.INSERTDATE = DateTime.Now;
            trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
            var ccys = _lookupBusiness.GetCurrencyAll().AsQueryable();
            var n1 = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID && p.LABEL == "THB");
            var n2 = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID && p.LABEL == "THB");
            var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
            var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
            var secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
            if (firstRate == null || secondRate == null)
            {
                var ccylabel = ccys.Where(p => (p.ID == trn.FIRST.CCY_ID && firstRate == null) || (p.ID == trn.SECOND.CCY_ID && secondRate == null)).Select(p => p.LABEL);
                var strCCY = string.Join(" and ",ccylabel);
                throw this.CreateException(new Exception(), "Error : There is no " + strCCY + " spot rate.");
            }
            if (n1 != null)
                trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value);
            else if (n2 != null)
                trn.NOTIONAL_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value);
            else
            {
                if (Math.Ceiling(trn.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Ceiling(trn.SECOND.NOTIONAL.Value * secondRate.RATE))
                    trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * firstRate.RATE);
                else
                    trn.NOTIONAL_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value * secondRate.RATE);
            }
            GenerateCashFlows(sessionInfo, trn, intDaySpan, firstRate.RATE, secondRate.RATE);

            return trn;
        }
Пример #12
0
        public 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)
        {
            //Validate business logics here
             //throw error to UI if fail validation
             LookupBusiness _lookupBusiness = new LookupBusiness();
             DA_TRN trn = new DA_TRN();
             DA_TRN lastrn = null;
             Guid guTemp;
             if (Guid.TryParse(strProductId, out guTemp))
             {
                 lastrn = new DA_TRN();
                 lastrn = GetByID(guTemp);
             }
             trn.ID = Guid.NewGuid();
             trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;
             trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO;
             trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1;
             trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.REPO.ToString()).ID;
             trn.SOURCE = SourceType.INT.ToString();
             trn.CTPY_ID = Guid.Parse(strCtpy);
             trn.INSTRUMENT_ID = Guid.Parse(strInstrument);
             trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);
             trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);
             trn.START_DATE = DateTime.ParseExact(strEffectiveDate, "dd/MM/yyyy", null);
             trn.MATURITY_DATE = DateTime.ParseExact(strMaturityDate, "dd/MM/yyyy", null);
             trn.FLAG_BUYSELL = strBuySell;
             trn.FIRST.NOTIONAL = Convert.ToDecimal(strNotional);
             trn.FIRST.CCY_ID = _lookupBusiness.GetCurrencyAll().FirstOrDefault(p => p.LABEL == "THB").ID;
             trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
             trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value);
             trn.FLAG_SETTLE = false;

             if (lastrn != null)
             {
                 if (strRemark == "")
                     throw this.CreateException(new Exception(), "Please input comment.");
                 else trn.REMARK = strRemark;
             }
             trn.LOG.INSERTDATE = DateTime.Now;
             trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
             return trn;
        }
Пример #13
0
        public 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)
        {
            LookupBusiness _lookupBusiness = new LookupBusiness();
             DA_TRN trn = new DA_TRN();

             trn.ID = Guid.NewGuid();
             trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;
             //trn.INT_DEAL_NO = strDealNo;
             trn.SOURCE = SourceType.INT.ToString();
             trn.VERSION = Version;
             trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL.Replace(" ", string.Empty) == ProductCode.FXSWAP.ToString()).ID;
             trn.CTPY_ID = Guid.Parse(strCtpy);
             trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);
             trn.INSTRUMENT_ID = Guid.Parse(strCurrencyPair);
             trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);
             trn.SPOT_DATE = DateTime.ParseExact(strSpotDate, "dd/MM/yyyy", null);

             //If settle after spot date (forward deal) then bucket is count from spot -> settlement date
             //else (O/N or T/N deal) no need to count bucket so start date will be null
             if (DateTime.ParseExact(strSetDateFar, "dd/MM/yyyy", null) > trn.SPOT_DATE)
                 trn.START_DATE = trn.SPOT_DATE;
             else
                 trn.START_DATE = trn.TRADE_DATE;

             trn.MATURITY_DATE = DateTime.ParseExact(strSetDateFar, "dd/MM/yyyy", null);
             trn.FLAG_BUYSELL = strBSFar;
             trn.FLAG_NEARFAR = "F";
             trn.FIRST.NOTIONAL = trn.FLAG_BUYSELL == "B" ? Convert.ToDecimal(strContractAmtFar) : -Convert.ToDecimal(strContractAmtFar);
             trn.FIRST.CCY_ID = Guid.Parse(strContractCcy);
             trn.FIRST.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "R" : "P";
             trn.FIRST.RATE = Convert.ToDecimal(strSpotRate) + Convert.ToDecimal(strSwapPointFar);
             trn.FIRST.SWAP_POINT = Convert.ToDecimal(strSwapPointFar);
             trn.SECOND.NOTIONAL = trn.FLAG_BUYSELL == "B" ? -Convert.ToDecimal(strCounterAmtFar) : Convert.ToDecimal(strCounterAmtFar);
             trn.SECOND.CCY_ID = Guid.Parse(strCounterCcy);
             trn.SECOND.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "P" : "R";
             trn.LOG.INSERTDATE = DateTime.Now;
             trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
             trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
             trn.FLAG_SETTLE = !settleFlag;
             trn.REMARK = strRemark;
             var ccys = _lookupBusiness.GetCurrencyAll().AsQueryable();
             var n1 = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID && p.LABEL == "THB");
             var n2 = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID && p.LABEL == "THB");
             var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
             if (n1 != null)
                 trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value);
             else if (n2 != null)
                 trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value);
             else
             {
                 var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                 var secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);

                 if (firstRate != null && secondRate != null)
                 {
                     if (Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE))
                         trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE);
                     else
                         trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE);
                 }
                 else
                 {
                     var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                     throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                 }
             }

             //StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
             //trn.KK_PCCF = _staticdataBusiness.GetFXPCCF(sessionInfo, trn);
             //trn.KK_CONTRIBUTE = Math.Abs(trn.NOTIONAL_THB.Value) * trn.KK_PCCF / 100;

             DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW();

             flow1.ID = Guid.NewGuid();
             flow1.DA_TRN_ID = trn.ID;
             flow1.FLAG_FIRST = true;
             flow1.RATE = trn.FIRST.RATE + trn.FIRST.SWAP_POINT;
             flow1.FLOW_DATE = trn.MATURITY_DATE;
             flow1.FLOW_AMOUNT = trn.FIRST.NOTIONAL;
             if (n1 != null)
                 flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value);
             else
             {
                 var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                 if (a != null)
                 {
                     flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE);
                 }
                 else
                 {
                     var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                     throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                 }

             }
             flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE;
             flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

             DA_TRN_CASHFLOW flow2 = new DA_TRN_CASHFLOW();

             flow2.ID = Guid.NewGuid();
             flow2.DA_TRN_ID = trn.ID;
             flow2.FLAG_FIRST = false;
             flow2.FLOW_DATE = trn.MATURITY_DATE;
             flow2.FLOW_AMOUNT = trn.SECOND.NOTIONAL;
             if (n2 != null)
                 flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value);
             else
             {
                 var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                 if (a != null)
                 {
                     flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value * a.RATE);
                 }
                 else
                 {
                     var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID);
                     throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                 }
             }

             flow2.LOG.INSERTDATE = trn.LOG.INSERTDATE;
             flow2.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

             trn.DA_TRN_FLOW.Add(flow1);
             trn.DA_TRN_FLOW.Add(flow2);
             return trn;
        }