Files
moadiran/Back/Services/servTaxPayer.cs
mmrbnjd 131330041c ...
2024-05-31 00:24:45 +03:30

59 lines
2.6 KiB
C#

using Shared.DTOs;
using Back.Data.Contracts;
using Back.Data.Models;
using Microsoft.EntityFrameworkCore;
using Back.Common;
namespace Back.Services
{
public class servTaxPayer
{
private readonly IAsyncRepository<SentTax> _repoSentTax;
private readonly IAsyncRepository<Pattern> _repoPattern;
private readonly IAsyncRepository<Invoice> _invoiceRepo;
public servTaxPayer(IAsyncRepository<SentTax> repoSentTax, IAsyncRepository<Pattern> repoPattern
, IAsyncRepository<Invoice> invoiceRepo)
{
_repoSentTax = repoSentTax;
_repoPattern = repoPattern;
_invoiceRepo = invoiceRepo;
}
public async Task<bool> ExistSuccessfulorSendorpendingInvoiceinCompanyID(int CompanyID)
{
return await _repoSentTax.Get(w => w.invoice.CompanyID == CompanyID && (w.SentStatus == SentStatus.Successful || w.SentStatus == SentStatus.Send || w.SentStatus == SentStatus.pending)).AnyAsync();
}
public async Task<bool> ExistSuccessfulorSendorpendingInvoice(Invoice invoice)
{
return _repoSentTax.Get(w => w.InvoiceType == invoice.invoiceType && w.InvoiceID == invoice.ID &&
(w.SentStatus == SentStatus.Successful || w.SentStatus == SentStatus.Send || w.SentStatus == SentStatus.pending)).Any();
}
public async Task<bool> CheckingTheCompanyKeyInformation(int CompanyID, string UniqeMemory, string PrivateKey, string EconomicCode)
{
return await _repoSentTax.Get(w => (w.invoice.company.UniqeMemory == UniqeMemory || w.invoice.company.PrivateKey == PrivateKey || w.invoice.company.EconomicCode == EconomicCode)
&& (w.SentStatus == SentStatus.Successful || w.SentStatus == SentStatus.Send || w.SentStatus == SentStatus.pending)
&& w.invoice.CompanyID != CompanyID).AnyAsync();
}
public async Task<List<IdName<int>>> GetPatterns()
{
return await _repoPattern.Get(w=>w.Status).Select(s => new IdName<int> { ID = s.ID, Title = s.Title }).ToListAsync();
}
public async Task<Invoice?> GetInvoice(int CompanyID, int ID)
{
#region AdvancedSearch
var invok = _invoiceRepo
.Get(w => w.CompanyID == CompanyID && w.ID == ID && !w.IsDeleted);
#endregion
//-----------------------
return await invok
.Include(inc => inc.invoiceDetails)
.ThenInclude(inc => inc.cODItem)
.ThenInclude(inc => inc.CODUnit)
.FirstOrDefaultAsync();
}
}
}