public void Insert(WeeklySummaryCollection weeklySummaryCollection)
 {
     foreach (WeeklySummary _week in weeklySummaryCollection)
     {
         Insert(_week);
     }
 }
        public bool IsWeeklyConfirm(int periodID, int entityID)
        {
            WeeklySummaryCollection collection = new WeeklySummaryCollection();
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand();
                command.Connection = connection;
                command.CommandText = "SP_SEL_Table";
                SqlParameter _param = command.Parameters.Add("@value1", System.Data.SqlDbType.VarChar);
                _param.Value = "Weekly_Summary";
                SqlParameter _param2 = command.Parameters.Add("@value2", System.Data.SqlDbType.VarChar);
                _param2.Value = "1,2";
                SqlParameter _param3 = command.Parameters.Add("@value3", System.Data.SqlDbType.VarChar);
                _param3.Value = periodID + "," + entityID;
                SqlParameter _param4 = command.Parameters.Add("@order_by1", System.Data.SqlDbType.VarChar);
                _param4.Value = "1";
                SqlParameter _param5 = command.Parameters.Add("@order_by2", System.Data.SqlDbType.TinyInt);
                _param5.Value = 0;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        WeeklySummary _week = new WeeklySummary();
                        PeriodAccess _perioda = new PeriodAccess();
                        _week.Period = new PeriodCollection(_perioda.Query(Convert.ToInt32(reader["Period_ID"])))[0]; //_periodc[0];

                        EntityAccess _entity = new EntityAccess();
                        _week.Entity = new EntityCollection(_entity.Query(Convert.ToInt32(reader["Entity_Id"])))[0];
                        _week.BaseCurrency = reader["Base_Currency"].ToString();
                        _week.ExchangeRate = Convert.ToDecimal(reader["Exchange_Rate"].ToString());
                        _week.BasePrevBalance = Convert.ToDecimal(reader["Base_Prev_Balance"].ToString());
                        _week.SGDPrevBalance = Convert.ToDecimal(reader["SGD_Prev_Balance"].ToString());
                        _week.BaseWinAndLoss = Convert.ToDecimal(reader["Base_Win_Lose"].ToString());
                        _week.SGDWinAndLoss = Convert.ToDecimal(reader["SGD_Win_Lose"].ToString());
                        _week.BaseTransfer = Convert.ToDecimal(reader["Base_Transfer"].ToString());
                        _week.SGDTransfer = Convert.ToDecimal(reader["SGD_Transfer"].ToString());
                        _week.BaseTransaction = Convert.ToDecimal(reader["Base_Transaction"].ToString());
                        _week.SGDTransaction = Convert.ToDecimal(reader["SGD_Transaction"].ToString());
                        _week.BaseBalance = Convert.ToDecimal(reader["Base_Balance"].ToString());
                        _week.SGDBalance = Convert.ToDecimal(reader["SGD_Balance"].ToString());
                        _week.Status = (WeeklySummaryStatus)Convert.ToInt32(reader["Status"].ToString());
                        string userinfo = reader["Confirm_User"].ToString();
                        try
                        {
                            UserAccess usera = new UserAccess();
                            _week.ConfirmUser = new UserCollection(usera.Query(Convert.ToInt32(reader["Confirm_User"])))[0];
                        }
                        catch
                        {
                            _week.ConfirmUser = new User();
                        }
                        collection.Add(_week);
                    }
                    reader.Close();
                    if (collection.Count > 0)
                    {
                        if (collection[0].ConfirmUser.UserID.Equals(0))
                            return false;
                        else
                            return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    reader.Close();
                    return false;
                }
            }
        }
 public void WinLossConfirm(WeeklySummaryCollection weeklySummaryCollection)
 {
     foreach (WeeklySummary _week in weeklySummaryCollection)
     {
         using (SqlConnection connection = new SqlConnection(connectionString))
         {
             SqlCommand _command = new SqlCommand();
             _command.Connection = connection;
             _command.CommandText = "SP_UPD_Table";
             SqlParameter _param = _command.Parameters.Add("@value1", System.Data.SqlDbType.VarChar);
             _param.Value = "Weekly_Summary";
             SqlParameter _param2 = _command.Parameters.Add("@value2", System.Data.SqlDbType.VarChar);
             _param2.Value = "7,8,10,13,14,15,16";
             StringBuilder _content = new StringBuilder();
             _content.AppendFormat("{0}{1}", _week.BaseTransfer, ",");
             _content.AppendFormat("{0}{1}", _week.SGDTransfer, ",");
             _content.AppendFormat("{0}{1}", _week.BaseBalance, ",");
             _content.AppendFormat("{0}{1}", _week.SGDBalance, ",");
             _content.AppendFormat("{0}{1}", (int)_week.Status, ",");
             _content.AppendFormat("{0}", _week.ConfirmUser.UserID, ",");
             SqlParameter _param3 = _command.Parameters.Add("@value3", System.Data.SqlDbType.VarChar);
             _param3.Value = _content.ToString();
             SqlParameter _param4 = _command.Parameters.Add("@value4", System.Data.SqlDbType.VarChar);
             _param4.Value = "1,2";
             SqlParameter _param5 = _command.Parameters.Add("@value5", System.Data.SqlDbType.VarChar);
             _param5.Value = _week.Period.ID + "," + _week.Entity.EntityID;
             _command.CommandType = System.Data.CommandType.StoredProcedure;
             connection.Open();
             _command.ExecuteNonQuery();
         }
     }
 }
        private void HasWeeklySummary(int entityID)
        {
            WeeklySummaryCollection _wsa;
            using (WeeklySummaryAccessClient _weeklySummaryAccessClient = new WeeklySummaryAccessClient(EndpointName.WeeklySummaryAccess))
            {
                var _period = PeriodService.Instance.GetCurrentPeriod()[0];
                _wsa = new WeeklySummaryCollection(_weeklySummaryAccessClient.Query(_period.ID, entityID));
                if (!_wsa.Any())
                {
                    using (EntityAccessClient _entityAccessClient = new EntityAccessClient(EndpointName.EntityAccess))
                    {
                        var _entity = _entityAccessClient.Query2(entityID)[0];
                        if (_entity.SumType != SumType.Not)
                        {
                            WeeklySummary _newWeeklySummary = new WeeklySummary
                            {
                                Entity = _entity,
                                ExchangeRate = _entity.ExchangeRate,
                                Period = _period,
                                BaseCurrency = _entity.Currency.CurrencyID,
                            };
                            _weeklySummaryAccessClient.Insert1(_newWeeklySummary);
                        }
                    }
                }

            }
        }
 public void Update(WeeklySummaryCollection weeklySummaryCollection)
 {
     foreach (WeeklySummary _week in weeklySummaryCollection)
     {
         Update(_week);
     }
 }
        public void SetConfirm(Transaction transaction)
        {
            using (TransactionAccessClient _tran = new TransactionAccessClient(EndpointName.TransactionAccess))
            {
                SettleService _settle = new SettleService();
                WeeklySummaryCollection _weekco = new WeeklySummaryCollection();
                //From Entity
                WeeklySummary _weekFrom = new WeeklySummary();
                _weekFrom.ExchangeRate = transaction.ExchangeRate;
                _weekFrom.Period = transaction.Period;
                _weekFrom.Entity = transaction.FromEntity;
                _weekFrom.BaseTransaction = -(transaction.Amount);
                _weekFrom.BaseCurrency = transaction.FromCurrency;
                //To Entity
                WeeklySummary _weekTo = new WeeklySummary();
                _weekTo.ExchangeRate = transaction.ExchangeRate;
                _weekTo.Period = transaction.Period;
                _weekTo.Entity = transaction.ToEntity;
                _weekTo.BaseTransaction = transaction.To_Amount;
                _weekTo.BaseCurrency = transaction.ToCurrency;
                _weekco.Add(_weekFrom);
                _weekco.Add(_weekTo);

                _settle.TransactionConfirm(_weekco);

                _tran.SetConfirm(transaction.ID, transaction.Updater.UserID, transaction.Period.ID);
            }
        }
        public Tuple<Transfer, Entity> Transfer(int entryUserID, EntityCollection entityCollection, decimal[] baseTransfer)
        {
            User _user = (new UserAccessClient(EndpointName.UserAccess)).QueryuserID(entryUserID)[0];

            Entity _exchangeDiffEntity = EntityService.Instance.LoadEntity(int.Parse(PropertiesService.Instance.GetPropertyValue(SpecialProperty.ExchangeDiff)[0].PropertyValue))[0];

            WeeklySummaryCollection _weeklySummaryCollection = new WeeklySummaryCollection();

            foreach (Entity _entity in entityCollection)
            {
                _weeklySummaryCollection.AddRange(GetWeeklySummary(_entity.EntityID));
            }

            Record _record = RecordHelper.GenerateTempRecord();

            _record.Type = RecordType.Transfer;

            int _index = 0;

            //Transfer
            Transfer _transfer = new Transfer()
            {
                RecordID = _record.RecordID,
                ToEntity = entityCollection[_index],
                Currency = new Currency() { CurrencyID = _weeklySummaryCollection[_index].BaseCurrency },
                ExchangeRate = _weeklySummaryCollection[_index].ExchangeRate,
                BaseBefore = _weeklySummaryCollection[_index].BaseBalance,
                SGDBefore = _weeklySummaryCollection[_index].SGDBalance,
            };

            foreach (Entity _entity in entityCollection)
            {
                if (_index == 0)
                {
                    _index++;

                    continue;
                }

                TransferDetail _transferDetail = new TransferDetail()
                {
                    RecordID = _record.RecordID,
                    Entity = _entity,
                    BaseCurrency = _weeklySummaryCollection[_index].BaseCurrency,
                    ExchangeRate = _weeklySummaryCollection[_index].ExchangeRate,
                    BaseBefore = _weeklySummaryCollection[_index].BaseBalance,
                    SGDBefore = _weeklySummaryCollection[_index].SGDBalance,
                };

                _transferDetail.BaseTransfer = baseTransfer[_index];
                _transferDetail.SGDTransfer = (_transferDetail.BaseTransfer / _transfer.ExchangeRate).ExtRound();
                _transferDetail.ProfitAndLoss = (_transferDetail.BaseTransfer / _transferDetail.ExchangeRate).ExtRound() - _transferDetail.SGDTransfer;

                _transferDetail.BaseResult = 0;
                _transferDetail.SGDResult = 0;

                _transfer.TransferDetailCollection.Add(_transferDetail);

                _index++;
            }

            _transfer.BaseResult = _transfer.TransferDetailCollection.Sum(x=>x.BaseTransfer)+_transfer.BaseBefore;
            _transfer.SGDResult = (_transfer.BaseResult / _transfer.ExchangeRate).ExtRound();

            //Record
            _index = 0;

            Journal _journal = new Journal()
            {
                RecordID = _record.RecordID,
                EntityID = entityCollection[_index].EntityID,
                BaseCurrency = _transfer.Currency.CurrencyID,
                ExchangeRate = _transfer.ExchangeRate,
                BaseAmount = _transfer.TransferDetailCollection.Sum(TransferDetail => TransferDetail.BaseTransfer),
                SGDAmount = _transfer.TransferDetailCollection.Sum(TransferDetail => TransferDetail.SGDTransfer),
                EntryUser = _user,
            };

            _record.JournalCollection.Add(_journal);

            foreach (Entity _entity in entityCollection)
            {
                if (_index == 0)
                {
                    _index++;

                    continue;
                }

                _journal = new Journal()
                {
                    RecordID = _record.RecordID,
                    EntityID = _entity.EntityID,
                    BaseCurrency = _transfer.TransferDetailCollection[_index - 1].BaseCurrency,
                    ExchangeRate = _transfer.TransferDetailCollection[_index - 1].ExchangeRate,
                    BaseAmount = _transfer.TransferDetailCollection[_index - 1].BaseTransfer * -1,
                    SGDAmount = (_transfer.TransferDetailCollection[_index - 1].SGDTransfer + _transfer.TransferDetailCollection[_index - 1].ProfitAndLoss) * -1,
                    EntryUser = _user,
                };

                _record.JournalCollection.Add(_journal);

                _index++;
            }

            _journal = new Journal()
            {
                RecordID = _record.RecordID,
                EntityID = _exchangeDiffEntity.EntityID,
                SGDAmount = _transfer.TransferDetailCollection.Sum(TransferDetail => TransferDetail.ProfitAndLoss)
            };

            _record.JournalCollection.Add(_journal);

            _transfer.RecordNotInDB = _record;

            return new Tuple<Transfer, Entity>(_transfer, _exchangeDiffEntity);
        }
