Exemplo n.º 1
0
function addReminderFees($intInvoiceId)
{
    $strAlert = '';
    $strQuery = 'SELECT inv.due_date, inv.state_id, inv.print_date ' . 'FROM {prefix}invoice inv ' . 'WHERE inv.id = ?';
    $intRes = mysqli_param_query($strQuery, [$intInvoiceId]);
    if ($row = mysqli_fetch_assoc($intRes)) {
        $intStateId = $row['state_id'];
        $strDueDate = dateConvDBDate2Date($row['due_date']);
        $strPrintDate = $row['print_date'];
    } else {
        return $GLOBALS['locRecordNotFound'];
    }
    $intDaysOverdue = floor((time() - strtotime($strDueDate)) / 60 / 60 / 24);
    if ($intDaysOverdue <= 0) {
        $strAlert = addslashes($GLOBALS['locInvoiceNotOverdue']);
    } elseif ($intStateId == 3 || $intStateId == 4) {
        $strAlert = addslashes($GLOBALS['locWrongStateForReminderFee']);
    } else {
        // Update invoice state
        if ($intStateId == 1 || $intStateId == 2) {
            $intStateId = 5;
        } elseif ($intStateId == 5) {
            $intStateId = 6;
        }
        mysqli_param_query('UPDATE {prefix}invoice SET state_id=? where id=?', [$intStateId, $intInvoiceId]);
        // Add reminder fee
        if (getSetting('invoice_notification_fee')) {
            // Remove old fee from same day
            mysqli_param_query('UPDATE {prefix}invoice_row SET deleted=1 WHERE invoice_id=? AND reminder_row=2 AND row_date = ?', [$intInvoiceId, date('Ymd')]);
            $strQuery = 'INSERT INTO {prefix}invoice_row (invoice_id, description, pcs, price, row_date, vat, vat_included, order_no, reminder_row) ' . 'VALUES (?, ?, 1, ?, ?, 0, 0, -2, 2)';
            mysqli_param_query($strQuery, [$intInvoiceId, $GLOBALS['locReminderFeeDesc'], getSetting('invoice_notification_fee'), date('Ymd')]);
        }
        // Add penalty interest
        $penaltyInterest = getSetting('invoice_penalty_interest');
        if ($penaltyInterest) {
            // Remove old penalty interest
            mysqli_param_query('UPDATE {prefix}invoice_row SET deleted=1 WHERE invoice_id=? AND reminder_row=1', [$intInvoiceId]);
            // Add new interest
            $intTotSumVAT = 0;
            $strQuery = 'SELECT ir.pcs, ir.price, ir.discount, ir.vat, ir.vat_included, ir.reminder_row ' . 'FROM {prefix}invoice_row ir ' . 'WHERE ir.deleted=0 AND ir.invoice_id=?';
            $intRes = mysqli_param_query($strQuery, [$intInvoiceId]);
            while ($row = mysqli_fetch_assoc($intRes)) {
                if ($row['reminder_row']) {
                    continue;
                }
                list($rowSum, $rowVAT, $rowSumVAT) = calculateRowSum($row['price'], $row['pcs'], $row['vat'], $row['vat_included'], $row['discount']);
                $intTotSumVAT += $rowSumVAT;
            }
            $intPenalty = $intTotSumVAT * $penaltyInterest / 100 * $intDaysOverdue / 360;
            $strQuery = 'INSERT INTO {prefix}invoice_row (invoice_id, description, pcs, price, discount, row_date, vat, vat_included, order_no, reminder_row) ' . 'VALUES (?, ?, 1, ?, 0, ?, 0, 0, -1, 1)';
            mysqli_param_query($strQuery, [$intInvoiceId, $GLOBALS['locPenaltyInterestDesc'], $intPenalty, date('Ymd')]);
        }
    }
    return $strAlert;
}
Exemplo n.º 2
0
 private function printReport()
 {
     $intBaseId = getRequest('base', false);
     $intCompanyId = getRequest('company', false);
     $grouping = getRequest('grouping', '');
     $format = getRequest('format', 'html');
     $printFields = getRequest('fields', array());
     $rowTypes = getRequest('row_types', 'all');
     $dateRange = explode(' - ', getRequest('date', ''));
     $startDate = $dateRange[0];
     $endDate = isset($dateRange[1]) ? $dateRange[1] : $startDate;
     if ($startDate) {
         $startDate = dateConvDate2DBDate($startDate);
     }
     if ($endDate) {
         $endDate = dateConvDate2DBDate($endDate);
     }
     $rowDateRange = explode(' - ', getRequest('row_date', ''));
     $rowStartDate = $rowDateRange[0];
     $rowEndDate = isset($rowDateRange[1]) ? $rowDateRange[1] : $rowStartDate;
     if ($rowStartDate) {
         $rowStartDate = dateConvDate2DBDate($rowStartDate);
     }
     if ($rowEndDate) {
         $rowEndDate = dateConvDate2DBDate($rowEndDate);
     }
     $paymentDateRange = explode(' - ', getRequest('payment_date', ''));
     $paymentStartDate = $paymentDateRange[0];
     $paymentEndDate = isset($paymentDateRange[1]) ? $paymentDateRange[1] : '';
     if ($paymentStartDate) {
         $paymentStartDate = dateConvDate2DBDate($paymentStartDate);
     }
     if ($paymentEndDate) {
         $paymentEndDate = dateConvDate2DBDate($paymentEndDate);
     }
     $arrParams = array();
     $strQuery = "SELECT i.id, i.invoice_no, i.invoice_date, i.due_date, i.payment_date, i.ref_number, i.ref_number, c.company_name AS name, c.billing_address, ist.name as state " . "FROM {prefix}invoice i " . "LEFT OUTER JOIN {prefix}company c ON c.id = i.company_id " . "LEFT OUTER JOIN {prefix}invoice_state ist ON i.state_id = ist.id " . "WHERE i.deleted=0";
     if ($startDate) {
         $strQuery .= ' AND i.invoice_date >= ?';
         $arrParams[] = $startDate;
     }
     if ($endDate) {
         $strQuery .= ' AND i.invoice_date <= ?';
         $arrParams[] = $endDate;
     }
     if ($paymentStartDate) {
         $strQuery .= ' AND i.payment_date >= ?';
         $arrParams[] = $paymentStartDate;
     }
     if ($paymentEndDate) {
         $strQuery .= ' AND i.payment_date <= ?';
         $arrParams[] = $paymentEndDate;
     }
     if ($intBaseId) {
         $strQuery .= ' AND i.base_id = ?';
         $arrParams[] = $intBaseId;
     }
     if ($intCompanyId) {
         $strQuery .= ' AND i.company_id = ?';
         $arrParams[] = $intCompanyId;
     }
     $strQuery2 = '';
     $strQuery3 = "SELECT id, name " . "FROM {prefix}invoice_state WHERE deleted=0 " . "ORDER BY order_no";
     $intRes = mysqli_query_check($strQuery3);
     while ($row = mysqli_fetch_assoc($intRes)) {
         $intStateId = $row['id'];
         $strStateName = $row['name'];
         $strTemp = "stateid_{$intStateId}";
         $tmpSelected = getRequest($strTemp, false);
         if ($tmpSelected) {
             $strQuery2 .= 'i.state_id = ? OR ';
             $arrParams[] = $intStateId;
         }
     }
     if ($strQuery2) {
         $strQuery2 = ' AND (' . substr($strQuery2, 0, -4) . ')';
     }
     $strQuery .= "{$strQuery2} ORDER BY ";
     switch ($grouping) {
         case 'state':
             $strQuery .= "state_id, invoice_date, invoice_no";
             break;
         case 'client':
             $strQuery .= "name, invoice_date, invoice_no";
             break;
         default:
             $strQuery .= "invoice_date, invoice_no";
     }
     $this->printHeader($format, $printFields, $startDate, $endDate);
     $intTotSum = 0;
     $intTotVAT = 0;
     $intTotSumVAT = 0;
     $currentGroup = false;
     $groupTotSum = 0;
     $groupTotVAT = 0;
     $groupTotSumVAT = 0;
     $intRes = mysqli_param_query($strQuery, $arrParams);
     while ($row = mysqli_fetch_assoc($intRes)) {
         switch ($grouping) {
             case 'state':
                 $invoiceGroup = $row['state'];
                 break;
             case 'month':
                 $invoiceGroup = substr($row['invoice_date'], 4, 2);
                 break;
             case 'client':
                 $invoiceGroup = $row['name'];
                 break;
             default:
                 $invoiceGroup = false;
         }
         $rowParams = array($row['id']);
         $strQuery = "SELECT ir.description, ir.pcs, ir.price, ir.discount, ir.row_date, ir.vat, ir.vat_included " . "FROM {prefix}invoice_row ir " . "WHERE ir.invoice_id=? AND ir.deleted=0";
         if ($rowStartDate) {
             $strQuery .= ' AND ir.row_date >= ?';
             $rowParams[] = $rowStartDate;
         }
         if ($rowEndDate) {
             $strQuery .= ' AND ir.row_date <= ?';
             $rowParams[] = $rowEndDate;
         }
         if ($rowTypes != 'all') {
             if ($rowTypes == 'normal') {
                 $strQuery .= ' AND ir.reminder_row = 0';
             } else {
                 if ($rowTypes == 'reminder') {
                     $strQuery .= ' AND ir.reminder_row in (1, 2)';
                 }
             }
         }
         $intRes2 = mysqli_param_query($strQuery, $rowParams);
         $intRowSum = 0;
         $intRowVAT = 0;
         $intRowSumVAT = 0;
         $rows = false;
         while ($row2 = mysqli_fetch_assoc($intRes2)) {
             $rows = true;
             list($intSum, $intVAT, $intSumVAT) = calculateRowSum($row2['price'], $row2['pcs'], $row2['vat'], $row2['vat_included'], $row2['discount']);
             $intRowSum += $intSum;
             $intRowVAT += $intVAT;
             $intRowSumVAT += $intSumVAT;
             $intTotSum += $intSum;
             $intTotVAT += $intVAT;
             $intTotSumVAT += $intSumVAT;
         }
         if (!$rows) {
             continue;
         }
         if ($grouping && $currentGroup !== false && $currentGroup != $invoiceGroup) {
             $this->printGroupSums($format, $printFields, $row, $groupTotSum, $groupTotVAT, $groupTotSumVAT);
             $groupTotSum = 0;
             $groupTotVAT = 0;
             $groupTotSumVAT = 0;
         }
         $currentGroup = $invoiceGroup;
         $groupTotSum += $intRowSum;
         $groupTotVAT += $intRowVAT;
         $groupTotSumVAT += $intRowSumVAT;
         $this->printRow($format, $printFields, $row, $intRowSum, $intRowVAT, $intRowSumVAT);
     }
     if ($grouping) {
         $this->printGroupSums($format, $printFields, $row, $groupTotSum, $groupTotVAT, $groupTotSumVAT);
     }
     $this->printTotals($format, $printFields, $intTotSum, $intTotVAT, $intTotSumVAT);
     $this->printFooter($format, $printFields);
 }
