From 6d03fedbebc40ac02e7d24467afceeae08842a03 Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Sat, 11 Jan 2025 10:10:47 +0330 Subject: [PATCH] models --- .../Persistence/SqlDbContext.cs | 3 + Back/Data/Models/CODItem.cs | 5 +- Back/Data/Models/Warehouse/Receipt.cs | 21 ++++ Back/Data/Models/Warehouse/Remittance.cs | 20 +++ Back/Services/Warehouse/ReceiptService.cs | 118 ++++++++++++++++++ Back/Services/Warehouse/RemittanceService.cs | 113 +++++++++++++++++ Back/Services/Warehouse/WarehouseService.cs | 65 ++++++++++ Shared/DTOs/Warehouse/CirculationDto.cs | 31 +++++ Shared/DTOs/Warehouse/ReceiptDto.cs | 21 ++++ Shared/DTOs/Warehouse/RemittanceDto.cs | 20 +++ Shared/Enums/TypeReceipt.cs | 17 +++ Shared/Enums/TypeRemittance.cs | 17 +++ 12 files changed, 450 insertions(+), 1 deletion(-) create mode 100644 Back/Data/Models/Warehouse/Receipt.cs create mode 100644 Back/Data/Models/Warehouse/Remittance.cs create mode 100644 Back/Services/Warehouse/ReceiptService.cs create mode 100644 Back/Services/Warehouse/RemittanceService.cs create mode 100644 Back/Services/Warehouse/WarehouseService.cs create mode 100644 Shared/DTOs/Warehouse/CirculationDto.cs create mode 100644 Shared/DTOs/Warehouse/ReceiptDto.cs create mode 100644 Shared/DTOs/Warehouse/RemittanceDto.cs create mode 100644 Shared/Enums/TypeReceipt.cs create mode 100644 Shared/Enums/TypeRemittance.cs diff --git a/Back/Data/Infrastructure/Persistence/SqlDbContext.cs b/Back/Data/Infrastructure/Persistence/SqlDbContext.cs index 6776274..f55f612 100644 --- a/Back/Data/Infrastructure/Persistence/SqlDbContext.cs +++ b/Back/Data/Infrastructure/Persistence/SqlDbContext.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using Back.Data.Models; +using Back.Data.Models.Warehouse; namespace TaxPayer.Infrastructure.Persistence { @@ -50,6 +51,8 @@ namespace TaxPayer.Infrastructure.Persistence public DbSet Promotions { get; set; } public DbSet PromotionDetails { get; set; } public DbSet CreditDocuments { get; set; } + public DbSet Receipts { get; set; } + public DbSet Remittances { get; set; } #endregion //public override Task SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken()) //{ diff --git a/Back/Data/Models/CODItem.cs b/Back/Data/Models/CODItem.cs index 4fcaa39..836249d 100644 --- a/Back/Data/Models/CODItem.cs +++ b/Back/Data/Models/CODItem.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using Back.Data.Models.Warehouse; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace Back.Data.Models @@ -21,6 +22,8 @@ namespace Back.Data.Models [ForeignKey("CompanyID")] public virtual Company Company { get; set; } public virtual ICollection invoiceDetails { get; set; } + public virtual ICollection Receipts { get; set; } + public virtual ICollection Remittances { get; set; } #endregion } } diff --git a/Back/Data/Models/Warehouse/Receipt.cs b/Back/Data/Models/Warehouse/Receipt.cs new file mode 100644 index 0000000..f4aaa71 --- /dev/null +++ b/Back/Data/Models/Warehouse/Receipt.cs @@ -0,0 +1,21 @@ +using Shared.Enums; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Back.Data.Models.Warehouse +{ + + //رسید + public class Receipt + { + public int ID { get; set; } + public int CODID { get; set; } + public int Count { get; set; } + public string Date { get; set; } + public bool ForSale { get; set; } + public TypeReceipt Type { get; set; } + public string info { get; set; } + + [ForeignKey("CODID")] + public CODItem cODItem { get; set; } + } +} \ No newline at end of file diff --git a/Back/Data/Models/Warehouse/Remittance.cs b/Back/Data/Models/Warehouse/Remittance.cs new file mode 100644 index 0000000..7b4058a --- /dev/null +++ b/Back/Data/Models/Warehouse/Remittance.cs @@ -0,0 +1,20 @@ +using Shared.Enums; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Back.Data.Models.Warehouse +{ + + //حواله + public class Remittance + { + public int ID { get; set; } + public int CODID { get; set; } + public int Count { get; set; } + public string Date { get; set; } + public TypeRemittance Type { get; set; } + public string info { get; set; } + + [ForeignKey("CODID")] + public CODItem cODItem { get; set; } + } +} diff --git a/Back/Services/Warehouse/ReceiptService.cs b/Back/Services/Warehouse/ReceiptService.cs new file mode 100644 index 0000000..72732a5 --- /dev/null +++ b/Back/Services/Warehouse/ReceiptService.cs @@ -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 _ReceiptRepo; + + public ReceiptService(IAsyncRepository ReceiptRepo) + { + _ReceiptRepo = ReceiptRepo; + } + + public async Task 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 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 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 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?> 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(); + + + + } + } + +} diff --git a/Back/Services/Warehouse/RemittanceService.cs b/Back/Services/Warehouse/RemittanceService.cs new file mode 100644 index 0000000..ab3ee1a --- /dev/null +++ b/Back/Services/Warehouse/RemittanceService.cs @@ -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 _ReceiptRepo; + + public RemittanceService(IAsyncRepository remittanceRepo) + { + _ReceiptRepo = remittanceRepo; + } + + public async Task 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 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 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 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?> 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(); + + + + } + + } +} diff --git a/Back/Services/Warehouse/WarehouseService.cs b/Back/Services/Warehouse/WarehouseService.cs new file mode 100644 index 0000000..65f5e77 --- /dev/null +++ b/Back/Services/Warehouse/WarehouseService.cs @@ -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 _RemittanceRepo; + private readonly IAsyncRepository _ReceiptRepo; + + public WarehouseService(IAsyncRepository remittanceRepo, IAsyncRepository receiptRepo) + { + _RemittanceRepo = remittanceRepo; + _ReceiptRepo = receiptRepo; + } + public async Task> 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(); + } + } +} diff --git a/Shared/DTOs/Warehouse/CirculationDto.cs b/Shared/DTOs/Warehouse/CirculationDto.cs new file mode 100644 index 0000000..5954b07 --- /dev/null +++ b/Shared/DTOs/Warehouse/CirculationDto.cs @@ -0,0 +1,31 @@ +using Shared.Enums; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTOs.Warehouse +{ + public enum TypeCirculation + { + [Display(Name = "رسید")] + Receipt, + + [Display(Name = "حواله")] + Remittance + } + public class CirculationDto + { + public int CODID { get; set; } + public string? CODTitle { get; set; } + public int Count { get; set; } + public string Date { get; set; } + public bool? ForSale { get; set; } + public string ModelTypeTitle { get; set; } + public int ModelTypeID { get; set; } + public string info { get; set; } + public TypeCirculation Type { get; set; } + } +} diff --git a/Shared/DTOs/Warehouse/ReceiptDto.cs b/Shared/DTOs/Warehouse/ReceiptDto.cs new file mode 100644 index 0000000..6a5ded4 --- /dev/null +++ b/Shared/DTOs/Warehouse/ReceiptDto.cs @@ -0,0 +1,21 @@ +using Shared.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTOs.Warehouse +{ + public class ReceiptDto + { + public int? ID { get; set; } + public int CODID { get; set; } + public string? CODTitle { get; set; } + public int Count { get; set; } + public string Date { get; set; } + public bool ForSale { get; set; } + public TypeReceipt Type { get; set; } + public string info { get; set; } + } +} diff --git a/Shared/DTOs/Warehouse/RemittanceDto.cs b/Shared/DTOs/Warehouse/RemittanceDto.cs new file mode 100644 index 0000000..0110099 --- /dev/null +++ b/Shared/DTOs/Warehouse/RemittanceDto.cs @@ -0,0 +1,20 @@ +using Shared.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTOs.Warehouse +{ + public class RemittanceDto + { + public int? ID { get; set; } + public int CODID { get; set; } + public string CODTitle { get; set; } + public int Count { get; set; } + public string Date { get; set; } + public TypeRemittance Type { get; set; } + public string info { get; set; } + } +} diff --git a/Shared/Enums/TypeReceipt.cs b/Shared/Enums/TypeReceipt.cs new file mode 100644 index 0000000..118539b --- /dev/null +++ b/Shared/Enums/TypeReceipt.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.Enums +{ + public enum TypeReceipt + { + [Display(Name = "خرید")] + Shopping=1, + [Display(Name = "امانت")] + trust=2 + } +} diff --git a/Shared/Enums/TypeRemittance.cs b/Shared/Enums/TypeRemittance.cs new file mode 100644 index 0000000..8fcf199 --- /dev/null +++ b/Shared/Enums/TypeRemittance.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.Enums +{ + public enum TypeRemittance + { + [Display(Name = "فروش")] + Sale=3, + [Display(Name = "امانت")] + trust=4 + } +}