Ejemplo n.º 8
0
        private EntityCollection SetLastLevel(EntityCollection entityCollection, WeeklySummaryCollection weeklySummaryCollection)
        {
            for (int i = 0; i < entityCollection.Count; i++)
            {
                if (entityCollection[i].IsLastLevel == 1)
                {
                    WeeklySummaryCollection _weeklySummaryCollection = CalculateService.Instance.GetWeeklySummary(entityCollection[i].EntityID);

                    if (_weeklySummaryCollection.Count == 0)
                    {
                        entityCollection.RemoveAt(i--);
                    }
                    else
                    {
                        weeklySummaryCollection.AddRange(_weeklySummaryCollection);
                    }

                    continue;
                }

                EntityCollection _subEntities = entityCollection[i].SubEntities;

                entityCollection.RemoveAt(i);

                if (_subEntities.Count > 0)
                {
                    entityCollection.InsertRange(i, _subEntities);
                }

                i--;
            }

            return entityCollection;
        }
Ejemplo n.º 9
0
        private EntityCollection SetTransaction(EntityCollection entityCollection, WeeklySummaryCollection weeklySummaryCollection)
        {
            for (int i = 0; i < entityCollection.Count; i++)
            {
                if (entityCollection[i].SumType == SumType.Transaction)
                {
                    entityCollection[i].SubEntities = SetSubtotal(entityCollection[i].SubEntities, weeklySummaryCollection);

                    WeeklySummaryCollection _weeklySummaryCollection = CalculateService.Instance.GetWeeklySummary(entityCollection[i].EntityID);

                    if (_weeklySummaryCollection.Count == 0)
                    {
                        WeeklySummary _weeklySummary = new WeeklySummary(PeriodService.Instance.GetCurrentPeriod()[0], entityCollection[i]);

                        using (WeeklySummaryAccessClient _weeklySummaryAccessClient = new WeeklySummaryAccessClient(EndpointName.WeeklySummaryAccess))
                        {
                            _weeklySummaryAccessClient.Insert1(_weeklySummary);
                        }

                        weeklySummaryCollection.Add(_weeklySummary);
                    }
                    else
                    {
                        weeklySummaryCollection.AddRange(_weeklySummaryCollection);
                    }

                    continue;
                }

                EntityCollection _subEntities = entityCollection[i].SubEntities;

                entityCollection.RemoveAt(i);

                if (_subEntities.Count > 0)
                {
                    entityCollection.InsertRange(i, _subEntities);
                }

                i--;
            }

            return entityCollection;
        }