Exemplo n.º 3
0
    protected function process_import_row($table, $row, $dupMode, $dupCheckColumns, $mode, &$addedRecordId)
    {
        if (!isset($row['date']) || !isset($row['amount']) || !isset($row['refnr'])) {
            return $GLOBALS['locImportStatementFieldMissing'];
        }
        $refnr = str_replace(' ', '', $row['refnr']);
        $refnr = ltrim($refnr, '0');
        $date = date('Ymd', DateTime::createFromFormat(getRequest('date_format', 'd.m.Y'), $row['date'])->getTimestamp());
        $amount = trim($row['amount']);
        if (substr($amount, 0, 1) == '-') {
            return;
        }
        if (substr($amount, 0, 1) == '+') {
            $amount = substr($amount, 1);
        }
        $sep = getRequest('decimal_separator', ',');
        if ($sep == ' ' || $sep == ',') {
            $amount = str_replace('.', '', $amount);
            $amount = str_replace($sep, '.', $amount);
        } elseif ($sep == '.') {
            $amount = str_replace(',', '', $amount);
        }
        $amount = floatval($amount);
        if ($row['refnr'] === '') {
            return $GLOBALS['locImportStatementFieldMissing'];
        }
        $sql = 'SELECT i.* FROM {prefix}invoice i' . ' WHERE i.Deleted=0 AND REPLACE(i.ref_number, " ", "") = ?';
        $params = [$refnr];
        $baseId = getRequest('base_id', '');
        if ($baseId) {
            $sql .= ' AND i.base_id = ?';
            $params[] = $baseId;
        }
        $intRes = mysqli_param_query($sql, $params);
        $count = mysqli_num_rows($intRes);
        if ($count == 0) {
            return str_replace('{refnr}', $refnr, $GLOBALS['locImportStatementInvoiceNotFound']);
        }
        if ($count > 1) {
            return str_replace('{refnr}', $refnr, $GLOBALS['locImportStatementMultipleInvoicesFound']);
        }
        $row = mysqli_fetch_assoc($intRes);
        if ($row['state_id'] == 3) {
            return str_replace('{refnr}', $refnr, $GLOBALS['locImportStatementInvoiceAlreadyPaid']);
        }
        $res2 = mysqli_param_query('SELECT ir.price, ir.pcs, ir.vat, ir.vat_included, ir.discount, ir.partial_payment from {prefix}invoice_row ir where ir.deleted = 0 AND ir.invoice_id = ?', [$row['id']]);
        $rowTotal = 0;
        $partialPayments = 0;
        while ($invoiceRow = mysqli_fetch_assoc($res2)) {
            if ($invoiceRow['partial_payment']) {
                $partialPayments += $invoiceRow['price'];
            }
            list($rowSum, $rowVAT, $rowSumVAT) = calculateRowSum($invoiceRow['price'], $invoiceRow['pcs'], $invoiceRow['vat'], $invoiceRow['vat_included'], $invoiceRow['discount']);
            $rowTotal += $rowSumVAT;
        }
        $totalToPay = $rowTotal + $partialPayments;
        if (miscRound2Decim($totalToPay) != miscRound2Decim($amount)) {
            if (getRequest('partial_payments', false) && miscRound2Decim($totalToPay) > miscRound2Decim($amount)) {
                if ($mode == 'import') {
                    $sql = <<<EOT
INSERT INTO {prefix}invoice_row
    (invoice_id, description, pcs, price, row_date, order_no, partial_payment)
    VALUES (?, ?, 0, ?, ?, 100000, 1)
EOT;
                    mysqli_param_query($sql, [$row['id'], $GLOBALS['locPartialPayment'], -$amount, $date]);
                }
                $msg = str_replace('{statementAmount}', miscRound2Decim($amount), $GLOBALS['locImportStatementPartialPayment']);
                $msg = str_replace('{invoiceAmount}', miscRound2Decim($totalToPay), $msg);
                $msg = str_replace('{id}', $row['id'], $msg);
                $msg = str_replace('{date}', dateConvDBDate2Date($date), $msg);
                $msg = str_replace('{refnr}', $refnr, $msg);
                return $msg;
            } else {
                $msg = str_replace('{statementAmount}', miscRound2Decim($amount), $GLOBALS['locImportStatementAmountMismatch']);
                $msg = str_replace('{invoiceAmount}', miscRound2Decim($totalToPay), $msg);
                $msg = str_replace('{refnr}', $refnr, $msg);
                return $msg;
            }
        }
        $archive = $row['interval_type'] == 0 && getRequest('archive', '');
        if ($mode == 'import') {
            $sql = 'UPDATE {prefix}invoice SET state_id=3, payment_date=?';
            if ($archive) {
                $sql .= ', archived=1';
            }
            $sql .= ' WHERE id = ?';
            mysqli_param_query($sql, [$date, $row['id']]);
        }
        $msg = str_replace('{amount}', miscRound2Decim($amount), $archive ? $GLOBALS['locImportStatementInvoiceMarkedAsPaidAndArchived'] : $GLOBALS['locImportStatementInvoiceMarkedAsPaid']);
        $msg = str_replace('{id}', $row['id'], $msg);
        $msg = str_replace('{date}', dateConvDBDate2Date($date), $msg);
        $msg = str_replace('{refnr}', $refnr, $msg);
        return $msg;
    }
 protected function printRows()
 {
     $pdf = $this->pdf;
     $invoiceData = $this->invoiceData;
     $pdf->printFooterOnFirstPage = true;
     $pdf->SetAutoPageBreak(true, 22);
     $left = 10;
     $nameColWidth = $this->discountedRows ? 98 : 110;
     $pdf->Cell($nameColWidth, 5, $GLOBALS['locPDFRowName'], 0, 0, 'L');
     $pdf->Cell(20, 5, $GLOBALS['locPDFOrderConfirmationRowDate'], 0, 0, 'L');
     $pdf->Cell(17, 5, $GLOBALS['locPDFRowPrice'], 0, 0, 'R');
     if ($this->discountedRows) {
         $pdf->Cell(12, 5, $GLOBALS['locPDFRowDiscount'], 0, 0, 'R');
     }
     $pdf->Cell(20, 5, $GLOBALS['locPDFRowPieces'], 0, 0, 'R');
     $pdf->Cell(20, 5, $GLOBALS['locPDFRowTotal'], 0, 1, 'R');
     $pdf->Cell(20, 5, '', 0, 1, 'R');
     // line feed
     foreach ($this->invoiceRowData as $row) {
         // Product / description
         $description = '';
         switch ($row['reminder_row']) {
             case 1:
                 $description = $GLOBALS['locPDFPenaltyInterestDesc'];
                 break;
             case 2:
                 $description = $GLOBALS['locPDFReminderFeeDesc'];
                 break;
             default:
                 if ($row['product_name']) {
                     if ($row['description']) {
                         $description = $row['product_name'] . ' (' . $row['description'] . ')';
                     } else {
                         $description = $row['product_name'];
                     }
                     if (getSetting('invoice_display_product_codes') && $row['product_code']) {
                         $description = $row['product_code'] . ' ' . $description;
                     }
                 } else {
                     $description = $row['description'];
                 }
         }
         // Sums
         list($rowSum, $rowVAT, $rowSumVAT) = calculateRowSum($row['price'], $row['pcs'], $row['vat'], $row['vat_included'], $row['discount']);
         if ($row['vat_included']) {
             $row['price'] /= 1 + $row['vat'] / 100;
         }
         if ($row['price'] == 0 && $row['pcs'] == 0) {
             $pdf->SetX($left);
             $pdf->MultiCell(0, 5, $description, 0, 'L');
         } else {
             $pdf->SetX($nameColWidth + $left);
             $pdf->Cell(20, 5, $this->_formatDate($row['row_date']), 0, 0, 'L');
             $decimals = isset($row['price_decimals']) ? $row['price_decimals'] : 2;
             $pdf->Cell(17, 5, $this->_formatCurrency($row['price'], $decimals), 0, 0, 'R');
             if ($this->discountedRows) {
                 $pdf->Cell(12, 5, isset($row['discount']) && $row['discount'] != '0' ? $this->_formatCurrency($row['discount'], 2, true) : '', 0, 0, 'R');
             }
             $pdf->Cell(13, 5, $this->_formatNumber($row['pcs'], 2, true), 0, 0, 'R');
             $pdf->Cell(7, 5, isset($GLOBALS["locPDF{$row['type']}"]) ? $GLOBALS["locPDF{$row['type']}"] : $row['type'], 0, 0, 'L');
             $pdf->Cell(20, 5, $this->_formatCurrency($rowSum), 0, 0, 'R');
             $pdf->SetX($left);
             $pdf->MultiCell($nameColWidth, 5, $description, 0, 'L');
         }
     }
     if ($this->printStyle != 'dispatch') {
         if ($this->senderData['vat_registered']) {
             $pdf->SetFont('Helvetica', '', 10);
             $pdf->SetY($pdf->GetY() + 10);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalExcludingVAT'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSum), 0, 0, 'R');
             $pdf->SetFont('Helvetica', '', 10);
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalVAT'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalVAT), 0, 0, 'R');
             $pdf->SetFont('Helvetica', 'B', 10);
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalIncludingVAT'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSumVAT), 0, 1, 'R');
             $pdf->SetFont('Helvetica', '', 10);
         } else {
             $pdf->SetFont('Helvetica', 'B', 10);
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalPrice'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSumVAT), 0, 1, 'R');
             $pdf->SetFont('Helvetica', '', 10);
         }
     }
     $terms = getSetting('order_confirmation_terms');
     if ($terms) {
         $pdf->SetY($pdf->GetY() + 10);
         $pdf->MultiCell(187, 4, $terms, 0, 'L', 0);
     }
 }
