public IList <CompanyCashFlowOutputDto> Get(CompanyCashFlowInputDto input)
        {
            var companyCashFlowsDtos = new List <CompanyCashFlowOutputDto>();

            try
            {
                if (input.CoinId != 0)
                {
                    decimal?lastBalance = 0;
                    var     companyCash = _unitOfWork.GenericRepository <CompanyCash>()
                                          .FindBy(x => x.CoinId == input.CoinId && x.CompanyId == input.CompanyId).FirstOrDefault();
                    if (companyCash != null)
                    {
                        lastBalance = companyCash.InitialBalance;
                    }
                    var companyCashFlows = _unitOfWork.GenericRepository <CompanyCashFlow>()
                                           .FindBy(x => x.CoinId.Equals(input.CoinId) && x.CompanyId.Equals(input.CompanyId)
                                                   , c => c.MoenyAction.Clearing.FromClient
                                                   , c => c.MoenyAction.Clearing.ToClient
                                                   , c => c.MoenyAction.Clearing.ToCompany
                                                   , c => c.MoenyAction.Clearing.ToCompany
                                                   , c => c.MoenyAction.Clearing.FromCompany
                                                   , c => c.MoenyAction.PublicMoney.PublicExpense
                                                   , c => c.MoenyAction.PublicMoney.PublicIncome
                                                   ).OrderBy(x => x.MoenyAction.Date);
                    var companyCashFlowsBeforeFromDate = companyCashFlows.Where(x => x.MoenyAction.Date < input.From);
                    if (companyCashFlowsBeforeFromDate.Any())
                    {
                        var lastCompanyCashFlowBeforeFromDate = companyCashFlowsBeforeFromDate.Sum(c => c.Amount);
                        lastBalance = lastCompanyCashFlowBeforeFromDate;
                    }

                    companyCashFlowsDtos.Add(
                        new CompanyCashFlowOutputDto()
                    {
                        Balance = lastBalance,
                        Type    = "رصيد سابق"
                    });


                    var dataCashFlows = new List <CompanyCashFlow>();

                    if (input.From != null && input.To != null)
                    {
                        dataCashFlows = companyCashFlows.Where(x => x.MoenyAction.Date >= input.From && x.MoenyAction.Date <= input.To).ToList();
                    }
                    else if (input.From == null && input.To != null)
                    {
                        dataCashFlows = companyCashFlows.Where(x => x.MoenyAction.Date <= input.To).ToList();
                    }
                    else if (input.From != null && input.To == null)
                    {
                        dataCashFlows = companyCashFlows.Where(x => x.MoenyAction.Date >= input.From).ToList();
                    }
                    else
                    {
                        dataCashFlows = companyCashFlows.ToList();
                    }
                    foreach (var companyCashFlow in dataCashFlows)
                    {
                        var temp = new CompanyCashFlowOutputDto()
                        {
                            Id                                           = companyCashFlow.Id,
                            Balance                                      = companyCashFlowsDtos.Last().Balance + companyCashFlow.Amount,
                            Amount                                       = companyCashFlow.Amount,
                            Commission                                   = companyCashFlow.Commission(),
                            SecondCommission                             = companyCashFlow.SecounCommission(),
                            ReceiverName                                 = companyCashFlow.ReceiverName(Requester.Company, input.CompanyId),
                            SenderName                                   = companyCashFlow.SenderName(Requester.Company, input.CompanyId),
                            CountryName                                  = companyCashFlow.CountryName(),
                            Type                                         = companyCashFlow.MoenyAction.GetTypeName(Requester.Company, companyCashFlow.CompanyId),
                            Name                                         = _moneyActionAppService.GetActionName(companyCashFlow.MoenyAction),
                            Number                                       = companyCashFlow.MoenyAction.GetActionId(),
                            Date                                         = companyCashFlow.MoenyAction.Date != null?companyCashFlow.MoenyAction.Date.ToString("dd/MM/yyyy", new CultureInfo("ar-AE")) : string.Empty,
                                                           Note          = companyCashFlow.MoenyAction.GetNote(Requester.Company, companyCashFlow.CompanyId),
                                                           MoneyActionId = companyCashFlow.MoneyActionId,
                                                           Matched       = companyCashFlow.Matched
                        };
                        //temp.Balance = companyCashFlowsDtos.Last().Balance + companyCashFlow.Amount;
                        temp.Balance += temp.Commission;
                        companyCashFlowsDtos.Add(temp);
                    }
                }
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
            }

            return(companyCashFlowsDtos);
        }
