Exemple #1
0
        public virtual async Task MoveAsync(long id, long?parentId, int coaId)
        {
            var accountUnit = await AccountUnitRepository.GetAsync(id);

            if (accountUnit.ParentId == parentId)
            {
                return;
            }

            //Should find children before Code change
            var children = await FindChildrenAsync(id, true);

            //Store old code of OU
            var oldCode = accountUnit.Code;

            //Move OU
            accountUnit.Code = await GetNextChildCodeAsync(parentId, coaId);

            accountUnit.ParentId = parentId;

            await ValidateAccountUnitAsync(accountUnit);

            //Update Children Codes
            foreach (var child in children)
            {
                child.Code = AccountUnit.AppendCode(accountUnit.Code, AccountUnit.GetRelativeCode(child.Code, oldCode));
            }
        }
Exemple #2
0
        public virtual async Task <string> GetNextChildCodeAsync(long?parentId, int coaId)
        {
            var lastChild = await GetLastChildOrNullAsync(parentId, coaId);

            if (lastChild != null)
            {
                return(AccountUnit.CalculateNextCode(lastChild.Code));
            }
            var parentCode = parentId != null?GetCode(parentId.Value) : null;

            return(AccountUnit.AppendCode(parentCode, AccountUnit.CreateCode(1)));
        }