/app/code/community/Vianetz/AdvancedInvoiceLayout/Model/Order/Pdf/Items/Bundle/Invoice.php

https://bitbucket.org/spenna/alexoo_produzione · PHP · 169 lines · 128 code · 23 blank · 18 comment · 14 complexity · a29db86902c69b3ab9b53d72a89bd307 MD5 · raw file

  1. <?php
  2. /**
  3. * AdvancedInvoiceLayout Invoice Bundle Pdf Items renderer
  4. *
  5. * @category Vianetz
  6. * @package Vianetz_AdvancedInvoiceLayout
  7. * @author Christoph Massmann <C.Massmann@vianetz.com>
  8. * @license http://www.vianetz.com/license
  9. */
  10. class Vianetz_AdvancedInvoiceLayout_Model_Order_Pdf_Items_Bundle_Invoice extends Vianetz_AdvancedInvoiceLayout_Model_Order_Pdf_Items_Bundle_Abstract
  11. {
  12. /**
  13. * Draw item line
  14. */
  15. public function draw()
  16. {
  17. $order = $this->getOrder();
  18. $item = $this->getItem();
  19. $pdf = $this->getPdf();
  20. $page = $this->getPage();
  21. $this->loadConfig($pdf, $order->getStore());
  22. $this->_setFontRegular();
  23. $items = $this->getChilds($item);
  24. $_prevOptionId = '';
  25. foreach ($items as $_item) {
  26. $shift = array(0, 0, 0, 0);
  27. $attributes = $this->getSelectionAttributes($_item);
  28. if ($pdf->y-$shift[1] < $pdf->footer_y+30) {
  29. $pdf->page = $this->_newPage($pdf, $pdf->page, $order->getStore());
  30. $this->_drawHeader($pdf, $pdf->page);
  31. $pdf->y -=30;
  32. }
  33. if ($_item->getOrderItem()->getParentItem()) {
  34. if ($_prevOptionId != $attributes['option_id']) {
  35. $this->_setFontItalic();
  36. foreach
  37. (Mage::helper('core/string')->str_split($attributes['option_label'],58-$this->fontsize_regular*2,
  38. true, true) as $key => $part) {
  39. $pdf->page->drawText($part, $this->margin_left+108, $pdf->y,
  40. $this->charset);
  41. $pdf->y -= 10;
  42. }
  43. $this->_setFontRegular();
  44. $_prevOptionId = $attributes['option_id'];
  45. $pdf->y -= 10;
  46. }
  47. }
  48. /* in case Product name is longer than 80 chars - it is written in a few lines */
  49. if ($_item->getOrderItem()->getParentItem()) {
  50. $feed = $this->margin_left+110;
  51. $name = $this->getValueHtml($_item);
  52. $shortdesc = $this->_parseItemShortDescription($_item);
  53. } else {
  54. $feed = $this->margin_left+108;
  55. $name = $_item->getName();
  56. $shortdesc = $this->_parseShortDescription();
  57. }
  58. foreach (Mage::helper('core/string')->str_split($name,
  59. 58-$this->fontsize_regular*2, true, true) as $key => $part) {
  60. $pdf->page->drawText($part, $feed, $pdf->y-$shift[0],
  61. $this->charset);
  62. # if ($key > 0) {
  63. $shift[0] += 10;
  64. # }
  65. }
  66. if (
  67. Mage::getStoreConfig(Vianetz_AdvancedInvoiceLayout_Model_Order_Pdf_Items_Abstract::XML_PATH_SALES_PDF_INVOICE_SHOW_PRODUCT_SHORTDESCRIPTION,
  68. $order->getStore()) ) {
  69. $shift[0] += 4;
  70. $this->_setFontRegular($this->fontsize_regular-1);
  71. foreach
  72. (Mage::helper('core/string')->str_split(strip_tags($shortdesc),
  73. 60-$this->fontsize_regular*2,
  74. true, true) as $description) {
  75. $shift[0] += 10;
  76. $pdf->page->drawText(strip_tags($description), $feed, $pdf->y-$shift[0],
  77. $this->charset);
  78. }
  79. $this->_setFontRegular();
  80. }
  81. // draw SKUs
  82. if (!$_item->getOrderItem()->getParentItem()) {
  83. foreach (Mage::helper('core/string')->str_split($item->getSku(), 15) as $key => $part) {
  84. if ($key > 0) {
  85. $shift[2] += 10;
  86. }
  87. $pdf->page->drawText($part, $this->margin_left+8, $pdf->y-$shift[2],
  88. $this->charset);
  89. }
  90. }
  91. // draw prices
  92. if ($this->canShowPriceInfo($_item)) {
  93. $font = $this->_setFontBold();
  94. $price = $order->formatPriceTxt($_item->getPrice());
  95. $pdf->page->drawText($price, $page->getWidth()-$this->margin_right-100-$pdf->widthForStringUsingFontSize($price,
  96. $font, $this->fontsize_bold), $pdf->y,
  97. $this->charset);
  98. $pdf->page->drawText($_item->getQty()*1,
  99. $page->getWidth()-$this->margin_right-170-$pdf->widthForStringUsingFontSize($_item->getQty()*1,
  100. $font, $this->fontsize_bold), $pdf->y,
  101. $this->charset);
  102. $tax = $order->formatPriceTxt($_item->getTaxAmount());
  103. //$page->drawText($tax, 495-$pdf->widthForStringUsingFontSize($tax, $font, 9), $pdf->y, self::PDF_CHARSET);
  104. $row_total = $order->formatPriceTxt($_item->getRowTotal());
  105. $pdf->page->drawText($row_total,
  106. $page->getWidth()-$this->margin_right-5-$pdf->widthForStringUsingFontSize($row_total, $font, $this->fontsize_bold), $pdf->y,
  107. $this->charset);
  108. $this->_setFontRegular();
  109. }
  110. $pdf->y -= max($shift)+10;
  111. }
  112. if ($item->getOrderItem()->getProductOptions() || $item->getOrderItem()->getDescription()) {
  113. $options = $item->getOrderItem()->getProductOptions();
  114. if (isset($options['options'])) {
  115. foreach ($options['options'] as $option) {
  116. $this->_setFontItalic();
  117. foreach (Mage::helper('core/string')->str_split(strip_tags($option['label']), 60,false, true) as $_option) {
  118. $pdf->page->drawText($_option, $this->margin_left+108, $pdf->y-$shift[1],
  119. $this->charset);
  120. $shift[1] += 10;
  121. }
  122. $this->_setFontRegular();
  123. if ($option['value']) {
  124. $_printValue = isset($option['print_value']) ?
  125. $option['print_value'] : strip_tags($option['value']);
  126. $values = explode(', ', $_printValue);
  127. foreach ($values as $value) {
  128. foreach (Mage::helper('core/string')->str_split($value, 70, true, true) as $_value) {
  129. $pdf->page->drawText($_value, $this->margin_left+110, $pdf->y-$shift[1],
  130. $this->charset);
  131. $shift[1] += 10;
  132. }
  133. }
  134. }
  135. }
  136. }
  137. foreach ($this->_parseDescription() as $description){
  138. $pdf->page->drawText(strip_tags($description), 208, $pdf->y-$shift{1},
  139. $this->charset);
  140. $shift{1} += 10;
  141. }
  142. $pdf->y -= max($shift)+10;
  143. }
  144. }
  145. }
  146. /* vim: set ts=4 sw=4 expandtab nu tw=90: */