From 88d4b633946e037bf2cda5c7cb0c41d25ce9a78b Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Wed, 22 Jan 2025 13:02:53 +0330 Subject: [PATCH] ... --- Back/Services/Warehouse/WarehouseService.cs | 36 +- Shared/DTOs/Warehouse/CirculationDto.cs | 6 +- TaxPayerFULL.sln | 5 - TaxPayerFull/CUSComponent/WarehouseItem.razor | 321 ++++++++++++++++++ TaxPayerFull/Pages/UserPanel/Warehouse.razor | 68 ++-- 5 files changed, 382 insertions(+), 54 deletions(-) create mode 100644 TaxPayerFull/CUSComponent/WarehouseItem.razor diff --git a/Back/Services/Warehouse/WarehouseService.cs b/Back/Services/Warehouse/WarehouseService.cs index 5ca641c..7ebb9f2 100644 --- a/Back/Services/Warehouse/WarehouseService.cs +++ b/Back/Services/Warehouse/WarehouseService.cs @@ -23,51 +23,55 @@ namespace Back.Services.Warehouse _RemittanceRepo = remittanceRepo; _ReceiptRepo = receiptRepo; } - public async Task> Circulation(int CompanyID,string date="",int CODID=0,int PageIndex=1,int PageSize=5) + public async Task> Circulation(int CompanyID, string date = "", int CODID = 0, int PageIndex = 1, int PageSize = 5) { var RequestRemittance = _RemittanceRepo.Get(w => w.cODItem.CompanyID == CompanyID && !w.Deleted) - .Select(s=>new CirculationDto + .Select(s => new CirculationDto { - CODID=s.CODID, - CODTitle=s.cODItem.Title, - Date=s.Date, - Count=s.Count, - info=s.info, - Type=TypeCirculation.Remittance, + ID= s.ID, + CODID = s.CODID, + CODTitle = s.cODItem.Title, + Date = s.Date.ShamciToFormatShamci(), + Count = s.Count, + info = s.info, + Type = TypeCirculation.Remittance, ModelTypeID = (int)s.Type, - ModelTypeTitle= s.Type.GetDisplayName() + ModelTypeTitle = s.Type.GetDisplayName(), + invoiceID = s.InvoiceID, }); if (!string.IsNullOrEmpty(date)) RequestRemittance = RequestRemittance.Where(w => w.Date == date); - if (CODID!=0) + if (CODID != 0) RequestRemittance = RequestRemittance.Where(w => w.CODID == CODID); //----------- var RequestReceipt = _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID && !w.Deleted) .Select(s => new CirculationDto { + ID = s.ID, CODID = s.CODID, CODTitle = s.cODItem.Title, - Date = s.Date, + Date = s.Date.ShamciToFormatShamci(), Count = s.Count, info = s.info, Type = TypeCirculation.Receipt, ModelTypeID = (int)s.Type, - ModelTypeTitle = s.Type.GetDisplayName() + ModelTypeTitle = s.Type.GetDisplayName(), + invoiceID = s.InvoiceID, }); if (!string.IsNullOrEmpty(date)) RequestReceipt = RequestReceipt.Where(w => w.Date == date); if (CODID != 0) RequestReceipt = RequestReceipt.Where(w => w.CODID == CODID); - return await RequestReceipt.Union(RequestRemittance).OrderByDescending(o => o.Date).Paging(PageIndex, PageSize); + return await RequestReceipt.Union(RequestRemittance).OrderByDescending(o => o.Date).Paging(PageIndex, PageSize); //var list = await RequestReceipt.ToListAsync(); //list.AddRange(await RequestRemittance.ToListAsync()); //return await list.OrderByDescending(o=>o.Date).AsQueryable().Paging(PageIndex, PageSize); } - public async Task Inventory(int CompanyID,int CODID) + public async Task Inventory(int CompanyID, int CODID) { - var CReceipt=await _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID && w.CODID == CODID && w.ForSale && !w.Deleted).SumAsync(s => s.Count); - var CRemittance=await _RemittanceRepo.Get(w => w.cODItem.CompanyID == CompanyID && w.CODID == CODID && !w.Deleted).SumAsync(s => s.Count); + var CReceipt = await _ReceiptRepo.Get(w => w.cODItem.CompanyID == CompanyID && w.CODID == CODID && w.ForSale && !w.Deleted).SumAsync(s => s.Count); + var CRemittance = await _RemittanceRepo.Get(w => w.cODItem.CompanyID == CompanyID && w.CODID == CODID && !w.Deleted).SumAsync(s => s.Count); return CReceipt - CRemittance; } } diff --git a/Shared/DTOs/Warehouse/CirculationDto.cs b/Shared/DTOs/Warehouse/CirculationDto.cs index 1319dba..a235c8d 100644 --- a/Shared/DTOs/Warehouse/CirculationDto.cs +++ b/Shared/DTOs/Warehouse/CirculationDto.cs @@ -11,13 +11,14 @@ namespace Shared.DTOs.Warehouse public enum TypeCirculation { [Display(Name = "رسید")] - Receipt, + Receipt=10, [Display(Name = "حواله")] - Remittance + Remittance=20 } public class CirculationDto { + public int ID { get; set; } public int CODID { get; set; } [Display(Name = "کالا")] public string? CODTitle { get; set; } @@ -35,5 +36,6 @@ namespace Shared.DTOs.Warehouse public TypeCirculation Type { get; set; } [Display(Name = "نوع سند")] public string msgType { get { return Type.GetEnumDisplayName(); } } + public int? invoiceID { get; set; } } } diff --git a/TaxPayerFULL.sln b/TaxPayerFULL.sln index 357095b..d15e9f9 100644 --- a/TaxPayerFULL.sln +++ b/TaxPayerFULL.sln @@ -13,11 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "View", "View", "{25C58D68-C EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "moadiran", "moadiran\moadiran.csproj", "{E209C152-76D5-469F-A969-B5BE5970CA7A}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8B482DB5-6DE6-4983-A3B2-36458EAEAD5F}" - ProjectSection(SolutionItems) = preProject - next.txt = next.txt - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/TaxPayerFull/CUSComponent/WarehouseItem.razor b/TaxPayerFull/CUSComponent/WarehouseItem.razor new file mode 100644 index 0000000..0567711 --- /dev/null +++ b/TaxPayerFull/CUSComponent/WarehouseItem.razor @@ -0,0 +1,321 @@ +@using Front.Services +@using Shared +@using Shared.DTOs +@using Shared.DTOs.Warehouse +@using Shared.Enums +@inject HttpClientController hc; + +
+ @* alert *@ +
+ +
+
    + @if (_UsedFromInvoice) + { +
  • style="color:indianred"این سند از فاکتور صادر شده، ویرایش مستقیم آن ممکن نیست
  • +
    + } +
+
+ +
+ @*
+ +
*@ + +
+ + +
+
+ + +
+ +
+ +
+ @if (model.Type == TypeCirculation.Receipt) + { +
+ +
+ } + +
+ + +
+ +
+
+
+ @if (model.CODID == 0) + { + + } + else + { + @if (!_UsedFromInvoice) + { + + + } + } +
+
+ +
+
+@code { + [Parameter] public CirculationDto model { get; set; } + [Parameter] public EventCallback OnMultipleOfThree { get; set; } + [Parameter] public bool NewItem { get; set; } + [Parameter] public List> CODrequest { get; set; } + private ConfirmDialog dialog = default!; + + AlertColor alertColor = AlertColor.Primary; + IconName alertIconName = IconName.CheckCircleFill; + bool Hidealert = true; + string alertMessage = ""; + + bool _UsedFromInvoice = false; + + public bool SpinnerVisible { get; set; } = false; + + private bool forsale { get; set; } = false; +} +@functions { + protected override async Task OnParametersSetAsync() + { + _UsedFromInvoice = model.invoiceID.HasValue; + if (NewItem) + model.Date = DateTime.Now.ConvertMiladiToShamsiinFront().ShamciToFormatShamciinFront(); + + await base.OnParametersSetAsync(); + } + private void ShowSuccessAlert(string msg) + { + Hidealert = false; + alertColor = AlertColor.Success; + alertIconName = IconName.CheckCircleFill; + alertMessage = msg; + } + private void ShowDangerAlert(string msg) + { + Hidealert = false; + alertColor = AlertColor.Danger; + alertIconName = IconName.ExclamationTriangleFill; + alertMessage = msg; + } + public async Task OnClickDelete() + { + if (NewItem) + return; + + SpinnerVisible = true; + await Delete(); + SpinnerVisible = false; + + } + private async Task Delete() + { + string route = model.Type == TypeCirculation.Receipt ? "Receipt" : "Remittance"; + + var rsp = await hc.Delete($"{route}/{model.ID}"); + if (rsp.IsSuccessStatusCode) + { + var request = await rsp.Content.ReadFromJsonAsync(); + if (request) + { + ActionInResultComponent result = new ActionInResultComponent(); + result.Status = ComponentStatus.success; + result.Action = ComponentAction.delete; + await OnMultipleOfThree.InvokeAsync(result); + } + else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); + } + + else if (rsp.StatusCode == System.Net.HttpStatusCode.NotFound) + { + ShowDangerAlert("سندی یافت نشد"); + } + else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); + } + private async Task Addorupdate() + { + string controller = model.Type == TypeCirculation.Receipt ? "Receipt" : "Remittance"; + string route = NewItem ? "ADD" : "Update"; + ActionInResultComponent result = new ActionInResultComponent(); + HttpResponseMessage rsp = new HttpResponseMessage(); + + if (NewItem) + { + if (model.Type == TypeCirculation.Receipt) + rsp = await hc.Post($"{controller}/{NewItem}/{model.ID}", new ReceiptDto() + { + CODID = model.CODID, + Count = model.Count, + Date = model.Date, + ForSale = model.ForSale.Value, + info = model.info, + Type = (TypeReceipt)model.ModelTypeID, + }); + + if (model.Type == TypeCirculation.Remittance) + rsp = await hc.Post($"{route}/Update/{model.ID}", new RemittanceDto() + { + CODID = model.CODID, + Count = model.Count, + Date = model.Date, + info = model.info, + Type = (TypeRemittance)model.ModelTypeID, + }); + result.Action = ComponentAction.add; + } + else + { + if (model.Type == TypeCirculation.Receipt) + rsp = await hc.Put($"{controller}/{NewItem}/{model.ID}", new ReceiptDto() + { + CODID = model.CODID, + Count = model.Count, + Date = model.Date, + ForSale = model.ForSale.Value, + info = model.info, + Type = (TypeReceipt)model.ModelTypeID, + }); + + if (model.Type == TypeCirculation.Remittance) + rsp = await hc.Put($"{route}/Update/{model.ID}", new RemittanceDto() + { + CODID = model.CODID, + Count = model.Count, + Date = model.Date, + info = model.info, + Type = (TypeRemittance)model.ModelTypeID, + }); + + result.Action = ComponentAction.update; + } + + + if (rsp.IsSuccessStatusCode) + { + result.Status = ComponentStatus.success; + + await OnMultipleOfThree.InvokeAsync(result); + + } + else + { + var request = await rsp.Content.ReadFromJsonAsync>(); + ShowDangerAlert(request[0]); + } + } + public async Task OnClickAddOrUpdate() + { + SpinnerVisible = true; + await Addorupdate(); + SpinnerVisible = false; + } + private async Task ShowConfirmationDeleteAsync() + { + if (!NewItem) + { + var confirmation = await dialog.ShowAsync( + title: "عملیات حذف سند انبار", + message1: $"{model.info}", + message2: "اطمینان دارید?"); + + if (confirmation) + await OnClickDelete(); + + + } + + } + private async Task ValidateRemittance() + { + if (model.Type == TypeCirculation.Remittance) + { + if (model.ModelTypeID != 3 && model.ModelTypeID != 4) + ShowDangerAlert("نوع سند صحیح نمی باشد"); + + else return await Validate(); + } + return false; + } + private async Task ValidateReceipt() + { + if (model.Type == TypeCirculation.Receipt) + { + model.ForSale = forsale; + if (model.ModelTypeID != 1 && model.ModelTypeID != 2) + ShowDangerAlert("نوع سند صحیح نمی باشد"); + + else return await Validate(); + } + return false; + + } + private async Task Validate() + { + + if (model.CODID == null || model.CODID == 0) + ShowDangerAlert("کالایی انتخاب کنید"); + if (model.Count <= 0) + ShowDangerAlert("تعدادی وارد کنید"); + if (string.IsNullOrEmpty(model.Date)) + ShowDangerAlert("تاریخ را مشخص کنید"); + if (model.Date.Replace("/", "").Length != 10) + ShowDangerAlert("تاریخ صحیح نمی باشد"); + if (string.IsNullOrEmpty(model.info)) + ShowDangerAlert("توضیحی مشخص کنید"); + else return true; + + return false; + } + private async Task>> CODDataProvider(AutoCompleteDataProviderRequest> request) + { + return await Task.FromResult(request.ApplyTo(CODrequest.OrderBy(cod => cod.ID))); + } + private void OnAutoCompleteChanged(CODIdName cOD) + { + model.CODID = cOD.ID; + } +} \ No newline at end of file diff --git a/TaxPayerFull/Pages/UserPanel/Warehouse.razor b/TaxPayerFull/Pages/UserPanel/Warehouse.razor index 88db301..1810e3c 100644 --- a/TaxPayerFull/Pages/UserPanel/Warehouse.razor +++ b/TaxPayerFull/Pages/UserPanel/Warehouse.razor @@ -1,5 +1,6 @@ انبارداری @page "/Warehouse" +@using Front.CUSComponent @using Front.Services @using Shared.DTOs @using Shared.DTOs.Warehouse @@ -20,7 +21,7 @@
  • -= + =
    @@ -157,7 +158,15 @@ string query = ""; if (!string.IsNullOrEmpty(date)) - query = $"date={date}&"; + { + if (date.Replace("/","").Length==10) + query = $"date={date}&"; + else + { + ShowDangerAlert("تاریخ صحیح نمی باشد"); + return; + } + } if (CODID != null && CODID != 0) query += $"CODID={CODID}&"; @@ -183,44 +192,41 @@ } public async Task CallBackItem(ActionInResultComponent result) { - + if (result.Status == ComponentStatus.success && result.Action==ComponentAction.delete) + ShowSuccessAlert("حذف با موفقیت انجام شد"); + if (result.Status == ComponentStatus.success && result.Action == ComponentAction.update) + ShowSuccessAlert("ویرایش با موفقیت انجام شد"); + if (result.Status == ComponentStatus.success && result.Action == ComponentAction.add) + ShowSuccessAlert("سند جدید اضافه شد"); + + if (result.Status==ComponentStatus.success) + { + await Load(1); + } } public async Task Item(CirculationDto circulationDto) { - //رسید + string title = ""; + //رسید if (circulationDto.Type == TypeCirculation.Receipt) - { - //جدید - if (circulationDto.CODID==0) - { - - } - else - { - - } - } - //حواله + title = "رسید"; + + //حواله if (circulationDto.Type == TypeCirculation.Remittance) - { - //جدید - if (circulationDto.CODID == 0) - { + title = "حواله"; - } - else - { - } - } - - // var parameters = new Dictionary(); + if (circulationDto.CODID == 0) + title += " جدید"; + else title = "اطلاعات " + title; + var parameters = new Dictionary(); - // if (ID == 0) parameters.Add("Cus", new RCustomer() { ID = 0 }); - // else parameters.Add("Cus", request.list.Where(w => w.ID == ID).First().Clone()); - // parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBackCustomerItem)); - // await modal.ShowAsync(title: ID == 0 ? "مشتری جدید" : "ویرایش اطلاعات", parameters: parameters); + parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBackItem)); + parameters.Add("model", circulationDto); + parameters.Add("NewItem", circulationDto.CODID == 0); + parameters.Add("CODrequest", CODrequest); + await modal.ShowAsync(title: title, parameters: parameters); }