function getChecksMulti() { console.log('multi mode')
var splitMode = parent.$("input[name='chainMode']:checked").val();
if (splitMode == "split") {
splitter('multi')
} else {
var str = '';
var x = '';
var y = '';

var pass = '';
var selected = '';

$('input[type=checkbox]').each(function() {
if ($(this).is(":checked")) {
if ($(this).attr('name') == null) {} else {
x = $(this).attr('name').split("-")
selected = selected + ($(this).attr('name') + '|');
if ($(this).data('status') === "URGENT") {
y = $(this).attr('name').split("-")
hse = hse + '../output/reports/<?= $_REQUEST['clientnumber']?>/' + y[0] + '_' + y[1] + '.pdf,';
errordel = errordel + ($(this).attr('name') + '|');

} else {}
}
//DEBUG ITEMS
$('#itemList').text(pass)

}
});
if (selected == "") {
showResponse('warning', 'No Items Selected')
} else {

loadModalContent(
'<p>Do you wish to manually sort the reports?</p>',
"multiBox",
"modal-xl",
1060,
"true",
'Manual Sort',
'sortReports',
'genPack(\'' + selected + '\',\'' + errordel + '\',\'' + hse + '\')',
'manualSort(\'' + selected + '\',\'' + errordel + '\',\'' + hse + '\')'
);


}
}
}


////////////////////////////////////////////////////////////////////////////////

var mCount = 0;
var sCount = 0;
var xCount = 0;
var finalcount = 0;

