focus = $this; $pdf->Ln(2); $pdf->SetY($pdf->GetY() + 2); $current = $pdf->GetY(); $pdf->SetFont('arialpl', '', 9); //$p_name = html_entity_decode($this->parent_name); //$p_name = explode(' ', $p_name); // //$name = array(); // //if (sizeof($p_name) > 4) { // for ($i = 0; $i < sizeof($p_name); $i++) { // $n.=$p_name[$i] . ' '; // //$pdf->Cell(40,5, $n,0,1,'L'); // if (($i % 5 == 0) && ($i != 0)) { // $name[] = $n; // $n = ''; // } // } // $name[] = $n; //} // //if ($this->parent_name) { // if (sizeof($p_name) > 4) // foreach ($name as $n) // $pdf->Cell(40, 5, $n, 0, 1, 'L'); // else // $pdf->Cell(40, 5, html_entity_decode($this->parent_name), 0, 1, 'L'); //} $pdf->MultiCell(100, 5, html_entity_decode($this->parent_name), 0, 1, 'L'); //$pdf->SetFont('arialpl', '', 10); if ($this->parent_address_street) $pdf->Cell(20, 5, html_entity_decode($this->parent_address_street), 0, 1, 'L'); if (($this->parent_address_postalcode) || ($this->parent_address_city)) $pdf->Cell(20, 5, html_entity_decode($this->parent_address_postalcode) . ' ' . html_entity_decode($this->parent_address_city), 0, 1, 'L'); if ($this->to_vatid) $pdf->Cell(20, 5, $mod_strings['LBL_PDF_VATID'] . ' ' . html_entity_decode($this->to_vatid), 0, 1, 'L'); $title = ''; if ($this->parent_contact_title) { $title.=$this->parent_contact_title . ' '; } if ($this->parent_contact_name) { $pdf->SetFont('arialpl', 'b', 10); $pdf->Cell(20, 5, $title . $this->parent_contact_name, 0, 1, 'L'); $pdf->SetFont('arialpl', 'b', 10); } if ($this->parent_shipping_address_name || $this->parent_shipping_address_street) { $x = $pdf->getX(); $y = $pdf->getY(); $pdf->setY($current); $pdf->setX(100); $pdf->Cell(100, 5, $mod_strings['LBL_PDF_DELIVERY_TO'], 0, 1, 'L'); $pdf->setX(100); $pdf->MultiCell(100, 5, html_entity_decode($this->parent_shipping_address_name), 0, 1, 'L'); $pdf->setX(100); if ($this->parent_shipping_address_street) $pdf->Cell(100, 5, html_entity_decode($this->parent_shipping_address_street), 0, 1, 'L'); $pdf->setX(100); if (($this->parent_shipping_address_postalcode) || ($this->parent_shipping_address_city)) $pdf->Cell(20, 5, html_entity_decode($this->parent_address_postalcode) . ' ' . html_entity_decode($this->parent_address_city), 0, 1, 'L'); $pdf->setY($y); $pdf->setX($x); } //if ($this->name) { // $pdf->Cell(20, 5, '', 0, 1, 'L'); // $pdf->SetFont('arialpl', 'b', 10); // $pdf->Cell(20, 5, $mod_strings['LBL_PDF_NAME'], 0, 1, 'L'); // $pdf->SetFont('arialpl', '', 10); // $pdf->Cell(20, 5, html_entity_decode($this->name), 0, 1, 'L'); //} $pdf->SetFont('arialpl', '', 10); $pdf->Ln(2); //$current = $pdf->GetY(); //$pdf->MultiCell(120,4,$address,0,'L'); //$pdf->SetFont('arialpl','B','10'); //$pdf->MultiCell(0,4,$address_cnt,0,'L'); if ($this->parent_type = "Contacts") $pdf->Ln(14); $current2 = $pdf->GetY(); $pdf->SetFont('arialpl', '', '10'); $subFontSizeold = $pdf->FontSizePt; $pdf->SetFontSize($subFontSize); //// reposition y //$subOffset = ((($subFontSize - $subFontSizeold) / $pdf->k) * 0.3) + ($subOffset / $pdf->k); //$subX = $pdf->x; //$subY = $pdf->y; //$pdf->SetXY($subX, $subY - $subOffset); // ////Output text //$pdf->Write(5, 'test', ''); // //// restore y position //$subX = $pdf->x; //$subY = $pdf->y; //$pdf->SetXY($subX, $subY + $subOffset); // //// restore font size //$pdf->SetFontSize($subFontSizeold); //$pdf->Ln(7); $pdf->SetXY($pdf->fw - $pdf->rMargin - 37, $current); $table = array(); $table[0]['data'] = array( 'width' => 30, 'value' => $mod_strings['LBL_PDF_DATE_REGISTER'], 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-style' => 'b', 'font-size' => 9, ); $table[1]['data'] = array( 'width' => 30, 'value' => date("d.m.Y"), 'border' => 0, 'overflow' => 1, 'align' => 'L', ); $table[2]['data'] = array( 'width' => 30, 'value' => "", 'border' => 0, 'overflow' => 1, 'align' => 'L', ); $r_created_by = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select first_name, last_name from users where id='" . $this->modified_user_id . "'")); $table[4]['data'] = array( 'width' => 30, 'value' => $mod_strings['LBL_PDF_OWNER'], 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-style' => 'b', 'font-size' => 9, ); $table[4]['data'] = array( 'width' => 30, 'value' => $mod_strings['LBL_PDF_OWNER'], 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-style' => 'b', 'font-size' => 9, ); $table[5]['data'] = array( 'width' => 30, 'value' => $r_created_by['first_name'] . " " . $r_created_by['last_name'], 'border' => 0, 'overflow' => 1, 'align' => 'L', ); $table[6]['data'] = array( 'width' => 30, 'value' => $mod_strings['LBL_PDF_ASSIGNED_TO'], 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-style' => 'b', 'font-size' => 9, ); $tmp = ''; $tmp .= $this->setUser()->full_name . PHP_EOL; $tmp .= 'tel.: ' . $this->setUser()->phone_work . PHP_EOL; $tmp .= 'kom.: ' . $this->setUser()->phone_mobile . PHP_EOL; $tmp .= 'e-mail: ' . $this->setUser()->email1; $table[7]['data'] = array( 'width' => 30, 'value' => $tmp, 'border' => 0, 'overflow' => 1, 'align' => 'L', ); $pdf->DrawTable($table, null, 0, 0, 3); $pdf->SetY($current2 - 10); $pdf->Ln(2); $pdf->SetFont('arialpl', '', '14'); $pdf->MultiCell(0, 0, $mod_strings['LBL_PDF_CONFIRM'] . " " . $this->document_no, 0, 'L'); $pdf->SetFont('arialpl', '', '9'); $pdf->Ln(7); $table = array(); $table[0][0] = array( 'width' => 30, 'value' => $mod_strings['LBL_PDF_PARENT_DOCUMENT_NO'], 'background' => array(255, 255, 255), 'border' => 0, 'overflow' => '1', 'align' => 'L', ); $table[0][1] = array( 'width' => 80, 'value' => $this->parent_document_no, 'background' => array(255, 255, 255), 'border' => 0, 'overflow' => '1', 'align' => 'L', ); $pdf->DrawTable($table); //$pdf->MultiCell(0,0,'Szablon dokumentu jest aktualnie przebudowywany.',0,'L'); //$pdf->SetY($current2 + 5); //$pdf->MultiCell(0,0,'Spróbuj za 30 min.',0,'L'); $this->loadParser(); $this->header_text = $this->template->mfp->parseText($this->header_text); $this->footer_text = $this->template->mfp->parseText($this->footer_text); $this->ads_text = $this->template->mfp->parseText($this->ads_text); //header text if ($this->header_text) { $pdf->Ln(4); $pdf->SetFont('arialpl', '', '10'); $pdf->MultiCell(0, 4, $this->header_text, 0, 'J'); } $pdf->Ln(4); //************************************************** global $mod_strings; $currency = new Currency(); $currency->retrieve($this->currency_id); $this->currency_symbol = $currency->iso4217; if (!isset($this->position_list) || !is_array($this->position_list)) { $this->position_list = $this->getPositionList(true); } //echo '
' . var_export($this->currency_id, true) . '
'; exit; // $calc = $this->calculate_currency($this->position_list, $this->currency_symbol, null); $calc = $this->calculate_currency($this->position_list, $this->currency_id, $this->currency_value); //$this->position_list = $this->formatPositions($this->position_list, $this->currency_id, $this->currency_value); //$this->position_list = $this->getPositionList(true); //$calc['total'] .= ' ' . $this->currency_symbol; //$calc['subtotal'] .= ' ' . $this->currency_symbol; //if ($calc['discount']) { // $calc['total2'] .= ' ' . $this->currency_symbol; // $calc['discount']['value'] .= ' ' . $this->currency_symbol; //} // //if (isset($calc['vats']) && is_array($calc['vats']) && count($calc['vats']) > 0) // foreach ($calc['vats'] as $key => $value) // $calc['vats'][$key] .= ' ' . $this->currency_symbol; $widths = array( 'position' => 5, 'description' => 64, 'quantity' => 8, 'unit_price' => 15, 'discount' => 7, 'total' => 15, // 'fix' => 73 - 8 +4, 'subtotal1' => 15 + 8, // 66 'subtotal2' => 15, // 34 ); //$calc['draw_discount'] = false; //echo '
' . var_export($calc, true); exit;

