Ejemplo n.º 1
0
    private function printRow($format, $printFields, $row, $intRowSum, $intRowVAT, $intRowSumVAT)
    {
        if ($format == 'pdf' || $format == 'pdfl') {
            $pdf = $this->pdf;
            $pdf->SetFont('Helvetica', '', 8);
            $pdf->setY($pdf->getY() + 1);
            if (in_array('invoice_no', $printFields)) {
                $pdf->Cell(18, 4, $row['invoice_no'], 0, 0, 'L');
            }
            if (in_array('invoice_date', $printFields)) {
                $pdf->Cell(20, 4, dateConvDBDate2Date($row['invoice_date']), 0, 0, 'L');
            }
            if (in_array('due_date', $printFields)) {
                $pdf->Cell(20, 4, dateConvDBDate2Date($row['due_date']), 0, 0, 'L');
            }
            if (in_array('payment_date', $printFields)) {
                $pdf->Cell(20, 4, dateConvDBDate2Date($row['payment_date']), 0, 0, 'L');
            }
            if (in_array('company_name', $printFields)) {
                $nameX = $pdf->getX();
                $pdf->setX($nameX + 45);
            }
            if (in_array('status', $printFields)) {
                $pdf->Cell(20, 4, isset($GLOBALS['loc' . $row['state']]) ? $GLOBALS['loc' . $row['state']] : $row['state'], 0, 0, 'L');
            }
            if (in_array('ref_number', $printFields)) {
                $pdf->Cell(25, 4, formatRefNumber($row['ref_number']), 0, 0, 'L');
            }
            if (in_array('sums', $printFields)) {
                $pdf->Cell(25, 4, miscRound2Decim($intRowSum), 0, 0, 'R');
                $pdf->Cell(25, 4, miscRound2Decim($intRowVAT), 0, 0, 'R');
                $pdf->Cell(25, 4, miscRound2Decim($intRowSumVAT), 0, 0, 'R');
            }
            // Print company name last, as it can span multiple lines
            if (in_array('company_name', $printFields)) {
                $pdf->setX($nameX);
                $pdf->MultiCell(45, 4, $row['name'], 0, 'L');
            }
            return;
        }
        ?>
    <tr>
      <?php 
        if (in_array('invoice_no', $printFields)) {
            ?>
        <td class="input">
            <?php 
            echo htmlspecialchars($row['invoice_no']);
            ?>
        </td>
      <?php 
        }
        if (in_array('invoice_date', $printFields)) {
            ?>
        <td class="input">
            <?php 
            echo htmlspecialchars(dateConvDBDate2Date($row['invoice_date']));
            ?>
        </td>
      <?php 
        }
        if (in_array('due_date', $printFields)) {
            ?>
        <td class="input">
            <?php 
            echo htmlspecialchars(dateConvDBDate2Date($row['due_date']));
            ?>
        </td>
      <?php 
        }
        if (in_array('payment_date', $printFields)) {
            ?>
        <td class="input">
            <?php 
            echo htmlspecialchars(dateConvDBDate2Date($row['payment_date']));
            ?>
        </td>
      <?php 
        }
        if (in_array('company_name', $printFields)) {
            ?>
        <td class="input">
            <?php 
            echo htmlspecialchars($row['name']);
            ?>
        </td>
      <?php 
        }
        if (in_array('status', $printFields)) {
            ?>
        <td class="input">
            <?php 
            echo htmlspecialchars(isset($GLOBALS['loc' . $row['state']]) ? $GLOBALS['loc' . $row['state']] : $row['state']);
            ?>
        </td>
      <?php 
        }
        if (in_array('ref_number', $printFields)) {
            ?>
        <td class="input">
            <?php 
            echo htmlspecialchars(formatRefNumber($row['ref_number']));
            ?>
        </td>
      <?php 
        }
        if (in_array('sums', $printFields)) {
            ?>
        <td class="input" style="text-align: right">
            <?php 
            echo miscRound2Decim($intRowSum);
            ?>
        </td>
        <td class="input" style="text-align: right">
            <?php 
            echo miscRound2Decim($intRowVAT);
            ?>
        </td>
        <td class="input" style="text-align: right">
            <?php 
            echo miscRound2Decim($intRowSumVAT);
            ?>
        </td>
      <?php 
        }
        ?>
      </tr>
<?php 
    }