Ejemplo n.º 10
0
        private WeeklySummaryCollection ExcelConfirmTransfer(EntityCollection entityCollection, WeeklySummaryCollection forSave)
        {
            WeeklySummaryCollection _return = new WeeklySummaryCollection();

            foreach (Entity _entity in entityCollection)
            {
                if (_entity.IsLastLevel == 1)
                {
                    WeeklySummaryCollection _lastLevel = forSave;

                    if (_lastLevel.Count == 0)
                    {
                        continue;
                    }

                    forSave.AddRange(_lastLevel);
                    _return.AddRange(_lastLevel);
                }
                else if (_entity.SumType == SumType.Subtotal)
                {
                    WeeklySummaryCollection _lastLevel = ConfirmTransfer(_entity.SubEntities, forSave);

                    WeeklySummary _subtotal = CalculateService.Instance.GetWeeklySummary(_entity.EntityID)[0];

                    if (_subtotal.Status == WeeklySummaryStatus.Confirm)
                    {
                        forSave.Add(_subtotal);
                        _return.Add(_subtotal);

                        continue;
                    }

                    _subtotal.BaseTransfer = _lastLevel.Sum(WeeklySummary => WeeklySummary.BaseWinAndLoss);
                    _subtotal.SGDTransfer = _lastLevel.Sum(WeeklySummary => WeeklySummary.SGDWinAndLoss);

                    _lastLevel.All(lastLevel =>
                    {
                        lastLevel.BaseTransfer = lastLevel.BaseWinAndLoss * -1;
                        lastLevel.SGDTransfer = lastLevel.SGDWinAndLoss * -1;

                        lastLevel.BaseBalance += lastLevel.BasePrevBalance + lastLevel.BaseWinAndLoss + lastLevel.BaseTransfer;
                        lastLevel.SGDBalance += lastLevel.SGDPrevBalance + lastLevel.SGDWinAndLoss + lastLevel.SGDTransfer;

                        return true;
                    });

                    _subtotal.BaseBalance += _subtotal.BasePrevBalance + _subtotal.BaseWinAndLoss + _subtotal.BaseTransfer;
                    _subtotal.SGDBalance += _subtotal.SGDPrevBalance + _subtotal.SGDWinAndLoss + _subtotal.SGDTransfer;

                    forSave.Add(_subtotal);
                    _return.Add(_subtotal);
                }
                else if (_entity.SumType == SumType.Transaction)
                {
                    WeeklySummaryCollection _subtotal = ConfirmTransfer(_entity.SubEntities, forSave);

                    WeeklySummary _transfer = CalculateService.Instance.GetWeeklySummary(_entity.EntityID)[0];

                    if (_transfer.Status == WeeklySummaryStatus.Confirm)
                    {
                        forSave.Add(_transfer);
                        _return.Add(_transfer);

                        continue;
                    }

                    _transfer.BaseTransfer = _subtotal.Sum(WeeklySummary => WeeklySummary.BaseTransfer);
                    _transfer.SGDTransfer = _subtotal.Sum(WeeklySummary => WeeklySummary.SGDTransfer);

                    _subtotal.All(subtotal =>
                    {
                        subtotal.BaseBalance += subtotal.BasePrevBalance + subtotal.BaseWinAndLoss + subtotal.BaseTransfer;
                        subtotal.SGDBalance += subtotal.SGDPrevBalance + subtotal.SGDWinAndLoss + subtotal.SGDTransfer;

                        return true;
                    });

                    _transfer.BaseBalance += _transfer.BasePrevBalance + _transfer.BaseWinAndLoss + _transfer.BaseTransfer;
                    _transfer.SGDBalance += _transfer.SGDPrevBalance + _transfer.SGDWinAndLoss + _transfer.SGDTransfer;

                    forSave.Add(_transfer);
                    _return.Add(_transfer);
                }

                continue;
            }

            return _return;
        }
