using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Enums;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_Core.Utilities;
|
using WIDESEA_DTO.Stock;
|
using WIDESEA_IStockService;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_StockService
|
{
|
public class PlasticContainerLedgerService : ServiceBase<Dt_PlasticContainerLedger, IRepository<Dt_PlasticContainerLedger>>, IPlasticContainerLedgerService
|
{
|
private readonly IRepository<Dt_StockInfo> _stockRepository;
|
public PlasticContainerLedgerService(IRepository<Dt_PlasticContainerLedger> BaseDal, IRepository<Dt_StockInfo> stockRepository) : base(BaseDal)
|
{
|
_stockRepository = stockRepository;
|
}
|
|
public IRepository<Dt_PlasticContainerLedger> Repository => BaseDal;
|
|
public WebResponseContent GlueLineLedgerSummary(string supplyCode)
|
{
|
|
supplyCode = supplyCode?.Trim() ?? "";
|
|
var now = DateTime.Now;
|
|
|
var borrowGroup = BaseDal.Db.Queryable<Dt_PlasticContainerLedger>()
|
.Where(x => x.SupplyCode == supplyCode)
|
.GroupBy(x => new { x.SupplyCode, x.CreateDate.Date })
|
.Select(x => new
|
{
|
x.SupplyCode,
|
CreateDate = x.CreateDate.Date,
|
BorrowQty = SqlFunc.AggregateCount(x.Id)
|
})
|
.ToList();
|
|
|
var returnedGroup = _stockRepository.Db.Queryable<Dt_StockInfo>()
|
.Where(x => x.SupplyCode == supplyCode && !string.IsNullOrEmpty(x.Remark))
|
.GroupBy(x => new { x.SupplyCode, x.BorrowTime.Date })
|
.Select(x => new
|
{
|
x.SupplyCode,
|
CreateDate = x.BorrowTime.Date,
|
ReturnedQty = SqlFunc.AggregateCount(x.Id)
|
})
|
.ToList();
|
|
var result = new List<GlueLineLedgerSummaryDTO>();
|
|
|
foreach (var item in borrowGroup)
|
{
|
result.Add(new GlueLineLedgerSummaryDTO
|
{
|
SupplyCode = item.SupplyCode,
|
BorrowTime = item.CreateDate.ToString("yyyy-MM-dd"),
|
UnreturnedQuantity = item.BorrowQty,
|
ReturnedQty = 0,
|
PendingReturnQty = item.BorrowQty
|
});
|
}
|
|
|
foreach (var item in returnedGroup)
|
{
|
result.Add(new GlueLineLedgerSummaryDTO
|
{
|
SupplyCode = item.SupplyCode,
|
BorrowTime = item.CreateDate.ToString("yyyy-MM-dd"),
|
UnreturnedQuantity = item.ReturnedQty,
|
ReturnedQty = item.ReturnedQty,
|
PendingReturnQty = 0
|
});
|
}
|
|
var filterResult = result
|
.Where(x =>
|
{
|
DateTime borrowTime = DateTime.Parse(x.BorrowTime);
|
|
if (x.PendingReturnQty > 0)
|
return true;
|
|
if (borrowTime >= now.AddMonths(-1))
|
return true;
|
|
return false;
|
})
|
.ToList();
|
|
return WebResponseContent.Instance.OK(data: filterResult);
|
}
|
|
|
public class GlueLineLedgerSummaryDTO{
|
public string SupplyCode { get; set; }
|
|
public int UnreturnedQuantity { get; set; }
|
|
public int ReturnedQty { get; set; }
|
public int PendingReturnQty { get; set; }
|
public string BorrowTime { get; set; }
|
|
|
}
|
}
|
}
|