Files
everything2/EveryThing/Pages/Invoices/Print.cshtml
David Štaleker 03b92525d7 Prvi commit
2023-05-12 09:00:07 +02:00

386 lines
17 KiB
Plaintext

@page
@using System.Web
@using EveryThing.Models.Invoice
@using Org.BouncyCastle.Asn1
@model EveryThing.Pages.Invoices.PrintModel
@{
ViewData["Title"] = "Izpis";
Layout = "~/Pages/Layouts/_Layout.cshtml";
}
<style type="text/css">
table {
page-break-inside: auto;
color: black !important;
}
tr {
page-break-inside: avoid;
page-break-after: auto
}
thead {
display: table-header-group
}
tfoot {
display: table-footer-group
}
body {
color: black !important;
}
</style>
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
<span>
<span class="text-muted font-weight-light">
@switch ((int)Model.Invoice.Type)
{
case 1:
<i>Naročila dobaviteljem</i>
break;
case 0:
<i>Računi</i>
break;
case 2:
<i>Dobavnice</i>
break;
case 3:
<i>Naročila kupcev</i>
break;
default:
<i>Fakture</i>
break;
}
/</span> Izpis
</span>
</h4>
<div class="card pt-2" style="width: 595pt">
<div id="print-content" class="card-body pb-4 pl-4 pt-0" style="padding-right: 2rem !important">
<div class="row">
<div class="col-6 h-100 my-auto">
@*<img src="~/img/logos/trans-fer.png"/>*@
<img src="~/img/logos/@Html.DisplayFor(modelItem => Model.Invoice.Company.LogoFileName)"/>
</div>
<div class="col-6">
<address class="mb-0">
<strong>@Html.DisplayFor(modelItem => Model.Invoice.Company.Title)</strong> <br/>
@Html.DisplayFor(modelItem => Model.Invoice.Company.Street) @Html.DisplayFor(modelItem => Model.Invoice.Company.HouseNumber) <br/>
@Html.DisplayFor(modelItem => Model.Invoice.Company.PostNumber) @Html.DisplayFor(modelItem => Model.Invoice.Company.Post) <br/>
<div style="font-size: 0.7rem">
<label>@Model.Translation.Email</label> @Html.DisplayFor(modelItem => Model.Invoice.Company.Email),<label>@Model.Translation.Telephone</label> @Html.DisplayFor(modelItem => Model.Invoice.Company.Phone) <br />
<label>@Model.Translation.IdTax</label> @Html.DisplayFor(modelItem => Model.Invoice.Company.TaxNumber), Matična številka: @Html.DisplayFor(modelItem => Model.Invoice.Company.RegistrationNumber)<br />
<label>@Model.Translation.Iban</label> @Html.DisplayFor(modelItem => Model.Invoice.Company.Iban) <label>@Model.Translation.SwiftBic</label> @Html.DisplayFor(modelItem => Model.Invoice.Company.SwiftBic)
</div>
</address>
</div>
</div>
<hr/>
<address class="mb-2">
<strong>@Html.DisplayFor(modelItem => Model.Invoice.Partner.Title)</strong> <br/>
@Html.DisplayFor(modelItem => Model.Invoice.Partner.Street) @Html.DisplayFor(modelItem => Model.Invoice.Partner.HouseNumber) <br/>
@Html.DisplayFor(modelItem => Model.Invoice.Partner.PostNumber) @Html.DisplayFor(modelItem => Model.Invoice.Partner.Post) <br/>
@Html.DisplayFor(modelItem => Model.Invoice.Partner.Country.TranslationSlovenian) <br/>
</address>
<h6 class="text-big font-weight-bold mb-3">
<label>@Model.Translation.InvoiceType</label> <label>@Model.Translation.Number</label>: @Html.DisplayFor(modelItem => Model.Invoice.InvoiceYear)-@Html.DisplayFor(modelItem => Model.Invoice.InvoiceNumber)
</h6>
<div class="mb-3" style="margin-top: 0 !important; margin-bottom: 0 !important;">
<label style="margin-top: 0 !important; margin-bottom: 0 !important;">@Model.Translation.Date</label>: <strong class="font-weight-semibold">@Html.DisplayFor(modelItem => Model.Invoice.Date)</strong>
</div>
@if ((Model.Invoice.Type == Invoice.InvoiceType.DeliveryNote
|| Model.Invoice.Type == Invoice.InvoiceType.BuyersOrder)
&& !string.IsNullOrEmpty(Model.Invoice.BuyersOrderNumber))
{
<div class="mb-3" style="margin-top: 0 !important; margin-bottom: 0 !important;">
<label style="margin-top: 0 !important; margin-bottom: 0 !important;">@Model.Translation.OrderNumber</label>:&nbsp;
<strong class="font-weight-semibold">@Html.DisplayFor(modelItem => Model.Invoice.BuyersOrderNumber)</strong>
</div>
}
@if (!string.IsNullOrEmpty(Model.ProjectNumber))
{
<div class="mb-3" style="margin-top: 0 !important; margin-bottom: 0 !important;">
<label style="margin-top: 0 !important; margin-bottom: 0 !important;">@Model.Translation.Project</label>:&nbsp;
<strong class="font-weight-semibold">@Html.DisplayFor(modelItem => Model.ProjectNumber)</strong>
</div>
}
<div class="mb-3">
@switch (Model.Invoice.Type)
{
case Models.Invoice.Invoice.InvoiceType.Order:
case Models.Invoice.Invoice.InvoiceType.BuyersOrder:
<label>@Model.Translation.DeliveryTime</label>
break;
default:
<label>@Model.Translation.DateOfDispatch</label>
break;
}
<strong class="font-weight-semibold">@Html.DisplayFor(modelItem => Model.Invoice.DateOfDispatch)</strong>
</div>
<div class="mb-2" style="font-size: 0.75rem">
@Html.Raw(HttpUtility.HtmlDecode(Model.Invoice.PreText))
</div>
<div class="table-responsive mb-4">
<table class="table m-0">
<thead style="font-size: 0.75rem">
<tr>
<th>#</th>
<th class="py-1">
@Model.Translation.Article
</th>
<th class="py-1 text-right">
@Model.Translation.Quantity
</th>
@if (Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.Invoice
|| Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.BuyersOrder)
{
<th class="py-1 text-right">
@Model.Translation.Price
</th>
<th class="py-1 text-right">
@Model.Translation.Amount
</th>
}
else if (Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.Order)
{
<th class="py-1">
@Model.Translation.Dimensions
</th>
}
</tr>
</thead>
<tbody style="font-size: 0.75rem">
@foreach (var item in Model.InvoiceItems)
{
<tr>
<td>
@(Model.InvoiceItems.IndexOf(item) + 1)
</td>
<td>
@Html.DisplayFor(x => item.Item.Title)
@if (Model.Invoice.Type != Models.Invoice.Invoice.InvoiceType.Order && !string.IsNullOrEmpty(item.ItemDescription))
{
<br/>
<small>
@Html.DisplayFor(x => item.ItemDescription)
</small>
}
@if (Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.Invoice)
{
<br/>
<small>
@Model.Translation.DeliveryNote
<b>@Html.DisplayFor(x => item.InvoiceItemJoin.Invoice.InvoiceNumberFormatted)</b>
</small>
}
</td>
<td class="text-right">@Html.DisplayFor(x => item.Quantity)</td>
@if (Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.Invoice
|| Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.BuyersOrder)
{
<td class="text-right">@Html.DisplayFor(x => item.Price)</td>
<td class="text-right">@Html.DisplayFor(x => item.TotalValue)</td>
}
else if (Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.Order)
{
<td>@Html.DisplayFor(x => item.ItemDescription)</td>
}
</tr>
}
</tbody>
</table>
</div>
@if (Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.Invoice
|| Model.Invoice.Type == Models.Invoice.Invoice.InvoiceType.BuyersOrder)
{
<div class="mb-4">
@{
string total = Model.InvoiceItems.Sum(x => x.TotalValue).ToString("0.00");
}
<label>@Model.Translation.Total</label> <b>@total €</b>
</div>
}
<div style="font-size: 0.75rem">
@Html.Raw(HttpUtility.HtmlDecode(Model.Invoice.PostText))
</div>
@if (Model.Invoice.Type == Invoice.InvoiceType.DeliveryNote)
{
<div class="row pt-3" style="font-size: 0.85rem">
<div class="col-4">
<label>@Model.Translation.Issued</label> <br />__________________________
</div>
<div class="col-4"></div>
<div class="col-4">
<label>@Model.Translation.Received</label> <br />__________________________
</div>
</div>
}
else
{
<div class="row pt-3" style="font-size: 0.85rem">
<div class="col-4"></div>
<div class="col-4"></div>
<div class="col-4 text-center">
<label>@Model.Translation.Director</label> <br /> @Html.DisplayFor(modelItem => Model.Invoice.Company.Ceo)
</div>
</div>
}
<div style="display: none" id="footer1">@Html.DisplayFor(modelItem => Model.Invoice.Company.Title), @Html.DisplayFor(modelItem => Model.Invoice.Company.Street) @Html.DisplayFor(modelItem => Model.Invoice.Company.HouseNumber), @Html.DisplayFor(modelItem => Model.Invoice.Company.PostNumber) @Html.DisplayFor(modelItem => Model.Invoice.Company.Post), @Html.DisplayFor(modelItem => Model.Invoice.Company.Country.TranslationSlovenian); ID za DDV: @Html.DisplayFor(modelItem => Model.Invoice.Company.TaxNumber), E-pošta: @Html.DisplayFor(modelItem => Model.Invoice.Company.Email)</div>
<div style="display: none" id="footer2">Tel.: @Html.DisplayFor(modelItem => Model.Invoice.Company.Phone), @Html.DisplayFor(modelItem => Model.Invoice.Company.Bank); IBAN: @Html.DisplayFor(modelItem => Model.Invoice.Company.Iban); SWIFT/BIC: @Html.DisplayFor(modelItem => Model.Invoice.Company.SwiftBic)</div>
</div>
<div class="card-footer">
<div class="row">
<div class="col-6">
<select id="selTranslationLangue" asp-items="Html.GetEnumSelectList<PrintModel.PrintTranslationLanguage>()" class="form-control" style="width: 200px;">
</select>
<button id="btnTranslate" type="button" class="btn btn-success pull-right" data-style="zoom-out" onclick="setLanguage();return false;">Prevedi</button>
</div>
<div class="col-6 text-right">
@if (Model.Invoice.State == Models.Invoice.Invoice.InvoiceState.New)
{
<button id="btnPrintAndConfirm" type="button" class="btn btn-success btn-print ladda-button pull-right" data-style="zoom-out" data-confirm="true"><i class="ion ion-md-print"></i>&nbsp; Natisni in potrdi</button>
}
<button id="btnPrint" type="button" class="btn btn-primary btn-print ladda-button pull-right" data-style="zoom-out"><i class="ion ion-md-print"></i>&nbsp; Natisni</button>
</div>
</div>
</div>
</div>
@Html.AntiForgeryToken()
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<!-- PDF -->
<script src="~/vendor/libs/html2pdf.js/dist/html2pdf.bundle.min.js" asp-append-version="true"></script>
<script>
var laddaPrint = Ladda.create(document.querySelector('#btnPrint'));
var laddaPrintAndConfirm = document.querySelector('#btnPrintAndConfirm') == null ? null : Ladda.create(document.querySelector('#btnPrintAndConfirm'));
var element = document.getElementById('print-content');
var opt = {
//pagebreak: { mode: 'avoid-all' },
filename: 'nalog.pdf',
image: { type: 'png' },
enableLinks: false,
margin: [5, 0, 13, 0],
html2canvas: {
scale: 1.2,
scrollX: 0,
scrollY: 0,
dpi: 300,
letterRendering: true
},
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
};
function print(confirm) {
laddaPrint.start();
if (laddaPrintAndConfirm != null) {
laddaPrintAndConfirm.start();
}
html2pdf().set(opt).from(element).toPdf().get('pdf').then(function (pdf) {
var totalPages = pdf.internal.getNumberOfPages();
for (i = 1; i <= totalPages; i++) {
pdf.setPage(i);
pdf.setFontSize(8);
pdf.setTextColor(0);
var fontSize = pdf.internal.getFontSize();
var pageWidth = pdf.internal.pageSize.width;
var txt = $('#footer1').text();
var txtWidth = pdf.getStringUnitWidth(txt) * fontSize / pdf.internal.scaleFactor;
var x = (pageWidth - txtWidth) / 2;
pdf.text(x, pdf.internal.pageSize.getHeight() - 8, txt);
txt = $('#footer2').text();
txtWidth = pdf.getStringUnitWidth(txt) * fontSize / pdf.internal.scaleFactor;
x = (pageWidth - txtWidth) / 2;
pdf.text(x, pdf.internal.pageSize.getHeight() - 5, txt);
//pdf.addImage("YOUR_IMAGE", 'JPEG', pdf.internal.pageSize.getWidth() - 1.1, pdf.internal.pageSize.getHeight() - 0.25, 1, 0.2);
}
laddaPrint.stop();
if (laddaPrintAndConfirm != null) {
laddaPrintAndConfirm.stop();
}
//window.open(pdf.output('bloburl'), '_blank');
let link = document.createElement('a');
link.target = '_blank';
link.href = pdf.output('bloburl');
link.download = '@Model.Invoice.InvoiceNumberFull.Replace("-", "_")';
link.click();
link.remove();
if (confirm) {
confirmInvoice();
}
});
}
$(document).ready(function () {
//print();
});
$(".btn-print").click(function () {
print($(this).attr("data-confirm") === 'true');
});
function confirmInvoice() {
$.blockUI();
$.ajax({
type: "POST",
beforeSend: function(xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: "Print/?handler=ConfirmInvoice",
data: {
idInvoice : @Model.Invoice.IdInvoice
},
success: function(data) {
if (data.successful){
location.reload();
} else {
Swal.fire('Napaka pri potrjevanju dokumenta',
data.error,
'error');
}
$.unblockUI();
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
$.unblockUI();
}
});
}
function setLanguage() {
const language = $('#selTranslationLangue').val();
const idInvoice = @Model.Invoice.IdInvoice;
window.location.replace('/Invoices/Print?id=' + idInvoice + '&printTranslationLanguage=' + language);
}
</script>
}