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>
|
/// <param name="IncomeCostTitleId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public ResultDto<List<CostCycleDto>> CostCyclsList(Guid ComplexId, DateOnly? StartDate = null,
|
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)
|
if (IncomeCostTitleId.HasValue && StartDate.HasValue)
|
||||||
StartDate = GetStartOfMonth(StartDate.Value);
|
StartDate = GetStartOfMonth(StartDate.Value);
|
||||||
@@ -70,6 +70,9 @@ namespace Complex.Application.Services.Basic
|
|||||||
else/*مدیریت شارژ ها فقط*/
|
else/*مدیریت شارژ ها فقط*/
|
||||||
ChargeCycleQuery = ChargeCycleQuery.Where(c => c.IncomeCostTitleId == null);
|
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
|
var ChargeCycleList = ChargeCycleQuery.ToList().Select(c => new CostCycleDto
|
||||||
{
|
{
|
||||||
ComplexId = c.ComplexId,
|
ComplexId = c.ComplexId,
|
||||||
@@ -80,8 +83,18 @@ namespace Complex.Application.Services.Basic
|
|||||||
StartDate = c.StartDate,
|
StartDate = c.StartDate,
|
||||||
Id = c.Id,
|
Id = c.Id,
|
||||||
Title = c.Title,
|
Title = c.Title,
|
||||||
UnitIds = c.Units?.Select(u => u.Id).ToList(),
|
Units = c.Units?.Select(u =>
|
||||||
UnitNames = c.Units?.Select(u => u.Id + "#" + u.UnitName).ToList(),
|
{
|
||||||
|
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,
|
IncomeCostTitleId = c.IncomeCostTitleId,
|
||||||
IncomeCostTitle = c.IncomeCostTitle?.Title
|
IncomeCostTitle = c.IncomeCostTitle?.Title
|
||||||
}).ToList();
|
}).ToList();
|
||||||
@@ -107,9 +120,12 @@ namespace Complex.Application.Services.Basic
|
|||||||
|
|
||||||
cycle = _mapper.Map<CostCycle>(costCycleDto);
|
cycle = _mapper.Map<CostCycle>(costCycleDto);
|
||||||
cycle.IncomeCostTitleId = costCycleDto.IncomeCostTitleId;
|
cycle.IncomeCostTitleId = costCycleDto.IncomeCostTitleId;
|
||||||
if (costCycleDto.UnitIds != null)
|
if (costCycleDto.Units != null)
|
||||||
cycle.Units = _complexDBContext.Units.Where(u => costCycleDto.UnitIds.Contains(u.Id)
|
{
|
||||||
|
var unitIds = costCycleDto.Units.Select(u => u.Id).ToList();
|
||||||
|
cycle.Units = _complexDBContext.Units.Where(u => unitIds.Contains(u.Id)
|
||||||
&& u.ComplexId == costCycleDto.ComplexId).ToList();
|
&& u.ComplexId == costCycleDto.ComplexId).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var u in cycle.Units)
|
foreach (var u in cycle.Units)
|
||||||
{
|
{
|
||||||
@@ -139,8 +155,11 @@ namespace Complex.Application.Services.Basic
|
|||||||
costCycleDto.StartDate = GetStartOfMonth(costCycleDto.StartDate);
|
costCycleDto.StartDate = GetStartOfMonth(costCycleDto.StartDate);
|
||||||
|
|
||||||
var newCycle = _mapper.Map<CostCycle>(costCycleDto);
|
var newCycle = _mapper.Map<CostCycle>(costCycleDto);
|
||||||
if (costCycleDto.UnitIds != null)
|
if (costCycleDto.Units != null)
|
||||||
newCycle.Units = _complexDBContext.Units.Where(u => costCycleDto.UnitIds.Contains(u.Id) && costCycleDto.ComplexId == u.ComplexId).ToList();
|
{
|
||||||
|
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)
|
//if(newCycle.Units==null)
|
||||||
//{
|
//{
|
||||||
@@ -381,6 +400,12 @@ namespace Complex.Application.Services.Basic
|
|||||||
public string? CostTitle { get; set; }
|
public string? CostTitle { get; set; }
|
||||||
public DateOnly? PaymentDate { set; get; }
|
public DateOnly? PaymentDate { set; get; }
|
||||||
}
|
}
|
||||||
|
public class UnitInfoDto
|
||||||
|
{
|
||||||
|
public Guid Id { set; get; }
|
||||||
|
public string Name { set; get; }
|
||||||
|
}
|
||||||
|
|
||||||
public class CostCycleDto
|
public class CostCycleDto
|
||||||
{
|
{
|
||||||
public Guid Id { set; get; }
|
public Guid Id { set; get; }
|
||||||
@@ -400,11 +425,7 @@ namespace Complex.Application.Services.Basic
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// اگر برای واحدهای خاصی بود
|
/// اگر برای واحدهای خاصی بود
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <summary>
|
public virtual List<UnitInfoDto>? Units { set; get; }
|
||||||
/// اگر برای واحدهای خاصی بود
|
|
||||||
/// </summary>
|
|
||||||
public virtual List<Guid>? UnitIds { set; get; }
|
|
||||||
public virtual List<string>? UnitNames { set; get; }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// null یعنی شارژ
|
/// null یعنی شارژ
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ namespace Complex.Application.Complex
|
|||||||
//وقتی واحد تازه ثبت شده پس در مدیریت شارژ قابلیت ثبت اختصاصی برای خودش نداشته پس باید شارژ عمومی برایش تعریف شود
|
//وقتی واحد تازه ثبت شده پس در مدیریت شارژ قابلیت ثبت اختصاصی برای خودش نداشته پس باید شارژ عمومی برایش تعریف شود
|
||||||
// اگر خواست میتواند برایش به صورت اختصاصی هم ثبت کند که اون موقع برایش محاسبه مجدد خواهد شد
|
// اگر خواست میتواند برایش به صورت اختصاصی هم ثبت کند که اون موقع برایش محاسبه مجدد خواهد شد
|
||||||
var costCycleDto = _costService.CostCyclsList(unit.ComplexId, nowDate, nowDate, null).Data
|
var costCycleDto = _costService.CostCyclsList(unit.ComplexId, nowDate, nowDate, null).Data
|
||||||
.FirstOrDefault(c => c.UnitIds == null);
|
.FirstOrDefault(c => c.Units == null);
|
||||||
if (costCycleDto != null)
|
if (costCycleDto != null)
|
||||||
{
|
{
|
||||||
//var costCycle = new CostCycle
|
//var costCycle = new CostCycle
|
||||||
|
|||||||
@@ -41,11 +41,12 @@ namespace Complex.EndPoint.Controllers
|
|||||||
/// <param name="EndDate"></param>
|
/// <param name="EndDate"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[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,
|
return _costCycleService.CostCyclsList(ComplexId,
|
||||||
!StartDate.HasValue ? null : DateOnly.FromDateTime(StartDate.Value),
|
!StartDate.HasValue ? null : DateOnly.FromDateTime(StartDate.Value),
|
||||||
!EndDate.HasValue ? null : DateOnly.FromDateTime(EndDate.Value));
|
!EndDate.HasValue ? null : DateOnly.FromDateTime(EndDate.Value),
|
||||||
|
UnitId: UnitId);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// بدهی یک واحد
|
/// بدهی یک واحد
|
||||||
|
|||||||
Reference in New Issue
Block a user