Ejemplo n.º 2
0
 public function init($invoiceId, $printParameters, $outputFileName, $senderData, $recipientData, $invoiceData, $invoiceRowData)
 {
     $this->invoiceId = $invoiceId;
     $parameters = explode(',', $printParameters);
     $this->printStyle = $parameters[0];
     $this->printLanguage = isset($parameters[1]) ? $parameters[1] : 'fi';
     $this->printVirtualBarcode = isset($parameters[2]) ? $parameters[2] == 'Y' : false;
     $this->outputFileName = $outputFileName;
     $this->senderData = $senderData;
     $this->recipientData = $recipientData;
     $this->invoiceData = $invoiceData;
     $this->invoiceRowData = $invoiceRowData;
     initInvoicePDFLocalizations($this->printLanguage);
     $this->totalSum = 0;
     $this->totalVAT = 0;
     $this->totalSumVAT = 0;
     $this->discountedRows = false;
     $this->partialPayments = 0;
     foreach ($this->invoiceRowData as $key => $row) {
         if ($row['partial_payment']) {
             $this->partialPayments -= $row['price'];
             continue;
         }
         list($rowSum, $rowVAT, $rowSumVAT) = calculateRowSum($row['price'], $row['pcs'], $row['vat'], $row['vat_included'], $row['discount']);
         $this->invoiceRowData[$key]['rowsum'] = $rowSum;
         $this->invoiceRowData[$key]['rowvat'] = $rowVAT;
         $this->invoiceRowData[$key]['rowsumvat'] = $rowSumVAT;
         $this->totalSum += $rowSum;
         $this->totalVAT += $rowVAT;
         $this->totalSumVAT += $rowSumVAT;
         if (isset($row['discount']) && $row['discount'] > 0) {
             $this->discountedRows = true;
         }
         // Create array grouped by the VAT base
         $vat = 'vat' . number_format($row['vat'], 2, '', '');
         if (isset($this->groupedVATs[$vat])) {
             $this->groupedVATs[$vat]['totalsum'] += $rowSum;
             $this->groupedVATs[$vat]['totalvat'] += $rowVAT;
             $this->groupedVATs[$vat]['totalsumvat'] += $rowSumVAT;
         } else {
             $this->groupedVATs[$vat]['vat'] = $row['vat'];
             $this->groupedVATs[$vat]['totalsum'] = $rowSum;
             $this->groupedVATs[$vat]['totalvat'] = $rowVAT;
             $this->groupedVATs[$vat]['totalsumvat'] = $rowSumVAT;
         }
     }
     $this->separateStatement = $this->printStyle == 'invoice' && getSetting('invoice_separate_statement');
     $this->senderAddressLine = $senderData['name'];
     $strCompanyID = trim($senderData['company_id']);
     if ($strCompanyID) {
         $strCompanyID = $GLOBALS['locPDFVATID'] . ": {$strCompanyID}";
     }
     if ($strCompanyID) {
         $strCompanyID .= ', ';
     }
     if ($senderData['vat_registered']) {
         $strCompanyID .= $GLOBALS['locPDFVATReg'];
     } else {
         $strCompanyID .= $GLOBALS['locPDFNonVATReg'];
     }
     if ($strCompanyID) {
         $this->senderAddressLine .= " ({$strCompanyID})";
     }
     $this->senderAddressLine .= "\n" . $senderData['street_address'];
     if ($senderData['street_address'] && ($senderData['zip_code'] || $senderData['city'])) {
         $this->senderAddressLine .= ', ';
     }
     if ($senderData['zip_code']) {
         $this->senderAddressLine .= $senderData['zip_code'] . ' ';
     }
     $this->senderAddressLine .= $senderData['city'];
     if ($senderData['country'] && $this->senderAddressLine) {
         $this->senderAddressLine .= ', ';
     }
     $this->senderAddressLine .= $senderData['country'];
     $this->senderAddress = $senderData['name'] . "\n" . $senderData['street_address'] . "\n" . $senderData['zip_code'] . ' ' . $senderData['city'];
     if ($senderData['country'] && $this->senderAddress) {
         $this->senderAddress .= ', ';
     }
     $this->senderAddress .= $senderData['country'];
     if ($senderData['phone']) {
         $this->senderContactInfo = "\n" . $GLOBALS['locPDFPhone'] . ' ' . $senderData['phone'];
     } else {
         $this->senderContactInfo = '';
     }
     if ($invoiceData['ref_number'] && strlen($invoiceData['ref_number']) < 4) {
         error_log('Reference number too short, will not be displayed');
         $invoiceData['ref_number'] = '';
     }
     $this->refNumber = formatRefNumber($invoiceData['ref_number']);
     $this->recipientFullAddress = $recipientData['company_name'] . "\n" . $recipientData['street_address'] . "\n" . $recipientData['zip_code'] . ' ' . $recipientData['city'];
     $this->billingAddress = $recipientData['billing_address'];
     if (!$this->billingAddress || $this->printStyle != 'invoice' || ($invoiceData['state_id'] == 5 || $invoiceData['state_id'] == 6) && !getSetting('invoice_send_reminder_to_invoicing_address')) {
         $this->billingAddress = $this->recipientFullAddress;
     }
     $addressParts = explode("\n", $this->billingAddress, 2);
     $this->recipientName = isset($addressParts[0]) ? $addressParts[0] : '';
     $this->recipientAddress = isset($addressParts[1]) ? $addressParts[1] : '';
     // barcode
     /*
      * 1 Barcode version, this is version 4 or 5
      * 1 Currency (1=FIM, 2=EURO)
      * 16 IBAN without leading country code
      * 6 Euros
      * 2 Cents
      * 3 Spares, contain zeros
      * 20 Reference Number
      * 6 Due Date. Format is YYMMDD.
      */
     $this->barcode = '';
     $paymentAmount = $this->totalSumVAT - $this->partialPayments;
     if ($paymentAmount > 0) {
         $tmpRefNumber = str_replace(' ', '', $this->refNumber);
         $IBAN = str_replace(' ', '', substr($senderData['bank_iban'], 2));
         if (intval($tmpRefNumber) == 0 || strncmp($tmpRefNumber, 'RF', 2) == 0 && intval(substr($tmpRefNumber, 2) == 0)) {
             error_log('Empty or invalid reference number "' . $tmpRefNumber . '", barcode not created');
         } elseif (strlen($IBAN) != 16) {
             error_log('IBAN length invalid (should be 16 numbers without leading country code and spaces), barcode not created');
         } elseif (strlen($invoiceData['due_date']) != 8) {
             error_log('Invalid due date \'' . $invoiceData['due_date'] . '\' - barcode not created');
         } elseif ($paymentAmount >= 1000000) {
             error_log('Invoice total too large, barcode not created');
         } else {
             $tmpSum = miscRound2Decim($paymentAmount, 2, '', '');
             $tmpSum = str_repeat('0', 8 - strlen($tmpSum)) . $tmpSum;
             $tmpDueDate = substr($invoiceData['due_date'], 2);
             if (strncmp($tmpRefNumber, 'RF', 2) == 0) {
                 $checkDigits = substr($tmpRefNumber, 2, 2);
                 $tmpRefNumber = substr($tmpRefNumber, 4);
                 $tmpRefNumber = $checkDigits . str_repeat('0', 21 - strlen($tmpRefNumber)) . $tmpRefNumber;
                 $this->barcode = '5' . $IBAN . $tmpSum . $tmpRefNumber . $tmpDueDate;
             } else {
                 $tmpRefNumber = str_repeat('0', 20 - strlen($tmpRefNumber)) . $tmpRefNumber;
                 $this->barcode = '4' . $IBAN . $tmpSum . '000' . $tmpRefNumber . $tmpDueDate;
             }
         }
     }
     $this->addressXOffset = getSetting('invoice_address_x_offset', 0);
     $this->addressYOffset = getSetting('invoice_address_y_offset', 0);
 }