Ejemplo n.º 11
0
        private WeeklySummaryCollection ConfirmTransfer(EntityCollection entityCollection, WeeklySummaryCollection forSave)
        {
            WeeklySummaryCollection _return = new WeeklySummaryCollection();

            foreach (Entity _entity in entityCollection)
            {
                if (_entity.IsLastLevel == 1)
                {
                    WeeklySummaryCollection _lastLevel = CalculateService.Instance.GetWeeklySummary(_entity.EntityID);

                    if (_lastLevel.Count == 0)
                    {
                        continue;
                    }

                    _lastLevel.All(lastLevel =>
                    {
                        List<decimal> _winAndLoss = DataEntryService.Instance.GetjournalSum(PeriodService.Instance.GetCurrentPeriod()[0].ID, (int)SumType.Subtotal, lastLevel.Entity.EntityID);

                        if (_winAndLoss.Count < 2)
                        {
                            return true;
                        }

                        lastLevel.BaseWinAndLoss = _winAndLoss[0];
                        lastLevel.SGDWinAndLoss = _winAndLoss[1];

                        return true;
                    });

                    forSave.AddRange(_lastLevel);
                    _return.AddRange(_lastLevel);
                }
                else if (_entity.SumType == SumType.Subtotal)
                {
                    WeeklySummaryCollection _lastLevel = ConfirmTransfer(_entity.SubEntities, forSave);

                    WeeklySummary _subtotal = CalculateService.Instance.GetWeeklySummary(_entity.EntityID)[0];

                    _subtotal.BaseWinAndLoss = _lastLevel.Sum(WeeklySummary => WeeklySummary.BaseWinAndLoss);
                    _subtotal.SGDWinAndLoss = _lastLevel.Sum(WeeklySummary => WeeklySummary.SGDWinAndLoss);

                    List<decimal> _transfer = DataEntryService.Instance.GetjournalSum(PeriodService.Instance.GetCurrentPeriod()[0].ID, (int)SumType.Transaction, _subtotal.Entity.EntityID);

                    if (_transfer.Count >= 2)
                    {
                        _subtotal.BaseTransfer = _transfer[0];
                        _subtotal.SGDTransfer = _transfer[1];
                    }

                    _lastLevel.All(lastLevel =>
                        {
                            lastLevel.BaseBalance = lastLevel.BasePrevBalance + lastLevel.BaseWinAndLoss + lastLevel.BaseTransfer;
                            lastLevel.SGDBalance = lastLevel.SGDPrevBalance + lastLevel.SGDWinAndLoss + lastLevel.SGDTransfer;

                            return true;
                        });

                    _subtotal.BaseBalance = _subtotal.BasePrevBalance + _subtotal.BaseWinAndLoss + _subtotal.BaseTransfer;
                    _subtotal.SGDBalance = _subtotal.SGDPrevBalance + _subtotal.SGDWinAndLoss + _subtotal.SGDTransfer;

                    forSave.Add(_subtotal);
                    _return.Add(_subtotal);
                }
                else if (_entity.SumType == SumType.Transaction)
                {
                    WeeklySummaryCollection _subtotal = ConfirmTransfer(_entity.SubEntities, forSave);

                    WeeklySummary _transfer = CalculateService.Instance.GetWeeklySummary(_entity.EntityID)[0];

                    _transfer.BaseWinAndLoss = _subtotal.Sum(WeeklySummary => WeeklySummary.BaseBalance);
                    _transfer.SGDWinAndLoss = _subtotal.Sum(WeeklySummary => WeeklySummary.SGDBalance);

                    _subtotal.All(subtotal =>
                    {
                        //subtotal.BaseBalance = subtotal.BasePrevBalance + subtotal.BaseWinAndLoss + subtotal.BaseTransfer;
                        //subtotal.SGDBalance = subtotal.SGDPrevBalance + subtotal.SGDWinAndLoss + subtotal.SGDTransfer;

                        return true;
                    });

                    _transfer.BaseBalance = _transfer.BasePrevBalance + _transfer.BaseWinAndLoss + _transfer.BaseTransfer;
                    _transfer.SGDBalance = _transfer.SGDPrevBalance + _transfer.SGDWinAndLoss + _transfer.SGDTransfer;

                    forSave.Add(_transfer);
                    _return.Add(_transfer);
                }

                continue;
            }

            return _return;
        }
