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+''; docageing_html = docageing_html + ''+doccount+''; docageing_html = docageing_html + ''+item[jsonProp]+''; docageing_html = docageing_html + ''+item[jsonProp]+'-0'; docageing_html = docageing_html + ''+item[jsonProp]+'-1'; docageing_html = docageing_html + ''+item[jsonProp]+'-2'; docageing_html = docageing_html + ''+item[jsonProp]+'-3'; docageing_html = docageing_html + ''+item[jsonProp]+'-4'; docageing_html = docageing_html + ''+item[jsonProp]+'-5'; docageing_html = docageing_html + ''+item[jsonProp]+'-tot'; docageing_html = docageing_html + ''; doccount = doccount + 1; prevval = item[jsonProp]; } if(item.hasOwnProperty('age0')) a0 = a0 + item.age0; if(item.hasOwnProperty('age1')) a1 = a1 + item.age1; if(item.hasOwnProperty('age2')) a2 = a2 + item.age2; if(item.hasOwnProperty('age3')) a3 = a3 + item.age3; if(item.hasOwnProperty('age4')) a4 = a4 + item.age4; if(item.hasOwnProperty('age5')) a5 = a5 + item.age5; }); if(docageing_html.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; $('#d-age-0').html(ta0); $('#d-age-1').html(ta1); $('#d-age-2').html(ta2); $('#d-age-3').html(ta3); $('#d-age-4').html(ta4); $('#d-age-5').html(ta5); $('#d-age-all').html(gtotal); } $('#docwise_ageing').html(docageing_html); $(".dagecountport").on('click',function(e){ getDocAgeingCaseDetails(this); }); } function getDocAgeingCaseDetails(elm){ var filteredJson = {}; var age = $(elm).attr('code'); var cases = $(elm).html(); var desc = $(elm).attr('value'); var jsonPropValue = $(elm).attr('data-port'); $("#modalTitle").html(cases+" "+(desc+" Cases").trim()); if(docageingmode == 'radioport'){ filteredJson = $(docJson).filter(function (i,n){ if(age == '-1') return n.portname===jsonPropValue; else return (n.portname===jsonPropValue && n['age'+age] > 0); }); } else if(docageingmode == 'radiodoc'){ filteredJson = $(docJson).filter(function (i,n){ if(age == '-1') return n.doctype===jsonPropValue; else return (n.doctype===jsonPropValue && n['age'+age] > 0); }); } else if(docageingmode == 'radiovendor'){ filteredJson = $(docJson).filter(function (i,n){ if(age < 0) return n.vname===jsonPropValue; else return (n.vname===jsonPropValue && n['age'+age] > 0); }); } //alert(JSON.Stringify(filteredJson)); openModalForDocAgeingDetailMis(filteredJson); } function openModalForDocAgeingDetailMis(jsonArr){ var modalContent = '
'; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; var i = 0; for (var jsonRow of jsonArr){ i = i + 1; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; modalContent = modalContent + ''; } modalContent = modalContent + '
'; $(".modal-body").html(modalContent); bootstrap.Modal.getOrCreateInstance(document.getElementById("helperModal")).show(); $(".modal-dialog").removeClass('modal-xl').addClass('modal-xl'); $('#modal-table').DataTable({ paging: false, dom: 't', searching: false }); }