使用金额阈值计算佣金

时间:2016-09-15 11:56:48

标签: c#

我对销售的不同佣金有不同的模式。从0到10.000欧元,它支付2%的佣金,从10.001到20.000佣金是2.5%,20.001到30.000是收款人佣金3%,所以直到佣金为5%或更多。阈值金额和佣金是从列表中的数据库中获取的。问题是,我必须考虑自年初以来的销售额,以达到给定的门槛,但只计算当月销售的佣金。例如,如果给定月份的销售额为30.000且年初的累计销售额为8.000,则计算结果为:2.000%2%,10.000%2.5%,10.000%3%和8.000%3.5%,结果为这是我的代码,但不能正常工作。任何帮助,将不胜感激。提前谢谢。

            foreach (var bound in fxCollection)
            {
                if (antAmount < bound.FinalAmount)
                {
                    if (antAmount >= bound.InitialAmount && antAmount <= bound.FinalAmount)
                    {
                        if (totalAmount > bound.FinalAmount)
                        {
                            totalAmountCardSchema = totalPeriod - (bound.FinalAmount.Value - antAmount);
                            totalCommission += (bound.FinalAmount.Value - antAmount) * (bound.Commission / 100);
                        }
                        else
                        {
                            totalCommission += totalPeriod * (bound.Commission / 100);
                            totalCommission = 0;
                        }
                    }
                    else
                    {
                        if ((bound.FinalAmount - bound.InitialAmount) < totalAmountCardSchema)
                        {
                            if (index == count) //last loop
                            {
                                totalCommission += totalAmountCardSchema * (bound.Commission / 100);
                                totalAmountCardSchema = 0;
                            }
                            else
                            {
                                totalCommission += (bound.FinalAmount.Value - bound.InitialAmount.Value) * (bound.Commission / 100);
                                totalAmountCardSchema = totalAmountCardSchema - (bound.FinalAmount.Value - bound.InitialAmount.Value);
                            }
                        }
                        else if (totalAmountCardSchema > 0)
                        {
                            totalCommission += totalAmountCardSchema * (bound.Commission / 100);
                            totalAmountCardSchema = 0;
                        }
                    }
                }
                index++;
                var valueInvoiceLine = totalCommission;

澄清: 是的,这就是重点。在这个例子中很好。澄清一下,1月1日至5月31日的销售额为8.000,一个月的销售额为30.000。我把这个例子放在一个因为我想在几个频段中循环来计算当月的佣金但是为了实现第一个频段来计算本月的初始频段,我必须添加自今年第一天以来的销售额。在示例中,第一个乐队是从0到10.000,但我必须添加一年中第一天的销售额(8.000),然后是当月销售额(30.000),我必须在第一个乐队中只需要2.000 ,在第二个乐队中,我必须花费10.000,在第三个乐队中,我必须再拿10.000,在第四个乐队中,我必须采取其余的(8.000)。对不起,如果不是很清楚。我希望你理解。非常感谢你。

1 个答案:

答案 0 :(得分:1)

尝试这样的事情

            decimal totalAmount = 35;
            decimal commission = 0.0M;
            decimal commissionAmount = 0.0M;

            Dictionary<decimal,decimal> commissions = new Dictionary<decimal,decimal>() {
                { 0, .02M}, ///2%
                { 10, .005M}, //2.5%
                { 20, .005M}, //3.0%
                { 30, .005M}, //3.5%
                { 40, .005M}, //4.0%
                { 50, .005M}, //4.5%
                { 60, .005M}, //5.0%
            };

            foreach (decimal key in commissions.Keys)
            {
                if (totalAmount > key)
                {
                    commissionAmount = totalAmount - key;
                }
                else
                {
                    commissionAmount = totalAmount - key < 0 ? 0 : totalAmount - key;
                }
                commission += commissionAmount * commissions[key];
            }
相关问题