function genPack(selected, errordel, hse) {console.log('genpack multi')
$('#multiBox').modal('hide');
$('#deliveryScreen').css('display', 'none');
$('#loading').css('display', 'block')
var varray = selected.split('|');
var earray = errordel.split('|');
var R500 = [];
var R502 = [];
var R503 = [];
var R504 = [];
var R506 = [];
var R507 = [];
var R508 = [];
var R601 = [];
var R602 = [];
var R700 = [];
var R701 = [];
var R800 = [];
var R801 = [];
var R802 = [];
var R900 = [];
$('#statusCount').html('Generating Report Covers<br><i class="fad fa-blanket"></i>')
console.log('varrayIn='+varray)
$.post(ROOT_URL+'/functions/generators/genCoverMulti.php', {
items: varray,
clientnumber: '<?= $_REQUEST['clientnumber']?>',
site: '<?= $_REQUEST['site']?>',
tenant: TENANT_URL
}, function(ret) {//debug(ret)


//PACK ALL REPORTS
var cnt = 0;
for (var i = 0; i < varray.length; i++) {
  if (varray[i] !="" ) {
  $('#attachBtn').css('display', 'none' );
  var sarray=varray[i].split('-');
  var ml=$('#multiList').text()
  if (sarray[2]==500) {
  R500.push(varray[i])
  }
  if (sarray[2]==502) {
  R502.push(varray[i])
  }
  if (sarray[2]==503) {
  R503.push(varray[i])
  }
  if (sarray[2]==504) {
  R504.push(varray[i])
  }
  if (sarray[2]==506) {
  R506.push(varray[i])
  }
  if (sarray[2]==507) {
  xCount +=1;
  genSinglePdf(varray[i].toString(), xCount)
  }
  if (sarray[2]==508) {
  xCount +=1;
  genSinglePdf(varray[i].toString(), xCount)
  }
  if (sarray[2]==601) {
  xCount +=1;
  genSinglePdf(varray[i].toString(), xCount)
  }
  if (sarray[2]==602) {
  xCount +=1;
  genSinglePdf(varray[i].toString(), xCount)
  }
  if (sarray[2]==700) {
  xCount +=1;
  genSinglePdf(varray[i].toString(), xCount)
  }
  if (sarray[2]==701) {
  xCount +=1;
  genSinglePdf(varray[i].toString(), xCount)
  }
  if (sarray[2]==800) {
  xCount +=1;
  genSinglePdf(varray[i].toString(), xCount)
  }
  if (sarray[2]==801) {
  xCount +=1;
  genSinglePdf(varray[i].toString(), xCount)
  }
  if (sarray[2]==802) {
  xCount +=1;
  genSinglePdf(varray[i].toString(), xCount)
  }
  if (sarray[2]==900) {
  xCount +=1;
  genSinglePdf(varray[i].toString(), xCount)
  }
  }
  }

  if ($.isEmptyObject(R500)) {} else {
  var string=R500.toString();
  var n=R500.length;
  if (n> 1) {
    $.post(ROOT_URL+'/functions/compare_reports.php', {
    data: R500,
    tenant:TENANT_URL
    }, function(ret) {
    ret = $.trim(ret);
    ret = $.parseJSON(ret);
    $(ret).each(function(i, item) {
    var xn = item.length;
    if (xn > 1) {
    mCount += 1;
    genMultiPdf(item, 500, mCount, hse)
    } else {
    sCount += 1;
    genSinglePdf(item.toString(), sCount, hse)
    }
    })
    })
    } else {
    sCount += 1;
    genSinglePdf(R500.toString(), sCount, hse)
    }
    }


    if ($.isEmptyObject(R502)) {} else {
    var string = R502.toString();
    var n = R502.length;
    if (n > 1) {
    $.post(ROOT_URL+'/functions/compare_reports.php', {
    data: R502,
    tenant:TENANT_URL
    }, function(ret) {
    ret = $.trim(ret);
    ret = $.parseJSON(ret);
    $(ret).each(function(i, item) {
    var xn = item.length;
    if (xn > 1) {
    mCount += 1;
    genMultiPdf(item, 502, mCount, hse)
    } else {
    sCount += 1;
    genSinglePdf(item.toString(), sCount, hse)
    }
    })
    })
    } else {
    sCount += 1;
    genSinglePdf(R502.toString(), sCount, hse)
    }
    }

    if ($.isEmptyObject(R503)) {} else {
    var string = R503.toString();
    var n = R503.length;
    if (n > 1) {
    $.post(ROOT_URL+'/functions/compare_reports.php', {
    data: R503,
    tenant:TENANT_URL
    }, function(ret) {
    ret = $.trim(ret);
    ret = $.parseJSON(ret);
    $(ret).each(function(i, item) {
    var xn = item.length;
    if (xn > 1) {
    mCount += 1;
    genMultiPdf(item, 503, mCount, hse)
    } else {
    sCount += 1;
    genSinglePdf(item.toString(), sCount, hse)
    }
    })
    })
    } else {
    sCount += 1;
    genSinglePdf(R503.toString(), sCount, hse)
    }
    }


    if ($.isEmptyObject(R504)) {} else {
    var string = R504.toString();
    var n = R504.length;
    if (n > 1) {
    $.post(ROOT_URL+'/functions/compare_reports.php', {
    data: R504,
    tenant:TENANT_URL
    }, function(ret) {
    ret = $.trim(ret);
    ret = $.parseJSON(ret);
    $(ret).each(function(i, item) {
    var xn = item.length;
    if (xn > 1) {
    mCount += 1;
    genMultiPdf(item, 504, mCount, hse)
    } else {
    sCount += 1;
    genSinglePdf(item.toString(), sCount, hse)
    }
    })
    })
    } else {
    sCount += 1;
    genSinglePdf(R504.toString(), sCount, hse)
    }
    }


    if ($.isEmptyObject(R506)) {} else {
    var string = R506.toString();
    var n = R506.length;
    if (n > 1) {
    $.post(ROOT_URL+'/functions/compare_reports.php', {
    data: R506,
    tenant:TENANT_URL
    }, function(ret) {
    ret = $.trim(ret);
    ret = $.parseJSON(ret);
    $(ret).each(function(i, item) {
    var xn = item.length;
    if (xn > 1) {
    mCount += 1;
    genMultiPdf(item, 506, mCount, hse)
    } else {
    sCount += 1;
    genSinglePdf(item.toString(), sCount, hse)
    }
    })
    })
    } else {
    sCount += 1;
    genSinglePdf(R506.toString(), sCount, hse)
    }
    }

    if ($.isEmptyObject(R900)) {} else {
    var string = R900.toString();
    var n = R900.length;
    if (n > 1) {
    $.post(ROOT_URL+'/functions/compare_reports.php', {
    data: R900,
    tenant:TENANT_URL
    }, function(ret) {
    ret = $.trim(ret);
    ret = $.parseJSON(ret);
    $(ret).each(function(i, item) {
    var xn = item.length;
    if (xn > 1) {
    mCount += 1;
    genMultiPdf(item, 900, mCount, hse)
    } else {
    sCount += 1;
    genSinglePdf(item.toString(), sCount, hse)
    }
    })
    })
    } else {
    sCount += 1;
    genSinglePdf(R900.toString(), sCount, hse)
    }
    }

    $('#itemList').text(selected)
    $('#debug').text(varray.length - 1)
    })
    }

    // EOF GENPACK
    ////////////////////////////////////////////////////////////////////////////////

    function genMultiPdf(array, form, count, hse) {
    var chainMode = parent.$("input[name='chainMode']:checked").val();
    var outputMode = parent.$("input[name='outputMode']:checked").val();
    //alert(array)
    $('#statusCount').html('Generating Multi ' + form + ' Report<br><i class="fad fa-file-spreadsheet"></i>')
    $.post(ROOT_URL+'/functions/generators/genMultiPDF.php', {
    clientnumber: '<?= $_REQUEST['clientnumber']?>',
    items: array,
    form: form,
    tenant:TENANT_URL
    }, function(data) { //debug(data)

    var ml = $('#multiList').text()
    $('#multiList').text(ml + data + "|")
    var add = finalcount += 1
    window.finalcount = add
    var total = (mCount + sCount + xCount);

    if (outputMode == "zip") {

    genZips(hse);
    }
    if (outputMode == "pdf") {

    genMPDO(hse);
    }



    })
    }

    ////////////////////////////////////////////////////////////////////////////////

    function genSinglePdf(data) {
    var y = data.split("-")
    //alert(y[2])
    $.post(ROOT_URL+'/functions/generators/checkPDF.php', {
    clientnumber: '<?= $_REQUEST['clientnumber']?>',
    repnumber: y[0],
    items: y[1],
    form: y[2],
    tenant: TENANT_URL
    }, function(ret) { //debug(ret)
    var ml = $('#multiList').text()
    $('#multiList').text(ml + data + "|")

    var add = finalcount += 1
    window.finalcount = add
    var total = (mCount + sCount + xCount);

    //alert(total+' | '+finalcount)
    })
    }