", $this->parent_name))); if ($this->parent_contact_name) { $address .= "\n" . $this->parent_contact_name; if ($this->parent_contact_title) { $address .= "\n" . $this->parent_contact_title; } $personplus = 5; } else { $personplus = 0; } if ($this->parent_address_street) { $address .= "\n" . $this->parent_address_street; } if ($this->parent_address_postalcode) { $address .= "\n" . $this->parent_address_postalcode; } if ($this->parent_address_city) { $address .= " " . $this->parent_address_city; } $v = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT to_vatid FROM ecmprepaymentinvoices WHERE id='".$this->id."'")); $this->to_vatid = $v['to_vatid']; //$this->to_vatid="SELECT to_vatid FROM ecmprapaymentinvoices WHERE id='".$this->id."'"; if($this->to_vatid) $address .= "\nNIP ".$this->to_vatid; /* if ($this->to_nip) { $address .= "\nNip: " . $this->to_nip; } elseif (!$this->to_nip && $this->to_vatid) { $address .= "\nNip: " . $this->to_vatid; } */ $r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select iln,to_nip from accounts where id='" . $this->parent_id . "'")); if ($r['iln']) { $address .= "\nILN: " . $r['iln']; } //to address $old_x = $pdf->GetX(); $old_y = $pdf->GetY(); $pdf->SetXY(10, 53); $db = $GLOBALS['db']; //$pdf->header_text = $pdf->template->mfp->parseText($pdf->header_text); //$pdf->MultiCell(60, 4, $pdf->edt->header_text, 0, 'L'); $pdf->SetFont('arialpl', 'B', 8); $pdf->Cell(35, 1,$mod_strings['LBL_PDF_BUYER'], 0, 0, 'L', 1); $pdf->Ln(3); $pdf->SetFont('arialpl', '', 8); $pdf->MultiCell(60, 4, $address, 0, 'L'); $address = ""; $address = str_replace("<", "<", str_replace(">", ">", $r['parent_name'])); if ($r['parent_address_street']) { $address .= "\n" . $r['parent_address_street']; } if ($r['parent_address_postalcode']) { $address .= "\n" . $r['parent_address_postalcode']; } if ($r['parent_address_city']) { $address .= " " . $r['parent_address_city']; } if ($r['to_nip']) { $address .= "\nNip: " . $r['to_nip']; } elseif (!$r['to_nip'] && $r['to_vatid']) { $address .= "\nNip: " . $r['to_vatid']; } $rr = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select iln from accounts where id='" . $r['parent_id'] . "'")); if ($rr['iln']) { $address .= "\nILN: " . $rr['iln']; } $ynew = $pdf->GetY() + 12; if ($this->ecmpaymentcondition_id) { require_once("modules/EcmPaymentConditions/EcmPaymentCondition.php"); $pc = new EcmPaymentCondition(); $pc->retrieve($this->ecmpaymentcondition_id); } $pdf->SetXY(160, $old_y + 10 + $personplus); $table = array(); $table[0]['date_reg'] = array( 'width' => 16, 'value' => "Data wystawienia", 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-style' => 'b', 'font-size' => 8, ); $table[1]['date_reg_value'] = array( 'width' => 36+ 4, 'value' => $this->register_date, 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-size' => 8, ); $table[2]['date_reg1'] = array( 'width' => 16, 'value' => "Data przedpłaty", 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-style' => 'b', 'font-size' => 8, ); $table[3]['date_reg1_value'] = array( 'width' => 36+ 4, 'value' => $this->register_date, 'border' => 0, 'overflow' => 1, 'align' => 'L', 'font-size' => 8, ); $q = 'select s.`document_no` as `number`, s.`parent_document_no` as `doc_number`, s.`date_entered` as `date` from `ecmprepaymentinvoices` as pi join `ecmsales` as s on s.`id` = pi.`ecmsale_id` where pi.`id` = \'' . $this->id . '\' group by s.`document_no`;'; $result = $db->query($q); $results = $db->fetchByAssoc($result); // echo '
' . var_export($results['doc_number'], true);
// echo '
' . var_export(preg_split ('/( )/', $results['doc_number']), true);
// exit;
 