Exemplo n.º 5
0
 private function printReport()
 {
     $intStateID = getRequest('stateid', FALSE);
     $intBaseId = getRequest('base', FALSE);
     $intCompanyId = getRequest('company', FALSE);
     $intProductId = getRequest('product', FALSE);
     $format = getRequest('format', 'html');
     $dateRange = explode(' - ', getRequest('date', ''));
     $startDate = $dateRange[0];
     $endDate = isset($dateRange[1]) ? $dateRange[1] : $startDate;
     if ($startDate) {
         $startDate = dateConvDate2DBDate($startDate);
     }
     if ($endDate) {
         $endDate = dateConvDate2DBDate($endDate);
     }
     $arrParams = [];
     $strQuery = 'SELECT i.id ' . 'FROM {prefix}invoice i ' . 'WHERE i.deleted=0';
     if ($startDate) {
         $strQuery .= ' AND i.invoice_date >= ?';
         $arrParams[] = $startDate;
     }
     if ($endDate) {
         $strQuery .= ' AND i.invoice_date <= ?';
         $arrParams[] = $endDate;
     }
     if ($intBaseId) {
         $strQuery .= ' AND i.base_id = ?';
         $arrParams[] = $intBaseId;
     }
     if ($intCompanyId) {
         $strQuery .= ' AND i.company_id = ?';
         $arrParams[] = $intCompanyId;
     }
     $strQuery2 = '';
     $strQuery3 = 'SELECT id, name ' . 'FROM {prefix}invoice_state WHERE deleted=0 ' . 'ORDER BY order_no';
     $intRes = mysqli_query_check($strQuery3);
     while ($row = mysqli_fetch_assoc($intRes)) {
         $intStateId = $row['id'];
         $strStateName = $row['name'];
         $strTemp = "stateid_{$intStateId}";
         $tmpSelected = getRequest($strTemp, FALSE) ? TRUE : FALSE;
         if ($tmpSelected) {
             $strQuery2 .= ' i.state_id = ? OR ';
             $arrParams[] = $intStateId;
         }
     }
     if ($strQuery2) {
         $strQuery2 = ' AND (' . substr($strQuery2, 0, -3) . ')';
     }
     $strQuery .= "{$strQuery2} ORDER BY invoice_no";
     if ($intProductId) {
         $strProductWhere = 'AND ir.product_id = ? ';
         $arrParams[] = $intProductId;
     } else {
         $strProductWhere = '';
     }
     $strProductQuery = 'SELECT p.id, p.product_code, p.product_name, ir.description, ' . 'ir.vat, ir.pcs, t.name as unit, ir.price, ir.vat_included, ir.discount ' . 'FROM {prefix}invoice_row ir ' . 'LEFT OUTER JOIN {prefix}product p ON p.id = ir.product_id ' . 'LEFT OUTER JOIN {prefix}row_type t ON t.id = ir.type_id ' . "WHERE ir.deleted = 0 AND ir.partial_payment = 0 AND ir.invoice_id IN ({$strQuery}) {$strProductWhere}" . 'ORDER BY p.id, ir.description, t.name, ir.vat';
     $this->printHeader($format, $startDate, $endDate);
     $totalSum = 0;
     $totalVAT = 0;
     $totalSumVAT = 0;
     $prevRow = false;
     $productCount = 0;
     $productSum = 0;
     $productVAT = 0;
     $productSumVAT = 0;
     $intRes = mysqli_param_query($strProductQuery, $arrParams);
     while ($row = mysqli_fetch_assoc($intRes)) {
         if ($prevRow !== false && ($prevRow['id'] != $row['id'] || $prevRow['description'] != $row['description'] || $prevRow['unit'] != $row['unit'] || $prevRow['vat'] != $row['vat'])) {
             $this->printRow($format, $prevRow['product_code'], $prevRow['product_name'], $prevRow['description'], $productCount, $prevRow['unit'], $productSum, $prevRow['vat'], $productVAT, $productSumVAT);
             $productCount = 0;
             $productSum = 0;
             $productVAT = 0;
             $productSumVAT = 0;
         }
         $prevRow = $row;
         $productCount += $row['pcs'];
         list($rowSum, $rowVAT, $rowSumVAT) = calculateRowSum($row['price'], $row['pcs'], $row['vat'], $row['vat_included'], $row['discount']);
         $productSum += $rowSum;
         $productVAT += $rowVAT;
         $productSumVAT += $rowSumVAT;
         $totalSum += $rowSum;
         $totalVAT += $rowVAT;
         $totalSumVAT += $rowSumVAT;
     }
     if ($prevRow !== false) {
         $this->printRow($format, $prevRow['product_code'], $prevRow['product_name'], $prevRow['description'], $productCount, $prevRow['unit'], $productSum, $prevRow['vat'], $productVAT, $productSumVAT);
     }
     $this->printTotals($format, $totalSum, $totalVAT, $totalSumVAT);
     $this->printFooter($format);
 }
