Esempio n. 1
0
        //public ExigoApiServices api
        //{
        //    get
        //    {
        //        if (_api == null)
        //        {
        //            _api = new ExigoApiServices();
        //        }
        //        return _api;
        //    }
        //}
        #endregion

        public Node GetCustomerData(Node customerNode)
        {
            var context = ExigoApiContext.CreateODataContext();
            var cQuery = (from c in context.Customers
                          where c.CustomerID == customerNode.CustomerID
                          select new
                          {
                              c.FirstName,
                              c.LastName,
                              c.SponsorID,
                              c.EnrollerID,
                              c.CustomerTypeID,
                              c.CustomerStatusID,
                              c.RankID,
                              c.CreatedDate,
                          }).FirstOrDefault();

            customerNode.FirstName = cQuery.FirstName;
            customerNode.LastName = cQuery.LastName;
            customerNode.SponsorID = (int)cQuery.SponsorID;
            customerNode.EnrollerID = (int)cQuery.EnrollerID;
            customerNode.CustomerType = cQuery.CustomerTypeID;
            customerNode.RankID = cQuery.RankID;
            customerNode.CreatedDate = cQuery.CreatedDate;
            customerNode.CustomerStatus = cQuery.CustomerStatusID;

            return customerNode;

        }
Esempio n. 2
0
        public List<string[]> IsOrderQualifiedMEC(List<Order> orders, int toCustomer, Node fromCustomer)
        {
            List<string[]> qualified = new List<string[]>();
            string[] order;

            if (orders.Count() > 0)
            {
                if (toCustomer == fromCustomer.EnrollerID)
                {
                    foreach (Order o in orders)
                    {
                        order = new string[] { "Monthly Enroller Bonus", o.OrderID.ToString(), "", "First Level Order" };
                        qualified.Add(order);
                    }
                }
                else
                {
                    foreach (Order o in orders)
                    {
                        order = new string[] { "Monthly Enroller Bonus", o.OrderID.ToString(), string.Format("{0:N}", o.BusinessVolumeTotal), "No Volume" };
                        qualified.Add(order);
                    }
                }
            }
            else
            {
                order = new string[] { "Monthly Enroller Bonus", "No Order", "", "No Volume" };
                qualified.Add(order);
            }

            return qualified;
        }
Esempio n. 3
0
        public bool IsNode60PCV(List<Order> orders, Node customerNode)
        {
            bool Active = false;
            customerNode.PCV = 0;

            foreach (Order o in orders)
            {
                customerNode.PCV += o.BusinessVolumeTotal;
            }

            if (customerNode.PCV >= 60) Active = true;

            return Active;
        }
Esempio n. 4
0
        public Node GetReasonsNotPaying(Node customerNode, string toID, int periodID, int periodType)
        {
            //Grab the customer data for this node
            customerNode = GetCustomerData(customerNode);

            List<string[]> reasonsNotQualified = new List<string[]>();
            string[] reason;
            //Get the orders of the person 
            List<Order> periodOrders = GetListOfQualifiedOrders(periodID, periodType, Convert.ToInt32(customerNode.CustomerID));


            //Check if active customer status
            if (customerNode.CustomerStatus != 1)
            {
                reason = new string[] { "Customer Status", "Not Active" };
                reasonsNotQualified.Add(reason);
            }

            //check if meeting 60PCV qualification
            if (IsNode60PCV(periodOrders, customerNode))
            {
                customerNode.Active = true;
            }
            else
            {
                customerNode.Active = false;
                reason = new string[] { "PCV", string.Format("{0:N}", customerNode.PCV) };
                reasonsNotQualified.Add(reason);
            }

            //check if any orders exist
            if (periodOrders.Count() > 0)
            {
                //check each bonus against the list of orders to see why they didn't pay out
                switch (periodType)
                {
                    case 1: foreach (var i in weeklyBonuses)
                        {
                            reasonsNotQualified = TryOrdersQualifiedForBonus(i, periodOrders, Convert.ToInt32(toID), customerNode, reasonsNotQualified);
                        }
                        break;
                    case 2: foreach (var i in monthlyBonuses)
                        {
                            reasonsNotQualified = TryOrdersQualifiedForBonus(i, periodOrders, Convert.ToInt32(toID), customerNode, reasonsNotQualified);
                        }
                        break;
                    case 3: foreach (var i in quarterlyBonuses)
                        {
                            reasonsNotQualified = TryOrdersQualifiedForBonus(i, periodOrders, Convert.ToInt32(toID), customerNode, reasonsNotQualified);
                        }
                        break;
                    case 4: break;
                }
            }
            else
            {
                reason = new string[] { "Inactive", "No Qualifying Orders" };
                reasonsNotQualified.Add(reason);
            }

            customerNode.reasonsNotQualified = reasonsNotQualified;

            return customerNode;
        }
