$("head").append(''); $("head").append(''); function IsEmptyOrUndefined(_this) { var result = false; for (var i = 0; i < 4; i++) { if (typeof $(_this).find("td").eq(i).text() !== "undefined" && $(_this).find("td").eq(i).text().trim() !== "") result = true; } return result; } (function ($) { $.fn.extend({ ContentPagination: function (options) { var defaults = { height: 400 }; var options = $.extend(defaults, options); //Creating a reference to the object var objContent = $(this); // other inner variables var fullPages = new Array(); var subPages = new Array(); var height = 0; var activePage = 1; var pageCount = 1; // initialization function init = function () { objContent.children().each(function (i) { if (height + this.clientHeight > options.height) { fullPages.push(subPages); subPages = new Array(); height = 0; pageCount++; } height += this.clientHeight; subPages.push(this); $(this).addClass("p" + pageCount); }); if (height > 0) { fullPages.push(subPages); } // draw controls showPaginationBar(pageCount); // show first page showPageContent(1); }; // show page content function showPageContent = function (page) { objContent.children().css("display", "none"); $(".p" + page).css("display", ""); $(".number").removeClass("selected"); $("#ap" + page).addClass("current"); $("#countPage").text("tiep theo trang truoc - trang " + page + "/" + pageCount); activePage = page; //th1.chi co mot trang if (pageCount == 1) { $("#countPage").text(""); $("#countPage").css("display", "none"); $(".nextpage").css("display", "line"); $("#footer").css("display", ""); $(".hide").css("display", ""); $('.totalInWord').css("display", ""); } //th2.truong hop nhieu trang if (pageCount > 1) { //trang thu 1 if (page == 1) { var t = fullPages; var tong = 0; $("#footer").css("display", "none"); $("#countPage").text(""); $("#countPage").text("trang " + page + "/" + pageCount); $(".nextpage").css("display", "none"); $('.totalInWord').css("display", "none"); $(".hide").css("display", "none","important"); } //trang tiep theo else if (page > 1 && page < pageCount) { $("#footer").css("display", "none"); $(".nextpage").css("display", "none"); $('.label-sign').css("display", "none"); $(".bgimg").css("display", "none"); $('.totalInWord').css("display", "none"); $(".hide").css("display", "none", "important"); } //trang cuoi cung else if (page == pageCount) { $("#footer").css("display", ""); $('.label-sign').css("display", ""); $('.bgimg').css("display", ""); $(".nextpage").css("display", ""); $(".hide").css("display", ""); $('.totalInWord').css("display", ""); } } showPaginationBar(pageCount); }; // show pagination bar function (draw switching numbers) showPaginationBar = function (numPages) { $('.pagination').empty(); var pagins = ''; pagins += '<<'; pagins += "<"; var limit = 10; var start = 1; var end = numPages; if (numPages > limit) { var middle = Math.ceil(limit / 4); var below = (activePage - middle); var above = (activePage + middle); if (below < 4) { above = limit; below = 1; } else if (above > (numPages - 4)) { above = numPages; below = (numPages - limit); } start = below; end = above; } if (start > 3) pagins += "..."; for (var i = start; i <= end; i++) { if (i == activePage || (activePage <= 0 && i == 0)) { pagins += '' + i + ''; } else pagins += '' + i + ''; } if (end < (pageCount - 3)) pagins += "..."; pagins += ">"; pagins += '>>' $('.pagination').append(pagins); }; // perform initialization init(); // and binding 2 events - on clicking to Prev $('.pagination #prev').click(function () { if (activePage > 1) showPageContent(activePage - 1); }); // and Next $('.pagination #next').click(function () { if (activePage < pageCount) showPageContent(activePage + 1); }); // print function print4Convert = function () { overrideStyleRound(); var printContent = ""; $(".pagination").css("display", "none"); for (var i = 1; i <= pageCount; i++) { showPageContent(i); tempContent = $("#container").html(); printContent += tempContent + "
"; } $("#ds").html(printContent); var printElement = document.getElementById("ds"); $(printElement).printArea({ mode: "iframe", popWd: 900, popHt: 600, popClose: false }); }; }, ProductNumberPagination: function (options, data) { var defaults = { number: 10 }; var options = $.extend(defaults, options); //Creating a reference to the object var objContent = $(this); // other inner variables var fullPages = new Array(); var subPages = new Array(); var k = 0; var currentPage = 0; var pageCount = 1; if (data && data.IsAutoRow) { //var headerHeight = $(".VATTEMP .content #header").height(); //var headerTitleHeight = $(".VATTEMP .content #main-content .header-title").height(); // mot so mau moi co element dong nay //var compHeight = $(".VATTEMP .content #main-content .comp").height(); //var cusHeight = $(".VATTEMP .content #main-content .cus").height(); //var taikhoan = $(".VATTEMP .content #main-content .taikhoan").height(); // mot so mau moi co element dong nay //var topHeight = headerHeight + compHeight + cusHeight + headerTitleHeight + taikhoan; var topHeight = $('.invtable').offset().top - $('.VATTEMP').offset().top; var docHeight = 1170; var tempHeight = topHeight; var emptyRow = null; //var bottomHeight = $(".VATTEMP .invtable .nextpage").height() + $(".VATTEMP .sds").height() + $(".VATTEMP .content #footer .fl-r").height() + $(".VATTEMP .content .tracuu").height() + $(".VATTEMP .content .thongbao").height(); var bottomHeight = $('.VATTEMP').height() + $('.VATTEMP').offset().top - $('.invtable').offset().top - $('.invtable').height(); var _difference = 0; var differenceRowAppended = data.DiffRowBreaking === null ? 260 : data.DiffRowBreaking; // tang len neu muon giam so dong trong 1 trang va nguoc lai // initialization function init = function () { objContent.children().slice(0, objContent.children().length).each(function (i) { if (IsEmptyOrUndefined(this)) { tempHeight += $(this).height(); var nextRow = $(".invtable").find('tbody').find('tr').eq(i + 1).height(); if (nextRow === null) { // truong hop la trang cuoi, thi phai tinh toan cong them footer, vi footer trang cuoi moi hien thi _difference = bottomHeight; nextRow = 0; } else { _difference = differenceRowAppended; } if (docHeight >= tempHeight + _difference && docHeight <= nextRow + tempHeight + _difference) { fullPages.push(subPages); subPages = new Array(); subPages.push(this); k = 1; tempHeight = topHeight; $(this).addClass("p" + pageCount); pageCount++; } else { k++; subPages.push(this); $(this).addClass("p" + pageCount); } } else { emptyRow = $(this).clone(true); $(this).css("display", "none"); } }); if (k > 0) { fullPages.push(subPages); } var lastProdPageHeight = 0; $('.prds .data.p' + pageCount).each(function () { lastProdPageHeight += $(this).outerHeight(); }); //tinh va break footer, phan chu ky xuong, neu nhu no nam giua 2 trang var differenceBreakFooter = data.DiffFooterBreaking === null ? 0 : data.DiffFooterBreaking; // giam xuong neu muon break som hon va nguoc lai var tableHeaderHeight = $(".VATTEMP .invtable thead").height(); var tableFooterHeight = $(".VATTEMP .invtable .nextpage").height(); var isBreakFooter = false; if (topHeight + bottomHeight + lastProdPageHeight + tableFooterHeight + tableHeaderHeight - differenceBreakFooter > docHeight) { isBreakFooter = true; //$(".VATTEMP .content #footer").css({ "page-break-before": "always"}); pageCount++; if (emptyRow !== null) { $(emptyRow).css("display", ""); $(emptyRow).addClass("p" + pageCount); $('.invtable tr.p' + pageCount - 1 + ':last').after(emptyRow.wrap("").parent().html()); } else { //var lastRow = $('.invtable tr.p' + pageCount - 1 + ':last'); //$('.invtable tr.p' + pageCount - 1 + ':last').after(lastRow.outerHTML); var previousCount = pageCount - 1; var temp = $('.invtable tr.p' + previousCount + ':last'); $('.invtable tr.p' + previousCount + ':last').after(temp[0].outerHTML); $('.invtable tr.p' + previousCount + ':last').addClass("p" + pageCount); $('.invtable tr.p' + pageCount + ':last').removeClass("p" + previousCount); $('.invtable tr.p' + pageCount + ':last').find('td').each(function () { $(this).text(""); }); } } //them dong trong neu nhu cuoi trang con cho trong if (data.IsAppendEmptyRow && !isBreakFooter) { if (emptyRow === null) { emptyRow = $('.invtable tr.p' + pageCount + ':last').clone(); for (el of emptyRow[0].cells) $(el).text(""); } $(emptyRow).css("display", ""); $(emptyRow).addClass("p" + pageCount); tempHeight = 0; var differenceEmptyPage = data.DiffEmptyRowAppended === null ? 50 : data.DiffEmptyRowAppended; // tang len neu muon giam dong trong hoac nguoc lai var defaultEmptyRowHeight = 25; for (var i = 0; i < 10; i++) { if (topHeight + bottomHeight + lastProdPageHeight + tempHeight + tableFooterHeight + tableHeaderHeight + differenceEmptyPage < docHeight) { tempHeight += defaultEmptyRowHeight; $('.invtable tr.p' + pageCount + ':last').after(emptyRow.wrap("").parent().html()); } else { break; } } } if (pageCount > 1) { currentPage = 0; // draw controls showPaginationBar(pageCount); // show first page showPageContent(1); } }; } else { // initialization function init = function () { objContent.children().slice(0, objContent.children().length).each(function (i) { k++; if (k > options.number) { fullPages.push(subPages); subPages = new Array(); subPages.push(this); k = 1; pageCount++; $(this).addClass("p" + pageCount); } //k++; subPages.push(this); $(this).addClass("p" + pageCount); }); if (k > 0) { fullPages.push(subPages); } if (pageCount > 1) { currentPage = 0; // draw controls showPaginationBar(pageCount); // show first page showPageContent(1); } }; } downloadPdfAndFileAttachFromAvailableHtml = function (invId, pattern, fkey) { HoldOn.open({ message: 'Vui lòng chờ trong giây lát ...', theme: "sk-circle" }); if (data.IsAutoRow) { //set this style property to break page $("#printView").css("display", "grid"); } var printContent = ""; $(".pagination").css("display", "none"); $('.modal-footer').css("display", "none"); for (var i = 1; i <= pageCount; i++) { showPageContent(i); tempContent = document.getElementById("container").innerHTML; printContent += tempContent; if (i !== pageCount) { printContent += ""; } } //$("#ds").html(printContent); //var doc = new jsPDF(); //var elementHTML = $('#ds').html().replace(/</g, '<').replace(/>/g, '>'); $.ajax({ type: "POST", url: "/Invoice/DownloadPdfAndFileAttachFromAvailableHtml", data: { id: invId, pattern: pattern, fKey: fkey, html: b64EncodeUnicode(printContent.replace('
', "")) // remove the danh dau hoa don huy neu ton tai, se them lai tren server
},
//dataType: 'arraybuffer',
success: function (rs) {
HoldOn.close();
if (typeof rs.msg !== 'undefined' && rs.msg !== "") {
sweetAlert("Lỗi!", rs.msg, "error");
return;
}
window.location = '/Invoice/Download?fileGuid=' + rs.fileGuid
+ '&fileName=' + rs.fileName;
},
error: function () {
HoldOn.close();
}
});
if (pageCount > 1)
$(".pagination").css("display", "");
$('.modal-footer').css("display", "");
};
downloadFileFromHtml = function (invId, pattern, fkey, isImage) {
HoldOn.open({
message: 'Vui lòng chờ trong giây lát ...',
theme: "sk-circle"
});
if (data.IsAutoRow) {
//set this style property to break page
$("#printView").css("display", "grid");
}
var printContent = "";
$(".pagination").css("display", "none");
$('.modal-footer').css("display", "none");
for (var i = 1; i <= pageCount; i++) {
showPageContent(i);
tempContent = document.getElementById("container").innerHTML;
printContent += tempContent;
if (i !== pageCount) {
printContent += "";
}
}
$.ajax({
type: "POST",
url: "/Invoice/DownloadFileFromHtml",
data: {
id: invId,
pattern: pattern,
fKey: fkey,
html: b64EncodeUnicode(printContent.replace('
', "")), // remove the danh dau hoa don huy neu ton tai, se them lai tren server
isImage: isImage
},
//dataType: 'arraybuffer',
success: function (rs) {
HoldOn.close();
if (typeof rs.msg !== 'undefined' && rs.msg !== "") {
sweetAlert("Lỗi!", rs.msg, "error");
return;
}
window.location = '/Invoice/Download?fileGuid=' + rs.fileGuid
+ '&fileName=' + rs.fileName;
},
error: function () {
HoldOn.close();
}
});
if (pageCount > 1)
$(".pagination").css("display", "");
$('.modal-footer').css("display", "");
};
// print function
print4Convert = function () {
overrideStyleRound();
if (data.IsAutoRow) {
//set this style property to break page
$("#printView").css("display", "grid");
}
var printContent = "";
$(".pagination").css("display", "none");
$('.modal-footer').css("display", "none");
for (var i = 1; i <= pageCount; i++) {
showPageContent(i);
tempContent = document.getElementById("container").innerHTML;
printContent += tempContent;
if (i !== pageCount) {
printContent += "";
}
}
$("#ds").html(printContent);
setTimeout(function () {
var printElement = document.getElementById("ds");
$(printElement).printArea({
mode: "iframe",
popWd: 900,
popHt: 600,
popClose: false
});
$("#ds").html("");
if (pageCount > 1)
$(".pagination").css("display", "");
$('.modal-footer').css("display", "");
}, 300)
};
// show page content function
showPageContent = function (page) {
currentPage = 0;
objContent.children().css("display", "none");
$(".p" + page).css("display", "");
$(".number").removeClass("selected");
$("#ap" + page).addClass("current");
$("#countPage").text("tiep theo trang truoc - trang " + page + "/" + pageCount);
currentPage = parseInt(page);
//th1.chi co mot trang
if (pageCount == 1) {
$("#footer").css("display", "");
$("#countPage").text("");
$("#countPage").css("display", "none");
$('.totalInWord').css("display", "");
$(".nextpage").css("display", "");
$(".hide").css("display", "");
}
//th2.truong hop nhieu trang
if (pageCount > 1) {
//trang thu 1
if (page == 1) {
var t = fullPages;
var tong = 0;
$("#footer").css("display", "none");
$("#countPage").text("");
$("#countPage").text("trang " + page + "/" + pageCount);
$('.totalInWord').css("display", "none");
$(".nextpage").css("display", "none");
$('.label-sign').css("display", "none");
$(".bgimg").css("display", "none");
$(".hide").css("display", "none", "important");
}
//trang tiep theo
else if (page > 1 && page < pageCount) {
$("#footer").css("display", "none");
$(".nextpage").css("display", "none");
$('.label-sign').css("display", "none");
$('.totalInWord').css("display", "none");
$(".bgimg").css("display", "none");
$(".hide").css("display", "none", "important");
}
//trang cuoi cung
else if (page == pageCount) {
$("#footer").css("display", "");
$('.label-sign').css("display", "");
$('.bgimg').css("display", "");
$(".nextpage").css("display", "");
$(".hide").css("display", "");
$('.totalInWord').css("display", "");
}
}
showPaginationBar(pageCount);
};
// show pagination bar function (draw switching numbers)
showPaginationBar = function (numPages) {
$('.pagination').empty();
var pagins = '';
pagins += '<<';
pagins += "<";
pagins += '1';
var limit = 10;
var start = 2;
var end = numPages - 1;
if (numPages > limit) {
var middle = Math.ceil(limit / 4);
var below = (currentPage - middle);
var above = (currentPage + middle);
if (below < 4) {
above = limit;
below = 2;
}
else if (above > (numPages - 5)) {
above = numPages - 1;
below = (numPages - limit);
}
start = below;
end = above;
}
if (start > 3)
pagins += "...";
for (var i = start; i <= end; i++) {
if (i == currentPage || (currentPage <= 0 && i == 0)) {
pagins += '' + i + '';
}
else
pagins += '' + i + '';
}
if (end < (numPages - 4))
pagins += "...";
pagins += '' + numPages + ''
pagins += '>';
pagins += '>>';
$('.pagination').append(pagins);
};
// perform initialization
init();
// and binding 2 events - on clicking to Prev
previewPage = function () {
if (currentPage > 1) {
showPageContent(currentPage - 1);
}
}
// and Next
nextPage = function () {
if (currentPage < pageCount) {
showPageContent(currentPage + 1);
}
}
}
});
}(jQuery));
function b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
function base64ToArrayBuffer(data) {
var binaryString = window.atob(data);
var binaryLen = binaryString.length;
var bytes = new Uint8Array(binaryLen);
for (var i = 0; i < binaryLen; i++) {
var ascii = binaryString.charCodeAt(i);
bytes[i] = ascii;
}
return bytes;
}
function overrideStyleRound() {
var element = document.getElementsByClassName("content")
if (element.length > 0) {
var computedStyle = getComputedStyle(element[0])
if (computedStyle.getPropertyValue('border-image-repeat') == 'round')
element[0].style.borderImageRepeat = 'unset'
}
}