Пример #1
0
 protected function _formatNumber($value, $decimals = 2, $decimalsOptional = false)
 {
     if ($decimalsOptional) {
         return miscRound2OptDecim($value, $decimals, $GLOBALS['locPDFDecimalSeparator'], $GLOBALS['locPDFThousandSeparator']);
     }
     return miscRound2Decim($value, $decimals, $GLOBALS['locPDFDecimalSeparator'], $GLOBALS['locPDFThousandSeparator']);
 }
Пример #2
0
 protected function transform($xslt, $xsd = '')
 {
     $xml = new SimpleXMLElement('<?xml version="1.0"?><invoicedata/>');
     $sender = $xml->addChild('sender');
     $this->arrayToXML($this->senderData, $sender);
     $recipient = $xml->addChild('recipient');
     $this->arrayToXML($this->recipientData, $recipient);
     $invoice = $xml->addChild('invoice');
     $invoiceData = $this->invoiceData;
     $invoiceData['totalsum'] = $this->totalSum;
     $invoiceData['totalvat'] = $this->totalVAT;
     $invoiceData['totalsumvat'] = $this->totalSumVAT;
     $invoiceData['formatted_ref_number'] = $this->refNumber;
     $invoiceData['barcode'] = $this->barcode;
     $invoiceData['groupedvats'] = $this->groupedVATs;
     $this->arrayToXML($invoiceData, $invoice);
     $rows = $invoice->addChild('rows');
     $this->arrayToXML($this->invoiceRowData, $rows, 'row');
     foreach ($this->invoiceRowData as &$data) {
         if (isset($GLOBALS["locPDF{$data['type']}"])) {
             $data['type'] = $GLOBALS["locPDF{$data['type']}"];
         }
     }
     require 'settings_def.php';
     $settingsData = array();
     foreach ($arrSettings as $key => $value) {
         if (substr($key, 0, 8) == 'invoice_' && $value['type'] != 'LABEL') {
             switch ($key) {
                 case 'invoice_terms_of_payment':
                     $settingsData[$key] = sprintf(getTermsOfPayment($invoiceData['company_id']), getPaymentDays($invoiceData['company_id']));
                     break;
                 case 'invoice_pdf_filename':
                     $settingsData[$key] = $this->getPrintOutFileName(getSetting('invoice_pdf_filename'));
                     break;
                 default:
                     $settingsData[$key] = getSetting($key);
             }
         }
     }
     $settingsData['invoice_penalty_interest_desc'] = $GLOBALS['locPDFPenaltyInterestDesc'] . ': ' . miscRound2OptDecim(getSetting('invoice_penalty_interest'), 1) . ' %';
     $settingsData['current_time_year'] = date('Y');
     $settingsData['current_time_mon'] = date('m');
     $settingsData['current_time_day'] = date('d');
     $settingsData['current_time_hour'] = date('H');
     $settingsData['current_time_min'] = date('i');
     $settingsData['current_time_sec'] = date('s');
     $settingsData['current_timestamp'] = date('c');
     $settingsData['current_timestamp_utc'] = gmdate('Y-m-d\\TH:i:s\\Z');
     $settings = $xml->addChild('settings');
     $this->arrayToXML($settingsData, $settings);
     $xsltproc = new XSLTProcessor();
     $xsl = new DOMDocument();
     $xsl->load($xslt);
     $xsltproc->importStylesheet($xsl);
     $xsltproc->setParameter('', 'stylesheet', $this->printStyle);
     $domDoc = dom_import_simplexml($xml)->ownerDocument;
     $this->xml = $xsltproc->transformToXML($domDoc);
     if ($xsd) {
         libxml_use_internal_errors(true);
         $xmlDoc = new DOMDocument();
         $xmlDoc->loadXML($this->xml);
         if (!$xmlDoc->schemaValidate($xsd)) {
             header("Content-Type: text/plain");
             echo "Result XML validation failed:\n\n";
             $errors = libxml_get_errors();
             foreach ($errors as $error) {
                 switch ($error->level) {
                     case LIBXML_ERR_WARNING:
                         $type = 'Warning';
                         break;
                     case LIBXML_ERR_FATAL:
                         $type = 'Fatal';
                         break;
                     default:
                         $type = 'Error';
                 }
                 echo "{$type} {$error->code}({$error->level}) at {$error->line}:{$error->column}: {$error->message}\n";
             }
             echo "\n\nXML:\n\n";
             $lineno = 1;
             foreach (explode("\n", $this->xml) as $line) {
                 echo "{$lineno}\t{$line}\n";
                 ++$lineno;
             }
             exit(1);
         }
     }
 }
