private void ProcessSalesBoundGbCommission(SqlConnection con, SqlTransaction tran, List <SalesmanModel> salesmanList)
        {
            foreach (var salesman in salesmanList)
            {
                double salesAmount = _salesman.GetSalesAmount(salesman.CompanyCode, code: salesman.Code);
                if (salesman.IsAlphaMember)
                {
                    double inboundCommissionPercent = _policy.InboundCommissionPercentage(salesAmount);
                    double inboundCommission        = salesAmount * inboundCommissionPercent / 100;
                    _salary.AddInboundCommission(con, tran, salesman.CompanyCode, salesman.Code, inboundCommission);
                }
                if (salesman.IsBetaMember)
                {
                    double outboundCommissionPercent = _policy.OutboundCommissionPercentage(salesAmount);
                    double outboundCommission        = salesAmount * outboundCommissionPercent / 100;
                    _salary.AddOutboundCommission(con, tran, salesman.CompanyCode, salesman.Code, outboundCommission);
                }
                ProcessSalesCommission(con, tran, salesman, salesAmount);
                ProcessGbCommission(con, tran, salesman, salesAmount);
                var associates = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code);
                ProcessSalesBoundGbCommission(con, tran, associates);

                salesman.Designation = _policy.NextDesignation(salesman.CompanyCode, salesman.Code);
                _salesman.Update(con, tran, salesman);
            }
        }
Esempio n. 2
0
        public bool IsEligibleForOrdinalCommission(SalesmanModel salesman)
        {
            double personalSale = _salesman.GetSalesAmount(salesman.CompanyCode, code: salesman.Code);

            if (!IsEligible(personalSale))
            {
                return(false);
            }
            double associatesSale = _salesman.GetAssociatesSalesAmount(salesman.CompanyCode, referenceCode: salesman.ReferenceCode);

            switch (salesman.Designation)
            {
            case Designation.C: {
                return(associatesSale >= 16000);
            }

            case Designation.D: {
                if (associatesSale >= 6000)
                {
                    var  associates = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.C);
                    bool isEligible = false;
                    foreach (var associate in associates)
                    {
                        if (isEligible)
                        {
                            return(true);
                        }
                        isEligible = IsEligibleForOrdinalCommission(associate);
                    }
                }
                return(false);
            }

            case Designation.E: {
                if ((personalSale + associatesSale) >= 70000)
                {
                    var associatesB = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.B);
                    int eligibleB   = 0;
                    foreach (var associate in associatesB)
                    {
                        if (eligibleB == 3)
                        {
                            break;
                        }
                        if (IsEligible(_salesman.GetSalesAmount(associate.CompanyCode, code: associate.Code)))
                        {
                            eligibleB++;
                        }
                    }
                    if (eligibleB == 3)
                    {
                        var associatesC = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.C);
                        int eligibleC   = 0;
                        foreach (var associate in associatesC)
                        {
                            if (eligibleC == 3)
                            {
                                break;
                            }
                            if (IsEligibleForOrdinalCommission(associate))
                            {
                                eligibleC++;
                            }
                        }
                        return(eligibleC == 3);
                    }
                }
                return(false);
            }

            case Designation.F: {
                #region Checking B Eligiblity
                var associatesB = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.B);
                int eligibleB   = 0;
                foreach (var associate in associatesB)
                {
                    if (eligibleB == 2)
                    {
                        break;
                    }
                    if (IsEligible(_salesman.GetSalesAmount(salesman.CompanyCode, code: associate.Code)))
                    {
                        eligibleB++;
                    }
                }
                if (eligibleB < 2)
                {
                    return(false);
                }
                #endregion

                #region #region Checking C Eligiblity
                var  associatesC = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.C);
                bool eligibleC   = false;
                foreach (var associate in associatesC)
                {
                    if (eligibleC)
                    {
                        break;
                    }
                    if (IsEligibleForOrdinalCommission(associate))
                    {
                        eligibleC = true;
                    }
                }
                if (!eligibleC)
                {
                    return(false);
                }
                #endregion

                #region #region Checking E Eligiblity
                var associatesE = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.E);
                int eligibleE   = 0;
                foreach (var associate in associatesE)
                {
                    if (eligibleE == 2)
                    {
                        break;
                    }
                    if (IsEligibleForOrdinalCommission(associate))
                    {
                        eligibleE++;
                    }
                }
                return(eligibleE >= 2);

                #endregion
            }

            case Designation.G: {
                var associatesE = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.E);
                int eligibleE   = 0;
                foreach (var associate in associatesE)
                {
                    if (eligibleE == 4)
                    {
                        break;
                    }
                    if (IsEligibleForOrdinalCommission(associate))
                    {
                        eligibleE++;
                    }
                }
                return(eligibleE >= 4);
            }

            case Designation.H: {
                var associatesE = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.E);
                int eligibleE   = 0;
                foreach (var associate in associatesE)
                {
                    if (eligibleE == 6)
                    {
                        break;
                    }
                    if (IsEligibleForOrdinalCommission(associate))
                    {
                        eligibleE++;
                    }
                }
                return(eligibleE >= 6);
            }

            case Designation.I: {
                var associatesH = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.H);
                int eligibleH   = 0;
                foreach (var associate in associatesH)
                {
                    if (eligibleH == 6)
                    {
                        break;
                    }
                    if (IsEligibleForOrdinalCommission(associate))
                    {
                        eligibleH++;
                    }
                }
                return(eligibleH >= 6);
            }

            case Designation.J: {
                var associatesI = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.I);
                int eligibleI   = 0;
                foreach (var associate in associatesI)
                {
                    if (eligibleI == 3)
                    {
                        break;
                    }
                    if (IsEligibleForOrdinalCommission(associate))
                    {
                        eligibleI++;
                    }
                }
                return(eligibleI >= 3);
            }

            case Designation.K: {
                var associatesJ = _salesman.GetAssociates(salesman.CompanyCode, salesman.Code, (int)Designation.J);
                int eligibleJ   = 0;
                foreach (var associate in associatesJ)
                {
                    if (eligibleJ == 2)
                    {
                        break;
                    }
                    if (IsEligibleForOrdinalCommission(associate))
                    {
                        eligibleJ++;
                    }
                }
                return(eligibleJ >= 2);
            }

            default:
                return(false);
            }
        }