Esempio n. 5
0
        public List<string[]> TryOrdersQualifiedForBonus(string bonusCode, List<Order> orders, int toCustomerID, Node fromCustomer, List<string[]> qualificationStatus)
        {
            switch (bonusCode)
            {
                case "active": foreach (Order o in orders)
                    {
                        fromCustomer.PCV += o.BusinessVolumeTotal;

                        if (fromCustomer.PCV >= 60)
                        {
                            fromCustomer.Active = true;
                        }
                    }
                    break;
                case "htc": foreach (Order o in orders)
                    {
                        string[] qualified = IsOrderQualifiedHTC(o);
                        if (qualified.Length > 0)
                        {
                            for (int i = 0; i < qualified.Length; i++)
                            {
                                qualificationStatus.Add(qualified);
                            }
                        }
                        else
                        {
                            qualified = new string[] { "Home Transaction Credit", o.OrderID.ToString(), "Not qualified" };
                            qualificationStatus.Add(qualified);
                        }
                    }
                    break;
                case "rc": foreach (Order o in orders)
                    {
                        string[] qualified = IsOrderQualifiedRC(o);
                        if (qualified.Length > 0)
                        {
                            for (int i = 0; i < qualified.Length; i++)
                            {
                                qualificationStatus.Add(qualified);
                            }
                        }
                        else
                        {
                            qualified = new string[] { "Retail Commission", o.OrderID.ToString(), string.Format("{0:N0}", o.Other1Total), "No Retail Value" };
                            qualificationStatus.Add(qualified);
                        }
                    }
                    break;
                case "wtb": 
                    List<string[]> tierQualified = IsOrderQualifiedWTB(orders, toCustomerID, fromCustomer);
                    if (tierQualified.Count() > 0)
                    {
                        foreach (var o in tierQualified)
                        {
                            qualificationStatus.Add(o);
                        }
                    }
                    else
                    {
                        string[] noOrder = new string[] { "Weekly Tier Bonus", "No Orders", "Not Qualified" };
                        qualificationStatus.Add(noOrder);
                    }
                    break;
                case "wec":
                    List<string[]> wecQualified = IsOrderQualifiedWEC(orders, toCustomerID, fromCustomer);
                    if (wecQualified.Count() > 0)
                    {
                        foreach (var o in wecQualified)
                        {
                            qualificationStatus.Add(o);
                        }
                    }
                    else
                    {
                        string[] noOrder = new string[] { "Weekly Enroller Bonus", "No Orders", "Not Qualified" };
                        qualificationStatus.Add(noOrder);
                    }
                    break;
                case "mec": 
                    List<string[]> mecQualified = IsOrderQualifiedMEC(orders, toCustomerID, fromCustomer);
                    if (mecQualified.Count() > 0)
                    {
                        foreach (var o in mecQualified)
                        {
                            qualificationStatus.Add(o);
                        }
                    }
                    else
                    {
                        string[] noOrder = new string[] { "Weekly Enroller Bonus", "No Orders", "Not Qualified" };
                        qualificationStatus.Add(noOrder);
                    }
                    break;
                case "mtb": break;
                case "smb": break;
                case "reb": break;
                case "bbp": break;
            }

            return qualificationStatus;
        }
