Beispiel #1
0
        public CurrencyRateLightViewModel GetLatestCurrencyRate(long?currencyId, long?exchangeCurrencyId)
        {
            CurrencyRateLightViewModel result = null;
            var lates = this._CurrencyRatesRepository.Get(null)
                        .OrderByDescending(x => x.Date)
                        .Where(x => x.CurrencyId == currencyId &&
                               x.ExchangeCurrencyId == exchangeCurrencyId)
                        .FirstOrDefault();

            if (lates != null)
            {
                result = lates.ToLightModel();
            }

            return(result);
        }
Beispiel #2
0
        public AccountsReportViewModel MapToReportModel(Transaction item, Language lang, CurrencyRateLightViewModel latestCurrencyRate = null)
        {
            AccountsReportViewModel account = new AccountsReportViewModel();

            account.Name         = item.AccountChart.ChildTranslatedAccountCharts.FirstOrDefault(x => x.Language == lang).Name;
            account.Code         = item.AccountChart.Code;
            account.FullCode     = item.AccountChart.FullCode;
            account.CreationDate = item.CreationDate;
            account.Description  = item.Journal.ChildTranslatedJournals.FirstOrDefault(x => x.Language == lang).Description;
            account.MovementType = this._resourcesService.GetMovementTypeName(item.Journal.MovementType, lang);
            //account.DocumentCode = item.Journal.ObjectId.ToString();
            account.DocumentCode = item.Id.ToString();

            if (latestCurrencyRate != null)
            {
                account.AccountCurrencyName  = item.AccountChart.Currency?.ChildTranslatedCurrencys.FirstOrDefault(x => x.Language == lang)?.Name;
                account.ExchangeCurrencyName = this._currencysRepository.Get(latestCurrencyRate.ExchangeCurrencyId.Value)?.ChildTranslatedCurrencys?.FirstOrDefault(x => x.Language == lang)?.Name;
                account.PriceValue           = $"{account.AccountCurrencyName} = {latestCurrencyRate.Price} {account.ExchangeCurrencyName}";
            }


            if (item.IsCreditor)
            {
                account.OriginalCreditorValue = item.Amount;
                account.CreditorValue         = item.Amount;
                account.OriginalDebtorValue   = 0;
                account.DebtorValue           = 0;

                if (latestCurrencyRate != null)
                {
                    account.CreditorValue = item.Amount * latestCurrencyRate.Price;
                }
            }
            else
            {
                account.OriginalDebtorValue   = item.Amount;
                account.DebtorValue           = item.Amount;
                account.OriginalCreditorValue = 0;
                account.CreditorValue         = 0;

                if (latestCurrencyRate != null)
                {
                    account.DebtorValue = item.Amount * latestCurrencyRate.Price;
                }
            }

            return(account);
        }