$image_w = 10;

$recipient_code_w = 10;

if ($this->show_images_on_offers) {
    $widths['description'] -= $image_w;
}

if ($this->show_recipient_code) {
    $widths['description'] -= $recipient_code_w;
}

/*
if ($calc['draw_discount']) {
    $widths['description'] -= 8;
}

if ($calc['draw_vat']) {
    $widths['description'] -= 8;
}
*/

//jest rabat?
$rabat = false;

foreach ($this->position_list as $p) {
    if ($p['discount'] != 0)
        $rabat = true;
}

if($rabat) {
    $widths['description'] -= $widths['discount'];
    
    $widths['fix'] -= $widths['discount'];
    $widths['subtotal2'] += $widths['discount'];
}

if ($this->total_netto != '')
    $widths['description'] +=35;

$table = array();

$table[0]['position'] = array(
    'width' => $widths['position'],
    'value' => $mod_strings['LBL_PDF_LIST_POSITION'],
    'background' => array(233, 233, 233),
    'border' => 1,
    'overflow' => 1,
    'align' => 'C',
);

$table[0]['description'] = array(
    'width' => $widths['description'],
    'value' => $mod_strings['LBL_PDF_LIST_DESCRIPTION'],
    'background' => array(233, 233, 233),
    'border' => 1,
    'overflow' => 1,
    'align' => 'C',
);

