2024-05-01 15:42:21 +03:30
|
|
|
|
using Shared.DTOs;
|
2024-04-30 16:40:05 +03:30
|
|
|
|
using Back.Data.Contracts;
|
|
|
|
|
using Back.Data.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-05-31 00:24:45 +03:30
|
|
|
|
using Back.Common;
|
2024-04-30 16:40:05 +03:30
|
|
|
|
|
|
|
|
|
namespace Back.Services
|
|
|
|
|
{
|
|
|
|
|
public class servTaxPayer
|
|
|
|
|
{
|
|
|
|
|
private readonly IAsyncRepository<SentTax> _repoSentTax;
|
2024-05-16 23:40:32 +03:30
|
|
|
|
private readonly IAsyncRepository<Pattern> _repoPattern;
|
2024-05-31 00:24:45 +03:30
|
|
|
|
private readonly IAsyncRepository<Invoice> _invoiceRepo;
|
2024-06-01 12:58:04 +03:30
|
|
|
|
private readonly IAsyncRepository<FildModeInPattern> _fildModeInPatternRepo;
|
|
|
|
|
private readonly IAsyncRepository<Coding> _codingRepo;
|
|
|
|
|
private readonly IAsyncRepository<SpecialCondition> _specialConditionRepo;
|
2024-05-31 00:24:45 +03:30
|
|
|
|
public servTaxPayer(IAsyncRepository<SentTax> repoSentTax, IAsyncRepository<Pattern> repoPattern
|
2024-06-01 12:58:04 +03:30
|
|
|
|
, IAsyncRepository<Invoice> invoiceRepo, IAsyncRepository<FildModeInPattern> fildModeInPatternRepo
|
|
|
|
|
, IAsyncRepository<Coding> codingRepo, IAsyncRepository<SpecialCondition> specialConditionRepo)
|
2024-04-30 16:40:05 +03:30
|
|
|
|
{
|
|
|
|
|
_repoSentTax = repoSentTax;
|
2024-05-16 23:40:32 +03:30
|
|
|
|
_repoPattern = repoPattern;
|
2024-05-31 00:24:45 +03:30
|
|
|
|
_invoiceRepo = invoiceRepo;
|
2024-06-01 12:58:04 +03:30
|
|
|
|
_fildModeInPatternRepo = fildModeInPatternRepo;
|
|
|
|
|
_codingRepo = codingRepo;
|
|
|
|
|
_specialConditionRepo = specialConditionRepo;
|
2024-04-30 16:40:05 +03:30
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
2024-05-13 16:50:26 +03:30
|
|
|
|
public async Task<bool> ExistSuccessfulorSendorpendingInvoice(Invoice invoice)
|
|
|
|
|
{
|
2024-05-25 21:30:11 +03:30
|
|
|
|
return _repoSentTax.Get(w => w.InvoiceType == invoice.invoiceType && w.InvoiceID == invoice.ID &&
|
2024-05-13 16:50:26 +03:30
|
|
|
|
(w.SentStatus == SentStatus.Successful || w.SentStatus == SentStatus.Send || w.SentStatus == SentStatus.pending)).Any();
|
|
|
|
|
}
|
2024-04-30 16:40:05 +03:30
|
|
|
|
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();
|
|
|
|
|
}
|
2024-05-16 23:40:32 +03:30
|
|
|
|
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();
|
2024-04-30 16:40:05 +03:30
|
|
|
|
|
2024-05-16 23:40:32 +03:30
|
|
|
|
}
|
2024-05-31 00:24:45 +03:30
|
|
|
|
|
|
|
|
|
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
|
2024-06-01 12:58:04 +03:30
|
|
|
|
.Include(inc => inc.Customer)
|
|
|
|
|
.Include(inc => inc.company)
|
|
|
|
|
.Include(inc => inc.company)
|
|
|
|
|
.Include(inc => inc.pattern)
|
2024-06-07 22:07:04 +03:30
|
|
|
|
.ThenInclude(inc => inc.BillType)
|
2024-06-01 12:58:04 +03:30
|
|
|
|
.Include(inc => inc.payments)
|
|
|
|
|
.Include(inc => inc.invoice)
|
2024-05-31 00:24:45 +03:30
|
|
|
|
.Include(inc => inc.invoiceDetails)
|
|
|
|
|
.ThenInclude(inc => inc.cODItem)
|
|
|
|
|
.ThenInclude(inc => inc.CODUnit)
|
|
|
|
|
.FirstOrDefaultAsync();
|
|
|
|
|
}
|
2024-06-01 12:58:04 +03:30
|
|
|
|
|
|
|
|
|
public async Task<_TaxPayer.Atemplatefield> GetFildInvoiceForPreparation(Invoice InvoiceItem)
|
|
|
|
|
{
|
|
|
|
|
_TaxPayer.Atemplatefield ret = new _TaxPayer.Atemplatefield();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var invok = _fildModeInPatternRepo.Get
|
|
|
|
|
(w => w.PatternID == InvoiceItem.PatternID && w.FildModeID != 4 && (w.Fild.InputBox == "fild" || w.Fild.InputBox == "fromdb" || w.Fild.InputBox == "autofild") && w.pattern.Status);
|
|
|
|
|
|
|
|
|
|
//-----------------------head
|
|
|
|
|
var head = await invok.Where(w => w.Fild.Title == "H").Select(s => new _TaxPayer.Fild()
|
|
|
|
|
{
|
|
|
|
|
FildID = s.FildID,
|
|
|
|
|
eName = s.Fild.Name == "indatim" ? "InvoicIssueDate" : s.Fild.Name == "Indati2m" ? "InvoiceDate" : s.Fild.Name == "cdcd" ? "CottageDateOfCustomsDeclaration" : s.Fild.Name,
|
|
|
|
|
fName = s.Fild.Type,
|
|
|
|
|
ModeID = s.FildModeID,
|
|
|
|
|
ModeTitle = s.FildMode.Title,
|
|
|
|
|
Title = s.Fild.Title,
|
|
|
|
|
InputBox = s.Fild.Name == "indatim" || s.Fild.Name == "Indati2m" || s.Fild.Name == "cdcd" ? "fild" : s.Fild.InputBox
|
|
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
foreach (_TaxPayer.Fild item in head)
|
|
|
|
|
{
|
|
|
|
|
var resval = InvoiceItem.GetType().GetProperties().Where(w => w.Name == item.eName).Select(s => s.GetValue(InvoiceItem)).FirstOrDefault();
|
|
|
|
|
item.Value = resval == null ? "" : (item.eName == "InvoicIssueDate" || item.eName == "InvoiceDate" || item.eName == "CottageDateOfCustomsDeclaration" ? resval.ToString().ShamciToFormatShamci() : resval.ToString());
|
|
|
|
|
item.DefVals = item.InputBox == "fromdb" ? _codingRepo.Get(w => w.FildID == item.FildID).Select(ss => new _TaxPayer.Coding() { ID = ss.Code, Name = ss.Title }).ToList() : new List<_TaxPayer.Coding>();
|
|
|
|
|
item.Des = item.ModeID == 3 ? _specialConditionRepo.Get(w => w.FildID == item.FildID).Select(ss => ss.condition).ToArray() : null;
|
|
|
|
|
}
|
|
|
|
|
ret.header = new _TaxPayer.Filds() { ID = InvoiceItem.ID, filds = head };
|
|
|
|
|
//-------------------body
|
|
|
|
|
var body = await invok.Where(w => w.Fild.Title == "B").Select(s => new _TaxPayer.Fild()
|
|
|
|
|
{
|
|
|
|
|
FildID = s.FildID,
|
|
|
|
|
eName = s.Fild.Name,
|
|
|
|
|
fName = s.Fild.Type,
|
|
|
|
|
ModeID = s.FildModeID,
|
|
|
|
|
ModeTitle = s.FildMode.Title,
|
|
|
|
|
Title = s.Fild.Title,
|
|
|
|
|
InputBox = s.Fild.InputBox
|
|
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
foreach (var invoicedetail in InvoiceItem.invoiceDetails)
|
|
|
|
|
{
|
|
|
|
|
foreach (_TaxPayer.Fild item in body)
|
|
|
|
|
{
|
2024-06-07 22:07:04 +03:30
|
|
|
|
var resval = invoicedetail.GetType().GetProperties().Where(w => w.Name == item.eName).Select(s => s.GetValue(invoicedetail)).FirstOrDefault();
|
2024-06-01 12:58:04 +03:30
|
|
|
|
item.Value = resval == null ? "" : resval.ToString();
|
|
|
|
|
item.DefVals = item.InputBox == "fromdb" ? _codingRepo.Get(w => w.FildID == item.FildID).Select(ss => new _TaxPayer.Coding() { ID = ss.Code, Name = ss.Title }).ToList() : new List<_TaxPayer.Coding>();
|
|
|
|
|
item.Des = item.ModeID == 3 ? _specialConditionRepo.Get(w => w.FildID == item.FildID).Select(ss => ss.condition).ToArray() : null;
|
|
|
|
|
}
|
|
|
|
|
ret.Bodys.Add(new _TaxPayer.Filds() { ID = invoicedetail.ID, filds = body });
|
|
|
|
|
}
|
|
|
|
|
//-----------------payment
|
|
|
|
|
var pay = await invok.Where(w => w.Fild.Title == "P").Select(s => new _TaxPayer.Fild()
|
|
|
|
|
{
|
|
|
|
|
FildID = s.FildID,
|
|
|
|
|
eName = s.Fild.Name == "pdt" ? "PaymentDateTime" : s.Fild.Name,
|
|
|
|
|
fName = s.Fild.Type,
|
|
|
|
|
ModeID = s.FildModeID,
|
|
|
|
|
ModeTitle = s.FildMode.Title,
|
|
|
|
|
Title = s.Fild.Title,
|
|
|
|
|
InputBox = s.Fild.Name == "pdt" ? "fild" : s.Fild.InputBox
|
|
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
foreach (var invoicepay in InvoiceItem.payments)
|
|
|
|
|
{
|
|
|
|
|
foreach (_TaxPayer.Fild item in pay)
|
|
|
|
|
{
|
2024-06-07 22:07:04 +03:30
|
|
|
|
var resval = InvoiceItem.payments.GetType().GetProperties().Where(w => w.Name == item.eName).Select(s => s.GetValue(InvoiceItem.payments)).FirstOrDefault();
|
2024-06-01 12:58:04 +03:30
|
|
|
|
item.Value = resval == null ? "" : resval.ToString();
|
|
|
|
|
item.DefVals = item.InputBox == "fromdb" ? _codingRepo.Get(w => w.FildID == item.FildID).Select(ss => new _TaxPayer.Coding() { ID = ss.Code, Name = ss.Title }).ToList() : new List<_TaxPayer.Coding>();
|
|
|
|
|
item.Des = item.ModeID == 3 ? _specialConditionRepo.Get(w => w.FildID == item.FildID).Select(ss => ss.condition).ToArray() : null;
|
|
|
|
|
}
|
|
|
|
|
ret.Payments.Add(new _TaxPayer.Filds() { ID = invoicepay.ID, filds = pay });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2024-04-30 16:40:05 +03:30
|
|
|
|
}
|
|
|
|
|
}
|