Beispiel #2
0
        public IList <TreasuryActionsDto> GetMoneyActions(TreasuryMoneyActionInputDto input)
        {
            var treasuryMoneyActionsDto = new List <TreasuryActionsDto>();

            try
            {
                var treasuryMoneyActions = _unitOfWork.GenericRepository <TreasuryMoneyAction>()
                                           .FindBy(x => x.TreasuryId == input.TreasuryId && x.CoinId == input.CoinId);

                if (input.From == null && input.To != null)
                {
                    treasuryMoneyActions = treasuryMoneyActions.Where(x => x.Created < input.To);
                }
                else if (input.From != null && input.To == null)
                {
                    treasuryMoneyActions = treasuryMoneyActions.Where(x => x.Created > input.From);
                }
                else if (input.From != null && input.To != null)
                {
                    treasuryMoneyActions = treasuryMoneyActions.Where(x => x.Created > input.From && x.Created < input.To);
                }

                foreach (var treasuryMoneyAction in treasuryMoneyActions.ToList())
                {
                    if (treasuryMoneyAction.BranchCashFlowId != null)
                    {
                        var moneyAction = treasuryMoneyAction.BranchCashFlow.MoenyAction;
                        treasuryMoneyActionsDto.Add(new TreasuryActionsDto()
                        {
                            Amount        = treasuryMoneyAction.Amount,
                            Total         = treasuryMoneyAction.Total,
                            Id            = treasuryMoneyAction.Id,
                            Type          = moneyAction.GetTypeName(Requester.Branch, null),
                            Name          = _moneyActionAppService.GetActionName(moneyAction),
                            Number        = moneyAction.GetActionId(),
                            Date          = moneyAction.GetDate(),
                            Note          = moneyAction.GetNote(Requester.Branch, null),
                            MoneyActionId = moneyAction.Id,
                            CreatedBy     = treasuryMoneyAction.BranchCashFlow.CreatedBy
                        });
                    }
                    else
                    {
                        treasuryMoneyActionsDto.Add(new TreasuryActionsDto()
                        {
                            Amount    = treasuryMoneyAction.Amount,
                            Total     = treasuryMoneyAction.Total,
                            Id        = treasuryMoneyAction.Id,
                            Type      = treasuryMoneyAction.Amount > 0 ? "إعطاء" : "اخذ",
                            Date      = treasuryMoneyAction.Created != null ? treasuryMoneyAction.Created.Value.ToString("dd/MM/yyyy", new CultureInfo("ar-AE")) : string.Empty,
                            CreatedBy = treasuryMoneyAction.CreatedBy
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
            }

            return(treasuryMoneyActionsDto);
        }
        public IList <BranchCashFlowOutputDto> Get(int?branchId, int coinId, DateTime?from, DateTime?to)
        {
            IList <BranchCashFlowOutputDto> branchCashFlowsDto = new List <BranchCashFlowOutputDto>();

            try
            {
                if (branchId == null)
                {
                    branchId = BranchHelper.Id;
                }

                #region Last Total

                decimal lastTotal;
                var     brachCashs = _unitOfWork.GenericRepository <BranchCash>()
                                     .FindBy(c => c.CoinId == coinId && c.BranchId == branchId).ToList();

                if (!brachCashs.Any())
                {
                    return(branchCashFlowsDto);
                }

                lastTotal = brachCashs.FirstOrDefault().InitialBalance;
                branchCashFlowsDto.Add(new BranchCashFlowOutputDto
                {
                    Balance = lastTotal,
                    Type    = "ÑÕíÏ ÓÇÈÞ",
                });


                #endregion

                var allBranchCashFlows = _unitOfWork.GenericRepository <BranchCashFlow>()
                                         .FindBy(c => c.CoinId == coinId && c.BranchId == branchId).OrderBy(x => new { x.MoenyAction.Date, x.Id }).ToList();
                if (allBranchCashFlows.Any())
                {
                    var branchCashFlows = new List <BranchCashFlow>();

                    if (from != null || to != null)
                    {
                        if (from != null)
                        {
                            var tempLastBranchCahsFlow = allBranchCashFlows.Where(c => c.MoenyAction.Date < from).ToList();
                            if (tempLastBranchCahsFlow.Any())
                            {
                                branchCashFlowsDto.Clear();
                                lastTotal = tempLastBranchCahsFlow.Last().Total;
                                branchCashFlowsDto.Add(new BranchCashFlowOutputDto
                                {
                                    Balance = lastTotal,
                                    Type    = "ÑÕíÏ ÓÇÈÞ"
                                });
                            }
                        }

                        if (from != null && to == null)
                        {
                            branchCashFlows = allBranchCashFlows.Where(c => c.MoenyAction.Date >= from).ToList();
                        }
                        else if (to != null && from == null)
                        {
                            branchCashFlows = allBranchCashFlows.Where(c => c.MoenyAction.Date <= to).ToList();
                        }
                        else
                        {
                            branchCashFlows = allBranchCashFlows.Where(c => c.MoenyAction.Date >= from && c.MoenyAction.Date <= to).ToList();
                        }
                    }
                    else
                    {
                        branchCashFlows = allBranchCashFlows.ToList();
                    }

                    foreach (var item in branchCashFlows)
                    {
                        string note = item.MoenyAction.GetNote(Requester.Branch, null);
                        var    dto  = new BranchCashFlowOutputDto()
                        {
                            Id            = item.Id,
                            Balance       = branchCashFlowsDto.Last().Balance + item.Amount,
                            Amount        = item.Amount,
                            Type          = item.MoenyAction.GetTypeName(Requester.Branch, null),
                            Name          = _moneyActionAppService.GetActionName(item.MoenyAction),
                            Number        = item.MoenyAction.GetActionId().ToString(),
                            Date          = item.MoenyAction.GetDate(),
                            Note          = note,
                            MoneyActionId = item.MoenyAction.Id,
                            CreatedBy     = item.MoenyAction.CreateBy()
                        };
                        branchCashFlowsDto.Add(dto);
                    }
                }
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
            }

            return(branchCashFlowsDto);
        }