function genPDO(selected, errordel) {console.log('pdf')
var output = new Array();

if (parent.$('#schAttach').is(":checked")) {
output.push({
source: 'output/reports/<?= $_REQUEST['clientnumber']?>',
file: '<?= $_REQUEST['clientnumber']?>_schedule.pdf',
type: 'sch'
});
}

var str = selected.split('|');

output.push({
source: 'output/reports/<?= $_REQUEST['clientnumber']?>',
file: 'report_cover.pdf',
type: 'rc'
});

if (parent.$('#wsAttach').is(":checked") || outputMode == "pdf") {
console.log('ws started')
var x = parent.$('#itemList').text()
console.log(x)
$.post(ROOT_URL+'/includes/master/report_functions.php', {
FUNCTION: 'detectPWS',
items: x,
client: '<?= $_REQUEST['clientnumber']?>',
tenant:TENANT_URL
}, function(ret) {
var files = ret.split('|');
$.each(files, function(key, value) {
if (value != '') {
const {
length
} = output;
const id = length + 1;
const found = output.some(el => el.file === value + '.pdf');
if (!found) {
output.push({
source: 'output/wsfiles/<?= $_REQUEST['clientnumber']?>',
file: value + '.pdf',
type: 'ws'
});
console.log(value + ' added')
} else {}
}
});


$.each(str, function(key, value) {
var val = value.split('-');
output.push({
source: 'output/reports/<?= $_REQUEST['clientnumber']?>',
file: val[0] + '_' + val[1] + '.pdf',
type: 'pdf'
});
});

$('#delivery').css('display', 'block');
var outputString = JSON.stringify(output);
console.log('1')
$('#mailerContainer').load(ROOT_URL+'/includes/master/deliveryMailer.php?attachments=' + outputString + '&clientnumber=<?= $_REQUEST['clientnumber']?>&tenant='+TENANT_URL)
$('#loading').css('display', 'none')

})
} else {
$.each(str, function(key, value) {
var val = value.split('-');
output.push({
source: 'output/reports/<?= $_REQUEST['clientnumber']?>',
file: val[0] + '_' + val[1] + '.pdf',
type: 'pdf'
});
});
$('#delivery').css('display', 'block');
var outputString = JSON.stringify(output);
console.log('2')
$('#mailerContainer').load(ROOT_URL+'/includes/master/deliveryMailer.php?attachments=' + outputString + '&clientnumber=<?= $_REQUEST['clientnumber']?>&tenant='+TENANT_URL)

$('#loading').css('display', 'none')


}
}



function genMPDO(hse) {
var output = new Array();

if (parent.$('#schAttach').is(":checked")) {
output.push({
source: 'output/reports/<?= $_REQUEST['clientnumber']?>',
file: '<?= $_REQUEST['clientnumber']?>_schedule.pdf',
type: 'sch'
});
}

var found = output.filter(function(item) {
return item.file === 'report_cover.pdf';
});
if (found != "") {} else {
output.push({
source: 'output/reports/<?= $_REQUEST['clientnumber']?>',
file: 'report_cover.pdf',
type: 'rc'
});
}


if (parent.$('#wsAttach').is(":checked") || outputMode == "pdf") {
var s = parent.$('#itemList').text()
//genMasterPDF()
$.post(ROOT_URL+'/includes/master/report_functions.php', {
FUNCTION: 'detectPWS',
items: s,
client: '<?= $_REQUEST['clientnumber']?>',
tenant:TENANT_URL
}, function(ret) { //debug(ret)
var files = ret.split('|');
$.each(files, function(key, value) {
if (value != '') {
const {
length
} = output;
const id = length + 1;
const found = output.some(el => el.file === value + '.pdf');
if (!found) {
output.push({
source: 'output/wsfiles/<?= $_REQUEST['clientnumber']?>',
file: value + '.pdf',
type: 'ws'
});
}
}

});

var ml = $('#multiList').text()
var str = ml.split('|');
$.each(str, function(key, value) {

if (value.indexOf('multi') !== -1) {
var found = output.filter(function(item) {
return item.file === value + '.pdf';
});
if (found != "") {} else {
output.push({
source: 'output/reports/<?= $_REQUEST['clientnumber']?>',
file: value + '.pdf',
type: 'mpdf'
});
}
} else {
var val = value.split('-');
var found = output.filter(function(item) {
return item.file === val[0] + '_' + val[1] + '.pdf';
});
if (found != "") {} else {
output.push({
source: 'output/reports/<?= $_REQUEST['clientnumber']?>',
file: val[0] + '_' + val[1] + '.pdf',
type: 'pdf'
});
}
}
});


$('#delivery').css('display', 'block');
var outputString = JSON.stringify(output);
console.log('3')
$('#mailerContainer').load(ROOT_URL+'/includes/master/deliveryMailer.php?attachments=' + outputString + '&clientnumber=<?= $_REQUEST['clientnumber']?>&tenant='+TENANT_URL)

$('#loading').css('display', 'none')




})
} else {
var ml = $('#multiList').text()
var str = ml.split('|');
$.each(str, function(key, value) {

if (value.indexOf('multi') !== -1) {
var found = output.filter(function(item) {
return item.file === value + '.pdf';
});
if (found != "") {} else {
output.push({
source: 'output/reports/<?= $_REQUEST['clientnumber']?>',
file: value + '.pdf',
type: 'mpdf'
});
}
} else {
var val = value.split('-');
var found = output.filter(function(item) {
return item.file === val[0] + '_' + val[1] + '.pdf';
});
if (found != "") {} else {
output.push({
source: 'output/reports/<?= $_REQUEST['clientnumber']?>',
file: val[0] + '_' + val[1] + '.pdf',
type: 'pdf'
});
}
}
});


$('#delivery').css('display', 'block');
var outputString = JSON.stringify(output);
console.log('4')
$('#mailerContainer').load(ROOT_URL+'/includes/master/deliveryMailer.php?attachments=' + outputString + '&clientnumber=<?= $_REQUEST['clientnumber']?>&tenant='+TENANT_URL)

$('#loading').css('display', 'none')


}
if (hse === '') {}
else {

setTimeout(function() {
var defectListElement = document.getElementById('defectList');
if (defectListElement) {
console.log("defectList found, calling genHSEZip");
genHSEZip(selected, errordel); // Call genHSEZip after delay
} else {
console.error("defectList not found.");
}
}, 300);


}
}