var docJson = {};
var docageingmode = 'radioport';
function ageingFigures(jsonObj){
$("#age-0").html(jsonObj["age-0"]);
$("#age-1").html(jsonObj["age-1"]);
$("#age-2").html(jsonObj["age-2"]);
$("#age-3").html(jsonObj["age-3"]);
$("#age-4").html(jsonObj["age-4"]);
$("#age-5").html(jsonObj["age-5"]);
$("#age-all").html(jsonObj["age-0"]+jsonObj["age-1"]+jsonObj["age-2"]+jsonObj["age-3"]+jsonObj["age-4"]+jsonObj["age-5"]);
if(jsonObj.hasOwnProperty('portwise')){
var ageing_html ='';
var portcount = 1;
jsonObj.portwise.forEach((item)=>{
ageing_html = ageing_html + '
';
ageing_html = ageing_html + '| '+portcount+' | ';
ageing_html = ageing_html + ''+item.portname+' | ';
ageing_html = ageing_html + ''+(item.hasOwnProperty('age0') ? item.age0:0)+' | ';
ageing_html = ageing_html + ''+(item.hasOwnProperty('age1') ? item.age1:0)+' | ';
ageing_html = ageing_html + ''+(item.hasOwnProperty('age2') ? item.age2:0)+' | ';
ageing_html = ageing_html + ''+(item.hasOwnProperty('age3') ? item.age3:0)+' | ';
ageing_html = ageing_html + ''+(item.hasOwnProperty('age4') ? item.age4:0)+' | ';
ageing_html = ageing_html + ''+(item.hasOwnProperty('age5') ? item.age5:0)+' | ';
var total = (item.hasOwnProperty('age0') ? item.age0:0);
total = total + (item.hasOwnProperty('age1') ? item.age1:0);
total = total + (item.hasOwnProperty('age2') ? item.age2:0);
total = total + (item.hasOwnProperty('age3') ? item.age3:0);
total = total + (item.hasOwnProperty('age4') ? item.age4:0);
total = total + (item.hasOwnProperty('age5') ? item.age5:0);
ageing_html = ageing_html + ''+total+' | ';
var risktotal = (item.hasOwnProperty('risklevel2') ? item.risklevel2:0);
risktotal = risktotal + (item.hasOwnProperty('risklevel3') ? item.risklevel3:0);
risktotal = risktotal + (item.hasOwnProperty('risklevel4') ? item.risklevel4:0);
ageing_html = ageing_html + ''+item.totalreceived+' | ';
ageing_html = ageing_html + ''+risktotal+' | ';
ageing_html = ageing_html + ''+(item.hasOwnProperty('risklevel2') ? item.risklevel2:0)+' '+(item.hasOwnProperty('risklevel2perc') ? item.risklevel2perc:'')+' | ';
ageing_html = ageing_html + ''+(item.hasOwnProperty('risklevel3') ? item.risklevel3:0)+' '+(item.hasOwnProperty('risklevel3perc') ? item.risklevel3perc:'')+' | ';
ageing_html = ageing_html + ''+(item.hasOwnProperty('risklevel4') ? item.risklevel4:0)+' '+(item.hasOwnProperty('risklevel4perc') ? item.risklevel4perc:'')+' | ';
ageing_html = ageing_html + '
';
portcount++;
});
$('#portwise_ageing').html(ageing_html);
$(".agecountport").on('click',function(e){
getAgeingCaseDetails(this);
});
}
if(jsonObj.hasOwnProperty('docs')){
docJson = jsonObj.docs;
populateDocAgeingTable();
}
}
function GetSortOrder(prop) {
return function(a, b) {
if (a[prop] > b[prop]) {
return 1;
} else if (a[prop] < b[prop]) {
return -1;
}
return 0;
}
}
function populateDocAgeingTable(){
if(docageingmode == 'radioport'){
docAgeingMis("portname");
}
else if(docageingmode == 'radiodoc'){
docAgeingMis("doctype");
}
else if(docageingmode == 'radiovendor'){
docAgeingMis("vname");
}
}
function docAgeingMis(jsonProp){
var sortedJson = docJson.sort(GetSortOrder(jsonProp));
$('#docwise_ageing').html('');
var docageing_html ='';
var doccount = 1;
var prevval = '';
var gtotal = 0;
var ta0=0;
var ta1=0;
var ta2=0;
var ta3=0;
var ta4=0;
var ta5=0;
var total = 0;
var a0=0;
var a1=0;
var a2=0;
var a3=0;
var a4=0;
var a5=0;
sortedJson.forEach((item)=>{
if(prevval != item[jsonProp]){
if(prevval.length > 0){
docageing_html = docageing_html.replace(prevval+'-0',a0);
docageing_html = docageing_html.replace(prevval+'-1',a1);
docageing_html = docageing_html.replace(prevval+'-2',a2);
docageing_html = docageing_html.replace(prevval+'-3',a3);
docageing_html = docageing_html.replace(prevval+'-4',a4);
docageing_html = docageing_html.replace(prevval+'-5',a5);
total = a0+a1+a2+a3+a4+a5;
docageing_html = docageing_html.replace(prevval+'-tot',total);
gtotal = gtotal + total;
ta0=ta0+a0;
ta1=ta1+a1;
ta2=ta2+a2;
ta3=ta3+a3;
ta4=ta4+a4;
ta5=ta5+a5;
}
total = 0;
a0=0;
a1=0;
a2=0;
a3=0;
a4=0;
a5=0;
docageing_html = docageing_html+'