This commit is contained in:
mmrbnjd
2024-05-26 17:25:34 +03:30
parent 58940b9e50
commit b2b2e2cf2d
7 changed files with 299 additions and 151 deletions

View File

@@ -122,38 +122,38 @@
<br /> <hr class="hr" />
<div class="row g-3">
<Tabs NavStyle="NavStyle.VerticalUnderline">
<Tab Title="آیتم ها" IsActive="true">
<Tab Title="آیتم ها" IsActive="InvoiceID==0 || InvoiceID==null ? false : true">
<Content>
<div class="row g-3">
<div class="form-group col-md-11">
<LGridInvoiceItem OnMultipleOfThree="EventCallback.Factory.Create<string>(this, CallBack)" InvoiceItems="invoice.items" />
<LGridInvoiceItem InvoiceID="InvoiceID??0" OnMultipleOfThree="EventCallback.Factory.Create<string>(this, CallBack)" InvoiceItems="invoice.items" />
</div>
<div class="form-group col-md-1">
<Button class="mt-3" Color="ButtonColor.Dark" @onclick="NewItemClick" Outline="true" Type="ButtonType.Button">
+
</Button>
</div>
</div>
</div>
</Content>
</Tab>
@* <Tab Title="پرداختی ها">
<Content>
<div class="row g-3">
<div class="form-group col-md-11">
<LGridInvoicePayment InvoicePays="invoice.payments" />
</div>
<div class="form-group col-md-1">
@* <Tab Title="پرداختی ها">
<Content>
<div class="row g-3">
<div class="form-group col-md-11">
<LGridInvoicePayment InvoicePays="invoice.payments" />
</div>
<div class="form-group col-md-1">
<Button class="mt-3" Color="ButtonColor.Dark" @onclick="OnClickDelete" Outline="true" Type="ButtonType.Button">
+
</Button>
</div>
</div>
<Button class="mt-3" Color="ButtonColor.Dark" @onclick="OnClickDelete" Outline="true" Type="ButtonType.Button">
+
</Button>
</div>
</div>
</Content>
</Content>
</Tab> *@
</Tabs>
@@ -216,7 +216,7 @@
invoice = new InvoiceDTO();
await base.OnInitializedAsync();
}
protected override async Task OnParametersSetAsync()
{
PreloadService.Show(SpinnerColor.Dark);
@@ -224,7 +224,7 @@
Patterns = await fv.GetPatterns();
if (InvoiceID != null && InvoiceID > 0)
{
await LoadData();
}
else
@@ -248,12 +248,16 @@
@functions {
private async Task NewItemClick()
{
var parameters = new Dictionary<string, object>();
if (InvoiceID.HasValue)
{
var parameters = new Dictionary<string, object>();
parameters.Add("InvoiceID", InvoiceID);
parameters.Add("itemDTO", new InvoiceItemDTO());
parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create<ActionInResultComponent>(this, CallBack));
await modal.ShowAsync<CUSComponent.InvoiceItem>(title: "آیتم جدید", parameters: parameters);
}
parameters.Add("itemDTO", new InvoiceItemDTO());
parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create<ActionInResultComponent>(this, CallBack));
await modal.ShowAsync<CUSComponent.InvoiceItem>(title: "آیتم جدید", parameters: parameters);
}
private async Task LoadData()
@@ -285,7 +289,7 @@
// if (result.Status == ComponentStatus.success)
// msg = "آیتم با موفقیت حذف شد";
// }
await CallBack(msg);
await CallBack(msg);
// if (result.Status == ComponentStatus.success)
// await LoadCod(1);
@@ -296,7 +300,7 @@
if (!string.IsNullOrEmpty(result))
{
ShowSuccessAlert(result);
await LoadData();
await LoadData();
}
}
private void ShowSuccessAlert(string msg)
@@ -315,33 +319,62 @@
}
public async Task OnClickDelete()
{
if (InvoiceID.HasValue)
{
var rsp = await hc.Delete($"Invoice/Delete/{InvoiceID.Value}");
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<bool>();
if (request)
{
hc._nav.NavigateTo("Invoice");
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
// var rsp = await hc.Delete($"Cod/Delete/{invoice.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("خطایی در اجرای عملیات رخ داده");
else if (rsp.StatusCode == System.Net.HttpStatusCode.NotFound)
{
ShowDangerAlert("صورتحساب با این شناسه یافت نشد");
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
}
public async Task OnClickUpdate()
{
if (InvoiceID.HasValue)
{
if (await Validate())
{
var rsp = await hc.Put<NUInvoiceDTO>("Invoice/Update", new NUInvoiceDTO
{
ID = InvoiceID,
CustomerID = invoice.CustomerID,
Des = invoice.Des,
InvoiceDate = invoice.InvoiceDate,
InvoicIssueDate = invoice.InvoicIssueDate,
PatternID = invoice.PatternID,
Title = invoice.Title
});
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<int>();
if (request > 0)
{
InvoiceID = request;
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
}
}
// if (Cod.UnitID > 0 && Cod.TaxRate > 0 && !string.IsNullOrEmpty(Cod.Title))
// {
@@ -367,33 +400,88 @@
}
public async Task OnClickAdd()
{
// if (Cod.UnitID > 0 && Cod.TaxRate > 0 && !string.IsNullOrEmpty(Cod.Title))
// {
if (await Validate())
{
var rsp = await hc.Post<NUInvoiceDTO>("Invoice/Add", new NUInvoiceDTO
{
CustomerID = invoice.CustomerID,
Des = invoice.Des,
InvoiceDate = invoice.InvoiceDate,
InvoicIssueDate = invoice.InvoicIssueDate,
PatternID = invoice.PatternID,
Title = invoice.Title
});
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<int>();
// var rsp = await hc.Post<RCOD>("Cod/Add", Cod);
// if (rsp.IsSuccessStatusCode)
// {
// var request = await rsp.Content.ReadFromJsonAsync<bool>();
if (request > 0)
{
InvoiceID = request;
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
// 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]);
}
}
// var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
// ShowDangerAlert(request[0]);
// }
// }
// else ShowDangerAlert("فیلدهای قرمز باید مقدار دهی شوند");
}
public async Task<bool> Validate()
{
return false;
if (string.IsNullOrEmpty(invoice.Title))
{
ShowDangerAlert("عنوان نمی تواند خالی باشد");
return false;
}
if (string.IsNullOrEmpty(invoice.InvoiceDate))
{
ShowDangerAlert("تاریخ صورتحساب نمی تواند خالی باشد");
return false;
}
else
{
int InvoiceDate = 0;
if (invoice.InvoiceDate.Replace("/", "").Length != 8 || !int.TryParse(invoice.InvoiceDate.Replace("/", ""), out InvoiceDate))
{
ShowDangerAlert("تاریخ صورتحساب صحیح نمی باشد");
return false;
}
else if (InvoiceDate.ToString().Trim().ToMiladiinFront() > DateTime.Now)
{
ShowDangerAlert("تاریخ صورتحساب نمی تواند از امروز جلوتر باشد");
return false;
}
}
if (string.IsNullOrEmpty(invoice.InvoicIssueDate))
{ ShowDangerAlert("تاریخ صدور نمی تواند خالی باشد"); return false; }
else
{
int InvoicIssueDate = 0;
if (invoice.InvoicIssueDate.Replace("/", "").Length != 8 || !int.TryParse(invoice.InvoicIssueDate.Replace("/", ""), out InvoicIssueDate))
{ ShowDangerAlert("تاریخ صدور صحیح نمی باشد"); return false; }
else if (InvoicIssueDate.ToString().Trim().ToMiladiinFront() > DateTime.Now)
{ ShowDangerAlert("تاریخ صدور نمی تواند از امروز جلوتر باشد"); return false; }
}
if (invoice.PatternID.HasValue)
if (invoice.PatternID <= 0 || !Patterns.Any(w => w.ID == invoice.PatternID.Value))
{ ShowDangerAlert("شناسه الگو صحیح نمی باشد"); return false; }
if (invoice.CustomerID == null || invoice.CustomerID <= 0 || !Cus.Any(w => w.ID == invoice.CustomerID))
{ ShowDangerAlert("مشتری صحیح نمی باشد"); return false; }
return true;
}
}