Esempio n. 6
0
        public List<Node> GetUnilevelDownlineTreeAndIfPaid(string topUnilevelID, int level, int period, int periodTypeID)
        {
            List<Node> unilevelDownline = new List<Node>();

            int skipCounter = 0;
            int takeCounter = 50;

            while (takeCounter == 50)
            {
                var context = ExigoApiContext.CreateODataContext();
                var query = (from c in context.UniLevelTreePeriodVolumes
                             where c.TopCustomerID == Convert.ToInt32(topUnilevelID)
                             where c.Level == level
                             where c.PeriodID == period
                             where c.PeriodTypeID == periodTypeID
                             select new
                             {
                                 c.CustomerID,
                                 c.SponsorID,
                                 c.Customer.EnrollerID,
                                 c.Customer.CustomerTypeID,
                                 c.Customer.CustomerStatusID,
                                 c.PeriodVolume.PaidRankID,
                                 c.Customer.FirstName,
                                 c.Customer.LastName,
                                 c.Customer.CreatedDate
                             }).Skip(skipCounter).Take(50);

                skipCounter += takeCounter;
                takeCounter = query.Count();

                if (query.Count() > 0)
                {
                    int nodeID = 0;
                    foreach (var c in query)
                    {
                        Node node = new Node()
                        {
                            CustomerID = c.CustomerID,
                            NodeID = nodeID,
                            ParentID = c.SponsorID,
                            CustomerType = c.CustomerTypeID,
                            CustomerStatus = c.CustomerStatusID,
                            PayRankID = c.PaidRankID,
                            FirstName = c.FirstName,
                            LastName = c.LastName,
                            CreatedDate = c.CreatedDate
                        };

                        node.IsPayingOutThisPeriod = IsIDPayingInPeriod(c.CustomerID, Convert.ToInt32(topUnilevelID), period);

                        unilevelDownline.Add(node);
                        nodeID++;
                    }
                }
            }

            return unilevelDownline;
        }
Esempio n. 7
0
        public Node GetCommissionsPaidToPersonFromIDInPreviousPeriod(string fromCustomerID, string toCustomerID, int periodID)
        {
            Node customerNode = new Node();
            List<NodeCommissions> comms = new List<NodeCommissions>();

            var context = ExigoApiContext.CreateODataContext();
            var commissionsQuery = (from c in context.CommissionDetails
                                    where c.FromCustomerID == Convert.ToInt32(fromCustomerID)
                                    where c.CustomerID == Convert.ToInt32(toCustomerID)
                                    where c.CommissionRun.PeriodID == periodID
                                    select new
                                    {
                                        c.Bonus.BonusDescription,
                                        c.OrderID,
                                        c.SourceAmount,
                                        c.Percentage,
                                        c.CommissionAmount,
                                        c.FromCustomer.FirstName,
                                        c.FromCustomer.LastName,
                                        c.FromCustomer.CreatedDate
                                    });

            if (commissionsQuery.Count() > 0)
            {
                foreach (var cq in commissionsQuery)
                {
                    if (customerNode.CustomerID != 0)
                    {
                        customerNode.CustomerID = Convert.ToInt32(fromCustomerID);
                        customerNode.FirstName = cq.FirstName;
                        customerNode.LastName = cq.LastName;
                    }
                    
                    NodeCommissions comm = new NodeCommissions()
                    {
                        BonusAmount = cq.CommissionAmount,
                        BonusType = cq.BonusDescription,
                        PercentagePaid = cq.Percentage
                    };
                    comms.Add(comm);
                }
                customerNode.BonusDetails = comms.ToArray();
            }

            return customerNode;
        }