if($results) {
    /*
    $table[3]['date_sell'] = array(
        'width' => 16,
        'value' => 'Zamówienie klienta',
        'border' => 0,
        'overflow' => 1,
        'align' => 'L',
        'font-size' => 8,
    );

    $table[3]['date_sell_value'] = array(
        // 'width' => 36 + 16 + 4,
        'width' => 36 + 4,
        'value' =>  chunk_split($results['doc_number'], 15),
        // 'value' =>  chunk_split('Zamówienie: ' . $results['doc_number'], 35), //chunk_split($results['doc_number'], 15),
        'border' => 0,
        'overflow' => 1,
        'align' => 'L',
        'font-style' => 'b',
        'font-size' => 8,
        'valign' => 'C',
    );
    */
    
    //echo '
' . var_dump($results['doc_number'], chunk_split($results['doc_number'], 9), true); exit;
    
    $table[4]['date_sell'] = array(
        'width' => 16,
        'value' => 'Nr ZS',
        'border' => 0,
        'overflow' => 1,
        'align' => 'L',
            'font-style' => 'b',
        'font-size' => 8,
    );

    $table[5]['date_sell_value'] = array(
        'width' => 36 + 4,
        'value' => $results['number'],
        'border' => 0,
        'overflow' => 1,
        'align' => 'L',
        'font-size' => 8,
        'valign' => 'C',
    );
    
    $table[6]['date_sell'] = array(
        'width' => 16,
        'value' => 'Data ZS',
        'border' => 0,
        'overflow' => 1,
        'align' => 'L',
            'font-style' => 'b',
        'font-size' => 8,
    );

    $table[7]['date_sell_value'] = array(
        'width' => 36 + 4,
        'value' => date('d.m.Y', strtotime($results['date'])),
        'border' => 0,
        'overflow' => 1,
        'align' => 'L',
       
        'font-size' => 8,
        'valign' => 'C',
    );
}

// if ($this->ecmpaymentcondition_id) {
    // $table[2]['payment_method'] = array(
        // 'width' => 20,
        // 'value' => "Metoda płatności",
        // 'border' => 0,
        // 'overflow' => 1,
        // 'align' => 'L',
        // 'font-size' => 8,
    // );

    // $table[2]['payment_method_value'] = array(
        // 'width' => 25,
        // 'value' => $app_list_strings['ecmpaymentconditions_payment_method_dom'][$pc->payment_method],
        // 'border' => 0,
        // 'overflow' => 1,
        // 'align' => 'L',
        // 'font-style' => 'b',
        // 'font-size' => 8,
    // );
// }

$pdf->SetXY(170,5);
$pdf->DrawTable($table, null, 0.5, 0.5, 3);

$pdf->Ln(5);

$pdf->SetFont('arialpl', '', '18');
$pdf->SetXY(60, $pdf->tMargin + 25);

$pdf->MultiCell(80, 7, "Faktura nr " . $this->document_no. PHP_EOL. 'zaliczkowa', 0, 'C');
$pdf->SetFont('arialpl', '', 4);
$pdf->Ln(3);
$pdf->SetX(60);

$pdf->SetY($ynew);

$table = array();

if (!$this->currency_value) {
    $this->currency_value = 1;
}

$widths = array(
    'position' => 4,
    'description' => 30,
    'quantity' => 8,
    //'unit' => 7,
    'unit_price' => 14,
    'unit_price_total' => 15,
    'vat_id' => 8,
    'vat_value' => 14,
    'total' => 16,
    //
    'number' => 20,
    'date' => 10,
    'value' => 14 + 8,
    'fix_right' => 53,
    // 
    'fix_left' => 56,
    'rate' => 8,
    'netto' => 15,
    'vat' => 14,
    'brutto' => 16,
);

$table[0]['position'] = array(
    'background' => array(233, 233, 233),
    'width' => $widths['position'],
    'value' => "Lp.",
    'border' => 1,
    'font-style' => 'b',
    'overflow' => 1,
    'align' => 'L',
);

