diff --git a/Back/Controllers/CODController.cs b/Back/Controllers/CODController.cs index a20f894..2639eda 100644 --- a/Back/Controllers/CODController.cs +++ b/Back/Controllers/CODController.cs @@ -114,7 +114,8 @@ namespace Back.Controllers ////-----change Cod Cod.TaxRate = item.TaxRate; - //Cod.Title = item.Title; + if(!await _servCOD.UsedInTheInvoice(Cod.ID)) + Cod.Title = item.Title; Cod.UnitID = item.UnitID; Cod.ItemTaxID = item.TaxID; Cod.IsDeleted = false; @@ -138,5 +139,10 @@ namespace Back.Controllers //----Update and sendResult return Ok(await _servCOD.DeleteCod(cod)); } + [HttpGet("UsedInTheInvoice/{ID}")] + public async Task> UsedInTheInvoice(int ID) + { + return Ok(await _servCOD.UsedInTheInvoice(ID)); + } } } diff --git a/Back/Controllers/CustomerController.cs b/Back/Controllers/CustomerController.cs index 345d6d6..27556a6 100644 --- a/Back/Controllers/CustomerController.cs +++ b/Back/Controllers/CustomerController.cs @@ -130,7 +130,8 @@ namespace Back.Controllers cus.CustomerType = item.CustomerType; cus.EconomicCode = item.EconomicCode; cus.Email = item.Email; - // cus.FullName = item.FullName; + if(!await _servCus.UsedInTheInvoice(cus.ID)) + cus.FullName = item.FullName; cus.Info = item.Info; cus.MeliCode = item.MeliCode; cus.PassportNumber = item.PassportNumber; @@ -157,5 +158,10 @@ namespace Back.Controllers //----Update and sendResult return Ok(await _servCus.DeleteCustomer(cus)); } + [HttpGet("UsedInTheInvoice/{ID}")] + public async Task> UsedInTheInvoice(int ID) + { + return Ok(await _servCus.UsedInTheInvoice(ID)); + } } } diff --git a/Back/Services/ServCOD.cs b/Back/Services/ServCOD.cs index aa77b6d..2499ed2 100644 --- a/Back/Services/ServCOD.cs +++ b/Back/Services/ServCOD.cs @@ -170,5 +170,9 @@ namespace Back.Services } } + public async Task UsedInTheInvoice(int codID) + { + return await _CODRepo.Get(w => w.invoiceDetails.Any(a=>a.CODID==codID)).AnyAsync(); + } } } diff --git a/Back/Services/servCustomer.cs b/Back/Services/servCustomer.cs index 80acaa5..d7e0e72 100644 --- a/Back/Services/servCustomer.cs +++ b/Back/Services/servCustomer.cs @@ -9,12 +9,13 @@ namespace Back.Services public class servCustomer { private readonly IAsyncRepository _repoCus; + private readonly IAsyncRepository _repoInvoice; private readonly CheckPermission _checkPermission; - public servCustomer(IAsyncRepository repoCus, CheckPermission checkPermission) + public servCustomer(IAsyncRepository repoCus, CheckPermission checkPermission, IAsyncRepository repoInvoice) { _repoCus = repoCus; _checkPermission = checkPermission; - + _repoInvoice = repoInvoice; } public async Task?> GetCustomers(int CompanyID, ItemSerchGetCustomer itemSerch) { @@ -189,6 +190,10 @@ namespace Back.Services } } + public async Task UsedInTheInvoice(int cusID) + { + return await _repoInvoice.Get(w => w.CustomerID == cusID).AnyAsync(); + } } diff --git a/Back/Services/servInvoice.cs b/Back/Services/servInvoice.cs index 15ec723..0fb885f 100644 --- a/Back/Services/servInvoice.cs +++ b/Back/Services/servInvoice.cs @@ -125,6 +125,9 @@ namespace Back.Services if (itemSerch.refInvoiceID != null) invok = invok.Where(w => w.BillReference==itemSerch.refInvoiceID); + + if(itemSerch.CodID != null) + invok = invok.Where(w => w.invoiceDetails.Any(wa=>wa.CODID== itemSerch.CodID)); //foreach (InputObj item in inputObjs) // invok = invok.Where(ExMethod.GetFunc(item.Param, item.Value)); diff --git a/Shared/DTOs/Serch/ItemSerchGetInvoices.cs b/Shared/DTOs/Serch/ItemSerchGetInvoices.cs index f296ec2..8a66040 100644 --- a/Shared/DTOs/Serch/ItemSerchGetInvoices.cs +++ b/Shared/DTOs/Serch/ItemSerchGetInvoices.cs @@ -12,6 +12,7 @@ namespace Shared.DTOs.Serch public int? InvoiceID { get; set; }// public int? refInvoiceID { get; set; }// public int? CustomerID { get; set; } + public int? CodID { get; set; } public InvoiceType? invoiceType { get; set; }// public int PageIndex { get; set; } = 1; public int PageSize { get; set; } = 5; diff --git a/TaxPayerFull/CUSComponent/CodItem.razor b/TaxPayerFull/CUSComponent/CodItem.razor index a41def1..b87bef1 100644 --- a/TaxPayerFull/CUSComponent/CodItem.razor +++ b/TaxPayerFull/CUSComponent/CodItem.razor @@ -16,21 +16,24 @@
نکته:
    -
  • در زمان ویرایش نمیتوانید نام کالا را عوض کنید
  • + @if (_UsedInTheInvoice) + { +
  • با این کالا صورتحسابی صادر کرده اید ،نمیتوانید نام کالا را ویرایش کنید
  • + }
  • زمان ویرایش دقت کنید تغییرات میتواند روی فاکتورهای صادر شده تائیر بگذارد
}
- @if (Cod.ID != 0) + @if (Cod.ID == 0 || !_UsedInTheInvoice) { + /> } else { - + }
@@ -95,6 +98,13 @@ else + @if (_UsedInTheInvoice) + + { + + } } @@ -105,25 +115,43 @@ else IconName alertIconName = IconName.CheckCircleFill; bool Hidealert = true; string alertMessage = ""; + bool _UsedInTheInvoice = false; [Parameter] public RCOD Cod { get; set; } [Parameter] public EventCallback OnMultipleOfThree { get; set; } [Parameter] public List>? Unitrequest { get; set; } public ActionInResultComponent result { get; set; } - - protected override Task OnParametersSetAsync() + + protected override async Task OnParametersSetAsync() { - + result = new ActionInResultComponent() { Status = ComponentStatus.fild }; Hidealert = true; alertMessage = ""; - return base.OnParametersSetAsync(); + await UsedInTheInvoice(); + await base.OnParametersSetAsync(); } } @functions { + public async Task OnClickGoToInvoice() + { + hc._nav.NavigateTo($"Invoice/{"cod:" + Cod.ID}"); + } + public async Task UsedInTheInvoice() + { + if (Cod.ID!=0) + { + var rsp = await hc.Get($"Cod/UsedInTheInvoice/{Cod.ID}"); + if (rsp.IsSuccessStatusCode) + _UsedInTheInvoice = await rsp.Content.ReadFromJsonAsync(); + + else _UsedInTheInvoice = false; + } + + } private void ShowSuccessAlert(string msg) { Hidealert = false; diff --git a/TaxPayerFull/CUSComponent/CustomerItem.razor b/TaxPayerFull/CUSComponent/CustomerItem.razor index 3f15a74..2529f26 100644 --- a/TaxPayerFull/CUSComponent/CustomerItem.razor +++ b/TaxPayerFull/CUSComponent/CustomerItem.razor @@ -15,14 +15,19 @@
نکته:
    -
  • در زمان ویرایش نمیتوانید نام کامل را عوض کنید
  • + + @if (_UsedInTheInvoice) + { +
  • با این مشتری صورتحسابی صادر کرده اید ، نمیتوانید نام کامل را ویرایش کنید
  • + } +
  • زمان ویرایش دقت کنید تغییرات میتواند روی فاکتورهای صادر شده تائیر بگذارد
}
- @if (Cus.ID == 0) + @if (Cus.ID == 0 || !_UsedInTheInvoice) { } @@ -111,6 +116,12 @@ else + @if (_UsedInTheInvoice) + { + + } } @@ -119,13 +130,14 @@ else AlertColor alertColor = AlertColor.Primary; IconName alertIconName = IconName.CheckCircleFill; bool Hidealert = true; + bool _UsedInTheInvoice = false; string alertMessage = ""; [Parameter] public RCustomer Cus { get; set; } public int? ItemSearchCustomertype { get; set; } [Parameter] public EventCallback OnMultipleOfThree { get; set; } public ActionInResultComponent result { get; set; } - protected override Task OnParametersSetAsync() + protected override async Task OnParametersSetAsync() { if (Cus.CustomerType != null) ItemSearchCustomertype = (int)Cus.CustomerType; @@ -136,7 +148,8 @@ else }; Hidealert = true; alertMessage = ""; - return base.OnParametersSetAsync(); + await UsedInTheInvoice(); + await base.OnParametersSetAsync(); } } @functions { @@ -154,6 +167,10 @@ else alertIconName = IconName.ExclamationTriangleFill; alertMessage = msg; } + public async Task OnClickGoToInvoice() + { + hc._nav.NavigateTo($"Invoice/{"cus:"+Cus.ID}"); + } public async Task OnClickDelete() { @@ -238,4 +255,16 @@ else } else ShowDangerAlert("فیلدهای قرمز باید مقدار دهی شوند"); } + public async Task UsedInTheInvoice() + { + if (Cus.ID!=0) + { + var rsp = await hc.Get($"Customer/UsedInTheInvoice/{Cus.ID}"); + if (rsp.IsSuccessStatusCode) + _UsedInTheInvoice = await rsp.Content.ReadFromJsonAsync(); + + else _UsedInTheInvoice = false; + } + + } } \ No newline at end of file diff --git a/TaxPayerFull/Pages/UserPanel/Invoice.razor b/TaxPayerFull/Pages/UserPanel/Invoice.razor index cedb9c1..fd28083 100644 --- a/TaxPayerFull/Pages/UserPanel/Invoice.razor +++ b/TaxPayerFull/Pages/UserPanel/Invoice.razor @@ -1,4 +1,5 @@ @page "/Invoice" +@page "/Invoice/{input}" @using Front.Services @using Shared @using Shared.DTOs @@ -130,6 +131,7 @@ return await Task.FromResult(request.ApplyTo(customers.OrderBy(customer => customer.CustomerName))); } //----------- + [Parameter] public string? input { get; set; } [Inject] protected PreloadService PreloadService { get; set; } = default!; public int? ItemSearchInvoicetype { get; set; } ItemSerchGetInvoices itemsearch = new ItemSerchGetInvoices(); @@ -146,6 +148,15 @@ protected override async Task OnParametersSetAsync() { if (PageIndex == null) PageIndex = 1; + if (!string.IsNullOrEmpty(input)) + { + if (input.StartsWith("cus")) + itemsearch.CustomerID = Convert.ToInt32(input.Split(':')[1]); + + else if (input.StartsWith("cod")) + itemsearch.CodID =Convert.ToInt32(input.Split(':')[1]); + + } await LoadInvoice(PageIndex.Value); await base.OnParametersSetAsync(); }