private void CalculateSupervisor(Broker brk, BrokerCommissionModal masterData)
        {
            // Calculate the total of all subordinates
            foreach (string key in brk.HashSubordinate.Keys)
            {
                Broker subBrk = (Broker)brk.HashSubordinate[key];

                brk.PaymentResult.SubtotalNetRevenue += subBrk.PaymentResult.NetRevenue;
                brk.PaymentResult.SubtotalInheritedNetRevenue += subBrk.PaymentResult.InheritedNetRevenue;
                brk.PaymentResult.SubtotalPrivateNetRevenue += subBrk.PaymentResult.PrivateNetRevenue;

                brk.PaymentResult.SubtotalTradingValue += subBrk.PaymentResult.TradingValue;
                brk.PaymentResult.SubtotalInheritedTradingValue += subBrk.PaymentResult.InheritedTradingValue;
                brk.PaymentResult.SubtotalPrivateTradingValue += subBrk.PaymentResult.PrivateTradingValue;
            }

            // Find the Commission Rates
            // Find the Commission Rate for ClientType = 1 --> Client from HSC
            CommissionRate rate4OldClient = masterData.FindCommissionRate(brk.SUPCommissionCode,
                ClientType.CLIENTTYPE_ID_FROMHSC, brk.PaymentResult.SubtotalNetRevenue);

            // Find the Commission Rate for ClientType = 2 --> Client found by broker
            CommissionRate rate4NewClient = masterData.FindCommissionRate(brk.SUPCommissionCode,
                    ClientType.CLIENTTYPE_ID_BYBROKER, brk.PaymentResult.SubtotalNetRevenue);

            if (rate4NewClient == null)
            {
                _logger.Error("CalculateSupervisor - rate4NewClient not found. BrokerID=" + brk.Id);
                rate4NewClient = new CommissionRate(ClientType.CLIENTTYPE_ID_BYBROKER, Constants.BROKERTYPE_SUP);
            }

            if (rate4OldClient == null)
            {
                _logger.Error("CalculateSupervisor - rate4OldClient not found. BrokerID=" + brk.Id);
                rate4OldClient = new CommissionRate(ClientType.CLIENTTYPE_ID_FROMHSC, Constants.BROKERTYPE_SUP);
            }

            Decimal a = (brk.PaymentResult.SubtotalInheritedNetRevenue * (decimal)rate4OldClient.Commissionrate); // A
            Decimal b = (brk.PaymentResult.SubtotalPrivateNetRevenue * (decimal)rate4NewClient.Commissionrate); // B1 or B2 depends on the matched rate
            brk.PaymentResult.SupervisorPayment = a + b;
            brk.PaymentResult.Payment += brk.PaymentResult.SupervisorPayment;
            //_logger.Debug("CalculateSupervisor - LEAVE");
        }
        private void CalculateManager(Broker brk, BrokerCommissionModal masterData)
        {
            //_logger.Debug("CalculateManager - ENTER");
            if ((brk.Office == null) || (brk.Office.Id == null) || (brk.Office.Branch == null)) return;

            decimal revenue = 0;
            decimal value = 0;
            decimal value4FindingRate = 0;
            if (brk.Office.IsBranch(Office.BRANCH_ID_HN))
            {
                revenue = brk.Office.Branch.Result.NetRevenue;
                value = brk.Office.Branch.Result.TradingValue;
                value4FindingRate = value;
            }
            else if (brk.Office.IsBranch(Office.BRANCH_ID_HCM))
            {
                revenue = brk.Office.Result.NetRevenue;
                value = brk.Office.Result.TradingValue;
                value4FindingRate = (value - 1000000000000); // 1K Bil
                if (value4FindingRate < 0) value4FindingRate = 0;
            }

            CommissionRate rate4Manager = masterData.FindCommissionRate(brk.MANCommissionCode,
                ClientType.CLIENTTYPE_ID_FROMHSC, value4FindingRate);

            if (rate4Manager == null)
            {
                _logger.Error("CalculateManager - rate4OldClient not found. BrokerID=" + brk.Id);
                rate4Manager = new CommissionRate(ClientType.CLIENTTYPE_ID_FROMHSC, Constants.BROKERTYPE_MAN);
            }

            brk.PaymentResult.ManagementBonusRate = rate4Manager.Commissionrate;
            brk.PaymentResult.SupervisorPayment = (revenue * (decimal)rate4Manager.Commissionrate);
            if (brk.AdjustRate != null)
            {
                brk.PaymentResult.SupervisorPayment = (brk.PaymentResult.SupervisorPayment * ((decimal)brk.AdjustRate.AdjustRate));
            }

            brk.PaymentResult.Payment += brk.PaymentResult.SupervisorPayment;

            //_logger.Debug("CalculateManager - LEAVE");
        }
Esempio n. 3
0
        public List<CommissionRate> GetAllCommissionRate()
        {
            List<CommissionRate> retData = new List<CommissionRate>();
            string query = @"SELECT [ID], [ClientTypeID], [Code], [LowerLimit], [UpperLimit], 
                                [CommissionRate]  
                            FROM [CommissionRate] 
                            ORDER BY [Code], [ClientTypeID], [LowerLimit]";
            DataSet dataSet = DataAccess.ExecuteQuery(query);

            if ((dataSet != null) && (dataSet.Tables.Count > 0) && (dataSet.Tables[0].Rows.Count > 0))
            {
                for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                {
                    // ClientType 
                    CommissionRate rate = new CommissionRate();

                    rate.ClientTypeId = Int32.Parse(dataSet.Tables[0].Rows[i][1].ToString());
                    rate.Code = dataSet.Tables[0].Rows[i][2].ToString();
                    if (dataSet.Tables[0].Rows[i][3] != DBNull.Value)
                    {
                        rate.LowerLimit = (long)dataSet.Tables[0].Rows[i][3];
                    }

                    if (dataSet.Tables[0].Rows[i][4] != DBNull.Value)
                    {
                        rate.UpperLimit = (long)dataSet.Tables[0].Rows[i][4];
                    }

                    if (dataSet.Tables[0].Rows[i][5] != DBNull.Value)
                    {
                        rate.Commissionrate = (double)dataSet.Tables[0].Rows[i][5];
                    }

                    retData.Add(rate);
                }
            }

            return retData;
        }