...
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Back.Common;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using TaxCollectData.Library.Business;
|
||||
using TaxCollectData.Library.Dto.Config;
|
||||
using TaxCollectData.Library.Dto.Content;
|
||||
@@ -8,32 +9,23 @@ using TaxCollectData.Library.Enums;
|
||||
|
||||
namespace Back.Services
|
||||
{
|
||||
public class ActionTaxPayer : IDisposable
|
||||
public class ActionTaxPayer
|
||||
{
|
||||
private string _UniqueMemory;
|
||||
public ActionTaxPayer(string UniqueMemory, string PrivateKey)
|
||||
private string _PrivateKey;
|
||||
private readonly servCompany _servCompany;
|
||||
public ActionTaxPayer(servCompany servCompany)
|
||||
{
|
||||
#region TokenTax
|
||||
if (!string.IsNullOrEmpty(UniqueMemory) && !string.IsNullOrEmpty(PrivateKey))
|
||||
{
|
||||
_UniqueMemory = UniqueMemory;
|
||||
|
||||
TaxApiService.Instance.Init(UniqueMemory,
|
||||
new SignatoryConfig(PrivateKey, null),
|
||||
new NormalProperties(ClientType.SELF_TSP), "https://tp.tax.gov.ir/req/api/");
|
||||
TaxApiService.Instance.TaxApis.GetServerInformation();
|
||||
}
|
||||
#endregion
|
||||
_servCompany = servCompany;
|
||||
}
|
||||
public string GenerateTaxid(string FactorNo, string InvoiceDate)
|
||||
{
|
||||
return TaxApiService.Instance.TaxIdGenerator.GenerateTaxId(_UniqueMemory,
|
||||
Convert.ToInt64(FactorNo), InvoiceDate.ToMiladi());
|
||||
}
|
||||
|
||||
public InquiryResultModel GetResultByUid(string uid)
|
||||
public async Task<InquiryResultModel> GetResultByUid(int CompanyID, string uid)
|
||||
{
|
||||
if (!login())
|
||||
if (!await login(CompanyID))
|
||||
return null;
|
||||
var uidAndFiscalId = new UidAndFiscalId(uid, _UniqueMemory);
|
||||
var inquiryResultModels = TaxApiService.Instance.TaxApis.InquiryByUidAndFiscalId(new() { uidAndFiscalId });
|
||||
@@ -41,45 +33,58 @@ namespace Back.Services
|
||||
return inquiryResultModels[0];
|
||||
return null;
|
||||
}
|
||||
public TaxCollectData.Library.Dto.HttpResponse<AsyncResponseModel> SendInvoice(InvoiceHeaderDto header, List<InvoiceBodyDto> InvoiceBody, PaymentDto payment)
|
||||
public async Task<TaxCollectData.Library.Dto.HttpResponse<AsyncResponseModel>> SendInvoice(int CompanyID,InvoiceHeaderDto header, List<InvoiceBodyDto> InvoiceBody, PaymentDto payment)
|
||||
{
|
||||
if (!login())
|
||||
if (!await login(CompanyID))
|
||||
return null;
|
||||
return TaxApiService.Instance.TaxApis.SendInvoices(new List<InvoiceDto>()
|
||||
return await TaxApiService.Instance.TaxApis.SendInvoicesAsync(new List<InvoiceDto>()
|
||||
{
|
||||
new InvoiceDto()
|
||||
new()
|
||||
{
|
||||
Header =header,Body =InvoiceBody,Payments = new() {payment}
|
||||
}
|
||||
}
|
||||
, null);
|
||||
}
|
||||
public EconomicCodeModel? GetEconomicCodeInformation(string Item)
|
||||
public async Task<EconomicCodeModel?> GetEconomicCodeInformation(string Item)
|
||||
{
|
||||
return TaxApiService.Instance.TaxApis.GetEconomicCodeInformation(Item);
|
||||
return await TaxApiService.Instance.TaxApis.GetEconomicCodeInformationAsync(Item);
|
||||
}
|
||||
//-------------------internal
|
||||
public bool login()
|
||||
public async Task<bool> login(int CompanyID)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region TokenTax
|
||||
var resquth = await _servCompany.GetTaxAuth(CompanyID);
|
||||
if (string.IsNullOrEmpty(resquth.UniqueMemory) || string.IsNullOrEmpty(resquth.PrivateKey))
|
||||
return false;
|
||||
|
||||
if (!string.IsNullOrEmpty(resquth.UniqueMemory) && !string.IsNullOrEmpty(resquth.PrivateKey))
|
||||
{
|
||||
_UniqueMemory = resquth.UniqueMemory;
|
||||
_PrivateKey = resquth.PrivateKey;
|
||||
TaxApiService.Instance.Init(_UniqueMemory,
|
||||
new SignatoryConfig(_PrivateKey, null),
|
||||
new NormalProperties(ClientType.SELF_TSP), "https://tp.tax.gov.ir/req/api/");
|
||||
await TaxApiService.Instance.TaxApis.GetServerInformationAsync();
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (TaxApiService.Instance.TaxApis.GetToken() is null)
|
||||
{
|
||||
if(TaxApiService.Instance.TaxApis.RequestToken()==null)
|
||||
return false;
|
||||
if (await TaxApiService.Instance.TaxApis.RequestTokenAsync() == null)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -18,38 +18,38 @@ namespace Back.Services
|
||||
_repoCompany = repoCompany;
|
||||
_repoRolUser = repoRolUser;
|
||||
}
|
||||
public async Task<bool> ExsistCompanyByComoanyIDandUserID(int ComoanyID, int UserID,bool InAdmin=false)
|
||||
public async Task<bool> ExsistCompanyByComoanyIDandUserID(int ComoanyID, int UserID, bool InAdmin = false)
|
||||
{
|
||||
var res= _repoRolUser.Get(w => w.CompanyID == ComoanyID && w.UserID == UserID && w.Company.IsActive);
|
||||
var res = _repoRolUser.Get(w => w.CompanyID == ComoanyID && w.UserID == UserID && w.Company.IsActive);
|
||||
if (InAdmin)
|
||||
res = res.Where( w=> w.IsAdmin);
|
||||
res = res.Where(w => w.IsAdmin);
|
||||
|
||||
return await res.AnyAsync();
|
||||
return await res.AnyAsync();
|
||||
}
|
||||
public async Task<CompanyDTO?> GetCompany(int ComoanyID)
|
||||
{
|
||||
return await _repoCompany.Get(w => w.ID == ComoanyID && w.IsActive)
|
||||
.Select(s=>new CompanyDTO()
|
||||
{
|
||||
BranchID = s.BranchID,
|
||||
EconomicCode = s.EconomicCode,
|
||||
ID = s.ID,
|
||||
Email = s.Email,
|
||||
Logo= s.Logo==null ?null: System.Text.Encoding.UTF8.GetString(s.Logo) ,
|
||||
Mobile = s.Mobile,
|
||||
Name = s.Name,
|
||||
Phone = s.Phone,
|
||||
PrivateKey= s.PrivateKey,
|
||||
UniqeMemory = s.UniqeMemory
|
||||
}).FirstOrDefaultAsync();
|
||||
return await _repoCompany.Get(w => w.ID == ComoanyID && w.IsActive)
|
||||
.Select(s => new CompanyDTO()
|
||||
{
|
||||
BranchID = s.BranchID,
|
||||
EconomicCode = s.EconomicCode,
|
||||
ID = s.ID,
|
||||
Email = s.Email,
|
||||
Logo = s.Logo == null ? null : System.Text.Encoding.UTF8.GetString(s.Logo),
|
||||
Mobile = s.Mobile,
|
||||
Name = s.Name,
|
||||
Phone = s.Phone,
|
||||
PrivateKey = s.PrivateKey,
|
||||
UniqeMemory = s.UniqeMemory
|
||||
}).FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task<Company?> GetCompanyOrg(int ComoanyID,bool IsActive=true)
|
||||
public async Task<Company?> GetCompanyOrg(int ComoanyID, bool IsActive = true)
|
||||
{
|
||||
var inv = _repoCompany.Get(w => w.ID == ComoanyID);
|
||||
if (IsActive)
|
||||
inv= inv.Where(w=>w.IsActive);
|
||||
|
||||
return await inv.FirstOrDefaultAsync();
|
||||
inv = inv.Where(w => w.IsActive);
|
||||
|
||||
return await inv.FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task<Company?> GetCompanyOrgByMobileAndCompanynotActive(string Mobile)
|
||||
{
|
||||
@@ -72,16 +72,16 @@ namespace Back.Services
|
||||
//};
|
||||
//_contextMongodb.InsertItem(log);
|
||||
|
||||
if (item.ID == null || item.ID ==0)
|
||||
if (item.ID == null || item.ID == 0)
|
||||
{
|
||||
return await _repoCompany.AddAsync(item);
|
||||
return await _repoCompany.AddAsync(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
return await _repoCompany.UpdateByObjAsync(item);
|
||||
return await _repoCompany.UpdateByObjAsync(item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -144,15 +144,23 @@ namespace Back.Services
|
||||
|
||||
}
|
||||
}
|
||||
public async Task<bool> ExistMobileInCompany(string mobile,bool IsActive=true)
|
||||
public async Task<bool> ExistMobileInCompany(string mobile, bool IsActive = true)
|
||||
{
|
||||
var resquest= _repoCompany.GetAll().Where(w => w.Mobile == mobile );
|
||||
var resquest = _repoCompany.GetAll().Where(w => w.Mobile == mobile);
|
||||
if (IsActive)
|
||||
resquest = resquest.Where(w => w.IsActive);
|
||||
|
||||
|
||||
return await resquest.AnyAsync();
|
||||
}
|
||||
|
||||
public async Task<CheckAuthDTO> GetTaxAuth(int ComoanyID)
|
||||
{
|
||||
return await _repoCompany.Get(w => w.ID == ComoanyID && w.IsActive)
|
||||
.Select(s => new CheckAuthDTO()
|
||||
{
|
||||
PrivateKey = s.PrivateKey,
|
||||
UniqueMemory = s.UniqeMemory
|
||||
}).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -3,6 +3,9 @@ using Back.Data.Contracts;
|
||||
using Back.Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Back.Common;
|
||||
using Shared;
|
||||
using Microsoft.OpenApi.Extensions;
|
||||
using Shared.DTOs.Serch;
|
||||
|
||||
namespace Back.Services
|
||||
{
|
||||
@@ -48,7 +51,10 @@ namespace Back.Services
|
||||
return await _repoPattern.Get(w=>w.Status).Select(s => new IdName<int> { ID = s.ID, Title = s.Title }).ToListAsync();
|
||||
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateInvoice(Invoice invoice)
|
||||
{
|
||||
return await _invoiceRepo.UpdateAsync(invoice);
|
||||
}
|
||||
public async Task<Invoice?> GetInvoice(int CompanyID, int ID)
|
||||
{
|
||||
#region AdvancedSearch
|
||||
@@ -71,7 +77,10 @@ namespace Back.Services
|
||||
.ThenInclude(inc => inc.CODUnit)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> AddSentTax(SentTax sentTax)
|
||||
{
|
||||
return await _repoSentTax.AddBoolResultAsync(sentTax);
|
||||
}
|
||||
public async Task<_TaxPayer.Atemplatefield> GetFildInvoiceForPreparation(Invoice InvoiceItem)
|
||||
{
|
||||
_TaxPayer.Atemplatefield ret = new _TaxPayer.Atemplatefield();
|
||||
@@ -192,6 +201,35 @@ namespace Back.Services
|
||||
|
||||
|
||||
|
||||
}
|
||||
public async Task<PagingDto<SentTaxDto>> GetSentTax(int CompanyID, ItemSerchGetSentTax itemSerchGetSentTax)
|
||||
{
|
||||
var request = _repoSentTax.Get(w => w.invoice.CompanyID == CompanyID);
|
||||
|
||||
if (itemSerchGetSentTax.ID.HasValue)
|
||||
request = request.Where(w => w.ID == itemSerchGetSentTax.ID.Value);
|
||||
|
||||
if (itemSerchGetSentTax.invoiceType.HasValue)
|
||||
request = request.Where(w => w.invoice.invoiceType == itemSerchGetSentTax.invoiceType.Value);
|
||||
|
||||
if (itemSerchGetSentTax.SentStatus.HasValue)
|
||||
request = request.Where(w => w.SentStatus == itemSerchGetSentTax.SentStatus.Value);
|
||||
|
||||
if (itemSerchGetSentTax.InvoiceID.HasValue)
|
||||
request = request.Where(w => w.InvoiceID == itemSerchGetSentTax.InvoiceID.Value);
|
||||
|
||||
return await request.OrderByDescending(o=>o.ID)
|
||||
.Select(s => new SentTaxDto
|
||||
{
|
||||
Date = s.Date.ShamciToFormatShamciinFront(),
|
||||
Time = s.Time,
|
||||
ID = s.ID,
|
||||
InvoiceID = s.InvoiceID,
|
||||
SentStatus=s.SentStatus,
|
||||
msgInvoiceType = s.InvoiceType.GetDisplayName(),
|
||||
msgSentStatus = s.SentStatus.GetDisplayName()
|
||||
|
||||
}).Paging(itemSerchGetSentTax.PageIndex, itemSerchGetSentTax.PageSize);
|
||||
}
|
||||
private void SetValue<T>(_TaxPayer.Fild fild, ref T obj)
|
||||
{
|
||||
|
Reference in New Issue
Block a user