From 8902650dcf588607eba6235e8f8d647fd6d18086 Mon Sep 17 00:00:00 2001 From: Daniel Schmitzer Date: Mon, 6 Oct 2025 04:11:27 +0000 Subject: - Karlchens Multirechnungsanpassung git-svn-id: https://[internal]/wordpress/plugins/wpsg4@8505 0d5edaf7-2b12-4e95-93f4-047927463d4b --- views/mods/mod_rechnungen/multi_invoice_pdf.phtml | 165 ++++++++++++++++++++-- 1 file changed, 157 insertions(+), 8 deletions(-) diff --git a/views/mods/mod_rechnungen/multi_invoice_pdf.phtml b/views/mods/mod_rechnungen/multi_invoice_pdf.phtml index f3d48e8..ca4cc50 100644 --- a/views/mods/mod_rechnungen/multi_invoice_pdf.phtml +++ b/views/mods/mod_rechnungen/multi_invoice_pdf.phtml @@ -34,11 +34,17 @@ // Anzahl an Produkten pro Seite $prod_break = $this->get_option('wpsg_rechnungen_pdfperpage'); - /* - $arCalculation = $this->view['basket']['arCalculation']; - $data = $this->view['multi_data']['orders'][0]['data']; - $sum = $this->view['multi_data']['orders'][0]['sum']; - */ + // Unterkante nutzbarer Bereich (297 - Margin) + $PAGE_LIMIT_MM = 290; + // bestehender Abstand nach einer Bestellung + $ORDER_SPACING = 30; + + +/* +$arCalculation = $this->view['basket']['arCalculation']; +$data = $this->view['multi_data']['orders'][0]['data']; +$sum = $this->view['multi_data']['orders'][0]['sum']; +*/ $arCalculation = array_values($this->view['multi_data']['order_data'])[0]['arCalculation']; $data = $this->view['data']; @@ -215,7 +221,141 @@ } } - + + // Hoehe einer kompletten Bestellung abschaetzen + $estimateOrderBlockHeight = function($shop, $pdf, $oOrder, $arCalculation, $bTaxCol) use ($ORDER_SPACING) { + + // Spaltenbreite für den Produkttext wie im Rendering + $produkt_text_cell_width = $bTaxCol ? 87 : 102; + + // Höhe: Kopf der Bestellung (Zähler + 3 Meta-Zeilen rechts) + // „1 Bestellung“, Bestelldatum, Zahlungsbedingungen, Best. Nr. + $h = 12; // Kopf + $h += 8; // Tabellenkopf (Nr/Name/MwSt/Menge/Einzelpreis/Gesamtpreis) + + foreach ($oOrder->getOrderProducts() as $oOrderProduct) { + $product_id = $oOrderProduct->getProductId(); + + // Produktname/Detailname wie im Code + $produkt_text = ($shop->get_option('wpsg_rechnungen_pdetailname') == '1') + ? $shop->getProductName($product_id, true) + : $shop->getProductName($product_id, false); + + // Übersetzung + if ($shop->isOtherLang()) { + $trans_db = $shop->db->fetchRow( + "SELECT * FROM `".WPSG_TBL_PRODUCTS."` WHERE `lang_parent` = '".wpsg_q($product_id)."' AND `lang_code` = '".wpsg_q($shop->getCurrentLanguageCode())."'" + ); + if (is_array($trans_db) && sizeof($trans_db) > 0) { + $produkt_text = $trans_db['name']; + } + } + + // Artikelnummer zusätzlich? + if ($shop->get_option('wpsg_mod_rechnungen_anr') === '2') { + $anr = $shop->getProductAnr($oOrderProduct->getProductKey()); + $produkt_text .= "\n".wpsg_translate(__('Artikelnummer: #1#', 'wpsg'), $anr); + } + + // Produktvariablen optional anhängen (wir rechnen Zeilenhöhe mit) + if ($shop->hasMod('wpsg_mod_productvars') && $shop->get_option("wpsg_mod_rechnungen_showpv") == "1") { + $arPV = $shop->callMod('wpsg_mod_productvars', 'getAllProductVarValues', array($oOrder->getId(), $oOrderProduct->getProductIndex())); + if (wpsg_isSizedArray($arPV)) { + foreach ($arPV as $pv) { + if ($pv['value'] != '') { + $produkt_text .= "\n".$pv['name'].': '.$pv['value']; + } + } + } + } + + // Name/Text-Zeilen (MultiCell-Schätzung) + $txt = str_replace(["\r\n", "\r"], "\n", (string)$produkt_text); + $manual = substr_count($txt, "\n") + 1; + $wrap = max(1, (int)ceil($pdf->GetStringWidth(str_replace("\n", ' ', $txt)) / $produkt_text_cell_width)); + $name_lines = max($manual, $wrap); + + $rowH = 5 * $name_lines + 3; + + // Kurzbeschreibung? + if ($shop->get_option("wpsg_rechnungen_pbeschreibung") == "1") { + $desc = trim(strip_tags($oOrderProduct->getProduct()->getShortDescription())); + if ($shop->isOtherLang() && isset($trans_db['beschreibung'])) { + $desc = trim(strip_tags($trans_db['beschreibung'])); + } + if ($desc !== '') { + $descW = $pdf->GetStringWidth($desc); + $rowH += 5 * max(1, (int)ceil($descW / $produkt_text_cell_width)); + } + } + + // Attribute? + if ($shop->get_option('wpsg_rechnungen_produktattribute') == '1') { + $attributeInfo = $shop->callMod('wpsg_mod_produktattribute', 'getProductAttributeByProductId', array($shop->getProduktId($oOrderProduct->getId()))); + if (is_array($attributeInfo)) { + foreach ($attributeInfo as $pa) { + $pa_txt = $pa['name'].': '.$pa['value']; + $paW = $pdf->GetStringWidth($pa_txt); + $rowH += 5 * max(1, (int)ceil($paW / $produkt_text_cell_width)); + } + } + } + + // Variante? + if (preg_match('/pv_(.*)/', $oOrderProduct->getProductKey())) { + $variInfo = $shop->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', array($oOrderProduct->getProductKey())); + $vtxt = wpsg_translate(__('Variante: #1#', 'wpsg'), $variInfo['key']); + $vW = $pdf->GetStringWidth($vtxt); + $rowH += 5 * max(1, (int)ceil($vW / $produkt_text_cell_width)); + } + + // Lieferdatum (bei mehreren Lieferscheinen) + if ($shop->hasMod('wpsg_mod_deliverynote')) { + $arDN_order = $shop->callMod('wpsg_mod_deliverynote', 'loadDeliveryNotesFromOrder', array($oOrder->getId())); + if (sizeof($arDN_order) > 1) { + // eine Zeile + $rowH += 5; + } + } + + $h += $rowH; + } + + // Gutschein(e) + if (!empty($arCalculation['voucher']) && is_array($arCalculation['voucher'])) { + $h += 8 * count($arCalculation['voucher']); + } + + // Versandkosten + if (!empty($arCalculation['sum']['shipping_brutto']) && $arCalculation['sum']['shipping_brutto'] > 0) { + $h += 8; + } + + // Zahlungskosten + $cost_payment = ((wpsg_ShopController::getShop()->getFrontendTaxview() === WPSG_BRUTTO) + ? ($arCalculation['sum']['payment_brutto'] ?? 0) + : ($arCalculation['sum']['payment_netto'] ?? 0)); + if ($cost_payment > 0) { $h += 8; } + + // Rabatt + if (!empty($arCalculation['sum']['discount_brutto']) && $arCalculation['sum']['discount_brutto'] < 0) { + $h += 8; + } + + // Wertgutscheine (coupon) + if (!empty($arCalculation['coupon']) && is_array($arCalculation['coupon'])) { + $h += 8 * count($arCalculation['coupon']); + } + + // „Bestellbetrag …“ Block (Text + Zahl) + $h += 10; + + // Abstand zur nächsten Bestellung + $h += $ORDER_SPACING?(int)$ORDER_SPACING:30; + + return $h; + }; + // FOREACH ORDER START foreach ($this->view['multi_data']['order_data'] as $order_data) { @@ -224,7 +364,16 @@ /** @var \wpsg\wpsg_calculation $arCalculation */ $arCalculation = $order_data['arCalculation']; - + + $currentTop = $prod_top + $sum_multi_offset; + $need = $estimateOrderBlockHeight($this, $pdf, $oOrder, $arCalculation, $bTaxCol); + + if (($currentTop + $need) > $PAGE_LIMIT_MM) { + AddRechnungPage($this, $pdf); + $sum_multi_offset = 0; // Bestellung startet oben auf der neuen Seite + $currentTop = $prod_top; // (nur zur Vollständigkeit) + } + // Sammelrechnung Zähler $pdf->SetFont('Arial', 'B', 12); $pdf->Text($rhead_left, $rhead_top + $sum_multi_offset, $rhead_count); @@ -479,7 +628,7 @@ $bKopf = false; $count = 0; $offset = 0; } - + } // produkte // Gutschein -- cgit v1.2.3