From dc9b8c81f9173f71c585abdc48aa0350f93fcce1 Mon Sep 17 00:00:00 2001 From: avogt Date: Sat, 1 Jun 2013 13:34:43 +0200 Subject: [PATCH 01/13] #28: manually merged --- .../Pdf/Block/Adminhtml/ColumnOrder.php | 113 ++++++++++++++++ .../Pdf/Model/Engine/Invoice/Default.php | 68 +++++++--- .../FireGento/Pdf/Model/Items/Default.php | 124 +++++++++++++----- .../community/FireGento/Pdf/etc/config.xml | 14 +- .../community/FireGento/Pdf/etc/system.xml | 17 +++ app/locale/de_DE/FireGento_Pdf.csv | 12 +- 6 files changed, 296 insertions(+), 52 deletions(-) create mode 100644 app/code/community/FireGento/Pdf/Block/Adminhtml/ColumnOrder.php diff --git a/app/code/community/FireGento/Pdf/Block/Adminhtml/ColumnOrder.php b/app/code/community/FireGento/Pdf/Block/Adminhtml/ColumnOrder.php new file mode 100644 index 0000000..e49a3a4 --- /dev/null +++ b/app/code/community/FireGento/Pdf/Block/Adminhtml/ColumnOrder.php @@ -0,0 +1,113 @@ + + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class Firegento_Pdf_Block_Adminhtml_ColumnOrder + extends Mage_Adminhtml_Block_System_Config_Form_Field +{ + protected $sortableListHtml = ''; + + protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) + { + return ' + +

' . $this->__('Define the order by moving the following items using your mouse:') . '

+

