Files
crm.twinpol.com/modules/EcmDocumentTemplates/templates/EcmPrepaymentInvoices/subfooter.php
2025-05-12 15:44:39 +00:00

401 lines
10 KiB
PHP
Executable File

<?php
//return;
$pdf->Ln(8);
//if($pdf->GetY()>240)$pdf->AddPage();
$total = 0;
$pdf->SetFont('arialpl', '', '8');
include_once("modules/EcmSales/EcmSale.php");
$sale = new EcmSale();
$sale->retrieve($this->ecmsale_id);
if (strlen($this->currency_id) > 10) {
$rc = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select iso4217 from currencies where id='" . $this->currency_id . "'"));
$this->currency_id = $rc['iso4217'];
}
$w = $GLOBALS['db']->query("select inv_value,currency_value from ecmprepaymentinvoices where ecmsale_id='" . $this->ecmsale_id . "' and date_entered<'" . $this->date_entered . "'");
while ($r = $GLOBALS['db']->fetchByAssoc($w)) {
if (!$r['currency_value']) {
$r['currency_value'] = 1;
}
$total+=$r['inv_value'] * $r['currency_value'];
}
$total = format_number($sale->getTotal() - $total);
$pdf->Cell(30, 4, "Do zapłaty:", 0, 0, 'L', 1);
$pdf->SetFont('arialpl', 'B', '8');
$pdf->Cell(30, 4, format_number($this->inv_value)." ".$this->currency_id, 0, 0, 'L', 1);
$pdf->writeHTML('</b>');
$pdf->Ln(4);
$pdf->Cell(30, 4, "Zapłacono:", 0, 0, 'L', 1);
$pdf->SetFont('arialpl', 'B', '8');
$pdf->Cell(30, 4, format_number($this->inv_value). " " . $this->currency_id, 0, 0, 'L', 1);
// echo '<pre>' . var_export($this->toArray(), true);exit;
// echo '<pre>' . var_export($app_list_strings['payment_method_dom'], true);exit;
if($this->ecmpaymentcondition_name) {
$pdf->SetX(70);
$pdf->SetFont('arialpl', '', '8');
$pdf->WriteHtml($this->ecmpaymentcondition_name);
}
// $pdf->Ln(4);
// $pdf->SetFont('arialpl', '', '8');
// $pdf->Cell(30, 4, "Słownie:", 0, 0, 'L', 1);
// $pdf->SetFont('arialpl', 'B', '8');
// include_once("modules/EcmInvoiceOuts/EcmInvoiceOut.php");
// $sl = EcmInvoiceOut::slowniePL(format_number($this->inv_value));
// $pdf->Cell(150, 4, $sl . " ".$this->currency_id, 0, 0, 'L', 1);
$pdf->Ln(10);
// $inv_type = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT invoice_type FROM accounts WHERE id='".$this->parent_id."'"));
if ($this->currency_symbol != 'PLN') {
// $r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT conversion_rate FROM currencies WHERE id='6336d9a0-ee5f-52e3-7d0c-4e6f1472b2bf'"));
// $this->currency_value = $r['conversion_rate'];
$pdf->Cell(85, 1, "Kurs 1 EUR = " . format_number($this->currency_value_nbp, 4, 4) . ' PLN', 0, 0, 'L', 1);
$pdf->Ln(4);
$pdf->Cell(85, 1, "Wartość VAT = " . format_number(($this->inv_value - ($this->inv_value / (1 + $this->ecmvat_value / 100))) * $this->currency_value_nbp) . ' PLN', 0, 0, 'L', 1);
}
/*
*/
//get products
$pdf->SetFont('arialpl', '', '7');
$pdf->Ln(10);
//$pdf->Cell(85,1,"Dane dotyczące zamówienia, lub umowy",0,0,'L',1);
$pdf->Cell(85, 1, "Dane dotyczące zamówienia, lub umowy", 0, 0, 'L', 1);
$pdf->Ln(5);
$inv_prod = explode("|", $this->products_on_pdf);
$query = "SELECT * FROM `ecmsaleitems` WHERE id IN ('" . implode("','", $inv_prod) . "') order by position asc";
//echo '<pre>' . var_export($this->products_on_pdf, true) . '</pre>';
//exit;
$prod = $GLOBALS['db']->query($query);
$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]['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" . PHP_EOL . 'Waluta',
'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śc Brutto",
'border' => 1,
'font-style' => 'b',
'overflow' => 1,
'align' => 'L',
);
$i = 1;
$total = 0;
while ($p = $GLOBALS['db']->fetchByAssoc($prod)) {
// echo '<pre>'. var_export($p, true); exit;
$table[$i]['position'] = array(
'width' => $widths['position'],
'value' => $i,
'border' => 1,
'font-style' => '',
'overflow' => 1,
'align' => 'L',
);
$table[$i]['description'] = array(
'width' => $widths['description'],
'value' => $p['name'],
'border' => 1,
'font-style' => '',
'overflow' => 1,
'align' => 'L',
);
$table[$i]['quantity'] = array(
'width' => $widths['quantity'],
'value' => format_number($p['quantity'], 2) . PHP_EOL . $p['dd_unit_name'],
'border' => 1,
'overflow' => 1,
'font-style' => '',
'align' => 'R',
);
/*
$table[$i]['unit'] = array(
'width' => $widths['unit'],
'value' => $p['dd_unit_name'],
'border' => 1,
'font-style' => '',
'overflow' => 1,
'align' => 'L',
);
*/
$price = ($p['discount'] ? ($p['price']) * (1 - $p['discount'] / 100) : ($p['price']));
$price_total = $price * $p['quantity'];
$table[$i]['unit_price'] = array(
'width' => $widths['unit_price'],
// 'value' => format_number($p['price'], 2) . PHP_EOL . $p['currency_name'],
'value' => format_number($price, 2) . PHP_EOL . $p['currency_name'],
'border' => 1,
'font-style' => '',
'overflow' => 1,
'align' => 'R',
);
$table[$i]['unit_price_total'] = array(
'width' => $widths['unit_price_total'],
'value' => format_number($price_total, 2),
'border' => 1,
'font-style' => '',
'overflow' => 1,
'align' => 'R',
);
$table[$i]['vat_id'] = array(
'width' => $widths['vat_id'],
'value' => $p['ecmvat_value'].'%',
'border' => 1,
'font-style' => '',
'overflow' => 1,
'align' => 'C',
);
$vat_value = round($price_total * ($p['ecmvat_value'] / 100), 2);
$table[$i]['vat_value'] = array(
'width' => $widths['vat_value'],
'value' => format_number($vat_value, 2),
'border' => 1,
'font-style' => '',
'overflow' => 1,
'align' => 'R',
);
$table[$i]['total'] = array(
'width' => $widths['total'],
'value' => format_number($price_total + $vat_value, 2),
'border' => 1,
'font-style' => '',
'overflow' => 1,
'align' => 'R',
);
$total += $p['quantity'] * ($p['price'] + ($p['price'] * ($p['ecmvat_value']/100)));
$i++;
}
$pdf->DrawTable($table, array(0));
$pdf->Ln(0.1);
$table = array();
$table[0]['position'] = array(
'width' => $widths['position'],
'value' => '',
'border' => 0,
'font-style' => '',
'overflow' => 1,
'align' => 'L',
);
$table[0]['description'] = array(
'width' => $widths['description'],
'value' => '',
'border' => 0,
'font-style' => '',
'overflow' => 1,
'align' => 'L',
);
$table[0]['quantity'] = array(
'width' => $widths['quantity'],
'value' => '',
'border' => 0,
'overflow' => 1,
'font-style' => '',
'align' => 'L',
);
$table[0]['unit'] = array(
'width' => $widths['unit'],
'value' => '',
'border' => 0,
'font-style' => '',
'overflow' => 1,
'align' => 'L',
);
$table[0]['unit_price'] = array(
'width' => $widths['unit_price'],
'value' => '',
'border' => 0,
'font-style' => '',
'overflow' => 1,
'align' => 'L',
);
$table[0]['unit_price_total'] = array(
'width' => $widths['unit_price_total'],
'value' => '',
'border' => 0,
'font-style' => '',
'overflow' => 1,
'align' => 'L',
);
$table[0]['vat_id'] = array(
'width' => $widths['vat_id'],
'value' => '',
'border' => 0,
'font-style' => '',
'overflow' => 1,
'align' => 'L',
);
$table[0]['vat_value'] = array(
'width' => $widths['vat_value'],
'value' => 'Razem',
'border' => 1,
'font-style' => '',
'overflow' => 1,
'align' => 'R',
);
$table[0]['total'] = array(
'width' => $widths['total'],
'value' => format_number($total, 2),
'border' => 1,
'font-style' => '',
'overflow' => 1,
'align' => 'R',
);
// $pdf->DrawTable($table, array(0));
$pdf->Ln(20);
$pdf->SetX(10);
$pdf->SetFont('arialpl', '', '7');
$pdf->Cell(95, 1, "...............................................................", 0, 0, 'L', 1);
$pdf->Cell(95, 1, "...............................................................", 0, 0, 'R', 1);
$pdf->Ln(4);
$pdf->SetX(10);
$pdf->Cell(43, 1, "Podpis wystawiajacego", 0, 0, 'C', 1);
$pdf->SetX(162);
$pdf->Cell(35, 1, "Podpis odbiorcy", 0, 0, 'C', 1);
$pdf->Ln(4);
$pdf->Cell(43, 1, $this->setUser()->full_name, 0, 0, 'C', 1);
//footer text
$pdf->Ln(18);
$pdf->SetFont('arialpl', '', '8');
$pdf->MultiCell(0, 4, $this->footer_text, 0, 'J');
//header text
$pdf->Ln(6);
$pdf->SetFont('arialpl', 'B', '8');
$pdf->MultiCell(0, 4, $this->ads_text, 0, 'J');