$table[0]['quantity'] = array(
    'width' => $widths['quantity'],
    'value' => $mod_strings['LBL_PDF_LIST_QUANTITY'],
    'background' => array(233, 233, 233),
    'border' => 1,
    'overflow' => 1,
    'align' => 'C',
);

if ($this->total_netto == '') {
    $table[0]['unit_price'] = array(
        'width' => $widths['unit_price'],
        'value' => $mod_strings['LBL_PDF_LIST_PRICE'],
        'background' => array(233, 233, 233),
        'border' => 1,
        'overflow' => 1,
        'align' => 'C',
    );

    if ($rabat == true) {
        $table[0]['discount'] = array(
            'width' => $widths['discount'],
            'value' => 'Rabat (%)', $mod_strings['LBL_PDF_LIST_DISCOUNT'],
            'background' => array(233, 233, 233),
            'border' => 1,
            'overflow' => 1,
            'align' => 'C',
        );
    }

    $table[0]['total'] = array(
        'width' => $widths['total'],
        'value' => $mod_strings['LBL_PDF_LIST_TOTAL'],
        'background' => array(233, 233, 233),
        'border' => 1,
        'overflow' => 1,
        'align' => 'R',
    );
}

$i = 1;
$netto_weight = $brutto_weight = 0;

$lv = return_app_list_strings_language($this->ecmlanguage);