Exemplo n.º 6
0
 protected function printRows()
 {
     $pdf = $this->pdf;
     $invoiceData = $this->invoiceData;
     if ($this->separateStatement) {
         $pdf->AddPage();
         $pdf->SetAutoPageBreak(TRUE, 22);
         $pdf->SetFont('Helvetica', 'B', 20);
         $pdf->SetXY(4, $pdf->GetY());
         $pdf->Cell(80, 5, $GLOBALS['locPDFInvoiceStatement'], 0, 0, 'L');
         $pdf->SetFont('Helvetica', '', 10);
         $pdf->SetX(115);
         if ($this->printStyle == 'dispatch') {
             $locStr = 'DispatchNote';
         } elseif ($this->printStyle == 'receipt') {
             $locStr = 'Receipt';
         } else {
             $locStr = 'Invoice';
         }
         $pdf->Cell(40, 5, $GLOBALS["locPDF{$locStr}Number"] . ': ', 0, 0, 'R');
         $pdf->Cell(60, 5, $invoiceData['invoice_no'], 0, 1);
         $pdf->SetXY(7, $pdf->GetY() + 10);
     } elseif ($this->printStyle != 'invoice') {
         $pdf->printFooterOnFirstPage = true;
         $pdf->SetAutoPageBreak(TRUE, $this->printStyle == 'receipt' ? 32 : 22);
     }
     if ($this->printStyle == 'dispatch') {
         $nameColWidth = 120;
     } else {
         if ($this->senderData['vat_registered']) {
             $nameColWidth = 80;
         } else {
             $nameColWidth = 130;
         }
     }
     $showDate = getSetting('invoice_show_row_date');
     if ($this->discountedRows) {
         $left = 4;
     } else {
         $left = 10;
     }
     $pdf->SetX($left);
     if ($showDate) {
         $pdf->Cell($nameColWidth - 20, 5, $GLOBALS['locPDFRowName'], 0, 0, 'L');
         $pdf->Cell(20, 5, $GLOBALS['locPDFRowDate'], 0, 0, 'L');
     } else {
         $pdf->Cell($nameColWidth, 5, $GLOBALS['locPDFRowName'], 0, 0, 'L');
     }
     if ($this->printStyle != 'dispatch') {
         $pdf->Cell(17, 5, $GLOBALS['locPDFRowPrice'], 0, 0, 'R');
         if ($this->discountedRows) {
             $pdf->Cell(12, 5, $GLOBALS['locPDFRowDiscount'], 0, 0, 'R');
         }
     }
     $pdf->Cell(20, 5, $GLOBALS['locPDFRowPieces'], 0, 0, 'R');
     if ($this->printStyle != 'dispatch') {
         if ($this->senderData['vat_registered']) {
             $pdf->MultiCell(20, 5, $GLOBALS['locPDFRowTotalVATLess'], 0, 'R', 0, 0);
             $pdf->Cell(15, 5, $GLOBALS['locPDFRowVATPercent'], 0, 0, 'R');
             $pdf->Cell(15, 5, $GLOBALS['locPDFRowTax'], 0, 0, 'R');
         }
         $pdf->Cell(20, 5, $GLOBALS['locPDFRowTotal'], 0, 1, 'R');
     } else {
         $pdf->Cell(20, 5, '', 0, 1, 'R');
         // line feed
     }
     $descMaxHeight = getSetting('invoice_row_description_first_line_only', false) ? 5 : 0;
     $pdf->SetY($pdf->GetY() + 5);
     foreach ($this->invoiceRowData as $row) {
         if (!$this->separateStatement && $this->printStyle == 'invoice' && $pdf->GetY() > $this->invoiceRowMaxY) {
             $this->separateStatement = true;
             $this->printInvoice();
             exit;
         }
         $partial = $row['partial_payment'];
         // Product / description
         $description = '';
         switch ($row['reminder_row']) {
             case 1:
                 $description = $GLOBALS['locPDFPenaltyInterestDesc'];
                 break;
             case 2:
                 $description = $GLOBALS['locPDFReminderFeeDesc'];
                 break;
             default:
                 if ($partial) {
                     $description = $GLOBALS['locPDFPartialPaymentDesc'];
                 } elseif ($row['product_name']) {
                     if ($row['description']) {
                         $description = $row['product_name'] . ' (' . $row['description'] . ')';
                     } else {
                         $description = $row['product_name'];
                     }
                     if (getSetting('invoice_display_product_codes') && $row['product_code']) {
                         $description = $row['product_code'] . ' ' . $description;
                     }
                 } else {
                     $description = $row['description'];
                 }
         }
         // Sums
         if ($partial) {
             $rowSum = $rowSumVAT = $row['price'];
             $rowVAT = 0;
         } else {
             list($rowSum, $rowVAT, $rowSumVAT) = calculateRowSum($row['price'], $row['pcs'], $row['vat'], $row['vat_included'], $row['discount']);
             if ($row['vat_included']) {
                 $row['price'] /= 1 + $row['vat'] / 100;
             }
         }
         if ($row['price'] == 0 && $row['pcs'] == 0) {
             $pdf->SetX($left);
             $pdf->MultiCell(0, 5, $description, 0, 'L', false, 1, '', '', true, 0, false, true, $descMaxHeight);
         } else {
             if ($showDate) {
                 $pdf->SetX($nameColWidth - 20 + $left);
                 $pdf->Cell(20, 5, $this->_formatDate($row['row_date']), 0, 0, 'L');
             } else {
                 $pdf->SetX($nameColWidth + $left);
             }
             if ($this->printStyle != 'dispatch') {
                 $decimals = isset($row['price_decimals']) ? $row['price_decimals'] : 2;
                 $pdf->Cell(17, 5, $partial ? '' : $this->_formatCurrency($row['price'], $decimals), 0, 0, 'R');
                 if ($this->discountedRows) {
                     $pdf->Cell(12, 5, isset($row['discount']) && $row['discount'] != '0' ? $this->_formatCurrency($row['discount'], 2, true) : '', 0, 0, 'R');
                 }
             }
             $pdf->Cell(13, 5, $partial ? '' : $this->_formatNumber($row['pcs'], 2, true), 0, 0, 'R');
             $pdf->Cell(7, 5, isset($GLOBALS["locPDF{$row['type']}"]) ? $GLOBALS["locPDF{$row['type']}"] : $row['type'], 0, 0, 'L');
             if ($this->printStyle != 'dispatch') {
                 if ($this->senderData['vat_registered']) {
                     $pdf->Cell(20, 5, $partial ? '' : $this->_formatCurrency($rowSum), 0, 0, 'R');
                     $pdf->Cell(11, 5, $partial ? '' : $this->_formatNumber($row['vat'], 1, true), 0, 0, 'R');
                     $pdf->Cell(4, 5, '', 0, 0, 'R');
                     $pdf->Cell(15, 5, $partial ? '' : $this->_formatCurrency($rowVAT), 0, 0, 'R');
                 }
                 $pdf->Cell(20, 5, $this->_formatCurrency($rowSumVAT), 0, 0, 'R');
             }
             $pdf->SetX($left);
             if ($showDate) {
                 $pdf->MultiCell($nameColWidth - 20, 5, $description, 0, 'L', false, 1, '', '', true, 0, false, true, $descMaxHeight);
             } else {
                 $pdf->MultiCell($nameColWidth, 5, $description, 0, 'L', false, 1, '', '', true, 0, false, true, $descMaxHeight);
             }
             if ($this->printStyle == 'dispatch' && getSetting('dispatch_note_show_barcodes') && (!empty($row['barcode1']) && !empty($row['barcode1_type']) || !empty($row['barcode2']) && !empty($row['barcode2_type']))) {
                 $style = ['position' => '', 'align' => 'L', 'stretch' => false, 'fitwidth' => true, 'cellfitalign' => '', 'border' => false, 'hpadding' => 'auto', 'vpadding' => 'auto', 'fgcolor' => [0, 0, 0], 'bgcolor' => false, 'text' => true, 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4];
                 //
                 if (!empty($row['barcode1']) && !empty($row['barcode1_type'])) {
                     $pdf->write1DBarcode($row['barcode1'], $row['barcode1_type'], $left, $pdf->getY(), 98, 15, 0.34, $style, 'T');
                 }
                 if (!empty($row['barcode2']) && !empty($row['barcode2_type'])) {
                     $pdf->write1DBarcode($row['barcode2'], $row['barcode2_type'], $left + 98, $pdf->getY(), 105, 15, 0.34, $style, 'T');
                 }
                 $pdf->SetY($pdf->GetY() + 18);
             }
         }
     }
     if ($this->printStyle != 'dispatch') {
         if ($this->senderData['vat_registered']) {
             $pdf->SetFont('Helvetica', '', 10);
             $pdf->SetY($pdf->GetY() + 10);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalExcludingVAT'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSum), 0, 0, 'R');
             $pdf->SetFont('Helvetica', '', 10);
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalVAT'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalVAT), 0, 0, 'R');
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalIncludingVAT'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSumVAT), 0, 0, 'R');
             $pdf->SetFont('Helvetica', 'B', 10);
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalToPay'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSumVAT - $this->partialPayments), 0, 1, 'R');
         } else {
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalPrice'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSumVAT), 0, 0, 'R');
             $pdf->SetFont('Helvetica', 'B', 10);
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalToPay'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSumVAT - $this->partialPayments), 0, 1, 'R');
         }
     }
 }
