327 lines
11 KiB
Plaintext
327 lines
11 KiB
Plaintext
@using Front.Services
|
|
@using Shared.DTOs
|
|
@inject HttpClientController hc;
|
|
<Modal @ref="modal" />
|
|
<ConfirmDialog @ref="dialog" />
|
|
<form>
|
|
@* alert *@
|
|
<div class="row">
|
|
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
|
|
<Icon Name="@alertIconName" class="me-2"></Icon>
|
|
@alertMessage
|
|
</Alert>
|
|
|
|
</div>
|
|
@if (Cod.ID != 0)
|
|
{
|
|
|
|
<ul>
|
|
|
|
@if (_SuccessfulSubmissiontoTaxPayer)
|
|
{
|
|
<li style="color:red">با این کالا صورتحسابی به سامانه مودیان ارسال کرده اید <br />نمیتوانید آن را ویرایش کنید</li>
|
|
}
|
|
else
|
|
{
|
|
@if (_UsedInTheInvoice)
|
|
{
|
|
<li style="color:indianred">با این کالا صورتحسابی صادر کرده اید <br />نمیتوانید نام کالا را ویرایش کنید</li>
|
|
<br />
|
|
}
|
|
<li style="color:dodgerblue">زمان ویرایش دقت کنید<br /> تغییرات میتواند روی فاکتورهای صادر شده تائیر بگذارد</li>
|
|
}
|
|
|
|
@if (InventoryValue > 0)
|
|
{
|
|
<li style="color:seagreen">موجودی کالا در انبار : @InventoryValue</li>
|
|
}
|
|
else
|
|
{
|
|
<li style="color:red">این کالا در انبار موجودی ندارد</li>
|
|
|
|
}
|
|
</ul>
|
|
}
|
|
<div class="row g-3">
|
|
<div class="form-group col-md-6">
|
|
<label class="col-sm-4 col-form-label" style="color:red" for="inputTitle">نام کالا</label>
|
|
@if (Cod.ID == 0 || !_UsedInTheInvoice)
|
|
{
|
|
<InputText style="text-align:center" @bind-Value="Cod.Title" type="text" class="form-control" id="inputTitle" placeholder="نام کالا" />
|
|
}
|
|
else
|
|
{
|
|
<InputText style="text-align:center" @bind-Value="Cod.Title" type="text" class="form-control" id="inputTitle" placeholder="نام کالا" readonly />
|
|
}
|
|
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label class="col-sm-5 col-form-label" style="color:red" for="inputUnitID">واحد اندازه گیزی</label>
|
|
<select @bind="Cod.UnitID" class="form-control" aria-label="Default select example" id="inputUnitID">
|
|
@if (Cod.UnitID > 0)
|
|
{
|
|
<option value="0" style="color: #b5b5b5">انتخاب کنید...</option>
|
|
|
|
}
|
|
else
|
|
{
|
|
<option value="0" style="color: #b5b5b5" selected>انتخاب کنید...</option>
|
|
|
|
}
|
|
|
|
@if (Unitrequest != null)
|
|
{
|
|
foreach (var item in Unitrequest)
|
|
{
|
|
if (Cod.UnitID == item.ID)
|
|
{
|
|
<option value="@item.ID" selected>@item.Title</option>
|
|
}
|
|
else
|
|
{
|
|
<option value="@item.ID">@item.Title</option>
|
|
}
|
|
}
|
|
}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<label class="col-sm-5 col-form-label">شناسه مالیاتی کالا</label>
|
|
<InputText dir="ltr" style="text-align:center" @bind-Value="Cod.TaxID" type="text" class="form-control" id="inputTaxID" placeholder="شناسه مالیاتی کالا" />
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label style="color:red" class="col-sm-5 col-form-label">% نرخ مالیات کالا</label>
|
|
<NumberInput dir="ltr" style="text-align:center" @bind-Value="Cod.TaxRate" type="number" class="form-control" id="inputTaxRate" placeholder="نرخ مالیات کالا" />
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
</form>
|
|
<div class="row g-3">
|
|
<div class="col-md-10">
|
|
@if (Cod.ID == 0)
|
|
{
|
|
<Button class="mt-3" Color="ButtonColor.Success" @onclick="OnClickAdd" Type="ButtonType.Button">
|
|
جدید
|
|
</Button>
|
|
}
|
|
else
|
|
{
|
|
@if (!_SuccessfulSubmissiontoTaxPayer)
|
|
{
|
|
<Button Disabled="SpinnerVisible" class="mt-3" Color="ButtonColor.Success" @onclick="OnClickUpdate" Type="ButtonType.Button">
|
|
ثبت تغییرات
|
|
</Button>
|
|
<Button Disabled="SpinnerVisible" class=" mt-3" Color="ButtonColor.Danger" @onclick="ShowConfirmationDeleteAsync" Type="ButtonType.Button">
|
|
حذف
|
|
</Button>
|
|
}
|
|
|
|
@if (_UsedInTheInvoice)
|
|
|
|
{
|
|
<Button Disabled="SpinnerVisible" class=" mt-3" Color="ButtonColor.Link" @onclick="OnClickGoToInvoice" Type="ButtonType.Button">
|
|
صورتحساب های مرتبط
|
|
</Button>
|
|
}
|
|
|
|
}
|
|
</div>
|
|
<div class="col-md-2">
|
|
<Spinner Visible="SpinnerVisible" Color="SpinnerColor.Primary" />
|
|
</div>
|
|
</div>
|
|
@code {
|
|
public bool SpinnerVisible { get; set; } = false;
|
|
private ConfirmDialog dialog = default!;
|
|
private Modal modal = default!;
|
|
// alert
|
|
AlertColor alertColor = AlertColor.Primary;
|
|
IconName alertIconName = IconName.CheckCircleFill;
|
|
bool Hidealert = true;
|
|
string alertMessage = "";
|
|
bool _UsedInTheInvoice = false;
|
|
bool _SuccessfulSubmissiontoTaxPayer = false;
|
|
[Parameter] public RCOD Cod { get; set; }
|
|
[Parameter] public EventCallback<ActionInResultComponent> OnMultipleOfThree { get; set; }
|
|
[Parameter] public List<IdName<int>>? Unitrequest { get; set; }
|
|
public ActionInResultComponent result { get; set; }
|
|
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
|
|
result = new ActionInResultComponent()
|
|
{
|
|
Status = ComponentStatus.fild
|
|
};
|
|
Hidealert = true;
|
|
alertMessage = "";
|
|
await UsedInTheInvoice();
|
|
await SuccessfulSubmissiontoTaxPayer();
|
|
// موجودی
|
|
await Inventory();
|
|
//
|
|
SpinnerVisible = false;
|
|
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<bool>();
|
|
|
|
else _UsedInTheInvoice = false;
|
|
}
|
|
|
|
}
|
|
public decimal InventoryValue { get; set; } = 0;
|
|
public async Task Inventory()
|
|
{
|
|
if (Cod.ID != 0)
|
|
{
|
|
var rsp = await hc.Get($"Warehouse/Inventory/{Cod.ID}");
|
|
if (rsp.IsSuccessStatusCode)
|
|
InventoryValue = await rsp.Content.ReadFromJsonAsync<decimal>();
|
|
}
|
|
}
|
|
public async Task SuccessfulSubmissiontoTaxPayer()
|
|
{
|
|
SpinnerVisible = true;
|
|
if (Cod.ID != 0)
|
|
{
|
|
var rsp = await hc.Get($"TaxPayer/CodInTaxPayerHaveBeenSentSuccessfully/{Cod.ID}");
|
|
if (rsp.IsSuccessStatusCode)
|
|
_SuccessfulSubmissiontoTaxPayer = await rsp.Content.ReadFromJsonAsync<bool>();
|
|
|
|
else _SuccessfulSubmissiontoTaxPayer = false;
|
|
}
|
|
|
|
SpinnerVisible = false;
|
|
}
|
|
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()
|
|
{
|
|
SpinnerVisible = true;
|
|
var rsp = await hc.Delete($"Cod/Delete/{Cod.ID}");
|
|
if (rsp.IsSuccessStatusCode)
|
|
{
|
|
var request = await rsp.Content.ReadFromJsonAsync<bool>();
|
|
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 = false;
|
|
|
|
}
|
|
public async Task OnClickUpdate()
|
|
{
|
|
SpinnerVisible = true;
|
|
if (Cod.UnitID > 0 && Cod.TaxRate >= 0 && !string.IsNullOrEmpty(Cod.Title))
|
|
{
|
|
|
|
var rsp = await hc.Put<RCOD>("Cod/Update", Cod);
|
|
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]);
|
|
}
|
|
}
|
|
else ShowDangerAlert("فیلدهای قرمز باید مقدار دهی شوند");
|
|
SpinnerVisible = false;
|
|
}
|
|
public async Task OnClickAdd()
|
|
{
|
|
SpinnerVisible = true;
|
|
if (Cod.UnitID > 0 && Cod.TaxRate >= 0 && !string.IsNullOrEmpty(Cod.Title))
|
|
{
|
|
|
|
var rsp = await hc.Post<RCOD>("Cod/Add", Cod);
|
|
if (rsp.IsSuccessStatusCode)
|
|
{
|
|
var request = await rsp.Content.ReadFromJsonAsync<bool>();
|
|
|
|
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("فیلدهای قرمز باید مقدار دهی شوند");
|
|
SpinnerVisible = false;
|
|
}
|
|
private async Task ShowConfirmationDeleteAsync()
|
|
{
|
|
if (Cod.ID.HasValue && Cod.ID.Value > 0)
|
|
{
|
|
var confirmation = await dialog.ShowAsync(
|
|
title: "عملیات حذف کالا",
|
|
message1: $"از حذف کالای {Cod.Title}",
|
|
message2: "اطمینان دارید?");
|
|
|
|
if (confirmation)
|
|
await OnClickDelete();
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |