function genCvr(selected, errordel) {
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 = deliveryListFromAny(selected);

deliveryAppendCoverAttachments(output);

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 {}
}
});




$('#delivery').css('display', 'block');
var outputString = JSON.stringify(output);
// alert("A" + outputString)
//genMasterPDF()
deliveryLoadMailer({attachments: output, clientnumber: '<?= $_REQUEST['clientnumber']?>'});
$('#loading').css('display', 'none')

})
} else {

$('#delivery').css('display', 'block');
var outputString = JSON.stringify(output);
//alert("B" + outputString)
//genMasterPDF()
deliveryLoadMailer({attachments: output, clientnumber: '<?= $_REQUEST['clientnumber']?>'});

$('#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'
});
}

deliveryAppendCoverAttachments(output);


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 = deliveryListFromAny(ml);
$.each(str, function(key, value) {
if (value === '') return;

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);
//genMasterPDF()
deliveryLoadMailer({attachments: output, clientnumber: '<?= $_REQUEST['clientnumber']?>'});

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




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

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);
//genMasterPDF()
deliveryLoadMailer({attachments: output, clientnumber: '<?= $_REQUEST['clientnumber']?>'});

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


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

genHSEZip(parent.$('#itemList').text(), errordel)
}
}
