private ManagerL2 AddToQl2Tree(long calcAccountId) { // Get level and level_index var lastestChild = (ManagerL2)m_PersistenceManager.GetQlLatestChild <ManagerL2>(); // Find Parent account if (lastestChild == null) { var root = new ManagerL2 { 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 ((lastestChild.Level == 0) || (Math.Pow(3, lastestChild.Level) == lastestChild.LevelIndex)) { newLevel = lastestChild.Level + 1; newLevelIndex = 1; } var l1ParentLevel = newLevel - 1; var l1ParentLevelIndex = (newLevelIndex % 3 > 0) ? ((newLevelIndex / 3) + 1) : (newLevelIndex / 3); if (newLevel == 1) { l1ParentLevel = 0; l1ParentLevelIndex = 0; } var managerParent = (ManagerL2)m_PersistenceManager.FindQlByLocation <ManagerL2>(l1ParentLevel, l1ParentLevelIndex); // Insert into QL2 tree var newNode = new ManagerL2 { 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); } }
private void CalculateBonusOfQl2(ManagerL2 newManager) { // Hoa hong quan ly m_PersistenceManager.SaveAccountBonus(newManager.ParentId, ConstUtil.BONUS_TYPE_QL2.Amount, ConstUtil.BONUS_TYPE_QL2.Type); var firstUpLevel = (ManagerL2)m_PersistenceManager.GetManagerLevel <ManagerL2>(newManager.ParentId); ManagerL2 secondUpLevel = null; if (firstUpLevel != null && firstUpLevel.Level != 0) { m_PersistenceManager.SaveAccountBonus(firstUpLevel.ParentId, ConstUtil.BONUS_TYPE_QL2.Amount, ConstUtil.BONUS_TYPE_QL2.Type); secondUpLevel = (ManagerL2)m_PersistenceManager.GetManagerLevel <ManagerL2>(firstUpLevel.ParentId); if (secondUpLevel != null && secondUpLevel.Level != 0) { m_PersistenceManager.SaveAccountBonus(secondUpLevel.ParentId, ConstUtil.BONUS_TYPE_QL2.Amount, ConstUtil.BONUS_TYPE_QL2.Type); } } // Can cap if ((newManager.LevelIndex % 3) != 1) { m_PersistenceManager.SaveAccountBonus(newManager.ParentId, ConstUtil.BONUS_TYPE_CCL2.Amount, ConstUtil.BONUS_TYPE_CCL2.Type); if (firstUpLevel != null && firstUpLevel.ParentId != -1) { m_PersistenceManager.SaveAccountBonus(firstUpLevel.ParentId, ConstUtil.BONUS_TYPE_CCL2.Amount, ConstUtil.BONUS_TYPE_CCL2.Type); if (secondUpLevel != null && secondUpLevel.Level != 0) { m_PersistenceManager.SaveAccountBonus(secondUpLevel.ParentId, ConstUtil.BONUS_TYPE_CCL2.Amount, ConstUtil.BONUS_TYPE_CCL2.Type); } } } // move to QL3 approved queue if (newManager.LevelIndex % 27 == 0) { if (secondUpLevel != null && secondUpLevel.ParentId != -1) { InsertToQlApproveQueue(secondUpLevel.ParentId, 3); } } }