CreateReport
This commit is contained in:
@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Shared.DTOs;
|
||||
using Shared.DTOs.Serch;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Back.Controllers
|
||||
{
|
||||
@@ -441,11 +442,30 @@ namespace Back.Controllers
|
||||
return Ok(await _servTaxPayer.GetPatterns());
|
||||
}
|
||||
[HttpGet("GetReport/{InvoiceID}")]
|
||||
public IActionResult GetReport(int InvoiceID)
|
||||
public async Task<ActionResult<string>> GetReport(int InvoiceID)
|
||||
{
|
||||
var reportPath = $"Reports\\invoice.mrt";
|
||||
var bytes = System.IO.File.ReadAllBytes(reportPath);
|
||||
return new FileContentResult(bytes, "application/xml");
|
||||
string output = "";
|
||||
//-----GetUserAndCompany
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
|
||||
var CompanyID= user?.RolUsers.First().CompanyID;
|
||||
|
||||
if (await _servInvoice.ExistInvoiceByInvoiceID(CompanyID.Value, InvoiceID))
|
||||
return NotFound();
|
||||
|
||||
// Start the child process.
|
||||
Process p = new Process();
|
||||
// Redirect the output stream of the child process.
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.StartInfo.FileName = "C:\\CreateReport\\CreateReport.exe";
|
||||
p.StartInfo.Arguments = $"{CompanyID} {InvoiceID}";
|
||||
p.Start();
|
||||
output = p.StandardOutput.ReadToEnd();
|
||||
p.WaitForExit();
|
||||
return Ok(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
@using Front.Services
|
||||
@using Shared.DTOs
|
||||
@using Shared
|
||||
|
||||
@inject IJSRuntime JS
|
||||
|
||||
@inject HttpClientController hc;
|
||||
@layout PanelLayout
|
||||
@@ -51,7 +51,7 @@
|
||||
<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;
|
||||
@@ -84,13 +84,13 @@
|
||||
</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>
|
||||
}
|
||||
@@ -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">
|
||||
@@ -331,9 +331,9 @@
|
||||
<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>
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -476,10 +476,18 @@
|
||||
}
|
||||
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()
|
||||
@@ -492,7 +500,7 @@
|
||||
|
||||
}
|
||||
|
||||
else if(rsp.StatusCode==System.Net.HttpStatusCode.BadRequest)
|
||||
else if (rsp.StatusCode == System.Net.HttpStatusCode.BadRequest)
|
||||
{
|
||||
ShowDangerAlert("صورتحساب مرجع یافت نشد");
|
||||
}
|
||||
@@ -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>
|
||||
}
|
Reference in New Issue
Block a user