Exemplo n.º 7
0
 protected function process_import_row($table, $row, $dupMode, $dupCheckColumns, $mode, &$addedRecordId)
 {
     if (!isset($row['date']) || !isset($row['amount']) || !isset($row['refnr'])) {
         return $GLOBALS['locImportStatementFieldMissing'];
     }
     $refnr = str_replace(' ', '', $row['refnr']);
     $refnr = ltrim($refnr, '0');
     $date = date('Ymd', DateTime::createFromFormat(getRequest('date_format', 'd.m.Y'), $row['date'])->getTimestamp());
     $amount = trim($row['amount']);
     if (substr($amount, 0, 1) == '-') {
         return;
     }
     if (substr($amount, 0, 1) == '+') {
         $amount = substr($amount, 1);
     }
     $sep = getRequest('decimal_separator', ',');
     if ($sep == ' ' || $sep == ',') {
         $amount = str_replace('.', '', $amount);
         $amount = str_replace($sep, '.', $amount);
     } elseif ($sep == '.') {
         $amount = str_replace(',', '', $amount);
     }
     $amount = floatval($amount);
     if ($row['refnr'] === '') {
         return $GLOBALS['locImportStatementFieldMissing'];
     }
     $intRes = mysqli_param_query('SELECT i.* FROM {prefix}invoice i' . ' WHERE i.Deleted=0 AND REPLACE(i.ref_number, " ", "") = ?', array($refnr));
     $count = mysqli_num_rows($intRes);
     if ($count == 0) {
         return str_replace('{refnr}', $refnr, $GLOBALS['locImportStatementInvoiceNotFound']);
     }
     if ($count > 1) {
         return str_replace('{refnr}', $refnr, $GLOBALS['locImportStatementMultipleInvoicesFound']);
     }
     $row = mysqli_fetch_assoc($intRes);
     if ($row['state_id'] == 3) {
         return str_replace('{refnr}', $refnr, $GLOBALS['locImportStatementInvoiceAlreadyPaid']);
     }
     $res2 = mysqli_param_query('SELECT ir.price, ir.pcs, ir.vat, ir.vat_included, ir.discount from {prefix}invoice_row ir where ir.deleted = 0 AND ir.invoice_id = ?', array($row['id']));
     $rowTotal = 0;
     while ($invoiceRow = mysqli_fetch_assoc($res2)) {
         list($rowSum, $rowVAT, $rowSumVAT) = calculateRowSum($invoiceRow['price'], $invoiceRow['pcs'], $invoiceRow['vat'], $invoiceRow['vat_included'], $invoiceRow['discount']);
         $rowTotal += $rowSumVAT;
     }
     if (miscRound2Decim($rowTotal) != miscRound2Decim($amount)) {
         $msg = str_replace('{statementAmount}', miscRound2Decim($amount), $GLOBALS['locImportStatementAmountMismatch']);
         $msg = str_replace('{invoiceAmount}', miscRound2Decim($rowTotal), $msg);
         $msg = str_replace('{refnr}', $refnr, $msg);
         return $msg;
     }
     if ($mode == 'import') {
         $sql = 'UPDATE {prefix}invoice SET state_id=3, payment_date=?';
         if (getSetting('invoice_auto_archive')) {
             $sql .= ', archived=1';
         }
         $sql .= ' WHERE id = ?';
         mysqli_param_query($sql, array($date, $row['id']));
     }
     $msg = str_replace('{amount}', miscRound2Decim($amount), $GLOBALS['locImportStatementInvoiceMarkedAsPaid']);
     $msg = str_replace('{id}', $row['id'], $msg);
     $msg = str_replace('{date}', dateConvDBDate2Date($date), $msg);
     $msg = str_replace('{refnr}', $refnr, $msg);
     return $msg;
 }