Beispiel #3
0
        public IList <AccountsReportViewModel> GetAccountBalanceReport(long AccountChartId, long?currencyId, DateTime?DateFrom, DateTime?DateTo)
        {
            var  lang = this._languageService.CurrentLanguage;
            long?accountCurrencyId = 0;
            CurrencyRateLightViewModel latestCurrencyRate = null;

            var    accountChart             = this._AccountChartsRepository.Get(AccountChartId);
            string accountChartCurrencyName = "";
            string currencyName             = "";
            string priceValue = "";

            //DateFrom = DateFrom.SetTimeToNow();
            DateTo = DateTo.SetTimeToMax();

            if (currencyId.HasValue)
            {
                accountCurrencyId        = this._AccountChartsRepository.Get(AccountChartId).CurrencyId;
                accountChartCurrencyName = this._currencysRepository.Get(accountCurrencyId.Value)?.ChildTranslatedCurrencys?.FirstOrDefault(x => x.Language == lang)?.Name;
                latestCurrencyRate       = this._currencyRatesService.GetLatestCurrencyRate(accountCurrencyId, currencyId);
                currencyName             = this._currencysRepository.Get(currencyId.Value)?.ChildTranslatedCurrencys?.FirstOrDefault(x => x.Language == lang)?.Name;
                if (latestCurrencyRate != null)
                {
                    priceValue = $"{accountChartCurrencyName} = {latestCurrencyRate.Price} {currencyName}";
                }
            }

            List <AccountsReportViewModel>      AccountsReport = new List <AccountsReportViewModel>();
            ConditionFilter <Transaction, long> condition      = new ConditionFilter <Transaction, long>();

            AccountsReport = GetAccReportBeforeDate(AccountChartId, currencyId, DateFrom.Value).ToList();

            if (DateFrom.HasValue && DateTo.HasValue)
            {
                condition.Query = x =>
                                  x.Journal.PostingStatus == PostingStatus.Approved &&
                                  x.CreationDate >= DateFrom &&
                                  x.CreationDate <= DateTo &&
                                  x.AccountChartId == AccountChartId;
            }
            else
            {
                condition.Query = x =>
                                  x.Journal.PostingStatus == PostingStatus.Approved &&
                                  x.AccountChartId == AccountChartId;
            }

            var entityCollection = this._TransactionsRepository.Get(condition).ToList();

            if (entityCollection.Any())
            {
                AccountsReportViewModel accountCreditor = new AccountsReportViewModel();
                AccountsReportViewModel accountDebtor   = new AccountsReportViewModel();

                accountCreditor.CreationDate          = DateFrom;
                accountCreditor.MovementType          = this._resourcesService[ResourceKeyEnum.TotalCreditBalanceInPeriod, lang].Value;
                accountCreditor.OriginalCreditorValue = 0;
                accountCreditor.CreditorValue         = 0;
                accountCreditor.OriginalDebtorValue   = 0;
                accountCreditor.DebtorValue           = 0;
                accountCreditor.AccountCurrencyName   = accountChartCurrencyName;
                if (latestCurrencyRate != null)
                {
                    accountCreditor.ExchangeCurrencyName = currencyName;
                    accountCreditor.PriceValue           = priceValue;
                }

                accountDebtor.CreationDate          = DateFrom;
                accountDebtor.MovementType          = this._resourcesService[ResourceKeyEnum.TotalDebtBalanceInPeriod, lang].Value;
                accountDebtor.OriginalDebtorValue   = 0;
                accountDebtor.DebtorValue           = 0;
                accountDebtor.OriginalCreditorValue = 0;
                accountDebtor.CreditorValue         = 0;
                accountDebtor.AccountCurrencyName   = accountChartCurrencyName;
                if (latestCurrencyRate != null)
                {
                    accountDebtor.ExchangeCurrencyName = currencyName;
                    accountDebtor.PriceValue           = priceValue;
                }

                foreach (var item in entityCollection)
                {
                    if (item.Amount < 1)
                    {
                        continue;
                    }
                    else
                    {
                        if (item.IsCreditor)
                        {
                            accountCreditor.OriginalCreditorValue += item.Amount;

                            if (latestCurrencyRate != null)
                            {
                                accountCreditor.CreditorValue += (item.Amount * latestCurrencyRate.Price);
                            }
                            else
                            {
                                accountCreditor.CreditorValue += item.Amount;
                            }
                        }
                        else
                        {
                            accountDebtor.OriginalDebtorValue += item.Amount;

                            if (latestCurrencyRate != null)
                            {
                                accountDebtor.DebtorValue += (item.Amount * latestCurrencyRate.Price);
                            }
                            else
                            {
                                accountDebtor.DebtorValue += item.Amount;
                            }
                        }
                    }
                }
                AccountsReport.Add(accountCreditor);
                AccountsReport.Add(accountDebtor);
            }

            //foreach (var item in entityCollection)
            //{
            //    if (item.Amount < 1)
            //        continue;
            //    else
            //        AccountsReport.Add(MapToReportModel(item, lang));
            //}
            return(AccountsReport);
        }
