Example #1
0
        private ManagerL4 AddToQl4Tree(long calcAccountId)
        {
            // Get level and level_index
            var lastestChild = (ManagerL4)m_PersistenceManager.GetQlLatestChild <ManagerL4>();

            // Find Parent account
            if (lastestChild == null)
            {
                var root = new ManagerL4
                {
                    AccountId   = calcAccountId,
                    ChildIndex  = 0,
                    Level       = 0,
                    LevelIndex  = 0,
                    IsActive    = "Y",
                    ParentId    = -1,
                    CreatedBy   = "JOB",
                    CreatedDate = DateTime.Now
                };
                m_PersistenceManager.Save(root);
                return(root);
            }
            else
            {
                var newLevel      = lastestChild.Level;
                var newLevelIndex = lastestChild.LevelIndex + 1;

                if (Math.Pow(3, lastestChild.Level) == lastestChild.LevelIndex)
                {
                    newLevel      = lastestChild.Level + 1;
                    newLevelIndex = 1;
                }

                var parentLevel      = newLevel - 1;
                var parentLevelIndex = (newLevelIndex % 3 > 0) ? ((newLevelIndex / 3) + 1) : (newLevelIndex / 3);

                var managerParent = (ManagerL4)m_PersistenceManager.FindQlByLocation <ManagerL4>(parentLevel, parentLevelIndex);

                // Insert into QL4 tree
                var newNode = new ManagerL4
                {
                    AccountId   = calcAccountId,
                    ChildIndex  = (newLevelIndex % 3) == 0 ? 3 : newLevelIndex % 3,
                    Level       = newLevel,
                    LevelIndex  = newLevelIndex,
                    IsActive    = "Y",
                    ParentId    = managerParent.AccountId,
                    CreatedBy   = "JOB",
                    CreatedDate = DateTime.Now
                };
                m_PersistenceManager.Save(newNode);

                return(newNode);
            }
        }
Example #2
0
        private void CalculateBonusOfQl4(ManagerL4 newManager)
        {
            // Hoa hong quan ly
            m_PersistenceManager.SaveAccountBonus(newManager.ParentId, ConstUtil.BONUS_TYPE_QL4.Amount,
                                                  ConstUtil.BONUS_TYPE_QL4.Type);

            var       firstUpLevel  = (ManagerL4)m_PersistenceManager.GetManagerLevel <ManagerL4>(newManager.ParentId);
            ManagerL4 secondUpLevel = null;

            if (firstUpLevel != null && firstUpLevel.Level != 0)
            {
                m_PersistenceManager.SaveAccountBonus(firstUpLevel.ParentId, ConstUtil.BONUS_TYPE_QL4.Amount,
                                                      ConstUtil.BONUS_TYPE_QL4.Type);
                secondUpLevel = (ManagerL4)m_PersistenceManager.GetManagerLevel <ManagerL4>(firstUpLevel.ParentId);
                if (secondUpLevel != null && secondUpLevel.Level != 0)
                {
                    m_PersistenceManager.SaveAccountBonus(secondUpLevel.ParentId, ConstUtil.BONUS_TYPE_QL4.Amount,
                                                          ConstUtil.BONUS_TYPE_QL4.Type);
                }
            }

            // Can cap
            if ((newManager.LevelIndex % 3) != 1)
            {
                m_PersistenceManager.SaveAccountBonus(newManager.ParentId, ConstUtil.BONUS_TYPE_CCL4.Amount,
                                                      ConstUtil.BONUS_TYPE_CCL4.Type);
                if (firstUpLevel != null && firstUpLevel.ParentId != -1)
                {
                    m_PersistenceManager.SaveAccountBonus(firstUpLevel.ParentId, ConstUtil.BONUS_TYPE_CCL4.Amount,
                                                          ConstUtil.BONUS_TYPE_CCL4.Type);
                    if (secondUpLevel != null && secondUpLevel.Level != 0)
                    {
                        m_PersistenceManager.SaveAccountBonus(secondUpLevel.ParentId, ConstUtil.BONUS_TYPE_CCL4.Amount,
                                                              ConstUtil.BONUS_TYPE_CCL4.Type);
                    }
                }
            }

            // move to QL5 approved queue
            if (newManager.LevelIndex % 27 == 0)
            {
                if (secondUpLevel != null && secondUpLevel.ParentId != -1)
                {
                    InsertToQlApproveQueue(secondUpLevel.ParentId, 5);
                }
            }
        }