Exemplo n.º 8
0
 private function printReport()
 {
     $intBaseId = getRequest('base', false);
     $intCompanyId = getRequest('company', false);
     $grouping = getRequest('grouping', '');
     $format = getRequest('format', 'html');
     $printFields = getRequest('fields', []);
     $rowTypes = getRequest('row_types', 'all');
     $dateRange = explode(' - ', getRequest('date', ''));
     $startDate = $dateRange[0];
     $endDate = isset($dateRange[1]) ? $dateRange[1] : $startDate;
     if ($startDate) {
         $startDate = dateConvDate2DBDate($startDate);
     }
     if ($endDate) {
         $endDate = dateConvDate2DBDate($endDate);
     }
     $rowDateRange = explode(' - ', getRequest('row_date', ''));
     $rowStartDate = $rowDateRange[0];
     $rowEndDate = isset($rowDateRange[1]) ? $rowDateRange[1] : $rowStartDate;
     if ($rowStartDate) {
         $rowStartDate = dateConvDate2DBDate($rowStartDate);
     }
     if ($rowEndDate) {
         $rowEndDate = dateConvDate2DBDate($rowEndDate);
     }
     $paymentDateRange = explode(' - ', getRequest('payment_date', ''));
     $paymentStartDate = $paymentDateRange[0];
     $paymentEndDate = isset($paymentDateRange[1]) ? $paymentDateRange[1] : '';
     if ($paymentStartDate) {
         $paymentStartDate = dateConvDate2DBDate($paymentStartDate);
     }
     if ($paymentEndDate) {
         $paymentEndDate = dateConvDate2DBDate($paymentEndDate);
     }
     $arrParams = [];
     $strQuery = 'SELECT i.id, i.invoice_no, i.invoice_date, i.due_date, i.payment_date, i.ref_number, i.ref_number, c.company_name AS name, c.billing_address, ist.name as state, ist.invoice_unpaid as unpaid' . ($grouping == 'vat' ? ', ir.vat' : '') . ' FROM {prefix}invoice i' . ($grouping == 'vat' ? ' INNER JOIN {prefix}invoice_row ir ON ir.invoice_id = i.id' : '') . ' LEFT OUTER JOIN {prefix}company c ON c.id = i.company_id' . ' LEFT OUTER JOIN {prefix}invoice_state ist ON i.state_id = ist.id' . ' WHERE i.deleted=0';
     if ($startDate) {
         $strQuery .= ' AND i.invoice_date >= ?';
         $arrParams[] = $startDate;
     }
     if ($endDate) {
         $strQuery .= ' AND i.invoice_date <= ?';
         $arrParams[] = $endDate;
     }
     if ($paymentStartDate) {
         $strQuery .= ' AND i.payment_date >= ?';
         $arrParams[] = $paymentStartDate;
     }
     if ($paymentEndDate) {
         $strQuery .= ' AND i.payment_date <= ?';
         $arrParams[] = $paymentEndDate;
     }
     if ($intBaseId) {
         $strQuery .= ' AND i.base_id = ?';
         $arrParams[] = $intBaseId;
     }
     if ($intCompanyId) {
         $strQuery .= ' AND i.company_id = ?';
         $arrParams[] = $intCompanyId;
     }
     $strQuery2 = '';
     $strQuery3 = 'SELECT id, name ' . 'FROM {prefix}invoice_state WHERE deleted=0 ORDER BY order_no';
     $intRes = mysqli_query_check($strQuery3);
     while ($row = mysqli_fetch_assoc($intRes)) {
         $intStateId = $row['id'];
         $strStateName = $row['name'];
         $strTemp = "stateid_{$intStateId}";
         $tmpSelected = getRequest($strTemp, false);
         if ($tmpSelected) {
             $strQuery2 .= 'i.state_id = ? OR ';
             $arrParams[] = $intStateId;
         }
     }
     if ($strQuery2) {
         $strQuery2 = ' AND (' . substr($strQuery2, 0, -4) . ')';
     }
     $strQuery .= $strQuery2;
     switch ($grouping) {
         case 'state':
             $strQuery .= ' ORDER BY state_id, invoice_date, invoice_no';
             break;
         case 'client':
             $strQuery .= ' ORDER BY name, invoice_date, invoice_no';
             break;
         case 'vat':
             $strQuery .= ' GROUP BY i.id, ir.vat ORDER BY vat, invoice_date, invoice_no';
             break;
         default:
             $strQuery .= ' ORDER BY invoice_date, invoice_no';
     }
     $this->printHeader($format, $printFields, $startDate, $endDate);
     $intTotSum = 0;
     $intTotVAT = 0;
     $intTotSumVAT = 0;
     $intTotalToPay = 0;
     $currentGroup = false;
     $groupTotSum = 0;
     $groupTotVAT = 0;
     $groupTotSumVAT = 0;
     $groupTotalToPay = 0;
     $totalsPerVAT = [];
     $intRes = mysqli_param_query($strQuery, $arrParams);
     while ($row = mysqli_fetch_assoc($intRes)) {
         switch ($grouping) {
             case 'state':
                 $invoiceGroup = $row['state'];
                 break;
             case 'month':
                 $invoiceGroup = substr($row['invoice_date'], 4, 2);
                 break;
             case 'client':
                 $invoiceGroup = $row['name'];
                 break;
             case 'vat':
                 $invoiceGroup = $row['vat'];
                 break;
             default:
                 $invoiceGroup = false;
         }
         $rowParams = [$row['id']];
         $strQuery = 'SELECT ir.description, ir.pcs, ir.price, ir.discount, ir.row_date, ir.vat, ir.vat_included, ir.partial_payment ' . 'FROM {prefix}invoice_row ir ' . 'WHERE ir.invoice_id=? AND ir.deleted=0';
         if ($rowStartDate) {
             $strQuery .= ' AND ir.row_date >= ?';
             $rowParams[] = $rowStartDate;
         }
         if ($rowEndDate) {
             $strQuery .= ' AND ir.row_date <= ?';
             $rowParams[] = $rowEndDate;
         }
         if ($rowTypes != 'all') {
             if ($rowTypes == 'normal') {
                 $strQuery .= ' AND ir.reminder_row = 0';
             } else {
                 if ($rowTypes == 'reminder') {
                     $strQuery .= ' AND ir.reminder_row in (1, 2)';
                 }
             }
         }
         if ($grouping == 'vat') {
             if ($row['vat'] === null) {
                 $strQuery .= ' AND ir.vat IS NULL';
             } else {
                 $strQuery .= ' AND ir.vat = ?';
                 $rowParams[] = $row['vat'];
             }
         }
         $intRes2 = mysqli_param_query($strQuery, $rowParams);
         $intRowSum = 0;
         $intRowVAT = 0;
         $intRowSumVAT = 0;
         $rowPayments = 0;
         $rows = false;
         while ($row2 = mysqli_fetch_assoc($intRes2)) {
             $rows = true;
             if ($row2['partial_payment']) {
                 $rowPayments -= $row2['price'];
                 continue;
             }
             list($intSum, $intVAT, $intSumVAT) = calculateRowSum($row2['price'], $row2['pcs'], $row2['vat'], $row2['vat_included'], $row2['discount']);
             $intRowSum += $intSum;
             $intRowVAT += $intVAT;
             $intRowSumVAT += $intSumVAT;
             if (!isset($totalsPerVAT[$row2['vat']])) {
                 $totalsPerVAT[$row2['vat']] = ['sum' => $intSum, 'VAT' => $intVAT, 'sumVAT' => $intSumVAT];
             } else {
                 $totalsPerVAT[$row2['vat']]['sum'] += $intSum;
                 $totalsPerVAT[$row2['vat']]['VAT'] += $intVAT;
                 $totalsPerVAT[$row2['vat']]['sumVAT'] += $intSumVAT;
             }
         }
         if (!$rows) {
             continue;
         }
         $intTotSum += $intRowSum;
         $intTotVAT += $intRowVAT;
         $intTotSumVAT += $intRowSumVAT;
         if ($row['unpaid']) {
             $intTotalToPay += $intRowSumVAT - $rowPayments;
         } else {
             $rowPayments = $intRowSumVAT;
         }
         if ($grouping && $currentGroup !== false && $currentGroup != $invoiceGroup) {
             $this->printGroupSums($format, $printFields, $row, $groupTotSum, $groupTotVAT, $groupTotSumVAT, $groupTotalToPay, $grouping == 'vat' ? $GLOBALS['locVAT'] . ' ' . miscRound2Decim($currentGroup) : '');
             $groupTotSum = 0;
             $groupTotVAT = 0;
             $groupTotSumVAT = 0;
             $groupTotalToPay = 0;
         }
         $currentGroup = $invoiceGroup;
         $groupTotSum += $intRowSum;
         $groupTotVAT += $intRowVAT;
         $groupTotSumVAT += $intRowSumVAT;
         $groupTotalToPay += $intRowSumVAT - $rowPayments;
         $this->printRow($format, $printFields, $row, $intRowSum, $intRowVAT, $intRowSumVAT, $intRowSumVAT - $rowPayments);
     }
     if ($grouping) {
         $this->printGroupSums($format, $printFields, $row, $groupTotSum, $groupTotVAT, $groupTotSumVAT, $groupTotalToPay, $grouping == 'vat' ? $GLOBALS['locVAT'] . ' ' . miscRound2Decim($currentGroup) : '');
     }
     ksort($totalsPerVAT, SORT_NUMERIC);
     $this->printTotals($format, $printFields, $intTotSum, $intTotVAT, $intTotSumVAT, $intTotalToPay, $totalsPerVAT);
     $this->printFooter($format, $printFields);
 }
 protected function printRows()
 {
     $pdf = $this->pdf;
     $invoiceData = $this->invoiceData;
     $pdf->printFooterOnFirstPage = true;
     $pdf->SetAutoPageBreak(true, 22);
     /*
      * +tuotekoodi,
      * +tuote,
      * +määrä,
      * +yksikkö,
      * +yksikköhinta,
      * +rivin yhteishinta,
      * +kokonaishinta tilaukselle (periaatteessa riittää alv 0% ja loppusummalle 0% ja 24%)
      * +maksuehto,
      * +toimitusehto,
      * +toimituspäivä,
      * +kuljetustapa,
      * +asiakkaan viite (osa näistä voisi olla lisätietorivillä, jos muuten hankala).
      * Mahdollinen vapaa teksti kenttä loppuun: (esim.) "Ellei toisin ole sovittu tässä kaupassa noudatetaan "Teknisen Kaupan yleiset myyntiehdot (TK Yleiset 2010)" -myyntiehtoja"
      */
     $left = 10;
     $nameColWidth = 110;
     $pdf->Cell($nameColWidth, 5, $GLOBALS['locPDFRowName'], 0, 0, 'L');
     $pdf->Cell(20, 5, $GLOBALS['locPDFOrderConfirmationRowDate'], 0, 0, 'L');
     $pdf->Cell(17, 5, $GLOBALS['locPDFRowPrice'], 0, 0, 'R');
     $pdf->Cell(20, 5, $GLOBALS['locPDFRowPieces'], 0, 0, 'R');
     $pdf->Cell(20, 5, $GLOBALS['locPDFRowTotal'], 0, 1, 'R');
     $pdf->Cell(20, 5, '', 0, 1, 'R');
     // line feed
     foreach ($this->invoiceRowData as $row) {
         // Product / description
         $description = '';
         switch ($row['reminder_row']) {
             case 1:
                 $description = $GLOBALS['locPDFPenaltyInterestDesc'];
                 break;
             case 2:
                 $description = $GLOBALS['locPDFReminderFeeDesc'];
                 break;
             default:
                 if ($row['product_name']) {
                     if ($row['description']) {
                         $description = $row['product_name'] . ' (' . $row['description'] . ')';
                     } else {
                         $description = $row['product_name'];
                     }
                     if (getSetting('invoice_display_product_codes') && $row['product_code']) {
                         $description = $row['product_code'] . ' ' . $description;
                     }
                 } else {
                     $description = $row['description'];
                 }
         }
         // Sums
         list($rowSum, $rowVAT, $rowSumVAT) = calculateRowSum($row['price'], $row['pcs'], $row['vat'], $row['vat_included'], $row['discount']);
         if ($row['vat_included']) {
             $row['price'] /= 1 + $row['vat'] / 100;
         }
         if ($row['price'] == 0 && $row['pcs'] == 0) {
             $pdf->SetX($left);
             $pdf->MultiCell(0, 5, $description, 0, 'L');
         } else {
             $pdf->SetX($nameColWidth + $left);
             $pdf->Cell(20, 5, $this->_formatDate($row['row_date']), 0, 0, 'L');
             $decimals = isset($row['price_decimals']) ? $row['price_decimals'] : 2;
             $pdf->Cell(17, 5, $this->_formatCurrency($row['price'], $decimals), 0, 0, 'R');
             $pdf->Cell(13, 5, $this->_formatNumber($row['pcs'], 2, true), 0, 0, 'R');
             $pdf->Cell(7, 5, isset($GLOBALS["locPDF{$row['type']}"]) ? $GLOBALS["locPDF{$row['type']}"] : $row['type'], 0, 0, 'L');
             $pdf->Cell(20, 5, $this->_formatCurrency($rowSum), 0, 0, 'R');
             $pdf->SetX($left);
             $pdf->MultiCell($nameColWidth, 5, $description, 0, 'L');
         }
     }
     if ($this->printStyle != 'dispatch') {
         if ($this->senderData['vat_registered']) {
             $pdf->SetFont('Helvetica', '', 10);
             $pdf->SetY($pdf->GetY() + 10);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalExcludingVAT'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSum), 0, 0, 'R');
             $pdf->SetFont('Helvetica', '', 10);
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalVAT'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalVAT), 0, 0, 'R');
             $pdf->SetFont('Helvetica', 'B', 10);
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalIncludingVAT'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSumVAT), 0, 1, 'R');
             $pdf->SetFont('Helvetica', '', 10);
         } else {
             $pdf->SetFont('Helvetica', 'B', 10);
             $pdf->SetY($pdf->GetY() + 5);
             $pdf->Cell(162, 5, $GLOBALS['locPDFTotalPrice'] . ': ', 0, 0, 'R');
             $pdf->SetX(187 - $left);
             $pdf->Cell(20, 5, $this->_formatCurrency($this->totalSumVAT), 0, 1, 'R');
             $pdf->SetFont('Helvetica', '', 10);
         }
     }
     $terms = getSetting('order_confirmation_terms');
     if ($terms) {
         $pdf->SetY($pdf->GetY() + 10);
         $pdf->MultiCell(187, 4, $terms, 0, 'L', 0);
     }
 }