...
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Service">
|
||||
<HintPath>..\..\Dlls\Service.dll</HintPath>
|
||||
<HintPath>..\..\..\LocalGit\TaxPayerTools\Service\bin\Debug\Service.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
|
@@ -3,6 +3,7 @@ using Back.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Shared.DTOs;
|
||||
using static Shared.DTOs._TaxPayer;
|
||||
|
||||
namespace Back.Controllers
|
||||
{
|
||||
@@ -53,5 +54,18 @@ namespace Back.Controllers
|
||||
}
|
||||
|
||||
}
|
||||
[HttpPost("PreparationInvoiceBeforeSending")]
|
||||
public async Task<ActionResult<bool>> PreparationInvoiceBeforeSending([FromBody] Atemplatefield item)
|
||||
{
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
var result = await _servTaxPayer.GetInvoice(user.RolUsers.First().CompanyID, item.header.ID);
|
||||
if (result == null)
|
||||
return BadRequest(new List<string> { "صورتحساب یافت نشد" });
|
||||
|
||||
|
||||
return Ok(await _servTaxPayer.PreparationInvoiceBeforeSending(item, result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,12 +11,14 @@ namespace Back.Services
|
||||
private readonly IAsyncRepository<SentTax> _repoSentTax;
|
||||
private readonly IAsyncRepository<Pattern> _repoPattern;
|
||||
private readonly IAsyncRepository<Invoice> _invoiceRepo;
|
||||
private readonly IAsyncRepository<InvoiceItem> _invoiceitemRepo;
|
||||
private readonly IAsyncRepository<FildModeInPattern> _fildModeInPatternRepo;
|
||||
private readonly IAsyncRepository<Coding> _codingRepo;
|
||||
private readonly IAsyncRepository<SpecialCondition> _specialConditionRepo;
|
||||
public servTaxPayer(IAsyncRepository<SentTax> repoSentTax, IAsyncRepository<Pattern> repoPattern
|
||||
, IAsyncRepository<Invoice> invoiceRepo, IAsyncRepository<FildModeInPattern> fildModeInPatternRepo
|
||||
, IAsyncRepository<Coding> codingRepo, IAsyncRepository<SpecialCondition> specialConditionRepo)
|
||||
, IAsyncRepository<Coding> codingRepo, IAsyncRepository<SpecialCondition> specialConditionRepo
|
||||
, IAsyncRepository<InvoiceItem> invoiceitemRepo)
|
||||
{
|
||||
_repoSentTax = repoSentTax;
|
||||
_repoPattern = repoPattern;
|
||||
@@ -24,6 +26,7 @@ namespace Back.Services
|
||||
_fildModeInPatternRepo = fildModeInPatternRepo;
|
||||
_codingRepo = codingRepo;
|
||||
_specialConditionRepo = specialConditionRepo;
|
||||
_invoiceitemRepo = invoiceitemRepo;
|
||||
}
|
||||
public async Task<bool> ExistSuccessfulorSendorpendingInvoiceinCompanyID(int CompanyID)
|
||||
{
|
||||
@@ -86,7 +89,7 @@ namespace Back.Services
|
||||
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
|
||||
InputBox = s.Fild.Name == "indatim" || s.Fild.Name == "Indati2m" || s.Fild.Name == "cdcd" ? "autofild" : s.Fild.InputBox
|
||||
|
||||
}).ToListAsync();
|
||||
foreach (_TaxPayer.Fild item in head)
|
||||
@@ -106,7 +109,7 @@ namespace Back.Services
|
||||
ModeID = s.FildModeID,
|
||||
ModeTitle = s.FildMode.Title,
|
||||
Title = s.Fild.Title,
|
||||
InputBox = s.Fild.InputBox
|
||||
InputBox = s.Fild.Name == "dis" || s.Fild.Name == "fee" || s.Fild.Name == "am" ? "autofild" : s.Fild.InputBox
|
||||
|
||||
}).ToListAsync();
|
||||
foreach (var invoicedetail in InvoiceItem.invoiceDetails)
|
||||
@@ -146,5 +149,107 @@ namespace Back.Services
|
||||
|
||||
return ret;
|
||||
}
|
||||
public async Task<bool> PreparationInvoiceBeforeSending(Shared.DTOs._TaxPayer.Atemplatefield FildItems, Invoice InvoiceItem)
|
||||
{
|
||||
foreach (var item in FildItems.header.filds.Where(w=>w.InputBox== "fild" || w.InputBox == "fromdb"))
|
||||
{
|
||||
if (item.eName == "indatim" || item.eName == "Indati2m" || item.eName == "cdcd")
|
||||
item.Value = item.Value.Replace("/", "");
|
||||
SetValue(item, ref InvoiceItem);
|
||||
|
||||
}
|
||||
if (await _invoiceRepo.UpdateAsync(InvoiceItem))
|
||||
{
|
||||
foreach (var Bitem in FildItems.Bodys)
|
||||
{
|
||||
var invoiceDetItem = InvoiceItem.invoiceDetails.Where(w => w.ID == Bitem.ID).FirstOrDefault();
|
||||
foreach (var item in Bitem.filds.Where(w => w.InputBox == "fild" || w.InputBox == "fromdb"))
|
||||
{
|
||||
if (invoiceDetItem != null)
|
||||
SetValue(item, ref invoiceDetItem);
|
||||
}
|
||||
if (!await _invoiceitemRepo.UpdateAsync(invoiceDetItem))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else return false;
|
||||
return true;
|
||||
|
||||
//foreach (var Pitem in FildItems.Payments)
|
||||
//{
|
||||
// var invoicepayItem = InvoiceItem.payments.Where(w => w.ID == Pitem.ID).FirstOrDefault();
|
||||
// foreach (var item in Pitem.filds)
|
||||
// {
|
||||
// if (invoicepayItem != null)
|
||||
// {
|
||||
// SetValue(item, ref invoicepayItem);
|
||||
// }
|
||||
|
||||
// }
|
||||
// // _repositores.UPDATE(invoicepayItem);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
private void SetValue<T>(_TaxPayer.Fild fild, ref T obj)
|
||||
{
|
||||
var resvaltype = obj.GetType().GetProperties().Where(w => w.Name == (fild.eName=="tax17" ? "seventeentax" : fild.eName)).FirstOrDefault();
|
||||
//if (resvaltype != null)
|
||||
//{
|
||||
if ((resvaltype.GetValue(obj) == null && !string.IsNullOrEmpty(fild.Value))
|
||||
||
|
||||
resvaltype.GetValue(obj) != null && resvaltype.GetValue(obj).ToString() != fild.Value)
|
||||
{
|
||||
if (resvaltype != null && resvaltype.CanWrite)
|
||||
{
|
||||
string _type = ""; object _val = "";
|
||||
|
||||
if (resvaltype.PropertyType.FullName.Contains("Nullable"))
|
||||
_type = resvaltype.PropertyType.GenericTypeArguments[0].FullName;
|
||||
else
|
||||
_type = resvaltype.PropertyType.FullName;
|
||||
|
||||
try
|
||||
{
|
||||
_val = Convert.ChangeType(fild.Value, Type.GetType(_type));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//_contextMongodb.InsertItem(new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/SetValue",
|
||||
// Value = ex.Message + '\n' + "_____________" + '\n' + JsonConvert.SerializeObject(fild),
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "catch"
|
||||
//});
|
||||
|
||||
switch (_type)
|
||||
{
|
||||
case "string":
|
||||
_val = Convert.ChangeType("", Type.GetType(_type));
|
||||
break;
|
||||
|
||||
case "bool":
|
||||
if (fild.Value == "1" || fild.Value == "true") _val = Convert.ChangeType(true, Type.GetType(_type));
|
||||
else _val = Convert.ChangeType(false, Type.GetType(_type));
|
||||
break;
|
||||
|
||||
default:
|
||||
_val = Convert.ChangeType("0", Type.GetType(_type));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
resvaltype.SetValue(obj, _val);
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user