if ($this->position_list != '') {
    //$p = array_pop($this->position_list);
    //$this->position_list = array_fill(0, 100, $p);
    
    //$result = $db->query("SELECT total_netto from ecmquotes where id=$p['id']");
    foreach ($this->position_list as $p) {
        //$p['price'] = unformat_number(substr($p['price'], 0, -4));
        //$p['total'] = unformat_number(substr($p['total'], 0, -4));

        //echo '
' . var_export($p, true); exit;
    
        $table[$i]['position'] = array(
            'width' => $widths['position'],
            'value' => $i,
            'border' => 1,
            'align' => 'C',
        );

        $name = str_replace('–', '-', htmlspecialchars_decode($p['name']));

        $table[$i]['description'] = array(
            'width' => $widths['description'],
            'value' => $name,
            'border' => 1,
            'align' => 'L',
        );
        
        $netto_weight += $p['netto_weight'];
        //$brutto_weight += $p['brutto_weight'];
        $brutto_weight += ($p['quantity'] * $p['netto_weight']);

        $table[$i]['quantity'] = array(
            'width' => $widths['quantity'],
            'value' => format_number($p['quantity']),
            'border' => 1,
            'align' => 'C',
        );

        $price_total = $p['price'] * $p['quantity'];
        $discount = ((100 * $p['price']) / (100 - $p['discount']));
        
        //echo '
' . var_export($price_total, true);
        //echo '
' . var_export($discount, true);
        //exit;
        
        if ($this->total_netto == '') {
            $table[$i]['unit_price'] = array(
                'width' => $widths['unit_price'],
                // 'value' => format_number($p['price']). ' ' . $this->currency_symbol,
                'value' => format_number($p['price']). ' ' . $p['currency_name'],
                'border' => 1,
                'align' => 'R',
            );

            if ($rabat == true) {
                if ($p['discount'] == 0) {
                    $tmp = '---';
                } else {
                    $tmp = format_number($p['discount']) . '%';
                }

                $table[$i]['discount'] = array(
                    'width' => $widths['discount'],
                    'value' => $tmp,
                    'border' => 1,
                    'align' => 'C',
                );
            }

            $table[$i]['total'] = array(
                'width' => $widths['total'],
                // 'value' => format_number($p['total']) . ' '. $this->currency_symbol,
                'value' => format_number($p['total']) . ' '. $p['currency_name'],
                'border' => 1,
                'align' => 'R',
            );
        }

        $tmp_sep = ereg_replace('[^0-9.,]', '', $p['total']);
        
        $len = strlen($tmp_sep);
        $separator = substr($tmp_sep, $len - 3, 1);

        if ($separator == '.') {
            $tmp = (float) ereg_replace('[^0-9.]', '', $p['total']);
        }

        if ($separator == ',') {
            $tmp = (float) ereg_replace('[^0-9,]', '', $p['total']);
        }

        if ($p['currency_id'] == 'PLN') {
            if (isset($total_price_pln)) {
                $total_price_pln += $tmp;
            } else {
                $total_price_pln = $tmp;
            }
        }

        if ($p['currency_id'] == '6336d9a0-ee5f-52e3-7d0c-4e6f1472b2bf') {
            if (isset($total_price_eur)) {
                $total_price_eur+= $tmp;
            } else {
                $total_price_eur = $tmp;
            }
        }

        $i++;
    }
}

$starttab = $pdf->GetY() + 10;

$pdf->DrawTable($table, array(0));

$endtab = $pdf->GetY();
$pdf->SetY($endtab);

//mz
$table = array();

//echo '
'. var_export($calc, true); exit;

