299 lines
10 KiB
Plaintext
299 lines
10 KiB
Plaintext
@using Front.Services
|
|
@using Shared.DTOs
|
|
@inject HttpClientController hc;
|
|
@inject Fixedvalues fv;
|
|
<form>
|
|
@* alert *@
|
|
<div class="row">
|
|
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
|
|
<Icon Name="@alertIconName" class="me-2"></Icon>
|
|
@alertMessage
|
|
</Alert>
|
|
|
|
</div>
|
|
<div class="row g-3">
|
|
|
|
<div class="form-group col-md-6">
|
|
<label class="col-sm-4 col-form-label" style="color:red" for="inputcod">کالا</label>
|
|
<select @bind="itemDTO.CODID" @bind:after="() =>
|
|
{
|
|
if(itemDTO.ID==null)
|
|
itemDTO.vra=cods.Where(w=>w.ID==itemDTO.CODID).Select(s=>s.Tax).FirstOrDefault();
|
|
}" class="form-control" aria-label="Default select example" id="inputcod">
|
|
@if (itemDTO.CODID > 0)
|
|
{
|
|
<option value="0" style="color: #b5b5b5">انتخاب کنید...</option>
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
<option value="0" style="color: #b5b5b5" selected>انتخاب کنید...</option>
|
|
|
|
}
|
|
|
|
@if (cods != null)
|
|
{
|
|
foreach (var item in cods)
|
|
{
|
|
if (itemDTO.CODID == item.ID)
|
|
{
|
|
<option value="@item.ID" selected>@item.Title</option>
|
|
}
|
|
else
|
|
{
|
|
<option value="@item.ID">@item.Title</option>
|
|
}
|
|
}
|
|
}
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label class="col-sm-4 col-form-label" style="color:red" for="inputFullName">تعداد</label>
|
|
<InputNumber @bind-Value="itemDTO.am" @bind-Value:after="AfterAsync" type="text" class="form-control" id="inputam" placeholder="تعداد" />
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label style="color:red" class="col-sm-6 col-form-label">مبلغ واحد</label>
|
|
<InputNumber @bind-Value="itemDTO.fee" @bind-Value:after="AfterAsync" type="text" class="form-control" id="inputfee" placeholder="مبلغ واحد" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-3">
|
|
<div class="form-group col-md-4">
|
|
<label class="col-sm-6 col-form-label">مبلغ کل</label>
|
|
<InputNumber @bind-Value="itemDTO.prdis" type="text" class="form-control" id="inputfee" placeholder="مبلغ کل" readonly />
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="col-sm-6 col-form-label">مبلغ تخفیف</label>
|
|
<InputNumber @bind-Value="itemDTO.dis" type="text" @bind-Value:after="AfterAsync" class="form-control" id="inputdis" placeholder="مبلغ تخفیف" />
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="col-sm-8 col-form-label">مبلغ بعد تخفیف</label>
|
|
<InputNumber @bind-Value="itemDTO.adis" type="text" class="form-control" id="inputadis" placeholder="مبلغ تخفیف" readonly />
|
|
</div>
|
|
</div>
|
|
<div class="row g-3">
|
|
<div class="form-group col-md-4">
|
|
<label class="col-sm-6 col-form-label">نرخ مالیات</label>
|
|
<InputNumber @bind-Value="itemDTO.vra" type="text" class="form-control" id="inputvra" placeholder="نرخ مالیات" readonly />
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label class="col-sm-6 col-form-label">مبلغ مالیات</label>
|
|
<InputNumber @bind-Value="itemDTO.vam" type="text" class="form-control" id="inputvra" placeholder="مبلغ مالیات" readonly />
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label class="col-sm-6 col-form-label">مبلغ نهایی</label>
|
|
<InputNumber @bind-Value="itemDTO.tsstam" type="text" class="form-control" id="inputvra" placeholder="مبلغ نهایی" readonly />
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
|
|
@if (itemDTO.ID == null)
|
|
{
|
|
<Button class="mt-3" Color="ButtonColor.Success" @onclick="OnClickAdd" Type="ButtonType.Button">
|
|
جدید
|
|
</Button>
|
|
}
|
|
else
|
|
{
|
|
<Button class="mt-3" Color="ButtonColor.Success" @onclick="OnClickUpdate" Type="ButtonType.Button">
|
|
ثبت تغییرات
|
|
</Button>
|
|
<Button class="mt-3" Color="ButtonColor.Danger" @onclick="OnClickDelete" Type="ButtonType.Button">
|
|
حذف
|
|
</Button>
|
|
}
|
|
|
|
|
|
@code {
|
|
// alert
|
|
AlertColor alertColor = AlertColor.Primary;
|
|
IconName alertIconName = IconName.CheckCircleFill;
|
|
bool Hidealert = true;
|
|
string alertMessage = "";
|
|
public int Tax { get; set; } = 0;
|
|
[Parameter] public int InvoiceID { get; set; }
|
|
[Parameter] public InvoiceItemDTO itemDTO { get; set; }
|
|
[Parameter] public EventCallback<ActionInResultComponent> OnMultipleOfThree { get; set; }
|
|
public List<CODIdName<int>> cods { get; set; } = new();
|
|
public ActionInResultComponent result { get; set; }
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
cods = await fv.GetCODs();
|
|
await base.OnInitializedAsync();
|
|
}
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
|
|
result = new ActionInResultComponent()
|
|
{
|
|
Status = ComponentStatus.fild
|
|
};
|
|
Hidealert = true;
|
|
alertMessage = "";
|
|
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;
|
|
}
|
|
//-----------------------
|
|
private async Task prdisAsync()
|
|
{
|
|
if (itemDTO.ID == null)
|
|
itemDTO.prdis = itemDTO.fee * itemDTO.am;
|
|
}
|
|
private async Task adisAsync()
|
|
{
|
|
if (itemDTO.ID == null)
|
|
itemDTO.adis = itemDTO.prdis - itemDTO.dis;
|
|
|
|
// await AftervamAsync();
|
|
}
|
|
private async Task vamAsync()
|
|
{
|
|
if (itemDTO.ID == null)
|
|
itemDTO.vam = itemDTO.vra * itemDTO.adis / 100;
|
|
}
|
|
private async Task tsstamAsync()
|
|
{
|
|
if (itemDTO.ID == null)
|
|
itemDTO.tsstam = itemDTO.vam + itemDTO.adis;
|
|
}
|
|
private async Task AfterAsync()
|
|
{
|
|
await prdisAsync();
|
|
await adisAsync();
|
|
await vamAsync();
|
|
await tsstamAsync();
|
|
}
|
|
//-----------------------
|
|
public async Task OnClickDelete()
|
|
{
|
|
|
|
var rsp = await hc.Delete($"InvoiceItem/DeleteItem/{InvoiceID}/{itemDTO.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
|
|
{
|
|
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
|
|
ShowDangerAlert(request[0]);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
public async Task OnClickUpdate()
|
|
{
|
|
if (itemDTO.CODID == null || itemDTO.CODID <= 0)
|
|
{
|
|
ShowDangerAlert("کالا انتخاب نشده");
|
|
return;
|
|
}
|
|
|
|
if (itemDTO.am == null || itemDTO.am <= 0)
|
|
{
|
|
ShowDangerAlert("تعداد وارد نشده");
|
|
return;
|
|
}
|
|
|
|
if (itemDTO.fee == null || itemDTO.fee < 0)
|
|
{
|
|
ShowDangerAlert("مبلغ واحد وارد نشده");
|
|
return;
|
|
}
|
|
|
|
if (itemDTO.dis == null || itemDTO.dis < 0)
|
|
{
|
|
ShowDangerAlert("مبلغ تخفیف درست نیست");
|
|
return;
|
|
}
|
|
var rsp = await hc.Put<InvoiceItemDTO>($"InvoiceItem/UpdateItem/{InvoiceID}", itemDTO);
|
|
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]);
|
|
}
|
|
}
|
|
public async Task OnClickAdd()
|
|
{
|
|
if (itemDTO.CODID == null || itemDTO.CODID <= 0)
|
|
{
|
|
ShowDangerAlert("کالا انتخاب نشده");
|
|
return;
|
|
}
|
|
|
|
if (itemDTO.am == null || itemDTO.am <= 0)
|
|
{
|
|
ShowDangerAlert("تعداد وارد نشده");
|
|
return;
|
|
}
|
|
|
|
if (itemDTO.fee == null || itemDTO.fee < 0)
|
|
{
|
|
ShowDangerAlert("مبلغ واحد وارد نشده");
|
|
return;
|
|
}
|
|
|
|
if (itemDTO.dis == null || itemDTO.dis < 0)
|
|
{
|
|
ShowDangerAlert("مبلغ تخفیف درست نیست");
|
|
return;
|
|
}
|
|
|
|
var rsp = await hc.Post<InvoiceItemDTO>($"InvoiceItem/AddItem/{InvoiceID}", itemDTO);
|
|
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]);
|
|
}
|
|
|
|
}
|
|
} |