Пример #3
0
    private function printTotals($format, $printFields, $intTotSum, $intTotVAT, $intTotSumVAT, $totalToPay, $totalsPerVAT)
    {
        if (!in_array('sums', $printFields)) {
            return;
        }
        if ($format == 'pdf' || $format == 'pdfl') {
            $pdf = $this->pdf;
            if ($pdf->getY() > $pdf->getPageHeight() - 7 - 15) {
                $pdf->AddPage();
            }
            $pdf->SetFont('Helvetica', '', 8);
            $pdf->setLineWidth(0.2);
            $rowWidth = 0;
            $sumPos = 75;
            if (in_array('invoice_no', $printFields)) {
                $rowWidth += 18;
            }
            if (in_array('invoice_date', $printFields)) {
                $rowWidth += 20;
            }
            if (in_array('due_date', $printFields)) {
                $rowWidth += 20;
            }
            if (in_array('payment_date', $printFields)) {
                $rowWidth += 20;
            }
            if (in_array('company_name', $printFields)) {
                $rowWidth += 40;
            }
            if (in_array('status', $printFields)) {
                $rowWidth += 15;
            }
            if (in_array('ref_number', $printFields)) {
                $rowWidth += 25;
            }
            $sumPos = $rowWidth;
            $rowWidth += 80;
            $pdf = $this->pdf;
            $pdf->SetFont('Helvetica', 'B', 8);
            $pdf->line($pdf->getX() + $sumPos, $pdf->getY(), $pdf->getX() + $rowWidth, $pdf->getY());
            $pdf->setY($pdf->getY() + 1);
            $pdf->Cell($sumPos, 4, $GLOBALS['locTotal'], 0, 0, 'R');
            $pdf->Cell(20, 4, miscRound2Decim($intTotSum), 0, 0, 'R');
            $pdf->Cell(20, 4, miscRound2Decim($intTotVAT), 0, 0, 'R');
            $pdf->Cell(20, 4, miscRound2Decim($intTotSumVAT), 0, 0, 'R');
            $pdf->Cell(20, 4, miscRound2Decim($totalToPay), 0, 1, 'R');
            if (in_array('vat_breakdown', $printFields)) {
                if ($pdf->getY() > $pdf->getPageHeight() - 30) {
                    $pdf->AddPage();
                } else {
                    $pdf->setY($pdf->getY() + 4);
                }
                $pdf->setY($pdf->getY() + 4);
                $pdf->Cell(15, 4, $GLOBALS['locVATBreakdown'], 0, 0, 'R');
                $pdf->Cell(25, 4, $GLOBALS['locVATLess'], 0, 0, 'R');
                $pdf->Cell(25, 4, $GLOBALS['locVATPart'], 0, 0, 'R');
                $pdf->Cell(25, 4, $GLOBALS['locWithVAT'], 0, 1, 'R');
                $pdf->SetFont('Helvetica', '', 8);
                foreach ($totalsPerVAT as $vat => $sums) {
                    $pdf->Cell(15, 4, miscRound2OptDecim($vat) . '%', 0, 0, 'R');
                    $pdf->Cell(25, 4, miscRound2Decim($sums['sum']), 0, 0, 'R');
                    $pdf->Cell(25, 4, miscRound2Decim($sums['VAT']), 0, 0, 'R');
                    $pdf->Cell(25, 4, miscRound2Decim($sums['sumVAT']), 0, 1, 'R');
                }
            }
            return;
        }
        $colSpan = 0;
        if (in_array('invoice_no', $printFields)) {
            ++$colSpan;
        }
        if (in_array('invoice_date', $printFields)) {
            ++$colSpan;
        }
        if (in_array('due_date', $printFields)) {
            ++$colSpan;
        }
        if (in_array('payment_date', $printFields)) {
            ++$colSpan;
        }
        if (in_array('company_name', $printFields)) {
            ++$colSpan;
        }
        if (in_array('status', $printFields)) {
            ++$colSpan;
        }
        if (in_array('ref_number', $printFields)) {
            ++$colSpan;
        }
        ?>
    <tr>
    <?php 
        if ($colSpan > 0) {
            ?>
        <td class="input total_sum" colspan="<?php 
            echo $colSpan;
            ?>
"
				style="text-align: right">
            <?php 
            echo $GLOBALS['locTotal'];
            ?>
        </td>
    <?php 
        }
        ?>
        <td class="input total_sum" style="text-align: right">
            &nbsp;<?php 
        echo miscRound2Decim($intTotSum);
        ?>
        </td>
        <td class="input total_sum" style="text-align: right">
            &nbsp;<?php 
        echo miscRound2Decim($intTotVAT);
        ?>
        </td>
        <td class="input total_sum" style="text-align: right">
            &nbsp;<?php 
        echo miscRound2Decim($intTotSumVAT);
        ?>
        </td>
        <td class="input total_sum" style="text-align: right">
            &nbsp;<?php 
        echo miscRound2Decim($totalToPay);
        ?>
        </td>
    </tr>
<?php 
        if (in_array('vat_breakdown', $printFields)) {
            ?>
    </table>
    <table>
        <tr>
            <th class="label" style="text-align: right"><?php 
            echo $GLOBALS['locVATBreakdown'];
            ?>
</th>
            <th class="label" style="text-align: right"><?php 
            echo $GLOBALS['locVATLess'];
            ?>
</th>
            <th class="label" style="text-align: right"><?php 
            echo $GLOBALS['locVATPart'];
            ?>
</th>
            <th class="label" style="text-align: right"><?php 
            echo $GLOBALS['locWithVAT'];
            ?>
</th>
        </tr>
<?php 
            foreach ($totalsPerVAT as $vat => $sums) {
                ?>
        <tr>
            <td class="input" style="text-align: right"><?php 
                echo miscRound2OptDecim($vat);
                ?>
%</td>
            <td class="input" style="text-align: right"><?php 
                echo miscRound2Decim($sums['sum']);
                ?>
</td>
            <td class="input" style="text-align: right"><?php 
                echo miscRound2Decim($sums['VAT']);
                ?>
</td>
            <td class="input" style="text-align: right"><?php 
                echo miscRound2Decim($sums['sumVAT']);
                ?>
</td>
        </tr>
<?php 
            }
        }
    }