<h2>Statements for <?= getClientName($_REQUEST['clientnumber'])?></h2>
<?php 
$files=array();
$docs=glob("output/reps/*.pdf");
$docs=array_combine(array_map("filemtime", $docs), $docs);
$cname=getClientName($_REQUEST['clientnumber']);
$cname=str_replace(" ","_",$_REQUEST['name']);
krsort($docs);
foreach ($docs as $filename) {

if (preg_match("/statement/",$filename) && preg_match("/".$cname."/",$filename)){
$files[] = $filename;
}
}
?>
<div class="card-deck">
    <?php foreach($files as $file){
        $dir=$file;
$doc=$file;
$color='';
$file=str_replace('output/reps/'.$_REQUEST['clientnumber'].'_','',$file);
$file=str_replace('.pdf','',$file);
$file=explode('_',$file);
if($file[1]=="unpaid"){$color="text-danger"; $title="Summary of unpaid invoices";}
if($file[1]=="paid"){$color="text-success"; $title="Summary of paid invoices";}
if($file[1]=="both"){$color="text-dark"; $title="Balance Sheet";}
?>

    <div class="card">
        <div class="card-header <?= $color?>"><?= strtoupper($title)?></div>
        <div class="card-body"><a class="btn btn-block btn-secondary" href="javascript:void(0)" onClick="">Statement Generated<br><?= $file[2]?></a></div>
        <div class="card-footer text-center">
            <a href="javascript:void(0)" class="btn btn-secondary noprint emailButton" data-values="<?= $_REQUEST['clientnumber']?>|||Emailing Statement|Please find attached your statement of account|<?= $doc?>"
               data-href="includes/master/mailer.php" data-toggle="tooltip" data-placement="top" data-original-title="Email Client"><i class="fad fa-envelope"></i></a>
            <a href="<?= $dir?>" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="View  Report"><i class="fad fa-eye"></i></a>
            <a href="javascript:void(0)" class="btn btn-secondary delButton" data-values="<?= $doc?>" data-toggle="tooltip" data-placement="top" data-original-title="Delete Statement"><i class="fad fa-trash"></i></a>
        </div>
    </div>


    <?php }?>
</div>
<script>
$(".formButton,.transferButton,.archiveButton, .emailButton").click(function() {
    $('#popupBox .modal-body').html('');
    $('#popupBox .modal-footer').html('');
    var target = $(this).data('href');
    var string = $(this).data('values');
    var dest = encodeURI(target + "?mode=popup&data=" + string)
    $('#popupBox').modal('show');
    $('#popupBox .modal-body').load(dest);
})

$(".delButton").click(function() {
    $('#popupBox .modal-body').html('');
    $('#popupBox .modal-footer').html('');
    var target = $(this).data('href');
    var string = $(this).data('values');
    var dest = encodeURI(target + "?mode=popup&data=" + string)
    $('#popupBox').modal('show');
    $('#popupBox .modal-body').load(dest);
})


$('#navBox').html(
    '<li class="breadrumb-item"><a href="index.php?t=includes/finance&p=finance_invoices.php">Finance</a><i class="fad fa-angle-double-right mx-2 mt-1"" aria-hidden="true"></i></li><li class="breadrumb-item active">Statements</li>')
</script>