<?php
if (!isset($this->headerBackground)) {
    $this->headerBackground = '#303030';
}
if (!isset($this->tableBackground)) {
    $this->tableBackground = '#3299bb';
}
if (!isset($this->pageBackground)) {
    $this->pageBackground = '#f6f6f6';
}
?>

<!DOCTYPE>
<html>
    <head>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <style>
            @page {
                margin: 0;
                margin-header: 0;
                header: html_header;
                footer: html_footer;
                background-color: <?php echo $this->pageBackground; ?>
            }
            body {
                font-family:'DejaVuSansCondensed';
            }
            .list-header {
                margin: .25cm 0;
                padding: .25cm 1cm;
                color: white;
            }

            table {
                margin: 0 1cm;
                width: 100%;
            }

            .content {
                padding: 0 1cm;
            }

            .clear {
                clear: both;
            }
        </style>
    </head>
    <body>
        <htmlpageheader name="header">
            <div style="background-color: #18365e; color: white; text-align: right;">
            <?php if ($this->status != "") { ?>
                <img alt="status" style="float: right;" border="0" src="images/<?php echo $this->status;?>_ribbon.png" />
            <?php } ?>

            <?php if ($this->invoicelogo != "") { ?>
                <img src="<?php echo $this->invoicelogo; ?>" alt="logo" style="max-width: 45%; max-height: 150px; margin: 0.5cm 0 0 0.5cm; float: left;" />
            <?php } else { ?>
                <p style="width: 45%;float: left;">&nbsp;</p>
            <?php } ?>

                <p style="float: right; padding: 1.5cm 1.5cm 0;">
                    <?php echo $this->companyName; ?><br/>

                <?php if (trim($this->companyAddress) != "") { ?>
                    <?php echo nl2br($this->companyAddress); ?><br/>
                <?php } ?>

                <?php if (trim($this->companyEmail) != "") { ?>
                    <a style="text-decoration: none; color: white;" href="mailto:<?php echo $this->companyEmail; ?>"><?php echo $this->companyEmail; ?></a><br/>
                <?php } ?>
                </p>
            </div>
        </htmlpageheader>

        <div style="margin-top: 15px; padding: 0.3cm 0.3cm 0;">
            <h3 style="text-align: center; text-transform: uppercase; margin: 0;"><?php echo $this->invoice; ?> - #<?php echo $this->invoiceNum; ?></h3>
            <?php if (trim($this->duedateMonth) != "") { ?>
                <h3 style="text-align: center; text-transform: uppercase; margin: 0; color: grey; letter-spacing: -1px; word-spacing: 5px;"><?php echo date('M Y', $this->duedateMonth); ?></h3>
            <?php } ?>
        </div>

        <table class="content">
            <tr>
                <td width="65%">
                    <?php if (trim($this->datecreated) != "") { ?>
                    <b><?php echo $this->user->lang('Invoice Date'); ?>:</b> <?php echo $this->datecreated; ?><br/>
                    <?php } ?>

                    <?php if (trim($this->duedate) != "") { ?>
                    <b><?php echo $this->user->lang('Due Date'); ?>:</b> <?php echo $this->duedate; ?><br/>
                    <?php } ?>

                    <?php if (trim($this->paidDate) != "") { ?>
                    <b><?php echo $this->user->lang("Paid"); ?>:</b> <?php echo $this->unescape($this->paidDate); ?><br/>
                    <?php } ?>

                    <?php if ($this->vatNumber != "") { ?>
                    <b><?php echo $this->user->lang('VAT Number'); ?>:</b> <?php echo $this->vatNumber; ?><br/>
                    <?php } ?>
                    <?php if (trim($this->paymentMethod) != "") { ?>
                        <b><?php echo $this->paymentLabel; ?></b>: <?php echo $this->paymentMethod; ?><br/>
                    <?php } ?>
                    <?php if (trim($this->pmtRef) != "") { ?>
                        <b><?php echo $this->user->lang('Pmt Reference'); ?>:</b> <?php echo $this->pmtRef; ?><br/>
                    <?php } ?>
                </td>

                <td>
                    <b><?php echo $this->user->lang("Bill To");?>:</b><br/>
                    <?php
                    if (trim($this->customerOrg) != '' && trim($this->customerName) != '') {
                        echo $this->customerOrg . ' - ' . $this->customerName . '<br/>';
                    } else {
                        if (trim($this->customerOrg) != "") {
                            echo $this->customerOrg."<br/>";
                        }
                        if (trim($this->customerName) != "") {
                            echo $this->customerName."<br/>";
                        }
                    }
                    if (trim($this->customerAddress) != "") {
                        echo $this->unescape($this->customerAddress)."<br/>";
                    }
                    if (trim($this->customerPhone) != "") {
                        echo $this->customerPhone."<br/>";
                    }
                    if (trim($this->customerEmail) != "") {
                        echo $this->customerEmail."<br/>";
                    }
                    ?>
                </td>
            </tr>
        </table>

        <table class="list-header" style="background-color: #20477a">
            <tr>
            <?php foreach ($this->invoiceheaders as $header) { ?>
                <th style="width: <?php echo $header['width']; ?>; text-align: <?php echo $header['align']; ?>"><?php echo $header['text']; ?></th>
            <?php } ?>
            </tr>
        </table>
        <table>
        <?php foreach ( $this->invoiceEntries as $invoiceEntry ) { ?>
            <tr>
            <?php foreach ($invoiceEntry['data'] as $entry) { ?>
                <td style="width: <?php echo $entry['width']; ?>; text-align: <?php echo $entry['align']; ?>">
                <?php
                if (is_array($entry['data'])) {
                    echo '<b>' . $entry['data'][0] . '</b>';

                    if ($entry['data'][1] != "") {
                        echo "<br/>".$entry['data'][1];
                    }
                } else {
                    echo $entry['data'];
                }
                ?>
                </td>
            <?php } ?>
            </tr>
        <?php } ?>
        </table>

        <table style="margin: 0 0 0 1cm; border-spacing: 0;page-break-inside: avoid;">
            <tr>
                <td style="vertical-align: top;padding-top: 25px;"><?php echo $this->unescape($this->pmtSuccessfulTransactions); ?></td>
                <td style="width: 36%; margin: 0; padding: 0;">
                    <table align="right" style="page-break-inside: avoid; background-color: #20477a; color: white; padding: .5cm 1cm .5cm .5cm; margin: 0; text-align: right; border-spacing: 0 10px;">
                    <?php foreach ($this->totalLabels as $total) { ?>
                        <tr>
                            <td width="50%"><?php echo str_replace(':', '', $total['totalLabel']); ?></td>
                            <td width="50%"><?php echo $total['totalPrice']; ?></td>
                        </tr>
                    <?php } ?>
                    </table>
                </td>
            </tr>
        </table>

        <?php if ($this->additionalnotes != "") { ?>
            <div class="content">
                <p>
                    <b><?php echo $this->user->lang("Additional Notes");?></b><br/>
                    <?php echo nl2br($this->unescape($this->additionalnotes)); ?>
                </p>
            </div>
        <?php } ?>

        <htmlpagefooter name="footer">
            <div class="content">
            <?php
                echo "<p>".nl2br($this->footerContent)."</p>";
                if ($this->disclaimerContent != "") {
                    echo "<hr>";
                    echo "<small>".nl2br($this->disclaimerContent)."</small>";
                }
            ?>
            </div>
        </htmlpagefooter>

    </body>
</html>
