예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="idCollection"></param>
        /// <returns></returns>
        public IList <AccountsReportViewModel> SafeChecksUnderCollectionOfReceiptsMovement(IList <long> idCollection)
        {
            List <AccountsReportViewModel> list = new List <AccountsReportViewModel>();

            ConditionFilter <Donation, long> condition = new ConditionFilter <Donation, long>
            {
                Query = (x => x.IsPosted &&
                         x.ParentKeyDonationId.HasValue == false &&
                         idCollection.Any(item => item == x.Id))
            };

            var sourceEntities = this._donationsRepository.Get(condition);

            if (sourceEntities != null && sourceEntities.Count() > 0)
            {
                DateTime now              = DateTime.Now;
                var      userId           = this._currentUserService.CurrentUserId;
                var      financialSetting = this._settingsService.GetFinancialSetting();
                foreach (var source in sourceEntities)
                {
                    AccountsReportViewModel safeReport = new AccountsReportViewModel();
                    safeReport.Code         = source.Code;
                    safeReport.Name         = source.Safe.Name;
                    safeReport.MovementType = "فاتورة الشراء";
                    safeReport.Description  = source.Description;
                    safeReport.FullCode     = source.Safe.Code;
                    safeReport.CreationDate = source.CreationDate;
                    safeReport.DebtorValue  = source.Amount;
                    list.Add(safeReport);
                }
            }

            return(list);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="toDate"></param>
        /// <param name="IsAutomaticPosting"></param>
        /// <param name="IsBulkPosting"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public IList <AccountsReportViewModel> SafeReceiptsMovement(long SafeId, DateTime DateFrom, DateTime DateTo)
        {
            List <AccountsReportViewModel> list = new List <AccountsReportViewModel>();
            var safe = this._safesRepository.Get(SafeId);
            ConditionFilter <Donation, long> condition = new ConditionFilter <Donation, long>
            {
                Query = (x => x.ParentKeyDonationId.HasValue == false &&
                         x.Date <= DateTo &&
                         x.Date >= DateFrom &&
                         x.SafeId == SafeId)
            };
            var sourceEntities = this._donationsRepository.Get(condition);

            if (sourceEntities != null && sourceEntities.Count() > 0)
            {
                foreach (var source in sourceEntities)
                {
                    AccountsReportViewModel safeReport = new AccountsReportViewModel();
                    safeReport.Code         = source.Code;
                    safeReport.Name         = safe.Name;
                    safeReport.MovementType = "فاتورة الشراء";
                    safeReport.Description  = source.Description;
                    safeReport.FullCode     = safe.Code;
                    safeReport.CreationDate = source.CreationDate;
                    safeReport.DebtorValue  = source.Amount;
                    list.Add(safeReport);
                }
            }

            return(list);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="toDate"></param>
        /// <param name="IsAutomaticPosting"></param>
        /// <param name="IsBulkPosting"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public IList <AccountsReportViewModel> SafePurchaseInvoice(long SafeId, DateTime DateFrom, DateTime DateTo)
        {
            List <AccountsReportViewModel> list = new List <AccountsReportViewModel>();
            var safe = this._safesRepository.Get(SafeId);
            ConditionFilter <PurchaseInvoice, long> condition = new ConditionFilter <PurchaseInvoice, long>
            {
                Query = (x => x.Date <= DateTo &&
                         x.Date >= DateFrom &&
                         x.SafeId == SafeId)
            };
            var sourceEntities = this._purchaseInvoicesRepository.Get(condition);

            if (sourceEntities != null && sourceEntities.Count() > 0)
            {
                foreach (var source in sourceEntities)
                {
                    AccountsReportViewModel safeReport = new AccountsReportViewModel();
                    safeReport.Code          = source.Code;
                    safeReport.Name          = safe.Name;
                    safeReport.MovementType  = "فاتورة الشراء";
                    safeReport.Description   = "";
                    safeReport.FullCode      = safe.Code;
                    safeReport.CreationDate  = source.CreationDate;
                    safeReport.CreditorValue = source.NetAmount;
                    list.Add(safeReport);
                }
            }

            return(list);
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
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);
        }