+ + + '; + } + + protected function _getSortableListHtml(Varien_Data_Form_Element_Abstract $element) + { + $availableItems = array( + 'price_incl_tax' => array('width' => 60, 'label' => $this->__('Price (incl. tax)')), + 'price' => array('width' => 60, 'label' => $this->__('Price')), + 'qty' => array('width' => 40, 'label' => $this->__('Qty')), + 'subtotal_incl_tax' => array('width' => 70, 'label' => $this->__('Subtotal (incl. tax)')), + 'subtotal' => array('width' => 50, 'label' => $this->__('Subtotal')), + 'tax' => array('width' => 50, 'label' => $this->__('Tax amount')), + 'tax_rate' => array('width' => 50, 'label' => $this->__('Tax rate')), + ); + $activeItems = array(); + foreach (explode(',', $element->getValue()) as $item) { + $item = trim($item); + if (array_key_exists($item, $availableItems)) { + $activeItems[$item] = $availableItems[$item]; + unset($availableItems[$item]); + } + } + + $this->_addListItems($activeItems); + $this->sortableListHtml .= '
  • + +
    + ' . $this->__('not to be listed') . ' +
  • '; + $this->_addListItems($availableItems); + + return $this->sortableListHtml; + } + + protected function _addListItems($items) + { + foreach ($items as $name=>$item) { + $this->sortableListHtml .= sprintf( + '
  • %s
  • ', + $name, + $name, + $item['width'], + $item['label'] + ); + } + return $this; + } +} \ No newline at end of file diff --git a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php index 6042f41..4d10a0b 100644 --- a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php +++ b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php @@ -92,7 +92,7 @@ public function getPdf($invoices = array()) $this->y = 562; $this->insertTableHeader($page); - $this->y -=20; + $this->y -= 20; $position = 0; @@ -142,20 +142,58 @@ protected function insertTableHeader(&$page) $font = $this->_setFontRegular($page, 9); $this->y -= 11; - $page->drawText(Mage::helper('firegento_pdf')->__('Pos'), $this->margin['left'] + 3, $this->y, $this->encoding); - $page->drawText(Mage::helper('firegento_pdf')->__('No.'), $this->margin['left'] + 25, $this->y, $this->encoding); - $page->drawText(Mage::helper('firegento_pdf')->__('Description'), $this->margin['left'] + 120, $this->y, $this->encoding); - - $singlePrice = Mage::helper('firegento_pdf')->__('Price (excl. tax)'); - $page->drawText($singlePrice, $this->margin['right'] - 153 - $this->widthForStringUsingFontSize($singlePrice, $font, 9), $this->y, $this->encoding); - - $page->drawText(Mage::helper('firegento_pdf')->__('Qty'), $this->margin['left'] + 360, $this->y, $this->encoding); - - $taxLabel = Mage::helper('firegento_pdf')->__('Tax'); - $page->drawText($taxLabel, $this->margin['right'] - 65 - $this->widthForStringUsingFontSize($taxLabel, $font, 9), $this->y, $this->encoding); - - $totalLabel = Mage::helper('firegento_pdf')->__('Total'); - $page->drawText($totalLabel, $this->margin['right'] - 10 - $this->widthForStringUsingFontSize($totalLabel, $font, 10), $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('Pos'), $this->margin['left'] + 3, $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('No.'), $this->margin['left'] + 25, $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('Description'), $this->margin['left'] + 120, $this->y, $this->encoding); + + $columns = array(); + $columns['price'] = array( + 'label' => Mage::helper('firegento_pdf')->__('Price'), + '_width' => 60 + ); + $columns['price_incl_tax'] = array( + 'label' => Mage::helper('firegento_pdf')->__('Price (incl. tax)'), + '_width' => 60 + ); + $columns['qty'] = array( + 'label' => Mage::helper('firegento_pdf')->__('Qty'), + '_width' => 40 + ); + $columns['tax'] = array( + 'label' => Mage::helper('firegento_pdf')->__('Tax'), + '_width' => 50 + ); + $columns['tax_rate'] = array( + 'label' => Mage::helper('firegento_pdf')->__('Tax rate'), + '_width' => 50 + ); + $columns['subtotal'] = array( + 'label' => Mage::helper('firegento_pdf')->__('Total'), + '_width' => 50 + ); + $columns['subtotal_incl_tax'] = array( + 'label' => Mage::helper('firegento_pdf')->__('Total (incl. tax)'), + '_width' => 70 + ); + // draw price, tax, and subtotal in specified order + $columnsOrder = explode(',', Mage::getStoreConfig('sales_pdf/invoice/item_price_column_order')); + // draw starting from right + $columnsOrder = array_reverse($columnsOrder); + $columnOffset = 0; + foreach ($columnsOrder as $columnName) { + $columnName = trim($columnName); + if (array_key_exists($columnName, $columns)) { + $column = $columns[$columnName]; + $labelWidth = $this->widthForStringUsingFontSize($column['label'], $font, 9); + $page->drawText( + $column['label'], + $this->margin['right'] - $columnOffset - $labelWidth, + $this->y, + +$this->encoding + ); + $columnOffset += $column['_width']; + } + } } /** diff --git a/app/code/community/FireGento/Pdf/Model/Items/Default.php b/app/code/community/FireGento/Pdf/Model/Items/Default.php index 0f204b0..4d7e13e 100644 --- a/app/code/community/FireGento/Pdf/Model/Items/Default.php +++ b/app/code/community/FireGento/Pdf/Model/Items/Default.php @@ -41,44 +41,36 @@ class FireGento_Pdf_Model_Items_Default extends Mage_Sales_Model_Order_Pdf_Items */ public function draw($position = 1) { - $order = $this->getOrder(); - $item = $this->getItem(); - $pdf = $this->getPdf(); - $page = $this->getPage(); - $lines = array(); + $order = $this->getOrder(); + $item = $this->getItem(); + $pdf = $this->getPdf(); + $page = $this->getPage(); + $lines = array(); $fontSize = 9; // draw Position Number - $lines[0]= array(array( - 'text' => $position, - 'feed' => $pdf->margin['left'] + 10, + $lines[0] = array(array( + 'text' => $position, + 'feed' => $pdf->margin['left'] + 10, 'align' => 'right', 'font_size' => $fontSize )); // draw SKU $lines[0][] = array( - 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 17), - 'feed' => $pdf->margin['left'] + 25, + 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 17), + 'feed' => $pdf->margin['left'] + 25, 'font_size' => $fontSize ); // draw Product name - $lines[0][]= array( + $lines[0][] = array( 'text' => Mage::helper('core/string')->str_split($item->getName(), 40, true, true), 'feed' => $pdf->margin['left'] + 120, 'font_size' => $fontSize ); - // draw QTY - $lines[0][] = array( - 'text' => $item->getQty() * 1, - 'feed' => $pdf->margin['right'] - 120, - 'align' => 'right', - 'font_size' => $fontSize - ); - $options = $this->getItemOptions(); if ($options) { foreach ($options as $option) { @@ -103,36 +95,98 @@ public function draw($position = 1) } } - // draw Price - $lines[0][] = array( - 'text' => $order->formatPriceTxt($item->getPrice()), - 'feed' => $pdf->margin['right'] - 160, + $columns = array(); + // prepare qty + $columns['qty'] = array( + 'text' => $item->getQty() * 1, 'align' => 'right', - 'font_size' => $fontSize + 'font_size' => $fontSize, + '_width' => 40 ); - // draw Tax - $lines[0][] = array( - 'text' => $order->formatPriceTxt($item->getTaxAmount()), - 'feed' => $pdf->margin['right'] - 60, + // prepare price + $columns['price'] = array( + 'text' => $order->formatPriceTxt($item->getPrice()), 'align' => 'right', - 'font_size' => $fontSize + 'font_size' => $fontSize, + '_width' => 60 ); - // draw Subtotal - $lines[0][] = array( + // prepare price_incl_tax + $columns['price_incl_tax'] = array( + 'text' => $order->formatPriceTxt($item->getPriceInclTax()), + 'align' => 'right', + 'font_size' => $fontSize, + '_width' => 60 + ); + + // prepare tax + $columns['tax'] = array( + 'text' => $order->formatPriceTxt($item->getTaxAmount()), + 'align' => 'right', + 'font_size' => $fontSize, + '_width' => 50 + ); + + // prepare tax_rate + $columns['tax_rate'] = array( + 'text' => round($item->getOrderItem()->getTaxPercent(), 2) . '%', + 'align' => 'right', + 'font_size' => $fontSize, + '_width' => 50 + ); + + // prepare subtotal + $columns['subtotal'] = array( + 'text' => $order->formatPriceTxt($item->getPrice() * $item->getQty() * 1), + 'align' => 'right', + 'font_size' => $fontSize, + '_width' => 50 + ); + + // prepare subtotal_incl_tax + $columns['subtotal_incl_tax'] = array( 'text' => $order->formatPriceTxt(($item->getPrice() * $item->getQty() * 1) + $item->getTaxAmount()), - 'feed' => $pdf->margin['right'] - 10, 'align' => 'right', - 'font_size' => $fontSize + 'font_size' => $fontSize, + '_width' => 70 ); + // draw columns in specified order + $columnsOrder = explode(',', Mage::getStoreConfig('sales_pdf/invoice/item_price_column_order')); + // draw starting from right + $columnsOrder = array_reverse($columnsOrder); + $columnOffset = 0; + foreach ($columnsOrder as $columnName) { + $columnName = trim($columnName); + if (array_key_exists($columnName, $columns)) { + $column = $columns[$columnName]; + $column['feed'] = $pdf->margin['right'] - $columnOffset; + $columnOffset += $column['_width']; + unset($column['_width']); + $lines[0][] = $column; + } + } + + if (Mage::getStoreConfig('sales_pdf/invoice/show_item_discount') && 0 < $item->getDiscountAmount()) { + // print discount + $text = Mage::helper('firegento_pdf')->__( + 'You get a discount of %s.', + $order->formatPriceTxt($item->getDiscountAmount()) + ); + $lines[][] = array( + 'text' => $text, + 'align' => 'right', + 'feed' => $pdf->margin['right'] - $columnOffset + ); + } + $lineBlock = array( - 'lines' => $lines, + 'lines' => $lines, 'height' => 15 ); $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true)); $this->setPage($page); } -} +} \ No newline at end of file diff --git a/app/code/community/FireGento/Pdf/etc/config.xml b/app/code/community/FireGento/Pdf/etc/config.xml index 27c4137..389d2c7 100644 --- a/app/code/community/FireGento/Pdf/etc/config.xml +++ b/app/code/community/FireGento/Pdf/etc/config.xml @@ -2,10 +2,15 @@ - 0.1.0 + 1.0.0 + + + FireGento_Pdf_Block + + FireGento_Pdf_Helper @@ -73,4 +78,11 @@ + + + + price_incl_tax,qty,tax,subtotal_incl_tax + + + diff --git a/app/code/community/FireGento/Pdf/etc/system.xml b/app/code/community/FireGento/Pdf/etc/system.xml index 7404bac..71a721c 100644 --- a/app/code/community/FireGento/Pdf/etc/system.xml +++ b/app/code/community/FireGento/Pdf/etc/system.xml @@ -66,6 +66,23 @@ 1 Printed on every invoice. + + + firegento_pdf/adminhtml_columnOrder + 5 + 1 + 1 + 1 + + + + select + adminhtml/system_config_source_yesno + 10 + 1 + 1 + 1 + diff --git a/app/locale/de_DE/FireGento_Pdf.csv b/app/locale/de_DE/FireGento_Pdf.csv index 30a2ef2..77342f6 100644 --- a/app/locale/de_DE/FireGento_Pdf.csv +++ b/app/locale/de_DE/FireGento_Pdf.csv @@ -66,4 +66,14 @@ "Position of payment method on invoice.","Position der Zahlungart auf der Rechnung." "Show Shipping Method","Versandart andrucken" "Hide shipping method","Nicht andrucken" -"Position of shipping method on invoice.","Position der Versandart auf der Rechnung." \ No newline at end of file +"Position of shipping method on invoice.","Position der Versandart auf der Rechnung." +"not to be listed","nicht aufzulisten" +"Show Item Discount","Rabatt auf Artikelebene anzeigen" +"You get a discount of %s.","Sie erhalten einen Rabatt von %s." +"Tax amount","Steuerbetrag" +"Price (incl. tax)","Preis (Brutto)" +"Subtotal (incl. tax)","Zwischensumme (Brutto)" +"Order of price columns of items","Reihenfolge der Spalten in der Artikelliste" +"Define the order by moving the following items using your mouse:","Legen Sie die Reihenfolge durch Verschieben der Einträge mit der Maus fest:" +"Tax rate","Steuersatz" +"Total (incl. tax)","Gesamt (brutto)" \ No newline at end of file From 0b9da464f53601689705b6e1efc3e99a5bb9456a Mon Sep 17 00:00:00 2001 From: avogt Date: Sat, 1 Jun 2013 13:41:02 +0200 Subject: [PATCH 02/13] #28: typo fix --- .../community/FireGento/Pdf/Model/Engine/Invoice/Default.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php index 4d10a0b..1ade73e 100644 --- a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php +++ b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php @@ -189,7 +189,7 @@ protected function insertTableHeader(&$page) $column['label'], $this->margin['right'] - $columnOffset - $labelWidth, $this->y, - +$this->encoding + $this->encoding ); $columnOffset += $column['_width']; } From f71f95af51fc81e5beef07f5e9b29c1f9fb15e89 Mon Sep 17 00:00:00 2001 From: avogt Date: Sat, 1 Jun 2013 15:39:12 +0200 Subject: [PATCH 03/13] #21: fixed last issue from list --- .../FireGento/Pdf/Model/Abstract.php | 206 +++++++++--------- .../Pdf/Model/Engine/Invoice/Default.php | 3 +- .../FireGento/Pdf/Model/Shipment.php | 2 +- 3 files changed, 107 insertions(+), 104 deletions(-) diff --git a/app/code/community/FireGento/Pdf/Model/Abstract.php b/app/code/community/FireGento/Pdf/Model/Abstract.php index ab36e00..b813187 100644 --- a/app/code/community/FireGento/Pdf/Model/Abstract.php +++ b/app/code/community/FireGento/Pdf/Model/Abstract.php @@ -68,7 +68,7 @@ public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSett if (!isset($itemsProp['lines']) || !is_array($itemsProp['lines'])) { Mage::throwException(Mage::helper('sales')->__('Invalid draw line data. Please define "lines" array')); } - $lines = $itemsProp['lines']; + $lines = $itemsProp['lines']; $height = isset($itemsProp['height']) ? $itemsProp['height'] : 10; if (empty($itemsProp['shift'])) { @@ -92,19 +92,18 @@ public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSett $itemsProp['shift'] = $shift; } - if ($this->y - $itemsProp['shift'] < 100) { + if ($this->y - $itemsProp['shift'] < 50 || (Mage::getStoreConfig('sales_pdf/firegento_pdf/show_footer') == 1 && $this->y - $itemsProp['shift'] < 100)) { $page = $this->newPage($pageSettings); } foreach ($lines as $line) { $maxHeight = 0; foreach ($line as $column) { - $fontSize = empty($column['font_size']) ? 7 : $column['font_size']; + $fontSize = empty($column['font_size']) ? 7 : $column['font_size']; if (!empty($column['font_file'])) { $font = Zend_Pdf_Font::fontWithPath($column['font_file']); $page->setFont($font, $fontSize); - } - else { + } else { $fontStyle = empty($column['font']) ? 'regular' : $column['font']; switch ($fontStyle) { case 'bold': @@ -133,8 +132,7 @@ public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSett case 'right': if ($width) { $feed = $this->getAlignRight($part, $feed, $width, $font, $fontSize); - } - else { + } else { $feed = $feed - $this->widthForStringUsingFontSize($part, $font, $fontSize); } break; @@ -144,7 +142,7 @@ public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSett } break; } - $page->drawText($part, $feed, $this->y-$top, 'UTF-8'); + $page->drawText($part, $feed, $this->y - $top, 'UTF-8'); $top += $lineSpacing; } @@ -227,9 +225,9 @@ protected function insertLogo(&$page, $store = null) $logoPosition = Mage::getStoreConfig('sales_pdf/firegento_pdf/logo_position', $store); - switch($logoPosition) { + switch ($logoPosition) { case 'center': - $startLogoAt = $this->margin['left'] + ( ($this->margin['right'] - $this->margin['left']) / 2 ) - $width / 2; + $startLogoAt = $this->margin['left'] + (($this->margin['right'] - $this->margin['left']) / 2) - $width / 2; break; case 'right': $startLogoAt = $this->margin['right'] - $width; @@ -281,44 +279,42 @@ protected function insertHeader(&$page, $order, $document) $this->_setFontBold($page, 15); - $page->drawText(Mage::helper('firegento_pdf')->__( ($mode == 'invoice') ? 'Invoice' : 'Creditmemo' ), $this->margin['left'], $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice' : 'Creditmemo'), $this->margin['left'], $this->y, $this->encoding); $this->_setFontRegular($page); $this->y += 80; - $rightoffset = 180; + $labelRightOffset = 180; - $page->drawText(Mage::helper('firegento_pdf')->__( ($mode == 'invoice') ? 'Invoice number:' : 'Creditmemo number:' ), ($this->margin['right'] - $rightoffset), $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice number:' : 'Creditmemo number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $this->Ln(); $yPlus = 15; $putOrderId = $this->_putOrderId($order); if ($putOrderId) { - $page->drawText(Mage::helper('firegento_pdf')->__('Order number:'), ($this->margin['right'] - $rightoffset), $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('Order number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $this->Ln(); $yPlus += 15; } - if ($order->getCustomerId() != '') { - $page->drawText(Mage::helper('firegento_pdf')->__('Customer number:'), ($this->margin['right'] - $rightoffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - } + $page->drawText(Mage::helper('firegento_pdf')->__('Customer number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); + $this->Ln(); + $yPlus += 15; if (!Mage::getStoreConfigFlag('sales/general/hide_customer_ip', $order->getStoreId())) { - $page->drawText(Mage::helper('firegento_pdf')->__('Customer IP:'), ($this->margin['right'] - $rightoffset), $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('Customer IP:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $this->Ln(); $yPlus += 15; } - $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice date:' : 'Date:'), ($this->margin['right'] - $rightoffset), $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice date:' : 'Date:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $this->Ln(); $yPlus += 15; // Draw payment method. $putPaymentMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/payment_method_position') == FireGento_Pdf_Model_System_Config_Source_Payment::POSITION_HEADER); if ($putPaymentMethod) { - $page->drawText(Mage::helper('firegento_pdf')->__('Payment method:'), ($this->margin['right'] - $rightoffset), $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('Payment method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $this->Ln(); $yPlus += 15; } @@ -326,22 +322,22 @@ protected function insertHeader(&$page, $order, $document) // Draw shipping method. $putShippingMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/shipping_method_position') == FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_HEADER); if ($putShippingMethod) { - $page->drawText(Mage::helper('firegento_pdf')->__('Shipping method:'), ($this->margin['right'] - $rightoffset), $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('Shipping method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $this->Ln(); $yPlus += 15; } $this->y += $yPlus; - $rightoffset = 10; + $valueRightOffset = 10; $font = $this->_setFontRegular($page, 10); $incrementId = $document->getIncrementId(); - $page->drawText($incrementId, ($this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($incrementId, $font, 10)), $this->y, $this->encoding); + $page->drawText($incrementId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($incrementId, $font, 10)), $this->y, $this->encoding); $this->Ln(); if ($putOrderId) { - $page->drawText($putOrderId, ($this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($putOrderId, $font, 10)), $this->y, $this->encoding); + $page->drawText($putOrderId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($putOrderId, $font, 10)), $this->y, $this->encoding); $this->Ln(); } @@ -350,39 +346,51 @@ protected function insertHeader(&$page, $order, $document) $prefix = Mage::getStoreConfig('sales_pdf/invoice/customeridprefix'); if (!empty($prefix)) { - $customerid = $prefix.$order->getCustomerId(); + $customerid = $prefix . $order->getCustomerId(); } else { $customerid = $order->getCustomerId(); } - $page->drawText($customerid, ($this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($customerid, $font, 10)), $this->y, $this->encoding); + $page->drawText($customerid, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($customerid, $font, 10)), $this->y, $this->encoding); $this->Ln(); - }else{ - $page->drawText('-', ($this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize('-', $font, 10)), $this->y, $this->encoding); + } else { + $page->drawText('-', ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize('-', $font, 10)), $this->y, $this->encoding); $this->Ln(); } if (!Mage::getStoreConfigFlag('sales/general/hide_customer_ip', $order->getStoreId())) { $customerIP = $order->getData('remote_ip'); $font = $this->_setFontRegular($page, 10); - $page->drawText($customerIP, ($this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($customerIP, $font, 10)), $this->y, $this->encoding); + $page->drawText($customerIP, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($customerIP, $font, 10)), $this->y, $this->encoding); $this->Ln(); } $documentDate = Mage::helper('core')->formatDate($document->getCreatedAtDate(), 'medium', false); - $page->drawText($documentDate, ($this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($documentDate, $font, 10)), $this->y, $this->encoding); + $page->drawText($documentDate, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($documentDate, $font, 10)), $this->y, $this->encoding); $this->Ln(); + $width = 80; + if ($putPaymentMethod) { - $paymentMethod = $order->getPayment()->getMethodInstance()->getTitle(); - $page->drawText($paymentMethod, ($this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($paymentMethod, $font, 10)), $this->y, $this->encoding); + $paymentMethodArray = $this->_stringToArray($order->getPayment()->getMethodInstance()->getTitle(), $page, $font, 10, $width); + $page->drawText(array_shift($paymentMethodArray), ($this->margin['right'] - $valueRightOffset - $width), $this->y, $this->encoding); $this->Ln(); + $paymentMethodArray = $this->_prepareText(implode(" ", $paymentMethodArray), $page, $font, 10, 2 * $width); + foreach ($paymentMethodArray as $methodString) { + $page->drawText($methodString, $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); + $this->Ln(); + } } if ($putShippingMethod) { - $shippingMethod = $order->getShippingDescription(); - $page->drawText($shippingMethod, ($this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($shippingMethod, $font, 10)), $this->y, $this->encoding); + $shippingMethodArray = $this->_prepareText($order->getShippingDescription(), $page, $font, 10, $width); + $page->drawText(array_shift($shippingMethodArray), ($this->margin['right'] - $valueRightOffset - $width), $this->y, $this->encoding); $this->Ln(); + $shippingMethodArray = $this->_prepareText(implode(" ", $shippingMethodArray), $page, $font, 10, 2 * $width); + foreach ($shippingMethodArray as $methodString) { + $page->drawText($methodString, $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); + $this->Ln(); + } } } @@ -452,7 +460,7 @@ protected function _drawItem(Varien_Object $item, Zend_Pdf_Page $page, Mage_Sale */ protected function insertTotals($page, $source) { - $this->y -=15; + $this->y -= 15; $order = $source->getOrder(); @@ -460,8 +468,8 @@ protected function insertTotals($page, $source) $shippingTaxRate = 0; $shippingTaxAmount = $order->getShippingTaxAmount(); - if($shippingTaxAmount > 0) { - $shippingTaxRate = $order->getShippingTaxAmount()*100/($order->getShippingInclTax()-$order->getShippingTaxAmount()); + if ($shippingTaxAmount > 0) { + $shippingTaxRate = $order->getShippingTaxAmount() * 100 / ($order->getShippingInclTax() - $order->getShippingTaxAmount()); } $groupedTax = array(); @@ -475,10 +483,10 @@ protected function insertTotals($page, $source) } array_push($items['items'], array( - 'row_invoiced' => $order->getShippingInvoiced(), + 'row_invoiced' => $order->getShippingInvoiced(), 'tax_inc_subtotal' => false, - 'tax_percent' => $shippingTaxRate, - 'tax_amount' => $shippingTaxAmount + 'tax_percent' => $shippingTaxRate, + 'tax_amount' => $shippingTaxAmount )); foreach ($items['items'] as $item) { @@ -487,13 +495,13 @@ protected function insertTotals($page, $source) if (!isset($item['row_invoiced'])) $item['row_invoiced'] = 0; if (!isset($item['price'])) $item['price'] = 0; if (!isset($item['tax_inc_subtotal'])) $item['tax_inc_subtotal'] = 0; - if (((float)$item['tax_amount'] > 0)&&((float)$item['row_invoiced'] > 0)) { - $_percent = round($item["tax_percent"],0); + if (((float)$item['tax_amount'] > 0) && ((float)$item['row_invoiced'] > 0)) { + $_percent = round($item["tax_percent"], 0); } if (!array_key_exists('tax_inc_subtotal', $item) || $item['tax_inc_subtotal']) { $total_tax += $item['tax_amount']; } - if (($item['tax_amount'])&&$_percent){ + if (($item['tax_amount']) && $_percent) { if (!array_key_exists((int)$_percent, $groupedTax)) { $groupedTax[$_percent] = $item['tax_amount']; } else { @@ -505,7 +513,7 @@ protected function insertTotals($page, $source) $totals = $this->_getTotalsList($source); $lineBlock = array( - 'lines' => array(), + 'lines' => array(), 'height' => 20 ); @@ -516,7 +524,7 @@ protected function insertTotals($page, $source) } $fontWeight = (isset($total['font_weight']) ? $total['font_weight'] : 'regular'); - switch($total['source_field']) { + switch ($total['source_field']) { case 'tax_amount': foreach ($groupedTax as $taxRate => $taxValue) { if (empty($taxValue)) { @@ -525,18 +533,18 @@ protected function insertTotals($page, $source) $lineBlock['lines'][] = array( array( - 'text' => Mage::helper('firegento_pdf')->__('Additional tax %s', $source->getStore()->roundPrice(number_format($taxRate, 0)).'%'), - 'feed' => $this->margin['left'] + 320, - 'align' => 'left', + 'text' => Mage::helper('firegento_pdf')->__('Additional tax %s', $source->getStore()->roundPrice(number_format($taxRate, 0)) . '%'), + 'feed' => $this->margin['left'] + 320, + 'align' => 'left', 'font_size' => $fontSize, - 'font' => $fontWeight + 'font' => $fontWeight ), array( - 'text' => $order->formatPriceTxt($taxValue), - 'feed' => $this->margin['right'] - 10, - 'align' => 'right', + 'text' => $order->formatPriceTxt($taxValue), + 'feed' => $this->margin['right'] - 10, + 'align' => 'right', 'font_size' => $fontSize, - 'font' => $fontWeight + 'font' => $fontWeight ), ); } @@ -557,18 +565,18 @@ protected function insertTotals($page, $source) $lineBlock['lines'][] = array( array( - 'text' => $label, - 'feed' => $this->margin['left'] + 320, - 'align' => 'left', + 'text' => $label, + 'feed' => $this->margin['left'] + 320, + 'align' => 'left', 'font_size' => $fontSize, - 'font' => $fontWeight + 'font' => $fontWeight ), array( - 'text' => $amount, - 'feed' => $this->margin['right'] - 10, - 'align' => 'right', + 'text' => $amount, + 'feed' => $this->margin['right'] - 10, + 'align' => 'right', 'font_size' => $fontSize, - 'font' => $fontWeight + 'font' => $fontWeight ), ); } @@ -589,18 +597,18 @@ protected function insertTotals($page, $source) $lineBlock['lines'][] = array( array( - 'text' => Mage::helper('firegento_pdf')->__('Shipping:'), - 'feed' => $this->margin['left'] + 320, - 'align' => 'left', + 'text' => Mage::helper('firegento_pdf')->__('Shipping:'), + 'feed' => $this->margin['left'] + 320, + 'align' => 'left', 'font_size' => $fontSize, - 'font' => $fontWeight + 'font' => $fontWeight ), array( - 'text' => $amount, - 'feed' => $this->margin['right'] - 10, - 'align' => 'right', + 'text' => $amount, + 'feed' => $this->margin['right'] - 10, + 'align' => 'right', 'font_size' => $fontSize, - 'font' => $fontWeight + 'font' => $fontWeight ), ); } @@ -621,18 +629,18 @@ protected function insertTotals($page, $source) $lineBlock['lines'][] = array( array( - 'text' => $label, - 'feed' => $this->margin['left'] + 320, - 'align' => 'left', + 'text' => $label, + 'feed' => $this->margin['left'] + 320, + 'align' => 'left', 'font_size' => $fontSize, - 'font' => $fontWeight + 'font' => $fontWeight ), array( - 'text' => $amount, - 'feed' => $this->margin['right'] - 10, - 'align' => 'right', + 'text' => $amount, + 'feed' => $this->margin['right'] - 10, + 'align' => 'right', 'font_size' => $fontSize, - 'font' => $fontWeight + 'font' => $fontWeight ), ); } @@ -653,18 +661,18 @@ protected function insertTotals($page, $source) $lineBlock['lines'][] = array( array( - 'text' => $label, - 'feed' => $this->margin['left'] + 320, - 'align' => 'left', + 'text' => $label, + 'feed' => $this->margin['left'] + 320, + 'align' => 'left', 'font_size' => $fontSize, - 'font' => $fontWeight + 'font' => $fontWeight ), array( - 'text' => $amount, - 'feed' => $this->margin['right'] - 10, - 'align' => 'right', + 'text' => $amount, + 'feed' => $this->margin['right'] - 10, + 'align' => 'right', 'font_size' => $fontSize, - 'font' => $fontWeight + 'font' => $fontWeight ), ); } @@ -709,11 +717,9 @@ protected function _insertNote($page, &$order, &$model) // Draw notes on PDF. foreach ($notes as $note) { // prepare the text so that it fits to the paper - $note = $this->_prepareText($note, $page, $font, $fontSize); - $tmpNotes = explode("\n", $note); - foreach ($tmpNotes as $tmpNote) { + foreach ($this->_prepareText($note, $page, $font, 10) as $tmpNote) { // create a new page if necessary - if ($this->y < 100) { + if ($this->y < 50 || (Mage::getStoreConfig('sales_pdf/firegento_pdf/show_footer') == 1 && $this->y < 100)) { $page = $this->newPage(array()); $this->y = $this->y - 60; $font = $this->_setFontRegular($page, $fontSize); @@ -836,20 +842,20 @@ protected function _insertFooterBlock(&$page, $fields, $colposition = 0, $valadj */ protected function _insertFooterAddress(&$page, $store = null) { - $address = $this->imprint['company_first']."\n"; + $address = $this->imprint['company_first'] . "\n"; if (array_key_exists('company_second', $this->imprint)) { $address .= $this->imprint['company_second'] . "\n"; } - $address .= $this->imprint['street']."\n"; - $address .= $this->imprint['zip']." "; - $address .= $this->imprint['city']."\n"; + $address .= $this->imprint['street'] . "\n"; + $address .= $this->imprint['zip'] . " "; + $address .= $this->imprint['city'] . "\n"; $this->_setFontRegular($page, 7); $y = $this->y; foreach (explode("\n", $address) as $value) { - if ($value!=='') { + if ($value !== '') { $page->drawText(trim(strip_tags($value)), $this->margin['left'] - 20, $y, $this->encoding); $y -= 12; } @@ -865,7 +871,7 @@ protected function _insertFooterAddress(&$page, $store = null) protected function _insertPageCounter(&$page) { $font = $this->_setFontRegular($page, 9); - $page->drawText(Mage::helper('firegento_pdf')->__('Page').' '.$this->pagecounter, $this->margin['right'] - 23 - $this->widthForStringUsingFontSize($this->pagecounter, $font, 9), $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('Page') . ' ' . $this->pagecounter, $this->margin['right'] - 23 - $this->widthForStringUsingFontSize($this->pagecounter, $font, 9), $this->y, $this->encoding); } /** @@ -945,8 +951,6 @@ protected function _prepareText($text, $page, $font, $fontSize, $width = null) } // append the last line $lines .= $currentLine; - return $lines; + return explode("\n", $lines); } - -} - +} \ No newline at end of file diff --git a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php index 1ade73e..dbaac16 100644 --- a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php +++ b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php @@ -100,8 +100,7 @@ public function getPdf($invoices = array()) if ($item->getOrderItem()->getParentItem()) { continue; } - - if ($this->y < 100) { + if ($this->y < 50 || (Mage::getStoreConfig('sales_pdf/firegento_pdf/show_footer') == 1 && $this->y < 100)) { $page = $this->newPage(array()); } diff --git a/app/code/community/FireGento/Pdf/Model/Shipment.php b/app/code/community/FireGento/Pdf/Model/Shipment.php index b51c82b..762f558 100644 --- a/app/code/community/FireGento/Pdf/Model/Shipment.php +++ b/app/code/community/FireGento/Pdf/Model/Shipment.php @@ -101,7 +101,7 @@ public function getPdf($shipments = array()) continue; } - if ($this->y < 100) { + if ($this->y < 50 || (Mage::getStoreConfig('sales_pdf/firegento_pdf/show_footer') == 1 && $this->y < 100)) { $page = $this->newPage(array()); } From eafcecff4836ec40211a02203c7c943d259f3254 Mon Sep 17 00:00:00 2001 From: avogt Date: Sat, 1 Jun 2013 15:48:35 +0200 Subject: [PATCH 04/13] #21: forgotten Funktion update --- app/code/community/FireGento/Pdf/Model/Abstract.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/community/FireGento/Pdf/Model/Abstract.php b/app/code/community/FireGento/Pdf/Model/Abstract.php index b813187..babdffc 100644 --- a/app/code/community/FireGento/Pdf/Model/Abstract.php +++ b/app/code/community/FireGento/Pdf/Model/Abstract.php @@ -823,9 +823,7 @@ protected function _insertFooterBlock(&$page, $fields, $colposition = 0, $valadj // calculate the maximum width for the value $width = $this->margin['left'] + $colposition + $colwidth - ($this->margin['left'] + $valposition); } - $tmpVal = $this->_prepareText($val, $page, $font, $fontSize, $width); - $tmpVals = explode("\n", $tmpVal); - foreach ($tmpVals as $tmpVal) { + foreach ($this->_prepareText($val, $page, $font, $fontSize, $width) as $tmpVal) { $page->drawText($tmpVal, $this->margin['left'] + $valposition, $y, $this->encoding); $y -= 12; } From 0bd854f997f2ac484597df24482336e504a391bf Mon Sep 17 00:00:00 2001 From: avogt Date: Sat, 1 Jun 2013 15:52:48 +0200 Subject: [PATCH 05/13] #21: forgotten function replacement --- app/code/community/FireGento/Pdf/Model/Abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/FireGento/Pdf/Model/Abstract.php b/app/code/community/FireGento/Pdf/Model/Abstract.php index babdffc..7256a95 100644 --- a/app/code/community/FireGento/Pdf/Model/Abstract.php +++ b/app/code/community/FireGento/Pdf/Model/Abstract.php @@ -372,7 +372,7 @@ protected function insertHeader(&$page, $order, $document) $width = 80; if ($putPaymentMethod) { - $paymentMethodArray = $this->_stringToArray($order->getPayment()->getMethodInstance()->getTitle(), $page, $font, 10, $width); + $paymentMethodArray = $this->_prepareText($order->getPayment()->getMethodInstance()->getTitle(), $page, $font, 10, $width); $page->drawText(array_shift($paymentMethodArray), ($this->margin['right'] - $valueRightOffset - $width), $this->y, $this->encoding); $this->Ln(); $paymentMethodArray = $this->_prepareText(implode(" ", $paymentMethodArray), $page, $font, 10, 2 * $width); From be7b4fec6ee8cc4e767a05fbc883fbc16cda2113 Mon Sep 17 00:00:00 2001 From: Damian Luszczymak Date: Sat, 1 Jun 2013 17:33:25 +0200 Subject: [PATCH 06/13] refactored insertHeader method --- .../FireGento/Pdf/Model/Abstract.php | 74 ++++++++----------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/app/code/community/FireGento/Pdf/Model/Abstract.php b/app/code/community/FireGento/Pdf/Model/Abstract.php index 7256a95..37cf26b 100644 --- a/app/code/community/FireGento/Pdf/Model/Abstract.php +++ b/app/code/community/FireGento/Pdf/Model/Abstract.php @@ -286,61 +286,32 @@ protected function insertHeader(&$page, $order, $document) $this->y += 80; $labelRightOffset = 180; + $valueRightOffset = 10; + $font = $this->_setFontRegular($page, 10); + $width = 80; + + + // Invoice Number $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice number:' : 'Creditmemo number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); $yPlus = 15; + $incrementId = $document->getIncrementId(); + $page->drawText($incrementId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($incrementId, $font, 10)), $this->y, $this->encoding); + $this->Ln(); + + // Order Number $putOrderId = $this->_putOrderId($order); if ($putOrderId) { $page->drawText(Mage::helper('firegento_pdf')->__('Order number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); + $page->drawText($putOrderId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($putOrderId, $font, 10)), $this->y, $this->encoding); $this->Ln(); $yPlus += 15; } + // Customer Number $page->drawText(Mage::helper('firegento_pdf')->__('Customer number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); $yPlus += 15; - if (!Mage::getStoreConfigFlag('sales/general/hide_customer_ip', $order->getStoreId())) { - $page->drawText(Mage::helper('firegento_pdf')->__('Customer IP:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - } - - $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice date:' : 'Date:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - - // Draw payment method. - $putPaymentMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/payment_method_position') == FireGento_Pdf_Model_System_Config_Source_Payment::POSITION_HEADER); - if ($putPaymentMethod) { - $page->drawText(Mage::helper('firegento_pdf')->__('Payment method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - } - - // Draw shipping method. - $putShippingMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/shipping_method_position') == FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_HEADER); - if ($putShippingMethod) { - $page->drawText(Mage::helper('firegento_pdf')->__('Shipping method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - } - - $this->y += $yPlus; - - $valueRightOffset = 10; - $font = $this->_setFontRegular($page, 10); - - $incrementId = $document->getIncrementId(); - $page->drawText($incrementId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($incrementId, $font, 10)), $this->y, $this->encoding); - $this->Ln(); - - if ($putOrderId) { - $page->drawText($putOrderId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($putOrderId, $font, 10)), $this->y, $this->encoding); - $this->Ln(); - } - if ($order->getCustomerId() != '') { $prefix = Mage::getStoreConfig('sales_pdf/invoice/customeridprefix'); @@ -358,20 +329,30 @@ protected function insertHeader(&$page, $order, $document) $this->Ln(); } + // Customer IP if (!Mage::getStoreConfigFlag('sales/general/hide_customer_ip', $order->getStoreId())) { + $page->drawText(Mage::helper('firegento_pdf')->__('Customer IP:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $customerIP = $order->getData('remote_ip'); $font = $this->_setFontRegular($page, 10); $page->drawText($customerIP, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($customerIP, $font, 10)), $this->y, $this->encoding); $this->Ln(); + + $yPlus += 15; } + $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice date:' : 'Date:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $documentDate = Mage::helper('core')->formatDate($document->getCreatedAtDate(), 'medium', false); $page->drawText($documentDate, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($documentDate, $font, 10)), $this->y, $this->encoding); $this->Ln(); + $yPlus += 15; - $width = 80; + // Payment method. + $putPaymentMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/payment_method_position') == FireGento_Pdf_Model_System_Config_Source_Payment::POSITION_HEADER); if ($putPaymentMethod) { + $page->drawText(Mage::helper('firegento_pdf')->__('Payment method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); + $yPlus += 15; + $paymentMethodArray = $this->_prepareText($order->getPayment()->getMethodInstance()->getTitle(), $page, $font, 10, $width); $page->drawText(array_shift($paymentMethodArray), ($this->margin['right'] - $valueRightOffset - $width), $this->y, $this->encoding); $this->Ln(); @@ -380,9 +361,14 @@ protected function insertHeader(&$page, $order, $document) $page->drawText($methodString, $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $this->Ln(); } + } + // Shipping method. + $putShippingMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/shipping_method_position') == FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_HEADER); if ($putShippingMethod) { + $page->drawText(Mage::helper('firegento_pdf')->__('Shipping method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); + $yPlus += 15; $shippingMethodArray = $this->_prepareText($order->getShippingDescription(), $page, $font, 10, $width); $page->drawText(array_shift($shippingMethodArray), ($this->margin['right'] - $valueRightOffset - $width), $this->y, $this->encoding); $this->Ln(); @@ -391,7 +377,9 @@ protected function insertHeader(&$page, $order, $document) $page->drawText($methodString, $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $this->Ln(); } + } + $this->y += $yPlus; } /** From 8fa1e1fb4647b2a1dda8b7eddc4b5feba6c1e2e6 Mon Sep 17 00:00:00 2001 From: Simon Sprankel Date: Sat, 1 Jun 2013 17:40:29 +0200 Subject: [PATCH 07/13] fixed return value of prepareText --- app/code/community/FireGento/Pdf/Model/Abstract.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/community/FireGento/Pdf/Model/Abstract.php b/app/code/community/FireGento/Pdf/Model/Abstract.php index 37cf26b..cf398f0 100644 --- a/app/code/community/FireGento/Pdf/Model/Abstract.php +++ b/app/code/community/FireGento/Pdf/Model/Abstract.php @@ -915,6 +915,9 @@ protected function _setFontItalic($object, $size = 10) */ protected function _prepareText($text, $page, $font, $fontSize, $width = null) { + if (empty($text)) { + return array(); + } $lines = ''; $currentLine = ''; // calculate the page's width with respect to the margins From 6437860115a6e9ad1528a8bd674cd18d21d4b7d5 Mon Sep 17 00:00:00 2001 From: Damian Luszczymak Date: Sat, 1 Jun 2013 18:01:48 +0200 Subject: [PATCH 08/13] item table y coordinate is now correctly calc. --- .../FireGento/Pdf/Model/Abstract.php | 23 +++++++++++-------- .../Pdf/Model/Engine/Invoice/Default.php | 9 ++++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/code/community/FireGento/Pdf/Model/Abstract.php b/app/code/community/FireGento/Pdf/Model/Abstract.php index cf398f0..cdf1563 100644 --- a/app/code/community/FireGento/Pdf/Model/Abstract.php +++ b/app/code/community/FireGento/Pdf/Model/Abstract.php @@ -289,15 +289,16 @@ protected function insertHeader(&$page, $order, $document) $valueRightOffset = 10; $font = $this->_setFontRegular($page, 10); $width = 80; + $numberOfLines = 0; // Invoice Number $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice number:' : 'Creditmemo number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $yPlus = 15; $incrementId = $document->getIncrementId(); $page->drawText($incrementId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($incrementId, $font, 10)), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; // Order Number $putOrderId = $this->_putOrderId($order); @@ -305,12 +306,12 @@ protected function insertHeader(&$page, $order, $document) $page->drawText(Mage::helper('firegento_pdf')->__('Order number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $page->drawText($putOrderId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($putOrderId, $font, 10)), $this->y, $this->encoding); $this->Ln(); - $yPlus += 15; + $numberOfLines++; } // Customer Number $page->drawText(Mage::helper('firegento_pdf')->__('Customer number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $yPlus += 15; + $numberOfLines++; if ($order->getCustomerId() != '') { @@ -324,9 +325,11 @@ protected function insertHeader(&$page, $order, $document) $page->drawText($customerid, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($customerid, $font, 10)), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; } else { $page->drawText('-', ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize('-', $font, 10)), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; } // Customer IP @@ -336,30 +339,29 @@ protected function insertHeader(&$page, $order, $document) $font = $this->_setFontRegular($page, 10); $page->drawText($customerIP, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($customerIP, $font, 10)), $this->y, $this->encoding); $this->Ln(); - - $yPlus += 15; + $numberOfLines++; } $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice date:' : 'Date:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $documentDate = Mage::helper('core')->formatDate($document->getCreatedAtDate(), 'medium', false); $page->drawText($documentDate, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($documentDate, $font, 10)), $this->y, $this->encoding); $this->Ln(); - $yPlus += 15; + $numberOfLines++; // Payment method. $putPaymentMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/payment_method_position') == FireGento_Pdf_Model_System_Config_Source_Payment::POSITION_HEADER); if ($putPaymentMethod) { $page->drawText(Mage::helper('firegento_pdf')->__('Payment method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $yPlus += 15; - $paymentMethodArray = $this->_prepareText($order->getPayment()->getMethodInstance()->getTitle(), $page, $font, 10, $width); $page->drawText(array_shift($paymentMethodArray), ($this->margin['right'] - $valueRightOffset - $width), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; $paymentMethodArray = $this->_prepareText(implode(" ", $paymentMethodArray), $page, $font, 10, 2 * $width); foreach ($paymentMethodArray as $methodString) { $page->drawText($methodString, $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; } } @@ -368,18 +370,19 @@ protected function insertHeader(&$page, $order, $document) $putShippingMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/shipping_method_position') == FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_HEADER); if ($putShippingMethod) { $page->drawText(Mage::helper('firegento_pdf')->__('Shipping method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $yPlus += 15; $shippingMethodArray = $this->_prepareText($order->getShippingDescription(), $page, $font, 10, $width); $page->drawText(array_shift($shippingMethodArray), ($this->margin['right'] - $valueRightOffset - $width), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; $shippingMethodArray = $this->_prepareText(implode(" ", $shippingMethodArray), $page, $font, 10, 2 * $width); foreach ($shippingMethodArray as $methodString) { $page->drawText($methodString, $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; } } - $this->y += $yPlus; + $this->y -= ($numberOfLines*2); } /** diff --git a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php index dbaac16..55453aa 100644 --- a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php +++ b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php @@ -84,12 +84,9 @@ public function getPdf($invoices = array()) $this->y = 592; $this->insertHeader($page, $order, $invoice); - // Add footer - $this->_addFooter($page, $invoice->getStore()); /* add table header */ $this->_setFontRegular($page, 9); - $this->y = 562; $this->insertTableHeader($page); $this->y -= 20; @@ -115,7 +112,11 @@ public function getPdf($invoices = array()) $page = $this->insertTotals($page, $invoice); /* add note */ - $this->_insertNote($page, $order, $invoice); + $page = $this->_insertNote($page, $order, $invoice); + + // Add footer + $this->_addFooter($page, $invoice->getStore()); + } $this->_afterGetPdf(); From 8a6ebc4477cee8767a1cfb9ead0a88656935a64f Mon Sep 17 00:00:00 2001 From: avogt Date: Sat, 1 Jun 2013 20:16:24 +0200 Subject: [PATCH 09/13] merged origin/development and new renderTotals --- .../FireGento/Pdf/Model/Abstract.php | 263 ++++-------------- .../Pdf/Model/Engine/Invoice/Default.php | 9 +- 2 files changed, 66 insertions(+), 206 deletions(-) diff --git a/app/code/community/FireGento/Pdf/Model/Abstract.php b/app/code/community/FireGento/Pdf/Model/Abstract.php index 7256a95..fbe3e31 100644 --- a/app/code/community/FireGento/Pdf/Model/Abstract.php +++ b/app/code/community/FireGento/Pdf/Model/Abstract.php @@ -286,61 +286,33 @@ protected function insertHeader(&$page, $order, $document) $this->y += 80; $labelRightOffset = 180; - $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice number:' : 'Creditmemo number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus = 15; - - $putOrderId = $this->_putOrderId($order); - if ($putOrderId) { - $page->drawText(Mage::helper('firegento_pdf')->__('Order number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - } - - $page->drawText(Mage::helper('firegento_pdf')->__('Customer number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - - if (!Mage::getStoreConfigFlag('sales/general/hide_customer_ip', $order->getStoreId())) { - $page->drawText(Mage::helper('firegento_pdf')->__('Customer IP:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - } - - $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice date:' : 'Date:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - - // Draw payment method. - $putPaymentMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/payment_method_position') == FireGento_Pdf_Model_System_Config_Source_Payment::POSITION_HEADER); - if ($putPaymentMethod) { - $page->drawText(Mage::helper('firegento_pdf')->__('Payment method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - } - - // Draw shipping method. - $putShippingMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/shipping_method_position') == FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_HEADER); - if ($putShippingMethod) { - $page->drawText(Mage::helper('firegento_pdf')->__('Shipping method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); - $this->Ln(); - $yPlus += 15; - } - - $this->y += $yPlus; - $valueRightOffset = 10; $font = $this->_setFontRegular($page, 10); + $width = 80; + $numberOfLines = 0; + + + // Invoice Number + $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice number:' : 'Creditmemo number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $incrementId = $document->getIncrementId(); $page->drawText($incrementId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($incrementId, $font, 10)), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; + // Order Number + $putOrderId = $this->_putOrderId($order); if ($putOrderId) { + $page->drawText(Mage::helper('firegento_pdf')->__('Order number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $page->drawText($putOrderId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($putOrderId, $font, 10)), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; } + // Customer Number + $page->drawText(Mage::helper('firegento_pdf')->__('Customer number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); + $numberOfLines++; + if ($order->getCustomerId() != '') { $prefix = Mage::getStoreConfig('sales_pdf/invoice/customeridprefix'); @@ -353,45 +325,64 @@ protected function insertHeader(&$page, $order, $document) $page->drawText($customerid, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($customerid, $font, 10)), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; } else { $page->drawText('-', ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize('-', $font, 10)), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; } + // Customer IP if (!Mage::getStoreConfigFlag('sales/general/hide_customer_ip', $order->getStoreId())) { + $page->drawText(Mage::helper('firegento_pdf')->__('Customer IP:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $customerIP = $order->getData('remote_ip'); $font = $this->_setFontRegular($page, 10); $page->drawText($customerIP, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($customerIP, $font, 10)), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; } + $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice date:' : 'Date:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $documentDate = Mage::helper('core')->formatDate($document->getCreatedAtDate(), 'medium', false); $page->drawText($documentDate, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($documentDate, $font, 10)), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; - $width = 80; + // Payment method. + $putPaymentMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/payment_method_position') == FireGento_Pdf_Model_System_Config_Source_Payment::POSITION_HEADER); if ($putPaymentMethod) { + $page->drawText(Mage::helper('firegento_pdf')->__('Payment method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $paymentMethodArray = $this->_prepareText($order->getPayment()->getMethodInstance()->getTitle(), $page, $font, 10, $width); $page->drawText(array_shift($paymentMethodArray), ($this->margin['right'] - $valueRightOffset - $width), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; $paymentMethodArray = $this->_prepareText(implode(" ", $paymentMethodArray), $page, $font, 10, 2 * $width); foreach ($paymentMethodArray as $methodString) { $page->drawText($methodString, $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; } + } + // Shipping method. + $putShippingMethod = ($mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/shipping_method_position') == FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_HEADER); if ($putShippingMethod) { + $page->drawText(Mage::helper('firegento_pdf')->__('Shipping method:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $shippingMethodArray = $this->_prepareText($order->getShippingDescription(), $page, $font, 10, $width); $page->drawText(array_shift($shippingMethodArray), ($this->margin['right'] - $valueRightOffset - $width), $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; $shippingMethodArray = $this->_prepareText(implode(" ", $shippingMethodArray), $page, $font, 10, 2 * $width); foreach ($shippingMethodArray as $methodString) { $page->drawText($methodString, $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $this->Ln(); + $numberOfLines++; } + } + $this->y -= ($numberOfLines*2); } /** @@ -518,164 +509,29 @@ protected function insertTotals($page, $source) ); foreach ($totals as $total) { - $fontSize = (isset($total['font_size']) ? $total['font_size'] : 7); - if ($fontSize < 9) { - $fontSize = 9; - } - $fontWeight = (isset($total['font_weight']) ? $total['font_weight'] : 'regular'); - - switch ($total['source_field']) { - case 'tax_amount': - foreach ($groupedTax as $taxRate => $taxValue) { - if (empty($taxValue)) { - continue; - } - - $lineBlock['lines'][] = array( - array( - 'text' => Mage::helper('firegento_pdf')->__('Additional tax %s', $source->getStore()->roundPrice(number_format($taxRate, 0)) . '%'), - 'feed' => $this->margin['left'] + 320, - 'align' => 'left', - 'font_size' => $fontSize, - 'font' => $fontWeight - ), - array( - 'text' => $order->formatPriceTxt($taxValue), - 'feed' => $this->margin['right'] - 10, - 'align' => 'right', - 'font_size' => $fontSize, - 'font' => $fontWeight - ), - ); - } - break; - - case 'subtotal': - $amount = $source->getDataUsingMethod($total['source_field']); - $displayZero = (isset($total['display_zero']) ? $total['display_zero'] : 0); - - if ($amount != 0 || $displayZero) { - $amount = $order->formatPriceTxt($amount); - - if (isset($total['amount_prefix']) && $total['amount_prefix']) { - $amount = "{$total['amount_prefix']}{$amount}"; - } - - $label = Mage::helper('sales')->__($total['title']) . ':'; - - $lineBlock['lines'][] = array( - array( - 'text' => $label, - 'feed' => $this->margin['left'] + 320, - 'align' => 'left', - 'font_size' => $fontSize, - 'font' => $fontWeight - ), - array( - 'text' => $amount, - 'feed' => $this->margin['right'] - 10, - 'align' => 'right', - 'font_size' => $fontSize, - 'font' => $fontWeight - ), - ); - } - break; - - case 'shipping_amount': - $amount = $source->getDataUsingMethod($total['source_field']); - $displayZero = (isset($total['display_zero']) ? $total['display_zero'] : 0); - - if ($amount != 0 || $displayZero) { - $amount = $order->formatPriceTxt($amount); - - if (isset($total['amount_prefix']) && $total['amount_prefix']) { - $amount = "{$total['amount_prefix']}{$amount}"; - } - - $label = Mage::helper('sales')->__($total['title']) . ':'; - - $lineBlock['lines'][] = array( - array( - 'text' => Mage::helper('firegento_pdf')->__('Shipping:'), - 'feed' => $this->margin['left'] + 320, - 'align' => 'left', - 'font_size' => $fontSize, - 'font' => $fontWeight - ), - array( - 'text' => $amount, - 'feed' => $this->margin['right'] - 10, - 'align' => 'right', - 'font_size' => $fontSize, - 'font' => $fontWeight - ), - ); - } - break; - - case 'grand_total': - $amount = $source->getDataUsingMethod($total['source_field']); - $displayZero = (isset($total['display_zero']) ? $total['display_zero'] : 0); - - if ($amount != 0 || $displayZero) { - $amount = $order->formatPriceTxt($amount); - - if (isset($total['amount_prefix']) && $total['amount_prefix']) { - $amount = "{$total['amount_prefix']}{$amount}"; - } - - $label = Mage::helper('sales')->__($total['title']) . ':'; - - $lineBlock['lines'][] = array( - array( - 'text' => $label, - 'feed' => $this->margin['left'] + 320, - 'align' => 'left', - 'font_size' => $fontSize, - 'font' => $fontWeight - ), - array( - 'text' => $amount, - 'feed' => $this->margin['right'] - 10, - 'align' => 'right', - 'font_size' => $fontSize, - 'font' => $fontWeight - ), - ); - } - break; - - default: - $amount = $source->getDataUsingMethod($total['source_field']); - $displayZero = (isset($total['display_zero']) ? $total['display_zero'] : 0); - - if ($amount != 0 || $displayZero) { - $amount = $order->formatPriceTxt($amount); - - if (isset($total['amount_prefix']) && $total['amount_prefix']) { - $amount = "{$total['amount_prefix']}{$amount}"; - } - - $label = Mage::helper('sales')->__($total['title']) . ':'; - - $lineBlock['lines'][] = array( - array( - 'text' => $label, - 'feed' => $this->margin['left'] + 320, - 'align' => 'left', - 'font_size' => $fontSize, - 'font' => $fontWeight - ), - array( - 'text' => $amount, - 'feed' => $this->margin['right'] - 10, - 'align' => 'right', - 'font_size' => $fontSize, - 'font' => $fontWeight - ), - ); - } + $total->setOrder($order) + ->setSource($source); + + if ($total->canDisplay()) { + $total->setFontSize(10); + foreach ($total->getTotalsForDisplay() as $totalData) { + $lineBlock['lines'][] = array( + array( + 'text' => $totalData['label'], + 'feed' => 475, + 'align' => 'right', + 'font_size' => $totalData['font_size'], + 'font' => 'bold' + ), + array( + 'text' => $totalData['amount'], + 'feed' => 565, + 'align' => 'right', + 'font_size' => $totalData['font_size'], + 'font' => 'bold' + ), + ); + } } } $page = $this->drawLineBlocks($page, array($lineBlock)); @@ -927,6 +783,9 @@ protected function _setFontItalic($object, $size = 10) */ protected function _prepareText($text, $page, $font, $fontSize, $width = null) { + if (empty($text)) { + return array(); + } $lines = ''; $currentLine = ''; // calculate the page's width with respect to the margins diff --git a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php index dbaac16..55453aa 100644 --- a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php +++ b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php @@ -84,12 +84,9 @@ public function getPdf($invoices = array()) $this->y = 592; $this->insertHeader($page, $order, $invoice); - // Add footer - $this->_addFooter($page, $invoice->getStore()); /* add table header */ $this->_setFontRegular($page, 9); - $this->y = 562; $this->insertTableHeader($page); $this->y -= 20; @@ -115,7 +112,11 @@ public function getPdf($invoices = array()) $page = $this->insertTotals($page, $invoice); /* add note */ - $this->_insertNote($page, $order, $invoice); + $page = $this->_insertNote($page, $order, $invoice); + + // Add footer + $this->_addFooter($page, $invoice->getStore()); + } $this->_afterGetPdf(); From 1f65eff835e0e70039f4e640028e0581cfb5d618 Mon Sep 17 00:00:00 2001 From: avogt Date: Sat, 1 Jun 2013 21:29:43 +0200 Subject: [PATCH 10/13] #12: tax output including new config option and some detail fixes --- .../FireGento/Pdf/Model/Abstract.php | 13 ++-- .../Pdf/Model/Tax/Sales/Pdf/Grandtotal.php | 69 +++++++++++++++++++ .../community/FireGento/Pdf/etc/config.xml | 10 +++ .../community/FireGento/Pdf/etc/system.xml | 17 +++++ 4 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 app/code/community/FireGento/Pdf/Model/Tax/Sales/Pdf/Grandtotal.php diff --git a/app/code/community/FireGento/Pdf/Model/Abstract.php b/app/code/community/FireGento/Pdf/Model/Abstract.php index fbe3e31..daa61c6 100644 --- a/app/code/community/FireGento/Pdf/Model/Abstract.php +++ b/app/code/community/FireGento/Pdf/Model/Abstract.php @@ -509,8 +509,7 @@ protected function insertTotals($page, $source) ); foreach ($totals as $total) { - $total->setOrder($order) - ->setSource($source); + $total->setOrder($order)->setSource($source); if ($total->canDisplay()) { $total->setFontSize(10); @@ -518,17 +517,15 @@ protected function insertTotals($page, $source) $lineBlock['lines'][] = array( array( 'text' => $totalData['label'], - 'feed' => 475, + 'feed' => 470, 'align' => 'right', - 'font_size' => $totalData['font_size'], - 'font' => 'bold' + 'font_size' => $totalData['font_size'] ), array( 'text' => $totalData['amount'], - 'feed' => 565, + 'feed' => 540, 'align' => 'right', - 'font_size' => $totalData['font_size'], - 'font' => 'bold' + 'font_size' => $totalData['font_size'] ), ); } diff --git a/app/code/community/FireGento/Pdf/Model/Tax/Sales/Pdf/Grandtotal.php b/app/code/community/FireGento/Pdf/Model/Tax/Sales/Pdf/Grandtotal.php new file mode 100644 index 0000000..c12ea5f --- /dev/null +++ b/app/code/community/FireGento/Pdf/Model/Tax/Sales/Pdf/Grandtotal.php @@ -0,0 +1,69 @@ + array( + * 'amount' => $amount, + * 'label' => $label, + * 'font_size'=> $font_size + * ) + * ) + * @return array + */ + public function getTotalsForDisplay() + { + $store = $this->getOrder()->getStore(); + $config = Mage::getSingleton('tax/config'); + $noDisplaySumOnDetails = Mage::getStoreConfig(self::NO_SUM_ON_DETAILS, $store); + if (!$config->displaySalesTaxWithGrandTotal($store)) { + return parent::getTotalsForDisplay(); + } + $amount = $this->getOrder()->formatPriceTxt($this->getAmount()); + $amountExclTax = $this->getAmount() - $this->getSource()->getTaxAmount(); + $amountExclTax = ($amountExclTax > 0) ? $amountExclTax : 0; + $amountExclTax = $this->getOrder()->formatPriceTxt($amountExclTax); + $tax = $this->getOrder()->formatPriceTxt($this->getSource()->getTaxAmount()); + $fontSize = $this->getFontSize() ? $this->getFontSize() : 7; + + $totals = array(array( + 'amount' => $this->getAmountPrefix() . $amountExclTax, + 'label' => Mage::helper('tax')->__('Grand Total (Excl. Tax)') . ':', + 'font_size' => $fontSize + )); + + /** + * if display_sales_full_summary = 1 + * display each tax group + * if no_sum_on_details is = 1 display tax total additionally + * else display only tax total + */ + if ($config->displaySalesFullSummary($store)) { + $totals = array_merge($totals, $this->getFullTaxInfo()); + if (!$noDisplaySumOnDetails) { + $totals[] = array( + 'amount' => $this->getAmountPrefix() . $tax, + 'label' => Mage::helper('tax')->__('Tax') . ':', + 'font_size' => $fontSize + ); + } + } else { + $totals[] = array( + 'amount' => $this->getAmountPrefix() . $tax, + 'label' => Mage::helper('tax')->__('Tax') . ':', + 'font_size' => $fontSize + ); + } + + $totals[] = array( + 'amount' => $this->getAmountPrefix() . $amount, + 'label' => Mage::helper('tax')->__('Grand Total (Incl. Tax)') . ':', + 'font_size' => $fontSize + ); + return $totals; + } +} \ No newline at end of file diff --git a/app/code/community/FireGento/Pdf/etc/config.xml b/app/code/community/FireGento/Pdf/etc/config.xml index 389d2c7..c9ab894 100644 --- a/app/code/community/FireGento/Pdf/etc/config.xml +++ b/app/code/community/FireGento/Pdf/etc/config.xml @@ -27,6 +27,11 @@ FireGento_Pdf_Model_Shipment + + + FireGento_Pdf_Model_Tax_Sales_Pdf_Grandtotal + + @@ -84,5 +89,10 @@ price_incl_tax,qty,tax,subtotal_incl_tax + + + 0 + + diff --git a/app/code/community/FireGento/Pdf/etc/system.xml b/app/code/community/FireGento/Pdf/etc/system.xml index 71a721c..da56b09 100644 --- a/app/code/community/FireGento/Pdf/etc/system.xml +++ b/app/code/community/FireGento/Pdf/etc/system.xml @@ -24,6 +24,23 @@ --> + + + + + + + select + adminhtml/system_config_source_yesno + 70 + 1 + 1 + 1 + + + + + From 3b8cf4db99c21486c5392d18c9e8395bf5325af5 Mon Sep 17 00:00:00 2001 From: Damian Luszczymak Date: Sun, 2 Jun 2013 11:12:27 +0200 Subject: [PATCH 11/13] license stuff --- .../Pdf/Block/Adminhtml/ColumnOrder.php | 3 +- .../Pdf/Model/Tax/Sales/Pdf/Grandtotal.php | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/code/community/FireGento/Pdf/Block/Adminhtml/ColumnOrder.php b/app/code/community/FireGento/Pdf/Block/Adminhtml/ColumnOrder.php index e49a3a4..9bf5a55 100644 --- a/app/code/community/FireGento/Pdf/Block/Adminhtml/ColumnOrder.php +++ b/app/code/community/FireGento/Pdf/Block/Adminhtml/ColumnOrder.php @@ -4,7 +4,8 @@ * * @category Block * @package FireGento_Pdf - * @author Thomas Birke + * @author FireGento Team + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Firegento_Pdf_Block_Adminhtml_ColumnOrder diff --git a/app/code/community/FireGento/Pdf/Model/Tax/Sales/Pdf/Grandtotal.php b/app/code/community/FireGento/Pdf/Model/Tax/Sales/Pdf/Grandtotal.php index c12ea5f..268c219 100644 --- a/app/code/community/FireGento/Pdf/Model/Tax/Sales/Pdf/Grandtotal.php +++ b/app/code/community/FireGento/Pdf/Model/Tax/Sales/Pdf/Grandtotal.php @@ -1,4 +1,34 @@ + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + */ +/** + * Shipment bundle item model. + * + * @category FireGento + * @package FireGento_Pdf + * @author FireGento Team + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ class FireGento_Pdf_Model_Tax_Sales_Pdf_Grandtotal extends Mage_Tax_Model_Sales_Pdf_Grandtotal { From 7bbc292afe5645e50de9ac8230e7ac17983c0a0a Mon Sep 17 00:00:00 2001 From: Simon Sprankel Date: Sun, 2 Jun 2013 13:50:44 +0200 Subject: [PATCH 12/13] refactoring, new feature configurable engines for shipment and creditmemo --- .../FireGento/Pdf/Model/Creditmemo.php | 153 ++------------- .../Pdf/Model/{ => Engine}/Abstract.php | 22 ++- .../Pdf/Model/Engine/Creditmemo/Default.php | 185 ++++++++++++++++++ .../Pdf/Model/Engine/Invoice/Default.php | 2 +- .../Pdf/Model/Engine/Shipment/Default.php | 170 ++++++++++++++++ .../community/FireGento/Pdf/Model/Invoice.php | 37 +--- .../FireGento/Pdf/Model/Shipment.php | 138 ++----------- .../Config/Source/Creditmemo/Engine.php | 74 +++++++ .../Config/Source/{ => Invoice}/Engine.php | 4 +- .../System/Config/Source/Shipment/Engine.php | 74 +++++++ .../community/FireGento/Pdf/etc/config.xml | 7 + .../community/FireGento/Pdf/etc/system.xml | 36 +++- 12 files changed, 591 insertions(+), 311 deletions(-) rename app/code/community/FireGento/Pdf/Model/{ => Engine}/Abstract.php (97%) create mode 100644 app/code/community/FireGento/Pdf/Model/Engine/Creditmemo/Default.php create mode 100644 app/code/community/FireGento/Pdf/Model/Engine/Shipment/Default.php create mode 100644 app/code/community/FireGento/Pdf/Model/System/Config/Source/Creditmemo/Engine.php rename app/code/community/FireGento/Pdf/Model/System/Config/Source/{ => Invoice}/Engine.php (94%) create mode 100644 app/code/community/FireGento/Pdf/Model/System/Config/Source/Shipment/Engine.php diff --git a/app/code/community/FireGento/Pdf/Model/Creditmemo.php b/app/code/community/FireGento/Pdf/Model/Creditmemo.php index c9286a7..07409a6 100644 --- a/app/code/community/FireGento/Pdf/Model/Creditmemo.php +++ b/app/code/community/FireGento/Pdf/Model/Creditmemo.php @@ -31,156 +31,35 @@ * @version $Id:$ * @since 0.1.0 */ -class FireGento_Pdf_Model_Creditmemo extends FireGento_Pdf_Model_Abstract +class FireGento_Pdf_Model_Creditmemo { - public function __construct() - { - parent::__construct(); - $this->setMode('creditmemo'); - } - /** - * Return PDF document - * - * @param array $creditmemos - * @return Zend_Pdf + * The actual PDF engine responsible for rendering the file. + * @var Mage_Sales_Model_Order_Pdf_Abstract */ - public function getPdf($creditmemos = array()) - { - $this->_beforeGetPdf(); - $this->_initRenderer('creditmemo'); - - $pdf = new Zend_Pdf(); - $this->_setPdf($pdf); - - $style = new Zend_Pdf_Style(); - $this->_setFontBold($style, 10); - - // pagecounter is 0 at the beginning, because it is incremented in newPage() - $this->pagecounter = 0; - - foreach ($creditmemos as $creditmemo) { - if ($creditmemo->getStoreId()) { - Mage::app()->getLocale()->emulate($creditmemo->getStoreId()); - Mage::app()->setCurrentStore($creditmemo->getStoreId()); - } - $page = $this->newPage(); + private $_engine; - $order = $creditmemo->getOrder(); - - // Add logo - $this->insertLogo($page, $creditmemo->getStore()); - - // Add billing address - $this->y = 692; - $this->insertBillingAddress($page, $order); - - // Add sender address - $this->y = 705; - $this->_insertSenderAddessBar($page); - - // Add head - $this->y = 592; - $this->insertHeader($page, $order, $creditmemo); - - // Add footer - $this->_addFooter($page, $creditmemo->getStore()); - - /* Add table head */ - $this->_setFontRegular($page, 9); - $this->y = 562; - $this->_drawHeader($page); - - $this->y -=20; - - $position = 0; + protected function getEngine() + { + if (!$this->_engine) { + $modelClass = Mage::getStoreConfig('sales_pdf/creditmemo/engine'); + $engine = Mage::getModel($modelClass); - /* Add body */ - foreach ($creditmemo->getAllItems() as $item){ - if ($item->getOrderItem()->getParentItem()) { - continue; - } - /* Draw item */ - $position++; - $this->_drawItem($item, $page, $order, $position); - $page = end($pdf->pages); + if (!$engine) { + // Fallback to Magento standard creditmemo layout. + $engine = new Mage_Sales_Model_Order_Pdf_Creditmemo(); } - /* add line after items */ - $page->drawLine($this->margin['left'], $this->y + 5, $this->margin['right'], $this->y + 5); - - /* Add totals */ - $page = $this->insertTotals($page, $creditmemo); - - /* add note */ - $page = $this->_insertNote($page, $order, $creditmemo); + $this->_engine = $engine; } - $this->_afterGetPdf(); - - if ($creditmemo->getStoreId()) { - Mage::app()->getLocale()->revert(); - } - return $pdf; + return $this->_engine; } - /** - * Draw table header for product items - * - * @param Zend_Pdf_Page $page - * @return void - */ - protected function _drawHeader(Zend_Pdf_Page $page) - { - $page->setFillColor($this->colors['grey1']); - $page->setLineColor($this->colors['grey1']); - $page->setLineWidth(1); - $page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'], $this->y - 15); - - $page->setFillColor($this->colors['black']); - $font = $this->_setFontRegular($page, 9); - - $this->y -= 11; - $page->drawText(Mage::helper('firegento_pdf')->__('Pos'), $this->margin['left'] + 3, $this->y, $this->encoding); - $page->drawText(Mage::helper('firegento_pdf')->__('No.'), $this->margin['left'] + 25, $this->y, $this->encoding); - $page->drawText(Mage::helper('firegento_pdf')->__('Description'), $this->margin['left'] + 120, $this->y, $this->encoding); - - $singlePrice = Mage::helper('firegento_pdf')->__('Price (excl. tax)'); - $page->drawText($singlePrice, $this->margin['right'] - 153 - $this->widthForStringUsingFontSize($singlePrice, $font, 9), $this->y, $this->encoding); - - $page->drawText(Mage::helper('firegento_pdf')->__('Qty'), $this->margin['left'] + 360, $this->y, $this->encoding); - - $taxLabel = Mage::helper('firegento_pdf')->__('Tax'); - $page->drawText($taxLabel, $this->margin['right'] - 65 - $this->widthForStringUsingFontSize($taxLabel, $font, 9), $this->y, $this->encoding); - - $totalLabel = Mage::helper('firegento_pdf')->__('Total'); - $page->drawText($totalLabel, $this->margin['right'] - 10 - $this->widthForStringUsingFontSize($totalLabel, $font, 10), $this->y, $this->encoding); - } - - /** - * Initialize renderer process. - * - * @param string $type - * @return void - */ - protected function _initRenderer($type) + public function getPdf($creditmemos = array()) { - parent::_initRenderer($type); - - $this->_renderers['default'] = array( - 'model' => 'firegento_pdf/items_default', - 'renderer' => null - ); - $this->_renderers['grouped'] = array( - 'model' => 'firegento_pdf/items_grouped', - 'renderer' => null - ); - $this->_renderers['bundle'] = array( - 'model' => 'firegento_pdf/items_bundle', - 'renderer' => null - ); + return $this->getEngine()->getPdf($creditmemos); } } - diff --git a/app/code/community/FireGento/Pdf/Model/Abstract.php b/app/code/community/FireGento/Pdf/Model/Engine/Abstract.php similarity index 97% rename from app/code/community/FireGento/Pdf/Model/Abstract.php rename to app/code/community/FireGento/Pdf/Model/Engine/Abstract.php index daa61c6..9f415b1 100644 --- a/app/code/community/FireGento/Pdf/Model/Abstract.php +++ b/app/code/community/FireGento/Pdf/Model/Engine/Abstract.php @@ -31,7 +31,7 @@ * @version $Id:$ * @since 0.1.0 */ -abstract class FireGento_Pdf_Model_Abstract extends Mage_Sales_Model_Order_Pdf_Abstract +abstract class FireGento_Pdf_Model_Engine_Abstract extends Mage_Sales_Model_Order_Pdf_Abstract { public $margin = array('left' => 45, 'right' => 540); public $colors = array(); @@ -279,7 +279,14 @@ protected function insertHeader(&$page, $order, $document) $this->_setFontBold($page, 15); - $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice' : 'Creditmemo'), $this->margin['left'], $this->y, $this->encoding); + if ($mode == 'invoice') { + $title = 'Invoice'; + } else if ($mode == 'shipment') { + $title = 'Shipment'; + } else { + $title = 'Creditmemo'; + } + $page->drawText(Mage::helper('firegento_pdf')->__($title), $this->margin['left'], $this->y, $this->encoding); $this->_setFontRegular($page); @@ -292,8 +299,15 @@ protected function insertHeader(&$page, $order, $document) $numberOfLines = 0; - // Invoice Number - $page->drawText(Mage::helper('firegento_pdf')->__(($mode == 'invoice') ? 'Invoice number:' : 'Creditmemo number:'), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); + // Invoice/shipment/creditmemo Number + if ($mode == 'invoice') { + $numberTitle = 'Invoice number:'; + } else if ($mode == 'shipment') { + $numberTitle = 'Shipment number:'; + } else { + $numberTitle = 'Creditmemo number:'; + } + $page->drawText(Mage::helper('firegento_pdf')->__($numberTitle), ($this->margin['right'] - $labelRightOffset), $this->y, $this->encoding); $incrementId = $document->getIncrementId(); $page->drawText($incrementId, ($this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($incrementId, $font, 10)), $this->y, $this->encoding); diff --git a/app/code/community/FireGento/Pdf/Model/Engine/Creditmemo/Default.php b/app/code/community/FireGento/Pdf/Model/Engine/Creditmemo/Default.php new file mode 100644 index 0000000..8bd210f --- /dev/null +++ b/app/code/community/FireGento/Pdf/Model/Engine/Creditmemo/Default.php @@ -0,0 +1,185 @@ + + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ +/** + * Creditmemo model rewrite. + * + * @category FireGento + * @package FireGento_Pdf + * @author FireGento Team + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ +class FireGento_Pdf_Model_Engine_Creditmemo_Default extends FireGento_Pdf_Model_Engine_Abstract +{ + + public function __construct() + { + parent::__construct(); + $this->setMode('creditmemo'); + } + + /** + * Return PDF document + * + * @param array $creditmemos + * @return Zend_Pdf + */ + public function getPdf($creditmemos = array()) + { + $this->_beforeGetPdf(); + $this->_initRenderer('creditmemo'); + + $pdf = new Zend_Pdf(); + $this->_setPdf($pdf); + + $style = new Zend_Pdf_Style(); + $this->_setFontBold($style, 10); + + // pagecounter is 0 at the beginning, because it is incremented in newPage() + $this->pagecounter = 0; + + foreach ($creditmemos as $creditmemo) { + if ($creditmemo->getStoreId()) { + Mage::app()->getLocale()->emulate($creditmemo->getStoreId()); + Mage::app()->setCurrentStore($creditmemo->getStoreId()); + } + $page = $this->newPage(); + + $order = $creditmemo->getOrder(); + + // Add logo + $this->insertLogo($page, $creditmemo->getStore()); + + // Add billing address + $this->y = 692; + $this->insertBillingAddress($page, $order); + + // Add sender address + $this->y = 705; + $this->_insertSenderAddessBar($page); + + // Add head + $this->y = 592; + $this->insertHeader($page, $order, $creditmemo); + + // Add footer + $this->_addFooter($page, $creditmemo->getStore()); + + /* Add table head */ + $this->_setFontRegular($page, 9); + $this->y = 562; + $this->_drawHeader($page); + + $this->y -=20; + + $position = 0; + + /* Add body */ + foreach ($creditmemo->getAllItems() as $item){ + if ($item->getOrderItem()->getParentItem()) { + continue; + } + /* Draw item */ + $position++; + $this->_drawItem($item, $page, $order, $position); + $page = end($pdf->pages); + } + + /* add line after items */ + $page->drawLine($this->margin['left'], $this->y + 5, $this->margin['right'], $this->y + 5); + + /* Add totals */ + $page = $this->insertTotals($page, $creditmemo); + + /* add note */ + $page = $this->_insertNote($page, $order, $creditmemo); + } + + $this->_afterGetPdf(); + + if ($creditmemo->getStoreId()) { + Mage::app()->getLocale()->revert(); + } + return $pdf; + } + + /** + * Draw table header for product items + * + * @param Zend_Pdf_Page $page + * @return void + */ + protected function _drawHeader(Zend_Pdf_Page $page) + { + $page->setFillColor($this->colors['grey1']); + $page->setLineColor($this->colors['grey1']); + $page->setLineWidth(1); + $page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'], $this->y - 15); + + $page->setFillColor($this->colors['black']); + $font = $this->_setFontRegular($page, 9); + + $this->y -= 11; + $page->drawText(Mage::helper('firegento_pdf')->__('Pos'), $this->margin['left'] + 3, $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('No.'), $this->margin['left'] + 25, $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('Description'), $this->margin['left'] + 120, $this->y, $this->encoding); + + $singlePrice = Mage::helper('firegento_pdf')->__('Price (excl. tax)'); + $page->drawText($singlePrice, $this->margin['right'] - 153 - $this->widthForStringUsingFontSize($singlePrice, $font, 9), $this->y, $this->encoding); + + $page->drawText(Mage::helper('firegento_pdf')->__('Qty'), $this->margin['left'] + 360, $this->y, $this->encoding); + + $taxLabel = Mage::helper('firegento_pdf')->__('Tax'); + $page->drawText($taxLabel, $this->margin['right'] - 65 - $this->widthForStringUsingFontSize($taxLabel, $font, 9), $this->y, $this->encoding); + + $totalLabel = Mage::helper('firegento_pdf')->__('Total'); + $page->drawText($totalLabel, $this->margin['right'] - 10 - $this->widthForStringUsingFontSize($totalLabel, $font, 10), $this->y, $this->encoding); + } + + /** + * Initialize renderer process. + * + * @param string $type + * @return void + */ + protected function _initRenderer($type) + { + parent::_initRenderer($type); + + $this->_renderers['default'] = array( + 'model' => 'firegento_pdf/items_default', + 'renderer' => null + ); + $this->_renderers['grouped'] = array( + 'model' => 'firegento_pdf/items_grouped', + 'renderer' => null + ); + $this->_renderers['bundle'] = array( + 'model' => 'firegento_pdf/items_bundle', + 'renderer' => null + ); + } + +} diff --git a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php index 55453aa..28c3240 100644 --- a/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php +++ b/app/code/community/FireGento/Pdf/Model/Engine/Invoice/Default.php @@ -31,7 +31,7 @@ * @version $Id:$ * @since 0.1.0 */ -class FireGento_Pdf_Model_Engine_Invoice_Default extends FireGento_Pdf_Model_Abstract +class FireGento_Pdf_Model_Engine_Invoice_Default extends FireGento_Pdf_Model_Engine_Abstract { public function __construct() diff --git a/app/code/community/FireGento/Pdf/Model/Engine/Shipment/Default.php b/app/code/community/FireGento/Pdf/Model/Engine/Shipment/Default.php new file mode 100644 index 0000000..6e7343d --- /dev/null +++ b/app/code/community/FireGento/Pdf/Model/Engine/Shipment/Default.php @@ -0,0 +1,170 @@ + + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ +/** + * Shipment model rewrite. + * + * @category FireGento + * @package FireGento_Pdf + * @author FireGento Team + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ +class FireGento_Pdf_Model_Engine_Shipment_Default extends FireGento_Pdf_Model_Engine_Abstract +{ + + public function __construct() + { + parent::__construct(); + $this->setMode('shipment'); + } + + /** + * Return PDF document + * + * @param array $shipments + * @return Zend_Pdf + */ + public function getPdf($shipments = array()) + { + $this->_beforeGetPdf(); + $this->_initRenderer('shipment'); + + $pdf = new Zend_Pdf(); + $this->_setPdf($pdf); + + $style = new Zend_Pdf_Style(); + $this->_setFontBold($style, 10); + + // pagecounter is 0 at the beginning, because it is incremented in newPage() + $this->pagecounter = 0; + + foreach ($shipments as $shipment) { + if ($shipment->getStoreId()) { + Mage::app()->getLocale()->emulate($shipment->getStoreId()); + Mage::app()->setCurrentStore($shipment->getStoreId()); + } + $page = $this->newPage(); + + $order = $shipment->getOrder(); + + /* add logo */ + $this->insertLogo($page, $shipment->getStore()); + + // Add shipping address + $this->y = 692; + $this->insertShippingAddress($page, $order); + + /* add sender address */ + $this->y = 705; + $this->_insertSenderAddessBar($page); + + /* add header */ + $this->y = 592; + $this->insertHeader($page, $order, $shipment); + + // Add footer + $this->_addFooter($page, $shipment->getStore()); + + /* add table header */ + $this->_setFontRegular($page, 9); + $this->y = 562; + $this->insertTableHeader($page); + + $this->y -=20; + + $position = 0; + + foreach ($shipment->getAllItems() as $item) { + if ($item->getOrderItem()->getParentItem()) { + continue; + } + + if ($this->y < 50 || (Mage::getStoreConfig('sales_pdf/firegento_pdf/show_footer') == 1 && $this->y < 100)) { + $page = $this->newPage(array()); + } + + $position++; + $page = $this->_drawItem($item, $page, $order, $position); + } + + /* add note */ + $page = $this->_insertNote($page, $order, $shipment); + } + + $this->_afterGetPdf(); + + return $pdf; + } + + protected function insertTableHeader(&$page) + { + $page->setFillColor($this->colors['grey1']); + $page->setLineColor($this->colors['grey1']); + $page->setLineWidth(1); + $page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'] - 10, $this->y - 15); + + $page->setFillColor($this->colors['black']); + $font = $this->_setFontRegular($page, 9); + + $this->y -= 11; + $page->drawText(Mage::helper('firegento_pdf')->__('No.'), $this->margin['left'], $this->y, $this->encoding); + $page->drawText(Mage::helper('firegento_pdf')->__('Description'), $this->margin['left'] + 105, $this->y, $this->encoding); + + $page->drawText(Mage::helper('firegento_pdf')->__('Qty'), $this->margin['left'] + 450, $this->y, $this->encoding); + } + + protected function insertShippingAddress(&$page, $order) + { + $this->_setFontRegular($page, 9); + + $billing = $this->_formatAddress($order->getShippingAddress()->format('pdf')); + + foreach ($billing as $line) { + $page->drawText(trim(strip_tags($line)), $this->margin['left'], $this->y, $this->encoding); + $this->Ln(12); + } + } + + /** + * Initialize renderer process. + * + * @param string $type + * @return void + */ + protected function _initRenderer($type) + { + parent::_initRenderer($type); + + $this->_renderers['default'] = array( + 'model' => 'firegento_pdf/items_shipment_default', + 'renderer' => null + ); + $this->_renderers['bundle'] = array( + 'model' => 'firegento_pdf/items_shipment_bundle', + 'renderer' => null + ); + } + +} diff --git a/app/code/community/FireGento/Pdf/Model/Invoice.php b/app/code/community/FireGento/Pdf/Model/Invoice.php index 196d1cb..f4df73b 100644 --- a/app/code/community/FireGento/Pdf/Model/Invoice.php +++ b/app/code/community/FireGento/Pdf/Model/Invoice.php @@ -46,7 +46,7 @@ class FireGento_Pdf_Model_Invoice protected function getEngine() { if (!$this->_engine) { - $modelClass = Mage::getStoreConfig('sales_pdf/firegento_pdf/engine'); + $modelClass = Mage::getStoreConfig('sales_pdf/invoice/engine'); $engine = Mage::getModel($modelClass); if (!$engine) { @@ -65,39 +65,4 @@ public function getPdf($invoices = array()) return $this->getEngine()->getPdf($invoices); } - public function widthForStringUsingFontSize($string, $font, $fontSize) - { - return $this->getEngine()->widthForStringUsingFontSize($string, $font, $fontSize); - } - - public function getAlignRight($string, $x, $columnWidth, Zend_Pdf_Resource_Font $font, $fontSize, $padding = 5) - { - return $this->getEngine()->getAlignRight($string, $x, $columnWidth, $font, $fontSize); - } - - public function getAlignCenter($string, $x, $columnWidth, Zend_Pdf_Resource_Font $font, $fontSize) - { - return $this->getEngine()->getAlignCenter($string, $x, $columnWidth, $font, $fontSize); - } - - public function insertDocumentNumber(Zend_Pdf_Page $page, $text) - { - return $this->getEngine()->insertDocumentNumber($page, $text); - } - - public function getRenderer($type) - { - return $this->getEngine()->getRenderer($type); - } - - public function newPage(array $settings = array()) - { - return $this->getEngine()->newPage($settings); - } - - public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSettings = array()) - { - return $this->getEngine()->drawLineBlocks($page, $draw, $pageSettings); - } - } diff --git a/app/code/community/FireGento/Pdf/Model/Shipment.php b/app/code/community/FireGento/Pdf/Model/Shipment.php index 762f558..055d328 100644 --- a/app/code/community/FireGento/Pdf/Model/Shipment.php +++ b/app/code/community/FireGento/Pdf/Model/Shipment.php @@ -31,141 +31,35 @@ * @version $Id:$ * @since 0.1.0 */ -class FireGento_Pdf_Model_Shipment extends FireGento_Pdf_Model_Abstract +class FireGento_Pdf_Model_Shipment { - public function __construct() - { - parent::__construct(); - $this->setMode('shipment'); - } - /** - * Return PDF document - * - * @param array $shipments - * @return Zend_Pdf + * The actual PDF engine responsible for rendering the file. + * @var Mage_Sales_Model_Order_Pdf_Abstract */ - public function getPdf($shipments = array()) - { - $this->_beforeGetPdf(); - $this->_initRenderer('shipment'); - - $pdf = new Zend_Pdf(); - $this->_setPdf($pdf); - - $style = new Zend_Pdf_Style(); - $this->_setFontBold($style, 10); - - // pagecounter is 0 at the beginning, because it is incremented in newPage() - $this->pagecounter = 0; - - foreach ($shipments as $shipment) { - if ($shipment->getStoreId()) { - Mage::app()->getLocale()->emulate($shipment->getStoreId()); - Mage::app()->setCurrentStore($shipment->getStoreId()); - } - $page = $this->newPage(); - - $order = $shipment->getOrder(); - - /* add logo */ - $this->insertLogo($page, $shipment->getStore()); - - // Add shipping address - $this->y = 692; - $this->insertShippingAddress($page, $order); - - /* add sender address */ - $this->y = 705; - $this->_insertSenderAddessBar($page); - - /* add header */ - $this->y = 592; - $this->insertHeader($page, $order, $shipment); - - // Add footer - $this->_addFooter($page, $shipment->getStore()); - - /* add table header */ - $this->_setFontRegular($page, 9); - $this->y = 562; - $this->insertTableHeader($page); - - $this->y -=20; - - $position = 0; - - foreach ($shipment->getAllItems() as $item) { - if ($item->getOrderItem()->getParentItem()) { - continue; - } + private $_engine; - if ($this->y < 50 || (Mage::getStoreConfig('sales_pdf/firegento_pdf/show_footer') == 1 && $this->y < 100)) { - $page = $this->newPage(array()); - } + protected function getEngine() + { + if (!$this->_engine) { + $modelClass = Mage::getStoreConfig('sales_pdf/shipment/engine'); + $engine = Mage::getModel($modelClass); - $position++; - $page = $this->_drawItem($item, $page, $order, $position); + if (!$engine) { + // Fallback to Magento standard shipment layout. + $engine = new Mage_Sales_Model_Order_Pdf_Shipment(); } - /* add note */ - $page = $this->_insertNote($page, $order, $shipment); + $this->_engine = $engine; } - $this->_afterGetPdf(); - - return $pdf; - } - - protected function insertTableHeader(&$page) - { - $page->setFillColor($this->colors['grey1']); - $page->setLineColor($this->colors['grey1']); - $page->setLineWidth(1); - $page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'] - 10, $this->y - 15); - - $page->setFillColor($this->colors['black']); - $font = $this->_setFontRegular($page, 9); - - $this->y -= 11; - $page->drawText(Mage::helper('firegento_pdf')->__('No.'), $this->margin['left'], $this->y, $this->encoding); - $page->drawText(Mage::helper('firegento_pdf')->__('Description'), $this->margin['left'] + 105, $this->y, $this->encoding); - - $page->drawText(Mage::helper('firegento_pdf')->__('Qty'), $this->margin['left'] + 450, $this->y, $this->encoding); + return $this->_engine; } - protected function insertShippingAddress(&$page, $order) - { - $this->_setFontRegular($page, 9); - - $billing = $this->_formatAddress($order->getShippingAddress()->format('pdf')); - - foreach ($billing as $line) { - $page->drawText(trim(strip_tags($line)), $this->margin['left'], $this->y, $this->encoding); - $this->Ln(12); - } - } - - /** - * Initialize renderer process. - * - * @param string $type - * @return void - */ - protected function _initRenderer($type) + public function getPdf($shipments = array()) { - parent::_initRenderer($type); - - $this->_renderers['default'] = array( - 'model' => 'firegento_pdf/items_shipment_default', - 'renderer' => null - ); - $this->_renderers['bundle'] = array( - 'model' => 'firegento_pdf/items_shipment_bundle', - 'renderer' => null - ); + return $this->getEngine()->getPdf($shipments); } } - diff --git a/app/code/community/FireGento/Pdf/Model/System/Config/Source/Creditmemo/Engine.php b/app/code/community/FireGento/Pdf/Model/System/Config/Source/Creditmemo/Engine.php new file mode 100644 index 0000000..8243bb5 --- /dev/null +++ b/app/code/community/FireGento/Pdf/Model/System/Config/Source/Creditmemo/Engine.php @@ -0,0 +1,74 @@ + + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ +/** + * Pdf creation engine source model. + * + * @category FireGento + * @package FireGento_Pdf + * @author FireGento Team + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ +class FireGento_Pdf_Model_System_Config_Source_Creditmemo_Engine +{ + /** + * Config xpath to pdf engine node + * + */ + const XML_PATH_PDF_ENGINE = 'global/pdf/firegento_creditmemo_engines'; + + /** + * Return array of possible engines. + * + * @return array + */ + public function toOptionArray() + { + // load default engines shipped with Mage_Sales and FireGento_Pdf + $engines = array( + '' => Mage::helper('firegento_pdf')->__('Standard Magento'), + 'firegento_pdf/engine_creditmemo_default' => Mage::helper('firegento_pdf')->__('Standard Germany') + ); + + // load additional engines provided by third party extensions + $engineNodes = Mage::app()->getConfig()->getNode(self::XML_PATH_PDF_ENGINE); + if ($engineNodes && $engineNodes->hasChildren()) { + foreach ($engineNodes->children() as $engineName => $engineNode) { + $className = (string)$engineNode->class; + $engineLabel = Mage::helper('firegento_pdf')->__((string)$engineNode->label); + $engines[$className] = $engineLabel; + } + } + + $options = array(); + foreach ($engines as $k => $v) { + $options[] = array( + 'value' => $k, + 'label' => $v + ); + } + return $options; + } +} diff --git a/app/code/community/FireGento/Pdf/Model/System/Config/Source/Engine.php b/app/code/community/FireGento/Pdf/Model/System/Config/Source/Invoice/Engine.php similarity index 94% rename from app/code/community/FireGento/Pdf/Model/System/Config/Source/Engine.php rename to app/code/community/FireGento/Pdf/Model/System/Config/Source/Invoice/Engine.php index 6c1c76c..f0d4ed0 100644 --- a/app/code/community/FireGento/Pdf/Model/System/Config/Source/Engine.php +++ b/app/code/community/FireGento/Pdf/Model/System/Config/Source/Invoice/Engine.php @@ -31,13 +31,13 @@ * @version $Id:$ * @since 0.1.0 */ -class FireGento_Pdf_Model_System_Config_Source_Engine +class FireGento_Pdf_Model_System_Config_Source_Invoice_Engine { /** * Config xpath to pdf engine node * */ - const XML_PATH_PDF_ENGINE = 'global/pdf/firegento_engines'; + const XML_PATH_PDF_ENGINE = 'global/pdf/firegento_invoice_engines'; /** * Return array of possible engines. diff --git a/app/code/community/FireGento/Pdf/Model/System/Config/Source/Shipment/Engine.php b/app/code/community/FireGento/Pdf/Model/System/Config/Source/Shipment/Engine.php new file mode 100644 index 0000000..83cf51c --- /dev/null +++ b/app/code/community/FireGento/Pdf/Model/System/Config/Source/Shipment/Engine.php @@ -0,0 +1,74 @@ + + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ +/** + * Pdf creation engine source model. + * + * @category FireGento + * @package FireGento_Pdf + * @author FireGento Team + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ +class FireGento_Pdf_Model_System_Config_Source_Shipment_Engine +{ + /** + * Config xpath to pdf engine node + * + */ + const XML_PATH_PDF_ENGINE = 'global/pdf/firegento_shipment_engines'; + + /** + * Return array of possible engines. + * + * @return array + */ + public function toOptionArray() + { + // load default engines shipped with Mage_Sales and FireGento_Pdf + $engines = array( + '' => Mage::helper('firegento_pdf')->__('Standard Magento'), + 'firegento_pdf/engine_shipment_default' => Mage::helper('firegento_pdf')->__('Standard Germany') + ); + + // load additional engines provided by third party extensions + $engineNodes = Mage::app()->getConfig()->getNode(self::XML_PATH_PDF_ENGINE); + if ($engineNodes && $engineNodes->hasChildren()) { + foreach ($engineNodes->children() as $engineName => $engineNode) { + $className = (string)$engineNode->class; + $engineLabel = Mage::helper('firegento_pdf')->__((string)$engineNode->label); + $engines[$className] = $engineLabel; + } + } + + $options = array(); + foreach ($engines as $k => $v) { + $options[] = array( + 'value' => $k, + 'label' => $v + ); + } + return $options; + } +} diff --git a/app/code/community/FireGento/Pdf/etc/config.xml b/app/code/community/FireGento/Pdf/etc/config.xml index c9ab894..23a2808 100644 --- a/app/code/community/FireGento/Pdf/etc/config.xml +++ b/app/code/community/FireGento/Pdf/etc/config.xml @@ -86,8 +86,15 @@ + price_incl_tax,qty,tax,subtotal_incl_tax + + + + + + diff --git a/app/code/community/FireGento/Pdf/etc/system.xml b/app/code/community/FireGento/Pdf/etc/system.xml index da56b09..16baf03 100644 --- a/app/code/community/FireGento/Pdf/etc/system.xml +++ b/app/code/community/FireGento/Pdf/etc/system.xml @@ -45,6 +45,15 @@ + + + select + firegento_pdf/system_config_source_invoice_engine + 0 + 1 + 1 + 1 + text @@ -104,6 +113,15 @@ + + + select + firegento_pdf/system_config_source_shipment_engine + 0 + 1 + 1 + 1 + textarea @@ -117,6 +135,15 @@ + + + select + firegento_pdf/system_config_source_creditmemo_engine + 0 + 1 + 1 + 1 + textarea @@ -136,15 +163,6 @@ 1 1 - - - select - firegento_pdf/system_config_source_engine - 0 - 1 - 1 - 1 - text From 85889effd96600481b2d3f5e750ff79a05a35579 Mon Sep 17 00:00:00 2001 From: Simon Sprankel Date: Sun, 2 Jun 2013 14:14:25 +0200 Subject: [PATCH 13/13] increased version, deletes old config data --- .../community/FireGento/Pdf/etc/config.xml | 9 +++- .../upgrade-1.0.0-1.1.0.php | 44 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 app/code/community/FireGento/Pdf/sql/firegento_pdf_setup/upgrade-1.0.0-1.1.0.php diff --git a/app/code/community/FireGento/Pdf/etc/config.xml b/app/code/community/FireGento/Pdf/etc/config.xml index 23a2808..6fb5ca8 100644 --- a/app/code/community/FireGento/Pdf/etc/config.xml +++ b/app/code/community/FireGento/Pdf/etc/config.xml @@ -2,7 +2,7 @@ - 1.0.0 + 1.1.0 @@ -33,6 +33,13 @@ + + + + FireGento_Pdf + + + diff --git a/app/code/community/FireGento/Pdf/sql/firegento_pdf_setup/upgrade-1.0.0-1.1.0.php b/app/code/community/FireGento/Pdf/sql/firegento_pdf_setup/upgrade-1.0.0-1.1.0.php new file mode 100644 index 0000000..33d4c3c --- /dev/null +++ b/app/code/community/FireGento/Pdf/sql/firegento_pdf_setup/upgrade-1.0.0-1.1.0.php @@ -0,0 +1,44 @@ + + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ +/** + * Invoice model rewrite. + * + * The invoice model serves as a proxy to the actual PDF engine as set via + * backend configuration. + * + * @category FireGento + * @package FireGento_Pdf + * @author FireGento Team + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) + * @version $Id:$ + * @since 0.1.0 + */ + +/* @var $this Mage_Eav_Model_Entity_Setup */ +$installer = $this; +$installer->startSetup(); + +$installer->deleteConfigData('sales_pdf/firegento_pdf/engine'); + +$installer->endSetup();