public WeeklySummaryCollection Confirm(int confirmUserID, int entityID)
        {
            User _confirmUser = (new UserAccessClient(EndpointName.UserAccess)).QueryuserID(confirmUserID)[0];

            WeeklySummaryCollection _confirm = new WeeklySummaryCollection();

            Entity _entity = EntityService.Instance.LoadEntity(entityID)[0];

            if ((_entity.SumType != SumType.Transaction) && (_entity.SumType != SumType.Subtotal))
            {
                return _confirm;
            }

            _entity.SubEntities = ((_entity.SumType == SumType.Transaction) ? SetSubtotal(_entity.SubEntities, new WeeklySummaryCollection()) : SetLastLevel(_entity.SubEntities, new WeeklySummaryCollection()));

            ConfirmTransfer(new EntityCollection(new Entity[] { _entity }), _confirm);

            if (_confirm.Count <= 0)
            {
                return _confirm;
            }

            foreach (WeeklySummary _weeklySummary in _confirm)
            {
                _weeklySummary.Status = WeeklySummaryStatus.Confirm;
                _weeklySummary.ConfirmUser = _confirmUser;
            }

            using (WeeklySummaryAccessClient _weeklySummaryAccessClient = new WeeklySummaryAccessClient(EndpointName.WeeklySummaryAccess))
            {
                _weeklySummaryAccessClient.Update2(_confirm.ToArray());
            }

            //<EntityID, RecordID>
            Dictionary<int, int> _pairs = new Dictionary<int, int>();

            foreach (WeeklySummary _weeklySummary in _confirm)
            {
                int _recordID = -1;

                using (RecordAccessClient _recordAccessClient = new RecordAccessClient(EndpointName.RecordAccess))
                {
                    _pairs[_weeklySummary.Entity.EntityID] = (_recordID = _recordAccessClient.QueryRecordID(_weeklySummary.Entity.EntityID, PeriodService.Instance.GetCurrentPeriod()[0].ID));
                }

                if (_recordID > 0)
                {
                    if (_pairs.Values.Count(RecordID => (RecordID == _recordID)) == 1)
                    {
                        using (RecordAccessClient _recordAccessClient = new RecordAccessClient(EndpointName.RecordAccess))
                        {
                            _recordAccessClient.ChangeStatus(_recordID, RecordStatus.Confirm);
                        }
                    }
                }
            }

            foreach (KeyValuePair<int, int> _pair in _pairs)
            {
                if (_pair.Value > 0)
                {
                    continue;
                }

                Entity _subtotal = null;

                if (_entity.SumType == SumType.Transaction)
                {
                    if ((_subtotal = _entity.SubEntities.FirstOrDefault(Entity => (_pair.Key == Entity.EntityID))) == null)
                    {
                        continue;
                    }
                }
                else if (_pair.Key == _entity.EntityID)
                {
                    _subtotal = _entity;
                }
                else
                {
                    continue;
                }

                EntityCollection _entityCollection = new EntityCollection() { _subtotal };

                _entityCollection.AddRange(_subtotal.SubEntities);

                decimal[] _baseTransfer = new decimal[_entityCollection.Count];

                for (int i = 1; i < _entityCollection.Count; i++)
                {
                    _baseTransfer[i] = _confirm.FirstOrDefault(WeeklySummary => (WeeklySummary.Entity.EntityID == _entityCollection[i].EntityID)).BaseTransfer;
                }

                Transfer _transfer = CalculateService.Instance.Transfer(confirmUserID, _entityCollection, _baseTransfer).Item1;

                DataEntryService.Instance.InsertTransfer(_transfer.RecordNotInDB, _transfer);
            }

            return _confirm;
        }
        public Tuple<EntityCollection, WeeklySummaryCollection> LoadPAndLEntity(int entityID)
        {
            EntityCollection _entityTree = EntityService.Instance.LoadEntity();
            WeeklySummaryCollection _weeklySummaryCollection = new WeeklySummaryCollection();

            _entityTree.RemoveAll(Entity => ((Entity.EntityID != entityID) && (Entity.ParentID == 0)));

            foreach (Entity _entity in _entityTree)
            {
                _entity.SubEntities = SetTransaction(_entity.SubEntities, _weeklySummaryCollection);

                WeeklySummaryCollection _transferButNotSave = new WeeklySummaryCollection();

                ConfirmTransfer(_entity.SubEntities, _transferButNotSave);

                for (int i = 0; i < _weeklySummaryCollection.Count; i++)
                {
                    WeeklySummary _transfer = _transferButNotSave.FirstOrDefault(WeeklySummary => (WeeklySummary.Entity.EntityID == _weeklySummaryCollection[i].Entity.EntityID));

                    if (_transfer == null)
                    {
                        continue;
                    }

                    _weeklySummaryCollection[i] = _transfer;
                }
            }

            return new Tuple<EntityCollection, WeeklySummaryCollection>(_entityTree, _weeklySummaryCollection);
        }