Beispiel #4
0
        public IList <AccountsReportViewModel> GetAccReportBeforeDate(long AccountChartId, long?currencyId, DateTime DateFrom)
        {
            var  lang = this._languageService.CurrentLanguage;
            long?accountCurrencyId = 0;
            CurrencyRateLightViewModel latestCurrencyRate = null;
            //DateFrom = DateFrom.SetTimeToNow();
            string currencyName = "";

            if (currencyId.HasValue)
            {
                accountCurrencyId  = this._AccountChartsRepository.Get(AccountChartId).CurrencyId;
                latestCurrencyRate = this._currencyRatesService.GetLatestCurrencyRate(accountCurrencyId, currencyId);
                currencyName       = this._currencysRepository.Get(currencyId.Value)?.ChildTranslatedCurrencys?.FirstOrDefault(x => x.Language == lang)?.Name;
            }

            List <AccountsReportViewModel>      AccountsReport = new List <AccountsReportViewModel>();
            ConditionFilter <Transaction, long> condition      = new ConditionFilter <Transaction, long>
            {
                Query = x =>
                        x.Journal.PostingStatus == PostingStatus.Approved &&
                        x.CreationDate < DateFrom &&
                        x.AccountChartId == AccountChartId
            };
            var CurrentAccount = this._AccountChartsRepository.Get(AccountChartId);

            //if (CurrentAccount.OpeningCredit.HasValue)
            //{
            AccountsReportViewModel account = new AccountsReportViewModel();

            account.Name                = CurrentAccount.ChildTranslatedAccountCharts.FirstOrDefault(x => x.Language == lang).Name;
            account.Code                = CurrentAccount.Code;
            account.FullCode            = CurrentAccount.FullCode;
            account.CreationDate        = CurrentAccount.CreationDate;
            account.Description         = "";
            account.MovementType        = this._resourcesService[ResourceKeyEnum.OpeningBalance, lang].Value;
            account.DocumentCode        = CurrentAccount.Code;
            account.AccountCurrencyName = CurrentAccount?.Currency?.ChildTranslatedCurrencys?.FirstOrDefault(x => x.Language == lang)?.Name;
            if (latestCurrencyRate != null)
            {
                account.ExchangeCurrencyName = currencyName;
                account.PriceValue           = $"{account.AccountCurrencyName} = {latestCurrencyRate.Price} {account.ExchangeCurrencyName}";
            }

            if (CurrentAccount.IsDebt != null)
            {
                if (CurrentAccount.IsDebt == true)
                {
                    account.OriginalCreditorValue = CurrentAccount.OpeningCredit;
                    account.CreditorValue         = CurrentAccount.OpeningCredit;
                    account.OriginalDebtorValue   = 0;
                    account.DebtorValue           = 0;

                    if (latestCurrencyRate != null)
                    {
                        account.CreditorValue = CurrentAccount.OpeningCredit * latestCurrencyRate.Price;
                    }
                }
                else
                {
                    account.OriginalCreditorValue = 0;
                    account.CreditorValue         = 0;
                    account.OriginalDebtorValue   = CurrentAccount.OpeningCredit;
                    account.DebtorValue           = CurrentAccount.OpeningCredit;

                    if (latestCurrencyRate != null)
                    {
                        account.DebtorValue = CurrentAccount.OpeningCredit * latestCurrencyRate.Price;
                    }
                }
            }
            else
            {
                account.OriginalCreditorValue = 0;
                account.CreditorValue         = 0;
                account.OriginalDebtorValue   = 0;
                account.DebtorValue           = 0;
            }
            AccountsReport.Add(account);
            //}

            var entityCollection = this._TransactionsRepository.Get(condition).ToList();

            if (entityCollection.Any())
            {
                AccountsReportViewModel accountCreditor = new AccountsReportViewModel();
                AccountsReportViewModel accountDebtor   = new AccountsReportViewModel();

                accountCreditor.CreationDate          = DateFrom.AddDays(-1);
                accountCreditor.MovementType          = this._resourcesService[ResourceKeyEnum.TotalCreditBalanceBeforePeriod, lang].Value;
                accountCreditor.OriginalCreditorValue = 0;
                accountCreditor.CreditorValue         = 0;
                accountCreditor.OriginalDebtorValue   = 0;
                accountCreditor.DebtorValue           = 0;
                accountCreditor.AccountCurrencyName   = CurrentAccount.Currency?.ChildTranslatedCurrencys?.FirstOrDefault(x => x.Language == lang)?.Name;
                if (latestCurrencyRate != null)
                {
                    accountCreditor.ExchangeCurrencyName = currencyName;
                    accountCreditor.PriceValue           = $"{accountCreditor.AccountCurrencyName} = {latestCurrencyRate.Price} {accountCreditor.ExchangeCurrencyName}";
                }

                accountDebtor.CreationDate          = DateFrom.AddDays(-1);
                accountDebtor.MovementType          = this._resourcesService[ResourceKeyEnum.TotalDebtBalanceBeforePeriod, lang].Value;
                accountDebtor.OriginalDebtorValue   = 0;
                accountDebtor.DebtorValue           = 0;
                accountDebtor.OriginalCreditorValue = 0;
                accountDebtor.CreditorValue         = 0;
                accountDebtor.AccountCurrencyName   = CurrentAccount.Currency?.ChildTranslatedCurrencys?.FirstOrDefault(x => x.Language == lang)?.Name;
                if (latestCurrencyRate != null)
                {
                    accountDebtor.ExchangeCurrencyName = currencyName;
                    accountDebtor.PriceValue           = $"{accountDebtor.AccountCurrencyName} = {latestCurrencyRate.Price} {accountDebtor.ExchangeCurrencyName}";
                }

                foreach (var item in entityCollection)
                {
                    if (item.Amount < 1)
                    {
                        continue;
                    }
                    else
                    {
                        if (item.IsCreditor)
                        {
                            accountCreditor.OriginalCreditorValue += item.Amount;

                            if (latestCurrencyRate != null)
                            {
                                accountCreditor.CreditorValue += (item.Amount * latestCurrencyRate.Price);
                            }
                            else
                            {
                                accountCreditor.CreditorValue += item.Amount;
                            }
                        }
                        else
                        {
                            accountDebtor.OriginalDebtorValue += item.Amount;

                            if (latestCurrencyRate != null)
                            {
                                accountDebtor.DebtorValue += (item.Amount * latestCurrencyRate.Price);
                            }
                            else
                            {
                                accountDebtor.DebtorValue += item.Amount;
                            }
                        }
                    }
                }
                AccountsReport.Add(accountCreditor);
                AccountsReport.Add(accountDebtor);
            }

            //foreach (var item in entityCollection)
            //{
            //    if (item.Amount < 1)
            //        continue;
            //    else
            //        AccountsReport.Add(MapToReportModel(item));
            //}

            return(AccountsReport);
        }
