Files
moadiran/Back/Services/Warehouse/WarehouseService.cs

90 lines
3.9 KiB
C#
Raw Normal View History

2025-01-23 02:44:11 +03:30

using Back.Common;
2025-01-11 12:42:36 +03:30
using Back.Data.Contracts;
2025-01-11 10:10:47 +03:30
using Back.Data.Models.Warehouse;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Extensions;
2025-01-11 12:42:36 +03:30
using Shared.DTOs;
2025-01-11 10:10:47 +03:30
using Shared.DTOs.Warehouse;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Back.Services.Warehouse
{
public class WarehouseService
{
private readonly IAsyncRepository<Remittance> _RemittanceRepo;
private readonly IAsyncRepository<Receipt> _ReceiptRepo;
public WarehouseService(IAsyncRepository<Remittance> remittanceRepo, IAsyncRepository<Receipt> receiptRepo)
{
_RemittanceRepo = remittanceRepo;
_ReceiptRepo = receiptRepo;
}
2025-01-22 13:02:53 +03:30
public async Task<PagingDto<CirculationDto>> Circulation(int CompanyID, string date = "", int CODID = 0, int PageIndex = 1, int PageSize = 5)
2025-01-11 10:10:47 +03:30
{
2025-01-19 17:44:20 +03:30
var RequestRemittance = _RemittanceRepo.Get(w => w.cODItem.CompanyID == CompanyID && !w.Deleted)
2025-01-22 13:02:53 +03:30
.Select(s => new CirculationDto
2025-01-11 10:10:47 +03:30
{
2025-01-22 13:02:53 +03:30
ID= s.ID,
CODID = s.CODID,
CODTitle = s.cODItem.Title,
Date = s.Date.ShamciToFormatShamci(),
Count = s.Count,
info = s.info,
Type = TypeCirculation.Remittance,
2025-01-11 10:10:47 +03:30
ModelTypeID = (int)s.Type,
2025-01-23 02:44:11 +03:30
ModelTypeTitle = s.Type.GetEnumDisplayName(),
2025-01-22 13:02:53 +03:30
invoiceID = s.InvoiceID,
2025-01-25 20:46:47 +03:30
CreateDt = s.CreateDt,
2025-01-11 10:10:47 +03:30
});
if (!string.IsNullOrEmpty(date))
RequestRemittance = RequestRemittance.Where(w => w.Date == date);
2025-01-22 13:02:53 +03:30
if (CODID != 0)
2025-01-11 10:10:47 +03:30
RequestRemittance = RequestRemittance.Where(w => w.CODID == CODID);
//-----------
2025-01-19 17:44:20 +03:30
var RequestReceipt = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID && !w.Deleted)
2025-01-11 10:10:47 +03:30
.Select(s => new CirculationDto
{
2025-01-22 13:02:53 +03:30
ID = s.ID,
2025-01-11 10:10:47 +03:30
CODID = s.CODID,
CODTitle = s.cODItem.Title,
2025-01-22 13:02:53 +03:30
Date = s.Date.ShamciToFormatShamci(),
2025-01-11 10:10:47 +03:30
Count = s.Count,
info = s.info,
Type = TypeCirculation.Receipt,
ModelTypeID = (int)s.Type,
2025-01-23 02:44:11 +03:30
ModelTypeTitle = s.Type.GetEnumDisplayName(),
2025-01-22 13:02:53 +03:30
invoiceID = s.InvoiceID,
2025-01-23 02:44:11 +03:30
ForSale = s.ForSale,
2025-01-25 20:46:47 +03:30
CreateDt = s.CreateDt,
2025-01-11 10:10:47 +03:30
});
if (!string.IsNullOrEmpty(date))
RequestReceipt = RequestReceipt.Where(w => w.Date == date);
if (CODID != 0)
RequestReceipt = RequestReceipt.Where(w => w.CODID == CODID);
2025-01-23 02:44:11 +03:30
var itemsReceipt = await RequestReceipt.ToListAsync();
var Remittance = await RequestRemittance.ToListAsync();
2025-01-22 13:55:20 +03:30
2025-01-23 02:44:11 +03:30
2025-01-25 20:46:47 +03:30
return await itemsReceipt.Union(Remittance).OrderByDescending(o => o.CreateDt).Paging(PageIndex, PageSize);
2025-01-23 02:44:11 +03:30
// return await RequestReceipt.Union(RequestRemittance).OrderByDescending(o => o.Date).Paging(PageIndex, PageSize);
2025-01-11 12:42:36 +03:30
//var list = await RequestReceipt.ToListAsync();
//list.AddRange(await RequestRemittance.ToListAsync());
//return await list.OrderByDescending(o=>o.Date).AsQueryable().Paging(PageIndex, PageSize);
}
2025-01-22 13:02:53 +03:30
public async Task<decimal> Inventory(int CompanyID, int CODID)
2025-01-11 12:42:36 +03:30
{
2025-01-22 13:02:53 +03:30
var CReceipt = await _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID && w.CODID == CODID && w.ForSale && !w.Deleted).SumAsync(s => s.Count);
var CRemittance = await _RemittanceRepo.Get(w => w.cODItem.CompanyID == CompanyID && w.CODID == CODID && !w.Deleted).SumAsync(s => s.Count);
2025-01-11 23:03:16 +03:30
return CReceipt - CRemittance;
2025-01-11 10:10:47 +03:30
}
}
}