Ejemplo n.º 12
0
        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;
        }
Ejemplo n.º 13
0
        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);
        }
 protected void Tree_FromEntity_SelectedNodeChanged(object sender, EventArgs e)
 {
     if (Tree_FromEntity.SelectedNode.ImageToolTip.Equals("0"))
         return;
     tx_FromEntity.Text = Tree_FromEntity.SelectedNode.Text;
     lb_FromEntityID.Text = Tree_FromEntity.SelectedNode.Value;
     CalculateServiceClient _client = new CalculateServiceClient();
     WeeklySummary _week = new WeeklySummaryCollection(_client.GetWeeklySummary(Convert.ToInt32(Tree_FromEntity.SelectedNode.Value)))[0];
     lb_FromCurrency.Text = _week.BaseCurrency;
     tx_FromAmount.Text = ((int)_week.BaseBalance).ToString();
     int _toAmount = 0;
     try
     {
         _toAmount =(int)System.Math.Round(_week.BaseBalance * _week.ExchangeRate,1, MidpointRounding.AwayFromZero);
     }
     catch
     {
         //Library.Alert(" Please Check Number ");
         _toAmount = 0;
     }
     tx_Amount.Text = _toAmount.ToString();
     Panel_From.Visible = false;
     CheckExchange();
 }