Esempio n. 1
0
        public async Task <IActionResult> ExportAccountAnalysis([FromBody] ListQueryModel <AccountAnalysisQueryModel> listQuery)
        {
            if (listQuery == null)
            {
                throw new ArgumentNullException(nameof(listQuery));
            }
            if (listQuery.Model == null)
            {
                listQuery.Model = new AccountAnalysisQueryModel
                {
                    Month    = DateTime.Now.Month,
                    Year     = DateTime.Now.Year,
                    BranchId = _branchContext.Branch.Id
                }
            }
            ;

            var query = new
            {
                BeginDate = new DateTime(listQuery.Model.Year, listQuery.Model.Month, 1),
                EndDate   = new DateTime(listQuery.Model.Year, listQuery.Model.Month, 1, 23, 59, 59).AddMonths(1).AddDays(-1),
                BranchId  = listQuery.Model.BranchId,
                AccountId = listQuery.Model.AccountId
            };

            var model = new AccountAnalysisModel
            {
                BeginDate  = query.BeginDate,
                EndDate    = query.EndDate,
                BranchId   = listQuery.Model.BranchId,
                BranchName = _memberRepository.Groups(_sessionContext.UserId, null)
                             .FirstOrDefault(g => g.Type == GroupType.Branch && g.Id == listQuery.Model.BranchId)?.DisplayName,
                AccountId   = listQuery.Model.AccountId,
                AccountCode = _accountRepository.Get(listQuery.Model.AccountId)?.Code,
                List        = _accountAnalysisRepository.List(query).ToList(),
                Group       = _accountAnalysisRepository.Group(query),
            };

            using (var stream = _accountAnalysisExcelBuilder.Build(model))
            {
                var fileName = await _storage.Save(stream, ContainerName.Temp, "accountAnalysis.xlsx");

                string contentType;
                new FileExtensionContentTypeProvider().TryGetContentType(fileName, out contentType);

                var fileRow = new FileRow
                {
                    CreateDate  = DateTime.Now,
                    ContentType = contentType ?? "application/octet-stream",
                    FileName    = fileName,
                    FilePath    = fileName
                };
                return(Ok(fileRow));
            }
        }
Esempio n. 2
0
        public AccountAnalysisModel AccountAnalysis([FromBody] ListQueryModel <AccountAnalysisQueryModel> listQuery)
        {
            if (listQuery == null)
            {
                throw new ArgumentNullException(nameof(listQuery));
            }
            if (listQuery.Model == null)
            {
                listQuery.Model = new AccountAnalysisQueryModel
                {
                    Month    = DateTime.Now.Month,
                    Year     = DateTime.Now.Year,
                    BranchId = _branchContext.Branch.Id
                }
            }
            ;

            var query = new
            {
                BeginDate = new DateTime(listQuery.Model.Year, listQuery.Model.Month, 1),
                EndDate   = new DateTime(listQuery.Model.Year, listQuery.Model.Month, 1, 23, 59, 59).AddMonths(1).AddDays(-1),
                BranchId  = listQuery.Model.BranchId,
                AccountId = listQuery.Model.AccountId
            };

            var model = new AccountAnalysisModel
            {
                BeginDate  = query.BeginDate,
                EndDate    = query.EndDate,
                BranchId   = listQuery.Model.BranchId,
                BranchName = _memberRepository.Groups(_sessionContext.UserId, null)
                             .FirstOrDefault(g => g.Type == GroupType.Branch && g.Id == listQuery.Model.BranchId)?.DisplayName,
                AccountId   = listQuery.Model.AccountId,
                AccountCode = _accountRepository.Get(listQuery.Model.AccountId)?.Code,
                List        = _accountAnalysisRepository.List(query).ToList(),
                Group       = _accountAnalysisRepository.Group(query),
            };

            return(model);
        }