Beispiel #5
0
        public IList <AccountsReportViewModel> GetAccountsReport(long AccountChartId, long?currencyId, DateTime?DateFrom, DateTime?DateTo)
        {
            var  lang = this._languageService.CurrentLanguage;
            long?accountCurrencyId = 0;
            CurrencyRateLightViewModel latestCurrencyRate = null;

            //DateFrom = DateFrom.SetTimeToNow();
            DateTo = DateTo.SetTimeToMax();

            if (currencyId.HasValue)
            {
                accountCurrencyId  = this._AccountChartsRepository.Get(AccountChartId).CurrencyId;
                latestCurrencyRate = this._currencyRatesService.GetLatestCurrencyRate(accountCurrencyId, currencyId);
            }

            List <AccountsReportViewModel>      AccountsReport = new List <AccountsReportViewModel>();
            ConditionFilter <Transaction, long> condition      = new ConditionFilter <Transaction, long>();

            AccountsReport = GetAccReportBeforeDate(AccountChartId, currencyId, DateFrom.Value).ToList();

            if (DateFrom.HasValue && DateTo.HasValue)
            {
                condition.Query = x =>
                                  x.Journal.PostingStatus == PostingStatus.Approved &&
                                  x.CreationDate >= DateFrom &&
                                  x.CreationDate <= DateTo &&
                                  x.AccountChartId == AccountChartId;
            }
            else
            {
                condition.Query = x =>
                                  x.Journal.PostingStatus == PostingStatus.Approved &&
                                  x.AccountChartId == AccountChartId;
            }
            var entityCollection = this._TransactionsRepository.Get(condition).ToList();

            foreach (var item in entityCollection)
            {
                if (item.Amount < 1)
                {
                    continue;
                }
                else
                {
                    AccountsReport.Add(MapToReportModel(item, lang, latestCurrencyRate));
                }
            }

            if (AccountsReport != null && AccountsReport.Count > 0)
            {
                if (currencyId.HasValue && string.IsNullOrEmpty(AccountsReport[0].AccountCurrencyName))
                {
                    AccountsReport[0].AccountCurrencyName  = this._currencysRepository.Get(accountCurrencyId.Value)?.ChildTranslatedCurrencys?.FirstOrDefault(x => x.Language == lang)?.Name;
                    AccountsReport[0].ExchangeCurrencyName = this._currencysRepository.Get(currencyId.Value)?.ChildTranslatedCurrencys.FirstOrDefault(x => x.Language == lang)?.Name;
                    if (latestCurrencyRate != null)
                    {
                        AccountsReport[0].PriceValue = $"{AccountsReport[0].AccountCurrencyName} = {latestCurrencyRate.Price} {AccountsReport[0].ExchangeCurrencyName}";
                    }
                }
            }

            return(AccountsReport);
        }