Ejemplo n.º 1
0
        public IEnumerable <TransactionHistory> HistoryIn(Guid userId)
        {
            var res = new List <TransactionHistory>();

            var userDetail = _UserCollection.GetById(userId);

            if (userDetail != null)
            {
                var userTransfers = _TransferCollection.GetMany(new TransferFilter()
                {
                    DestinationAccountNumber = userDetail.AccountNumber, IsConfirmed = true
                });
                userTransfers = userTransfers.Where(x => x.DestinationLinkingBankId == Guid.Empty);
                if (userTransfers.Any())
                {
                    var bank = _LinkingBankCollection.Get(new LinkingBankFilter()
                    {
                        Code = _Setting.BankCode
                    }).FirstOrDefault();

                    foreach (var transfer in userTransfers)
                    {
                        var hisTransaction = new TransactionHistory();
                        // Nội bộ
                        if (transfer.SourceLinkingBankId == Guid.Empty)
                        {
                            // Get chi tiết người gửi
                            var source = _UserCollection.GetByAccountNumber(transfer.SourceAccountNumber);
                            if (source != null)
                            {
                                hisTransaction.AccountName   = source.Name;
                                hisTransaction.AccountNumber = source.AccountNumber;
                                hisTransaction.Description   = transfer.Description;
                                hisTransaction.IsPayIn       = transfer.IsPayIn;

                                if (transfer.IsSenderPay)
                                {
                                    hisTransaction.Money = transfer.Money;
                                }
                                else
                                {
                                    hisTransaction.Money = transfer.Money - transfer.Fee;
                                }

                                if (transfer.SourceLinkingBankId == bank.Id || (hisTransaction.IsPayIn.HasValue && hisTransaction.IsPayIn.Value == true))
                                {
                                    // noi bo
                                    hisTransaction.BankName = bank.Name;
                                }
                                else
                                {
                                    var linkingBank = _LinkingBankCollection.GetById(transfer.SourceLinkingBankId);
                                    if (linkingBank != null)
                                    {
                                        hisTransaction.BankName = linkingBank.Name;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        // Linking bank
                        else
                        {
                            // TODO
                            // Khuê
                            IExternalBanking externalBanking = null;
                            if (transfer.DestinationLinkingBankId == Guid.Parse("8df09f0a-fd6d-42b9-804c-575183dadaf3"))
                            {
                                externalBanking = new ExternalBanking_BKTBank(_Encrypt, _Setting);
                                externalBanking.SetPartnerCode();
                            }
                            var source = externalBanking.GetInfoUser(transfer.DestinationAccountNumber);
                            if (source != null)
                            {
                                hisTransaction.AccountName   = source.full_name;
                                hisTransaction.AccountNumber = source.account_number;
                                hisTransaction.Description   = transfer.Description;

                                if (transfer.IsSenderPay)
                                {
                                    hisTransaction.Money = transfer.Money;
                                }
                                else
                                {
                                    hisTransaction.Money = transfer.Money - transfer.Fee;
                                }

                                var linkingBank = _LinkingBankCollection.GetById(transfer.SourceLinkingBankId);
                                if (linkingBank != null)
                                {
                                    hisTransaction.BankName = linkingBank.Name;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }

                        res.Add(hisTransaction);
                    }
                }
            }

            return(res);
        }
        public IEnumerable <CrossChecking> CrossCheckingIn(DateTime?from, DateTime?to, Guid?bankId)
        {
            var res = new List <CrossChecking>();

            var transfers = _TransferCollection.GetMany(new TransferFilter()
            {
                IsConfirmed = true
            });

            transfers = transfers.Where(x => x.DestinationLinkingBankId == Guid.Empty);
            if (bankId.HasValue)
            {
                transfers = transfers.Where(x => x.SourceLinkingBankId == bankId.Value);
            }
            foreach (var transfer in transfers)
            {
                var bank = _LinkingBankCollection.Get(new LinkingBankFilter()
                {
                    Code = _Setting.BankCode
                }).FirstOrDefault();
                // Get ngân hàng liên kết
                var linkBank = _LinkingBankCollection.GetById(transfer.SourceLinkingBankId);
                if (linkBank != null)
                {
                    // Get thông tin giao dịch
                    var transactions = _TransactionCollection.GetMany(new TransactionFilter()
                    {
                        ReferenceId = transfer.Id, Type = 0
                    });
                    if (from.HasValue)
                    {
                        transactions = transactions.Where(x => x.ConfirmTime.Value.Date >= from.Value.Date);
                    }
                    if (to.HasValue)
                    {
                        transactions = transactions.Where(x => x.ConfirmTime.Value.Date <= to.Value.Date);
                    }

                    if (transactions.Any())
                    {
                        var transaction = transactions.FirstOrDefault();

                        // Get thông tin tài khoản nguồn
                        // TODO
                        var sourceAccount = new ExternalAccount();
                        IExternalBanking externalBanking = null;
                        if (transfer.SourceLinkingBankId == Guid.Parse("8df09f0a-fd6d-42b9-804c-575183dadaf3"))
                        {
                            externalBanking = new ExternalBanking_BKTBank(_Encrypt, _Setting);
                            externalBanking.SetPartnerCode();
                        }
                        var source = externalBanking.GetInfoUser(transfer.SourceAccountNumber);
                        if (source != null)
                        {
                            sourceAccount.Name          = source.full_name;
                            sourceAccount.AccountNumber = source.account_number;
                        }
                        else
                        {
                            sourceAccount = null;
                        }
                        if (sourceAccount != null)
                        {
                            // Get thông tin tài khoản đích
                            var destAccount = _UserCollection.GetByAccountNumber(transfer.DestinationAccountNumber);
                            if (destAccount != null)
                            {
                                var history = new CrossChecking();
                                history.SourceAccountName        = sourceAccount.Name;
                                history.SourceAccountNumber      = sourceAccount.AccountNumber;
                                history.SourceBankName           = linkBank.Name;
                                history.DestinationAccountName   = destAccount.Name;
                                history.DestinationAccountNumber = destAccount.AccountNumber;
                                history.DestinationBankName      = bank.Name;
                                history.Description = transfer.Description;
                                history.Money       = transfer.Money;
                                if (!transfer.IsSenderPay)
                                {
                                    history.Money -= transfer.Fee;
                                }
                                history.ConfirmTime = transaction.ConfirmTime.Value;

                                res.Add(history);
                            }
                        }
                    }
                }
            }

            return(res);
        }