@using Front.Services @using Shared.DTOs @inject HttpClientController hc;
@* alert *@
@if (Cus.ID != 0) { }
@if (Cus.ID == 0 || !_UsedInTheInvoice) { } else { }
@if (Cus.ID == 0) { } else { @if (!_SuccessfulSubmissiontoTaxPayer) { } @if (_UsedInTheInvoice) { } }
@code { public bool SpinnerVisible { get; set; } = false; // alert 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; } private ConfirmDialog dialog = default!; bool _SuccessfulSubmissiontoTaxPayer = false; public ActionInResultComponent result { get; set; } protected override async Task OnParametersSetAsync() { if (Cus.CustomerType != null) ItemSearchCustomertype = (int)Cus.CustomerType; result = new ActionInResultComponent() { Status = ComponentStatus.fild }; Hidealert = true; alertMessage = ""; await UsedInTheInvoice(); await SuccessfulSubmissiontoTaxPayer(); SpinnerVisible = false; await base.OnParametersSetAsync(); } } @functions { 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 OnClickGoToInvoice() { hc._nav.NavigateTo($"Invoice/{"cus:"+Cus.ID}"); } public async Task OnClickDelete() { SpinnerVisible = !SpinnerVisible; var rsp = await hc.Delete($"Customer/Delete/{Cus.ID}"); if (rsp.IsSuccessStatusCode) { var request = await rsp.Content.ReadFromJsonAsync(); if (request) { 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("خطایی در اجرای عملیات رخ داده"); SpinnerVisible = !SpinnerVisible; } public async Task OnClickUpdate() { SpinnerVisible = !SpinnerVisible; if (ItemSearchCustomertype > 0 && !string.IsNullOrEmpty(Cus.FullName)) { if (ItemSearchCustomertype > 0) Cus.CustomerType = (CustomerType)ItemSearchCustomertype; var rsp = await hc.Put("Customer/Update", Cus); if (rsp.IsSuccessStatusCode) { var request = await rsp.Content.ReadFromJsonAsync(); if (request) { result.Status = ComponentStatus.success; result.Action = ComponentAction.update; await OnMultipleOfThree.InvokeAsync(result); } else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); } else { var request = await rsp.Content.ReadFromJsonAsync>(); ShowDangerAlert(request[0]); } } else ShowDangerAlert("فیلدهای قرمز باید مقدار دهی شوند"); SpinnerVisible = !SpinnerVisible; } public async Task OnClickCheckEconomicCode() { SpinnerVisible = !SpinnerVisible; if (!string.IsNullOrEmpty(Cus.EconomicCode)) { var rsp = await hc.Get($"TaxPayer/EconomicCodeInformation?item={Cus.EconomicCode}"); if (rsp.IsSuccessStatusCode) { var request = await rsp.Content.ReadFromJsonAsync(); if (request.TaxpayerStatus != "ACTIVE") { ShowDangerAlert("کد اقتصادی فعال نیست"); } else ShowInfoAlert($"کد اقتصادی فعال و به نام '{request.NameTrade}' می باشد"); } else if (rsp.StatusCode == System.Net.HttpStatusCode.NotFound) { ShowDangerAlert("کد اقتصادی یافت نشد"); } else { ShowDangerAlert("خطا..."); } } else ShowDangerAlert("کد اقعصادی را مشخص کنید"); SpinnerVisible = !SpinnerVisible; } public async Task OnClickAdd() { if ((ItemSearchCustomertype == 1 || ItemSearchCustomertype == 2 || ItemSearchCustomertype == 3 || ItemSearchCustomertype == 4) && string.IsNullOrEmpty(Cus.EconomicCode)) { ShowDangerAlert("در این نوع خریدار کد اقتصادی الزامی می باشد"); return; } if ((ItemSearchCustomertype == 5 || ItemSearchCustomertype == 6) && (string.IsNullOrEmpty(Cus.MeliCode) || string.IsNullOrEmpty(Cus.ZipCode))) { ShowDangerAlert("در این نوع خریدار شناسه ملی با کد پستی الزامی می باشد"); return; } SpinnerVisible = !SpinnerVisible; if (ItemSearchCustomertype > 0 && !string.IsNullOrEmpty(Cus.FullName)) { if (ItemSearchCustomertype > 0) Cus.CustomerType = (CustomerType)ItemSearchCustomertype; Cus.ID = null; var rsp = await hc.Post("Customer/Add", Cus); if (rsp.IsSuccessStatusCode) { var request = await rsp.Content.ReadFromJsonAsync(); if (request) { result.Status = ComponentStatus.success; result.Action = ComponentAction.add; await OnMultipleOfThree.InvokeAsync(result); } else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); } else { var request = await rsp.Content.ReadFromJsonAsync>(); ShowDangerAlert(request[0]); } } else ShowDangerAlert("فیلدهای قرمز باید مقدار دهی شوند"); SpinnerVisible = !SpinnerVisible; } public async Task UsedInTheInvoice() { SpinnerVisible = !SpinnerVisible; if (Cus.ID!=0) { var rsp = await hc.Get($"Customer/UsedInTheInvoice/{Cus.ID}"); if (rsp.IsSuccessStatusCode) _UsedInTheInvoice = await rsp.Content.ReadFromJsonAsync(); else _UsedInTheInvoice = false; } SpinnerVisible = !SpinnerVisible; } public async Task SuccessfulSubmissiontoTaxPayer() { SpinnerVisible = !SpinnerVisible; if (Cus.ID != 0) { var rsp = await hc.Get($"TaxPayer/CustomerInTaxPayerHaveBeenSentSuccessfully/{Cus.ID}"); if (rsp.IsSuccessStatusCode) _SuccessfulSubmissiontoTaxPayer = await rsp.Content.ReadFromJsonAsync(); else _SuccessfulSubmissiontoTaxPayer = false; } SpinnerVisible = !SpinnerVisible; } private void ShowInfoAlert(string msg) { Hidealert = false; alertColor = AlertColor.Info; alertIconName = IconName.CheckCircleFill; alertMessage = msg; } private async Task ShowConfirmationDeleteAsync() { if (Cus.ID.HasValue && Cus.ID.Value > 0) { var confirmation = await dialog.ShowAsync( title: "عملیات حذف مشتری", message1: $"از حذف مشتری {Cus.FullName}", message2: "اطمینان دارید?"); if (confirmation) await OnClickDelete(); } } }