tiskanje in posiljanje po mailo
This commit is contained in:
@@ -61,6 +61,29 @@
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="card pt-2" style="width: 595pt; margin-bottom:10px;">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<select id="selTranslationLangue" asp-items="Html.GetEnumSelectList<PrintModel.PrintTranslationLanguage>()" class="form-control form-control-sm" style="width: 200px;">
|
||||
</select>
|
||||
<button id="btnTranslate" type="button" class="btn btn-sm btn-success ml-2" data-style="zoom-out" onclick="setLanguage();return false;">Prevedi</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6 text-right">
|
||||
@if (Model.Invoice.State == Models.Invoice.Invoice.InvoiceState.New)
|
||||
{
|
||||
<button id="btnPrintAndConfirm" type="button" class="btn btn-sm btn-success btn-print ladda-button pull-right" data-style="zoom-out" data-confirm="true"><i class="ion ion-md-print"></i> Natisni in potrdi</button>
|
||||
}
|
||||
<button id="btnPrint" type="button" class="btn btn-sm btn-primary btn-print ladda-button pull-right" data-style="zoom-out"><i class="ion ion-md-print"></i> Natisni</button>
|
||||
|
||||
<button id="btnSend" type="button" class="btn btn-sm btn-secondary ladda-button pull-right" data-style="zoom-out"><i class="far fa-envelope"></i> Pošlji</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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">
|
||||
|
||||
@@ -253,23 +276,6 @@
|
||||
<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> 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> Natisni</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
@@ -281,6 +287,7 @@
|
||||
|
||||
<script>
|
||||
var laddaPrint = Ladda.create(document.querySelector('#btnPrint'));
|
||||
var laddaSend = Ladda.create(document.querySelector('#btnSend'));
|
||||
var laddaPrintAndConfirm = document.querySelector('#btnPrintAndConfirm') == null ? null : Ladda.create(document.querySelector('#btnPrintAndConfirm'));
|
||||
|
||||
var element = document.getElementById('print-content');
|
||||
@@ -300,43 +307,40 @@
|
||||
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
|
||||
};
|
||||
|
||||
function print(confirm) {
|
||||
laddaPrint.start();
|
||||
if (laddaPrintAndConfirm != null) {
|
||||
laddaPrintAndConfirm.start();
|
||||
}
|
||||
|
||||
|
||||
function buildPdf(callback) {
|
||||
html2pdf().set(opt).from(element).toPdf().get('pdf').then(function (pdf) {
|
||||
|
||||
var totalPages = pdf.internal.getNumberOfPages();
|
||||
for (i = 1; i <= totalPages; i++) {
|
||||
for (var 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);
|
||||
}
|
||||
callback(pdf);
|
||||
});
|
||||
}
|
||||
|
||||
function print(confirm) {
|
||||
laddaPrint.start();
|
||||
if (laddaPrintAndConfirm != null) {
|
||||
laddaPrintAndConfirm.start();
|
||||
}
|
||||
|
||||
buildPdf(function (pdf) {
|
||||
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');
|
||||
@@ -346,7 +350,6 @@
|
||||
if (confirm) {
|
||||
confirmInvoice();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -358,6 +361,85 @@
|
||||
print($(this).attr("data-confirm") === 'true');
|
||||
});
|
||||
|
||||
$('#btnSend').click(function () {
|
||||
send();
|
||||
});
|
||||
|
||||
function send() {
|
||||
var partnerEmail = '@Html.Raw(Model.Invoice.Partner?.Email ?? "")';
|
||||
var partnerTitle = '@Html.Raw(Model.Invoice.Partner?.Title ?? "")';
|
||||
var emailInput = document.createElement('input');
|
||||
emailInput.type = 'email';
|
||||
emailInput.value = partnerEmail;
|
||||
|
||||
if (!partnerEmail || !emailInput.checkValidity()) {
|
||||
Swal.fire('Napaka', `Partner nima veljavnega e-poštnega naslova (${partnerEmail}).`, 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
Swal.fire({
|
||||
title: 'Pošlji dokument',
|
||||
html: 'Dokument bo poslan na:<br>' + partnerTitle + ' (' + partnerEmail + ')',
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
showDenyButton: true,
|
||||
confirmButtonText: 'Pošlji s prilogo',
|
||||
denyButtonText: 'Pošlji',
|
||||
cancelButtonText: 'Prekliči',
|
||||
denyButtonColor: '#007bff'
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
laddaSend.start();
|
||||
buildPdf(function (pdf) {
|
||||
var formData = new FormData();
|
||||
formData.append('pdfFile', pdf.output('blob'), '@(Model.Invoice.InvoiceNumberFull.Replace("-", "_"))' + '.pdf');
|
||||
formData.append('idInvoice', @Model.Invoice.IdInvoice);
|
||||
formData.append('withAttachment', 'true');
|
||||
sendDocument(formData);
|
||||
});
|
||||
} else if (result.isDenied) {
|
||||
laddaSend.start();
|
||||
buildPdf(function (pdf) {
|
||||
var formData = new FormData();
|
||||
formData.append('pdfFile', pdf.output('blob'), '@(Model.Invoice.InvoiceNumberFull.Replace("-", "_"))' + '.pdf');
|
||||
formData.append('idInvoice', @Model.Invoice.IdInvoice);
|
||||
formData.append('withAttachment', 'false');
|
||||
sendDocument(formData);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function sendDocument(formData) {
|
||||
$.blockUI();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader('XSRF-TOKEN',
|
||||
$('input:hidden[name="__RequestVerificationToken"]').val());
|
||||
},
|
||||
url: 'Print/?handler=SendDocument',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function (data) {
|
||||
laddaSend.stop();
|
||||
if (data.successful) {
|
||||
Swal.fire('Dokument poslan', '', 'success');
|
||||
} else {
|
||||
Swal.fire('Napaka pri pošiljanju dokumenta', data.error, 'error');
|
||||
}
|
||||
$.unblockUI();
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
laddaSend.stop();
|
||||
console.log(xhr);
|
||||
alert(xhr.responseText);
|
||||
$.unblockUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function confirmInvoice() {
|
||||
$.blockUI();
|
||||
$.ajax({
|
||||
@@ -378,7 +460,7 @@
|
||||
data.error,
|
||||
'error');
|
||||
}
|
||||
$.unblockUI();
|
||||
$.unblockUI();
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
console.log(xhr);
|
||||
|
||||
Reference in New Issue
Block a user