Skip to content
Merged

Dev #92

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using DFApp.CommonDtos;

namespace DFApp.Bookkeeping.Expenditure
{
public class GetExpendituresRequestDto : FilterAndPagedAndSortedResultRequestDto
{
public long? CategoryId { get; set; }

public bool? IsBelongToSelf { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ namespace DFApp.Bookkeeping.Expenditure
public interface IBookkeepingExpenditureService : ICrudAppService<
BookkeepingExpenditureDto
, long
, FilterAndPagedAndSortedResultRequestDto
, GetExpendituresRequestDto
, CreateUpdateBookkeepingExpenditureDto>
{
Task<List<BookkeepingCategoryLookupDto>> GetCategoryLookupDto();

Task<decimal> GetTotalExpenditureAsync(string? filter = null, long? categoryId = null, bool? isBelongToSelf = null);

Task<ChartJSDto> GetChartJSDto(DateTime start
, DateTime end
, CompareType compareType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BookkeepingExpenditureService : CrudAppService<
BookkeepingExpenditure
, BookkeepingExpenditureDto
, long
, FilterAndPagedAndSortedResultRequestDto
, GetExpendituresRequestDto
, CreateUpdateBookkeepingExpenditureDto>, IBookkeepingExpenditureService
{
private readonly IRepository<BookkeepingCategory, long> _categoryRepository;
Expand All @@ -34,18 +34,33 @@ public BookkeepingExpenditureService(IRepository<BookkeepingCategory, long> cate
DeletePolicyName = DFAppPermissions.BookkeepingExpenditure.Delete;
}

protected override async Task<IQueryable<BookkeepingExpenditure>> CreateFilteredQueryAsync(FilterAndPagedAndSortedResultRequestDto input)
protected override async Task<IQueryable<BookkeepingExpenditure>> CreateFilteredQueryAsync(GetExpendituresRequestDto input)
{
if(!string.IsNullOrWhiteSpace(input.Filter)){
var query = await Repository.WithDetailsAsync();
return query.Where(x => x.Category!.Category.Contains(input.Filter)
|| x.Remark!.Contains(input.Filter)
|| x.Expenditure.ToString().Contains(input.Filter));
var query = await Repository.WithDetailsAsync();

if (!string.IsNullOrWhiteSpace(input.Filter))
{
query = query.Where(x => x.Category!.Category.Contains(input.Filter)
|| x.Remark!.Contains(input.Filter)
|| x.Expenditure.ToString().Contains(input.Filter));
}
else{
return await Repository.WithDetailsAsync();

if (input.CategoryId.HasValue)
{
query = query.Where(x => x.CategoryId == input.CategoryId.Value);
}


if (input.IsBelongToSelf.HasValue)
{
query = query.Where(x => x.IsBelongToSelf == input.IsBelongToSelf.Value);
}

if (string.IsNullOrWhiteSpace(input.Sorting))
{
query = query.OrderByDescending(x => x.ExpenditureDate);
}

return query;
}

public async Task<List<BookkeepingCategoryLookupDto>> GetCategoryLookupDto()
Expand All @@ -57,6 +72,31 @@ public async Task<List<BookkeepingCategoryLookupDto>> GetCategoryLookupDto()
return result;
}

public async Task<decimal> GetTotalExpenditureAsync(string? filter = null, long? categoryId = null, bool? isBelongToSelf = null)
{
var query = await ReadOnlyRepository.GetQueryableAsync();

if (!string.IsNullOrWhiteSpace(filter))
{
query = query.Where(x => x.Category!.Category.Contains(filter)
|| x.Remark!.Contains(filter)
|| x.Expenditure.ToString().Contains(filter));
}

if (categoryId.HasValue)
{
query = query.Where(x => x.CategoryId == categoryId.Value);
}

if (isBelongToSelf.HasValue)
{
query = query.Where(x => x.IsBelongToSelf == isBelongToSelf.Value);
}

var total = await AsyncExecuter.SumAsync(query, x => x.Expenditure);
return total;
}

[Authorize(DFAppPermissions.BookkeepingExpenditure.Analysis)]
public async Task<ChartJSDto> GetChartJSDto(DateTime start, DateTime end
, CompareType compareType, NumberType numberType, bool? isBelongToSelf)
Expand Down
Loading