//EURO
if ($calc['vats']) {
    $table[] = array(
        'fix' => array(
            'width' => $widths['fix'],
            'value' => '',
            'border' => 0,
            'overflow' => 1,
            'align' => 'C',
            'font-style' => 'b',
            'font-size' => 7,
        ),
        'subtotal1' => array(
            'width' => $widths['subtotal1'],
            'value' => $mod_strings['LBL_PDF_TOTAL'],
            'background' => array(255, 255, 255),
            'border' => 1,
            'overflow' => 1,
            'align' => 'L',
            'font-size' => 9,
        ),
        'subtotal2' => array(
            'width' => $widths['subtotal2'],
            // 'value' => format_number($calc['subtotal']) . ' ' . $calc['currency_symbol'],
            'value' => format_number($calc['subtotal']) . ' ' . $this->currency_symbol,
            //'value' => 'test',
            'border' => 1,
            'overflow' => 1,
            'align' => 'R',
            'font-size' => 9,
        ),
    );

    foreach ($calc['vats'] as $key => $value) {
        $r = mysql_fetch_array(mysql_query("select name from ecmvats where id='" . $key . "'"));
        $vvn = $r['name'];

        $table[] = array(
            'fix' => array(
                'width' => $widths['fix'],
                'value' => '',
                'border' => 0,
                'overflow' => 1,
                'align' => 'C',
                'font-style' => 'b',
                'font-size' => 7,
            ),
            'subtotal1' => array(
                'width' => $widths['subtotal1'],
                'value' => $mod_strings['LBL_PDF_VAT'] . ' (' . $vvn . ')',
                'background' => array(255, 255, 255),
                'border' => 1,
                'overflow' => 1,
                'align' => 'L',
                'font-size' => 9),
            'subtotal2' => array(
                'width' => $widths['subtotal2'],
                // 'value' => format_number($value) . ' ' . $calc['currency_symbol'],
                'value' => format_number($value) . ' ' . $this->currency_symbol,
                'border' => 1,
                'overflow' => 1,
                'align' => 'R',
                'font-size' => 9,
            ),
        );
    }
}

$table[] = array(
    'fix' => array(
        'width' => $widths['fix'],
        'value' => '',
        'border' => 0,
        'overflow' => 1,
        'align' => 'C',
        'font-style' => 'b',
        'font-size' => 7,
    ),
    'total1' => array(
        'width' => $widths['subtotal1'],
        'value' => $mod_strings['LBL_PDF_END_TOTAL'],
        'background' => array(233, 233, 233),
        'border' => 1,
        'overflow' => 1,
        'align' => 'L',
        'font-size' => 9,
        'font-style' => 'b',
    ),
    'total2' => array(
        'width' => $widths['subtotal2'],
        // 'value' => format_number(unformat_number($calc['total'])) . ' ' . $calc['currency_symbol'],
        'value' => format_number(unformat_number($calc['total'])) . ' ' . $this->currency_symbol,
        'border' => 1,
        'background' => array(233, 233, 233),
        'overflow' => 1,
        'align' => 'R',
        'font-size' => 9,
        'font-style' => 'b',
    ),
);

//echo '
' . var_export($widths['subtotal2'], true); exit;

$pdf->Ln(4);
$pdf->DrawTable($table);

//PLN
//$starttab = $pdf->GetY() + 1;
//$pdf->SetY($starttab);
//
//$table = array();
//if ($calc['vats_pln']) {
//    $table[] = array(
//        'subtotal1' => array('width' => 66, 'value' => $mod_strings['LBL_PDF_TOTAL'], 'background' => array(255, 255, 255), 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-size' => 9),
//        'subtotal2' => array('width' => 34, 'value' => $calc['subtotal_pln'] . ' PLN', 'border' => 0, 'overflow' => 1, 'align' => 'R', 'font-size' => 9),);
//
//    foreach ($calc['vats_pln'] as $key => $value) {
//        $r = mysql_fetch_array(mysql_query("select name from ecmvats where id='" . $key . "'"));
//        $vvn = $r['name'];
//        $table[] = array(
//            'vat1' => array('width' => 66, 'value' => $mod_strings['LBL_PDF_VAT'] . ' (' . $vvn . ')', 'background' => array(255, 255, 255), 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-size' => 9),
//            'vat2' => array('width' => 34, 'value' => $value . ' PLN', 'border' => 0, 'overflow' => 1, 'align' => 'R', 'font-size' => 9),);
//    }
//}
//
//$table[] = array(
//    'total1' => array('width' => 66, 'value' => $mod_strings['LBL_PDF_END_TOTAL'], 'background' => array(233, 233, 233), 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-size' => 9, 'font-style' => 'b'),
//    'total2' => array('width' => 34, 'value' => $calc['subtotal_pln'] . ' PLN', 'border' => 0, 'background' => array(233, 233, 233), 'overflow' => 1, 'align' => 'R', 'font-size' => 9, 'font-style' => 'b'),);
//
//$pdf->DrawTable($table);