288 lines
7.6 KiB
JavaScript
288 lines
7.6 KiB
JavaScript
|
|
|
|
// Ezres szeparátor
|
|
function isPositiveInteger(n) {
|
|
return parseFloat(n) === n >>> 0;
|
|
}
|
|
var isLoaded=false;
|
|
|
|
function tsep(num)
|
|
{
|
|
var i=0;
|
|
var num_parts = num.toString().split(".");
|
|
num_parts[0] = num_parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, " ");
|
|
return num_parts.join(".");
|
|
};
|
|
|
|
function secondsToHms(d) {
|
|
d = Number(d);
|
|
var h = Math.floor(d / 3600);
|
|
var m = Math.floor(d % 3600 / 60);
|
|
var s = Math.floor(d % 3600 % 60);
|
|
|
|
var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
|
|
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
|
|
var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
|
|
return hDisplay + mDisplay + sDisplay;
|
|
}
|
|
|
|
function printPage(invoices,callback)
|
|
{
|
|
|
|
var item=[];
|
|
var i=1;
|
|
/*invoices.forEach(element => {
|
|
item.push({'nr':i,'owner':element.owner,'creationDate':element.creationDate,'expiryDate':element.expiryDate,'days':'1','state':element.state,'nPrice':element.nPrice});
|
|
});*/
|
|
|
|
|
|
// playground requires you to assign document definition to a variable called dd
|
|
|
|
/*var dd = {
|
|
content: [
|
|
{text: 'Számla lista', style: 'header'},
|
|
|
|
|
|
|
|
{
|
|
style: 'tableExample',
|
|
table: {
|
|
widths: [20, 'auto', 100, 100,'*','*','*'],
|
|
body: [
|
|
['#', 'Kibocsátó', 'Kelt', 'Esedékes', 'Határidő','Státusz','Érték'],
|
|
['1',
|
|
{text: 'ABB Kft g', italics: true, color: 'gray'},
|
|
{text: '2018.12.10', italics: true, color: 'gray'},
|
|
{text: '2019.12.09', italics: true, color: 'gray'},
|
|
{text: '30', italics: true, color: 'gray'},
|
|
{text: 'fizetetlen', italics: true, color: 'gray'},
|
|
{text: '122 512', italics: true, color: 'gray'}
|
|
],
|
|
['2',
|
|
{text: 'ABB Kft', italics: true, color: 'gray'},
|
|
{text: '2018.12.10', italics: true, color: 'gray'},
|
|
{text: '2019.12.09', italics: true, color: 'gray'},
|
|
{text: '30', italics: true, color: 'gray'},
|
|
{text: 'fizetetlen', italics: true, color: 'gray'},
|
|
{text: '122 512', italics: true, color: 'gray'}
|
|
]
|
|
]
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
styles: {
|
|
header: {
|
|
fontSize: 18,
|
|
bold: true,
|
|
fillColor: '#eeeeee',
|
|
margin: [0, 0, 0, 10]
|
|
},
|
|
subheader: {
|
|
fontSize: 16,
|
|
bold: true,
|
|
fillColor: '#eeeeee',
|
|
margin: [0, 10, 0, 5]
|
|
},
|
|
tableExample: {
|
|
margin: [0, 5, 0, 15]
|
|
},
|
|
tableHeader: {
|
|
bold: true,
|
|
fontSize: 13,
|
|
fillColor: '#eeeeee',
|
|
color: 'red'
|
|
}
|
|
},
|
|
defaultStyle: {
|
|
// alignment: 'justify'
|
|
}
|
|
|
|
}*/
|
|
|
|
//pdf.createPdf(dd).open();
|
|
callback(null,dd);
|
|
// ...
|
|
|
|
|
|
}
|
|
$(document).ready(function() {
|
|
$("#searchInvoices").keydown(function(){
|
|
isLoaded=false;
|
|
})
|
|
$("#searchInvoices").keyup(function () {
|
|
|
|
var searchTerm = $("#searchInvoices").val();
|
|
|
|
|
|
|
|
//var listItem = $('.results tbody').children('tr');
|
|
//var searchSplit = searchTerm.replace(/ /g, "'):containsi('")
|
|
if (searchTerm==="") searchTerm="noFilter";
|
|
if (isLoaded===false)
|
|
{
|
|
var mode=$("#invoicemode").text();
|
|
// console.log(mode);
|
|
$.get('/invoices/find/'+mode+'/'+ searchTerm, function(data) { console.log(data);
|
|
isLoaded=true;
|
|
|
|
|
|
localStorage.setItem("lastTableUrl", 'all');
|
|
renderInvoicesTable(data);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Táblázat sorainak generálása
|
|
function renderInvoicesTable(invoices)
|
|
{
|
|
$('#invoicesTable > tbody').empty();
|
|
var userName=$("#userName").text();
|
|
$.each(invoices,function(i,invoice){
|
|
var newRow = $('<tr class="clickable-row" id='+invoice._id+' data-href=/invoices/details/'+invoice._id+'>"');
|
|
var hatarido='</td><td style="text-align:center">'+'<span class="badge badge-pill badge-primary">'+invoice.daysLeft+' </span>'
|
|
var statusz='</td><td style="text-align:center">';
|
|
var expDate='</td><td style="text-align:center">'+invoice.expiryDate+"<br>";
|
|
var price=0;
|
|
if (invoice.state===0) invoice.daysLeft=0; // Ha kifizetett, akkor a hátralévő napok száma már 0
|
|
if (invoice.delayed>0)
|
|
{
|
|
hatarido='</td><td style="text-align:center">'+'<span class="badge badge-pill badge-primary">'+(invoice.daysLeft+invoice.delayed)+' </span>'
|
|
}
|
|
if (userName==='Vincze József') invoice.nPrice=0;
|
|
// var inputValue = parseInt(price.replace(/\D/g, ''),10);
|
|
if (invoice.currency==='HUF')
|
|
{
|
|
price=tsep(invoice.nPrice)+' HUF';
|
|
}
|
|
//if ($('#dropdownMenu1').val()==='EUR')
|
|
if (invoice.currency==='EUR')
|
|
{
|
|
price=tsep(invoice.nPrice)+ ' EUR';
|
|
}
|
|
//if ($('#dropdownMenu1').val()==='USD')
|
|
if (invoice.currency==='USD')
|
|
{
|
|
price=tsep(invoice.nPrice)+' USD';
|
|
}
|
|
// Bejövő
|
|
if(invoice.itype===false)
|
|
{
|
|
if (invoice.state===3)
|
|
{
|
|
if (invoice.delayed>0)
|
|
{ // Halasztott
|
|
statusz+="Halasztva +"+invoice.delayed+" nap";
|
|
expDate+=moment(invoice.expiryDate, "YYYY.MM.DD").add(invoice.delayed, 'days').format("YYYY.MM.DD");
|
|
}else
|
|
{ // Fizetetlen
|
|
statusz+="Fizetetlen";
|
|
}
|
|
}
|
|
|
|
}
|
|
// Kimenő
|
|
if(invoice.itype===true)
|
|
{
|
|
if (invoice.state===3)
|
|
{
|
|
if (invoice.delayed>0)
|
|
{ // Halasztott
|
|
statusz+="Halasztva +"+invoice.delayed+" nap";
|
|
expDate+=moment(invoice.expiryDate, "YYYY.MM.DD").add(invoice.delayed, 'days').format("YYYY.MM.DD");
|
|
}else
|
|
{ // Fizetetlen
|
|
statusz+="Kintlevőség";
|
|
}
|
|
}
|
|
|
|
}
|
|
if (invoice.state===0)
|
|
{
|
|
statusz+="Kiegyenlítve";
|
|
}
|
|
newRow.append('<td style="text-align:right">'+(i+1)+
|
|
'</td><td class="td">'+invoice.owner+
|
|
'</td><td class="td" style="text-align:right">'+invoice.invoiceNumber+
|
|
'</td><td style="text-align:center">'+invoice.dateEmission+
|
|
//'</td><td style="text-align:center">'+invoice.expiryDate+
|
|
expDate+
|
|
//'</td><td style="text-align:center">'+'<span class="badge badge-pill badge-primary">'+invoice.daysLeft+' </span>'+
|
|
hatarido+
|
|
//'</td><td style="text-align:center">'+invoice.state+
|
|
statusz+
|
|
'</td><td style="text-align:right">'+price+
|
|
'</td>');
|
|
$('#invoicesTable > tbody:last-child').append (newRow);
|
|
})
|
|
}
|
|
|
|
// Számla nyomtatása
|
|
$("#print").click(function(ev) {
|
|
var invoices;
|
|
isLoaded=false;
|
|
var mode= $(this).data("value");
|
|
if (mode)
|
|
{
|
|
//$.get('/invoices/print2' , function(data) { console.log(data);
|
|
$.get('/invoices/print2/'+mode , function(data) {
|
|
|
|
if (!isLoaded)
|
|
{ isLoaded=true;
|
|
|
|
//console.log(data);
|
|
pdfMake.createPdf(data).open();
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
alert('Nincs mit nyomtatni!');
|
|
}
|
|
});
|
|
|
|
$("#invoicesTable").on('click','tr',function(ev) {
|
|
//console.log($(this).attr("id"));
|
|
document.location = "/invoices/details/"+$(this).attr("id");
|
|
});
|
|
|
|
function updateInfoPanel()
|
|
{
|
|
$.get('/invoices/list/statement' , function(iboard) {
|
|
|
|
|
|
$('#kl_huf').text(tsep(iboard.kintlevoseg.HUF)+ ' HUF');
|
|
$('#kl_eur').text(tsep(iboard.kintlevoseg.EUR)+' EUR' );
|
|
$('#kl_usd').text(tsep(iboard.kintlevoseg.USD)+' USD' );
|
|
$('#tart_huf').text(tsep(iboard.tartozas.HUF)+' HUF');
|
|
$('#tart_eur').text(tsep(iboard.tartozas.EUR)+' EUR');
|
|
$('#tart_usd').text(tsep(iboard.tartozas.USD)+' USD');
|
|
$('#bev_huf').text(tsep(iboard.haviBevetel.HUF)+' HUF');
|
|
$('#bev_eur').text(tsep(iboard.haviBevetel.EUR)+' EUR');
|
|
$('#bev_usd').text(tsep(iboard.haviBevetel.USD)+' USD');
|
|
// $('#klh').text(klh[currEnum.HUF].toLocaleString('hu-HU', { style: 'currency', currency: 'HUF' })) ;
|
|
});
|
|
}
|
|
function printData()
|
|
{
|
|
var divToPrint=document.getElementById("invoicesTable");
|
|
newWin= window.open("");
|
|
newWin.document.write(divToPrint.outerHTML);
|
|
newWin.print();
|
|
newWin.close();
|
|
}
|
|
$('#print3').on('click',function(){
|
|
printData();
|
|
})
|
|
|
|
$(document).ready(function(e) {
|
|
updateInfoPanel();
|
|
setTimeout(function() {
|
|
|
|
$('#msg').fadeOut('slow');
|
|
}, 3000); // <-- time in milliseconds
|
|
}); |