Files
moadiran/TaxPayerFull/CUSComponent/CustomerItem.razor

338 lines
13 KiB
Plaintext
Raw Normal View History

2024-05-07 18:17:51 +03:30
@using Front.Services
@using Shared.DTOs
@inject HttpClientController hc;
2024-07-25 19:15:05 +03:30
<ConfirmDialog @ref="dialog" />
2024-05-07 17:49:02 +03:30
<form>
2024-05-07 18:17:51 +03:30
@* alert *@
<div class="row">
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
<Icon Name="@alertIconName" class="me-2"></Icon>
@alertMessage
</Alert>
</div>
2024-06-27 13:35:06 +03:30
@if (Cus.ID != 0)
{
<h6 style="color:red">نکته:</h6>
<ul>
2024-06-27 19:18:50 +03:30
@if (_UsedInTheInvoice)
{
<li>با این مشتری صورتحسابی صادر کرده اید ، نمیتوانید نام کامل را ویرایش کنید</li>
}
2024-06-27 13:35:06 +03:30
<li>زمان ویرایش دقت کنید تغییرات میتواند روی فاکتورهای صادر شده تائیر بگذارد</li>
</ul>
}
2024-05-07 17:49:02 +03:30
<div class="row g-3">
<div class="form-group col-md-6">
<label class="col-sm-4 col-form-label" style="color:red" for="inputFullName">نام کامل</label>
2024-06-27 19:18:50 +03:30
@if (Cus.ID == 0 || !_UsedInTheInvoice)
2024-06-27 13:35:06 +03:30
{
2024-10-14 15:56:45 +03:30
<InputText style="text-align:center" @bind-Value="Cus.FullName" type="text" class="form-control" id="inputFullName" placeholder="نام کامل" />
2024-06-27 13:35:06 +03:30
}
else
{
2024-10-14 15:56:45 +03:30
<InputText style="text-align:center" @bind-Value="Cus.FullName" type="text" class="form-control" id="inputFullName" placeholder="نام کامل" readonly />
2024-06-27 13:35:06 +03:30
}
2024-05-08 17:25:02 +03:30
</div>
2024-05-07 17:49:02 +03:30
<div class="form-group col-md-6">
<label class="col-sm-4 col-form-label" style="color:red" for="inputcustomertype">نوع مشتری</label>
2024-05-07 18:00:21 +03:30
<select @bind="ItemSearchCustomertype" class="form-control" aria-label="Default select example" id="inputcustomertype">
2024-05-07 17:49:02 +03:30
<option value="0" style="color: #b5b5b5" selected>انتخاب کنید...</option>
<option value="1">حقیقی</option>
<option value="2">حقوقی</option>
<option value="3">مشارکت مدنی</option>
<option value="4">اتباع غیر ایرانی</option>
</select>
</div>
</div>
2024-05-08 17:25:02 +03:30
2024-05-07 17:49:02 +03:30
<div class="row g-3">
<div class="col-md-6">
<label class="col-sm-4 col-form-label">تلفن</label>
2024-10-14 15:56:45 +03:30
<InputText style="text-align:center" dir="ltr" @bind-Value="Cus.Phone" type="number" class="form-control" id="inputPhone" placeholder="تلفن" />
2024-05-07 17:49:02 +03:30
</div>
<div class="col-md-6">
<label class="col-sm-4 col-form-label">آدرس</label>
2024-10-14 15:56:45 +03:30
<InputText style="text-align:center" @bind-Value="Cus.Address" type="text" class="form-control" id="inputAddress" placeholder="آدرس" />
2024-05-07 17:49:02 +03:30
</div>
2024-05-08 17:25:02 +03:30
</div>
2024-05-07 17:49:02 +03:30
<div class="row g-3">
<div class="col-md-6">
<label class="col-sm-4 col-form-label">پست الکترونیک</label>
2024-10-14 15:56:45 +03:30
<InputText @bind-Value="Cus.Email" style="text-align:center" dir="ltr" type="email" class="form-control" id="inputEmail" placeholder="پست الکترونیک" />
2024-05-07 17:49:02 +03:30
</div>
<div class="col-md-6">
<label class="col-sm-4 col-form-label">کد پستی</label>
2024-10-14 15:56:45 +03:30
<InputText style="text-align:center" dir="ltr" @bind-Value="Cus.ZipCode" type="number" class="form-control" id="inputZipCode" placeholder="کد پستی" />
2024-05-07 17:49:02 +03:30
</div>
2024-05-08 17:25:02 +03:30
</div>
2024-05-07 17:49:02 +03:30
<div class="row g-3">
<div class="col-md-6">
<label class="col-sm-4 col-form-label">کد اقتصادی</label>
2024-10-14 15:56:45 +03:30
<InputText @bind-Value="Cus.EconomicCode" type="number" style="text-align:center" dir="ltr" class="form-control" id="inputEconomicCode" placeholder="کد اقتصادی" />
2024-05-07 17:49:02 +03:30
</div>
<div class="col-md-6">
2024-10-14 15:56:45 +03:30
<label class="col-sm-4 col-form-label">کد/شناسه ملی</label>
<InputText @bind-Value="Cus.MeliCode" type="number" style="text-align:center" dir="ltr" class="form-control" id="inputMeliCode" placeholder="کدملی / شناسه ملی" />
2024-05-07 17:49:02 +03:30
</div>
</div>
<div class="row g-3">
<div class="col-md-6">
<label class="col-sm-4 col-form-label">کد شعبه</label>
2024-10-14 15:56:45 +03:30
<InputText @bind-Value="Cus.BranchID" type="number" style="text-align:center" dir="ltr" class="form-control" id="inputBranchID" placeholder="کد شعبه" />
2024-05-07 17:49:02 +03:30
</div>
<div class="col-md-6">
<label class="col-sm-4 col-form-label">شماره گذرنامه</label>
2024-10-14 15:56:45 +03:30
<InputText @bind-Value="Cus.PassportNumber" type="number" style="text-align:center" dir="ltr" class="form-control" id="inputPassportNumber" placeholder="شماره گذرنامه" />
2024-05-07 17:49:02 +03:30
</div>
</div>
<div class="row g-3">
<div class="col-md-12">
<label class="col-sm-4 col-form-label">توضیحات</label>
2024-10-14 15:56:45 +03:30
<InputTextArea @bind-Value="Cus.Info" style="text-align:right" class="form-control" id="inputMeliInfo" placeholder="توضیحات" rows="3"></InputTextArea>
2024-05-07 17:49:02 +03:30
</div>
2024-05-08 17:25:02 +03:30
2024-05-07 17:49:02 +03:30
</div>
2024-05-08 17:25:02 +03:30
2024-05-07 17:49:02 +03:30
</form>
2024-10-14 15:56:45 +03:30
<div class="row g-3">
<div class="col-md-10">
2024-05-08 17:25:02 +03:30
@if (Cus.ID == 0)
2024-05-07 13:55:11 +03:30
{
2024-10-16 23:36:52 +03:30
<Button Disabled="SpinnerVisible" class="mt-3" Color="ButtonColor.Success" @onclick="OnClickAdd" Type="ButtonType.Button">
2024-05-07 13:55:11 +03:30
جدید
</Button>
}
else
{
2024-10-16 23:36:52 +03:30
<Button Disabled="SpinnerVisible" class="mt-3" Color="ButtonColor.Success" @onclick="OnClickUpdate" Type="ButtonType.Button">
2024-05-07 13:55:11 +03:30
ثبت تغییرات
</Button>
2024-10-14 15:56:45 +03:30
<Button Disabled="SpinnerVisible" class="mt-3" Color="ButtonColor.Danger" @onclick="ShowConfirmationDeleteAsync" Type="ButtonType.Button">
2024-05-08 17:25:02 +03:30
حذف
2024-05-07 13:55:11 +03:30
</Button>
2024-06-27 19:18:50 +03:30
@if (_UsedInTheInvoice)
{
2024-10-14 15:56:45 +03:30
<Button Disabled="SpinnerVisible" class="mt-3" Color="ButtonColor.Link" @onclick="OnClickGoToInvoice" Type="ButtonType.Button">
2024-06-27 19:18:50 +03:30
صورتحساب های مرتبط
</Button>
}
2024-05-07 13:55:11 +03:30
}
2024-10-16 23:36:52 +03:30
<Button Disabled="SpinnerVisible" class="mt-3" Color="ButtonColor.Info" @onclick="OnClickCheckEconomicCode" Type="ButtonType.Button">
بررسی کد اقتصادی
</Button>
2024-10-14 15:56:45 +03:30
</div>
<div class="col-md-2" style="align-content:center">
<Spinner Visible="SpinnerVisible" Color="SpinnerColor.Primary" />
</div>
</div>
2024-05-07 13:55:11 +03:30
@code {
2024-10-14 15:56:45 +03:30
public bool SpinnerVisible { get; set; } = false;
2024-05-07 18:17:51 +03:30
// alert
AlertColor alertColor = AlertColor.Primary;
IconName alertIconName = IconName.CheckCircleFill;
bool Hidealert = true;
2024-06-27 19:18:50 +03:30
bool _UsedInTheInvoice = false;
2024-05-07 18:17:51 +03:30
string alertMessage = "";
2024-05-07 13:55:11 +03:30
[Parameter] public RCustomer Cus { get; set; }
2024-05-07 18:00:21 +03:30
public int? ItemSearchCustomertype { get; set; }
2024-05-07 13:55:11 +03:30
[Parameter] public EventCallback<ActionInResultComponent> OnMultipleOfThree { get; set; }
2024-07-25 19:15:05 +03:30
private ConfirmDialog dialog = default!;
2024-05-07 13:55:11 +03:30
public ActionInResultComponent result { get; set; }
2024-06-27 19:18:50 +03:30
protected override async Task OnParametersSetAsync()
2024-05-07 13:55:11 +03:30
{
2024-05-08 17:25:02 +03:30
if (Cus.CustomerType != null)
ItemSearchCustomertype = (int)Cus.CustomerType;
result = new ActionInResultComponent()
{
Status = ComponentStatus.fild
};
Hidealert = true;
alertMessage = "";
2024-06-27 19:18:50 +03:30
await UsedInTheInvoice();
2024-10-14 15:56:45 +03:30
SpinnerVisible = false;
2024-06-27 19:18:50 +03:30
await base.OnParametersSetAsync();
2024-05-07 13:55:11 +03:30
}
}
2024-05-08 17:25:02 +03:30
@functions {
2024-05-07 18:17:51 +03:30
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;
}
2024-06-27 19:18:50 +03:30
public async Task OnClickGoToInvoice()
{
hc._nav.NavigateTo($"Invoice/{"cus:"+Cus.ID}");
}
2024-05-08 17:25:02 +03:30
public async Task OnClickDelete()
2024-05-07 13:55:11 +03:30
{
2024-10-14 15:56:45 +03:30
SpinnerVisible = !SpinnerVisible;
2024-05-08 17:25:02 +03:30
var rsp = await hc.Delete($"Customer/Delete/{Cus.ID}");
2024-05-07 18:17:51 +03:30
if (rsp.IsSuccessStatusCode)
{
2024-05-08 17:25:02 +03:30
var request = await rsp.Content.ReadFromJsonAsync<bool>();
2024-05-07 18:17:51 +03:30
if (request)
{
2024-05-08 17:25:02 +03:30
result.Status = ComponentStatus.success;
result.Action = ComponentAction.delete;
2024-05-07 18:17:51 +03:30
await OnMultipleOfThree.InvokeAsync(result);
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
2024-05-08 17:25:02 +03:30
else if (rsp.StatusCode == System.Net.HttpStatusCode.NotFound)
{
ShowDangerAlert("مشتری با این شناسه یافت نشد");
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
2024-10-14 15:56:45 +03:30
SpinnerVisible = !SpinnerVisible;
2024-05-08 17:25:02 +03:30
}
public async Task OnClickUpdate()
{
2024-10-14 15:56:45 +03:30
SpinnerVisible = !SpinnerVisible;
2024-05-08 17:25:02 +03:30
if (ItemSearchCustomertype > 0 && !string.IsNullOrEmpty(Cus.FullName))
2024-05-07 18:17:51 +03:30
{
2024-05-08 17:25:02 +03:30
if (ItemSearchCustomertype > 0)
Cus.CustomerType = (CustomerType)ItemSearchCustomertype;
var rsp = await hc.Put<RCustomer>("Customer/Update", Cus);
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<bool>();
if (request)
{
result.Status = ComponentStatus.success;
result.Action = ComponentAction.update;
await OnMultipleOfThree.InvokeAsync(result);
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
2024-05-07 18:17:51 +03:30
}
2024-05-08 17:25:02 +03:30
else ShowDangerAlert("فیلدهای قرمز باید مقدار دهی شوند");
2024-10-14 15:56:45 +03:30
SpinnerVisible = !SpinnerVisible;
2024-10-16 23:36:52 +03:30
}
public async Task OnClickCheckEconomicCode()
{
SpinnerVisible = !SpinnerVisible;
if (!string.IsNullOrEmpty(Cus.EconomicCode))
{
2024-10-17 15:11:45 +03:30
2024-10-16 23:36:52 +03:30
var rsp = await hc.Get($"TaxPayer/EconomicCodeInformation?item={Cus.EconomicCode}");
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<EconomicCodeModelDto>();
2024-10-17 15:11:45 +03:30
if (request.TaxpayerStatus != "ACTIVE")
{
ShowDangerAlert("کد اقتصادی فعال نیست");
}
else
ShowInfoAlert($"کد اقتصادی فعال و به نام '{request.NameTrade}' می باشد");
2024-10-16 23:36:52 +03:30
}
2024-10-17 15:11:45 +03:30
else if (rsp.StatusCode == System.Net.HttpStatusCode.NotFound)
2024-10-16 23:36:52 +03:30
{
2024-10-17 15:11:45 +03:30
ShowDangerAlert("کد اقتصادی یافت نشد");
}
2024-10-16 23:36:52 +03:30
else
{
2024-10-17 15:11:45 +03:30
ShowDangerAlert("خطا...");
2024-10-16 23:36:52 +03:30
}
}
else ShowDangerAlert("کد اقعصادی را مشخص کنید");
SpinnerVisible = !SpinnerVisible;
2024-05-08 17:25:02 +03:30
}
public async Task OnClickAdd()
{
2024-10-14 15:56:45 +03:30
SpinnerVisible = !SpinnerVisible;
2024-05-08 17:25:02 +03:30
if (ItemSearchCustomertype > 0 && !string.IsNullOrEmpty(Cus.FullName))
{
if (ItemSearchCustomertype > 0)
Cus.CustomerType = (CustomerType)ItemSearchCustomertype;
Cus.ID = null;
var rsp = await hc.Post<RCustomer>("Customer/Add", Cus);
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<bool>();
2024-05-07 18:17:51 +03:30
2024-05-08 17:25:02 +03:30
if (request)
{
result.Status = ComponentStatus.success;
result.Action = ComponentAction.add;
await OnMultipleOfThree.InvokeAsync(result);
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
}
else ShowDangerAlert("فیلدهای قرمز باید مقدار دهی شوند");
2024-10-14 15:56:45 +03:30
SpinnerVisible = !SpinnerVisible;
2024-05-07 13:55:11 +03:30
}
2024-06-27 19:18:50 +03:30
public async Task UsedInTheInvoice()
{
2024-10-14 15:56:45 +03:30
SpinnerVisible = !SpinnerVisible;
2024-06-27 19:18:50 +03:30
if (Cus.ID!=0)
{
var rsp = await hc.Get($"Customer/UsedInTheInvoice/{Cus.ID}");
if (rsp.IsSuccessStatusCode)
_UsedInTheInvoice = await rsp.Content.ReadFromJsonAsync<bool>();
else _UsedInTheInvoice = false;
}
2024-10-14 15:56:45 +03:30
SpinnerVisible = !SpinnerVisible;
2024-06-27 19:18:50 +03:30
}
2024-10-17 15:11:45 +03:30
private void ShowInfoAlert(string msg)
{
Hidealert = false;
alertColor = AlertColor.Info;
alertIconName = IconName.CheckCircleFill;
alertMessage = msg;
}
2024-07-25 19:15:05 +03:30
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();
}
}
2024-05-07 13:55:11 +03:30
}