$table[0]['description'] = array(
    'background' => array(233, 233, 233),
    'width' => $widths['description'],
    'value' => "Nazwa",
    'border' => 1,
    'font-style' => 'b',
    'overflow' => 1,
    'align' => 'L',
);

$table[0]['quantity'] = array(
    'background' => array(233, 233, 233),
    'width' => $widths['quantity'],
    'value' => "Ilość" . PHP_EOL . 'J.m.',
    'border' => 1,
    'overflow' => 1,
    'font-style' => 'b',
    'align' => 'L',
);

/*
$table[0]['unit'] = array(
    'background' => array(233, 233, 233),
    'width' => $widths['unit'],
    'value' => "J.M.",
    'border' => 1,
    'font-style' => 'b',
    'overflow' => 1,
    'align' => 'L',
);
*/

$table[0]['unit_price'] = array(
    'background' => array(233, 233, 233),
    'width' => $widths['unit_price'],
    'value' => "Cena Netto",
    'border' => 1,
    'font-style' => 'b',
    'overflow' => 1,
    'align' => 'L',
);

$table[0]['unit_price_total'] = array(
    'background' => array(233, 233, 233),
    'width' => $widths['unit_price_total'],
    'value' => "Wartość Netto",
    'border' => 1,
    'font-style' => 'b',
    'overflow' => 1,
    'align' => 'L',
);

$table[0]['vat_id'] = array(
    'background' => array(233, 233, 233),
    'width' => $widths['vat_id'],
    'value' => "VAT (%)",
    'border' => 1,
    'font-style' => 'b',
    'overflow' => 1,
    'align' => 'L',
);

$table[0]['vat_value'] = array(
    'background' => array(233, 233, 233),
    'width' => $widths['vat_value'],
    'value' => "Wartość VAT",
    'border' => 1,
    'font-style' => 'b',
    'overflow' => 1,
    'align' => 'L',
);

$table[0]['total'] = array(
    'background' => array(233, 233, 233),
    'width' => $widths['total'],
    'value' => "Wartość Brutto",
    'border' => 1,
    'font-style' => 'b',
    'overflow' => 1,
    'align' => 'L',
);

// ~

$table[1]['position'] = array(
    'width' => $widths['position'],
    'value' => "1",
    'border' => 1,
    'font-style' => 'b',
    'overflow' => 1,
    'align' => 'L',
);

$table[1]['description'] = array(
    'width' => $widths['description'],
    'value' => $this->description,
    'border' => 1,
    'font-style' => '',
    'overflow' => 1,
    'align' => 'L',
);

$table[1]['quantity'] = array(
    'width' => $widths['quantity'],
    'value' => "1" . PHP_EOL . 'SZT.',
    'border' => 1,
    'overflow' => 1,
    'font-style' => '',
    'align' => 'R',
);

/*
$table[1]['unit'] = array(
    'width' => $widths['unit'],
    'value' => "SZT.",
    'border' => 1,
    'font-style' => '',
    'overflow' => 1,
    'align' => 'L',
);
*/

$c = new Currency();
$c->retrieve($this->currency_id);
$c->name = $c->iso4217;
$table[1]['unit_price'] = array(
    'width' => $widths['unit_price'],
    'value' => number_format(($this->inv_value / (1 + $this->ecmvat_value / 100)), 2, ",", ".") . ' ' . $c->name,
    'border' => 1,
    'font-style' => '',
    'overflow' => 1,
    'align' => 'R',
);

$table[1]['unit_price_total'] = array(
    'width' => $widths['unit_price_total'],
    'value' => number_format(($this->inv_value / (1 + $this->ecmvat_value / 100)), 2, ",", ".") . ' ' . $c->name,
    'border' => 1,
    'font-style' => '',
    'overflow' => 1,
    'align' => 'R',
);

$table[1]['vat_id'] = array(
    'width' => $widths['vat_id'],
    'value' => $this->ecmvat_name,
    'border' => 1,
    'font-style' => '',
    'overflow' => 1,
    'align' => 'C',
);

