diff --git a/Back/Back.csproj b/Back/Back.csproj index 52705f9..a6bcdd4 100644 --- a/Back/Back.csproj +++ b/Back/Back.csproj @@ -35,7 +35,7 @@ - ..\..\Dlls\Service.dll + ..\..\..\LocalGit\TaxPayerTools\Service\bin\Debug\Service.dll diff --git a/Back/Controllers/TaxPayerController.cs b/Back/Controllers/TaxPayerController.cs index 4cdd999..87a6145 100644 --- a/Back/Controllers/TaxPayerController.cs +++ b/Back/Controllers/TaxPayerController.cs @@ -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> 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 { "صورتحساب یافت نشد" }); + + + return Ok(await _servTaxPayer.PreparationInvoiceBeforeSending(item, result)); + } } } diff --git a/Back/Services/servTaxPayer.cs b/Back/Services/servTaxPayer.cs index e6f6226..e37da63 100644 --- a/Back/Services/servTaxPayer.cs +++ b/Back/Services/servTaxPayer.cs @@ -11,12 +11,14 @@ namespace Back.Services private readonly IAsyncRepository _repoSentTax; private readonly IAsyncRepository _repoPattern; private readonly IAsyncRepository _invoiceRepo; + private readonly IAsyncRepository _invoiceitemRepo; private readonly IAsyncRepository _fildModeInPatternRepo; private readonly IAsyncRepository _codingRepo; private readonly IAsyncRepository _specialConditionRepo; public servTaxPayer(IAsyncRepository repoSentTax, IAsyncRepository repoPattern , IAsyncRepository invoiceRepo, IAsyncRepository fildModeInPatternRepo - , IAsyncRepository codingRepo, IAsyncRepository specialConditionRepo) + , IAsyncRepository codingRepo, IAsyncRepository specialConditionRepo + , IAsyncRepository invoiceitemRepo) { _repoSentTax = repoSentTax; _repoPattern = repoPattern; @@ -24,6 +26,7 @@ namespace Back.Services _fildModeInPatternRepo = fildModeInPatternRepo; _codingRepo = codingRepo; _specialConditionRepo = specialConditionRepo; + _invoiceitemRepo = invoiceitemRepo; } public async Task 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 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(_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); + } + } + + // } + + } } } diff --git a/Shared/DTOs/_TaxPayer.cs b/Shared/DTOs/_TaxPayer.cs index db37e1c..ad481b9 100644 --- a/Shared/DTOs/_TaxPayer.cs +++ b/Shared/DTOs/_TaxPayer.cs @@ -31,7 +31,7 @@ namespace Shared.DTOs public string InputBox { get; set; } public List DefVals { get; set; } public string? Value { get; set; } - public string[] Des { get; set; } + public string[]? Des { get; set; } } public class Coding { diff --git a/TaxPayerFull/Pages/UserPanel/TaxPayerInvoiceItem.razor b/TaxPayerFull/Pages/UserPanel/TaxPayerInvoiceItem.razor index d545174..8e4c65f 100644 --- a/TaxPayerFull/Pages/UserPanel/TaxPayerInvoiceItem.razor +++ b/TaxPayerFull/Pages/UserPanel/TaxPayerInvoiceItem.razor @@ -8,6 +8,165 @@ آماده سازی صورتحساب + + + + اطلاعات تکمیلی سرآمد صورتحساب + + + + @if (invoice?.header != null) + { + + + @foreach (var item in invoice?.header.filds) + { + + @if (item.ModeID == 1 && item.InputBox != "autofild") + { + @item.fName + } + else + { + @item.fName + } + @if (item.InputBox == "fromdb") + { + + + @item.fName... + @foreach (var itema in item.DefVals) + { + if (itema.ID == item.Value) + { + @itema.Name + } + else + { + @itema.Name + } + } + + + + } + else if (item.InputBox == "autofild") + { + + + } + + else + { + + + } + + } + + + + + } + + + + + + + + + + + اطلاعات تکمیلی بدنه صورتحساب + + @if (invoice?.Bodys != null) + { + + @foreach (var item in invoice?.Bodys) + { + + s.Value).First()"> + + + @foreach (var itemB in item.filds) + { + + @if (itemB.ModeID == 1 && itemB.InputBox != "autofild") + { + @itemB.fName + } + else + { + @itemB.fName + } + @if (itemB.InputBox == "fromdb") + { + + + @itemB.fName... + @foreach (var itema in itemB.DefVals) + { + if (itema.ID == itemB.Value) + { + @itema.Name + } + else + { + @itema.Name + } + } + + + + } + else if (itemB.InputBox == "autofild") + { + + + } + else + { + + + } + + + + } + + + + + + + } + + + + + + } + + + + + +@* action *@ + + + + + + + ارسال + + + + + + + @code { private ConfirmDialog dialog = default!; [Parameter] public int? InvoiceID { get; set; } @@ -24,10 +183,33 @@ { await LoadData(); await base.OnParametersSetAsync(); + } } -@functions{ +@functions { + public async Task Send() + { + var rsp = await hc.Post<_TaxPayer.Atemplatefield>($"TaxPayer/PreparationInvoiceBeforeSending", invoice); + if (rsp.IsSuccessStatusCode) + { + var response = await rsp.Content.ReadFromJsonAsync(); + if (response) + { + ShowSuccessAlert("آماده سازی با موفقیت انجام شد"); + } + else + { + ShowDangerAlert("خطای در آماده سازی اطلاعات رخ داده"); + } + } + else + { + var request = await rsp.Content.ReadFromJsonAsync>(); + ShowDangerAlert(request[0]); + } + } + private void ShowSuccessAlert(string msg) { Hidealert = false; diff --git a/TaxPayerFull/Program.cs b/TaxPayerFull/Program.cs index 628e6c3..f8805c2 100644 --- a/TaxPayerFull/Program.cs +++ b/TaxPayerFull/Program.cs @@ -34,9 +34,9 @@ builder.Services.AddScoped(sp => new UserAuthenticationDTO() }) ; -builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") }); +//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") }); -//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") }); CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("fa-Ir");