Files
matrix/cygnus-onprem-app/build/WebContent/js/appjs/dashageing.js

262 lines
14 KiB
JavaScript

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 + '<tr class="hourlymis_data">';
ageing_html = ageing_html + '<td scope="row" class="td-orange-light" style="text-align:left;padding-left:0.5rem" >'+portcount+'</td>';
ageing_html = ageing_html + '<td scope="row" style="text-align:left;padding-left:0.5rem" >'+item.portname+'</td>';
ageing_html = ageing_html + '<td scope="row" class="reporting-data agecountport" data-port="'+item.portid+'" value="'+item.portname+' (Ageing 0)" code="0" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+(item.hasOwnProperty('age0') ? item.age0:0)+'</td>';
ageing_html = ageing_html + '<td scope="row" class="reporting-data agecountport" data-port="'+item.portid+'" value="'+item.portname+' (Ageing 1)" code="1" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+(item.hasOwnProperty('age1') ? item.age1:0)+'</td>';
ageing_html = ageing_html + '<td scope="row" class="reporting-data agecountport" data-port="'+item.portid+'" value="'+item.portname+' (Ageing 2)" code="2" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+(item.hasOwnProperty('age2') ? item.age2:0)+'</td>';
ageing_html = ageing_html + '<td scope="row" class="reporting-data agecountport" data-port="'+item.portid+'" value="'+item.portname+' (Ageing 3)" code="3" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+(item.hasOwnProperty('age3') ? item.age3:0)+'</td>';
ageing_html = ageing_html + '<td scope="row" class="reporting-data agecountport" data-port="'+item.portid+'" value="'+item.portname+' (Ageing 4)" code="4" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+(item.hasOwnProperty('age4') ? item.age4:0)+'</td>';
ageing_html = ageing_html + '<td scope="row" class="reporting-data agecountport" data-port="'+item.portid+'" value="'+item.portname+' (Ageing >4)" code="5" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+(item.hasOwnProperty('age5') ? item.age5:0)+'</td>';
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 + '<td scope="row" class="td-orange-light agecountport" data-port="'+item.portid+'" value="'+item.portname+' (Ageing All)" code="-1" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+total+'</td>';
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 + '<td scope="row" style="font-weight:bold" >'+item.totalreceived+'</td>';
ageing_html = ageing_html + '<td scope="row" class="riskcountport" data-port="'+item.portid+'" value="'+item.portname+' (All)" code="-1" style="font-weight:bold">'+risktotal+'</td>';
ageing_html = ageing_html + '<td scope="row" class="reporting-data riskcountport" data-port="'+item.portid+'" value="'+item.portname+' (Level 2)" code="2" ><strong>'+(item.hasOwnProperty('risklevel2') ? item.risklevel2:0)+'</strong> <sup>'+(item.hasOwnProperty('risklevel2perc') ? item.risklevel2perc:'')+'</sup></td>';
ageing_html = ageing_html + '<td scope="row" class="reporting-data riskcountport" data-port="'+item.portid+'" value="'+item.portname+' (Level 3)" code="3" ><strong>'+(item.hasOwnProperty('risklevel3') ? item.risklevel3:0)+'</strong> <sup>'+(item.hasOwnProperty('risklevel3perc') ? item.risklevel3perc:'')+'</sup></td>';
ageing_html = ageing_html + '<td scope="row" class="reporting-data riskcountport" data-port="'+item.portid+'" value="'+item.portname+' (Level 4)" code="4" ><strong>'+(item.hasOwnProperty('risklevel4') ? item.risklevel4:0)+'</strong> <sup>'+(item.hasOwnProperty('risklevel4perc') ? item.risklevel4perc:'')+'</sup></td>';
ageing_html = ageing_html + '</tr>';
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+'<tr class="hourlymis_data">';
docageing_html = docageing_html + '<td scope="row" class="td-orange-light" style="text-align:left;padding-left:0.5rem" >'+doccount+'</td>';
docageing_html = docageing_html + '<td scope="row" style="text-align:left;padding-left:0.5rem" >'+item[jsonProp]+'</td>';
docageing_html = docageing_html + '<td scope="row" class="reporting-data dagecountport" data-port="'+item[jsonProp]+'" value="'+item[jsonProp]+' (Ageing 0)" code="0" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+item[jsonProp]+'-0</td>';
docageing_html = docageing_html + '<td scope="row" class="reporting-data dagecountport" data-port="'+item[jsonProp]+'" value="'+item[jsonProp]+' (Ageing 1)" code="1" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+item[jsonProp]+'-1</td>';
docageing_html = docageing_html + '<td scope="row" class="reporting-data dagecountport" data-port="'+item[jsonProp]+'" value="'+item[jsonProp]+' (Ageing 2)" code="2" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+item[jsonProp]+'-2</td>';
docageing_html = docageing_html + '<td scope="row" class="reporting-data dagecountport" data-port="'+item[jsonProp]+'" value="'+item[jsonProp]+' (Ageing 3)" code="3" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+item[jsonProp]+'-3</td>';
docageing_html = docageing_html + '<td scope="row" class="reporting-data dagecountport" data-port="'+item[jsonProp]+'" value="'+item[jsonProp]+' (Ageing 4)" code="4" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+item[jsonProp]+'-4</td>';
docageing_html = docageing_html + '<td scope="row" class="reporting-data dagecountport" data-port="'+item[jsonProp]+'" value="'+item[jsonProp]+' (Ageing >4)" code="5" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+item[jsonProp]+'-5</td>';
docageing_html = docageing_html + '<td scope="row" class="td-orange-light dagecountport" data-port="'+item[jsonProp]+'" value="'+item[jsonProp]+' (Ageing All)" code="-1" style="font-weight:bold;text-decoration:underline;cursor:pointer" >'+item[jsonProp]+'-tot</td>';
docageing_html = docageing_html + '</tr>';
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 = '<div class="container"><table id="modal-table" class="table table-striped table-md border small">';
modalContent = modalContent + '<thead><tr>';
modalContent = modalContent + '<th style="text-align:left">S.No</th>';
modalContent = modalContent + '<th style="text-align:left">Portfolio</th>';
modalContent = modalContent + '<th style="text-align:left">Date</th>';
modalContent = modalContent + '<th style="text-align:left">Name</th>';
modalContent = modalContent + '<th style="text-align:left">Document</th>';
modalContent = modalContent + '<th style="text-align:left">Provider</th>';
modalContent = modalContent + '<th style="text-align:left">Unique No</th>';
modalContent = modalContent + '<th style="text-align:left">Vendor</th>';
modalContent = modalContent + '<th style="text-align:left">Status</th>';
modalContent = modalContent + '</tr></thead><tbody>';
var i = 0;
for (var jsonRow of jsonArr){
i = i + 1;
modalContent = modalContent + '<tr>';
modalContent = modalContent + '<td style="text-align:left">'+i+'</td>';
modalContent = modalContent + '<td style="text-align:left">'+jsonRow.portname+'</td>';
modalContent = modalContent + '<td style="text-align:left">'+jsonRow.recdate+'</td>';
modalContent = modalContent + '<td style="text-align:left">'+jsonRow.appname+'</td>';
modalContent = modalContent + '<td style="text-align:left">'+jsonRow.doctype+'</td>';
modalContent = modalContent + '<td style="text-align:left">'+jsonRow.provider+'</td>';
modalContent = modalContent + '<td style="text-align:left">'+jsonRow.uniqueno+'</td>';
modalContent = modalContent + '<td style="text-align:left">'+jsonRow.vname+'</td>';
modalContent = modalContent + '<td style="text-align:left">'+jsonRow.status+'</td>';
modalContent = modalContent + '</tr>';
}
modalContent = modalContent + '</tbody></table></div>';
$(".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: '<f>t',
searching: false
});
}