156 lines
5.8 KiB
C#
156 lines
5.8 KiB
C#
using AutoMapper;
|
|
using Complex.Application.Common;
|
|
using Complex.Application.Utility;
|
|
using Complex.Common.Dto;
|
|
using Complex.Domain.Commons;
|
|
using Complex.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Complex.Application.Services.TransactionServices
|
|
{
|
|
public interface ITransactionService
|
|
{
|
|
ResultDto<List<TransactionDto>> UnitsByTransStateList(Guid complexId, Guid? UnitId, CommonRequestDto commonRequestDto);
|
|
ResultDto PayCosts(List<long> UnitCostIds, Guid UnitId, long Amount, string UserPhone, string Description);
|
|
}
|
|
|
|
public class TransactionService : ITransactionService
|
|
{
|
|
private readonly IComplexDBContext _complexDBContext;
|
|
private IMapper _mapper;
|
|
|
|
public TransactionService(IComplexDBContext complexDBContext, IMapper mapper)
|
|
{
|
|
_complexDBContext = complexDBContext;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public ResultDto<List<TransactionDto>> UnitsByTransStateList(Guid complexId, Guid? UnitId, CommonRequestDto commonRequestDto)
|
|
{
|
|
var trans = _complexDBContext.Transactions.Include(t => t.TransactionTitle).Include(t => t.CostCycle).Include(t => t.Person).Where(t => t.ComplexId == complexId)
|
|
.Where(t => UnitId.HasValue ? t.UnitId == UnitId : true)
|
|
.ToPagedByOrder(commonRequestDto, out int rowCount).ToList();
|
|
var result = trans.Select(t => new TransactionDto
|
|
{
|
|
Amount = t.Amount,
|
|
CostCycleId = t.CostCycleId,
|
|
CostCycleTitle = t.CostCycle.Title,
|
|
Description = t.Description,
|
|
PersonId = t.PersonId,
|
|
PersonName = t.Person.FirstName + " " + t.Person.LastName,
|
|
TransactionDate = t.TransactionDate,
|
|
TransactionPersianDate = t.TransactionPersianDate,
|
|
TransactionTitle = t.TransactionTitle.Title,
|
|
UnitCostDate = t.UnitCost.Date,
|
|
UnitId = t.UnitId,
|
|
UnitName = t.Unit.UnitName
|
|
}).ToList();
|
|
return new ResultDto<List<TransactionDto>>
|
|
{
|
|
Data = result,
|
|
IsSuccess = true,
|
|
};
|
|
}
|
|
public ResultDto PayCosts(List<long> UnitCostIds, Guid UnitId, long Amount,
|
|
string UserPhone, string Description)
|
|
{
|
|
var costs = _complexDBContext.UnitCosts.Include(uc => uc.CostCycle)
|
|
.Where(uc => UnitCostIds.Contains(uc.Id) && !uc.TransactionId.HasValue).ToList();
|
|
var savedAmount = costs.Sum(c => c.CostCycle.Amount);
|
|
if (savedAmount != Amount)
|
|
return new ResultDto
|
|
{
|
|
IsSuccess = false,
|
|
Message = "مبلغ صحیح نمی باشد"
|
|
};
|
|
|
|
foreach (var c in costs)
|
|
{
|
|
var newTrans = new Transaction
|
|
{
|
|
PersonId = UserPhone,
|
|
TransactionDate = DateTime.Now,
|
|
Amount = c.CostCycle.Amount,
|
|
CostCycleId = c.CostCycleId,
|
|
UnitId = UnitId,
|
|
TransactionTitleId = c.CostCycle.IncomeCostTitleId,
|
|
ComplexId = c.CostCycle.ComplexId,
|
|
Description = Description,
|
|
TransactionPersianDate = PersianDate.GetDate(DateTime.Now),
|
|
UnitCostId = c.Id
|
|
};
|
|
c.Transaction = newTrans;
|
|
//_complexDBContext.Transactions.Add(newTrans);
|
|
}
|
|
_complexDBContext.SaveChanges();
|
|
return new ResultDto
|
|
{
|
|
IsSuccess = true,
|
|
Message = "ثبت با موفقیت انجام شد"
|
|
};
|
|
}
|
|
}
|
|
|
|
public class TransactionDto
|
|
{
|
|
public string TransactionTitle { set; get; }
|
|
public string TransactionPersianDate { set; get; }
|
|
public DateTime TransactionDate { set; get; }
|
|
public long Amount { set; get; } = 0;
|
|
public string? Description { set; get; }
|
|
public Guid? CostCycleId { set; get; }
|
|
public string CostCycleTitle { set; get; }
|
|
public Guid? UnitId { set; get; }
|
|
public string UnitName { set; get; }
|
|
//public string? TrackingCode { set; get; }
|
|
//public long Remaining { set; get; } = 0;
|
|
|
|
public DateOnly UnitCostDate { set; get; }
|
|
public string PersonId { set; get; }
|
|
public string PersonName { set; get; }
|
|
}
|
|
|
|
|
|
/*
|
|
public class UnitTrancactionStateDto
|
|
{
|
|
public Guid UnitId { get; set; }
|
|
public string UnitTitle { get; set; }
|
|
/// <summary>
|
|
/// مقدار شارژ پرداخت نشده
|
|
/// </summary>
|
|
public int ChargeNoPayAmount { get; set; }
|
|
/// <summary>
|
|
/// تعداد شارژ پرداخت نشده
|
|
/// </summary>
|
|
public int ChargeNoPayCount { get; set; }
|
|
/// <summary>
|
|
/// مقدار پرداخت نشده غیر شارژ
|
|
/// </summary>
|
|
public int OtherNoPayAmount { get; set; }
|
|
/// <summary>
|
|
/// میزان پرداخت کرده
|
|
/// </summary>
|
|
public long PayAmountInYear { set; get; }
|
|
/// <summary>
|
|
/// تعداد شارژ پرداخت شده
|
|
/// </summary>
|
|
public int ChargePayCountInYear { set; get; }
|
|
}
|
|
public class UnitsByTransState
|
|
{
|
|
public Guid UnitId { set; get; }
|
|
public string UnitName { set; get; }
|
|
public string UnitUserMobile { set; get; }
|
|
public string UnitUserFullName { set; get; }
|
|
public int ChargeReminigCount { set; get; }
|
|
}
|
|
*/
|
|
}
|