CreateReport
This commit is contained in:
@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http.HttpResults;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Shared.DTOs;
|
using Shared.DTOs;
|
||||||
using Shared.DTOs.Serch;
|
using Shared.DTOs.Serch;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Back.Controllers
|
namespace Back.Controllers
|
||||||
{
|
{
|
||||||
@@ -441,11 +442,30 @@ namespace Back.Controllers
|
|||||||
return Ok(await _servTaxPayer.GetPatterns());
|
return Ok(await _servTaxPayer.GetPatterns());
|
||||||
}
|
}
|
||||||
[HttpGet("GetReport/{InvoiceID}")]
|
[HttpGet("GetReport/{InvoiceID}")]
|
||||||
public IActionResult GetReport(int InvoiceID)
|
public async Task<ActionResult<string>> GetReport(int InvoiceID)
|
||||||
{
|
{
|
||||||
var reportPath = $"Reports\\invoice.mrt";
|
string output = "";
|
||||||
var bytes = System.IO.File.ReadAllBytes(reportPath);
|
//-----GetUserAndCompany
|
||||||
return new FileContentResult(bytes, "application/xml");
|
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 Front.Services
|
||||||
@using Shared.DTOs
|
@using Shared.DTOs
|
||||||
@using Shared
|
@using Shared
|
||||||
|
@inject IJSRuntime JS
|
||||||
|
|
||||||
@inject HttpClientController hc;
|
@inject HttpClientController hc;
|
||||||
@layout PanelLayout
|
@layout PanelLayout
|
||||||
@@ -331,9 +331,9 @@
|
|||||||
<Button class="mt-3" Color="ButtonColor.Danger" @onclick="ShowConfirmationDeleteAsync" Type="ButtonType.Button">
|
<Button class="mt-3" Color="ButtonColor.Danger" @onclick="ShowConfirmationDeleteAsync" Type="ButtonType.Button">
|
||||||
حذف
|
حذف
|
||||||
</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>
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -476,10 +476,18 @@
|
|||||||
}
|
}
|
||||||
private async Task ShowReport()
|
private async Task ShowReport()
|
||||||
{
|
{
|
||||||
if (InvoiceID.HasValue)
|
var rsp = await hc.Get($"Invoice/GetReport/{InvoiceID}");
|
||||||
|
if (rsp.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
fv.invoice = invoice;
|
var str = await rsp.Content.ReadFromJsonAsync<string>();
|
||||||
hc._nav.NavigateTo($"InvoiceReport/{InvoiceID}");
|
if (string.IsNullOrEmpty(str))
|
||||||
|
ShowDangerAlert("خطایی در ساخت فاکتور");
|
||||||
|
else
|
||||||
|
await DownloadFileFromStream(str, $"{InvoiceID}.pdf");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowDangerAlert("خطایی در ساخت فاکتور");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async Task LoadData()
|
private async Task LoadData()
|
||||||
@@ -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