models
This commit is contained in:
118
Back/Services/Warehouse/ReceiptService.cs
Normal file
118
Back/Services/Warehouse/ReceiptService.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using Back.Data.Contracts;
|
||||
using Back.Data.Models.Warehouse;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shared.DTOs.Warehouse;
|
||||
using Shared.Enums;
|
||||
|
||||
namespace Back.Services.Warehouse
|
||||
{
|
||||
|
||||
public class ReceiptService
|
||||
{
|
||||
private readonly IAsyncRepository<Receipt> _ReceiptRepo;
|
||||
|
||||
public ReceiptService(IAsyncRepository<Receipt> ReceiptRepo)
|
||||
{
|
||||
_ReceiptRepo = ReceiptRepo;
|
||||
}
|
||||
|
||||
public async Task<ReceiptDto?> ADD(ReceiptDto item)
|
||||
{
|
||||
var model = new Receipt()
|
||||
{
|
||||
Date = item.Date,
|
||||
CODID = item.CODID,
|
||||
Count = item.Count,
|
||||
ForSale = item.ForSale,
|
||||
info = item.info,
|
||||
Type = item.Type,
|
||||
};
|
||||
var returnmodel = await _ReceiptRepo.AddAsync(model);
|
||||
if (returnmodel!=null)
|
||||
{
|
||||
item.ID= returnmodel.ID;
|
||||
return item;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public async Task<ReceiptDto?> Update(ReceiptDto item)
|
||||
{
|
||||
var model= await _ReceiptRepo.Get(w => w.ID == item.ID).FirstOrDefaultAsync();
|
||||
model.Date= item.Date;
|
||||
model.CODID= item.CODID;
|
||||
model.Count= item.Count;
|
||||
model.ForSale= item.ForSale;
|
||||
model.info = item.info;
|
||||
model.Type = item.Type;
|
||||
var returnmodel = await _ReceiptRepo.UpdateAsync(model);
|
||||
if (returnmodel)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public async Task<bool> Delete(int itemID,int CompanyID)
|
||||
{
|
||||
var model = await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID==CompanyID).FirstOrDefaultAsync();
|
||||
|
||||
return await _ReceiptRepo.DeleteAsync(model);
|
||||
|
||||
}
|
||||
public async Task<ReceiptDto?> Get(int itemID, int CompanyID)
|
||||
{
|
||||
return await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID)
|
||||
.Include(inc=>inc.cODItem)
|
||||
.Select(s=>new ReceiptDto()
|
||||
{
|
||||
Date = s.Date,
|
||||
CODID=s.CODID,
|
||||
Count = s.Count,
|
||||
ForSale= s.ForSale,
|
||||
ID=s.ID,
|
||||
CODTitle=s.cODItem.Title,
|
||||
info = s.info,
|
||||
Type=s.Type
|
||||
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
|
||||
|
||||
}
|
||||
public async Task<List<ReceiptDto>?> GetAll(int CompanyID, TypeReceipt? Type=null, int CODID=0)
|
||||
{
|
||||
var request = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID);
|
||||
if (Type != null)
|
||||
request = request.Where(w => w.Type == Type);
|
||||
|
||||
if (CODID != 0)
|
||||
request = request.Where(w => w.CODID == CODID);
|
||||
|
||||
|
||||
return await request
|
||||
.Include(inc => inc.cODItem)
|
||||
.Select(s => new ReceiptDto()
|
||||
{
|
||||
Date = s.Date,
|
||||
CODID = s.CODID,
|
||||
Count = s.Count,
|
||||
ForSale = s.ForSale,
|
||||
ID = s.ID,
|
||||
CODTitle = s.cODItem.Title,
|
||||
info = s.info,
|
||||
Type = s.Type
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
113
Back/Services/Warehouse/RemittanceService.cs
Normal file
113
Back/Services/Warehouse/RemittanceService.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using Back.Data.Contracts;
|
||||
using Back.Data.Models.Warehouse;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shared.DTOs.Warehouse;
|
||||
using Shared.Enums;
|
||||
|
||||
namespace Back.Services.Warehouse
|
||||
{
|
||||
public class RemittanceService
|
||||
{
|
||||
private readonly IAsyncRepository<Remittance> _ReceiptRepo;
|
||||
|
||||
public RemittanceService(IAsyncRepository<Remittance> remittanceRepo)
|
||||
{
|
||||
_ReceiptRepo = remittanceRepo;
|
||||
}
|
||||
|
||||
public async Task<RemittanceDto?> ADD(RemittanceDto item)
|
||||
{
|
||||
var model = new Remittance()
|
||||
{
|
||||
Date = item.Date,
|
||||
CODID = item.CODID,
|
||||
Count = item.Count,
|
||||
info = item.info,
|
||||
Type = item.Type,
|
||||
};
|
||||
var returnmodel = await _ReceiptRepo.AddAsync(model);
|
||||
if (returnmodel != null)
|
||||
{
|
||||
item.ID = returnmodel.ID;
|
||||
return item;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public async Task<RemittanceDto?> Update(RemittanceDto item)
|
||||
{
|
||||
var model = await _ReceiptRepo.Get(w => w.ID == item.ID).FirstOrDefaultAsync();
|
||||
model.Date = item.Date;
|
||||
model.CODID = item.CODID;
|
||||
model.Count = item.Count;
|
||||
model.info = item.info;
|
||||
model.Type = item.Type;
|
||||
var returnmodel = await _ReceiptRepo.UpdateAsync(model);
|
||||
if (returnmodel)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public async Task<bool> Delete(int itemID, int CompanyID)
|
||||
{
|
||||
var model = await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID).FirstOrDefaultAsync();
|
||||
|
||||
return await _ReceiptRepo.DeleteAsync(model);
|
||||
|
||||
}
|
||||
public async Task<RemittanceDto?> Get(int itemID, int CompanyID)
|
||||
{
|
||||
return await _ReceiptRepo.Get(w => w.ID == itemID && w.cODItem.CompanyID == CompanyID)
|
||||
.Include(inc => inc.cODItem)
|
||||
.Select(s => new RemittanceDto()
|
||||
{
|
||||
Date = s.Date,
|
||||
CODID = s.CODID,
|
||||
Count = s.Count,
|
||||
ID = s.ID,
|
||||
CODTitle = s.cODItem.Title,
|
||||
info = s.info,
|
||||
Type = s.Type
|
||||
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
|
||||
|
||||
}
|
||||
public async Task<List<RemittanceDto>?> GetAll(int CompanyID, TypeRemittance? Type = null, int CODID = 0)
|
||||
{
|
||||
var request = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID);
|
||||
if (Type != null)
|
||||
request = request.Where(w => w.Type == Type);
|
||||
|
||||
if (CODID != 0)
|
||||
request = request.Where(w => w.CODID == CODID);
|
||||
|
||||
|
||||
return await request
|
||||
.Include(inc => inc.cODItem)
|
||||
.Select(s => new RemittanceDto()
|
||||
{
|
||||
Date = s.Date,
|
||||
CODID = s.CODID,
|
||||
Count = s.Count,
|
||||
ID = s.ID,
|
||||
CODTitle = s.cODItem.Title,
|
||||
info = s.info,
|
||||
Type = s.Type
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
65
Back/Services/Warehouse/WarehouseService.cs
Normal file
65
Back/Services/Warehouse/WarehouseService.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Back.Data.Contracts;
|
||||
using Back.Data.Models.Warehouse;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Extensions;
|
||||
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;
|
||||
}
|
||||
public async Task<List<CirculationDto>> Circulation(int CompanyID,string date="",int CODID=0)
|
||||
{
|
||||
var RequestRemittance = _RemittanceRepo.Get(w => w.cODItem.CompanyID == CompanyID)
|
||||
.Select(s=>new CirculationDto
|
||||
{
|
||||
CODID=s.CODID,
|
||||
CODTitle=s.cODItem.Title,
|
||||
Date=s.Date,
|
||||
Count=s.Count,
|
||||
info=s.info,
|
||||
Type=TypeCirculation.Remittance,
|
||||
ModelTypeID = (int)s.Type,
|
||||
ModelTypeTitle= s.Type.GetDisplayName()
|
||||
});
|
||||
if (!string.IsNullOrEmpty(date))
|
||||
RequestRemittance = RequestRemittance.Where(w => w.Date == date);
|
||||
if (CODID!=0)
|
||||
RequestRemittance = RequestRemittance.Where(w => w.CODID == CODID);
|
||||
//-----------
|
||||
var RequestReceipt = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID)
|
||||
.Select(s => new CirculationDto
|
||||
{
|
||||
CODID = s.CODID,
|
||||
CODTitle = s.cODItem.Title,
|
||||
Date = s.Date,
|
||||
Count = s.Count,
|
||||
info = s.info,
|
||||
Type = TypeCirculation.Receipt,
|
||||
ModelTypeID = (int)s.Type,
|
||||
ModelTypeTitle = s.Type.GetDisplayName()
|
||||
});
|
||||
if (!string.IsNullOrEmpty(date))
|
||||
RequestReceipt = RequestReceipt.Where(w => w.Date == date);
|
||||
if (CODID != 0)
|
||||
RequestReceipt = RequestReceipt.Where(w => w.CODID == CODID);
|
||||
|
||||
var list = await RequestReceipt.ToListAsync();
|
||||
list.AddRange(await RequestRemittance.ToListAsync());
|
||||
return list.OrderByDescending(o=>o.Date).ToList();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user