feat: add unit filtering and improve unit info handling in charge cycles
- Add optional UnitId parameter to CostCyclsList method for filtering cycles by specific unit - Replace UnitIds/UnitNames lists with structured UnitInfoDto containing Id and Name - Clean unit names by removing "GUID#" prefix when present - Update CostCycleDto to use UnitInfoDto list instead of separate Id and Name lists - Fix unit assignment logic in Add and Edit methods to use new DTO structure
This commit is contained in:
@@ -52,7 +52,7 @@ namespace Complex.Application.Services.Basic
|
||||
/// <param name="IncomeCostTitleId"></param>
|
||||
/// <returns></returns>
|
||||
public ResultDto<List<CostCycleDto>> CostCyclsList(Guid ComplexId, DateOnly? StartDate = null,
|
||||
DateOnly? EndDate = null, int? IncomeCostTitleId = null)
|
||||
DateOnly? EndDate = null, int? IncomeCostTitleId = null, Guid? UnitId = null)
|
||||
{
|
||||
if (IncomeCostTitleId.HasValue && StartDate.HasValue)
|
||||
StartDate = GetStartOfMonth(StartDate.Value);
|
||||
@@ -70,6 +70,9 @@ namespace Complex.Application.Services.Basic
|
||||
else/*مدیریت شارژ ها فقط*/
|
||||
ChargeCycleQuery = ChargeCycleQuery.Where(c => c.IncomeCostTitleId == null);
|
||||
|
||||
if (UnitId.HasValue)
|
||||
ChargeCycleQuery = ChargeCycleQuery.Where(c => c.Units == null || c.Units.Any(u => u.Id == UnitId.Value));
|
||||
|
||||
var ChargeCycleList = ChargeCycleQuery.ToList().Select(c => new CostCycleDto
|
||||
{
|
||||
ComplexId = c.ComplexId,
|
||||
@@ -80,8 +83,18 @@ namespace Complex.Application.Services.Basic
|
||||
StartDate = c.StartDate,
|
||||
Id = c.Id,
|
||||
Title = c.Title,
|
||||
UnitIds = c.Units?.Select(u => u.Id).ToList(),
|
||||
UnitNames = c.Units?.Select(u => u.Id + "#" + u.UnitName).ToList(),
|
||||
Units = c.Units?.Select(u =>
|
||||
{
|
||||
var name = u.UnitName ?? "";
|
||||
// Some units store "GUID#Name" format; extract just the name part
|
||||
var hashIndex = name.IndexOf('#');
|
||||
var cleanName = hashIndex >= 0 ? name[(hashIndex + 1)..] : name;
|
||||
return new UnitInfoDto
|
||||
{
|
||||
Id = u.Id,
|
||||
Name = cleanName
|
||||
};
|
||||
}).ToList(),
|
||||
IncomeCostTitleId = c.IncomeCostTitleId,
|
||||
IncomeCostTitle = c.IncomeCostTitle?.Title
|
||||
}).ToList();
|
||||
@@ -107,9 +120,12 @@ namespace Complex.Application.Services.Basic
|
||||
|
||||
cycle = _mapper.Map<CostCycle>(costCycleDto);
|
||||
cycle.IncomeCostTitleId = costCycleDto.IncomeCostTitleId;
|
||||
if (costCycleDto.UnitIds != null)
|
||||
cycle.Units = _complexDBContext.Units.Where(u => costCycleDto.UnitIds.Contains(u.Id)
|
||||
if (costCycleDto.Units != null)
|
||||
{
|
||||
var unitIds = costCycleDto.Units.Select(u => u.Id).ToList();
|
||||
cycle.Units = _complexDBContext.Units.Where(u => unitIds.Contains(u.Id)
|
||||
&& u.ComplexId == costCycleDto.ComplexId).ToList();
|
||||
}
|
||||
|
||||
foreach (var u in cycle.Units)
|
||||
{
|
||||
@@ -139,8 +155,11 @@ namespace Complex.Application.Services.Basic
|
||||
costCycleDto.StartDate = GetStartOfMonth(costCycleDto.StartDate);
|
||||
|
||||
var newCycle = _mapper.Map<CostCycle>(costCycleDto);
|
||||
if (costCycleDto.UnitIds != null)
|
||||
newCycle.Units = _complexDBContext.Units.Where(u => costCycleDto.UnitIds.Contains(u.Id) && costCycleDto.ComplexId == u.ComplexId).ToList();
|
||||
if (costCycleDto.Units != null)
|
||||
{
|
||||
var unitIds = costCycleDto.Units.Select(u => u.Id).ToList();
|
||||
newCycle.Units = _complexDBContext.Units.Where(u => unitIds.Contains(u.Id) && costCycleDto.ComplexId == u.ComplexId).ToList();
|
||||
}
|
||||
|
||||
//if(newCycle.Units==null)
|
||||
//{
|
||||
@@ -381,6 +400,12 @@ namespace Complex.Application.Services.Basic
|
||||
public string? CostTitle { get; set; }
|
||||
public DateOnly? PaymentDate { set; get; }
|
||||
}
|
||||
public class UnitInfoDto
|
||||
{
|
||||
public Guid Id { set; get; }
|
||||
public string Name { set; get; }
|
||||
}
|
||||
|
||||
public class CostCycleDto
|
||||
{
|
||||
public Guid Id { set; get; }
|
||||
@@ -400,13 +425,9 @@ namespace Complex.Application.Services.Basic
|
||||
/// <summary>
|
||||
/// اگر برای واحدهای خاصی بود
|
||||
/// </summary>
|
||||
public virtual List<UnitInfoDto>? Units { set; get; }
|
||||
/// <summary>
|
||||
/// اگر برای واحدهای خاصی بود
|
||||
/// </summary>
|
||||
public virtual List<Guid>? UnitIds { set; get; }
|
||||
public virtual List<string>? UnitNames { set; get; }
|
||||
/// <summary>
|
||||
/// null یعنی شارژ
|
||||
/// null یعنی شارژ
|
||||
/// </summary>
|
||||
public int? IncomeCostTitleId { set; get; }
|
||||
public string? IncomeCostTitle { set; get; }
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace Complex.Application.Complex
|
||||
//وقتی واحد تازه ثبت شده پس در مدیریت شارژ قابلیت ثبت اختصاصی برای خودش نداشته پس باید شارژ عمومی برایش تعریف شود
|
||||
// اگر خواست میتواند برایش به صورت اختصاصی هم ثبت کند که اون موقع برایش محاسبه مجدد خواهد شد
|
||||
var costCycleDto = _costService.CostCyclsList(unit.ComplexId, nowDate, nowDate, null).Data
|
||||
.FirstOrDefault(c => c.UnitIds == null);
|
||||
.FirstOrDefault(c => c.Units == null);
|
||||
if (costCycleDto != null)
|
||||
{
|
||||
//var costCycle = new CostCycle
|
||||
|
||||
@@ -41,11 +41,12 @@ namespace Complex.EndPoint.Controllers
|
||||
/// <param name="EndDate"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ResultDto<List<CostCycleDto>> CostCyclsList([FromForm] Guid ComplexId, [FromForm] DateTime? StartDate = null, [FromForm] DateTime? EndDate = null)
|
||||
public ResultDto<List<CostCycleDto>> CostCyclsList([FromForm] Guid ComplexId, [FromForm] DateTime? StartDate = null, [FromForm] DateTime? EndDate = null, [FromForm] Guid? UnitId = null)
|
||||
{
|
||||
return _costCycleService.CostCyclsList(ComplexId,
|
||||
!StartDate.HasValue ? null : DateOnly.FromDateTime(StartDate.Value),
|
||||
!EndDate.HasValue ? null : DateOnly.FromDateTime(EndDate.Value));
|
||||
!EndDate.HasValue ? null : DateOnly.FromDateTime(EndDate.Value),
|
||||
UnitId: UnitId);
|
||||
}
|
||||
/// <summary>
|
||||
/// بدهی یک واحد
|
||||
|
||||
Reference in New Issue
Block a user