$table[1]['vat_value'] = array(
    'width' => $widths['vat_value'],
    'value' => number_format(($this->inv_value - ($this->inv_value / (1 + $this->ecmvat_value / 100))), 2, ",", ".") . " " . $c->name,
    'border' => 1,
    'font-style' => '',
    'overflow' => 1,
    'align' => 'R',
);

$table[1]['total'] = array(
    'width' => $widths['total'],
    'value' => number_format((double) $this->inv_value, 2, ",", ".") . ' ' . $c->name,
    'border' => 1,
    'font-style' => '',
    'overflow' => 1,
    'align' => 'R',
);

// echo '
' . var_export($results, true) . '
'; // exit; if($docNumber = @$results['doc_number']) { $pdf->SetFont('arialpl', '', 8); $pdf->Cell(85, 1, "Zamówienie klienta: " . $docNumber, 0, 0, 'L', 1); $pdf->Ln(3); } $pdf->DrawTable($table, array(0)); $pdf->Ln(0); $pdf->SetFont('arialpl', '', '7'); global $mod_strings; $currency = new Currency(); $currency->retrieve($this->currency_id); $this->currency_symbol = $currency->iso4217; $lv = return_app_list_strings_language($this->ecmlanguage); if ($this->ecmsale_id) { include_once("modules/EcmSales/EcmSale.php"); $sale = new EcmSale(); $sale->retrieve($this->ecmsale_id); $this->position_list = $sale->getPositionList(true); $calc = $sale->calculate($this->position_list, true); } $pdf->Ln(8); $y = $pdf->GetY(); $table = array(); $table[0]['fix'] = array( //'background' => array(233, 0, 0), 'width' => $widths['fix_left'], 'value' => '', 'border' => 0, 'overflow' => 1, ); $table[0]['netto'] = array( 'background' => array(233, 233, 233), 'width' => $widths['netto'], 'value' => "Wartość netto", 'border' => 1, 'font-style' => 'b', 'overflow' => 1, 'align' => 'L', ); $table[0]['rate'] = array( 'background' => array(233, 233, 233), 'width' => $widths['rate'], 'value' => "VAT (%)", 'border' => 1, 'font-style' => 'b', 'overflow' => 1, 'align' => 'L', ); $table[0]['vat'] = array( 'background' => array(233, 233, 233), 'width' => $widths['vat'], 'value' => "Wartość VAT", 'border' => 1, 'overflow' => 1, 'font-style' => 'b', 'align' => 'L', ); $table[0]['brutto'] = array( 'background' => array(233, 233, 233), 'width' => $widths['brutto'], 'value' => "Wartość brutto", 'border' => 1, 'font-style' => 'b', 'overflow' => 1, 'align' => 'L', ); //$pdf->SetXY(10, $y); //$pdf->MultiCell(80, 7, "Rozliczenie zaliczki wg stawek:", 0, 'L'); $pdf->SetX(10); $pdf->DrawTable($table, array(0)); $pdf->Ln(0); if (!$this->currency_value) { $this->currency_value = 1; } $table = array(); $i = 1; $table[$i]['fix'] = array( //'background' => array(233, 0, 0), 'width' => $widths['fix_left'], 'value' => '', 'border' => 0, 'overflow' => 1, ); $table[$i]['netto'] = array( 'width' => $widths['netto'], 'value' => number_format(($this->inv_value / (1 + $this->ecmvat_value / 100)), 2, ",", ".") . ' ' . $c->name, 'border' => 1, 'align' => 'R', ); $table[$i]['rate'] = array( 'width' => $widths['rate'], 'value' => $this->ecmvat_name, 'border' => 1, 'align' => 'C', ); $table[$i]['vat'] = array( 'width' => $widths['vat'], 'value' => number_format(($this->inv_value - ($this->inv_value / (1 + $this->ecmvat_value / 100))) , 2, ",", ".") . " " . $c->name, 'border' => 1, 'align' => 'R', ); $table[$i]['brutto'] = array( 'width' => $widths['brutto'], 'value' => number_format(($this->inv_value), 2, ",", ".") . " ".$c->name, 'border' => 1, 'align' => 'R', ); //$table=array(); $pdf->SetX(10); $pdf->DrawTable($table); $rzal = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select date_entered from ecmprepaymentinvoices where id='" . $this->id . "'")); $q = "select document_no,register_date,inv_value,date_entered,currency_value from ecmprepaymentinvoices where deleted='0' and ecmsale_id='" . $this->ecmsale_id . "' and date_entered<'" . $rzal['date_entered'] . "'"; $wi = $GLOBALS['db']->query($q); if (mysql_num_rows($wi) > 0) { $table = array(); $table[0]['position'] = array( 'background' => array(233, 233, 233), 'width' => $widths['position'], 'value' => "Lp.", 'border' => 1, 'font-style' => 'b', 'overflow' => 1, 'align' => 'L', ); $table[0]['number'] = array( 'background' => array(233, 233, 233), 'width' => $widths['number'], 'value' => "Numer faktury", 'border' => 1, 'font-style' => 'b', 'overflow' => 1, 'align' => 'L', ); $table[0]['date'] = array( 'background' => array(233, 233, 233), 'width' => $widths['date'], 'value' => "Data", 'border' => 1, 'overflow' => 1, 'font-style' => 'b', 'align' => 'L', ); $table[0]['value'] = array( 'background' => array(233, 233, 233), 'width' => $widths['value'], 'value' => "Wartość brutto", 'border' => 1, 'font-style' => 'b', 'overflow' => 1, 'align' => 'L', ); $table[0]['fix'] = array( //'background' => array(233, 0, 0), 'width' => $widths['fix_right'], 'value' => '', 'border' => 0, 'overflow' => 1, ); $pdf->Ln(4); $pdf->MultiCell(80, 7, "Poprzednie zaliczki:", 0, 'L'); $pdf->DrawTable($table, array(0)); $pdf->Ln(0); $table = array(); $i = 1; $lv = return_app_list_strings_language($this->ecmlanguage); $rzal = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select date_entered from ecmprepaymentinvoices where id='" . $this->id . "'")); $wi = $GLOBALS['db']->query("select document_no,register_date,inv_value,date_entered,currency_value from ecmprepaymentinvoices where deleted='0' and ecmsale_id='" . $this->ecmsale_id . "' and date_entered<'" . $rzal['date_entered'] . "'"); while ($ri = $GLOBALS['db']->fetchByAssoc($wi)) { $m++; if (!$ri['currency_value']) { $ri['currency_value'] = 1; } $sum+=$ri['inv_value'] * $ri['currency_value']; $table[$m]['position'] = array( 'width' => $widths['position'], 'value' => $m, 'border' => 1, 'align' => 'L', ); $table[$m]['number'] = array( 'width' => $widths['number'], 'value' => $ri['document_no'], 'border' => 1, 'align' => 'L', ); $table[$m]['date'] = array( 'width' => $widths['date'], 'value' => $ri['register_date'], 'border' => 1, 'align' => 'L', ); $table[$m]['value'] = array( 'width' => $widths['value'], 'value' => number_format($ri['inv_value'] * $ri['currency_value'], 2, ",", ".") . ' ' . $this->currency_symbol, 'border' => 1, 'align' => 'R', ); $table[$m]['fix'] = array( //'background' => array(233, 0, 0), 'width' => $widths['fix_right'], 'value' => '', 'border' => 0, 'overflow' => 1, ); } $table[$m + 1]['position'] = array( 'width' => $widths['position'], 'value' => "", 'border' => 0, 'align' => 'L', ); $table[$m + 1]['number'] = array( 'width' => $widths['number'], 'value' => "", 'border' => 0, 'align' => 'L', ); $table[$m + 1]['date'] = array( 'width' => $widths['date'], 'value' => "Razem", 'border' => 1, 'align' => 'R', ); $table[$m + 1]['value'] = array( 'width' => $widths['value'], 'value' => number_format($sum, 2, ",", ".") . ' ' . $this->currency_symbol, 'border' => 1, 'align' => 'R', ); $table[$m + 1]['fix'] = array( //'background' => array(233, 0, 0), 'width' => $widths['fix_right'], 'value' => '', 'border' => 0, 'overflow' => 1, ); $pdf->DrawTable($table); }