CreateReport

This commit is contained in:
mmrbnjd
2024-07-01 15:39:40 +03:30
parent 3702145d02
commit 06496f8442
2 changed files with 120 additions and 60 deletions

View File

@@ -1,7 +1,7 @@
@using Front.Services
@using Shared.DTOs
@using Shared
@inject IJSRuntime JS
@inject HttpClientController hc;
@layout PanelLayout
@@ -22,20 +22,20 @@
<hr class="hr" />
}
<form>
@if (InvoiceID.HasValue)
{
@if (InvoiceID.HasValue)
{
<h4 class="fw-bold py-3 mb-4">
<span class="text-muted fw-light">سرویس ها / صورتحساب /</span> @invoice?.Title
</h4>
}
else
{
</h4>
}
else
{
<h4 class="fw-bold py-3 mb-4">
<span class="text-muted fw-light">سرویس ها / صورتحساب /</span> جدید
</h4>
}
}
@* alert *@
<div class="row">
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
@@ -47,11 +47,11 @@
@if (InvoiceID == 0 || InvoiceID == null ? false : true && !invoice.IsDeleted)
{
<div class="row g-3">
<div class="multi-button">
@switch (invoice.invoiceType)
{
case(InvoiceType.Bidding):
case (InvoiceType.Bidding):
<Button class="button" style="color:white;" @onclick="() => ChangeStatus((int)InvoiceType.Sale)" id="cut"><span>فاکتور</span></Button>
<Button class="button" style="color:white;" @onclick="() => ChangeStatus((int)InvoiceType.Cancellation)" id="sred1"><span>ابطال</span></Button>
break;
@@ -65,32 +65,32 @@
case (InvoiceType.BackFrmSale):
<Button class="button" style="color:white;" @onclick="() => ChangeStatus((int)InvoiceType.Cancellation)" id="sred"><span>ابطال</span></Button>
@* <Button class="button" style="color:white;" @onclick="() => ChangeStatus((int)InvoiceType.CANCEL)" id="sred1"><span>لغو</span></Button> *@
@* <Button class="button" style="color:white;" @onclick="() => ChangeStatus((int)InvoiceType.CANCEL)" id="sred1"><span>لغو</span></Button> *@
break;
case (InvoiceType.Repair):
<Button class="button" style="color:white;" @onclick="() => ChangeStatus((int)InvoiceType.Cancellation)" id="sred"><span>ابطال</span></Button>
@* <Button class="button" style="color:white;" @onclick="() => ChangeStatus((int)InvoiceType.CANCEL)" id="sred1"><span>لغو</span></Button> *@
<Button class="button" style="color:white;" @onclick="() => ChangeStatus((int)InvoiceType.Cancellation)" id="sred"><span>ابطال</span></Button>
@* <Button class="button" style="color:white;" @onclick="() => ChangeStatus((int)InvoiceType.CANCEL)" id="sred1"><span>لغو</span></Button> *@
<Button class="button" style="color:white;" id="copy" @onclick="() => ChangeStatus((int)InvoiceType.BackFrmSale)"><span>برگشت فروش</span></Button>
break;
@* case (InvoiceType.Cancellation):
<Button class="button" style="color:white;" id="sred1" @onclick="() => ChangeStatus((int)InvoiceType.CANCEL)"><span>لغو</span></Button>
break; *@
@* case (InvoiceType.Cancellation):
<Button class="button" style="color:white;" id="sred1" @onclick="() => ChangeStatus((int)InvoiceType.CANCEL)"><span>لغو</span></Button>
break; *@
}
</div>
</div>
<br />
@if (invoice.InvoiceSendTaxs.Count>0)
@if (invoice.InvoiceSendTaxs.Count > 0)
{
if (invoice.InvoiceSendTaxs.Any(a=>a.InvoiceType==invoice.invoiceType
&& a.SentStatus==SentStatus.Send))
if (invoice.InvoiceSendTaxs.Any(a => a.InvoiceType == invoice.invoiceType
&& a.SentStatus == SentStatus.Send))
{
SendInvoice = false;
<h6 >این صورتحساب با این وضعیت به سامانه مودیان ارسال شده ،برای اطلاع از وضعیت لطفا تعیین وضعیت کنید</h6>
<h6>این صورتحساب با این وضعیت به سامانه مودیان ارسال شده ،برای اطلاع از وضعیت لطفا تعیین وضعیت کنید</h6>
}
else if (invoice.InvoiceSendTaxs.Any(a => a.InvoiceType == invoice.invoiceType
&& a.SentStatus == SentStatus.Successful))
@@ -110,7 +110,7 @@
&& (a.SentStatus == SentStatus.pending || a.SentStatus == SentStatus.IN_PROGRESS)))
{
SendInvoice = false;
<h6 >
<h6>
این صورتحساب با این وضعیت به سامانه مودیان ارسال و در حال بررسی می باشد
</h6>
}
@@ -118,7 +118,7 @@
&& (a.SentStatus == SentStatus.NOT_FOUND || a.SentStatus == SentStatus.Unknown)))
{
SendInvoice = false;
<h6 >
<h6>
این صورتحساب با این وضعیت به سامانه مودیان ارسال شده ولی وضعیت آن مشخص نیست
</h6>
}
@@ -129,7 +129,7 @@
}
}
else SendInvoice = true;
<hr class="hr" />
}
<div class="row g-3">
@@ -234,7 +234,7 @@
<InputText style=" text-align: center;" @bind-Value="invoice.InvoiceDate" type="text" class="form-control" id="inputInvoiceDate" placeholder="تاریخ" />
</div>
</div>
@if (InvoiceID == 0 || InvoiceID == null ? false : true )
@if (InvoiceID == 0 || InvoiceID == null ? false : true)
{
<br /> <hr class="hr" />
<div class="row g-3">
@@ -256,7 +256,7 @@
+
</Button>
}
</div>
</div>
@@ -284,8 +284,8 @@
</div>
}
<br />
<br />
<hr class="hr" />
<div class="row g-3">
<div class="form-group col-md-4">
@@ -311,8 +311,8 @@
<InputText style=" text-align: center;" @bind-Value="invoice.Udate" class="form-control" id="inputUdate" readonly />
</div>
<div class="form-group col-md-4">
<br />
@if (!invoice.IsDeleted)
@@ -331,13 +331,13 @@
<Button class="mt-3" Color="ButtonColor.Danger" @onclick="ShowConfirmationDeleteAsync" Type="ButtonType.Button">
حذف
</Button>
@* <Button class="mt-3" Color="ButtonColor.Primary" @onclick="ShowReport" Type="ButtonType.Button">
<Button class="mt-3" Color="ButtonColor.Primary" @onclick="ShowReport" Type="ButtonType.Button">
چاپ
</Button> *@
</Button>
}
}
</div>
@if (invoice.invoiceType != InvoiceType.Bidding && SendInvoice)
{
@@ -348,19 +348,19 @@
</Button>
</div>
}
</div>
<br />
<div class="row g-3">
@if (invoice.BillReference.HasValue)
{
<div class="row g-3">
@{
string Prefence = "InvoiceDetails/" + invoice.BillReference.Value.ToString();
}
<Button Color="ButtonColor.Link"><NavLink href="@Prefence">صورتحساب مرجع</NavLink></Button>
</div>
}
@if (invoice.BillReference.HasValue)
{
<div class="row g-3">
@{
string Prefence = "InvoiceDetails/" + invoice.BillReference.Value.ToString();
}
<Button Color="ButtonColor.Link"><NavLink href="@Prefence">صورتحساب مرجع</NavLink></Button>
</div>
}
</div>
</form>
@@ -450,7 +450,7 @@
if (rsp.IsSuccessStatusCode)
{
var resinvoice = await rsp.Content.ReadFromJsonAsync<InvoiceDTO>();
if (resinvoice!=null)
if (resinvoice != null)
{
invoice = resinvoice;
InvoiceID = resinvoice.ID;
@@ -470,16 +470,24 @@
{
if (InvoiceID.HasValue)
{
hc._nav.NavigateTo($"TaxPayerInvoiceItem/{InvoiceID}");
}
}
private async Task ShowReport()
{
if (InvoiceID.HasValue)
var rsp = await hc.Get($"Invoice/GetReport/{InvoiceID}");
if (rsp.IsSuccessStatusCode)
{
fv.invoice = invoice;
hc._nav.NavigateTo($"InvoiceReport/{InvoiceID}");
var str = await rsp.Content.ReadFromJsonAsync<string>();
if (string.IsNullOrEmpty(str))
ShowDangerAlert("خطایی در ساخت فاکتور");
else
await DownloadFileFromStream(str, $"{InvoiceID}.pdf");
}
else
{
ShowDangerAlert("خطایی در ساخت فاکتور");
}
}
private async Task LoadData()
@@ -488,13 +496,13 @@
var rsp = await hc.Get($"Invoice/Get/{InvoiceID}/{true}");
if (rsp.IsSuccessStatusCode)
{
invoice = await rsp.Content.ReadFromJsonAsync<InvoiceDTO>();
invoice = await rsp.Content.ReadFromJsonAsync<InvoiceDTO>();
}
else if(rsp.StatusCode==System.Net.HttpStatusCode.BadRequest)
else if (rsp.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
ShowDangerAlert("صورتحساب مرجع یافت نشد");
ShowDangerAlert("صورتحساب مرجع یافت نشد");
}
else
{
@@ -739,4 +747,36 @@
}
}
//for download
private Stream GetFileStream(byte[] bytes)
{
var fileStream = new MemoryStream(bytes);
return fileStream;
}
private async Task DownloadFileFromStream(string Base64, string FileName)
{
byte[] bytes = System.Convert.FromBase64String(Base64);
var fileStream = GetFileStream(bytes);
// var fileName = "log.bin";
using var streamRef = new DotNetStreamReference(stream: fileStream);
await JS.InvokeVoidAsync("downloadFileFromStream", FileName, streamRef);
}
}
<script>
window.downloadFileFromStream = async (fileName, contentStreamReference) => {
const arrayBuffer = await contentStreamReference.arrayBuffer();
const blob = new Blob([arrayBuffer]);
const url = URL.createObjectURL(blob);
const anchorElement = document.createElement('a');
anchorElement.href = url;
anchorElement.download = fileName ?? '';
anchorElement.click();
anchorElement.remove();
URL.revokeObjectURL(url);
}
</script>
}