invoice
This commit is contained in:
@@ -12,11 +12,15 @@ namespace Back.Services
|
||||
private readonly IAsyncRepository<Invoice> _invoiceRepo;
|
||||
private readonly IAsyncRepository<InvoiceItem> _invoiceItemRepo;
|
||||
private readonly IAsyncRepository<InvoicePayment> _invoicePaymentRepo;
|
||||
private readonly IAsyncRepository<InvoiceStatusChang> _invoiceStatusChangPaymentRepo;
|
||||
private readonly CheckPermission _checkPermission;
|
||||
public servInvoice(IAsyncRepository<Invoice> invoiceRepo
|
||||
, IAsyncRepository<InvoiceItem> invoiceItemRepo
|
||||
, IAsyncRepository<InvoicePayment> invoicePaymentRepo, CheckPermission checkPermission)
|
||||
, IAsyncRepository<InvoicePayment> invoicePaymentRepo
|
||||
, CheckPermission checkPermission
|
||||
, IAsyncRepository<InvoiceStatusChang> invoiceStatusChangPaymentRepo)
|
||||
{
|
||||
_invoiceStatusChangPaymentRepo= invoiceStatusChangPaymentRepo;
|
||||
_invoiceItemRepo = invoiceItemRepo;
|
||||
_invoiceRepo = invoiceRepo;
|
||||
_invoicePaymentRepo = invoicePaymentRepo;
|
||||
@@ -101,15 +105,117 @@ namespace Back.Services
|
||||
return await _invoiceRepo.Get(w => w.ID == InvoiceID && w.CompanyID == CompanyID && !w.IsDeleted).AnyAsync();
|
||||
|
||||
}
|
||||
public async Task<bool> AddInvoice(Invoice invoice)
|
||||
public async Task<bool> AddInvoice(Invoice invoice, bool calculate = true)
|
||||
{
|
||||
invoice.Cdate = DateTime.Now.ConvertMiladiToShamsi();
|
||||
invoice.Udate = DateTime.Now.ConvertMiladiToShamsi();
|
||||
invoice.PreparedtoSendtoTax = false;
|
||||
if (calculate)
|
||||
{
|
||||
if (await _checkPermission.ExtensionofAccess(invoice.CompanyID.Value, 3, "-1"))
|
||||
return await _invoiceRepo.AddBoolResultAsync(invoice);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return await _invoiceRepo.AddBoolResultAsync(invoice);
|
||||
}
|
||||
|
||||
}
|
||||
public async Task<bool> UpdateInvoice(Invoice invoice)
|
||||
{
|
||||
invoice.Udate = DateTime.Now.ConvertMiladiToShamsi();
|
||||
invoice.PreparedtoSendtoTax = false;
|
||||
|
||||
if(await _checkPermission.ExtensionofAccess(invoice.CompanyID.Value, 3, "-1"))
|
||||
return await _invoiceRepo.AddBoolResultAsync(invoice);
|
||||
return false;
|
||||
|
||||
return await _invoiceRepo.UpdateAsync(invoice);
|
||||
}
|
||||
public async Task<Invoice?> GetInvoiceByInvoiceID(int CompanyID, int InvoiceID)
|
||||
{
|
||||
return await _invoiceRepo
|
||||
.Get(w => w.ID == InvoiceID && w.CompanyID == CompanyID && !w.IsDeleted)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task<bool> DeleteInvoice(Invoice item)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
item.Udate = DateTime.Now.ConvertMiladiToShamsi();
|
||||
item.IsDeleted = true;
|
||||
return await _invoiceRepo.UpdateAsync(item);
|
||||
//SysLog log = new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/DeleteCustomer",
|
||||
// Value = JsonConvert.SerializeObject(item.ID),
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "User"
|
||||
//};
|
||||
//_contextMongodb.InsertItem(log);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//SysLog log = new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/DeleteCustomer",
|
||||
// Value = ex.Message,
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "catch"
|
||||
//};
|
||||
//_contextMongodb.InsertItem(log);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
public async Task<bool> ChangeInvoiceType(Invoice invoiceitem, InvoiceType item, bool action = true)
|
||||
{
|
||||
string old = invoiceitem.invoiceType.GetEnumDisplayName();
|
||||
invoiceitem.invoiceType = item;
|
||||
invoiceitem.Udate = DateTime.Now.ConvertMiladiToShamsi();
|
||||
invoiceitem.PreparedtoSendtoTax = false;
|
||||
try
|
||||
{
|
||||
await _invoiceStatusChangPaymentRepo.AddBoolResultAsync(new InvoiceStatusChang()
|
||||
{
|
||||
InvoiceID = invoiceitem.ID,
|
||||
ToStatus = item.GetEnumDisplayName(),
|
||||
FromStatus = old,
|
||||
Date = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
UserID = invoiceitem.LastChangeUserID
|
||||
});
|
||||
if(action)
|
||||
return await _invoiceRepo.UpdateAsync(invoiceitem);
|
||||
else return true;
|
||||
//_contextMongodb.InsertItem(new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/ChangeInvoiceType",
|
||||
// Value = $"From {old} to {item.ToString()}",
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "User"
|
||||
//});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//_contextMongodb.InsertItem(new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/ChangeInvoiceType",
|
||||
// Value = $"From {old} to {item.ToString()}" + '\n' + ex.Message,
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "catch"
|
||||
//});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,11 @@ namespace Back.Services
|
||||
{
|
||||
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)
|
||||
|
Reference in New Issue
Block a user